[Scummvm-git-logs] scummvm-tools master -> 60d7a24f592be8d141cb6731a901e3f4c13f5d6d
aquadran
aquadran at gmail.com
Wed Oct 14 10:12:02 UTC 2020
This automated email contains information about 166 new commits which have been
pushed to the 'scummvm-tools' repo located at https://github.com/scummvm/scummvm-tools .
Summary:
f7aee03992 import tools
be39ac156c fix compilation
858ee081d2 fix incldue paths
eb78cf05c7 fix linking
baf7d1d887 remove left over game_engine
2bf84cc3c9 restore --enable-verbose-build option
b33b3ef617 Taken lua from revision 943. Delua works right now.
70350b7fe7 remove left over plugin code
806994d44f Merge branch 'master' of github.com:residual/residual-tools
f341cc3189 make bulding create missing dirs
6c686da6fe fix warnings
150a69a594 fix warnings
e45c177434 Added EMI-support to unlab, use with unlab <filename> EMI
82ac4d35e2 Added EMI-support to unlab, use with unlab <filename> EMI
ff0a995b75 Initial work on tiles and sets for EMI
5298d302fe Added some information about the EMI setb format
7c55785943 Improved setb2set
eee3f76b53 Added rudimentary zlib-support to til2bmp, please change all of that to use residuals zlib-wrapper later
5e6fce9790 til2bmp:Improved decompression
bf791283b4 Major cleanup in TIL2BMP
421a0c559b reorganize a bit
695baa76f3 added missing files
3fdcb4cbac Compilation fixes: removed references to non-existent icon object in
fc21f2dacc Added .gitignore for residual-tools
1d7b07df04 Merge pull request #3 from somaen/EMI.
be62b2db97 Merge pull request #2 from elQuotho/master.
2a770f7829 set exec for configure
fbd3640d60 til2bmp: fixed some typing and fixed some memory leaks
1d7b4d0792 TIL2BMP: Cleanup, now uses _notation for fields
d48c8f8618 First version of meshb2obj.cpp
b0860a1c5e PS2 TILE-support, and some endianness-fixes
eb11ddae63 TIL: Added bpp-detection
6762dc02e9 Removed fixed offset of Grimfandango updater
6e19011a8e Removed all files action
5c21186d17 Introduced support for EMI
d7738bf13b Skips some other binary files
19839b809f Removed some useless functions
12f3756290 unlab: Fixed some crashes and reduced memory leaks.
916b1c62c3 Cleanup in style, added Meshb to configure, and fixed til2bmp-compile-flags
7dfe443bc3 TIL2BMP: Complete Big-Endian support
c73855b6e9 Add labcopy
0b97532b54 MESHB2OBJ: Added offset-data to properly decipher faces for MI4-Demo
efd293da4a MESHB2OBJ: Formatting
f2b774c1ff Merge pull request #10 from somaen/meshb
62ed95e05c Merge pull request #8 from somaen/endianness
6bc6873afb Fix labcopy
2a5281ada7 Merge pull request #9 from YakBizzarro/labcopy
20cab0f50e Patchex: fixed the extraction of the whole cabinet and some possible memory-leaks. Simplified a bit the command line.
f7f7edc4bb Merge pull request #11 from YakBizzarro/patchex-clean
aef9a068e4 Initial commit of new EMI-tools
8e2afdaedf Added Meshb2obj to EMI-tools
249931064a Added sklb2txt to EMI-tools
a6daa890ac Cleanup in MESHB/SKLB/ANIMB-converters
0c4fcddb29 Added MESHB/SKLB/ANIMB-converters to module.mk
5b23a6b8bf EMI: Cleaned tools
5a60992303 Merge pull request #12 from somaen/emi-tools
a1cc6e9780 Moved SetB2Set into tools/emi
9ba04d48f1 MESHB2OBJ: Added decoding colors, and the header
b605a50a1e MESHB2OBJ: Cleanup
c7d2a86bc4 EMI: Add simple meshb-renderer, depends on GLFW
432505aa65 ANIMB: Add a bit more
ac1e31b185 EMI: Add Skeleton/Animation loading to renderModel
1dcb74fa28 EMI: Add cosb2cos
8e1dd319db Made Filetools endian-safe
ddefca720c Separated Lab-class from renderModel
762d977fc7 MESHB: Added support for reading directly from LAB-files
de0411d517 TIL2BMP: Add support for reading directly from LAB-files
bbbb3f330e SETB2SET: Add support for reading directly from LAB-files
2ed3136db3 SKLB2TXT: Add support for reading directly from LAB
7ce032d4f5 ANIMB2TXT: Add support for reading directly from LAB-files
911e67bf41 UNLAB: Add automatic detection of EMI-labs, thanks to bgbennyboy
7d91ece413 Fix type names.
ba1f40ae4a Remove unneeded type definition.
9c7a84ea07 Merge pull request #15 from vpelletier/master
1520a2ff96 Fix reading from a cd with bad sectores
0ca90f1cf7 Merge pull request #16 from YakBizzarro/labcopy-badsector
5bb712c6c9 LABCOPY: Proper handling of bad-sectors
17ac5cdc14 Merge pull request #17 from YakBizzarro/labcopy-rewrite
ea82f02f6e New mklab tool to build lab files.
56e19ba76a Merge pull request #18 from giucam/master
37966e3efd MKLAB: Fix ambiguous overload. Fix #19
2b968f37bf BUILD: Patch from Kirben, fixes mingw build
d75d0f138a Add lua bytecode generator (luac)
1da34cde0c Merge pull request #20 from YakBizzarro/luac
2d83a6abdf Added missing headers, fixed endianess bug and fixed string-releated warnings
42c30cf73b Merge pull request #21 from YakBizzarro/luac
ed3785a76b rename to ResidualVM
849f793bd2 sync with main credits
9cf3335afc DELUA: Parse correctly NOP opcode and fix a crash with EMI scripts
c38acc9209 Merge pull request #22 from YakBizzarro/delua-fix
0b6f79dc60 MKLAB: Add support for subdirectories and fix the version number for EMI
c804c97a0d UNLAB: Support creating directories on windows
28623c4542 Merge pull request #23 from klusark/master
810f0b948f ALL: update credits
b2a33fe8d5 ALL: update credits
2923e83a23 ALL: sync common files
d5b0806594 ALL: sync common files
9dca2bd418 ALL: update tools
0becc6b827 TOOLS: remove not needed defines
b93c6a54a1 UNLAB: Add a check to make sure that the input file is long enough to extract the files. This makes it properly report e
9d02719ed6 ALL: update credits
9ae2412a2a ALL: Add some entries in .gitignore
9d3d4fc260 LUAC: Fix a bug
4b0a47628f LUAC: Improve undump output format
f061b8d2fa DELUA: Remove a source of round errors by setting an higer precision
3458d6577d LUAC: Introduce rebase function
c2cc139c89 Merge pull request #24 from YakBizzarro/luac-diff2
d2fee8f0a1 ALL: update copyrights
ad0dfc7ed9 MKLAB: Lab files has the same version both in Grim and Emi
edaa41c7ff MKLAB: Fix a segfault
ed5a2beb72 Merge pull request #25 from YakBizzarro/mklab-fix
0ded9c95be LUAC/DELUA: Interpret all unused opcodes as NOP
2b60bcf9fa Add patchr and diffr tools
e9c54e46ba Merge pull request #26 from YakBizzarro/patchr2
aa854ae9e0 DELUA: Fix validIdentifier function
33332bd6bd DELUA: Fix some memory leaks
ea5b7ac38e DELUA: Don't search a POP after a SETTABLE0
92d9f2d4b9 DELUA: Decompile correctly access to the table fields
11cf6bed6c DELUA: Lua expects escape sequences for special characters with decimal digits
4d6c46b1d7 DELUA: In validIdentifier checks if the string isn't a reserved word
9428d0a2ef DELUA: Add a sanity-check on the input file
82f1aaaf2f DELUA: Avoid multiple definitions of local variables
6c0e2cff7f DELUA: Add a space before and after the concatenation operator
5eb746192a LUAC: Implement a better floating point comparison
f9ec24268f LUAC: Improve a little the performances of rebase function
4c9059728a COMMON: Refactor the build system.
30009e868f Merge pull request #27 from giucam/buildsystem
78cd2ba2a3 COMMON: Fix compilation order.
ba0cd00e2c TOOLS: Fix a bunch of warnings
ed562c55cd TOOLS: Correct loop-mistake in last commit
76e2321d2c LUAC: Fix the jumps when rebasing a function
0c07c27bd2 TOOLS: Make lab.{h,cpp} detect if it is a Grim or EMI lab and move them in tools/.
81ad269f3a TOOL: Add a tool to convert Grim's bm images to bmp bitmaps.
7e597d5c6c TOOLS: LGPL -> GPL headers
a49967ddf9 EMI: Read time correctly in .animb files
6cdcec7f42 EMI: Display a single chore in a .cosb
56f36d1ef5 EMI: Show normals in setb2set
1780f35cb1 ALL: Update .gitignore
7136479e07 TOOLS: Add a small stream workalike to tools.
7681803477 TOOLS: Reformat filetools.h
8199181ffb EMI: Add a tool for rendering TIL-files. (With selective layer-support)
cd3d83844a JANITORIAL: Reformat most files, to be closer to code-style of ResidualVM
110ac1b796 TOOLS: Add destructor to SeekableReadStream.
a04e0753d0 TOOLS: Fix warnings in cosb2cos
e525a54509 EMI: Show sortplanes for sectors (setb2set)
b2a2f1531e TOOLS: Use endian for lab
e2d29b077a TOOLS: Make unlab use lab.cpp and improve the lab.cpp code
d7c4b835c9 TOOLS: Update module.mk to add lab.o to the unlab linking
9a4f6fe880 TOOLS: Pass liblua.a to linker for delua
9b69f4bed9 TOOLS: Also link liblua.a statically for luac
f7ad1ec553 TOOLS: Implement recursive directory creation for UNIX-like systems.
53ca44d3d9 MKLAB: Fix creating labs with subdirectoires and generally cleanup the code
f2f166f13e TOOLS: Remove accedental comment
259ab2ec8b MKLAB: Fix a few warnings and use the correct d_type
307730f950 DELUA: Increase number precision to 9 digits for all streams
70192f5362 LUAC: Remove weird number comparison, since delua doesn't make anymore rounding errors
caf15cf031 LUAC: Improve checks on constants in rebase function
5c3e4a67ec TOOLS: synced with scummvm/(tools) and updates
45c69fb9d9 TOOLS: Add lighting decoding.
5a2e20fe69 Merge pull request #32 from JoseJX/FixSetb
d5072dcaa6 BUILD: Move liblua.a to TOOL_LDFLAGS. Fixes #33.
6f32e52d65 TOOLS: The interest and roll are actually a rotation Quaternion.
f215c8b33e Merge pull request #34 from JoseJX/ReallyAQuat
013e0a3a83 TOOLS: remove not used code from tools
85f6d59612 TOOLS: fixed compiler warnings
60d7a24f59 ALL: Merge ResidualVM tools
Commit: f7aee0399284de3f0e061651443c6ffe8a5431b2
https://github.com/scummvm/scummvm-tools/commit/f7aee0399284de3f0e061651443c6ffe8a5431b2
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-07T21:27:26+02:00
Commit Message:
import tools
Changed paths:
A AUTHORS
A COPYING.GPL
A COPYING.LGPL
A Makefile
A Makefile.common
A README
A common/sys.h
A config.guess
A config.sub
A configure
A ports.mk
A rules.mk
A tools/bmtoppm.cpp
A tools/delua.cpp
A tools/imc2wav.cpp
A tools/int2flt.cpp
A tools/lua/README.residual
A tools/lua/lapi.cpp
A tools/lua/lapi.h
A tools/lua/lauxlib.cpp
A tools/lua/lauxlib.h
A tools/lua/lbuffer.cpp
A tools/lua/lbuiltin.cpp
A tools/lua/lbuiltin.h
A tools/lua/ldo.cpp
A tools/lua/ldo.h
A tools/lua/lfunc.cpp
A tools/lua/lfunc.h
A tools/lua/lgc.cpp
A tools/lua/lgc.h
A tools/lua/liolib.cpp
A tools/lua/llex.cpp
A tools/lua/llex.h
A tools/lua/lmathlib.cpp
A tools/lua/lmem.cpp
A tools/lua/lmem.h
A tools/lua/lobject.cpp
A tools/lua/lobject.h
A tools/lua/lopcodes.h
A tools/lua/lparser.cpp
A tools/lua/lparser.h
A tools/lua/lrestore.cpp
A tools/lua/lsave.cpp
A tools/lua/lstate.cpp
A tools/lua/lstate.h
A tools/lua/lstring.cpp
A tools/lua/lstring.h
A tools/lua/lstrlib.cpp
A tools/lua/ltable.cpp
A tools/lua/ltable.h
A tools/lua/ltask.cpp
A tools/lua/ltask.h
A tools/lua/ltm.cpp
A tools/lua/ltm.h
A tools/lua/lua.h
A tools/lua/luadebug.h
A tools/lua/lualib.h
A tools/lua/lundump.cpp
A tools/lua/lundump.h
A tools/lua/lvm.cpp
A tools/lua/lvm.h
A tools/lua/lzio.cpp
A tools/lua/lzio.h
A tools/lua/module.mk
A tools/mat2ppm.cpp
A tools/module.mk
A tools/patchex/cab.h
A tools/patchex/cabd.cpp
A tools/patchex/mspack.h
A tools/patchex/mszip.h
A tools/patchex/mszipd.cpp
A tools/patchex/patchex.cpp
A tools/set2fig.cpp
A tools/unlab.cpp
A tools/vima.cpp
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 000000000..16f334693
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,95 @@
+Residual Team
+*************
+ Project Leader
+ --------------
+ Pawel Kolodziejski
+
+ Engine Teams
+ ------------
+ Grim:
+ James Brown - Core developer
+ Giulio Camuffo - Core developer
+ Pawel Kolodziejski - Core developer. SMUSH, iMUSE implemention
+
+ Grim Contributors:
+ If you have contributed to this engine then you deserve to be on this
+ list. Contact us and we'll add you.
+
+ Torbjorn Andersson - Various code fixes
+ Ori Avtalion - Lipsync, LAF support
+ Marcus Comstedt - Initial Dreamcast port
+ Andrea Corna - Improved font support, patch extractor
+ Jonathan Gray - Various code fixes
+ Yaron Tausky - Fixes to subtitles
+ Vincent Hamm - Various engine code
+ Erich Hoover - x86-64 fixes, various fixes and comments, menu
+ support, improved state support
+ Travis Howell - Various code fixes, Windows port
+ Joost Peters - Various code fixes
+ Christian Neumair - Various optimisation patches
+ Daniel Schepler - Initial engine codebase, LUA support
+ Pino Toscano - Debian GNU/Linux package files
+ Lionel Ulmer - OpenGL optimisations
+
+ScummVM code
+************
+ Residual use some ScummVM code. Copyrights for this code belongs to
+ persons listed below. If you are missed in this list contact us and we'll
+ add you.
+
+ Torbjorn Andersson
+ Chris Apers
+ Bertrand Augereau
+ Yotam Barnoy
+ James Brown
+ Jamieson Christian
+ David Corrales-Lopez
+ Oystein Eftevaag
+ Robert Goeffringmann
+ Paul Gilbert
+ Jonathan Gray
+ Vincent Hamm
+ Ruediger Hanke
+ Sven Hesse
+ Matthew Hoops
+ Max Horn
+ Florian Kagerer
+ Filippos Karapetis
+ Oliver Kiehl
+ Pawel Kolodziejski
+ Andrew Kurushin
+ Vicent Marti
+ Claudio Matsuoka
+ Gregory Montoir
+ Kostas Nakos
+ Chris Page
+ Willem Jan Palenstijn
+ Lars Persson
+ Joost Peters
+ Jordi Vilalta Prat
+ Kari Salminen
+ Eugene Sandulenko
+ Johannes Schickel
+ Ludvig Strigeus
+ Lionel Ulmer
+ Jody Northup
+ Jordi Vilalta
+ Robin Watts
+ agent-q
+ arisme
+ peres
+
+Website (code)
+**************
+ Fredrik Wendel
+
+Special thanks to
+*****************
+ The LUA developers, for creating a nice compact script interpreter.
+
+ Tim Schafer, for obvious reasons, and everybody else who helped make Grim
+ Fandango a brilliant game; and the EMI team for giving it their best try.
+
+ Bret Mogilefsky, for managing to create a SPUTM-style 3D LUA engine, and
+ avoiding the horrible hack it could have been.
+
diff --git a/COPYING.GPL b/COPYING.GPL
new file mode 100644
index 000000000..b6f92f3db
--- /dev/null
+++ b/COPYING.GPL
@@ -0,0 +1,340 @@
+ 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 Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 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.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/COPYING.LGPL b/COPYING.LGPL
new file mode 100644
index 000000000..00b4fedfe
--- /dev/null
+++ b/COPYING.LGPL
@@ -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.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..9af412932
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,84 @@
+# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/Makefile $
+# $Id: Makefile 1595 2009-10-05 08:50:25Z aquadran $
+
+#######################################################################
+# Default compilation parameters. Normally don't edit these #
+#######################################################################
+
+srcdir ?= .
+
+DEFINES := -DHAVE_CONFIG_H
+LDFLAGS :=
+INCLUDES := -I. -I$(srcdir)
+LIBS :=
+OBJS :=
+DEPDIR := .deps
+
+MODULES :=
+MODULE_DIRS :=
+
+# Load the make rules generated by configure
+-include config.mk
+
+ifeq "$(HAVE_GCC)" "1"
+ CXXFLAGS:= -Wall $(CXXFLAGS)
+ # Turn off some annoying and not-so-useful warnings
+ CXXFLAGS+= -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder
+ # Enable even more warnings...
+ CXXFLAGS+= -Wpointer-arith -Wcast-qual -Wcast-align
+ CXXFLAGS+= -Wshadow -Wimplicit -Wnon-virtual-dtor -Wwrite-strings
+
+ # Currently we disable this gcc flag, since it will also warn in cases,
+ # where using GCC_PRINTF (means: __attribute__((format(printf, x, y))))
+ # is not possible, thus it would fail compiliation with -Werror without
+ # being helpful.
+ #CXXFLAGS+= -Wmissing-format-attribute
+
+ # Disable RTTI and exceptions, and enabled checking of pointers returned by "new"
+ CXXFLAGS+= -fno-exceptions -fcheck-new
+
+ # There is a nice extra warning that flags variables that are potentially
+ # used before being initialized. Very handy to catch a certain kind of
+ # bugs. Unfortunately, it only works when optimizations are turned on,
+ # which is why we normally don't use it.
+ #CXXFLAGS+= -O -Wuninitialized
+endif
+
+#######################################################################
+# Default commands - put the necessary replacements in config.mk #
+#######################################################################
+
+CAT ?= cat
+CP ?= cp
+ECHO ?= printf
+INSTALL ?= install
+MKDIR ?= mkdir -p
+RM ?= rm -f
+RM_REC ?= $(RM) -r
+ZIP ?= zip -q
+
+#######################################################################
+# Misc stuff - you should never have to edit this #
+#######################################################################
+
+EXECUTABLE := residual$(EXEEXT)
+
+include $(srcdir)/Makefile.common
+
+# check if configure has been run or has been changed since last run
+config.h config.mk: $(srcdir)/configure
+ifeq "$(findstring config.mk,$(MAKEFILE_LIST))" "config.mk"
+ @echo "Running $(srcdir)/configure with the last specified parameters"
+ @sleep 2
+ LDFLAGS="$(SAVED_LDFLAGS)" CXX="$(SAVED_CXX)" \
+ CXXFLAGS="$(SAVED_CXXFLAGS)" CPPFLAGS="$(SAVED_CPPFLAGS)" \
+ ASFLAGS="$(SAVED_ASFLAGS)" WINDRESFLAGS="$(SAVED_WINDRESFLAGS)" \
+ $(srcdir)/configure $(SAVED_CONFIGFLAGS)
+else
+ $(error You need to run $(srcdir)/configure before you can run make. Check $(srcdir)/configure --help for a list of parameters)
+endif
+
+ifneq ($(origin port_mk), undefined)
+include $(srcdir)/$(port_mk)
+endif
+
diff --git a/Makefile.common b/Makefile.common
new file mode 100644
index 000000000..610a985d7
--- /dev/null
+++ b/Makefile.common
@@ -0,0 +1,147 @@
+# This file is used by Makefile and declares common build rules,
+# a list of common object files etc.
+#
+# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/Makefile.common $
+# $Id: Makefile.common 1635 2010-01-21 19:25:03Z aquadran $
+
+######################################################################
+# The default build target: just build the residual executable
+######################################################################
+
+all: build
+
+
+######################################################################
+# Module settings
+######################################################################
+
+MODULES := tools $(MODULES)
+
+# After the game specific modules follow the shared modules
+MODULES += \
+ tools/lua
+# common \
+
+######################################################################
+# The build rules follow - normally you should have no need to
+# touch whatever comes after here.
+######################################################################
+
+# Concat DEFINES and INCLUDES to form the CPPFLAGS
+CPPFLAGS := $(DEFINES) $(INCLUDES)
+
+# Include the build instructions for all modules
+-include $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES)))
+
+# Depdir information
+DEPDIRS = $(addsuffix $(DEPDIR),$(MODULE_DIRS))
+DEPFILES =
+
+# Replace regular output with quiet messages
+ifneq ($(findstring $(MAKEFLAGS),s),s)
+ifneq ($(VERBOSE_BUILD),1)
+ifneq ($(VERBOSE_BUILD),yes)
+QUIET_CXX = @echo ' ' C++ ' ' $@;
+QUIET_AS = @echo ' ' AS ' ' $@;
+QUIET_NASM = @echo ' ' NASM ' ' $@;
+QUIET_AR = @echo ' ' AR ' ' $@;
+QUIET_RANLIB = @echo ' ' RANLIB ' ' $@;
+QUIET_PLUGIN = @echo ' ' PLUGIN ' ' $@;
+QUIET_LINK = @echo ' ' LINK ' ' $@;
+QUIET = @
+endif
+endif
+endif
+
+build: $(OBJS) $(MODULES)
+
+distclean: clean
+ $(RM) config.h config.mk config.log
+
+clean:
+ $(RM_REC) $(DEPDIRS)
+ $(RM) $(OBJS) $(EXECUTABLE)
+
+
+#
+# The build rules for object files.
+#
+
+ifdef CXX_UPDATE_DEP_FLAG
+
+# Build rule for C++ files. Makes use of CXX_UPDATE_DEP_FLAG for advanced
+# dependency tracking.
+%.o: %.cpp
+ $(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
+ $(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+
+
+# Build rules for Objective-C and Objective-C++ files. Strictly speaking, this is for OS X only.
+%.o: %.mm
+ $(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
+ $(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+
+%.o: %.m
+ $(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
+ $(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(OBJCFLAGS) -c $(<) -o $*.o
+
+else
+
+# Dumb compile rule, for C++ compilers that don't allow dependency tracking or
+# where it is broken (such as GCC 2.95).
+.cpp.o:
+ $(QUIET_CXX)$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+
+endif
+
+# Build rule for assembler files
+%.o: %.s
+ $(QUIET)$(MKDIR) $(*D)
+ $(QUIET_AS)$(AS) $(ASFLAGS) $(<) -o $*.o
+
+# Build rule for assembler files with preprocessing
+%.o: %.S
+ $(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
+ $(QUIET_AS)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(ASFLAGS) -c $(<) -o $*.o
+
+ifdef HAVE_NASM
+# Build rule for NASM assembler files
+%.o: %.asm
+ $(QUIET)$(MKDIR) $(*D)
+ $(QUIET_NASM)$(NASM) -O1 $(NASMFLAGS) -g -o $*.o $(<)
+endif
+
+# Include the dependency tracking files.
+-include $(wildcard $(addsuffix /*.d,$(DEPDIRS)))
+
+# Mark *.d files and most *.mk files as PHONY. This stops make from trying to
+# recreate them (which it can't), and in particular from looking for potential
+# source files. This can save quite a bit of disk access time.
+.PHONY: $(wildcard $(addsuffix /*.d,$(DEPDIRS))) $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES))) \
+ $(srcdir)/$(port_mk) $(srcdir)/rules.mk
+
+
+######################################################################
+# Distribution settings
+######################################################################
+
+DISTNAME := residual-tools
+DISTDIR := dist
+
+$(DISTDIR)/$(DISTNAME).tar.gz: $(VERFILE)
+ cd $(DISTDIR); tar zcf $(DISTNAME).tar.gz $(DISTNAME)
+
+$(DISTDIR)/$(DISTNAME).tar.bz2: $(VERFILE)
+ cd $(DISTDIR); tar jcf $(DISTNAME).tar.bz2 $(DISTNAME)
+
+$(DISTDIR)/$(DISTNAME).zip: $(VERFILE)
+ cd $(DISTDIR); zip -qr9 $(DISTNAME).zip $(DISTNAME)
+
+dist-src: \
+ $(DISTDIR)/$(DISTNAME).tar.gz \
+ $(DISTDIR)/$(DISTNAME).tar.bz2 \
+ $(DISTDIR)/$(DISTNAME).zip
+ @#RPM-src?
+ @#DEB-src?
+
+.PHONY: all clean distclean dist-src
diff --git a/README b/README
new file mode 100644
index 000000000..e69de29bb
diff --git a/common/sys.h b/common/sys.h
new file mode 100644
index 000000000..5fb28f7f0
--- /dev/null
+++ b/common/sys.h
@@ -0,0 +1,362 @@
+/* Residual - A 3D game interpreter
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/common/sys.h $
+ * $Id: sys.h 1648 2010-01-23 09:56:04Z aquadran $
+ *
+ */
+
+#ifndef COMMON_SYS_H
+#define COMMON_SYS_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <ctype.h>
+#include <math.h>
+
+#ifndef _MSC_VER
+#include <dirent.h>
+#include <unistd.h>
+#endif
+
+#ifdef _MSC_VER
+#pragma once
+#pragma warning( disable : 4068 ) // turn off "unknown pragma" warning
+#pragma warning( disable : 4100 ) // turn off "unreferenced formal parameter" warning
+#pragma warning( disable : 4127 ) // turn off "conditional expression is constant" warning
+#pragma warning( disable : 4189 ) // turn off "local variable is initialized but not referenced" warning
+#pragma warning( disable : 4244 ) // turn off "conversion type" warning
+#pragma warning( disable : 4250 ) // turn off "inherits via dominance" warning
+#pragma warning( disable : 4505 ) // turn off "unreferenced local function has been removed" warning
+#pragma warning( disable : 4512 ) // turn off "assignment operator could not be generated" warning
+#pragma warning( disable : 4611 ) // turn off "interaction between '_setjmp' and C++ object destruction is non-portable" warning
+#pragma warning( disable : 4800 ) // turn off "forcing value to bool 'true' or 'false' (performance warning)"
+#pragma warning( disable : 4996 ) // turn off "This function or variable may be unsafe" warning
+
+// vsnprintf is already defined in Visual Studio 2008
+#if (_MSC_VER < 1500)
+ #define vsnprintf _vsnprintf
+#endif
+
+#endif
+
+#ifndef LOCAL_PI
+#define LOCAL_PI 3.14159265358979323846
+#endif
+
+// Use config.h, generated by configure
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
+
+// In the following we configure various targets, in particular those
+// which can't use our "configure" tool and hence don't use config.h.
+//
+// Some #defines that occur here frequently:
+// SYSTEM_LITTLE_ENDIAN
+// - Define this on a little endian target
+// SYSTEM_BIG_ENDIAN
+// - Define this on a big endian target
+// SYSTEM_NEED_ALIGNMENT
+// - Define this if your system has problems reading e.g. an int32 from an odd address
+// SYSTEM_DONT_DEFINE_TYPES
+// - Define this if you need to provide your own typedefs, e.g. because your
+// system headers conflict with our typenames, or because you have odd
+// type requirements.
+// SMALL_SCREEN_DEVICE
+// - ...
+// ...
+
+// We define all types in config.h, so we don't want to typedef those types
+// here again!
+#ifdef HAVE_CONFIG_H
+#define SYSTEM_DONT_DEFINE_TYPES
+#endif
+
+
+//
+// By default we try to use pragma push/pop to ensure various structs we use
+// are "packed". If your compiler doesn't support this pragma, you are in for
+// a problem. If you are lucky, there is a compiler switch, or another pragma,
+// doing the same thing -- in that case, try to modify common/pack-begin.h and
+// common/pack-end.h accordingly. Or maybe your port simply *always* packs
+// everything, in which case you could #undefine SCUMMVM_USE_PRAGMA_PACK.
+//
+// If neither is possible, tough luck. Try to contact the team, maybe we can
+// come up with a solution, though I wouldn't hold my breath on it :-/.
+//
+#define SYSTEM_USE_PRAGMA_PACK
+
+
+#if defined(__SYMBIAN32__)
+
+ #define SYSTEM_LITTLE_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+ #define SMALL_SCREEN_DEVICE
+
+ // Enable Symbians own datatypes
+ // This is done for two reasons
+ // a) uint is already defined by Symbians libc component
+ // b) Symbian is using its "own" datatyping, and the Residual port
+ // should follow this to ensure the best compability possible.
+ #define SYSTEM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short int uint16;
+ typedef signed short int int16;
+
+ typedef unsigned long int uint32;
+ typedef signed long int int32;
+
+#elif defined(_WIN32_WCE)
+
+ #define strcasecmp stricmp
+ #define strncasecmp strnicmp
+ #define snprintf _snprintf
+
+ #define SYSTEM_LITTLE_ENDIAN
+
+ #ifndef __GNUC__
+ #define FORCEINLINE __forceinline
+ #define NORETURN_PRE __declspec(noreturn)
+ #endif
+ #define PLUGIN_EXPORT __declspec(dllexport)
+
+ #if _WIN32_WCE < 300
+ #define SMALL_SCREEN_DEVICE
+ #endif
+
+#elif defined(_MSC_VER)
+
+ #define strcasecmp stricmp
+ #define strncasecmp strnicmp
+ #define snprintf _snprintf
+
+ #define SYSTEM_LITTLE_ENDIAN
+
+ #define FORCEINLINE __forceinline
+ #define NORETURN_PRE __declspec(noreturn)
+ #define PLUGIN_EXPORT __declspec(dllexport)
+
+
+#elif defined(__MINGW32__)
+
+ #define strcasecmp stricmp
+ #define strncasecmp strnicmp
+
+ #define SYSTEM_LITTLE_ENDIAN
+
+ #define PLUGIN_EXPORT __declspec(dllexport)
+
+#elif defined(UNIX)
+
+ #ifndef CONFIG_H
+ /* need this for the SDL_BYTEORDER define */
+ #include <SDL_byteorder.h>
+
+ #if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ #define SCUMM_LITTLE_ENDIAN
+ #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
+ #define SCUMM_BIG_ENDIAN
+ #else
+ #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
+ #endif
+ #endif
+
+ // You need to set this manually if necessary
+// #define SYSTEM_NEED_ALIGNMENT
+
+ #if defined(__DECCXX) // Assume alpha architecture
+ #define INVERSE_MKID
+ #define SYSTEM_NEED_ALIGNMENT
+ #endif
+
+#elif defined(__PALMOS_TRAPS__) || defined (__PALMOS_ARMLET__)
+
+#ifdef __PALMOS_ARMLET__
+ #include <extras_string.h>
+#endif
+ #define SYSTEM_LITTLE_ENDIAN
+
+ #define strcasecmp stricmp
+ #define strncasecmp strnicmp
+
+ #define SYSTEM_NEED_ALIGNMENT
+ #define STRINGBUFLEN 256
+
+ extern const char *RESIDUAL_SAVEPATH;
+
+ #if !defined(COMPILE_ZODIAC) && !defined(COMPILE_OS5)
+ # define NEWGUI_256
+ #else
+ # undef UNUSED
+ #endif
+
+#elif defined(__DC__)
+
+ #define SYSTEM_LITTLE_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+#elif defined(__GP32__)
+
+ #define strcasecmp stricmp
+ #define strncasecmp strnicmp
+
+ #define SYSTEM_LITTLE_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+ // Override typenames. uint is already defined by system header files.
+ #define SYSTEM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short int uint16;
+ typedef signed short int int16;
+
+ typedef unsigned long int uint32;
+ typedef signed long int int32;
+
+#elif defined(__PLAYSTATION2__)
+
+ #define SYSTEM_LITTLE_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+#elif defined(__N64__)
+
+ #define SYSTEM_BIG_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+ #define STRINGBUFLEN 256
+
+ #define SYSTEM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short int uint16;
+ typedef signed short int int16;
+
+ typedef unsigned int uint32;
+ typedef signed int int32;
+
+ typedef unsigned long long uint64;
+ typedef signed long long int64;
+
+#elif defined(__PSP__)
+
+ #define SYSTEM_LITTLE_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+#elif defined(__amigaos4__)
+
+ #define SYSTEM_BIG_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+#elif defined (__DS__)
+
+ #define strcasecmp stricmp
+ #define strncasecmp strnicmp
+
+ #define SYSTEM_NEED_ALIGNMENT
+ #define SYSTEM_LITTLE_ENDIAN
+
+ #include "nds/jtypes.h"
+
+ #define SYSTEM_DONT_DEFINE_TYPES
+
+ #define STRINGBUFLEN 256
+ #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
+
+#elif defined(__WII__)
+
+ #define SYSTEM_BIG_ENDIAN
+ #define SYSTEM_NEED_ALIGNMENT
+
+#else
+ #error No system type defined
+
+#endif
+
+
+//
+// GCC specific stuff
+//
+#if defined(__GNUC__)
+ #define NORETURN __attribute__((__noreturn__))
+ #define PACKED_STRUCT __attribute__((packed))
+ #define GCC_PRINTF(x,y) __attribute__((format(printf, x, y)))
+#else
+ #define PACKED_STRUCT
+ #define GCC_PRINTF(x,y)
+#endif
+
+//
+// Fallbacks / default values for various special macros
+//
+#ifndef FORCEINLINE
+#define FORCEINLINE inline
+#endif
+
+#ifndef PLUGIN_EXPORT
+#define PLUGIN_EXPORT
+#endif
+
+#ifndef NORETURN_PRE
+#define NORETURN_PRE
+#endif
+
+#ifndef NORETURN_POST
+#define NORETURN_POST
+#endif
+
+#ifndef STRINGBUFLEN
+#define STRINGBUFLEN 1024
+#endif
+
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 256
+#endif
+
+
+//
+// Typedef our system types unless SYSTEM_DONT_DEFINE_TYPES is set.
+//
+#ifndef SYSTEM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+ typedef unsigned char uint8;
+ typedef signed char int8;
+ typedef unsigned short uint16;
+ typedef signed short int16;
+ typedef unsigned int uint32;
+ typedef signed int int32;
+ typedef unsigned int uint;
+#endif
+
+
+#endif // COMMON_SYS_H
diff --git a/config.guess b/config.guess
new file mode 100755
index 000000000..64cae2741
--- /dev/null
+++ b/config.guess
@@ -0,0 +1,1501 @@
+#! /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, 2009
+# Free Software Foundation, Inc.
+
+timestamp='2009-12-13'
+
+# 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 (context
+# diff format) to <config-patches at gnu.org> and include a 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.
+#
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+
+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 <config-patches at gnu.org>."
+
+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, 2009 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 at 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 -q __ELF__
+ 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 at 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:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
+ echo i386-pc-auroraux${UNAME_RELEASE}
+ 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 <stdio.h> /* 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 <sys/systemcfg.h>
+
+ 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 <stdlib.h>
+ #include <unistd.h>
+
+ 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 -q __LP64__
+ 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 <unistd.h>
+ 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*:*)
+ case ${UNAME_MACHINE} in
+ x86)
+ echo i586-pc-interix${UNAME_RELEASE}
+ exit ;;
+ authenticamd | genuineintel | EM64T)
+ 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 ;;
+ 8664:Windows_NT:*)
+ echo x86_64-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 ;;
+ 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 -q ld.so.1
+ if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
+ echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+ 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 ;;
+ i*86:Linux:*:*)
+ LIBC=gnu
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #ifdef __dietlibc__
+ LIBC=dietlibc
+ #endif
+EOF
+ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
+ echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+ 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:*:* | mips64:Linux:*:*)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #undef CPU
+ #undef ${UNAME_MACHINE}
+ #undef ${UNAME_MACHINE}el
+ #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+ CPU=${UNAME_MACHINE}el
+ #else
+ #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+ CPU=${UNAME_MACHINE}
+ #else
+ CPU=
+ #endif
+ #endif
+EOF
+ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
+ test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+ ;;
+ or32:Linux:*:*)
+ echo or32-unknown-linux-gnu
+ exit ;;
+ padre:Linux:*:*)
+ echo sparc-unknown-linux-gnu
+ exit ;;
+ parisc64:Linux:*:* | hppa64:Linux:*:*)
+ echo hppa64-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 ;;
+ ppc64:Linux:*:*)
+ echo powerpc64-unknown-linux-gnu
+ exit ;;
+ ppc:Linux:*:*)
+ echo powerpc-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: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.[02]*:*)
+ 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' </usr/options/cb.name`
+ echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+ elif /bin/uname -X 2>/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.[02]*:*)
+ 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 <Richard.M.Bartel at ccMail.Census.GOV>
+ echo i586-unisys-sysv4
+ exit ;;
+ *:UNIX_System_V:4*:FTX*)
+ # From Gerald Hewes <hewes at openmarket.com>.
+ # How about differentiating between stratus architectures? -djm
+ echo hppa1.1-stratus-sysv4
+ exit ;;
+ *:*:*:FTX*)
+ # From seanf at swdc.stratus.com.
+ echo i860-stratus-sysv4
+ exit ;;
+ i*86:VOS:*:*)
+ # From Paul.Green at stratus.com.
+ echo ${UNAME_MACHINE}-stratus-vos
+ exit ;;
+ *:VOS:*:*)
+ # From Paul.Green at 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
+ i386)
+ eval $set_cc_for_build
+ if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+ if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+ grep IS_64BIT_ARCH >/dev/null
+ then
+ UNAME_PROCESSOR="x86_64"
+ fi
+ fi ;;
+ 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 <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#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 <sys/param.h>
+ 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 <sys/param.h>
+# 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 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+and
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches at gnu.org> 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/config.sub b/config.sub
new file mode 100755
index 000000000..110a68e34
--- /dev/null
+++ b/config.sub
@@ -0,0 +1,1705 @@
+#! /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, 2009
+# Free Software Foundation, Inc.
+
+timestamp='2009-12-13'
+
+# 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 <config-patches at gnu.org>. Submit a context
+# diff and a properly formatted GNU 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.
+
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+# 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 <config-patches at gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 | -microblaze)
+ os=
+ basic_machine=$1
+ ;;
+ -bluegene*)
+ os=-cnk
+ ;;
+ -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 \
+ | rx \
+ | 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 \
+ | ubicom32 \
+ | v850 | v850e \
+ | we32k \
+ | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
+ | z8k | z80)
+ basic_machine=$basic_machine-unknown
+ ;;
+ m6811 | m68hc11 | m6812 | m68hc12 | picochip)
+ # 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-* | microblaze-* \
+ | 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-* | rx-* \
+ | 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-* \
+ | ubicom32-* \
+ | 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
+ ;;
+ bluegene*)
+ basic_machine=powerpc-ibm
+ os=-cnk
+ ;;
+ 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
+ ;;
+ microblaze)
+ basic_machine=microblaze-xilinx
+ ;;
+ 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.
+ -auroraux)
+ os=-auroraux
+ ;;
+ -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* | -cnk* | -sunos | -sunos[34]*\
+ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -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* | -es*)
+ # 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
+ ;;
+ -cnk*|-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/configure b/configure
new file mode 100755
index 000000000..3e793d665
--- /dev/null
+++ b/configure
@@ -0,0 +1,1165 @@
+#!/bin/sh
+#
+# configure -- custom configure script for Residual.
+#
+# Residual is the legal property of its developers, whose names
+# are too numerous to list here. Please refer to the AUTHORS
+# file distributed with this source distribution.
+#
+# 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.
+#
+# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/configure $
+# $Id: configure 1650 2010-01-24 08:26:36Z aquadran $
+
+# Save the current environment variables for next runs
+SAVED_CONFIGFLAGS=$@
+SAVED_LDFLAGS=$LDFLAGS
+SAVED_CXX=$CXX
+SAVED_CXXFLAGS=$CXXFLAGS
+SAVED_CPPFLAGS=$CPPFLAGS
+SAVED_ASFLAGS=$ASFLAGS
+SAVED_WINDRESFLAGS=$WINDRESFLAGS
+
+# Use environment vars if set
+CXXFLAGS="$CXXFLAGS $CPPFLAGS"
+
+# Backslashes into forward slashes:
+# The following OS/2 specific code is performed to deal with handling of backslashes by ksh.
+# Borrowed from the Sane configure script
+
+if test "$ac_emxsupport" != "no" -a "$ac_emxsupport" != "NO"; then
+ ac_save_IFS="$IFS"
+ IFS="\\"
+ ac_TEMP_PATH=
+ for ac_dir in $PATH; do
+ IFS=$ac_save_IFS
+ if test -z "$ac_TEMP_PATH"; then
+ ac_TEMP_PATH="$ac_dir"
+ else
+ ac_TEMP_PATH="$ac_TEMP_PATH/$ac_dir"
+ fi
+ done
+ PATH="$ac_TEMP_PATH"
+ export PATH
+ unset ac_TEMP_PATH
+fi
+
+set_var() {
+ eval ${1}='${2}'
+}
+
+get_var() {
+ eval echo \$${1}
+}
+
+#
+# Default settings
+#
+# Default lib behaviour yes/no/auto
+_vorbis=auto
+_tremor=auto
+_flac=auto
+_mad=auto
+# Default option behaviour yes/no
+_debug_build=auto
+_release_build=auto
+_endian=unknown
+_need_memalign=no
+_have_x86=no
+_verbose_build=no
+# Default commands
+_ranlib=ranlib
+_strip=strip
+_ar="ar cru"
+_as="as"
+_windres=windres
+_win32path="C:/residual-tools"
+_aos4path="Games:Residual-tools"
+_staticlibpath=/sw
+_prefix=/usr/local
+# For cross compiling
+_host=""
+_host_cpu=""
+_host_vendor=""
+_host_os=""
+_host_alias=""
+
+_srcdir=`dirname $0`
+_port_mk="ports.mk"
+
+# Determine a tmp file name, using mktemp(1) when available.
+if type mktemp > /dev/null 2>&1 ; then
+ TMPO=`mktemp /tmp/residual-conf.XXXXXXXXXX`
+else
+ TMPO=./residual-conf
+fi
+TMPC=${TMPO}.cpp
+TMPLOG=config.log
+
+cc_check() {
+ echo >> "$TMPLOG"
+ cat "$TMPC" >> "$TMPLOG"
+ echo >> "$TMPLOG"
+ echo "$CXX $TMPC -o $TMPO$HOSTEXEEXT $@" >> "$TMPLOG"
+ rm -f "$TMPO$HOSTEXEEXT"
+ ( $CXX $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
+ TMP="$?"
+ echo >> "$TMPLOG"
+ return "$TMP"
+}
+
+#
+# Function to provide echo -n for bourne shells that don't have it
+#
+echo_n() {
+ printf "$@"
+}
+
+echocheck() {
+ echo_n "Checking for $@... "
+}
+
+# Add a line of data to config.mk.
+add_line_to_config_mk() {
+ _config_mk_data="$_config_mk_data"'
+'"$1"
+}
+
+# Add a line of data to config.h.
+add_line_to_config_h() {
+ _config_h_data="$_config_h_data"'
+'"$1"
+}
+
+add_to_config_h_if_yes() {
+ if test "$1" = yes ; then
+ add_line_to_config_h "$2"
+ else
+ add_line_to_config_h "/* $2 */"
+ fi
+}
+
+# Conditionally add a line of data to config.mk. Takes two parameters:
+# The first one can be set to 'no' to "comment out" the line, i.e.
+# make it ineffective, use 'yes' otherwise.
+# The second param is the line to insert.
+add_to_config_mk_if_yes() {
+ if test "$1" = yes ; then
+ add_line_to_config_mk "$2"
+ else
+ add_line_to_config_mk "# $2"
+ fi
+}
+
+# Conditionally add a line of data to config.mk. Takes two parameters:
+# The first one can be set to 'yes' to "comment out" the line, i.e.
+# make it ineffective, use 'no' otherwise.
+# The second param is the line to insert.
+add_to_config_mk_if_no() {
+ if test "$1" = no ; then
+ add_line_to_config_mk "$2"
+ else
+ add_line_to_config_mk "# $2"
+ fi
+}
+
+#
+# Determine extension used for executables
+#
+get_system_exe_extension() {
+ case $1 in
+ mingw* | *os2-emx | wince)
+ _exeext=".exe"
+ ;;
+ arm-riscos)
+ _exeext=",ff8"
+ ;;
+ gp2xwiz-linux)
+ _exeext=".wiz"
+ ;;
+ gp2x-linux)
+ _exeext=".gp2x"
+ ;;
+ dreamcast | wii | gamecube | nds | psp | ps2)
+ _exeext=".elf"
+ ;;
+ *)
+ _exeext=""
+ ;;
+ esac
+}
+
+#
+# Generic options functions
+#
+
+# Show the configure help line for an option
+option_help() {
+ tmpopt=`echo $1 | sed 's/_/-/g'`
+ option=`echo "--${tmpopt} " | sed "s/\(.\{23\}\).*/\1/"`
+ echo " ${option} ${2}"
+}
+
+# Show an error about an unknown option
+option_error() {
+ echo "error: unrecognised option: $ac_option
+Try \`$0 --help' for more information." >&2
+ exit 1
+}
+
+#
+# Greet user
+#
+echo "Running Tools configure..."
+echo "Configure run on" `date` > $TMPLOG
+
+#
+# Check any parameters we received
+#
+
+for parm in "$@" ; do
+ if test "$parm" = "--help" || test "$parm" = "-help" || test "$parm" = "-h" ; then
+ for engine in $_engines; do
+ if test `get_engine_sub $engine` = no ; then
+ engines_help="$engines_help`show_engine_help $engine`
+"
+ fi
+ done
+ cat << EOF
+
+Usage: $0 [OPTIONS]...
+
+Configuration:
+ -h, --help display this help and exit
+
+Installation directories:
+ --prefix=DIR use this prefix for installing Residual [/usr/local]
+ --bindir=DIR directory to install the residual binary in [PREFIX/bin]
+ --mandir=DIR directory to install the manpage in [PREFIX/share/man]
+ --datadir=DIR directory to install the data files in [PREFIX/share]
+ --libdir=DIR directory to install the plugins in [PREFIX/lib]
+
+Special configuration feature:
+ --host=HOST cross-compile to target HOST (arm-linux, ...)
+
+Optional Features:
+ --disable-debug disable building with debugging symbols
+ --enable-Werror treat warnings as errors
+ --enable-profiling enable building with gprof profile information
+ --enable-release set flags to build release binary
+ --enable-verbose-build enable regular echoing of commands during build process
+
+Optional Libraries:
+ --with-ogg-prefix=DIR Prefix where libogg is installed (optional)
+ --with-vorbis-prefix=DIR Prefix where libvorbis is installed (optional)
+ --disable-vorbis disable Ogg Vorbis support [autodetect]
+
+ --with-tremor-prefix=DIR Prefix where tremor is installed (optional)
+ --disable-tremor disable tremor support [autodetect]
+
+ --with-mad-prefix=DIR Prefix where libmad is installed (optional)
+ --disable-mad disable libmad (MP3) support [autodetect]
+
+ --with-flac-prefix=DIR Prefix where libFLAC is installed (optional)
+ --disable-flac disable FLAC support [autodetect]
+
+ --with-zlib-prefix=DIR Prefix where zlib is installed (optional)
+
+Some influential environment variables:
+ LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
+ nonstandard directory <lib dir>
+ CXX C++ compiler command
+ CXXFLAGS C++ compiler flags
+ CPPFLAGS C++ preprocessor flags, e.g. -I<include dir> if you have
+ headers in a nonstandard directory <include dir>
+ ASFLAGS assembler flags
+ WINDRESFLAGS Windows resource compiler flags
+
+EOF
+ exit 0
+ fi
+done # for parm in ...
+
+DEBFLAGS="-g"
+
+for ac_option in $@; do
+ case "$ac_option" in
+ --enable-vorbis) _vorbis=yes ;;
+ --disable-vorbis) _vorbis=no ;;
+ --enable-tremor) _tremor=yes ;;
+ --disable-tremor) _tremor=no ;;
+ --enable-flac) _flac=yes ;;
+ --disable-flac) _flac=no ;;
+ --enable-mad) _mad=yes ;;
+ --disable-mad) _mad=no ;;
+
+ --with-ogg-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ OGG_CFLAGS="-I$arg/include"
+ OGG_LIBS="-L$arg/lib"
+ ;;
+ --with-vorbis-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ VORBIS_CFLAGS="-I$arg/include"
+ VORBIS_LIBS="-L$arg/lib"
+ ;;
+ --with-tremor-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ TREMOR_CFLAGS="-I$arg/include"
+ TREMOR_LIBS="-L$arg/lib"
+ ;;
+ --with-flac-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ FLAC_CFLAGS="-I$arg/include"
+ FLAC_LIBS="-L$arg/lib"
+ ;;
+ --with-mad-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ MAD_CFLAGS="-I$arg/include"
+ MAD_LIBS="-L$arg/lib"
+ ;;
+ --with-zlib-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ ZLIB_CFLAGS="-I$arg/include"
+ ZLIB_LIBS="-L$arg/lib"
+ ;;
+ --enable-debug)
+ # debug is enabled by default
+ ;;
+ --disable-debug)
+ DEBFLAGS=""
+ ;;
+ --enable-Werror)
+ CXXFLAGS="$CXXFLAGS -Werror"
+ ;;
+ --enable-release)
+ DEBFLAGS="-O2 -Wuninitialized"
+ ;;
+ --enable-profiling)
+ CXXFLAGS="$CXXFLAGS -pg"
+ LDFLAGS="$LDFLAGS -pg"
+ ;;
+ --with-staticlib-prefix=*)
+ _staticlibpath=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --host=*)
+ _host=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --prefix=*)
+ _prefix=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --bindir=*)
+ _bindir=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --mandir=*)
+ _mandir=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --datadir=*)
+ _datadir=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --libdir=*)
+ _libdir=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --enable-*)
+ engine_enable `echo $ac_option | cut -d '-' -f 4-`
+ ;;
+ --disable-*)
+ engine_disable `echo $ac_option | cut -d '-' -f 4-`
+ ;;
+ *)
+ option_error
+ ;;
+ esac;
+done;
+
+CXXFLAGS="$CXXFLAGS $DEBFLAGS"
+
+guessed_host=`$_srcdir/config.guess`
+get_system_exe_extension $guessed_host
+NATIVEEXEEXT=$_exeext
+
+case $_host in
+i586-mingw32msvc)
+ _host_os=mingw32msvc
+ _host_cpu=i586
+ ;;
+*)
+ if test -n "$_host"; then
+ guessed_host=`$_srcdir/config.sub $_host`
+ fi
+ _host_cpu=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+ _host_vendor=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+ _host_os=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+ ;;
+esac
+
+if test -z "$_host_alias"; then
+ _host_alias="$_host_cpu-$_host_os"
+else
+ # if _host_alias was set, default to the standard GNU tools
+ _ranlib=$_host_alias-ranlib
+ _strip=$_host_alias-strip
+ _ar="$_host_alias-ar cru"
+ _as="$_host_alias-as"
+ _windres=$_host_alias-windres
+fi
+
+#
+# Determine extension used for executables
+#
+get_system_exe_extension $_host_os
+HOSTEXEEXT=$_exeext
+
+#
+# Determine separator used for $PATH
+#
+case $_host_os in
+os2-emx* )
+ SEPARATOR=";"
+ ;;
+* )
+ SEPARATOR=":"
+ ;;
+esac
+
+#
+# Platform specific sanity checks
+#
+case $_host_os in
+*)
+ ;;
+esac
+
+#
+# Determine the C++ compiler
+#
+echo_n "Looking for C++ compiler... "
+
+# Check whether the given command is a working C++ compiler
+test_compiler() {
+ cat <<EOF >tmp_cxx_compiler.cpp
+ class Foo { int a; };
+ int main(int argc, char **argv) {
+ Foo *a = new Foo(); delete a; return 0;
+ }
+EOF
+
+ if test -n "$_host"; then
+ # In cross-compiling mode, we cannot run the result
+ eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$HOSTEXEEXT -c tmp_cxx_compiler.cpp" 2> /dev/null && rm -f tmp_cxx_compiler$HOSTEXEEXT tmp_cxx_compiler.cpp
+ else
+ eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$HOSTEXEEXT tmp_cxx_compiler.cpp" 2> /dev/null && eval "./tmp_cxx_compiler$HOSTEXEEXT 2> /dev/null" && rm -rf tmp_cxx_compiler$HOSTEXEEXT tmp_cxx_compiler.dSYM tmp_cxx_compiler.cpp
+ fi
+}
+
+# Prepare a list of candidates for the C++ compiler
+if test -n "$CXX" && test_compiler "$CXX"; then
+ # Use the compiler specified in CXX
+ echo $CXX
+else
+ if test -n "$_host"; then
+ compilers="$_host_alias-g++ $_host_alias-c++ $_host-g++ $_host-c++"
+ else
+ compilers="g++ c++"
+ fi
+
+ # Iterate over all candidates, pick the first working one
+ CXX=
+ for compiler in $compilers; do
+ if test_compiler $compiler; then
+ CXX=$compiler
+ echo $CXX
+ break
+ fi
+ done
+fi
+
+if test -z "$CXX"; then
+ echo "none found!"
+ exit 1
+fi
+
+# By default, use the C++ compiler as linker
+LD=$CXX
+
+#
+# Determine the compiler version
+#
+echocheck "compiler version"
+
+have_gcc=no
+cxx_version=`( $CXX -dumpversion ) 2>&1`
+if test "$?" -gt 0; then
+ # TODO: Big scary warning about unsupported Compilers
+ cxx_version=`( $CXX -version ) 2>&1`
+ if test "$?" -eq 0; then
+ cxx_version="`echo "${cxx_version}" | sed -ne 's/^.*[^0-9]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/gp'`"
+ if test -z "${cxx_version}"; then
+ cxx_version="not found"
+ cxx_verc_fail=yes
+ fi
+ echo non-gcc compiler version ${cxx_version}
+ else
+ cxx_version="not found"
+ cxx_verc_fail=yes
+ echo found non-gcc compiler version ${cxx_version}
+ fi
+else
+ add_line_to_config_mk 'HAVE_GCC = 1'
+ have_gcc=yes
+fi
+
+if test "$have_gcc" = yes; then
+ case $cxx_version in
+ 2.95.[2-9]|2.95.[2-9][-.]*|3.[0-9]|3.[0-9].[0-9]|3.[0-9].[0-9][-.]*|4.[0-9]|4.[0-9].[0-9]|4.[0-9].[0-9][-.]*)
+ _cxx_major=`echo $cxx_version | cut -d '.' -f 1`
+ _cxx_minor=`echo $cxx_version | cut -d '.' -f 2`
+ cxx_version="$cxx_version, ok"
+ cxx_verc_fail=no
+ ;;
+ # whacky beos version strings
+ 2.9-beos-991026*|2.9-beos-000224*)
+ _cxx_major=2
+ _cxx_minor=95
+ cxx_version="$cxx_version, ok"
+ cxx_verc_fail=no
+ ;;
+ 3_4)
+ _cxx_major=3
+ _cxx_minor=4
+ ;;
+ 'not found')
+ cxx_verc_fail=yes
+ ;;
+ *)
+ cxx_version="$cxx_version, bad"
+ cxx_verc_fail=yes
+ ;;
+ esac
+else
+ case $_host_os in
+ irix*)
+ case $cxx_version in
+ 7.4.4*)
+ # We just assume this is SGI MipsPRO
+ _cxx_major=7
+ _cxx_minor=4
+ add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MDupdate "$(*D)/$(DEPDIR)/$(*F).d"'
+ add_line_to_config_mk '-include Makedepend'
+ ;;
+ *)
+ cxx_version="$cxx_version, bad"
+ cxx_verc_fail=yes
+ ;;
+ esac
+ ;;
+ *)
+ cxx_version="$cxx_version, bad"
+ cxx_verc_fail=yes
+ ;;
+ esac
+
+fi
+
+echo "$cxx_version"
+
+if test "$cxx_verc_fail" = yes ; then
+ echo
+ echo "The version of your compiler is not supported at this time"
+ echo "Please ensure you are using GCC >= 2.95"
+ exit 1
+fi
+
+#
+# Check for endianness
+#
+echo_n "Checking endianness... "
+cat <<EOF >tmp_endianness_check.cpp
+short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+void _ascii() { char* s = (char*) ascii_mm; s = (char*) ascii_ii; }
+short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*) ebcdic_ii; }
+int main() { _ascii (); _ebcdic (); return 0; }
+EOF
+$CXX $CXXFLAGS -c -o tmp_endianness_check.o tmp_endianness_check.cpp
+if strings tmp_endianness_check.o | grep BIGenDianSyS >/dev/null; then
+ _endian=big
+else
+ _endian=little
+fi
+echo $_endian;
+rm -f tmp_endianness_check.o tmp_endianness_check.cpp
+
+#
+# Determine a data type with the given length
+#
+find_type_with_size() {
+ for datatype in int short char long 'long long' unknown; do
+ cat <<EOF >tmp_find_type_with_size.cpp
+typedef $datatype ac__type_sizeof_;
+int main() {
+ static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) == $1)];
+ test_array [0] = 0;
+ return 0;
+}
+EOF
+if $CXX $CXXFLAGS -c -o tmp_find_type_with_size$HOSTEXEEXT tmp_find_type_with_size.cpp 2>/dev/null ; then
+ break
+else
+ if test "$datatype" = "unknown"; then
+ echo "couldn't find data type with $1 bytes"
+ exit 1
+ fi
+ continue
+fi
+done
+rm -f tmp_find_type_with_size$HOSTEXEEXT tmp_find_type_with_size.cpp
+echo $datatype
+}
+
+#
+# Determine a size of pointer type
+#
+find_pointer_size() {
+ cat <<EOF >tmp_find_pointer_size.cpp
+int main() {
+ void *p;
+ int v = (int)p;
+ return 0;
+}
+EOF
+ $CXX $CXXFLAGS -c -o tmp_find_pointer_size$HOSTEXEEXT tmp_find_pointer_size.cpp 2>/dev/null
+ status=$?
+ rm -f tmp_find_pointer_size$HOSTEXEEXT tmp_find_pointer_size.cpp
+ return $status
+}
+
+#
+# Determine data type sizes
+#
+echo_n "Type with 1 byte... "
+type_1_byte=`find_type_with_size 1`
+TMP="$?"
+echo "$type_1_byte"
+test $TMP -eq 0 || exit 1 # check exit code of subshell
+
+echo_n "Type with 2 bytes... "
+type_2_byte=`find_type_with_size 2`
+TMP="$?"
+echo "$type_2_byte"
+test $TMP -eq 0 || exit 1 # check exit code of subshell
+
+echo_n "Type with 4 bytes... "
+type_4_byte=`find_type_with_size 4`
+TMP="$?"
+echo "$type_4_byte"
+test $TMP -eq 0 || exit 1 # check exit code of subshell
+
+echo_n "Type with 8 bytes... "
+type_8_byte=`find_type_with_size 8`
+TMP="$?"
+echo "$type_8_byte"
+if test $TMP -eq 0; then
+ _def_64bit_type_signed="typedef signed $type_8_byte int64;"
+ _def_64bit_type_unsigned="typedef unsigned $type_8_byte uint64;"
+fi
+
+echo_n "Target 64 bits... "
+find_pointer_size
+if test $? -eq 0; then
+ echo "no"
+ add_line_to_config_h "/* #define TARGET_64BITS */"
+else
+ echo "yes"
+ add_line_to_config_h "#define TARGET_64BITS"
+fi
+
+#
+# Check whether we can use x86 asm routines
+#
+echo_n "Compiling for x86... "
+case $_host_cpu in
+ i386|i486|i586|i686|x86_64)
+ _have_x86=yes
+ ;;
+ *)
+ _have_x86=no
+ ;;
+esac
+echo "$_have_x86"
+
+#
+# Determine build settings
+#
+echo_n "Checking hosttype... "
+echo $_host_os
+case $_host_os in
+ linux* | uclinux*)
+ # When not cross-compiling, enable large file support, but don't
+ # care if getconf doesn't exist or doesn't recognize LFS_CFLAGS.
+ if test -z "$_host"; then
+ CXXFLAGS="$CXXFLAGS $(getconf LFS_CFLAGS 2>/dev/null)"
+ fi
+ DEFINES="$DEFINES -DUNIX"
+ ;;
+ openbsd* | netbsd* | bsd* | sunos* | hpux*)
+ DEFINES="$DEFINES -DUNIX"
+
+ ;;
+ freebsd*)
+ DEFINES="$DEFINES -DUNIX"
+ LDFLAGS="$LDFLAGS -L/usr/local/lib"
+ CXXFLAGS="$CXXFLAGS -I/usr/local/include"
+ ;;
+ beos*)
+ DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ # Needs -lbind -lsocket for the timidity MIDI driver
+ LDFLAGS="-L/boot/home/config/lib"
+ CFLAGS="-I/boot/home/config/include"
+ CXXFLAGS="$CXXFLAGS -fhuge-objects"
+ # FIXME: Please document why 'long' has to be used instead of int
+ #type_4_byte='long'
+ ;;
+ solaris*)
+ DEFINES="$DEFINES -DUNIX -DSOLARIS -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ # Needs -lbind -lsocket for the timidity MIDI driver
+ LIBS="$LIBS -lnsl -lsocket"
+ ;;
+ irix*)
+ DEFINES="$DEFINES -DUNIX -DIRIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ LIBS="$LIBS -lmd -lfastm -lm"
+ _ranlib=:
+ ;;
+ darwin*)
+ DEFINES="$DEFINES -DUNIX -DMACOSX"
+ add_line_to_config_mk 'MACOSX = 1'
+ ;;
+ mingw*)
+ DEFINES="$DEFINES -DWIN32 -D__USE_MINGW_ANSI_STDIO=0"
+ LIBS="$LIBS -lmingw32 -lwinmm"
+ OBJS="$OBJS residualico.o"
+ ;;
+ cygwin*)
+ echo ERROR: Cygwin building is not supported by ScummVM anymore. Consider using MinGW.
+ exit 1
+ ;;
+ os2-emx*)
+ DEFINES="$DEFINES -DUNIX"
+ ;;
+ mint*)
+ DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ ;;
+ amigaos*)
+ CXXFLAGS="$CXXFLAGS -mcrt=newlib -mstrict-align -mcpu=750 -mtune=7400"
+ LDFLAGS="$LDFLAGS -mcrt=newlib -use-dynld -Lsobjs:"
+ # We have to use 'long' for our 4 byte typedef because AmigaOS already typedefs (u)int32
+ # as (unsigned) long, and consequently we'd get a compiler error otherwise.
+ type_4_byte='long'
+ ;;
+ # given this is a shell script assume some type of unix
+ *)
+ echo "WARNING: could not establish system type, assuming unix like"
+ DEFINES="$DEFINES -DUNIX"
+ ;;
+esac
+
+if test -n "$_host"; then
+ # Cross-compiling mode - add your target here if needed
+ echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes"
+ case "$_host" in
+ arm-linux|arm*-linux-gnueabi|arm-*-linux|*-angstrom-linux)
+ DEFINES="$DEFINES -DUNIX"
+ _need_memalign=yes
+ ;;
+ *darwin*)
+ _ranlib=$_host-ranlib
+ _strip=$_host-strip
+ ;;
+ ppc-amigaos)
+ _endian=big
+ _need_memalign=yes
+ # FIXME: Please document why 'long' has to be used instead of int
+ #type_4_byte='long'
+ ;;
+ m68k-atari-mint)
+ DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ _endian=big
+ _need_memalign=yes
+ # FIXME: Please document why 'long' has to be used instead of int
+ #type_4_byte='long'
+ _ranlib=m68k-atari-mint-ranlib
+ _ar="m68k-atari-mint-ar cru"
+ ;;
+ *mingw32*)
+ _windres=$_host-windres
+ _ar="$_host-ar cru"
+ _ranlib=$_host-ranlib
+ ;;
+ *)
+ echo "WARNING: Unknown target, continuing with auto-detected values"
+ ;;
+ esac
+
+else
+ #
+ # Check whether memory alignment is required
+ #
+ echo_n "Alignment required... "
+ case $_host_cpu in
+ arm*)
+ _need_memalign=yes
+ ;;
+ alpha*)
+ # Hardcode alignment requirements for Alpha processsors
+ _need_memalign=yes
+ ;;
+ sh*)
+ # Hardcode alignment requirements for SH processsors.
+ # While these can emulate unaligned memory access, this
+ # emulation is rather slow.
+ _need_memalign=yes
+ ;;
+ mips*)
+ # Hardcode alignment requirements for MIPS processsors.
+ # While these can emulate unaligned memory access, this
+ # emulation is rather slow.
+ _need_memalign=yes
+ ;;
+ *)
+ # Try to auto-detect....
+ cat > $TMPC << EOF
+#include <stdlib.h>
+#include <signal.h>
+int main(int argc, char **argv) {
+ unsigned char test[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
+ signal(SIGBUS, exit);
+ signal(SIGABRT, exit);
+ signal(SIGSEGV, exit);
+ if (*((unsigned int *)(test + 1)) != 0x55443322 && *((unsigned int *)(test + 1)) != 0x22334455) {
+ return 1;
+ }
+ return 0;
+}
+EOF
+ _need_memalign=yes
+ cc_check && $TMPO$HOSTEXEEXT && _need_memalign=no
+ ;;
+ esac
+ echo "$_need_memalign"
+fi
+
+#
+# Add the results of the above checks to config.h
+#
+case $_endian in
+ big)
+ add_line_to_config_h '/* #define SYSTEM_LITTLE_ENDIAN */'
+ add_line_to_config_h '#define SYSTEM_BIG_ENDIAN'
+ ;;
+ little)
+ add_line_to_config_h '#define SYSTEM_LITTLE_ENDIAN'
+ add_line_to_config_h '/* #define SYSTEM_BIG_ENDIAN */'
+ ;;
+ *)
+ exit 1
+ ;;
+esac
+
+add_to_config_h_if_yes $_have_x86 '#define HAVE_X86'
+
+add_to_config_h_if_yes $_need_memalign '#define SYSTEM_NEED_ALIGNMENT'
+
+#
+# Check whether to enable a verbose build
+#
+echo_n "Checking whether to have a verbose build... "
+echo "$_verbose_build"
+add_to_config_mk_if_yes "$_verbose_build" 'VERBOSE_BUILD = 1'
+
+#
+# Check for math lib
+#
+cat > $TMPC << EOF
+int main(void) { return 0; }
+EOF
+cc_check $LDFLAGS $CXXFLAGS -lm && LDFLAGS="$LDFLAGS -lm"
+
+#
+# Check for Ogg Vorbis
+#
+echocheck "Ogg Vorbis"
+if test "$_vorbis" = auto ; then
+ _vorbis=no
+ cat > $TMPC << EOF
+#include <vorbis/codec.h>
+int main(void) { vorbis_packet_blocksize(0,0); return 0; }
+EOF
+ cc_check $LDFLAGS $CXXFLAGS $OGG_CFLAGS $OGG_LIBS $VORBIS_CFLAGS $VORBIS_LIBS \
+ -lvorbisfile -lvorbis -logg && _vorbis=yes
+fi
+if test "$_vorbis" = yes ; then
+ _def_vorbis='#define USE_VORBIS'
+ LIBS="$LIBS $OGG_LIBS $VORBIS_LIBS -lvorbisfile -lvorbis -logg"
+ INCLUDES="$INCLUDES $OGG_CFLAGS $VORBIS_CFLAGS"
+else
+ _def_vorbis='#undef USE_VORBIS'
+fi
+add_to_config_mk_if_yes "$_vorbis" 'USE_VORBIS = 1'
+echo "$_vorbis"
+
+#
+# Check for Tremor
+#
+echocheck "Tremor"
+if test "$_tremor" = auto ; then
+ _tremor=no
+ cat > $TMPC << EOF
+#include <tremor/ivorbiscodec.h>
+int main(void) { vorbis_info_init(0); return 0; }
+EOF
+ cc_check $LDFLAGS $CXXFLAGS $TREMOR_CFLAGS $TREMOR_LIBS -lvorbisidec && \
+ _tremor=yes
+fi
+if test "$_tremor" = yes && test "$_vorbis" = no; then
+ _def_tremor='#define USE_TREMOR'
+ _def_vorbis='#define USE_VORBIS'
+ LIBS="$LIBS $TREMOR_LIBS -lvorbisidec"
+ INCLUDES="$INCLUDES $TREMOR_CFLAGS"
+else
+ if test "$_vorbis" = yes; then
+ _tremor="no (Ogg Vorbis/Tremor support is mutually exclusive)"
+ fi
+ _def_tremor='#undef USE_TREMOR'
+fi
+add_to_config_mk_if_yes "$_tremor" 'USE_TREMOR = 1'
+echo "$_tremor"
+
+#
+# Check for FLAC
+#
+echocheck "FLAC >= 1.0.1"
+if test "$_flac" = auto ; then
+ _flac=no
+ cat > $TMPC << EOF
+#include <FLAC/format.h>
+int main(void) { return FLAC__STREAM_SYNC_LEN >> 30; /* guaranteed to be 0 */ }
+EOF
+ if test "$_vorbis" = yes ; then
+ cc_check $LDFLAGS $CXXFLAGS $FLAC_CFLAGS $FLAC_LIBS $OGG_CFLAGS $OGG_LIBS \
+ -lFLAC -logg && _flac=yes
+ else
+ cc_check $LDFLAGS $CXXFLAGS $FLAC_CFLAGS $FLAC_LIBS \
+ -lFLAC && _flac=yes
+ fi
+fi
+if test "$_flac" = yes ; then
+ _def_flac='#define USE_FLAC'
+ if test "$_vorbis" = yes ; then
+ LIBS="$LIBS $FLAC_LIBS $OGG_LIBS -lFLAC -logg"
+ else
+ LIBS="$LIBS $FLAC_LIBS -lFLAC"
+ fi
+ INCLUDES="$INCLUDES $FLAC_CFLAGS"
+else
+ _def_flac='#undef USE_FLAC'
+fi
+add_to_config_mk_if_yes "$_flac" 'USE_FLAC = 1'
+echo "$_flac"
+
+#
+# Check for MAD (MP3 library)
+#
+echocheck "MAD"
+if test "$_mad" = auto ; then
+ _mad=no
+ cat > $TMPC << EOF
+#include <mad.h>
+int main(void) { return 0; }
+EOF
+ cc_check $LDFLAGS $CXXFLAGS $MAD_CFLAGS $MAD_LIBS -lmad && _mad=yes
+fi
+if test "$_mad" = yes ; then
+ _def_mad='#define USE_MAD'
+ LIBS="$LIBS $MAD_LIBS -lmad"
+ INCLUDES="$INCLUDES $MAD_CFLAGS"
+else
+ _def_mad='#undef USE_MAD'
+fi
+add_to_config_mk_if_yes "$_mad" 'USE_MAD = 1'
+echo "$_mad"
+
+#
+# Check for ZLib
+#
+echocheck "zlib"
+_zlib=no
+
+cat > $TMPC << EOF
+#include <string.h>
+#include <zlib.h>
+int main(void) { return strcmp(ZLIB_VERSION, zlibVersion()); }
+EOF
+
+cc_check $LDFLAGS $CXXFLAGS $ZLIB_CFLAGS $ZLIB_LIBS -lz && _zlib=yes
+
+if test "$_zlib" = yes ; then
+ _def_zlib='#define USE_ZLIB'
+ LIBS="$LIBS $ZLIB_LIBS -lz"
+ INCLUDES="$INCLUDES $ZLIB_CFLAGS"
+else
+ echo
+ echo "zlib library support required"
+ exit 1
+fi
+add_to_config_mk_if_yes "$_zlib" 'USE_ZLIB = 1'
+echo "$_zlib"
+
+#
+# Figure out installation directories
+#
+test -z "$_bindir" && _bindir="$_prefix/bin"
+test -z "$_mandir" && _mandir="$_prefix/share/man"
+test -z "$_datadir" && _datadir="$_prefix/share"
+test -z "$_libdir" && _libdir="$_prefix/lib"
+
+
+#
+# Do CXXFLAGS now that we know the compiler version
+#
+if test "$have_gcc" = yes ; then
+ if test "$_cxx_major" -ge "3" ; then
+ case $_host_os in
+ # newlib-based system include files suppress non-C89 function
+ # declarations under __STRICT_ANSI__
+ mingw* | dreamcast | wii | gamecube | psp | wince | amigaos*)
+ CXXFLAGS="$CXXFLAGS -W -Wno-unused-parameter"
+ ;;
+ *)
+ CXXFLAGS="$CXXFLAGS -ansi -W -Wno-unused-parameter"
+ ;;
+ esac
+ add_line_to_config_mk 'HAVE_GCC3 = 1'
+ add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP'
+ fi;
+
+ if test "$_cxx_major" -ge "4" && test "$_cxx_minor" -ge "3" ; then
+ CXXFLAGS="$CXXFLAGS -Wno-empty-body"
+ else
+ CXXFLAGS="$CXXFLAGS -Wconversion"
+ fi;
+fi;
+
+echo
+echo "Creating config.h"
+cat > config.h << EOF
+/* This file is automatically generated by configure */
+/* DO NOT EDIT MANUALLY */
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+$_config_h_data
+
+/* Data types */
+typedef unsigned $type_1_byte byte;
+typedef unsigned int uint;
+typedef unsigned $type_1_byte uint8;
+typedef unsigned $type_2_byte uint16;
+typedef unsigned $type_4_byte uint32;
+$_def_64bit_type_signed
+typedef signed $type_1_byte int8;
+typedef signed $type_2_byte int16;
+typedef signed $type_4_byte int32;
+$_def_64bit_type_unsigned
+
+/* Libs */
+$_def_vorbis
+$_def_tremor
+$_def_flac
+$_def_mad
+$_def_zlib
+
+#endif /* CONFIG_H */
+EOF
+
+echo "Creating config.mk"
+cat > config.mk << EOF
+# -------- Generated by configure -----------
+
+CXX := $CXX
+CXXFLAGS := $CXXFLAGS
+LD := $LD
+LIBS += $LIBS
+RANLIB := $_ranlib
+STRIP := $_strip
+AR := $_ar
+AS := $_as
+ASFLAGS := $ASFLAGS
+WINDRES := $_windres
+WINDRESFLAGS := $WINDRESFLAGS
+WIN32PATH=$_win32path
+AOS4PATH=$_aos4path
+STATICLIBPATH=$_staticlibpath
+
+MODULES += $MODULES
+MODULE_DIRS += $MODULE_DIRS
+EXEEXT := $HOSTEXEEXT
+
+PREFIX := $_prefix
+BINDIR := $_bindir
+MANDIR := $_mandir
+DATADIR := $_datadir
+LIBDIR := $_libdir
+
+INCLUDES += $INCLUDES
+OBJS += $OBJS
+DEFINES += $DEFINES
+LDFLAGS += $LDFLAGS
+
+port_mk = $_port_mk
+
+SAVED_CONFIGFLAGS := $SAVED_CONFIGFLAGS
+SAVED_LDFLAGS := $SAVED_LDFLAGS
+SAVED_CXX := $SAVED_CXX
+SAVED_CXXFLAGS := $SAVED_CXXFLAGS
+SAVED_CPPFLAGS := $SAVED_CPPFLAGS
+SAVED_ASFLAGS := $SAVED_ASFLAGS
+SAVED_WINDRESFLAGS := $SAVED_WINDRESFLAGS
+EOF
+
+#
+# Create a custom Makefile when building outside the source tree
+# TODO: Add a better check than just looking for 'Makefile'
+#
+if test ! -f Makefile.common ; then
+echo "Creating Makefile"
+
+cat > Makefile << EOF
+# -------- Generated by configure -----------
+srcdir = $_srcdir
+vpath %.h \$(srcdir)
+vpath %.cpp \$(srcdir)
+vpath %.c \$(srcdir)
+vpath %.m \$(srcdir)
+vpath %.mm \$(srcdir)
+vpath %.asm \$(srcdir)
+vpath %.s \$(srcdir)
+vpath %.S \$(srcdir)
+include \$(srcdir)/Makefile
+EOF
+
+fi
diff --git a/ports.mk b/ports.mk
new file mode 100644
index 000000000..b22534118
--- /dev/null
+++ b/ports.mk
@@ -0,0 +1,33 @@
+# This file contains port specific Makefile rules. It is automatically
+# included by the default (main) Makefile.
+#
+# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/ports.mk $
+# $Id: ports.mk 1635 2010-01-21 19:25:03Z aquadran $
+
+
+#
+# UNIX specific
+#
+install: all
+ $(INSTALL) -d "$(DESTDIR)$(BINDIR)"
+ $(INSTALL) -c -s -m 755 "./$(EXECUTABLE)" "$(DESTDIR)$(BINDIR)/$(EXECUTABLE)"
+ $(INSTALL) -d "$(DESTDIR)$(PREFIX)/share/doc/residual-tools/"
+ $(INSTALL) -c -m 644 $(DIST_FILES_DOCS) "$(DESTDIR)$(PREFIX)/share/doc/residual-tools/"
+ $(INSTALL) -d "$(DESTDIR)$(DATADIR)/residual-tools/"
+ $(INSTALL) -c -m 644 $(DIST_FILES_THEMES) "$(DESTDIR)$(DATADIR)/residual-tools/"
+ #$(INSTALL) -c -m 644 $(DIST_FILES_ENGINEDATA) "$(DESTDIR)$(DATADIR)/residual-tools/"
+
+uninstall:
+ rm -f "$(DESTDIR)$(BINDIR)/$(EXECUTABLE)"
+ rm -rf "$(DESTDIR)$(PREFIX)/share/doc/residual-tools/"
+ rm -rf "$(DESTDIR)$(DATADIR)/residual-tools/"
+
+
+#
+# ARM specific
+#
+ifdef USE_TREMOLO
+DEFINES += -DUSE_TREMOR -DUSE_VORBIS -DUSE_TREMOLO
+LIBS += -ltremolo
+endif
+
diff --git a/rules.mk b/rules.mk
new file mode 100644
index 000000000..0045e59ac
--- /dev/null
+++ b/rules.mk
@@ -0,0 +1,91 @@
+###############################################
+# Common build rules, used by the sub modules and their module.mk files
+#
+# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/rules.mk $
+# $Id: rules.mk 1566 2009-08-22 18:06:11Z salty-horse $
+###############################################
+
+
+# Copy the list of objects to a new variable. The name of the new variable
+# contains the module name, a trick we use so we can keep multiple different
+# module object lists, one for each module.
+MODULE_OBJS-$(MODULE) := $(addprefix $(MODULE)/, $(MODULE_OBJS))
+
+# Add all involved directories to the MODULE_DIRS list
+MODULE_DIRS += $(sort $(dir $(MODULE_OBJS-$(MODULE))))
+
+
+
+ifdef TOOL_EXECUTABLE
+################################################
+# Build rule for (tool) executables.
+# TODO: Refactor this, so that even our master executable can use this rule?
+################################################
+TOOL-$(MODULE) := $(MODULE)/$(TOOL_EXECUTABLE)$(EXEEXT)
+$(TOOL-$(MODULE)): $(MODULE_OBJS-$(MODULE))
+ $(QUIET_CXX)$(CXX) $(LDFLAGS) $+ -o $@
+
+# Reset TOOL_EXECUTABLE var
+TOOL_EXECUTABLE:=
+
+# Add to "tools" target
+tools: $(TOOL-$(MODULE))
+
+# Pseudo target for comfort, allows for "make tools/skycpt", etc.
+$(MODULE): $(TOOL-$(MODULE))
+clean-tools: clean-$(MODULE)
+
+else
+ifdef PLUGIN
+################################################
+# Build rule for dynamic (loadable) plugins
+################################################
+PLUGIN-$(MODULE) := plugins/$(PLUGIN_PREFIX)$(notdir $(MODULE))$(PLUGIN_SUFFIX)
+$(PLUGIN-$(MODULE)): $(MODULE_OBJS-$(MODULE)) $(PLUGIN_EXTRA_DEPS)
+ $(QUIET)$(MKDIR) plugins
+ $(QUIET_PLUGIN)$(CXX) $(filter-out $(PLUGIN_EXTRA_DEPS),$+) $(PLUGIN_LDFLAGS) -o $@
+
+# Reset PLUGIN var
+PLUGIN:=
+
+# Add to "plugins" target
+plugins: $(PLUGIN-$(MODULE))
+
+# Add to the PLUGINS variable
+PLUGINS += $(PLUGIN-$(MODULE))
+
+# Pseudo target for comfort, allows for "make common", "make gui" etc.
+$(MODULE): $(PLUGIN-$(MODULE))
+clean-plugins: clean-$(MODULE)
+
+else
+################################################
+# Build rule for static modules/plugins
+################################################
+MODULE_LIB-$(MODULE) := $(MODULE)/lib$(notdir $(MODULE)).a
+
+# If not building as a plugin, add the object files to the main OBJS list
+OBJS += $(MODULE_LIB-$(MODULE))
+
+# Convenience library target
+$(MODULE_LIB-$(MODULE)): $(MODULE_OBJS-$(MODULE))
+ $(QUIET)-$(RM) $@
+ $(QUIET_AR)$(AR) $@ $+
+ $(QUIET_RANLIB)$(RANLIB) $@
+
+# Pseudo target for comfort, allows for "make common", "make gui" etc.
+$(MODULE): $(MODULE_LIB-$(MODULE))
+
+endif # PLUGIN
+endif # TOOL_EXECUTABLE
+
+###############################################
+# Clean target, removes all object files. This looks a bit hackish, as we have to
+# copy the content of MODULE_OBJS to another unique variable (the next module.mk
+# will overwrite it after all). The same for the libMODULE.a library file.
+###############################################
+clean: clean-$(MODULE)
+clean-$(MODULE): clean-% :
+ -$(RM) $(MODULE_OBJS-$*) $(MODULE_LIB-$*) $(TOOL-$*)
+
+.PHONY: clean-$(MODULE) $(MODULE)
diff --git a/tools/bmtoppm.cpp b/tools/bmtoppm.cpp
new file mode 100644
index 000000000..725664098
--- /dev/null
+++ b/tools/bmtoppm.cpp
@@ -0,0 +1,237 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/bmtoppm.cpp $
+* $Id: bmtoppm.cpp 1375 2009-05-27 07:35:32Z aquadran $
+*
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <assert.h>
+
+#include <ppm.h>
+
+int32_t read_LEint32(FILE *f) {
+ unsigned char c[4];
+
+ fread(c, 1, 4, f);
+ return (c[0]) | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
+}
+
+void read_header(FILE *in, int *codec, int *num_images, int *format) {
+ char magic[8];
+
+ fread(magic, 1, 8, in);
+ if (memcmp(magic, "BM F\0\0\0", 8) != 0) {
+ fprintf(stderr, "not a bitmap file\n");
+ exit(1);
+ }
+ *codec = read_LEint32(in);
+
+ read_LEint32(in);
+ *num_images = read_LEint32(in);
+ read_LEint32(in); /* ignore x offset */
+ read_LEint32(in); /* ignore y offset */
+ read_LEint32(in);
+ *format = read_LEint32(in);
+ fseek(in, 128, SEEK_SET);
+}
+
+void read_data_codec0(FILE *in, int width, int height, unsigned char *result) {
+ fread(result, 1, width * height * 2, in);
+}
+
+void read_data_codec3(FILE *in, int size, unsigned char *result) {
+ unsigned char *data;
+ const unsigned char *data_ptr;
+ int bitstr_val, bitstr_len;
+ int offset, len;
+
+ data = malloc(size);
+ fread(data, 1, size, in);
+
+ bitstr_val = data[0] | (data[1] << 8);
+ bitstr_len = 16;
+ data_ptr = data + 2;
+
+#define GET_BIT ({ \
+ int bit_result = bitstr_val & 1; \
+ bitstr_val >>= 1; \
+ bitstr_len--; \
+ if (bitstr_len == 0) { \
+ bitstr_val = data_ptr[0] | (data_ptr[1] << 8); \
+ bitstr_len = 16; \
+ data_ptr += 2; \
+ } \
+ bit_result; \
+ })
+
+ for (;;) {
+ if (GET_BIT == 1)
+ *result++ = *data_ptr++;
+ else {
+ if (GET_BIT == 0) {
+ len = GET_BIT * 2;
+ len += GET_BIT;
+ len += 3;
+ offset = *data_ptr - 0x100;
+ data_ptr++;
+ } else {
+ offset = data_ptr[0] | ((data_ptr[1] & 0xf0) << 4);
+ offset -= 0x1000;
+ len = (data_ptr[1] & 0xf) + 3;
+ data_ptr += 2;
+ if (len == 3) {
+ len = *data_ptr++;
+ len++;
+ if (len == 1) {
+ free(data);
+ return;
+ }
+ }
+ }
+ while (len > 0) {
+ *result = result[offset];
+ result++;
+ len--;
+ }
+ }
+ }
+}
+
+void write_img(pixel **img, const char *fname, int img_num, int width, int height, int maxval) {
+ const char *basename;
+ char newname[1024];
+ FILE *out;
+
+ basename = strrchr(fname, '/');
+ if (basename != NULL)
+ basename++;
+ else
+ basename = fname;
+ strcpy(newname, basename);
+ if (strlen(newname) > 3 && strcasecmp(newname + strlen(newname) - 3, ".bm") == 0)
+ newname[strlen(newname) - 3] = '\0';
+ else if (strlen(newname) > 4 && strcasecmp(newname + strlen(newname) - 4, ".zbm") == 0) {
+ newname[strlen(newname) - 4] = '\0';
+ strcat(newname, "_z");
+ }
+ sprintf(newname + strlen(newname), "_%d.ppm", img_num);
+
+ out = fopen(newname, "wb");
+ if (out == NULL) {
+ perror(newname);
+ exit(1);
+ }
+
+ ppm_writeppm(out, img, width, height, maxval, 0);
+ fclose(out);
+}
+
+pixel **toimg_fmt1(const unsigned char *data, int width, int height) {
+ pixel **result;
+ int x, y;
+ int r, g, b;
+
+ result = ppm_allocarray(width, height);
+ for (y = 0; y < height; y++)
+ for (x = 0; x < width; x++) {
+ r = data[1] >> 3;
+ r = (r << 3) | (r >> 2);
+ g = ((data[1] & 7) << 3) | (data[0] >> 5);
+ g = (g << 2) | (g >> 4);
+ b = data[0] & 0x1f;
+ b = (b << 3) | (b >> 2);
+ PPM_ASSIGN(result[y][x], r, g, b);
+ data += 2;
+ }
+ return result;
+}
+
+pixel **toimg_fmt5(const unsigned char *data, int width, int height) {
+ pixel **result;
+ int x, y;
+ unsigned short gray;
+
+ result = ppm_allocarray(width, height);
+ for (y = 0; y < height; y++)
+ for (x = 0; x < width; x++) {
+ /* gray = data[0] | (data[1] << 8); */
+ gray = data[1];
+ PPM_ASSIGN(result[y][x], gray, gray, gray);
+ data += 2;
+ }
+ return result;
+}
+
+void process_file(const char *fname) {
+ FILE *in;
+ int codec, num_images, format;
+ int i;
+ int width, height, size, maxval;
+ unsigned char *data;
+ pixel **img;
+
+ in = fopen(fname, "rb");
+ if (in == NULL) {
+ perror(fname);
+ exit(1);
+ }
+ read_header(in, &codec, &num_images, &format);
+
+ for (i = 0; i < num_images; i++) {
+ width = read_LEint32(in);
+ height = read_LEint32(in);
+ data = malloc(width * height * 2);
+
+ if (codec == 0)
+ read_data_codec0(in, width, height, data);
+ else if (codec == 3) {
+ size = read_LEint32(in);
+ read_data_codec3(in, size, data);
+ } else {
+ fprintf(stderr, "%s: unsupported codec %d\n", fname, codec);
+ exit(1);
+ }
+
+ if (format == 1) {
+ img = toimg_fmt1(data, width, height);
+ maxval = 255;
+ } else if (format == 5) {
+ img = toimg_fmt5(data, width, height);
+ maxval = 255;
+ } else {
+ fprintf(stderr, "%s: unsupported format %d\n", fname, format);
+ exit(1);
+ }
+
+ write_img(img, fname, i, width, height, maxval);
+ free(data);
+ ppm_freearray(img, height);
+ }
+ fclose(in);
+}
+
+int main(int argc, char **argv) {
+ int i;
+
+ ppm_init(&argc, argv);
+ for (i = 1; i < argc; i++)
+ process_file(argv[i]);
+ return 0;
+}
diff --git a/tools/delua.cpp b/tools/delua.cpp
new file mode 100644
index 000000000..730ab2ecd
--- /dev/null
+++ b/tools/delua.cpp
@@ -0,0 +1,1307 @@
+/* Residual - A 3D game interpreter
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "tools/lua/lua.h"
+#include "tools/lua/lundump.h"
+#include "tools/lua/lopcodes.h"
+#include "tools/lua/lzio.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <iostream>
+#include <sstream>
+#include <map>
+#include <queue>
+#include <stack>
+#include <list>
+#include <set>
+
+// Provide debug.cpp functions which don't call SDL_Quit.
+void warning(const char *fmt, ...) {
+ fprintf(stderr, "WARNING: ");
+ va_list va;
+ va_start(va, fmt);
+ vfprintf(stderr, fmt, va);
+ va_end(va);
+ fprintf(stderr, "\n");
+}
+
+void error(const char *fmt, ...) {
+ fprintf(stderr, "ERROR: ");
+ va_list va;
+ va_start(va, fmt);
+ vfprintf(stderr, fmt, va);
+ va_end(va);
+ fprintf(stderr, "\n");
+ exit(1);
+}
+
+class Expression;
+
+void decompile(std::ostream &os, TProtoFunc *tf, std::string indent_str,
+ Expression **upvals, int num_upvals);
+
+std::string localname(TProtoFunc *tf, int n) {
+ LocVar *l = tf->locvars;
+ if (l != NULL)
+ for (int i = 0; i < n; i++, l++)
+ if (l->varname == NULL) {
+ l = NULL;
+ break;
+ }
+ if (l != NULL)
+ return l->varname->str;
+ else {
+ std::ostringstream s;
+ if (n < tf->code[1])
+ s << "arg" << n + 1;
+ else
+ s << "local" << n - tf->code[1] + 1;
+ return s.str();
+ }
+}
+
+class Expression {
+public:
+ Expression(Byte *p) : pos(p) { }
+ Byte *pos; // Position just after the expression
+ // is pushed onto the stack
+ virtual void print(std::ostream &os) const = 0;
+ virtual int precedence() const { return 100; }
+ virtual ~Expression() { }
+};
+
+inline std::ostream& operator <<(std::ostream &os, const Expression &e) {
+ e.print(os);
+ return os;
+}
+
+class NumberExpr : public Expression {
+public:
+ NumberExpr(Byte *p, float val) : Expression(p), value(val) { }
+ float value;
+ void print(std::ostream &os) const { os << value; }
+};
+
+class VarExpr : public Expression {
+public:
+ VarExpr(Byte *p, std::string varname) : Expression(p), name(varname) { }
+ std::string name;
+ void print(std::ostream &os) const { os << name; }
+};
+
+class StringExpr : public Expression {
+public:
+ StringExpr(Byte *p, TaggedString *txt) : Expression(p), text(txt) { }
+ TaggedString *text;
+ bool validIdentifier() const {
+ if (text->u.s.len == 0)
+ return false;
+ if (isdigit(text->str[0]))
+ return false;
+ if (text->str[0] >= '0' && text->str[0] <= '9')
+ return false;
+ for (int i = 0; i < text->u.s.len; i++) {
+ char c = text->str[i];
+ if ((! isalnum(text->str[0])) && c != '_')
+ return false;
+ }
+ return true;
+ }
+ void print(std::ostream &os) const {
+ static char *specials = "\a\b\f\n\r\t\v\\\"";
+ static char *special_text[] = {
+ "\\a", "\\b", "\\f", "\\n", "\\r", "\\t", "\\v", "\\\\", "\\\""
+ };
+
+ os << "\"";
+ std::string str(text->str, text->u.s.len);
+ for (std::string::iterator i = str.begin(); i != str.end(); i++) {
+ unsigned char c = *i;
+ if (strchr(specials, c)) {
+ int i = strchr(specials, c) - specials;
+ os << special_text[i];
+ }
+ else if (! isprint(c))
+ os << "\\" << int(c >> 6) << int((c >> 3) & 7) << int(c & 7);
+ else
+ os << c;
+ }
+ os << "\"";
+ }
+};
+
+class FuncExpr : public Expression {
+public:
+ FuncExpr(Byte *p, TProtoFunc *tf0, std::string is) :
+ Expression(p), indent_str(is), tf(tf0), upvals(NULL), num_upvals(0) { }
+ std::string indent_str;
+ TProtoFunc *tf;
+ Expression **upvals;
+ int num_upvals;
+
+ void print(std::ostream &os) const {
+ os << "function(";
+ for (int i = 0; i < tf->code[1]; i++) {
+ os << localname(tf, i);
+ if (i + 1 < tf->code[1])
+ os << ", ";
+ }
+ os << ") -- line " << tf->lineDefined << std::endl;
+ decompile(os, tf, indent_str + std::string(4, ' '),
+ upvals, num_upvals);
+ os << indent_str << "end";
+ }
+ ~FuncExpr() {
+ for (int i = 0; i < num_upvals; i++)
+ delete upvals[i];
+ delete[] upvals;
+ }
+};
+
+class IndexExpr : public Expression {
+public:
+ IndexExpr(Byte *p, Expression *tbl, Expression *i)
+ : Expression(p), table(tbl), index(i) { }
+ Expression *table, *index;
+ void print(std::ostream &os) const {
+ table->print(os);
+ StringExpr *field = dynamic_cast<StringExpr *>(index);
+ if (field != NULL && field->validIdentifier())
+ os << "." << field->text->str;
+ else
+ os << "[" << *index << "]";
+ }
+ ~IndexExpr() {
+ delete table;
+ delete index;
+ }
+};
+
+class SelfExpr : public IndexExpr {
+public:
+ SelfExpr(Byte *p, Expression *tbl, StringExpr *i) : IndexExpr(p, tbl, i) { }
+ void print(std::ostream &os) const {
+ StringExpr *field = static_cast<StringExpr *>(index);
+ os << *table << ":" << field->text->str;
+ }
+};
+
+class FuncCallExpr : public Expression {
+public:
+ FuncCallExpr(Byte *p) : Expression(p) { }
+ int num_args;
+ Expression **args;
+ Expression *func;
+ void print(std::ostream &os) const {
+ os << *func << "(";
+ int i = 0;
+
+ // Skip implicit self argument in a:b(c)
+ if (dynamic_cast<SelfExpr *>(func) != NULL)
+ i = 1;
+ for (; i < num_args; i++) {
+ args[i]->print(os);
+ if (i + 1 < num_args)
+ os << ", ";
+ }
+ os << ")";
+ }
+ ~FuncCallExpr() {
+ for (int i = 0; i < num_args; i++)
+ delete args[i];
+ delete args;
+ delete func;
+ }
+};
+
+class ArrayExpr : public Expression {
+public:
+ ArrayExpr(Byte *p) : Expression(p) { }
+ typedef std::pair<Expression *, Expression *> mapping;
+ typedef std::list<mapping> mapping_list;
+ mapping_list mappings;
+ void print(std::ostream &os) const {
+ os << "{";
+ mapping_list::const_iterator i = mappings.begin();
+ while (i != mappings.end()) {
+ if (i->first != NULL) {
+ StringExpr *field = dynamic_cast<StringExpr *>(i->first);
+ if (field != NULL && field->validIdentifier())
+ os << " " << field->text->str;
+ else
+ os << " [" << *i->first << "]";
+ os << " =";
+ }
+ os << " " << *i->second;
+ i++;
+ if (i != mappings.end())
+ os << ",";
+ }
+ os << " }";
+ }
+ ~ArrayExpr() {
+ for (mapping_list::iterator i = mappings.begin();
+ i != mappings.end(); i++) {
+ delete i->first;
+ delete i->second;
+ }
+ }
+};
+
+class BinaryExpr : public Expression {
+public:
+ BinaryExpr(Byte *ps, Expression *l, Expression *r, int p, bool ra,
+ std::string o) :
+ Expression(ps), left(l), right(r), prec(p), right_assoc(ra), op(o) { }
+ Expression *left, *right;
+ int prec;
+ bool right_assoc;
+ std::string op;
+ int precedence() const { return prec; }
+ void print(std::ostream &os) const {
+ if (left->precedence() < prec ||
+ (left->precedence() == prec && right_assoc))
+ os << "(" << *left << ")";
+ else
+ os << *left;
+ os << op;
+ if (right->precedence() < prec ||
+ (right->precedence() == prec && ! right_assoc))
+ os << "(" << *right << ")";
+ else
+ os << *right;
+ }
+ ~BinaryExpr() { delete left; delete right; }
+};
+
+class UnaryExpr : public Expression {
+public:
+ UnaryExpr(Byte *ps, Expression *a, int p, std::string o) :
+ Expression(ps), arg(a), prec(p), op(o) { }
+ Expression *arg;
+ int prec;
+ std::string op;
+ int precedence() const { return prec; }
+ void print(std::ostream &os) const {
+ os << op;
+ if (arg->precedence() < prec)
+ os << "(" << *arg << ")";
+ else
+ os << *arg;
+ }
+ ~UnaryExpr() { delete arg; }
+};
+
+typedef std::stack<Expression *> ExprStack;
+
+class Decompiler {
+public:
+ void decompileRange(Byte *start, Byte *end);
+
+ std::ostream *os;
+ ExprStack *stk;
+ TProtoFunc *tf;
+ std::string indent_str;
+ Byte *break_pos;
+ Expression **upvals; int num_upvals;
+ std::multiset<Byte *> *local_var_defs;
+
+private:
+ void do_multi_assign(Byte *&start);
+ void do_binary_op(Byte *pos, int prec, bool right_assoc, std::string op);
+ void do_unary_op(Byte *pos, int prec, std::string op);
+ static bool is_expr_opc(Byte opc);
+ void get_else_part(Byte *start, Byte *&if_part_end,
+ bool &has_else, Byte *&else_part_end);
+};
+
+// Scan for a series of assignments
+void Decompiler::do_multi_assign(Byte *&start) {
+ std::queue<Expression *> results;
+ ExprStack values;
+
+ bool done;
+ int num_tables = 0;
+ do {
+ int aux, opc;
+ done = false;
+
+ opc = *start++;
+ switch (opc) {
+ case SETLOCAL:
+ aux = *start++;
+ goto setlocal;
+
+ case SETLOCAL0:
+ case SETLOCAL1:
+ case SETLOCAL2:
+ case SETLOCAL3:
+ case SETLOCAL4:
+ case SETLOCAL5:
+ case SETLOCAL6:
+ case SETLOCAL7:
+ aux = opc - SETLOCAL0;
+ setlocal:
+ results.push(new VarExpr(start, localname(tf, aux)));
+ break;
+
+ case SETGLOBAL:
+ aux = *start++;
+ goto setglobal;
+
+ case SETGLOBAL0:
+ case SETGLOBAL1:
+ case SETGLOBAL2:
+ case SETGLOBAL3:
+ case SETGLOBAL4:
+ case SETGLOBAL5:
+ case SETGLOBAL6:
+ case SETGLOBAL7:
+ aux = opc - SETGLOBAL0;
+ goto setglobal;
+
+ case SETGLOBALW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ setglobal:
+ results.push(new VarExpr(start, svalue(tf->consts + aux)));
+ break;
+
+ case SETTABLE:
+ start++; // assume offset is correct
+ case SETTABLE0:
+ results.push(new IndexExpr(start, NULL, NULL));
+ num_tables++;
+ // this needs stuff from farther up the stack, wait until
+ // it's available
+ break;
+
+ default:
+ start--;
+ done = true;
+ }
+
+ if (! done) {
+ Expression *e = stk->top();
+ // Check for fake result from function calls with multiple return values
+ VarExpr *v = dynamic_cast<VarExpr *>(e);
+ if (v != NULL && v->name == "<extra result>")
+ delete e;
+ else
+ values.push(e);
+ stk->pop();
+ }
+ } while (! done);
+
+ // Check for popping tables and indices
+ if (num_tables > 0 && (*start == POP || *start == POP0 || *start == POP1)) {
+ start++;
+ if (start[-1] == POP)
+ start++;
+ }
+
+ // Now get actual tables and indices from the stack, reversing
+ // the list to the right order at the same time
+
+ ExprStack results2;
+ while (! results.empty()) {
+ Expression *var = results.front(); results.pop();
+ IndexExpr *tbl = dynamic_cast<IndexExpr *>(var);
+ if (tbl != NULL) {
+ tbl->index = stk->top(); stk->pop();
+ tbl->table = stk->top(); stk->pop();
+ }
+ results2.push(var);
+ }
+
+ *os << indent_str;
+ while (! results2.empty()) {
+ Expression *var = results2.top(); results2.pop();
+ *os << *var;
+ delete var;
+ if (! results2.empty())
+ *os << ", ";
+ }
+ *os << " = ";
+ while (! values.empty()) {
+ Expression *val = values.top(); values.pop();
+ *os << *val;
+ delete val;
+ if (! values.empty())
+ *os << ", ";
+ }
+ *os << std::endl;
+}
+
+void Decompiler::do_binary_op(Byte *pos, int prec, bool right_assoc,
+ std::string op) {
+ Expression *right = stk->top(); stk->pop();
+ Expression *left = stk->top(); stk->pop();
+ stk->push(new BinaryExpr(pos, left, right, prec, right_assoc, op));
+}
+
+void Decompiler::do_unary_op(Byte *pos, int prec, std::string op) {
+ Expression *arg = stk->top(); stk->pop();
+ stk->push(new UnaryExpr(pos, arg, prec, op));
+}
+
+// Provide instruction lengths to make it easy to scan through instructions
+int instr_lens[] = {
+ 1, // ENDCODE
+ 2, // PUSHNIL
+ 1, // PUSHNIL0
+ 2, // PUSHNUMBER
+ 1, 1, 1, // PUSHNUMBER0..2
+ 3, // PUSHNUMBERW
+ 2, // PUSHCONSTANT
+ 1, 1, 1, 1, 1, 1, 1, 1, // PUSHCONSTANT0..7
+ 3, // PUSHCONSTANTW
+ 2, // PUSHUPVALUE
+ 1, 1, // PUSHUPVALUE0,1
+ 2, // PUSHLOCAL
+ 1, 1, 1, 1, 1, 1, 1, 1, // PUSHLOCAL0..7
+ 2, // GETGLOBAL
+ 1, 1, 1, 1, 1, 1, 1, 1, // GETGLOBAL0..7
+ 3, // GETGLOBALW
+ 1, // GETTABLE
+ 2, // GETDOTTED
+ 1, 1, 1, 1, 1, 1, 1, 1, // GETDOTTED0..7
+ 3, // GETDOTTEDW
+ 2, // PUSHSELF
+ 1, 1, 1, 1, 1, 1, 1, 1, // PUSHSELF0..7
+ 3, // PUSHSELFW
+ 2, // CREATEARRAY
+ 1, 1, // CREATEARRAY0,1
+ 3, // CREATEARRAYW
+ 2, // SETLOCAL
+ 1, 1, 1, 1, 1, 1, 1, 1, // SETLOCAL0..7
+ 2, // SETGLOBAL
+ 1, 1, 1, 1, 1, 1, 1, 1, // SETGLOBAL0..7
+ 3, // SETGLOBALW
+ 1, // SETTABLE0
+ 2, // SETTABLE
+ 3, // SETLIST
+ 2, // SETLIST0
+ 4, // SETLISTW
+ 2, // SETMAP
+ 1, // SETMAP0
+ 1, // EQOP
+ 1, // NEQOP
+ 1, // LTOP
+ 1, // LEOP
+ 1, // GTOP
+ 1, // GEOP
+ 1, // ADDOP
+ 1, // SUBOP
+ 1, // MULTOP
+ 1, // DIVOP
+ 1, // POWOP
+ 1, // CONCOP
+ 1, // MINUSOP
+ 1, // NOTOP
+ 2, 3, // ONTJMP, ONTJMPW
+ 2, 3, // ONFJMP, ONFJMPW
+ 2, 3, // JMP, JMPW
+ 2, 3, // IFFJMP, IFFJMPW
+ 2, 3, // IFTUPJMP, IFTUPJMPW
+ 2, 3, // IFFUPJMP, IFFUPJMPW
+ 2, // CLOSURE
+ 1, 1, // CLOSURE0,1
+ 3, // CALLFUNC
+ 2, 2, // CALLFUNC0,1
+ 2, // RETCODE
+ 2, // SETLINE
+ 3, // SETLINEW
+ 2, // POP
+ 1, 1 // POP0,1
+};
+
+bool Decompiler::is_expr_opc(Byte opc) {
+ if (opc >= PUSHNIL && opc <= CREATEARRAYW)
+ return true;
+ if (opc == SETLIST0)
+ return true;
+ if (opc >= SETMAP && opc <= ONFJMPW)
+ return true;
+ if (opc >= CLOSURE && opc <= CLOSURE1)
+ return true;
+ if (opc == CALLFUNC1 || opc == SETLINE || opc == SETLINEW)
+ return true;
+ return false;
+}
+
+// Check for JMP or JMPW at end of "if" part
+void Decompiler::get_else_part(Byte *start, Byte *&if_part_end,
+ bool &has_else, Byte *&else_part_end) {
+ Byte *last_instr = NULL;
+ has_else = false;
+ else_part_end = NULL;
+
+ for (Byte *instr_scan = start; instr_scan < if_part_end;
+ instr_scan += instr_lens[*instr_scan])
+ last_instr = instr_scan;
+ if (last_instr != NULL &&
+ (*last_instr == JMP || *last_instr == JMPW)) {
+ has_else = true;
+ else_part_end = if_part_end + last_instr[1];
+ if (*last_instr == JMPW)
+ else_part_end += (last_instr[2] << 8);
+ if_part_end = last_instr;
+ }
+}
+
+void Decompiler::decompileRange(Byte *start, Byte *end) {
+ // First, scan for IFFUPJMP, which is used for repeat/until, so
+ // we can recognize the start of such loops. We only keep the
+ // last value to match each address, which represents the outermost
+ // repeat/until loop starting at that point.
+ std::map<Byte *, Byte *> rev_iffupjmp_map;
+
+ for (Byte *scan = start; end == NULL || scan < end;
+ scan += instr_lens[*scan]) {
+ if (*scan == IFFUPJMP)
+ rev_iffupjmp_map[scan + 2 - scan[1]] = scan;
+ else if (*scan == IFFUPJMPW)
+ rev_iffupjmp_map[scan + 3 - (scan[1] | (scan[2] << 8))] = scan;
+ else if (*scan == ENDCODE)
+ break;
+ }
+
+ while (end == NULL || start < end) {
+ int locs_here = local_var_defs->count(start);
+ if (locs_here > 0) {
+ // There were local variable slots just pushed onto the stack
+ // Print them out (in the second pass)
+
+ // First, if there are multiple defined, it must be from
+ // local x, y, z = f() or local a, b. So just ignore the extra
+ // entries.
+ for (int i = 1; i < locs_here; i++) {
+ delete stk->top(); stk->pop();
+ }
+ Expression *def = stk->top(); stk->pop();
+
+ // Print the local variable names, and at the same time push
+ // fake values onto the stack
+ *os << indent_str << "local ";
+ for (int i = 0; i < locs_here; i++) {
+ std::string locname = localname(tf, tf->code[1] + stk->size());
+ *os << locname;
+ if (i + 1 < locs_here)
+ *os << ", ";
+ stk->push(new VarExpr(start, "<" + locname + " stack slot>"));
+ }
+
+ // Print the definition, unless it's nil
+ VarExpr *v = dynamic_cast<VarExpr *>(def);
+ if (v == NULL || v->name != "nil")
+ *os << " = " << *def;
+ *os << std::endl;
+ }
+
+ if (rev_iffupjmp_map.find(start) != rev_iffupjmp_map.end()) {
+ // aha, do a repeat/until loop
+ *os << indent_str << "repeat\n";
+ Decompiler indented_dc = *this;
+ indented_dc.indent_str += std::string(4, ' ');
+ indented_dc.break_pos = rev_iffupjmp_map[start];
+ indented_dc.break_pos += instr_lens[*indented_dc.break_pos];
+ indented_dc.decompileRange(start, rev_iffupjmp_map[start]);
+
+ Expression *e = stk->top(); stk->pop();
+ *os << indent_str << "until " << *e << std::endl;
+ delete e;
+
+ start = indented_dc.break_pos;
+ continue;
+ }
+
+ Byte opc = *start++;
+ int aux;
+
+ switch (opc) {
+ case ENDCODE:
+ return;
+
+ case PUSHNIL:
+ aux = *start++;
+ goto pushnil;
+
+ case PUSHNIL0:
+ aux = 0;
+ pushnil:
+ for (int i = 0; i <= aux; i++)
+ stk->push(new VarExpr(start, "nil")); // Cheat a little :)
+ break;
+
+ case PUSHNUMBER:
+ aux = *start++;
+ goto pushnumber;
+
+ case PUSHNUMBER0:
+ case PUSHNUMBER1:
+ case PUSHNUMBER2:
+ aux = opc - PUSHNUMBER0;
+ goto pushnumber;
+
+ case PUSHNUMBERW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ pushnumber:
+ stk->push(new NumberExpr(start, aux));
+ break;
+
+ case PUSHCONSTANT:
+ aux = *start++;
+ goto pushconst;
+
+ case PUSHCONSTANT0:
+ case PUSHCONSTANT1:
+ case PUSHCONSTANT2:
+ case PUSHCONSTANT3:
+ case PUSHCONSTANT4:
+ case PUSHCONSTANT5:
+ case PUSHCONSTANT6:
+ case PUSHCONSTANT7:
+ aux = opc - PUSHCONSTANT0;
+ goto pushconst;
+
+ case PUSHCONSTANTW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ pushconst:
+ switch (ttype(tf->consts + aux)) {
+ case LUA_T_STRING:
+ stk->push(new StringExpr(start, tsvalue(tf->consts + aux)));
+ break;
+ case LUA_T_NUMBER:
+ stk->push(new NumberExpr(start, nvalue(tf->consts + aux)));
+ break;
+ case LUA_T_PROTO:
+ stk->push(new FuncExpr(start, tfvalue(tf->consts + aux), indent_str));
+ break;
+ default:
+ *os << indent_str << "error: invalid constant type "
+ << int(ttype(tf->consts + aux)) << std::endl;
+ }
+ break;
+
+ case PUSHUPVALUE:
+ aux = *start++;
+ goto pushupvalue;
+
+ case PUSHUPVALUE0:
+ case PUSHUPVALUE1:
+ aux = opc - PUSHUPVALUE0;
+ pushupvalue:
+ {
+ if (aux >= num_upvals) {
+ *os << indent_str << "error: invalid upvalue #"
+ << aux << std::endl;
+ }
+
+ std::ostringstream s;
+ s << "%" << *upvals[aux];
+ stk->push(new VarExpr(start, s.str()));
+ }
+ break;
+
+ case PUSHLOCAL:
+ aux = *start++;
+ goto pushlocal;
+
+ case PUSHLOCAL0:
+ case PUSHLOCAL1:
+ case PUSHLOCAL2:
+ case PUSHLOCAL3:
+ case PUSHLOCAL4:
+ case PUSHLOCAL5:
+ case PUSHLOCAL6:
+ case PUSHLOCAL7:
+ aux = opc - PUSHLOCAL0;
+ pushlocal:
+ stk->push(new VarExpr(start, localname(tf, aux)));
+ break;
+
+ case GETGLOBAL:
+ aux = *start++;
+ goto getglobal;
+
+ case GETGLOBAL0:
+ case GETGLOBAL1:
+ case GETGLOBAL2:
+ case GETGLOBAL3:
+ case GETGLOBAL4:
+ case GETGLOBAL5:
+ case GETGLOBAL6:
+ case GETGLOBAL7:
+ aux = opc - GETGLOBAL0;
+ goto getglobal;
+
+ case GETGLOBALW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ getglobal:
+ stk->push(new VarExpr(start, svalue(tf->consts + aux)));
+ break;
+
+ case GETTABLE:
+ {
+ Expression *index = stk->top(); stk->pop();
+ Expression *table = stk->top(); stk->pop();
+
+ stk->push(new IndexExpr(start, table, index));
+ }
+ break;
+
+ case GETDOTTED:
+ aux = *start++;
+ goto getdotted;
+
+ case GETDOTTED0:
+ case GETDOTTED1:
+ case GETDOTTED2:
+ case GETDOTTED3:
+ case GETDOTTED4:
+ case GETDOTTED5:
+ case GETDOTTED6:
+ case GETDOTTED7:
+ aux = opc - GETDOTTED0;
+ goto getdotted;
+
+ case GETDOTTEDW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ getdotted:
+ {
+ Expression *tbl = stk->top(); stk->pop();
+ stk->push(new IndexExpr(start, tbl, new StringExpr
+ (start, tsvalue(tf->consts + aux))));
+ }
+ break;
+
+ case PUSHSELF:
+ aux = *start++;
+ goto pushself;
+
+ case PUSHSELF0:
+ case PUSHSELF1:
+ case PUSHSELF2:
+ case PUSHSELF3:
+ case PUSHSELF4:
+ case PUSHSELF5:
+ case PUSHSELF6:
+ case PUSHSELF7:
+ aux = opc - PUSHSELF0;
+ goto pushself;
+
+ case PUSHSELFW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ pushself:
+ {
+ Expression *tbl = stk->top(); stk->pop();
+ stk->push(new SelfExpr(start, tbl, new StringExpr
+ (start, tsvalue(tf->consts + aux))));
+ stk->push(new VarExpr(start, "<self>"));
+ // Fake value, FuncCallExpr will handle it
+ }
+ break;
+
+ case CREATEARRAY:
+ start++;
+ goto createarray;
+
+ case CREATEARRAY0:
+ case CREATEARRAY1:
+ goto createarray;
+
+ case CREATEARRAYW:
+ start += 2;
+ createarray:
+ stk->push(new ArrayExpr(start));
+ break;
+
+ case SETLOCAL:
+ case SETLOCAL0:
+ case SETLOCAL1:
+ case SETLOCAL2:
+ case SETLOCAL3:
+ case SETLOCAL4:
+ case SETLOCAL5:
+ case SETLOCAL6:
+ case SETLOCAL7:
+ case SETGLOBAL:
+ case SETGLOBAL0:
+ case SETGLOBAL1:
+ case SETGLOBAL2:
+ case SETGLOBAL3:
+ case SETGLOBAL4:
+ case SETGLOBAL5:
+ case SETGLOBAL6:
+ case SETGLOBAL7:
+ case SETGLOBALW:
+ case SETTABLE0:
+ case SETTABLE:
+ start--;
+ do_multi_assign(start);
+ break;
+
+ case SETLIST:
+ start++; // assume offset is correct
+ goto setlist;
+
+ case SETLISTW:
+ start += 2;
+
+ case SETLIST0:
+ setlist:
+ aux = *start++;
+ {
+ ArrayExpr::mapping_list new_mappings;
+ for (int i = 0; i < aux; i++) {
+ Expression *val = stk->top(); stk->pop();
+ new_mappings.push_front(std::make_pair((Expression *) NULL, val));
+ }
+ ArrayExpr *a = dynamic_cast<ArrayExpr *>(stk->top());
+ if (a == NULL) {
+ *os << indent_str
+ << "error: attempt to setlist a non-array object\n";
+ }
+ // Append the new list
+ a->mappings.splice(a->mappings.end(), new_mappings);
+ a->pos = start;
+ }
+ break;
+
+ case SETMAP:
+ aux = *start++;
+ goto setmap;
+
+ case SETMAP0:
+ aux = 0;
+ setmap:
+ {
+ ArrayExpr::mapping_list new_mappings;
+ for (int i = 0; i <= aux; i++) {
+ Expression *val = stk->top(); stk->pop();
+ Expression *key = stk->top(); stk->pop();
+ new_mappings.push_front(std::make_pair(key, val));
+ }
+ ArrayExpr *a = dynamic_cast<ArrayExpr *>(stk->top());
+ if (a == NULL) {
+ *os << indent_str
+ << "error: attempt to setmap a non-array object\n";
+ }
+ // Append the new list
+ a->mappings.splice(a->mappings.end(), new_mappings);
+ a->pos = start;
+ }
+ break;
+
+ case EQOP:
+ do_binary_op(start, 1, false, " == ");
+ break;
+
+ case NEQOP:
+ do_binary_op(start, 1, false, " ~= ");
+ break;
+
+ case LTOP:
+ do_binary_op(start, 1, false, " < ");
+ break;
+
+ case LEOP:
+ do_binary_op(start, 1, false, " <= ");
+ break;
+
+ case GTOP:
+ do_binary_op(start, 1, false, " > ");
+ break;
+
+ case GEOP:
+ do_binary_op(start, 1, false, " >= ");
+ break;
+
+ case ADDOP:
+ do_binary_op(start, 3, false, " + ");
+ break;
+
+ case SUBOP:
+ do_binary_op(start, 3, false, " - ");
+ break;
+
+ case MULTOP:
+ do_binary_op(start, 4, false, " * ");
+ break;
+
+ case DIVOP:
+ do_binary_op(start, 4, false, " / ");
+ break;
+
+ case POWOP:
+ do_binary_op(start, 6, true, " ^ ");
+ break;
+
+ case CONCOP:
+ do_binary_op(start, 2, false, "..");
+ break;
+
+ case MINUSOP:
+ do_unary_op(start, 5, "-");
+ break;
+
+ case NOTOP:
+ do_unary_op(start, 5, "not ");
+ break;
+
+ case ONTJMP:
+ aux = *start++;
+ goto ontjmp;
+
+ case ONTJMPW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ ontjmp:
+ // push_expr_1 ontjmp(label) push_expr_2 label: -> expr_1 || expr_2
+ decompileRange(start, start + aux);
+ do_binary_op(start + aux, 0, false, " or ");
+ start = start + aux;
+ break;
+
+ case ONFJMP:
+ aux = *start++;
+ goto onfjmp;
+
+ case ONFJMPW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ onfjmp:
+ // push_expr_1 onfjmp(label) push_expr_2 label: -> expr_2 && expr_2
+ decompileRange(start, start + aux);
+ do_binary_op(start + aux, 0, false, " and ");
+ start = start + aux;
+ break;
+
+ case JMP:
+ aux = *start++;
+ goto jmp;
+
+ case JMPW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ jmp:
+ {
+ Byte *dest = start + aux;
+ if (dest == break_pos) {
+ *os << indent_str << "break\n";
+ break;
+ }
+
+ // otherwise, must be the start of a while statement
+ Byte *while_cond_end;
+ for (while_cond_end = dest; end == NULL || while_cond_end < end;
+ while_cond_end += instr_lens[*while_cond_end])
+ if (*while_cond_end == IFTUPJMP || *while_cond_end == IFTUPJMPW)
+ break;
+ if (end != NULL && while_cond_end >= end) {
+ *os << indent_str
+ << "error: JMP not in break, while, if/else\n";
+ }
+
+ // push the while condition onto the stack
+ decompileRange(dest, while_cond_end);
+
+ *os << indent_str << "while " << *stk->top()
+ << " do\n";
+ delete stk->top();
+ stk->pop();
+
+ // decompile the while body
+ Decompiler indented_dc = *this;
+ indented_dc.indent_str += std::string(4, ' ');
+ indented_dc.break_pos = while_cond_end + instr_lens[*while_cond_end];
+ indented_dc.decompileRange(start, dest);
+
+ *os << indent_str << "end\n";
+ start = indented_dc.break_pos;
+ }
+ break;
+
+ case IFFJMP:
+ aux = *start++;
+ goto iffjmp;
+
+ case IFFJMPW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ iffjmp:
+ {
+ // Output an if/end, if/else/end, if/elseif/else/end, ... statement
+ Byte *if_part_end = start + aux;
+ Decompiler indented_dc = *this;
+ indented_dc.indent_str += std::string(4, ' ');
+
+ *os << indent_str << "if " << *stk->top();
+ delete stk->top();
+ stk->pop();
+ *os << " then\n";
+
+ bool has_else;
+ Byte *else_part_end;
+ get_else_part(start, if_part_end, has_else, else_part_end);
+
+ // Output the if part
+ output_if:
+ indented_dc.decompileRange(start, if_part_end);
+ start = start + aux;
+
+ if (has_else) {
+ // Check whether the entire else part is a single
+ // if or if/else statement
+ Byte *instr_scan = start;
+ while (is_expr_opc(*instr_scan) &&
+ (end == NULL || instr_scan < else_part_end))
+ instr_scan += instr_lens[*instr_scan];
+ if ((end == NULL || instr_scan < else_part_end) &&
+ (*instr_scan == IFFJMP || *instr_scan == IFFJMPW)) {
+ // OK, first line will be if, check if it will go all
+ // the way through
+ Byte *new_start, *new_if_part_end, *new_else_part_end;
+ bool new_has_else;
+ if (*instr_scan == IFFJMP) {
+ aux = instr_scan[1];
+ new_start = instr_scan + 2;
+ }
+ else {
+ aux = instr_scan[1] | (instr_scan[2] << 8);
+ new_start = instr_scan + 3;
+ }
+ new_if_part_end = new_start + aux;
+ get_else_part(new_start, new_if_part_end, new_has_else,
+ new_else_part_end);
+ if (new_if_part_end == else_part_end ||
+ (new_has_else && new_else_part_end == else_part_end)) {
+ // Yes, output an elseif
+ decompileRange(start, instr_scan); // push condition
+ *os << indent_str << "elseif " << *stk->top() << " then\n";
+ delete stk->top();
+ stk->pop();
+
+ start = new_start;
+ if_part_end = new_if_part_end;
+ has_else = new_has_else;
+ else_part_end = new_else_part_end;
+ goto output_if;
+ }
+ }
+ *os << indent_str << "else\n";
+ indented_dc.decompileRange(start, else_part_end);
+ start = else_part_end;
+ }
+ *os << indent_str << "end\n";
+ }
+ break;
+
+ case CLOSURE:
+ aux = *start++;
+ goto closure;
+
+ case CLOSURE0:
+ case CLOSURE1:
+ aux = opc - CLOSURE0;
+ closure:
+ {
+ FuncExpr *f = dynamic_cast<FuncExpr *>(stk->top());
+ if (f == NULL) {
+ *os << indent_str
+ << "error: closure requires a function\n";
+ }
+ stk->pop();
+ f->num_upvals = aux;
+ f->upvals = new Expression*[aux];
+ for (int i = aux - 1; i >= 0; i--) {
+ f->upvals[i] = stk->top(); stk->pop();
+ }
+ stk->push(f);
+ }
+ break;
+
+ case CALLFUNC:
+ aux = *start++;
+ goto callfunc;
+
+ case CALLFUNC0:
+ case CALLFUNC1:
+ aux = opc - CALLFUNC0;
+ callfunc:
+ {
+ int num_args = *start++;
+ FuncCallExpr *e = new FuncCallExpr(start);
+ e->num_args = num_args;
+ e->args = new Expression*[num_args];
+ for (int i = num_args - 1; i >= 0; i--) {
+ e->args[i] = stk->top();
+ stk->pop();
+ }
+ e->func = stk->top();
+ stk->pop();
+ if (aux == 0) {
+ *os << indent_str << *e << std::endl;
+ delete e;
+ }
+ else if (aux == 1 || aux == 255) // 255 for return f()
+ stk->push(e);
+ else {
+ stk->push(e);
+ for (int i = 1; i < aux; i++)
+ stk->push(new VarExpr(start, "<extra result>"));
+ }
+ }
+ break;
+
+ case RETCODE:
+ {
+ int num_rets = stk->size() + tf->code[1] - *start++;
+ ExprStack rets;
+
+ for (int i = 0; i < num_rets; i++) {
+ rets.push(stk->top());
+ stk->pop();
+ }
+ *os << indent_str << "return";
+ for (int i = 0; i < num_rets; i++) {
+ *os << " " << *rets.top();
+ delete rets.top();
+ rets.pop();
+ if (i + 1 < num_rets)
+ *os << ",";
+ }
+ *os << std::endl;
+ }
+ break;
+
+ case SETLINE:
+ aux = *start++;
+ goto setline;
+
+ case SETLINEW:
+ aux = start[0] | (start[1] << 8);
+ start += 2;
+ setline:
+ break; // ignore line info
+
+ case POP:
+ aux = *start++;
+ goto pop;
+
+ case POP0:
+ case POP1:
+ aux = opc - POP0;
+ pop:
+ for (int i = 0; i <= aux; i++) {
+ local_var_defs->insert(stk->top()->pos);
+ delete stk->top(); stk->pop();
+ }
+ break;
+
+ default:
+ *os << indent_str << "error: unrecognized opcode "
+ << int(opc) << std::endl;
+ return;
+ }
+ }
+}
+
+// Decompile the body of a function.
+void decompile(std::ostream &os, TProtoFunc *tf, std::string indent_str,
+ Expression **upvals, int num_upvals) {
+ Byte *instr = tf->code + 2;
+ ExprStack s;
+ std::ostringstream first_time;
+ std::multiset<Byte *> loc_vars;
+
+ // First, do a preliminary pass to see where local variables are defined
+ Decompiler dc;
+ dc.os = &first_time;
+ dc.stk = &s;
+ dc.tf = tf;
+ dc.indent_str = indent_str;
+ dc.break_pos = NULL;
+ dc.upvals = upvals;
+ dc.num_upvals = num_upvals;
+ dc.local_var_defs = &loc_vars;
+ dc.decompileRange(instr, NULL);
+
+ if (s.empty() && loc_vars.empty()) {
+ // OK, it didn't actually have any local variables. Just output
+ // the results right now.
+ os << first_time.str();
+ return;
+ }
+
+ // See where the local variables were defined.
+ while (! s.empty()) {
+ loc_vars.insert(s.top()->pos);
+ delete s.top(); s.pop();
+ }
+
+ // Now do the real decompilation
+ dc.os = &os;
+ dc.decompileRange(instr, NULL);
+
+ while (! s.empty()) {
+ delete s.top(); s.pop();
+ }
+}
+
+int main(int argc, char *argv[]) {
+ int filename_pos = 1;
+
+ if (argc != filename_pos + 1) {
+ fprintf(stderr, "Usage: delua file.lua\n");
+ exit(1);
+ }
+ char *filename = argv[filename_pos];
+ FILE *f = fopen(filename, "rb");
+ if (f == NULL) {
+ perror(filename);
+ exit(1);
+ }
+
+ lua_open();
+ ZIO z;
+ luaZ_Fopen(&z, f, filename);
+ TProtoFunc *tf = luaU_undump1(&z);
+ fclose(f);
+
+ decompile(std::cout, tf, "", NULL, 0);
+
+ lua_close();
+ return 0;
+}
diff --git a/tools/imc2wav.cpp b/tools/imc2wav.cpp
new file mode 100644
index 000000000..8b837749b
--- /dev/null
+++ b/tools/imc2wav.cpp
@@ -0,0 +1,86 @@
+/* Residual - A 3D game interpreter
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ *
+ * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/imc2wav.cpp $
+ * $Id: imc2wav.cpp 1375 2009-05-27 07:35:32Z aquadran $
+ *
+ */
+
+#include <cstdio>
+#include <cstring>
+
+int get_be_uint32(char *pos) {
+ unsigned char *ucpos = reinterpret_cast<unsigned char *>(pos);
+ return (ucpos[0] << 24) | (ucpos[1] << 16) | (ucpos[2] << 8) | ucpos[3];
+}
+
+void write_le_uint32(unsigned val) {
+ putc(val, stdout);
+ putc(val >> 8, stdout);
+ putc(val >> 16, stdout);
+ putc(val >> 24, stdout);
+}
+
+void write_le_uint16(unsigned short val) {
+ putc(val, stdout);
+ putc(val >> 8, stdout);
+}
+
+int main() {
+ char block[1024];
+ fread(block, 8, 1, stdin); // skip iMUS header
+ fread(block, 8, 1, stdin); // read MAP header
+ int mapSize = get_be_uint32(block + 4);
+ int numBits = 16, rate = 22050, channels = 2;
+ for (int mapPos = 0; mapPos < mapSize; ) {
+ fread(block, 8, 1, stdin);
+ int blockSize = get_be_uint32(block + 4);
+ if (memcmp(block, "FRMT", 4) == 0) {
+ fread(block, blockSize, 1, stdin);
+ numBits = get_be_uint32(block + 8);
+ rate = get_be_uint32(block + 12);
+ channels = get_be_uint32(block + 16);
+ } else
+ fread(block, blockSize, 1, stdin);
+ mapPos += (blockSize + 8);
+ }
+ fread(block, 8, 1, stdin);
+ int dataSize = get_be_uint32(block + 4);
+ fputs("RIFF", stdout);
+ write_le_uint32(dataSize + 36);
+ fputs("WAVEfmt ", stdout);
+ write_le_uint32(16);
+ write_le_uint16(1);
+ write_le_uint16(channels);
+ write_le_uint32(rate);
+ write_le_uint32(channels * rate * (numBits / 8));
+ write_le_uint16(channels * (numBits / 8));
+ write_le_uint16(numBits);
+ fputs("data", stdout);
+ write_le_uint32(dataSize);
+ while (dataSize > 1024) {
+ fread(block, 1024, 1, stdin);
+ fwrite(block, 1024, 1, stdout);
+ dataSize -= 1024;
+ }
+ fread(block, dataSize, 1, stdin);
+ fwrite(block, dataSize, 1, stdout);
+ return 0;
+}
diff --git a/tools/int2flt.cpp b/tools/int2flt.cpp
new file mode 100644
index 000000000..4dbbfe219
--- /dev/null
+++ b/tools/int2flt.cpp
@@ -0,0 +1,34 @@
+/* Residual - A 3D game interpreter
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ *
+ * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/int2flt.cpp $
+ * $Id: int2flt.cpp 1359 2009-05-26 14:04:08Z aquadran $
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[]) {
+ unsigned i = atoi(argv[1]);
+ float *f = (float *)&i;
+ printf("%g\n", *f);
+ return 0;
+}
diff --git a/tools/lua/README.residual b/tools/lua/README.residual
new file mode 100644
index 000000000..0fd760a66
--- /dev/null
+++ b/tools/lua/README.residual
@@ -0,0 +1,11 @@
+This is a modified version of Lua 3.1 intended for use with Residual.
+The major changes made from the original version of Lua 3.1 are:
+
+* Changed the binary file loader to read the file format from Lua 3.1alpha2.
+* Revamped the way function calls and returns are handled in order to
+ facilitate implementing Residual/GrimE's cooperative multithreading model.
+* Added several internal functions which implement this multithreading.
+* Unified types like int -> int32 and similiars
+* Removed few unused library funcs by games
+* formatting code
+* replace FILE usage code with File class code
diff --git a/tools/lua/lapi.cpp b/tools/lua/lapi.cpp
new file mode 100644
index 000000000..286d31326
--- /dev/null
+++ b/tools/lua/lapi.cpp
@@ -0,0 +1,631 @@
+/*
+** $Id$
+** Lua API
+** See Copyright Notice in lua.h
+*/
+
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "lapi.h"
+#include "lauxlib.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 "lua.h"
+#include "luadebug.h"
+#include "lvm.h"
+
+
+char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
+ "$Autores: " LUA_AUTHORS " $";
+
+
+
+TObject *luaA_Address (lua_Object o)
+{
+ return Address(o);
+}
+
+
+static int normalized_type (TObject *o)
+{
+ int t = ttype(o);
+ switch (t) {
+ case LUA_T_PMARK:
+ return LUA_T_PROTO;
+ case LUA_T_CMARK:
+ return LUA_T_CPROTO;
+ case LUA_T_CLMARK:
+ return LUA_T_CLOSURE;
+ default:
+ return t;
+ }
+}
+
+
+static void set_normalized (TObject *d, TObject *s)
+{
+ d->value = s->value;
+ d->ttype = (lua_Type)normalized_type(s);
+}
+
+
+static TObject *luaA_protovalue (TObject *o)
+{
+ return (normalized_type(o) == LUA_T_CLOSURE) ? protovalue(o) : o;
+}
+
+
+void luaA_packresults (void)
+{
+ luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top);
+ incr_top;
+}
+
+
+int luaA_passresults (void)
+{
+ luaD_checkstack(L->Cstack.num);
+ memcpy(L->stack.top, L->Cstack.lua2C+L->stack.stack,
+ L->Cstack.num*sizeof(TObject));
+ L->stack.top += L->Cstack.num;
+ return L->Cstack.num;
+}
+
+
+static void checkCparams (int nParams)
+{
+ if (L->stack.top-L->stack.stack < L->Cstack.base+nParams)
+ lua_error("API error - wrong number of arguments in C2lua stack");
+}
+
+
+static lua_Object put_luaObject (TObject *o)
+{
+ luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
+ L->stack.stack[L->Cstack.base++] = *o;
+ return L->Cstack.base; /* this is +1 real position (see Ref) */
+}
+
+
+static lua_Object put_luaObjectonTop (void)
+{
+ luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
+ L->stack.stack[L->Cstack.base++] = *(--L->stack.top);
+ return L->Cstack.base; /* this is +1 real position (see Ref) */
+}
+
+
+lua_Object lua_pop (void)
+{
+ checkCparams(1);
+ return put_luaObjectonTop();
+}
+
+
+/*
+** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
+** 'number' must be 1 to get the first parameter.
+*/
+lua_Object lua_lua2C (int number)
+{
+ if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
+ /* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) ==
+ L->stack.stack+(L->Cstack.lua2C+number-1)-L->stack.stack+1 == */
+ return L->Cstack.lua2C+number;
+}
+
+
+int lua_callfunction (lua_Object function)
+{
+ if (function == LUA_NOOBJECT)
+ return 1;
+ else {
+ luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base);
+ set_normalized(L->stack.stack+L->Cstack.base, Address(function));
+ return luaD_protectedrun(MULT_RET);
+ }
+}
+
+
+lua_Object lua_gettagmethod (int tag, char *event)
+{
+ return put_luaObject(luaT_gettagmethod(tag, event));
+}
+
+
+lua_Object lua_settagmethod (int tag, char *event)
+{
+ checkCparams(1);
+ luaT_settagmethod(tag, event, L->stack.top-1);
+ return put_luaObjectonTop();
+}
+
+
+lua_Object lua_seterrormethod (void)
+{
+ TObject temp = L->errorim;
+ checkCparams(1);
+ L->errorim = *(--L->stack.top);
+ return put_luaObject(&temp);
+}
+
+
+lua_Object lua_gettable (void)
+{
+ checkCparams(2);
+ luaV_gettable();
+ return put_luaObjectonTop();
+}
+
+
+lua_Object lua_rawgettable (void)
+{
+ checkCparams(2);
+ if (ttype(L->stack.top-2) != LUA_T_ARRAY)
+ lua_error("indexed expression not a table in rawgettable");
+ else {
+ TObject *h = luaH_get(avalue(L->stack.top-2), L->stack.top-1);
+ --L->stack.top;
+ if (h != NULL)
+ *(L->stack.top-1) = *h;
+ else
+ ttype(L->stack.top-1) = LUA_T_NIL;
+ }
+ return put_luaObjectonTop();
+}
+
+
+void lua_settable (void)
+{
+ checkCparams(3);
+ luaV_settable(L->stack.top-3, 1);
+}
+
+
+void lua_rawsettable (void)
+{
+ checkCparams(3);
+ luaV_settable(L->stack.top-3, 0);
+}
+
+
+lua_Object lua_createtable (void)
+{
+ TObject o;
+ luaC_checkGC();
+ avalue(&o) = luaH_new(0);
+ ttype(&o) = LUA_T_ARRAY;
+ return put_luaObject(&o);
+}
+
+
+lua_Object lua_getglobal (char *name)
+{
+ luaD_checkstack(2); /* may need that to call T.M. */
+ luaV_getglobal(luaS_new(name));
+ return put_luaObjectonTop();
+}
+
+
+lua_Object lua_rawgetglobal (char *name)
+{
+ TaggedString *ts = luaS_new(name);
+ return put_luaObject(&ts->u.s.globalval);
+}
+
+
+void lua_setglobal (char *name)
+{
+ checkCparams(1);
+ luaD_checkstack(2); /* may need that to call T.M. */
+ luaV_setglobal(luaS_new(name));
+}
+
+
+void lua_rawsetglobal (char *name)
+{
+ TaggedString *ts = luaS_new(name);
+ checkCparams(1);
+ luaS_rawsetglobal(ts, --L->stack.top);
+}
+
+
+
+int lua_isnil (lua_Object o)
+{
+ return (o == LUA_NOOBJECT) || (ttype(Address(o)) == LUA_T_NIL);
+}
+
+int lua_istable (lua_Object o)
+{
+ return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY);
+}
+
+int lua_isuserdata (lua_Object o)
+{
+ return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA);
+}
+
+int lua_iscfunction (lua_Object o)
+{
+ return (lua_tag(o) == LUA_T_CPROTO);
+}
+
+int lua_isnumber (lua_Object o)
+{
+ return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0);
+}
+
+int lua_isstring (lua_Object o)
+{
+ int t = lua_tag(o);
+ return (t == LUA_T_STRING) || (t == LUA_T_NUMBER);
+}
+
+int lua_isfunction (lua_Object o)
+{
+ int t = lua_tag(o);
+ return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO);
+}
+
+
+double lua_getnumber (lua_Object object)
+{
+ if (object == LUA_NOOBJECT) return 0.0;
+ if (tonumber(Address(object))) return 0.0;
+ else return (nvalue(Address(object)));
+}
+
+char *lua_getstring (lua_Object object)
+{
+ luaC_checkGC(); /* "tostring" may create a new string */
+ if (object == LUA_NOOBJECT || tostring(Address(object)))
+ return NULL;
+ else return (svalue(Address(object)));
+}
+
+long lua_strlen (lua_Object object)
+{
+ luaC_checkGC(); /* "tostring" may create a new string */
+ if (object == LUA_NOOBJECT || tostring(Address(object)))
+ return 0L;
+ else return (tsvalue(Address(object))->u.s.len);
+}
+
+void *lua_getuserdata (lua_Object object)
+{
+ if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
+ return NULL;
+ else return tsvalue(Address(object))->u.d.v;
+}
+
+lua_CFunction lua_getcfunction (lua_Object object)
+{
+ if (!lua_iscfunction(object))
+ return NULL;
+ else return fvalue(luaA_protovalue(Address(object)));
+}
+
+
+void lua_pushnil (void)
+{
+ ttype(L->stack.top) = LUA_T_NIL;
+ incr_top;
+}
+
+void lua_pushnumber (double n)
+{
+ ttype(L->stack.top) = LUA_T_NUMBER;
+ nvalue(L->stack.top) = (real)n;
+ incr_top;
+}
+
+void lua_pushlstring (char *s, long len)
+{
+ tsvalue(L->stack.top) = luaS_newlstr(s, len);
+ ttype(L->stack.top) = LUA_T_STRING;
+ incr_top;
+ luaC_checkGC();
+}
+
+void lua_pushstring (char *s)
+{
+ if (s == NULL)
+ lua_pushnil();
+ else
+ lua_pushlstring(s, strlen(s));
+}
+
+void lua_pushcclosure (lua_CFunction fn, int n)
+{
+ if (fn == NULL)
+ lua_error("API error - attempt to push a NULL Cfunction");
+ checkCparams(n);
+ ttype(L->stack.top) = LUA_T_CPROTO;
+ fvalue(L->stack.top) = fn;
+ incr_top;
+ luaV_closure(n);
+ luaC_checkGC();
+}
+
+void lua_pushusertag (void *u, int tag)
+{
+ if (tag < 0 && tag != LUA_ANYTAG)
+ luaT_realtag(tag); /* error if tag is not valid */
+ tsvalue(L->stack.top) = luaS_createudata(u, tag);
+ ttype(L->stack.top) = LUA_T_USERDATA;
+ incr_top;
+ luaC_checkGC();
+}
+
+void luaA_pushobject (TObject *o)
+{
+ *L->stack.top = *o;
+ incr_top;
+}
+
+void lua_pushobject (lua_Object o)
+{
+ if (o == LUA_NOOBJECT)
+ lua_error("API error - attempt to push a NOOBJECT");
+ else {
+ set_normalized(L->stack.top, Address(o));
+ incr_top;
+ }
+}
+
+
+int lua_tag (lua_Object lo)
+{
+ if (lo == LUA_NOOBJECT)
+ return LUA_T_NIL;
+ else {
+ TObject *o = Address(lo);
+ int t;
+ switch (t = ttype(o)) {
+ case LUA_T_USERDATA:
+ return o->value.ts->u.d.tag;
+ case LUA_T_ARRAY:
+ return o->value.a->htag;
+ case LUA_T_PMARK:
+ return LUA_T_PROTO;
+ case LUA_T_CMARK:
+ return LUA_T_CPROTO;
+ case LUA_T_CLOSURE: case LUA_T_CLMARK:
+ return o->value.cl->consts[0].ttype;
+#ifdef DEBUG
+ case LUA_T_LINE:
+ LUA_INTERNALERROR("invalid type");
+#endif
+ default:
+ return t;
+ }
+ }
+}
+
+
+void lua_settag (int tag)
+{
+ checkCparams(1);
+ luaT_realtag(tag);
+ switch (ttype(L->stack.top-1)) {
+ case LUA_T_ARRAY:
+ (L->stack.top-1)->value.a->htag = tag;
+ break;
+ case LUA_T_USERDATA:
+ (L->stack.top-1)->value.ts->u.d.tag = tag;
+ break;
+ default:
+ luaL_verror("cannot change the tag of a %.20s",
+ luaO_typenames[-ttype((L->stack.top-1))]);
+ }
+ L->stack.top--;
+}
+
+
+/*
+** =======================================================
+** Debug interface
+** =======================================================
+*/
+
+
+/* Hooks */
+lua_CHFunction lua_callhook = NULL;
+lua_LHFunction lua_linehook = NULL;
+
+
+lua_Function lua_stackedfunction (int level)
+{
+ StkId i;
+ for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) {
+ int t = L->stack.stack[i].ttype;
+ if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK)
+ if (level-- == 0)
+ return Ref(L->stack.stack+i);
+ }
+ return LUA_NOOBJECT;
+}
+
+
+int lua_currentline (lua_Function func)
+{
+ TObject *f = Address(func);
+ return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ?
+ (f+1)->value.i : -1;
+}
+
+
+lua_Object lua_getlocal (lua_Function func, int local_number, char **name)
+{
+ /* check whether func is a Lua function */
+ if (lua_tag(func) != LUA_T_PROTO)
+ return LUA_NOOBJECT;
+ else {
+ TObject *f = Address(func);
+ TProtoFunc *fp = luaA_protovalue(f)->value.tf;
+ *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
+ if (*name) {
+ /* if "*name", there must be a LUA_T_LINE */
+ /* therefore, f+2 points to function base */
+ return Ref((f+2)+(local_number-1));
+ }
+ else
+ return LUA_NOOBJECT;
+ }
+}
+
+
+int lua_setlocal (lua_Function func, int local_number)
+{
+ /* check whether func is a Lua function */
+ if (lua_tag(func) != LUA_T_PROTO)
+ return 0;
+ else {
+ TObject *f = Address(func);
+ TProtoFunc *fp = luaA_protovalue(f)->value.tf;
+ char *name = luaF_getlocalname(fp, local_number, lua_currentline(func));
+ checkCparams(1);
+ --L->stack.top;
+ if (name) {
+ /* if "name", there must be a LUA_T_LINE */
+ /* therefore, f+2 points to function base */
+ *((f+2)+(local_number-1)) = *L->stack.top;
+ return 1;
+ }
+ else
+ return 0;
+ }
+}
+
+
+void lua_funcinfo (lua_Object func, char **filename, int *linedefined)
+{
+ if (!lua_isfunction(func))
+ lua_error("API - `funcinfo' called with a non-function value");
+ else {
+ TObject *f = luaA_protovalue(Address(func));
+ if (normalized_type(f) == LUA_T_PROTO) {
+ *filename = tfvalue(f)->fileName->str;
+ *linedefined = tfvalue(f)->lineDefined;
+ }
+ else {
+ *filename = "(C)";
+ *linedefined = -1;
+ }
+ }
+}
+
+
+static int checkfunc (TObject *o)
+{
+ return luaO_equalObj(o, L->stack.top);
+}
+
+
+char *lua_getobjname (lua_Object o, char **name)
+{ /* try to find a name for given function */
+ set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc */
+ if ((*name = luaT_travtagmethods(checkfunc)) != NULL)
+ return "tag-method";
+ else if ((*name = luaS_travsymbol(checkfunc)) != NULL)
+ return "global";
+ else return "";
+}
+
+/*
+** =======================================================
+** BLOCK mechanism
+** =======================================================
+*/
+
+
+void lua_beginblock (void)
+{
+ if (L->numCblocks >= MAX_C_BLOCKS)
+ lua_error("too many nested blocks");
+ L->Cblocks[L->numCblocks] = L->Cstack;
+ L->numCblocks++;
+}
+
+void lua_endblock (void)
+{
+ --L->numCblocks;
+ L->Cstack = L->Cblocks[L->numCblocks];
+ luaD_adjusttop(L->Cstack.base);
+}
+
+
+
+int lua_ref (int lock)
+{
+ int ref;
+ checkCparams(1);
+ ref = luaC_ref(L->stack.top-1, lock);
+ L->stack.top--;
+ return ref;
+}
+
+
+
+lua_Object lua_getref (int ref)
+{
+ TObject *o = luaC_getref(ref);
+ return (o ? put_luaObject(o) : LUA_NOOBJECT);
+}
+
+
+/*
+** =======================================================
+** Derived functions
+** =======================================================
+*/
+int (lua_call) (char *name) { return lua_call(name); }
+
+void (lua_pushref) (int ref) { lua_pushref(ref); }
+
+int (lua_refobject) (lua_Object o, int l) { return lua_refobject(o, l); }
+
+void (lua_register) (char *n, lua_CFunction f) { lua_register(n, f); }
+
+void (lua_pushuserdata) (void *u) { lua_pushuserdata(u); }
+
+void (lua_pushcfunction) (lua_CFunction f) { lua_pushcfunction(f); }
+
+int (lua_clonetag) (int t) { return lua_clonetag(t); }
+
+
+
+
+#ifdef LUA_COMPAT2_5
+/*
+** API: set a function as a fallback
+*/
+
+static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults)
+{
+ StkId base = (L->stack.top-L->stack.stack)-nParams;
+ luaD_openstack(nParams);
+ L->stack.stack[base].ttype = LUA_T_CPROTO;
+ L->stack.stack[base].value.f = f;
+ luaD_call(base+1, nResults);
+}
+
+lua_Object lua_setfallback (char *name, lua_CFunction fallback)
+{
+ lua_pushstring(name);
+ lua_pushcfunction(fallback);
+ do_unprotectedrun(luaT_setfallback, 2, 1);
+ return put_luaObjectonTop();
+}
+#endif
+
diff --git a/tools/lua/lapi.h b/tools/lua/lapi.h
new file mode 100644
index 000000000..d3d5a6977
--- /dev/null
+++ b/tools/lua/lapi.h
@@ -0,0 +1,20 @@
+/*
+** $Id$
+** Auxiliary functions from Lua API
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lapi_h
+#define lapi_h
+
+
+#include "lua.h"
+#include "lobject.h"
+
+
+TObject *luaA_Address (lua_Object o);
+void luaA_pushobject (TObject *o);
+void luaA_packresults (void);
+int luaA_passresults (void);
+
+#endif
diff --git a/tools/lua/lauxlib.cpp b/tools/lua/lauxlib.cpp
new file mode 100644
index 000000000..08be69eb2
--- /dev/null
+++ b/tools/lua/lauxlib.cpp
@@ -0,0 +1,132 @@
+/*
+** $Id$
+** Auxiliary functions for building Lua libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Please Notice: This file uses only the official API of Lua
+** Any function declared here could be written as an application
+** function. With care, these functions can be used by other libraries.
+*/
+#include "lauxlib.h"
+#include "lua.h"
+#include "luadebug.h"
+#include "lmem.h"
+
+
+int luaL_findstring (char *name, char *list[]) {
+ int i;
+ for (i=0; list[i]; i++)
+ if (strcmp(list[i], name) == 0)
+ return i;
+ return -1; /* name not found */
+}
+
+void luaL_argerror (int numarg, char *extramsg)
+{
+ char *funcname;
+ lua_getobjname(lua_stackedfunction(0), &funcname);
+ if (funcname == NULL)
+ funcname = "???";
+ if (extramsg == NULL)
+ luaL_verror("bad argument #%d to function `%.50s'", numarg, funcname);
+ else
+ luaL_verror("bad argument #%d to function `%.50s' (%.100s)",
+ numarg, funcname, extramsg);
+}
+
+char *luaL_check_lstr (int numArg, long *len)
+{
+ lua_Object o = lua_getparam(numArg);
+ luaL_arg_check(lua_isstring(o), numArg, "string expected");
+ if (len) *len = lua_strlen(o);
+ return lua_getstring(o);
+}
+
+char *luaL_opt_lstr (int numArg, char *def, long *len)
+{
+ return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
+ luaL_check_lstr(numArg, len);
+}
+
+double luaL_check_number (int numArg)
+{
+ lua_Object o = lua_getparam(numArg);
+ luaL_arg_check(lua_isnumber(o), numArg, "number expected");
+ return lua_getnumber(o);
+}
+
+
+double luaL_opt_number (int numArg, double def)
+{
+ return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
+ luaL_check_number(numArg);
+}
+
+
+lua_Object luaL_tablearg (int arg)
+{
+ lua_Object o = lua_getparam(arg);
+ luaL_arg_check(lua_istable(o), arg, "table expected");
+ return o;
+}
+
+lua_Object luaL_functionarg (int arg)
+{
+ lua_Object o = lua_getparam(arg);
+ luaL_arg_check(lua_isfunction(o), arg, "function expected");
+ return o;
+}
+
+lua_Object luaL_nonnullarg (int numArg)
+{
+ lua_Object o = lua_getparam(numArg);
+ luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
+ return o;
+}
+
+luaL_libList *list_of_libs = NULL;
+
+void luaL_addlibtolist(luaL_reg *l, int n) {
+ luaL_libList *list = (luaL_libList *)luaM_malloc(sizeof(luaL_libList));
+ list->list = l;
+ list->number = n;
+ list->next = list_of_libs;
+ list_of_libs = list;
+}
+
+void lua_removelibslists(void) {
+ luaL_libList *list = list_of_libs;
+ while (list) {
+ luaL_libList *nextList = list->next;
+ luaM_free(list);
+ list = nextList;
+ }
+}
+
+void luaL_openlib (struct luaL_reg *l, int n)
+{
+ int i;
+ lua_open(); /* make sure lua is already open */
+ for (i=0; i<n; i++)
+ lua_register(l[i].name, l[i].func);
+ luaL_addlibtolist(l, n);
+}
+
+
+void luaL_verror (char *fmt, ...)
+{
+ char buff[500];
+ va_list argp;
+ va_start(argp, fmt);
+ vsprintf(buff, fmt, argp);
+ va_end(argp);
+ lua_error(buff);
+}
+
diff --git a/tools/lua/lauxlib.h b/tools/lua/lauxlib.h
new file mode 100644
index 000000000..15a8c99ae
--- /dev/null
+++ b/tools/lua/lauxlib.h
@@ -0,0 +1,55 @@
+/*
+** $Id$
+** Auxiliary functions for building Lua libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef auxlib_h
+#define auxlib_h
+
+
+#include "lua.h"
+
+
+struct luaL_reg {
+ char *name;
+ lua_CFunction func;
+};
+
+struct luaL_libList {
+ luaL_reg *list;
+ int number;
+ luaL_libList *next;
+};
+
+extern luaL_libList *list_of_libs;
+
+#define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \
+ luaL_argerror(numarg,extramsg)
+
+void luaL_openlib (struct luaL_reg *l, int n);
+void luaL_addlibtolist(luaL_reg *l, int n);
+void luaL_argerror (int numarg, char *extramsg);
+#define luaL_check_string(n) (luaL_check_lstr((n), NULL))
+char *luaL_check_lstr (int numArg, long *len);
+#define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL))
+char *luaL_opt_lstr (int numArg, char *def, long *len);
+double luaL_check_number (int numArg);
+double luaL_opt_number (int numArg, double def);
+lua_Object luaL_functionarg (int arg);
+lua_Object luaL_tablearg (int arg);
+lua_Object luaL_nonnullarg (int numArg);
+void luaL_verror (char *fmt, ...);
+char *luaL_openspace (int size);
+void luaL_resetbuffer (void);
+void luaL_addchar (int c);
+int luaL_getsize (void);
+void luaL_addsize (int n);
+int luaL_newbuffer (int size);
+void luaL_oldbuffer (int old);
+char *luaL_buffer (void);
+int luaL_findstring (char *name, char *list[]);
+
+
+#endif
diff --git a/tools/lua/lbuffer.cpp b/tools/lua/lbuffer.cpp
new file mode 100644
index 000000000..bf491cf03
--- /dev/null
+++ b/tools/lua/lbuffer.cpp
@@ -0,0 +1,85 @@
+/*
+** $Id$
+** Auxiliary functions for building Lua libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#include <stdio.h>
+
+#include "lauxlib.h"
+#include "lmem.h"
+#include "lstate.h"
+
+
+/*-------------------------------------------------------
+** Auxiliary buffer
+-------------------------------------------------------*/
+
+#define BUFF_STEP 32
+
+#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
+
+static void Openspace (int size)
+{
+ lua_State *l = L; /* to optimize */
+ int base = l->Mbuffbase-l->Mbuffer;
+ l->Mbuffsize *= 2;
+ if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */
+ l->Mbuffsize = l->Mbuffnext+size;
+ l->Mbuffer = (char *)luaM_realloc(l->Mbuffer, l->Mbuffsize);
+ l->Mbuffbase = l->Mbuffer+base;
+}
+
+
+char *luaL_openspace (int size)
+{
+ openspace(size);
+ return L->Mbuffer+L->Mbuffnext;
+}
+
+
+void luaL_addchar (int c)
+{
+ openspace(BUFF_STEP);
+ L->Mbuffer[L->Mbuffnext++] = c;
+}
+
+
+void luaL_resetbuffer (void)
+{
+ L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
+}
+
+
+void luaL_addsize (int n)
+{
+ L->Mbuffnext += n;
+}
+
+int luaL_getsize (void)
+{
+ return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer);
+}
+
+int luaL_newbuffer (int size)
+{
+ int old = L->Mbuffbase-L->Mbuffer;
+ openspace(size);
+ L->Mbuffbase = L->Mbuffer+L->Mbuffnext;
+ return old;
+}
+
+
+void luaL_oldbuffer (int old)
+{
+ L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
+ L->Mbuffbase = L->Mbuffer+old;
+}
+
+
+char *luaL_buffer (void)
+{
+ return L->Mbuffbase;
+}
+
diff --git a/tools/lua/lbuiltin.cpp b/tools/lua/lbuiltin.cpp
new file mode 100644
index 000000000..4ab614299
--- /dev/null
+++ b/tools/lua/lbuiltin.cpp
@@ -0,0 +1,538 @@
+/*
+** $Id$
+** Built-in functions
+** See Copyright Notice in lua.h
+*/
+
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "lapi.h"
+#include "lauxlib.h"
+#include "lbuiltin.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "ltask.h"
+#include "ltm.h"
+#include "lua.h"
+#include "lundump.h"
+
+
+
+static void pushstring (TaggedString *s)
+{
+ TObject o;
+ o.ttype = LUA_T_STRING;
+ o.value.ts = s;
+ luaA_pushobject(&o);
+}
+
+
+static void nextvar (void)
+{
+ TObject *o = luaA_Address(luaL_nonnullarg(1));
+ TaggedString *g;
+ if (ttype(o) == LUA_T_NIL)
+ g = (TaggedString *)L->rootglobal.next;
+ else {
+ luaL_arg_check(ttype(o) == LUA_T_STRING, 1, "variable name expected");
+ g = tsvalue(o);
+ /* check whether name is in global var list */
+ luaL_arg_check((GCnode *)g != g->head.next, 1, "variable name expected");
+ g = (TaggedString *)g->head.next;
+ }
+ while (g && g->u.s.globalval.ttype == LUA_T_NIL) /* skip globals with nil */
+ g = (TaggedString *)g->head.next;
+ if (g) {
+ pushstring(g);
+ luaA_pushobject(&g->u.s.globalval);
+ }
+ else lua_pushnil();
+}
+
+
+static void foreachvar (void)
+{
+ TObject f = *luaA_Address(luaL_functionarg(1));
+ GCnode *g;
+ StkId name = L->Cstack.base++; /* place to keep var name (to avoid GC) */
+ ttype(L->stack.stack+name) = LUA_T_NIL;
+ L->stack.top++;
+ for (g = L->rootglobal.next; g; g = g->next) {
+ TaggedString *s = (TaggedString *)g;
+ if (s->u.s.globalval.ttype != LUA_T_NIL) {
+ ttype(L->stack.stack+name) = LUA_T_STRING;
+ tsvalue(L->stack.stack+name) = s; /* keep s on stack to avoid GC */
+ luaA_pushobject(&f);
+ pushstring(s);
+ luaA_pushobject(&s->u.s.globalval);
+ luaD_call((L->stack.top-L->stack.stack)-2, 1);
+ if (ttype(L->stack.top-1) != LUA_T_NIL)
+ return;
+ L->stack.top--;
+ }
+ }
+}
+
+
+static void next (void)
+{
+ lua_Object o = luaL_tablearg(1);
+ lua_Object r = luaL_nonnullarg(2);
+ Node *n = luaH_next(luaA_Address(o), luaA_Address(r));
+ if (n) {
+ luaA_pushobject(&n->ref);
+ luaA_pushobject(&n->val);
+ }
+ else lua_pushnil();
+}
+
+
+static void foreach (void)
+{
+ TObject t = *luaA_Address(luaL_tablearg(1));
+ TObject f = *luaA_Address(luaL_functionarg(2));
+ int i;
+ for (i=0; i<avalue(&t)->nhash; i++) {
+ Node *nd = &(avalue(&t)->node[i]);
+ if (ttype(ref(nd)) != LUA_T_NIL && ttype(val(nd)) != LUA_T_NIL) {
+ luaA_pushobject(&f);
+ luaA_pushobject(ref(nd));
+ luaA_pushobject(val(nd));
+ luaD_call((L->stack.top-L->stack.stack)-2, 1);
+ if (ttype(L->stack.top-1) != LUA_T_NIL)
+ return;
+ L->stack.top--;
+ }
+ }
+}
+
+
+static void internaldostring (void)
+{
+ long l;
+ char *s = luaL_check_lstr(1, &l);
+ if (*s == ID_CHUNK)
+ lua_error("`dostring' cannot run pre-compiled code");
+ if (lua_dobuffer(s, l, luaL_opt_string(2, NULL)) == 0)
+ if (luaA_passresults() == 0)
+ lua_pushuserdata(NULL); /* at least one result to signal no errors */
+}
+
+
+static void internaldofile (void)
+{
+ char *fname = luaL_opt_string(1, NULL);
+ if (lua_dofile(fname) == 0)
+ if (luaA_passresults() == 0)
+ lua_pushuserdata(NULL); /* at least one result to signal no errors */
+}
+
+
+static void to_string (void) {
+ lua_Object obj = lua_getparam(1);
+ char *buff = luaL_openspace(30);
+ TObject *o = luaA_Address(obj);
+ switch (ttype(o)) {
+ case LUA_T_NUMBER:
+ lua_pushstring(lua_getstring(obj));
+ return;
+ case LUA_T_STRING:
+ lua_pushobject(obj);
+ return;
+ case LUA_T_ARRAY: {
+ sprintf(buff, "table: %p", (void *)o->value.a);
+ break;
+ }
+ case LUA_T_CLOSURE: {
+ sprintf(buff, "function: %p", (void *)o->value.cl);
+ break;
+ }
+ case LUA_T_PROTO: {
+ sprintf(buff, "function: %p", (void *)o->value.tf);
+ break;
+ }
+ case LUA_T_CPROTO: {
+ sprintf(buff, "function: %p", (void *)o->value.f);
+ break;
+ }
+ case LUA_T_USERDATA: {
+ sprintf(buff, "userdata: %p", o->value.ts->u.d.v);
+ break;
+ }
+ case LUA_T_TASK: {
+ sprintf(buff, "task: %d", (int)o->value.n);
+ break;
+ }
+ case LUA_T_NIL:
+ lua_pushstring("nil");
+ return;
+ default:
+ LUA_INTERNALERROR("invalid type");
+ }
+ lua_pushstring(buff);
+}
+
+
+static void luaI_print (void) {
+ TaggedString *ts = luaS_new("tostring");
+ lua_Object obj;
+ int i = 1;
+ while ((obj = lua_getparam(i++)) != LUA_NOOBJECT) {
+ luaA_pushobject(&ts->u.s.globalval);
+ lua_pushobject(obj);
+ luaD_call((L->stack.top-L->stack.stack)-1, 1);
+ if (ttype(L->stack.top-1) != LUA_T_STRING)
+ lua_error("`tostring' must return a string to `print'");
+ printf("%s\t", svalue(L->stack.top-1));
+ L->stack.top--;
+ }
+ printf("\n");
+}
+
+
+static void luaI_type (void)
+{
+ lua_Object o = luaL_nonnullarg(1);
+ lua_pushstring(luaO_typenames[-ttype(luaA_Address(o))]);
+ lua_pushnumber(lua_tag(o));
+}
+
+
+static void tonumber (void)
+{
+ int base = (int)luaL_opt_number(2, 10);
+ if (base == 10) { /* standard conversion */
+ lua_Object o = lua_getparam(1);
+ if (lua_isnumber(o))
+ lua_pushnumber(lua_getnumber(o));
+ }
+ else {
+ char *s = luaL_check_string(1);
+ unsigned long n;
+ luaL_arg_check(0 <= base && base <= 36, 2, "base out of range");
+ n = strtol(s, &s, base);
+ while (isspace(*s)) s++; /* skip trailing spaces */
+ if (*s) lua_pushnil(); /* invalid format: return nil */
+ else lua_pushnumber(n);
+ }
+}
+
+
+static void luaI_error (void)
+{
+ lua_error(lua_getstring(lua_getparam(1)));
+}
+
+
+static void luaI_assert (void)
+{
+ lua_Object p = lua_getparam(1);
+ if (p == LUA_NOOBJECT || lua_isnil(p))
+ luaL_verror("assertion failed! %.100s", luaL_opt_string(2, ""));
+}
+
+
+static void setglobal (void)
+{
+ char *n = luaL_check_string(1);
+ lua_Object value = luaL_nonnullarg(2);
+ lua_pushobject(value);
+ lua_setglobal(n);
+ lua_pushobject(value); /* return given value */
+}
+
+static void rawsetglobal (void)
+{
+ char *n = luaL_check_string(1);
+ lua_Object value = luaL_nonnullarg(2);
+ lua_pushobject(value);
+ lua_rawsetglobal(n);
+ lua_pushobject(value); /* return given value */
+}
+
+static void getglobal (void)
+{
+ lua_pushobject(lua_getglobal(luaL_check_string(1)));
+}
+
+static void rawgetglobal (void)
+{
+ lua_pushobject(lua_rawgetglobal(luaL_check_string(1)));
+}
+
+static void luatag (void)
+{
+ lua_pushnumber(lua_tag(lua_getparam(1)));
+}
+
+
+static int getnarg (lua_Object table)
+{
+ lua_Object temp;
+ /* temp = table.n */
+ lua_pushobject(table); lua_pushstring("n"); temp = lua_rawgettable();
+ return (lua_isnumber(temp) ? (int)lua_getnumber(temp) : MAX_INT);
+}
+
+static void luaI_call (void)
+{
+ lua_Object f = luaL_nonnullarg(1);
+ lua_Object arg = luaL_tablearg(2);
+ char *options = luaL_opt_string(3, "");
+ lua_Object err = lua_getparam(4);
+ int narg = getnarg(arg);
+ int i, status;
+ if (err != LUA_NOOBJECT) { /* set new error method */
+ lua_pushobject(err);
+ err = lua_seterrormethod();
+ }
+ /* push arg[1...n] */
+ for (i=0; i<narg; i++) {
+ lua_Object temp;
+ /* temp = arg[i+1] */
+ lua_pushobject(arg); lua_pushnumber(i+1); temp = lua_rawgettable();
+ if (narg == MAX_INT && lua_isnil(temp))
+ break;
+ lua_pushobject(temp);
+ }
+ status = lua_callfunction(f);
+ if (err != LUA_NOOBJECT) { /* restore old error method */
+ lua_pushobject(err);
+ lua_seterrormethod();
+ }
+ if (status != 0) { /* error in call? */
+ if (strchr(options, 'x')) {
+ lua_pushnil();
+ return; /* return nil to signal the error */
+ }
+ else
+ lua_error(NULL);
+ }
+ else { /* no errors */
+ if (strchr(options, 'p'))
+ luaA_packresults();
+ else
+ luaA_passresults();
+ }
+}
+
+
+static void settag (void)
+{
+ lua_Object o = luaL_tablearg(1);
+ lua_pushobject(o);
+ lua_settag((int)luaL_check_number(2));
+ lua_pushobject(o); /* returns first argument */
+}
+
+
+static void newtag (void)
+{
+ lua_pushnumber(lua_newtag());
+}
+
+
+static void copytagmethods (void)
+{
+ lua_pushnumber(lua_copytagmethods((int)luaL_check_number(1),
+ (int)luaL_check_number(2)));
+}
+
+
+static void rawgettable (void)
+{
+ lua_pushobject(luaL_nonnullarg(1));
+ lua_pushobject(luaL_nonnullarg(2));
+ lua_pushobject(lua_rawgettable());
+}
+
+
+static void rawsettable (void)
+{
+ lua_pushobject(luaL_nonnullarg(1));
+ lua_pushobject(luaL_nonnullarg(2));
+ lua_pushobject(luaL_nonnullarg(3));
+ lua_rawsettable();
+}
+
+
+static void settagmethod (void)
+{
+ lua_Object nf = luaL_nonnullarg(3);
+ lua_pushobject(nf);
+ lua_pushobject(lua_settagmethod((int)luaL_check_number(1),
+ luaL_check_string(2)));
+}
+
+
+static void gettagmethod (void)
+{
+ lua_pushobject(lua_gettagmethod((int)luaL_check_number(1),
+ luaL_check_string(2)));
+}
+
+
+static void seterrormethod (void)
+{
+ lua_Object nf = luaL_functionarg(1);
+ lua_pushobject(nf);
+ lua_pushobject(lua_seterrormethod());
+}
+
+
+static void luaI_collectgarbage (void)
+{
+ lua_pushnumber(lua_collectgarbage((long int)luaL_opt_number(1, 0)));
+}
+
+
+/*
+** =======================================================
+** some DEBUG functions
+** =======================================================
+*/
+#ifdef DEBUG
+
+static void mem_query (void)
+{
+ lua_pushnumber(totalmem);
+ lua_pushnumber(numblocks);
+}
+
+
+static void countlist (void)
+{
+ char *s = luaL_check_string(1);
+ GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next :
+ (s[0]=='p') ? L->rootproto.next : L->rootglobal.next;
+ int i=0;
+ while (l) {
+ i++;
+ l = l->next;
+ }
+ lua_pushnumber(i);
+}
+
+
+static void testC (void)
+{
+#define getnum(s) ((*s++) - '0')
+#define getname(s) (nome[0] = *s++, nome)
+
+ static int locks[10];
+ lua_Object reg[10];
+ char nome[2];
+ char *s = luaL_check_string(1);
+ nome[1] = 0;
+ while (1) {
+ switch (*s++) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ lua_pushnumber(*(s-1) - '0');
+ break;
+
+ case 'c': reg[getnum(s)] = lua_createtable(); break;
+ case 'C': { lua_CFunction f = lua_getcfunction(lua_getglobal(getname(s)));
+ lua_pushcclosure(f, getnum(s));
+ break;
+ }
+ case 'P': reg[getnum(s)] = lua_pop(); break;
+ case 'g': { int n=getnum(s); reg[n]=lua_getglobal(getname(s)); break; }
+ case 'G': { int n = getnum(s);
+ reg[n] = lua_rawgetglobal(getname(s));
+ break;
+ }
+ case 'l': locks[getnum(s)] = lua_ref(1); break;
+ case 'L': locks[getnum(s)] = lua_ref(0); break;
+ case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; }
+ case 'u': lua_unref(locks[getnum(s)]); break;
+ case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; }
+ case '=': lua_setglobal(getname(s)); break;
+ case 's': lua_pushstring(getname(s)); break;
+ case 'o': lua_pushobject(reg[getnum(s)]); break;
+ case 'f': (lua_call)(getname(s)); break;
+ case 'i': reg[getnum(s)] = lua_gettable(); break;
+ case 'I': reg[getnum(s)] = lua_rawgettable(); break;
+ case 't': lua_settable(); break;
+ case 'T': lua_rawsettable(); break;
+ default: luaL_verror("unknown command in `testC': %c", *(s-1));
+ }
+ if (*s == 0) return;
+ if (*s++ != ' ') lua_error("missing ` ' between commands in `testC'");
+ }
+}
+
+#endif
+
+
+/*
+** Internal functions
+*/
+static struct luaL_reg int_funcs[] = {
+#ifdef LUA_COMPAT2_5
+ {"setfallback", luaT_setfallback},
+#endif
+#ifdef DEBUG
+ {"testC", testC},
+ {"totalmem", mem_query},
+ {"count", countlist},
+#endif
+ {"assert", luaI_assert},
+ {"call", luaI_call},
+ {"collectgarbage", luaI_collectgarbage},
+ {"dofile", internaldofile},
+ {"copytagmethods", copytagmethods},
+ {"dostring", internaldostring},
+ {"error", luaI_error},
+ {"foreach", foreach},
+ {"foreachvar", foreachvar},
+ {"getglobal", getglobal},
+ {"newtag", newtag},
+ {"next", next},
+ {"nextvar", nextvar},
+ {"print", luaI_print},
+ {"rawgetglobal", rawgetglobal},
+ {"rawgettable", rawgettable},
+ {"rawsetglobal", rawsetglobal},
+ {"rawsettable", rawsettable},
+ {"seterrormethod", seterrormethod},
+ {"setglobal", setglobal},
+ {"settagmethod", settagmethod},
+ {"gettagmethod", gettagmethod},
+ {"settag", settag},
+ {"tonumber", tonumber},
+ {"tostring", to_string},
+ {"tag", luatag},
+ {"type", luaI_type},
+ {"start_script", start_script},
+ {"stop_script", stop_script},
+ {"next_script", next_script},
+ {"identify_script", identify_script},
+ {"pause_scripts", pause_scripts},
+ {"unpause_scripts", unpause_scripts},
+ {"find_script", find_script},
+ {"break_here", break_here}
+};
+
+
+#define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0]))
+
+void luaB_predefine (void)
+{
+ /* pre-register mem error messages, to avoid loop when error arises */
+ luaS_newfixedstring(tableEM);
+ luaS_newfixedstring(memEM);
+ luaL_openlib(int_funcs, (sizeof(int_funcs)/sizeof(int_funcs[0])));
+ lua_pushstring(LUA_VERSION);
+ lua_setglobal("_VERSION");
+}
+
diff --git a/tools/lua/lbuiltin.h b/tools/lua/lbuiltin.h
new file mode 100644
index 000000000..81762c4c8
--- /dev/null
+++ b/tools/lua/lbuiltin.h
@@ -0,0 +1,14 @@
+/*
+** $Id$
+** Built-in functions
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lbuiltin_h
+#define lbuiltin_h
+
+
+void luaB_predefine (void);
+
+
+#endif
diff --git a/tools/lua/ldo.cpp b/tools/lua/ldo.cpp
new file mode 100644
index 000000000..a34eabfd8
--- /dev/null
+++ b/tools/lua/ldo.cpp
@@ -0,0 +1,528 @@
+/*
+** $Id$
+** Stack and Call structure of Lua
+** See Copyright Notice in lua.h
+*/
+
+
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.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 "ltask.h"
+#include "ltm.h"
+#include "lua.h"
+#include "luadebug.h"
+#include "lundump.h"
+#include "lvm.h"
+#include "lzio.h"
+
+
+
+#ifndef STACK_LIMIT
+#define STACK_LIMIT 6000
+#endif
+
+
+
+/* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */
+#define EXTRA_STACK 5
+
+
+/*
+** Error messages
+*/
+
+void stderrorim (void)
+{
+ fprintf(stderr, "lua error: %s\n", lua_getstring(lua_getparam(1)));
+}
+
+
+
+#define STACK_UNIT 128
+
+/* Initial size for CallInfo array */
+#define BASIC_CI_SIZE 8
+
+void luaD_init (void)
+{
+ ttype(&L->errorim) = LUA_T_CPROTO;
+ fvalue(&L->errorim) = stderrorim;
+}
+
+void luaD_initthr (void)
+{
+ L->stack.stack = luaM_newvector(STACK_UNIT, TObject);
+ L->stack.top = L->stack.stack;
+ L->stack.last = L->stack.stack+(STACK_UNIT-1);
+ L->base_ci = luaM_newvector(BASIC_CI_SIZE, struct CallInfo);
+ memset(L->base_ci, 0, sizeof(CallInfo) * BASIC_CI_SIZE);
+ L->base_ci_size = sizeof(CallInfo) * BASIC_CI_SIZE;
+ L->ci = L->base_ci;
+ L->ci->tf = NULL;
+ L->end_ci = L->base_ci + BASIC_CI_SIZE;
+}
+
+
+void luaD_checkstack (int n)
+{
+ struct Stack *S = &L->stack;
+ if (S->last-S->top <= n) {
+ StkId top = S->top-S->stack;
+ int stacksize = (S->last-S->stack)+1+STACK_UNIT+n;
+ S->stack = luaM_reallocvector(S->stack, stacksize, TObject);
+ S->last = S->stack+(stacksize-1);
+ S->top = S->stack + top;
+ if (stacksize >= STACK_LIMIT) { /* stack overflow? */
+ if (lua_stackedfunction(100) == LUA_NOOBJECT) /* 100 funcs on stack? */
+ lua_error("Lua2C - C2Lua overflow"); /* doesn't look like a rec. loop */
+ else
+ lua_error("stack size overflow");
+ }
+ }
+}
+
+
+/*
+** Adjust stack. Set top to the given value, pushing NILs if needed.
+*/
+void luaD_adjusttop (StkId newtop)
+{
+ int diff = newtop-(L->stack.top-L->stack.stack);
+ if (diff <= 0)
+ L->stack.top += diff;
+ else {
+ luaD_checkstack(diff);
+ while (diff--)
+ ttype(L->stack.top++) = LUA_T_NIL;
+ }
+}
+
+
+/*
+** Open a hole below "nelems" from the L->stack.top.
+*/
+void luaD_openstack (int nelems)
+{
+ luaO_memup(L->stack.top-nelems+1, L->stack.top-nelems,
+ nelems*sizeof(TObject));
+ incr_top;
+}
+
+
+void luaD_lineHook (int line)
+{
+ struct C_Lua_Stack oldCLS = L->Cstack;
+ StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
+ L->Cstack.num = 0;
+ (*lua_linehook)(line);
+ L->stack.top = L->stack.stack+old_top;
+ L->Cstack = oldCLS;
+}
+
+
+void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn)
+{
+ struct C_Lua_Stack oldCLS = L->Cstack;
+ StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
+ L->Cstack.num = 0;
+ if (isreturn)
+ (*lua_callhook)(LUA_NOOBJECT, "(return)", 0);
+ else {
+ TObject *f = L->stack.stack+base-1;
+ if (tf)
+ (*lua_callhook)(Ref(f), tf->fileName->str, tf->lineDefined);
+ else
+ (*lua_callhook)(Ref(f), "(C)", -1);
+ }
+ L->stack.top = L->stack.stack+old_top;
+ L->Cstack = oldCLS;
+}
+
+
+/*
+** Call a C function.
+** Cstack.num is the number of arguments; Cstack.lua2C points to the
+** first argument. Returns an index to the first result from C.
+*/
+static StkId callC (lua_CFunction f, StkId base)
+{
+ struct C_Lua_Stack *CS = &L->Cstack;
+ struct C_Lua_Stack oldCLS = *CS;
+ StkId firstResult;
+ int numarg = (L->stack.top-L->stack.stack) - base;
+ CS->num = numarg;
+ CS->lua2C = base;
+ CS->base = base+numarg; /* == top-stack */
+ if (lua_callhook)
+ luaD_callHook(base, NULL, 0);
+ (*f)(); /* do the actual call */
+ if (lua_callhook) /* func may have changed lua_callhook */
+ luaD_callHook(base, NULL, 1);
+ firstResult = CS->base;
+ *CS = oldCLS;
+ return firstResult;
+}
+
+
+static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base)
+{
+ TObject *pbase;
+ int nup = cl->nelems; /* number of upvalues */
+ luaD_checkstack(nup);
+ pbase = L->stack.stack+base; /* care: previous call may change this */
+ /* open space for upvalues as extra arguments */
+ luaO_memup(pbase+nup, pbase, (L->stack.top-pbase)*sizeof(TObject));
+ /* copy upvalues into stack */
+ memcpy(pbase, cl->consts+1, nup*sizeof(TObject));
+ L->stack.top += nup;
+ return callC(f, base);
+}
+
+
+void luaD_callTM (TObject *f, int nParams, int nResults)
+{
+ luaD_openstack(nParams);
+ *(L->stack.top-nParams-1) = *f;
+ luaD_call((L->stack.top-L->stack.stack)-nParams, nResults);
+}
+
+static void adjust_varargs (StkId first_extra_arg)
+{
+ TObject arg;
+ luaV_pack(first_extra_arg,
+ (L->stack.top-L->stack.stack)-first_extra_arg, &arg);
+ luaD_adjusttop(first_extra_arg);
+ *L->stack.top++ = arg;
+}
+
+
+
+/*
+** Prepare the stack for calling a Lua function.
+*/
+void luaD_precall (TObject *f, StkId base, int nResults)
+{
+ /* Create a new CallInfo record */
+ if (L->ci+1 == L->end_ci) {
+ int size_ci = L->end_ci - L->base_ci;
+ int index_ci = L->ci - L->base_ci;
+ int new_ci_size = size_ci * 2 * sizeof(CallInfo);
+ CallInfo *new_ci = (CallInfo *)luaM_malloc(new_ci_size);
+ memcpy(new_ci, L->base_ci, L->base_ci_size);
+ memset(new_ci + (L->base_ci_size / sizeof(CallInfo)), 0, (new_ci_size) - L->base_ci_size);
+ luaM_free(L->base_ci);
+ L->base_ci = new_ci;
+ L->base_ci_size = new_ci_size;
+ L->ci = L->base_ci + index_ci;
+ L->end_ci = L->base_ci + size_ci * 2;
+ }
+ L->ci++;
+ if (ttype(f) == LUA_T_CLOSURE) {
+ L->ci->c = clvalue(f);
+ f = &L->ci->c->consts[0]; /* Get the actual function */
+ }
+ else
+ L->ci->c = NULL;
+ L->ci->base = base;
+ L->ci->nResults = nResults;
+ if (ttype(f)==LUA_T_CPROTO) {
+ L->ci->tf = NULL;
+ L->ci->pc = NULL;
+ }
+ else {
+ Byte *pc = tfvalue(f)->code;
+ if (lua_callhook)
+ luaD_callHook(base, tfvalue(f), 0);
+ luaD_checkstack((*pc++)+EXTRA_STACK);
+ if (*pc < ZEROVARARG)
+ luaD_adjusttop(base+*(pc++));
+ else { /* varargs */
+ luaC_checkGC();
+ adjust_varargs(base+(*pc++)-ZEROVARARG);
+ }
+ L->ci->tf = tfvalue(f);
+ L->ci->pc = pc;
+ }
+}
+
+/*
+** Adjust the stack to the desired number of results
+*/
+void luaD_postret (StkId firstResult) {
+ int i;
+ StkId base = L->ci->base;
+ int nResults = L->ci->nResults;
+ if (L->ci == L->base_ci)
+ lua_error("call stack underflow");
+ /* adjust the number of results */
+ if (nResults != MULT_RET)
+ luaD_adjusttop(firstResult+nResults);
+ /* move results to base-1 (to erase parameters and function) */
+ base--;
+ nResults = L->stack.top - (L->stack.stack+firstResult); /* actual number of results */
+ for (i=0; i<nResults; i++)
+ *(L->stack.stack+base+i) = *(L->stack.stack+firstResult+i);
+ L->stack.top -= firstResult-base;
+ /* pop off the current CallInfo */
+ L->ci--;
+}
+
+/*
+** Call a function (C or Lua). The parameters must be on the L->stack.stack,
+** between [L->stack.stack+base,L->stack.top). The function to be called is at L->stack.stack+base-1.
+** When returns, the results are on the L->stack.stack, between [L->stack.stack+base-1,L->stack.top).
+** The number of results is nResults, unless nResults=MULT_RET.
+*/
+void luaD_call (StkId base, int nResults)
+{
+ StkId firstResult;
+ TObject *func = L->stack.stack+base-1;
+ switch (ttype(func)) {
+ case LUA_T_CPROTO:
+ luaD_precall(func, base, nResults);
+ ttype(func) = LUA_T_CMARK;
+ firstResult = callC(fvalue(func), base);
+ break;
+ case LUA_T_PROTO:
+ luaD_precall(func, base, nResults);
+ ttype(func) = LUA_T_PMARK;
+ firstResult = luaV_execute(L->ci);
+ break;
+ case LUA_T_CLOSURE: {
+ Closure *c = clvalue(func);
+ TObject *proto = &(c->consts[0]);
+ luaD_precall(func, base, nResults);
+ ttype(func) = LUA_T_CLMARK;
+ firstResult = (ttype(proto) == LUA_T_CPROTO) ?
+ callCclosure(c, fvalue(proto), base) :
+ luaV_execute(L->ci);
+ break;
+ }
+ default: { /* func is not a function */
+ /* Check the tag method for invalid functions */
+ TObject *im = luaT_getimbyObj(func, IM_FUNCTION);
+ if (ttype(im) == LUA_T_NIL)
+ lua_error("call expression not a function");
+ luaD_callTM(im, (L->stack.top-L->stack.stack)-(base-1), nResults);
+ return;
+ }
+ }
+ luaD_postret(firstResult);
+}
+
+
+static void travstack (struct Stack *S, int (*fn)(TObject *)) {
+ StkId i;
+ for (i = (S->top-1)-S->stack; i>=0; i--)
+ fn(S->stack+i);
+}
+
+/*
+** Traverse all objects on L->stack.stack, and all other active stacks
+*/
+void luaD_travstack (int (*fn)(TObject *))
+{
+ struct lua_Task *t;
+ travstack(&L->stack, fn);
+ for (t = L->root_task; t != NULL; t = t->next)
+ if (t != L->curr_task && t->Tstate != DONE)
+ travstack(&t->stack, fn);
+}
+
+
+
+static void message (char *s)
+{
+ TObject im = L->errorim;
+ if (ttype(&im) != LUA_T_NIL) {
+ lua_pushstring(s);
+ luaD_callTM(&im, 1, 0);
+ }
+}
+
+/*
+** Reports an error, and jumps up to the available recover label
+*/
+void lua_error (char *s)
+{
+ if (s) message(s);
+ if (L->errorJmp)
+ longjmp(*((jmp_buf *)L->errorJmp), 1);
+ else {
+ fprintf (stderr, "lua: exit(1). Unable to recover\n");
+ exit(1);
+ }
+}
+
+/*
+** Call the function at L->Cstack.base, and incorporate results on
+** the Lua2C structure.
+*/
+static void do_callinc (int nResults)
+{
+ StkId base = L->Cstack.base;
+ luaD_call(base+1, nResults);
+ L->Cstack.lua2C = base; /* position of the luaM_new results */
+ L->Cstack.num = (L->stack.top-L->stack.stack) - base; /* number of results */
+ L->Cstack.base = base + L->Cstack.num; /* incorporate results on L->stack.stack */
+}
+
+
+/*
+** Execute a protected call. Assumes that function is at L->Cstack.base and
+** parameters are on top of it. Leave nResults on the stack.
+*/
+int luaD_protectedrun (int nResults)
+{
+ jmp_buf myErrorJmp;
+ int status;
+ struct C_Lua_Stack oldCLS = L->Cstack;
+ jmp_buf *oldErr = L->errorJmp;
+ int ci_len = L->ci - L->base_ci;
+ L->errorJmp = &myErrorJmp;
+ if (setjmp(myErrorJmp) == 0) {
+ do_callinc(nResults);
+ status = 0;
+ }
+ else { /* an error occurred: restore L->Cstack and L->stack.top */
+ L->Cstack = oldCLS;
+ L->stack.top = L->stack.stack+L->Cstack.base;
+ L->ci = L->base_ci + ci_len;
+ status = 1;
+ }
+ L->errorJmp = oldErr;
+ return status;
+}
+
+
+/*
+** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load
+*/
+static int protectedparser (ZIO *z, int bin)
+{
+ volatile int status;
+ TProtoFunc *volatile tf;
+ jmp_buf myErrorJmp;
+ jmp_buf *volatile oldErr = L->errorJmp;
+ L->errorJmp = &myErrorJmp;
+ if (setjmp(myErrorJmp) == 0) {
+ tf = bin ? luaU_undump1(z) : luaY_parser(z);
+ status = 0;
+ }
+ else {
+ tf = NULL;
+ status = 1;
+ }
+ L->errorJmp = oldErr;
+ if (status) return 1; /* error code */
+ if (tf == NULL) return 2; /* 'natural' end */
+ luaD_adjusttop(L->Cstack.base+1); /* one slot for the pseudo-function */
+ L->stack.stack[L->Cstack.base].ttype = LUA_T_PROTO;
+ L->stack.stack[L->Cstack.base].value.tf = tf;
+ luaV_closure(0);
+ return 0;
+}
+
+
+static int do_main (ZIO *z, int bin)
+{
+ int status;
+ do {
+ long old_blocks = (luaC_checkGC(), L->nblocks);
+ status = protectedparser(z, bin);
+ if (status == 1) return 1; /* error */
+ else if (status == 2) return 0; /* 'natural' end */
+ else {
+ unsigned long newelems2 = 2*(L->nblocks-old_blocks);
+ L->GCthreshold += newelems2;
+ status = luaD_protectedrun(MULT_RET);
+ L->GCthreshold -= newelems2;
+ }
+ } while (bin && status == 0);
+ return status;
+}
+
+
+void luaD_gcIM (TObject *o)
+{
+ TObject *im = luaT_getimbyObj(o, IM_GC);
+ if (ttype(im) != LUA_T_NIL) {
+ *L->stack.top = *o;
+ incr_top;
+ luaD_callTM(im, 1, 0);
+ }
+}
+
+
+int lua_dofile (char *filename)
+{
+ ZIO z;
+ int status;
+ int c;
+ int bin;
+ FILE *f = (filename == NULL) ? stdin : fopen(filename, "r");
+ if (f == NULL)
+ return 2;
+ if (filename == NULL)
+ filename = "(stdin)";
+ c = fgetc(f);
+ ungetc(c, f);
+ bin = (c == ID_CHUNK);
+ if (bin)
+ f = freopen(filename, "rb", f); /* set binary mode */
+ luaZ_Fopen(&z, f, filename);
+ status = do_main(&z, bin);
+ if (f != stdin)
+ fclose(f);
+ return status;
+}
+
+
+#define SIZE_PREF 20 /* size of string prefix to appear in error messages */
+#define SSIZE_PREF "20"
+
+
+static void build_name (char *str, char *name) {
+ if (str == NULL || *str == ID_CHUNK)
+ strcpy(name, "(buffer)");
+ else {
+ char *temp;
+ sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str);
+ temp = strchr(name, '\n');
+ if (temp) { /* end string after first line */
+ *temp = '"';
+ *(temp+1) = 0;
+ }
+ }
+}
+
+
+int lua_dostring (char *str) {
+ return lua_dobuffer(str, strlen(str), NULL);
+}
+
+
+int lua_dobuffer (char *buff, int size, char *name) {
+ char newname[SIZE_PREF+25];
+ ZIO z;
+ int status;
+ if (name==NULL) {
+ build_name(buff, newname);
+ name = newname;
+ }
+ luaZ_mopen(&z, buff, size, name);
+ status = do_main(&z, buff[0]==ID_CHUNK);
+ return status;
+}
+
diff --git a/tools/lua/ldo.h b/tools/lua/ldo.h
new file mode 100644
index 000000000..f06931ab6
--- /dev/null
+++ b/tools/lua/ldo.h
@@ -0,0 +1,49 @@
+/*
+** $Id$
+** Stack and Call structure of Lua
+** See Copyright Notice in lua.h
+*/
+
+#ifndef ldo_h
+#define ldo_h
+
+
+#include "lobject.h"
+#include "lstate.h"
+
+
+#define MULT_RET 255
+
+
+
+/*
+** macro to increment stack top.
+** There must be always an empty slot at the L->stack.top
+*/
+#define incr_top { if (L->stack.top >= L->stack.last) luaD_checkstack(1); \
+ L->stack.top++; }
+
+
+/* macros to convert from lua_Object to (TObject *) and back */
+
+#define Address(lo) ((lo)+L->stack.stack-1)
+#define Ref(st) ((st)-L->stack.stack+1)
+
+
+void luaD_init (void);
+void luaD_initthr (void);
+void luaD_adjusttop (StkId newtop);
+void luaD_openstack (int nelems);
+void luaD_lineHook (int line);
+void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn);
+void luaD_precall (TObject *f, StkId base, int nResults);
+void luaD_postret (StkId firstResult);
+void luaD_call (StkId base, int nResults);
+void luaD_callTM (TObject *f, int nParams, int nResults);
+int luaD_protectedrun (int nResults);
+void luaD_gcIM (TObject *o);
+void luaD_travstack (int (*fn)(TObject *));
+void luaD_checkstack (int n);
+
+
+#endif
diff --git a/tools/lua/lfunc.cpp b/tools/lua/lfunc.cpp
new file mode 100644
index 000000000..a35779f7a
--- /dev/null
+++ b/tools/lua/lfunc.cpp
@@ -0,0 +1,98 @@
+/*
+** $Id$
+** Auxiliary functions to manipulate prototypes and closures
+** See Copyright Notice in lua.h
+*/
+
+
+#include <stdlib.h>
+
+#include "lfunc.h"
+#include "lmem.h"
+#include "lstate.h"
+
+#define gcsizeproto(p) 5 /* approximate "weight" for a prototype */
+#define gcsizeclosure(c) 1 /* approximate "weight" for a closure */
+
+
+
+Closure *luaF_newclosure (int nelems)
+{
+ Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
+ luaO_insertlist(&(L->rootcl), (GCnode *)c);
+ L->nblocks += gcsizeclosure(c);
+ c->nelems = nelems;
+ return c;
+}
+
+
+TProtoFunc *luaF_newproto (void)
+{
+ TProtoFunc *f = luaM_new(TProtoFunc);
+ f->code = NULL;
+ f->lineDefined = 0;
+ f->fileName = NULL;
+ f->consts = NULL;
+ f->nconsts = 0;
+ f->locvars = NULL;
+ luaO_insertlist(&(L->rootproto), (GCnode *)f);
+ L->nblocks += gcsizeproto(f);
+ return f;
+}
+
+
+
+static void freefunc (TProtoFunc *f)
+{
+ luaM_free(f->code);
+ luaM_free(f->locvars);
+ luaM_free(f->consts);
+ luaM_free(f);
+}
+
+
+void luaF_freeproto (TProtoFunc *l)
+{
+ while (l) {
+ TProtoFunc *next = (TProtoFunc *)l->head.next;
+ L->nblocks -= gcsizeproto(l);
+ freefunc(l);
+ l = next;
+ }
+}
+
+
+void luaF_freeclosure (Closure *l)
+{
+ while (l) {
+ Closure *next = (Closure *)l->head.next;
+ L->nblocks -= gcsizeclosure(l);
+ luaM_free(l);
+ l = next;
+ }
+}
+
+
+/*
+** Look for n-th local variable at line "line" in function "func".
+** Returns NULL if not found.
+*/
+char *luaF_getlocalname (TProtoFunc *func, int local_number, int line)
+{
+ int count = 0;
+ char *varname = NULL;
+ LocVar *lv = func->locvars;
+ if (lv == NULL)
+ return NULL;
+ for (; lv->line != -1 && lv->line < line; lv++) {
Commit: be39ac156c5c7af8c3d14c3baa5d42756c6e8ef4
https://github.com/scummvm/scummvm-tools/commit/be39ac156c5c7af8c3d14c3baa5d42756c6e8ef4
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-07T22:02:07+02:00
Commit Message:
fix compilation
Changed paths:
tools/lua/lapi.cpp
tools/lua/lapi.h
tools/lua/lauxlib.cpp
tools/lua/lauxlib.h
tools/lua/lbuffer.cpp
tools/lua/lbuiltin.cpp
tools/lua/ldo.cpp
tools/lua/ldo.h
tools/lua/lfunc.cpp
tools/lua/lfunc.h
tools/lua/lgc.cpp
tools/lua/lgc.h
tools/lua/liolib.cpp
tools/lua/llex.cpp
tools/lua/llex.h
tools/lua/lmathlib.cpp
tools/lua/lmem.cpp
tools/lua/lobject.cpp
tools/lua/lobject.h
tools/lua/lparser.cpp
tools/lua/lparser.h
tools/lua/lstate.cpp
tools/lua/lstate.h
tools/lua/lstring.cpp
tools/lua/lstring.h
tools/lua/lstrlib.cpp
tools/lua/ltable.cpp
tools/lua/ltable.h
tools/lua/ltask.cpp
tools/lua/ltask.h
tools/lua/ltm.cpp
tools/lua/ltm.h
tools/lua/luadebug.h
tools/lua/lualib.h
tools/lua/lundump.cpp
tools/lua/lundump.h
tools/lua/lvm.cpp
tools/lua/lvm.h
tools/lua/lzio.cpp
tools/module.mk
diff --git a/tools/lua/lapi.cpp b/tools/lua/lapi.cpp
index 286d31326..c3ec46eee 100644
--- a/tools/lua/lapi.cpp
+++ b/tools/lua/lapi.cpp
@@ -8,20 +8,20 @@
#include <stdlib.h>
#include <string.h>
-#include "lapi.h"
-#include "lauxlib.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 "lua.h"
-#include "luadebug.h"
-#include "lvm.h"
+#include <tools/lua/lapi.h>
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/ldo.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lgc.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/ltable.h>
+#include <tools/lua/ltm.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/luadebug.h>
+#include <tools/lua/lvm.h>
char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
diff --git a/tools/lua/lapi.h b/tools/lua/lapi.h
index d3d5a6977..d2904f2ed 100644
--- a/tools/lua/lapi.h
+++ b/tools/lua/lapi.h
@@ -8,8 +8,8 @@
#define lapi_h
-#include "lua.h"
-#include "lobject.h"
+#include <tools/lua/lua.h>
+#include <tools/lua/lobject.h>
TObject *luaA_Address (lua_Object o);
diff --git a/tools/lua/lauxlib.cpp b/tools/lua/lauxlib.cpp
index 08be69eb2..d2c10921e 100644
--- a/tools/lua/lauxlib.cpp
+++ b/tools/lua/lauxlib.cpp
@@ -14,10 +14,10 @@
** Any function declared here could be written as an application
** function. With care, these functions can be used by other libraries.
*/
-#include "lauxlib.h"
-#include "lua.h"
-#include "luadebug.h"
-#include "lmem.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/luadebug.h>
+#include <tools/lua/lmem.h>
int luaL_findstring (char *name, char *list[]) {
diff --git a/tools/lua/lauxlib.h b/tools/lua/lauxlib.h
index 15a8c99ae..c89f072b2 100644
--- a/tools/lua/lauxlib.h
+++ b/tools/lua/lauxlib.h
@@ -9,7 +9,7 @@
#define auxlib_h
-#include "lua.h"
+#include <tools/lua/lua.h>
struct luaL_reg {
diff --git a/tools/lua/lbuffer.cpp b/tools/lua/lbuffer.cpp
index bf491cf03..feb4322c9 100644
--- a/tools/lua/lbuffer.cpp
+++ b/tools/lua/lbuffer.cpp
@@ -7,9 +7,9 @@
#include <stdio.h>
-#include "lauxlib.h"
-#include "lmem.h"
-#include "lstate.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lstate.h>
/*-------------------------------------------------------
diff --git a/tools/lua/lbuiltin.cpp b/tools/lua/lbuiltin.cpp
index 4ab614299..421449acc 100644
--- a/tools/lua/lbuiltin.cpp
+++ b/tools/lua/lbuiltin.cpp
@@ -10,20 +10,20 @@
#include <stdlib.h>
#include <string.h>
-#include "lapi.h"
-#include "lauxlib.h"
-#include "lbuiltin.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltask.h"
-#include "ltm.h"
-#include "lua.h"
-#include "lundump.h"
+#include <tools/lua/lapi.h>
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lbuiltin.h>
+#include <tools/lua/ldo.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/ltable.h>
+#include <tools/lua/ltask.h>
+#include <tools/lua/ltm.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/lundump.h>
diff --git a/tools/lua/ldo.cpp b/tools/lua/ldo.cpp
index a34eabfd8..42f519e59 100644
--- a/tools/lua/ldo.cpp
+++ b/tools/lua/ldo.cpp
@@ -10,21 +10,21 @@
#include <stdlib.h>
#include <string.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 "ltask.h"
-#include "ltm.h"
-#include "lua.h"
-#include "luadebug.h"
-#include "lundump.h"
-#include "lvm.h"
-#include "lzio.h"
+#include <tools/lua/ldo.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lgc.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lopcodes.h>
+#include <tools/lua/lparser.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/ltask.h>
+#include <tools/lua/ltm.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/luadebug.h>
+#include <tools/lua/lundump.h>
+#include <tools/lua/lvm.h>
+#include <tools/lua/lzio.h>
diff --git a/tools/lua/ldo.h b/tools/lua/ldo.h
index f06931ab6..7be1a0208 100644
--- a/tools/lua/ldo.h
+++ b/tools/lua/ldo.h
@@ -8,8 +8,8 @@
#define ldo_h
-#include "lobject.h"
-#include "lstate.h"
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
#define MULT_RET 255
diff --git a/tools/lua/lfunc.cpp b/tools/lua/lfunc.cpp
index a35779f7a..48506f3a8 100644
--- a/tools/lua/lfunc.cpp
+++ b/tools/lua/lfunc.cpp
@@ -7,9 +7,9 @@
#include <stdlib.h>
-#include "lfunc.h"
-#include "lmem.h"
-#include "lstate.h"
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lstate.h>
#define gcsizeproto(p) 5 /* approximate "weight" for a prototype */
#define gcsizeclosure(c) 1 /* approximate "weight" for a closure */
diff --git a/tools/lua/lfunc.h b/tools/lua/lfunc.h
index 6b94d760a..4c57ceb40 100644
--- a/tools/lua/lfunc.h
+++ b/tools/lua/lfunc.h
@@ -8,7 +8,7 @@
#define lfunc_h
-#include "lobject.h"
+#include <tools/lua/lobject.h>
diff --git a/tools/lua/lgc.cpp b/tools/lua/lgc.cpp
index 6b93616a6..4d23c2c0d 100644
--- a/tools/lua/lgc.cpp
+++ b/tools/lua/lgc.cpp
@@ -5,16 +5,16 @@
*/
-#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 "lua.h"
+#include <tools/lua/ldo.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lgc.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/ltable.h>
+#include <tools/lua/ltm.h>
+#include <tools/lua/lua.h>
diff --git a/tools/lua/lgc.h b/tools/lua/lgc.h
index 7ed687ade..d67e066ca 100644
--- a/tools/lua/lgc.h
+++ b/tools/lua/lgc.h
@@ -8,7 +8,7 @@
#define lgc_h
-#include "lobject.h"
+#include <tools/lua/lobject.h>
void luaC_checkGC (void);
diff --git a/tools/lua/liolib.cpp b/tools/lua/liolib.cpp
index f3211e8f2..3777591b7 100644
--- a/tools/lua/liolib.cpp
+++ b/tools/lua/liolib.cpp
@@ -11,10 +11,10 @@
#include <string.h>
#include <time.h>
-#include "lauxlib.h"
-#include "lua.h"
-#include "luadebug.h"
-#include "lualib.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/luadebug.h>
+#include <tools/lua/lualib.h>
#ifndef OLD_ANSI
diff --git a/tools/lua/llex.cpp b/tools/lua/llex.cpp
index 80b7562fd..bda627852 100644
--- a/tools/lua/llex.cpp
+++ b/tools/lua/llex.cpp
@@ -8,15 +8,15 @@
#include <ctype.h>
#include <string.h>
-#include "lauxlib.h"
-#include "llex.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lparser.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "luadebug.h"
-#include "lzio.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/llex.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lparser.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/luadebug.h>
+#include <tools/lua/lzio.h>
diff --git a/tools/lua/llex.h b/tools/lua/llex.h
index db57bd9d6..9b66997b1 100644
--- a/tools/lua/llex.h
+++ b/tools/lua/llex.h
@@ -7,8 +7,8 @@
#ifndef llex_h
#define llex_h
-#include "lobject.h"
-#include "lzio.h"
+#include <tools/lua/lobject.h>
+#include <tools/lua/lzio.h>
#define FIRST_RESERVED 260
diff --git a/tools/lua/lmathlib.cpp b/tools/lua/lmathlib.cpp
index 685ec22da..c40125424 100644
--- a/tools/lua/lmathlib.cpp
+++ b/tools/lua/lmathlib.cpp
@@ -8,9 +8,9 @@
#include <stdlib.h>
#include <math.h>
-#include "lauxlib.h"
-#include "lua.h"
-#include "lualib.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/lualib.h>
#ifdef M_PI
#define PI M_PI
diff --git a/tools/lua/lmem.cpp b/tools/lua/lmem.cpp
index 5e8b0c409..72a474adb 100644
--- a/tools/lua/lmem.cpp
+++ b/tools/lua/lmem.cpp
@@ -7,9 +7,9 @@
#include <stdlib.h>
-#include "lmem.h"
-#include "lstate.h"
-#include "lua.h"
+#include <tools/lua/lmem.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lua.h>
diff --git a/tools/lua/lobject.cpp b/tools/lua/lobject.cpp
index c914b7950..0d42012df 100644
--- a/tools/lua/lobject.cpp
+++ b/tools/lua/lobject.cpp
@@ -6,8 +6,8 @@
#include <stdlib.h>
-#include "lobject.h"
-#include "lua.h"
+#include <tools/lua/lobject.h>
+#include <tools/lua/lua.h>
char *luaO_typenames[] = { /* ORDER LUA_T */
diff --git a/tools/lua/lobject.h b/tools/lua/lobject.h
index 2b91fa62f..43927db8c 100644
--- a/tools/lua/lobject.h
+++ b/tools/lua/lobject.h
@@ -10,11 +10,11 @@
#include <limits.h>
-#include "lua.h"
+#include <tools/lua/lua.h>
#ifdef DEBUG
-#include "lauxlib.h"
+#include <tools/lua/lauxlib.h>
#define LUA_INTERNALERROR(s) \
luaL_verror("INTERNAL ERROR - %s [%s:%d]",(s),__FILE__,__LINE__)
#define LUA_ASSERT(c,s) { if (!(c)) LUA_INTERNALERROR(s); }
diff --git a/tools/lua/lparser.cpp b/tools/lua/lparser.cpp
index 7c2191d91..b96abeba1 100644
--- a/tools/lua/lparser.cpp
+++ b/tools/lua/lparser.cpp
@@ -8,18 +8,18 @@
#include <stdlib.h>
#include <stdio.h>
-#include "lauxlib.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "llex.h"
-#include "lmem.h"
-#include "lopcodes.h"
-#include "lparser.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "lua.h"
-#include "luadebug.h"
-#include "lzio.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/ldo.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/llex.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lopcodes.h>
+#include <tools/lua/lparser.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/luadebug.h>
+#include <tools/lua/lzio.h>
/* for limit numbers in error messages */
diff --git a/tools/lua/lparser.h b/tools/lua/lparser.h
index 48e5e72b2..0657cf1a5 100644
--- a/tools/lua/lparser.h
+++ b/tools/lua/lparser.h
@@ -7,8 +7,8 @@
#ifndef lparser_h
#define lparser_h
-#include "lobject.h"
-#include "lzio.h"
+#include <tools/lua/lobject.h>
+#include <tools/lua/lzio.h>
void luaY_codedebugline (int line);
diff --git a/tools/lua/lstate.cpp b/tools/lua/lstate.cpp
index 0a49fd7e5..2f5448d34 100644
--- a/tools/lua/lstate.cpp
+++ b/tools/lua/lstate.cpp
@@ -6,18 +6,18 @@
#include <stdlib.h>
-#include "lbuiltin.h"
-#include "ldo.h"
-#include "lauxlib.h"
-#include "lfunc.h"
-#include "lgc.h"
-#include "llex.h"
-#include "lmem.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltask.h"
-#include "ltm.h"
+#include <tools/lua/lbuiltin.h>
+#include <tools/lua/ldo.h>
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lgc.h>
+#include <tools/lua/llex.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/ltable.h>
+#include <tools/lua/ltask.h>
+#include <tools/lua/ltm.h>
lua_State *lua_state = NULL;
diff --git a/tools/lua/lstate.h b/tools/lua/lstate.h
index 2faa57394..659685cb1 100644
--- a/tools/lua/lstate.h
+++ b/tools/lua/lstate.h
@@ -9,8 +9,8 @@
#include <setjmp.h>
-#include "lobject.h"
-#include "lua.h"
+#include <tools/lua/lobject.h>
+#include <tools/lua/lua.h>
#define MAX_C_BLOCKS 10
diff --git a/tools/lua/lstring.cpp b/tools/lua/lstring.cpp
index d48ff43b6..47b24bc64 100644
--- a/tools/lua/lstring.cpp
+++ b/tools/lua/lstring.cpp
@@ -8,11 +8,11 @@
#include <stdlib.h>
#include <string.h>
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "lua.h"
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/lua.h>
diff --git a/tools/lua/lstring.h b/tools/lua/lstring.h
index 0397a29ec..adddb0034 100644
--- a/tools/lua/lstring.h
+++ b/tools/lua/lstring.h
@@ -8,7 +8,7 @@
#define lstring_h
-#include "lobject.h"
+#include <tools/lua/lobject.h>
void luaS_init (void);
diff --git a/tools/lua/lstrlib.cpp b/tools/lua/lstrlib.cpp
index d2caba066..8a68d69d4 100644
--- a/tools/lua/lstrlib.cpp
+++ b/tools/lua/lstrlib.cpp
@@ -10,9 +10,9 @@
#include <stdlib.h>
#include <string.h>
-#include "lauxlib.h"
-#include "lua.h"
-#include "lualib.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lua.h>
+#include <tools/lua/lualib.h>
diff --git a/tools/lua/ltable.cpp b/tools/lua/ltable.cpp
index 31ebe71e2..bf90162a3 100644
--- a/tools/lua/ltable.cpp
+++ b/tools/lua/ltable.cpp
@@ -6,12 +6,12 @@
#include <stdlib.h>
-#include "lauxlib.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "ltable.h"
-#include "lua.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/ltable.h>
+#include <tools/lua/lua.h>
#define gcsize(n) (1+(n/16))
diff --git a/tools/lua/ltable.h b/tools/lua/ltable.h
index 6e01165cf..38aed7a52 100644
--- a/tools/lua/ltable.h
+++ b/tools/lua/ltable.h
@@ -7,7 +7,7 @@
#ifndef ltable_h
#define ltable_h
-#include "lobject.h"
+#include <tools/lua/lobject.h>
#define node(t,i) (&(t)->node[i])
diff --git a/tools/lua/ltask.cpp b/tools/lua/ltask.cpp
index 06527f7c1..abfd672e5 100644
--- a/tools/lua/ltask.cpp
+++ b/tools/lua/ltask.cpp
@@ -2,11 +2,11 @@
#include <stdio.h>
#include <search.h>
-#include "ltask.h"
-#include "lauxlib.h"
-#include "lmem.h"
-#include "ldo.h"
-#include "lvm.h"
+#include <tools/lua/ltask.h>
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/ldo.h>
+#include <tools/lua/lvm.h>
void pause_scripts (void) {
struct lua_Task *t;
diff --git a/tools/lua/ltask.h b/tools/lua/ltask.h
index 3a618da4d..4742f3b4c 100644
--- a/tools/lua/ltask.h
+++ b/tools/lua/ltask.h
@@ -1,8 +1,8 @@
#ifndef ltask_h
#define ltask_h
-#include "lua.h"
-#include "lstate.h"
+#include <tools/lua/lua.h>
+#include <tools/lua/lstate.h>
extern int task_tag;
diff --git a/tools/lua/ltm.cpp b/tools/lua/ltm.cpp
index cd4a9f49b..58d68e930 100644
--- a/tools/lua/ltm.cpp
+++ b/tools/lua/ltm.cpp
@@ -9,11 +9,11 @@
#include <stdio.h>
#include <string.h>
-#include "lauxlib.h"
-#include "lmem.h"
-#include "lobject.h"
-#include "lstate.h"
-#include "ltm.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/ltm.h>
char *luaT_eventname[] = { /* ORDER IM */
@@ -178,7 +178,7 @@ char *luaT_travtagmethods (int (*fn)(TObject *))
*/
#ifdef LUA_COMPAT2_5
-#include "lapi.h"
+#include <tools/lua/lapi.h>
void errorFB (void)
{
diff --git a/tools/lua/ltm.h b/tools/lua/ltm.h
index 1cd51f4d2..36b7cfa20 100644
--- a/tools/lua/ltm.h
+++ b/tools/lua/ltm.h
@@ -8,8 +8,8 @@
#define ltm_h
-#include "lobject.h"
-#include "lstate.h"
+#include <tools/lua/lobject.h>
+#include <tools/lua/lstate.h>
/*
* WARNING: if you change the order of this enumeration,
diff --git a/tools/lua/luadebug.h b/tools/lua/luadebug.h
index 0bba58e8e..442bf4053 100644
--- a/tools/lua/luadebug.h
+++ b/tools/lua/luadebug.h
@@ -9,7 +9,7 @@
#define luadebug_h
-#include "lua.h"
+#include <tools/lua/lua.h>
typedef lua_Object lua_Function;
diff --git a/tools/lua/lualib.h b/tools/lua/lualib.h
index 04e14c7b7..c48465933 100644
--- a/tools/lua/lualib.h
+++ b/tools/lua/lualib.h
@@ -8,7 +8,7 @@
#ifndef lualib_h
#define lualib_h
-#include "lua.h"
+#include <tools/lua/lua.h>
void lua_iolibopen (void);
diff --git a/tools/lua/lundump.cpp b/tools/lua/lundump.cpp
index e7f655ebd..f46327cfc 100644
--- a/tools/lua/lundump.cpp
+++ b/tools/lua/lundump.cpp
@@ -7,11 +7,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include "lauxlib.h"
-#include "lfunc.h"
-#include "lmem.h"
-#include "lstring.h"
-#include "lundump.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/lundump.h>
#define LoadBlock(b,size,Z) ezread(Z,b,size)
#define LoadNative(t,Z) LoadBlock(&t,sizeof(t),Z)
diff --git a/tools/lua/lundump.h b/tools/lua/lundump.h
index a1d177c14..3c2c60143 100644
--- a/tools/lua/lundump.h
+++ b/tools/lua/lundump.h
@@ -7,8 +7,8 @@
#ifndef lundump_h
#define lundump_h
-#include "lobject.h"
-#include "lzio.h"
+#include <tools/lua/lobject.h>
+#include <tools/lua/lzio.h>
TProtoFunc* luaU_undump1(ZIO* Z); /* load one chunk */
diff --git a/tools/lua/lvm.cpp b/tools/lua/lvm.cpp
index cfa9e46cb..fa6348362 100644
--- a/tools/lua/lvm.cpp
+++ b/tools/lua/lvm.cpp
@@ -8,18 +8,18 @@
#include <stdio.h>
#include <string.h>
-#include "lauxlib.h"
-#include "ldo.h"
-#include "lfunc.h"
-#include "lgc.h"
-#include "lmem.h"
-#include "lopcodes.h"
-#include "lstate.h"
-#include "lstring.h"
-#include "ltable.h"
-#include "ltm.h"
-#include "luadebug.h"
-#include "lvm.h"
+#include <tools/lua/lauxlib.h>
+#include <tools/lua/ldo.h>
+#include <tools/lua/lfunc.h>
+#include <tools/lua/lgc.h>
+#include <tools/lua/lmem.h>
+#include <tools/lua/lopcodes.h>
+#include <tools/lua/lstate.h>
+#include <tools/lua/lstring.h>
+#include <tools/lua/ltable.h>
+#include <tools/lua/ltm.h>
+#include <tools/lua/luadebug.h>
+#include <tools/lua/lvm.h>
#ifdef OLD_ANSI
#define strcoll(a,b) strcmp(a,b)
diff --git a/tools/lua/lvm.h b/tools/lua/lvm.h
index f49f592c6..d15d1ddc1 100644
--- a/tools/lua/lvm.h
+++ b/tools/lua/lvm.h
@@ -8,8 +8,8 @@
#define lvm_h
-#include "ldo.h"
-#include "lobject.h"
+#include <tools/lua/ldo.h>
+#include <tools/lua/lobject.h>
#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0))
diff --git a/tools/lua/lzio.cpp b/tools/lua/lzio.cpp
index 682ac731d..228b0c78c 100644
--- a/tools/lua/lzio.cpp
+++ b/tools/lua/lzio.cpp
@@ -9,7 +9,7 @@
#include <stdio.h>
#include <string.h>
-#include "lzio.h"
+#include <tools/lua/lzio.h>
diff --git a/tools/module.mk b/tools/module.mk
index 2d225b0dd..fe38fe32e 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -41,8 +41,8 @@ clean-tools:
tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I. -Wall \
- -Lcommon -lcommon -Ltools/lua -llua -o $@ $<
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -Wall \
+ -L$(srcdir)/common -L$(srcdir)/tools/lua -llua -o $@ $<
tools/mat2ppm$(EXEEXT): $(srcdir)/tools/mat2ppm.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: 858ee081d2fab3573447a2b1b3fd3cd2bb092d69
https://github.com/scummvm/scummvm-tools/commit/858ee081d2fab3573447a2b1b3fd3cd2bb092d69
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-07T22:14:18+02:00
Commit Message:
fix incldue paths
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 730ab2ecd..f78614737 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -23,10 +23,10 @@
*
*/
-#include "tools/lua/lua.h"
-#include "tools/lua/lundump.h"
-#include "tools/lua/lopcodes.h"
-#include "tools/lua/lzio.h"
+#include <tools/lua/lua.h>
+#include <tools/lua/lundump.h>
+#include <tools/lua/lopcodes.h>
+#include <tools/lua/lzio.h>
#include <stdio.h>
#include <stdlib.h>
Commit: eb78cf05c7c4072ca60e52f20d928e6604aabdaa
https://github.com/scummvm/scummvm-tools/commit/eb78cf05c7c4072ca60e52f20d928e6604aabdaa
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-07T22:14:39+02:00
Commit Message:
fix linking
Changed paths:
tools/module.mk
diff --git a/tools/module.mk b/tools/module.mk
index fe38fe32e..a1307cc6c 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -42,7 +42,7 @@ clean-tools:
tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -Wall \
- -L$(srcdir)/common -L$(srcdir)/tools/lua -llua -o $@ $<
+ -L$(srcdir)/common -Ltools/lua -llua -o $@ $<
tools/mat2ppm$(EXEEXT): $(srcdir)/tools/mat2ppm.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: baf7d1d887abd5582882041268140d510ed009c4
https://github.com/scummvm/scummvm-tools/commit/baf7d1d887abd5582882041268140d510ed009c4
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-08T11:04:45+02:00
Commit Message:
remove left over game_engine
Changed paths:
configure
diff --git a/configure b/configure
index 3e793d665..f506a83f0 100755
--- a/configure
+++ b/configure
@@ -372,12 +372,6 @@ for ac_option in $@; do
--libdir=*)
_libdir=`echo $ac_option | cut -d '=' -f 2`
;;
- --enable-*)
- engine_enable `echo $ac_option | cut -d '-' -f 4-`
- ;;
- --disable-*)
- engine_disable `echo $ac_option | cut -d '-' -f 4-`
- ;;
*)
option_error
;;
Commit: 2bf84cc3c9d0a346261943dad1c836ec8325d2b1
https://github.com/scummvm/scummvm-tools/commit/2bf84cc3c9d0a346261943dad1c836ec8325d2b1
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-08T11:07:37+02:00
Commit Message:
restore --enable-verbose-build option
Changed paths:
configure
diff --git a/configure b/configure
index f506a83f0..5db961905 100755
--- a/configure
+++ b/configure
@@ -305,6 +305,7 @@ for ac_option in $@; do
--enable-mad) _mad=yes ;;
--disable-mad) _mad=no ;;
+ --enable-verbose-build) _verbose_build=yes ;;
--with-ogg-prefix=*)
arg=`echo $ac_option | cut -d '=' -f 2`
OGG_CFLAGS="-I$arg/include"
Commit: b33b3ef61708390f04a4f4b641ba725663266170
https://github.com/scummvm/scummvm-tools/commit/b33b3ef61708390f04a4f4b641ba725663266170
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-04-08T11:13:28+02:00
Commit Message:
Taken lua from revision 943. Delua works right now.
Changed paths:
tools/lua/lapi.cpp
tools/lua/lapi.h
tools/lua/lauxlib.cpp
tools/lua/lauxlib.h
tools/lua/lbuffer.cpp
tools/lua/lbuiltin.cpp
tools/lua/lbuiltin.h
tools/lua/ldo.cpp
tools/lua/ldo.h
tools/lua/lfunc.cpp
tools/lua/lfunc.h
tools/lua/lgc.cpp
tools/lua/lgc.h
tools/lua/liolib.cpp
tools/lua/llex.cpp
tools/lua/llex.h
tools/lua/lmathlib.cpp
tools/lua/lmem.cpp
tools/lua/lmem.h
tools/lua/lobject.cpp
tools/lua/lobject.h
tools/lua/lopcodes.h
tools/lua/lparser.cpp
tools/lua/lparser.h
tools/lua/lrestore.cpp
tools/lua/lsave.cpp
tools/lua/lstate.cpp
tools/lua/lstate.h
tools/lua/lstring.cpp
tools/lua/lstring.h
tools/lua/lstrlib.cpp
tools/lua/ltable.cpp
tools/lua/ltable.h
tools/lua/ltask.cpp
tools/lua/ltask.h
tools/lua/ltm.cpp
tools/lua/ltm.h
tools/lua/lua.h
tools/lua/luadebug.h
tools/lua/lualib.h
tools/lua/lundump.cpp
tools/lua/lundump.h
tools/lua/lvm.cpp
tools/lua/lvm.h
tools/lua/lzio.cpp
tools/lua/lzio.h
tools/module.mk
diff --git a/tools/lua/lapi.cpp b/tools/lua/lapi.cpp
index c3ec46eee..128515f84 100644
--- a/tools/lua/lapi.cpp
+++ b/tools/lua/lapi.cpp
@@ -1,27 +1,24 @@
/*
-** $Id$
+** $Id: lapi.cpp 905 2008-07-20 21:08:22Z aquadran $
** Lua API
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <string.h>
-
-#include <tools/lua/lapi.h>
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/ldo.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lgc.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/ltable.h>
-#include <tools/lua/ltm.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/luadebug.h>
-#include <tools/lua/lvm.h>
+#include "lapi.h"
+#include "lauxlib.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 "lua.h"
+#include "luadebug.h"
+#include "lvm.h"
char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
@@ -35,9 +32,9 @@ TObject *luaA_Address (lua_Object o)
}
-static int normalized_type (TObject *o)
+static int32 normalized_type (TObject *o)
{
- int t = ttype(o);
+ int32 t = ttype(o);
switch (t) {
case LUA_T_PMARK:
return LUA_T_PROTO;
@@ -71,7 +68,7 @@ void luaA_packresults (void)
}
-int luaA_passresults (void)
+int32 luaA_passresults (void)
{
luaD_checkstack(L->Cstack.num);
memcpy(L->stack.top, L->Cstack.lua2C+L->stack.stack,
@@ -81,7 +78,7 @@ int luaA_passresults (void)
}
-static void checkCparams (int nParams)
+static void checkCparams (int32 nParams)
{
if (L->stack.top-L->stack.stack < L->Cstack.base+nParams)
lua_error("API error - wrong number of arguments in C2lua stack");
@@ -115,7 +112,7 @@ lua_Object lua_pop (void)
** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
** 'number' must be 1 to get the first parameter.
*/
-lua_Object lua_lua2C (int number)
+lua_Object lua_lua2C (int32 number)
{
if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
/* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) ==
@@ -124,7 +121,7 @@ lua_Object lua_lua2C (int number)
}
-int lua_callfunction (lua_Object function)
+int32 lua_callfunction (lua_Object function)
{
if (function == LUA_NOOBJECT)
return 1;
@@ -136,13 +133,13 @@ int lua_callfunction (lua_Object function)
}
-lua_Object lua_gettagmethod (int tag, char *event)
+lua_Object lua_gettagmethod (int32 tag, const char *event)
{
return put_luaObject(luaT_gettagmethod(tag, event));
}
-lua_Object lua_settagmethod (int tag, char *event)
+lua_Object lua_settagmethod (int32 tag, const char *event)
{
checkCparams(1);
luaT_settagmethod(tag, event, L->stack.top-1);
@@ -208,7 +205,7 @@ lua_Object lua_createtable (void)
}
-lua_Object lua_getglobal (char *name)
+lua_Object lua_getglobal (const char *name)
{
luaD_checkstack(2); /* may need that to call T.M. */
luaV_getglobal(luaS_new(name));
@@ -216,14 +213,14 @@ lua_Object lua_getglobal (char *name)
}
-lua_Object lua_rawgetglobal (char *name)
+lua_Object lua_rawgetglobal (const char *name)
{
TaggedString *ts = luaS_new(name);
return put_luaObject(&ts->u.s.globalval);
}
-void lua_setglobal (char *name)
+void lua_setglobal (const char *name)
{
checkCparams(1);
luaD_checkstack(2); /* may need that to call T.M. */
@@ -231,7 +228,7 @@ void lua_setglobal (char *name)
}
-void lua_rawsetglobal (char *name)
+void lua_rawsetglobal (const char *name)
{
TaggedString *ts = luaS_new(name);
checkCparams(1);
@@ -240,40 +237,40 @@ void lua_rawsetglobal (char *name)
-int lua_isnil (lua_Object o)
+int32 lua_isnil (lua_Object o)
{
return (o == LUA_NOOBJECT) || (ttype(Address(o)) == LUA_T_NIL);
}
-int lua_istable (lua_Object o)
+int32 lua_istable (lua_Object o)
{
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY);
}
-int lua_isuserdata (lua_Object o)
+int32 lua_isuserdata (lua_Object o)
{
return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA);
}
-int lua_iscfunction (lua_Object o)
+int32 lua_iscfunction (lua_Object o)
{
return (lua_tag(o) == LUA_T_CPROTO);
}
-int lua_isnumber (lua_Object o)
+int32 lua_isnumber (lua_Object o)
{
return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0);
}
-int lua_isstring (lua_Object o)
+int32 lua_isstring (lua_Object o)
{
- int t = lua_tag(o);
+ int32 t = lua_tag(o);
return (t == LUA_T_STRING) || (t == LUA_T_NUMBER);
}
-int lua_isfunction (lua_Object o)
+int32 lua_isfunction (lua_Object o)
{
- int t = lua_tag(o);
+ int32 t = lua_tag(o);
return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO);
}
@@ -285,7 +282,7 @@ double lua_getnumber (lua_Object object)
else return (nvalue(Address(object)));
}
-char *lua_getstring (lua_Object object)
+const char *lua_getstring (lua_Object object)
{
luaC_checkGC(); /* "tostring" may create a new string */
if (object == LUA_NOOBJECT || tostring(Address(object)))
@@ -293,11 +290,11 @@ char *lua_getstring (lua_Object object)
else return (svalue(Address(object)));
}
-long lua_strlen (lua_Object object)
+int32 lua_strlen (lua_Object object)
{
luaC_checkGC(); /* "tostring" may create a new string */
if (object == LUA_NOOBJECT || tostring(Address(object)))
- return 0L;
+ return 0;
else return (tsvalue(Address(object))->u.s.len);
}
@@ -329,7 +326,7 @@ void lua_pushnumber (double n)
incr_top;
}
-void lua_pushlstring (char *s, long len)
+void lua_pushlstring (const char *s, int32 len)
{
tsvalue(L->stack.top) = luaS_newlstr(s, len);
ttype(L->stack.top) = LUA_T_STRING;
@@ -337,7 +334,7 @@ void lua_pushlstring (char *s, long len)
luaC_checkGC();
}
-void lua_pushstring (char *s)
+void lua_pushstring (const char *s)
{
if (s == NULL)
lua_pushnil();
@@ -345,7 +342,7 @@ void lua_pushstring (char *s)
lua_pushlstring(s, strlen(s));
}
-void lua_pushcclosure (lua_CFunction fn, int n)
+void lua_pushcclosure (lua_CFunction fn, int32 n)
{
if (fn == NULL)
lua_error("API error - attempt to push a NULL Cfunction");
@@ -357,7 +354,7 @@ void lua_pushcclosure (lua_CFunction fn, int n)
luaC_checkGC();
}
-void lua_pushusertag (void *u, int tag)
+void lua_pushusertag (void *u, int32 tag)
{
if (tag < 0 && tag != LUA_ANYTAG)
luaT_realtag(tag); /* error if tag is not valid */
@@ -384,13 +381,13 @@ void lua_pushobject (lua_Object o)
}
-int lua_tag (lua_Object lo)
+int32 lua_tag (lua_Object lo)
{
if (lo == LUA_NOOBJECT)
return LUA_T_NIL;
else {
TObject *o = Address(lo);
- int t;
+ int32 t;
switch (t = ttype(o)) {
case LUA_T_USERDATA:
return o->value.ts->u.d.tag;
@@ -413,7 +410,7 @@ int lua_tag (lua_Object lo)
}
-void lua_settag (int tag)
+void lua_settag (int32 tag)
{
checkCparams(1);
luaT_realtag(tag);
@@ -444,11 +441,11 @@ lua_CHFunction lua_callhook = NULL;
lua_LHFunction lua_linehook = NULL;
-lua_Function lua_stackedfunction (int level)
+lua_Function lua_stackedfunction (int32 level)
{
StkId i;
for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) {
- int t = L->stack.stack[i].ttype;
+ int32 t = L->stack.stack[i].ttype;
if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK)
if (level-- == 0)
return Ref(L->stack.stack+i);
@@ -457,7 +454,7 @@ lua_Function lua_stackedfunction (int level)
}
-int lua_currentline (lua_Function func)
+int32 lua_currentline (lua_Function func)
{
TObject *f = Address(func);
return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ?
@@ -465,7 +462,7 @@ int lua_currentline (lua_Function func)
}
-lua_Object lua_getlocal (lua_Function func, int local_number, char **name)
+lua_Object lua_getlocal (lua_Function func, int32 local_number, char **name)
{
/* check whether func is a Lua function */
if (lua_tag(func) != LUA_T_PROTO)
@@ -485,7 +482,7 @@ lua_Object lua_getlocal (lua_Function func, int local_number, char **name)
}
-int lua_setlocal (lua_Function func, int local_number)
+int32 lua_setlocal (lua_Function func, int32 local_number)
{
/* check whether func is a Lua function */
if (lua_tag(func) != LUA_T_PROTO)
@@ -508,7 +505,7 @@ int lua_setlocal (lua_Function func, int local_number)
}
-void lua_funcinfo (lua_Object func, char **filename, int *linedefined)
+void lua_funcinfo (lua_Object func, const char **filename, int32 *linedefined)
{
if (!lua_isfunction(func))
lua_error("API - `funcinfo' called with a non-function value");
@@ -526,13 +523,13 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined)
}
-static int checkfunc (TObject *o)
+static int32 checkfunc (TObject *o)
{
return luaO_equalObj(o, L->stack.top);
}
-char *lua_getobjname (lua_Object o, char **name)
+const char *lua_getobjname (lua_Object o, const char **name)
{ /* try to find a name for given function */
set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc */
if ((*name = luaT_travtagmethods(checkfunc)) != NULL)
@@ -566,9 +563,9 @@ void lua_endblock (void)
-int lua_ref (int lock)
+int32 lua_ref (int32 lock)
{
- int ref;
+ int32 ref;
checkCparams(1);
ref = luaC_ref(L->stack.top-1, lock);
L->stack.top--;
@@ -577,7 +574,7 @@ int lua_ref (int lock)
-lua_Object lua_getref (int ref)
+lua_Object lua_getref (int32 ref)
{
TObject *o = luaC_getref(ref);
return (o ? put_luaObject(o) : LUA_NOOBJECT);
@@ -589,11 +586,11 @@ lua_Object lua_getref (int ref)
** Derived functions
** =======================================================
*/
-int (lua_call) (char *name) { return lua_call(name); }
+int32 (lua_call) (char *name) { return lua_call(name); }
-void (lua_pushref) (int ref) { lua_pushref(ref); }
+void (lua_pushref) (int32 ref) { lua_pushref(ref); }
-int (lua_refobject) (lua_Object o, int l) { return lua_refobject(o, l); }
+int32 (lua_refobject) (lua_Object o, int32 l) { return lua_refobject(o, l); }
void (lua_register) (char *n, lua_CFunction f) { lua_register(n, f); }
@@ -601,7 +598,7 @@ void (lua_pushuserdata) (void *u) { lua_pushuserdata(u); }
void (lua_pushcfunction) (lua_CFunction f) { lua_pushcfunction(f); }
-int (lua_clonetag) (int t) { return lua_clonetag(t); }
+int32 (lua_clonetag) (int32 t) { return lua_clonetag(t); }
@@ -611,7 +608,7 @@ int (lua_clonetag) (int t) { return lua_clonetag(t); }
** API: set a function as a fallback
*/
-static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults)
+static void do_unprotectedrun (lua_CFunction f, int32 nParams, int32 nResults)
{
StkId base = (L->stack.top-L->stack.stack)-nParams;
luaD_openstack(nParams);
diff --git a/tools/lua/lapi.h b/tools/lua/lapi.h
index d2904f2ed..11950cbb2 100644
--- a/tools/lua/lapi.h
+++ b/tools/lua/lapi.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lapi.h 905 2008-07-20 21:08:22Z aquadran $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/
@@ -8,13 +8,13 @@
#define lapi_h
-#include <tools/lua/lua.h>
-#include <tools/lua/lobject.h>
+#include "lua.h"
+#include "lobject.h"
TObject *luaA_Address (lua_Object o);
void luaA_pushobject (TObject *o);
void luaA_packresults (void);
-int luaA_passresults (void);
+int32 luaA_passresults (void);
#endif
diff --git a/tools/lua/lauxlib.cpp b/tools/lua/lauxlib.cpp
index d2c10921e..a59882d8c 100644
--- a/tools/lua/lauxlib.cpp
+++ b/tools/lua/lauxlib.cpp
@@ -1,36 +1,31 @@
/*
-** $Id$
+** $Id: lauxlib.cpp 905 2008-07-20 21:08:22Z aquadran $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
/* Please Notice: This file uses only the official API of Lua
** Any function declared here could be written as an application
** function. With care, these functions can be used by other libraries.
*/
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/luadebug.h>
-#include <tools/lua/lmem.h>
+#include "lauxlib.h"
+#include "lua.h"
+#include "luadebug.h"
+#include "lmem.h"
-int luaL_findstring (char *name, char *list[]) {
- int i;
+int32 luaL_findstring (const char *name, const char *list[]) {
+ int32 i;
for (i=0; list[i]; i++)
if (strcmp(list[i], name) == 0)
return i;
return -1; /* name not found */
}
-void luaL_argerror (int numarg, char *extramsg)
+void luaL_argerror (int32 numarg, const char *extramsg)
{
- char *funcname;
+ const char *funcname;
lua_getobjname(lua_stackedfunction(0), &funcname);
if (funcname == NULL)
funcname = "???";
@@ -41,7 +36,7 @@ void luaL_argerror (int numarg, char *extramsg)
numarg, funcname, extramsg);
}
-char *luaL_check_lstr (int numArg, long *len)
+const char *luaL_check_lstr (int32 numArg, int32 *len)
{
lua_Object o = lua_getparam(numArg);
luaL_arg_check(lua_isstring(o), numArg, "string expected");
@@ -49,13 +44,13 @@ char *luaL_check_lstr (int numArg, long *len)
return lua_getstring(o);
}
-char *luaL_opt_lstr (int numArg, char *def, long *len)
+const char *luaL_opt_lstr (int32 numArg, const char *def, int32 *len)
{
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
luaL_check_lstr(numArg, len);
}
-double luaL_check_number (int numArg)
+double luaL_check_number (int32 numArg)
{
lua_Object o = lua_getparam(numArg);
luaL_arg_check(lua_isnumber(o), numArg, "number expected");
@@ -63,28 +58,28 @@ double luaL_check_number (int numArg)
}
-double luaL_opt_number (int numArg, double def)
+double luaL_opt_number (int32 numArg, double def)
{
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
luaL_check_number(numArg);
-}
+}
-lua_Object luaL_tablearg (int arg)
+lua_Object luaL_tablearg (int32 arg)
{
lua_Object o = lua_getparam(arg);
luaL_arg_check(lua_istable(o), arg, "table expected");
return o;
}
-lua_Object luaL_functionarg (int arg)
+lua_Object luaL_functionarg (int32 arg)
{
lua_Object o = lua_getparam(arg);
luaL_arg_check(lua_isfunction(o), arg, "function expected");
return o;
}
-lua_Object luaL_nonnullarg (int numArg)
+lua_Object luaL_nonnullarg (int32 numArg)
{
lua_Object o = lua_getparam(numArg);
luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
@@ -93,7 +88,7 @@ lua_Object luaL_nonnullarg (int numArg)
luaL_libList *list_of_libs = NULL;
-void luaL_addlibtolist(luaL_reg *l, int n) {
+void luaL_addlibtolist(luaL_reg *l, int32 n) {
luaL_libList *list = (luaL_libList *)luaM_malloc(sizeof(luaL_libList));
list->list = l;
list->number = n;
@@ -110,9 +105,9 @@ void lua_removelibslists(void) {
}
}
-void luaL_openlib (struct luaL_reg *l, int n)
+void luaL_openlib (struct luaL_reg *l, int32 n)
{
- int i;
+ int32 i;
lua_open(); /* make sure lua is already open */
for (i=0; i<n; i++)
lua_register(l[i].name, l[i].func);
@@ -120,7 +115,7 @@ void luaL_openlib (struct luaL_reg *l, int n)
}
-void luaL_verror (char *fmt, ...)
+void luaL_verror (const char *fmt, ...)
{
char buff[500];
va_list argp;
diff --git a/tools/lua/lauxlib.h b/tools/lua/lauxlib.h
index c89f072b2..f6645474f 100644
--- a/tools/lua/lauxlib.h
+++ b/tools/lua/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lauxlib.h 905 2008-07-20 21:08:22Z aquadran $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -9,17 +9,17 @@
#define auxlib_h
-#include <tools/lua/lua.h>
+#include "lua.h"
struct luaL_reg {
- char *name;
+ const char *name;
lua_CFunction func;
};
struct luaL_libList {
luaL_reg *list;
- int number;
+ int32 number;
luaL_libList *next;
};
@@ -28,28 +28,28 @@ extern luaL_libList *list_of_libs;
#define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \
luaL_argerror(numarg,extramsg)
-void luaL_openlib (struct luaL_reg *l, int n);
-void luaL_addlibtolist(luaL_reg *l, int n);
-void luaL_argerror (int numarg, char *extramsg);
+void luaL_openlib (struct luaL_reg *l, int32 n);
+void luaL_addlibtolist(luaL_reg *l, int32 n);
+void luaL_argerror (int32 numarg, const char *extramsg);
#define luaL_check_string(n) (luaL_check_lstr((n), NULL))
-char *luaL_check_lstr (int numArg, long *len);
+const char *luaL_check_lstr (int32 numArg, int32 *len);
#define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL))
-char *luaL_opt_lstr (int numArg, char *def, long *len);
-double luaL_check_number (int numArg);
-double luaL_opt_number (int numArg, double def);
-lua_Object luaL_functionarg (int arg);
-lua_Object luaL_tablearg (int arg);
-lua_Object luaL_nonnullarg (int numArg);
-void luaL_verror (char *fmt, ...);
-char *luaL_openspace (int size);
+const char *luaL_opt_lstr (int32 numArg, const char *def, int32 *len);
+double luaL_check_number (int32 numArg);
+double luaL_opt_number (int32 numArg, double def);
+lua_Object luaL_functionarg (int32 arg);
+lua_Object luaL_tablearg (int32 arg);
+lua_Object luaL_nonnullarg (int32 numArg);
+void luaL_verror (const char *fmt, ...);
+char *luaL_openspace (int32 size);
void luaL_resetbuffer (void);
-void luaL_addchar (int c);
-int luaL_getsize (void);
-void luaL_addsize (int n);
-int luaL_newbuffer (int size);
-void luaL_oldbuffer (int old);
+void luaL_addchar (int32 c);
+int32 luaL_getsize (void);
+void luaL_addsize (int32 n);
+int32 luaL_newbuffer (int32 size);
+void luaL_oldbuffer (int32 old);
char *luaL_buffer (void);
-int luaL_findstring (char *name, char *list[]);
+int32 luaL_findstring (const char *name, const char *list[]);
#endif
diff --git a/tools/lua/lbuffer.cpp b/tools/lua/lbuffer.cpp
index feb4322c9..45a363623 100644
--- a/tools/lua/lbuffer.cpp
+++ b/tools/lua/lbuffer.cpp
@@ -1,15 +1,13 @@
/*
-** $Id$
+** $Id: lbuffer.cpp 905 2008-07-20 21:08:22Z aquadran $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
-#include <stdio.h>
-
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lstate.h>
+#include "lauxlib.h"
+#include "lmem.h"
+#include "lstate.h"
/*-------------------------------------------------------
@@ -20,10 +18,10 @@
#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
-static void Openspace (int size)
+static void Openspace (int32 size)
{
lua_State *l = L; /* to optimize */
- int base = l->Mbuffbase-l->Mbuffer;
+ int32 base = l->Mbuffbase-l->Mbuffer;
l->Mbuffsize *= 2;
if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */
l->Mbuffsize = l->Mbuffnext+size;
@@ -32,14 +30,14 @@ static void Openspace (int size)
}
-char *luaL_openspace (int size)
+char *luaL_openspace (int32 size)
{
openspace(size);
return L->Mbuffer+L->Mbuffnext;
}
-void luaL_addchar (int c)
+void luaL_addchar (int32 c)
{
openspace(BUFF_STEP);
L->Mbuffer[L->Mbuffnext++] = c;
@@ -52,26 +50,26 @@ void luaL_resetbuffer (void)
}
-void luaL_addsize (int n)
+void luaL_addsize (int32 n)
{
L->Mbuffnext += n;
}
-int luaL_getsize (void)
+int32 luaL_getsize (void)
{
return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer);
}
-int luaL_newbuffer (int size)
+int32 luaL_newbuffer (int32 size)
{
- int old = L->Mbuffbase-L->Mbuffer;
+ int32 old = L->Mbuffbase-L->Mbuffer;
openspace(size);
L->Mbuffbase = L->Mbuffer+L->Mbuffnext;
return old;
}
-void luaL_oldbuffer (int old)
+void luaL_oldbuffer (int32 old)
{
L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
L->Mbuffbase = L->Mbuffer+old;
diff --git a/tools/lua/lbuiltin.cpp b/tools/lua/lbuiltin.cpp
index 421449acc..c63e5ed6a 100644
--- a/tools/lua/lbuiltin.cpp
+++ b/tools/lua/lbuiltin.cpp
@@ -1,29 +1,24 @@
/*
-** $Id$
+** $Id: lbuiltin.cpp 905 2008-07-20 21:08:22Z aquadran $
** Built-in functions
** See Copyright Notice in lua.h
*/
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <tools/lua/lapi.h>
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lbuiltin.h>
-#include <tools/lua/ldo.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/ltable.h>
-#include <tools/lua/ltask.h>
-#include <tools/lua/ltm.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/lundump.h>
+#include "lapi.h"
+#include "lauxlib.h"
+#include "lbuiltin.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "ltask.h"
+#include "ltm.h"
+#include "lua.h"
+#include "lundump.h"
@@ -100,7 +95,7 @@ static void foreach (void)
{
TObject t = *luaA_Address(luaL_tablearg(1));
TObject f = *luaA_Address(luaL_functionarg(2));
- int i;
+ int32 i;
for (i=0; i<avalue(&t)->nhash; i++) {
Node *nd = &(avalue(&t)->node[i]);
if (ttype(ref(nd)) != LUA_T_NIL && ttype(val(nd)) != LUA_T_NIL) {
@@ -118,8 +113,8 @@ static void foreach (void)
static void internaldostring (void)
{
- long l;
- char *s = luaL_check_lstr(1, &l);
+ int32 l;
+ const char *s = luaL_check_lstr(1, &l);
if (*s == ID_CHUNK)
lua_error("`dostring' cannot run pre-compiled code");
if (lua_dobuffer(s, l, luaL_opt_string(2, NULL)) == 0)
@@ -130,7 +125,7 @@ static void internaldostring (void)
static void internaldofile (void)
{
- char *fname = luaL_opt_string(1, NULL);
+ const char *fname = luaL_opt_string(1, NULL);
if (lua_dofile(fname) == 0)
if (luaA_passresults() == 0)
lua_pushuserdata(NULL); /* at least one result to signal no errors */
@@ -185,7 +180,7 @@ static void to_string (void) {
static void luaI_print (void) {
TaggedString *ts = luaS_new("tostring");
lua_Object obj;
- int i = 1;
+ int32 i = 1;
while ((obj = lua_getparam(i++)) != LUA_NOOBJECT) {
luaA_pushobject(&ts->u.s.globalval);
lua_pushobject(obj);
@@ -209,19 +204,20 @@ static void luaI_type (void)
static void tonumber (void)
{
- int base = (int)luaL_opt_number(2, 10);
+ int32 base = (int32)luaL_opt_number(2, 10);
if (base == 10) { /* standard conversion */
lua_Object o = lua_getparam(1);
if (lua_isnumber(o))
lua_pushnumber(lua_getnumber(o));
}
else {
- char *s = luaL_check_string(1);
- unsigned long n;
+ const char *s = luaL_check_string(1);
+ char *e;
+ int32 n;
luaL_arg_check(0 <= base && base <= 36, 2, "base out of range");
- n = strtol(s, &s, base);
- while (isspace(*s)) s++; /* skip trailing spaces */
- if (*s) lua_pushnil(); /* invalid format: return nil */
+ n = (int32)strtol(s, &e, base);
+ while (isspace(*e)) e++; /* skip trailing spaces */
+ if (*e) lua_pushnil(); /* invalid format: return nil */
else lua_pushnumber(n);
}
}
@@ -243,7 +239,7 @@ static void luaI_assert (void)
static void setglobal (void)
{
- char *n = luaL_check_string(1);
+ const char *n = luaL_check_string(1);
lua_Object value = luaL_nonnullarg(2);
lua_pushobject(value);
lua_setglobal(n);
@@ -252,7 +248,7 @@ static void setglobal (void)
static void rawsetglobal (void)
{
- char *n = luaL_check_string(1);
+ const char *n = luaL_check_string(1);
lua_Object value = luaL_nonnullarg(2);
lua_pushobject(value);
lua_rawsetglobal(n);
@@ -275,22 +271,22 @@ static void luatag (void)
}
-static int getnarg (lua_Object table)
+static int32 getnarg (lua_Object table)
{
lua_Object temp;
/* temp = table.n */
lua_pushobject(table); lua_pushstring("n"); temp = lua_rawgettable();
- return (lua_isnumber(temp) ? (int)lua_getnumber(temp) : MAX_INT);
+ return (lua_isnumber(temp) ? (int32)lua_getnumber(temp) : MAX_INT);
}
static void luaI_call (void)
{
lua_Object f = luaL_nonnullarg(1);
lua_Object arg = luaL_tablearg(2);
- char *options = luaL_opt_string(3, "");
+ const char *options = luaL_opt_string(3, "");
lua_Object err = lua_getparam(4);
- int narg = getnarg(arg);
- int i, status;
+ int32 narg = getnarg(arg);
+ int32 i, status;
if (err != LUA_NOOBJECT) { /* set new error method */
lua_pushobject(err);
err = lua_seterrormethod();
@@ -330,7 +326,7 @@ static void settag (void)
{
lua_Object o = luaL_tablearg(1);
lua_pushobject(o);
- lua_settag((int)luaL_check_number(2));
+ lua_settag((int32)luaL_check_number(2));
lua_pushobject(o); /* returns first argument */
}
@@ -343,8 +339,8 @@ static void newtag (void)
static void copytagmethods (void)
{
- lua_pushnumber(lua_copytagmethods((int)luaL_check_number(1),
- (int)luaL_check_number(2)));
+ lua_pushnumber(lua_copytagmethods((int32)luaL_check_number(1),
+ (int32)luaL_check_number(2)));
}
@@ -369,14 +365,14 @@ static void settagmethod (void)
{
lua_Object nf = luaL_nonnullarg(3);
lua_pushobject(nf);
- lua_pushobject(lua_settagmethod((int)luaL_check_number(1),
+ lua_pushobject(lua_settagmethod((int32)luaL_check_number(1),
luaL_check_string(2)));
}
static void gettagmethod (void)
{
- lua_pushobject(lua_gettagmethod((int)luaL_check_number(1),
+ lua_pushobject(lua_gettagmethod((int32)luaL_check_number(1),
luaL_check_string(2)));
}
@@ -391,7 +387,7 @@ static void seterrormethod (void)
static void luaI_collectgarbage (void)
{
- lua_pushnumber(lua_collectgarbage((long int)luaL_opt_number(1, 0)));
+ lua_pushnumber(lua_collectgarbage((int32)luaL_opt_number(1, 0)));
}
@@ -414,7 +410,7 @@ static void countlist (void)
char *s = luaL_check_string(1);
GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next :
(s[0]=='p') ? L->rootproto.next : L->rootglobal.next;
- int i=0;
+ int32 i=0;
while (l) {
i++;
l = l->next;
@@ -428,7 +424,7 @@ static void testC (void)
#define getnum(s) ((*s++) - '0')
#define getname(s) (nome[0] = *s++, nome)
- static int locks[10];
+ static int32 locks[10];
lua_Object reg[10];
char nome[2];
char *s = luaL_check_string(1);
@@ -446,16 +442,16 @@ static void testC (void)
break;
}
case 'P': reg[getnum(s)] = lua_pop(); break;
- case 'g': { int n=getnum(s); reg[n]=lua_getglobal(getname(s)); break; }
- case 'G': { int n = getnum(s);
+ case 'g': { int32 n=getnum(s); reg[n]=lua_getglobal(getname(s)); break; }
+ case 'G': { int32 n = getnum(s);
reg[n] = lua_rawgetglobal(getname(s));
break;
}
case 'l': locks[getnum(s)] = lua_ref(1); break;
case 'L': locks[getnum(s)] = lua_ref(0); break;
- case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; }
+ case 'r': { int32 n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; }
case 'u': lua_unref(locks[getnum(s)]); break;
- case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; }
+ case 'p': { int32 n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; }
case '=': lua_setglobal(getname(s)); break;
case 's': lua_pushstring(getname(s)); break;
case 'o': lua_pushobject(reg[getnum(s)]); break;
diff --git a/tools/lua/lbuiltin.h b/tools/lua/lbuiltin.h
index 81762c4c8..a76db6dfa 100644
--- a/tools/lua/lbuiltin.h
+++ b/tools/lua/lbuiltin.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lbuiltin.h 692 2006-02-09 23:57:31Z fingolfin $
** Built-in functions
** See Copyright Notice in lua.h
*/
diff --git a/tools/lua/ldo.cpp b/tools/lua/ldo.cpp
index 42f519e59..faaab66b6 100644
--- a/tools/lua/ldo.cpp
+++ b/tools/lua/ldo.cpp
@@ -1,30 +1,25 @@
/*
-** $Id$
+** $Id: ldo.cpp 905 2008-07-20 21:08:22Z aquadran $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
-#include <setjmp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <tools/lua/ldo.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lgc.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lopcodes.h>
-#include <tools/lua/lparser.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/ltask.h>
-#include <tools/lua/ltm.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/luadebug.h>
-#include <tools/lua/lundump.h>
-#include <tools/lua/lvm.h>
-#include <tools/lua/lzio.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 "ltask.h"
+#include "ltm.h"
+#include "lua.h"
+#include "luadebug.h"
+#include "lundump.h"
+#include "lvm.h"
+#include "lzio.h"
@@ -74,12 +69,12 @@ void luaD_initthr (void)
}
-void luaD_checkstack (int n)
+void luaD_checkstack (int32 n)
{
struct Stack *S = &L->stack;
if (S->last-S->top <= n) {
StkId top = S->top-S->stack;
- int stacksize = (S->last-S->stack)+1+STACK_UNIT+n;
+ int32 stacksize = (S->last-S->stack)+1+STACK_UNIT+n;
S->stack = luaM_reallocvector(S->stack, stacksize, TObject);
S->last = S->stack+(stacksize-1);
S->top = S->stack + top;
@@ -98,7 +93,7 @@ void luaD_checkstack (int n)
*/
void luaD_adjusttop (StkId newtop)
{
- int diff = newtop-(L->stack.top-L->stack.stack);
+ int32 diff = newtop-(L->stack.top-L->stack.stack);
if (diff <= 0)
L->stack.top += diff;
else {
@@ -112,7 +107,7 @@ void luaD_adjusttop (StkId newtop)
/*
** Open a hole below "nelems" from the L->stack.top.
*/
-void luaD_openstack (int nelems)
+void luaD_openstack (int32 nelems)
{
luaO_memup(L->stack.top-nelems+1, L->stack.top-nelems,
nelems*sizeof(TObject));
@@ -120,7 +115,7 @@ void luaD_openstack (int nelems)
}
-void luaD_lineHook (int line)
+void luaD_lineHook (int32 line)
{
struct C_Lua_Stack oldCLS = L->Cstack;
StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
@@ -131,7 +126,7 @@ void luaD_lineHook (int line)
}
-void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn)
+void luaD_callHook (StkId base, TProtoFunc *tf, int32 isreturn)
{
struct C_Lua_Stack oldCLS = L->Cstack;
StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack;
@@ -160,7 +155,7 @@ static StkId callC (lua_CFunction f, StkId base)
struct C_Lua_Stack *CS = &L->Cstack;
struct C_Lua_Stack oldCLS = *CS;
StkId firstResult;
- int numarg = (L->stack.top-L->stack.stack) - base;
+ int32 numarg = (L->stack.top-L->stack.stack) - base;
CS->num = numarg;
CS->lua2C = base;
CS->base = base+numarg; /* == top-stack */
@@ -178,7 +173,7 @@ static StkId callC (lua_CFunction f, StkId base)
static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base)
{
TObject *pbase;
- int nup = cl->nelems; /* number of upvalues */
+ int32 nup = cl->nelems; /* number of upvalues */
luaD_checkstack(nup);
pbase = L->stack.stack+base; /* care: previous call may change this */
/* open space for upvalues as extra arguments */
@@ -190,7 +185,7 @@ static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base)
}
-void luaD_callTM (TObject *f, int nParams, int nResults)
+void luaD_callTM (TObject *f, int32 nParams, int32 nResults)
{
luaD_openstack(nParams);
*(L->stack.top-nParams-1) = *f;
@@ -211,13 +206,13 @@ static void adjust_varargs (StkId first_extra_arg)
/*
** Prepare the stack for calling a Lua function.
*/
-void luaD_precall (TObject *f, StkId base, int nResults)
+void luaD_precall (TObject *f, StkId base, int32 nResults)
{
/* Create a new CallInfo record */
if (L->ci+1 == L->end_ci) {
- int size_ci = L->end_ci - L->base_ci;
- int index_ci = L->ci - L->base_ci;
- int new_ci_size = size_ci * 2 * sizeof(CallInfo);
+ int32 size_ci = L->end_ci - L->base_ci;
+ int32 index_ci = L->ci - L->base_ci;
+ int32 new_ci_size = size_ci * 2 * sizeof(CallInfo);
CallInfo *new_ci = (CallInfo *)luaM_malloc(new_ci_size);
memcpy(new_ci, L->base_ci, L->base_ci_size);
memset(new_ci + (L->base_ci_size / sizeof(CallInfo)), 0, (new_ci_size) - L->base_ci_size);
@@ -260,9 +255,9 @@ void luaD_precall (TObject *f, StkId base, int nResults)
** Adjust the stack to the desired number of results
*/
void luaD_postret (StkId firstResult) {
- int i;
+ int32 i;
StkId base = L->ci->base;
- int nResults = L->ci->nResults;
+ int32 nResults = L->ci->nResults;
if (L->ci == L->base_ci)
lua_error("call stack underflow");
/* adjust the number of results */
@@ -284,7 +279,7 @@ void luaD_postret (StkId firstResult) {
** When returns, the results are on the L->stack.stack, between [L->stack.stack+base-1,L->stack.top).
** The number of results is nResults, unless nResults=MULT_RET.
*/
-void luaD_call (StkId base, int nResults)
+void luaD_call (StkId base, int32 nResults)
{
StkId firstResult;
TObject *func = L->stack.stack+base-1;
@@ -322,7 +317,7 @@ void luaD_call (StkId base, int nResults)
}
-static void travstack (struct Stack *S, int (*fn)(TObject *)) {
+static void travstack (struct Stack *S, int32 (*fn)(TObject *)) {
StkId i;
for (i = (S->top-1)-S->stack; i>=0; i--)
fn(S->stack+i);
@@ -331,7 +326,7 @@ static void travstack (struct Stack *S, int (*fn)(TObject *)) {
/*
** Traverse all objects on L->stack.stack, and all other active stacks
*/
-void luaD_travstack (int (*fn)(TObject *))
+void luaD_travstack (int32 (*fn)(TObject *))
{
struct lua_Task *t;
travstack(&L->stack, fn);
@@ -342,7 +337,7 @@ void luaD_travstack (int (*fn)(TObject *))
-static void message (char *s)
+static void message (const char *s)
{
TObject im = L->errorim;
if (ttype(&im) != LUA_T_NIL) {
@@ -354,7 +349,7 @@ static void message (char *s)
/*
** Reports an error, and jumps up to the available recover label
*/
-void lua_error (char *s)
+void lua_error (const char *s)
{
if (s) message(s);
if (L->errorJmp)
@@ -369,7 +364,7 @@ void lua_error (char *s)
** Call the function at L->Cstack.base, and incorporate results on
** the Lua2C structure.
*/
-static void do_callinc (int nResults)
+static void do_callinc (int32 nResults)
{
StkId base = L->Cstack.base;
luaD_call(base+1, nResults);
@@ -383,13 +378,13 @@ static void do_callinc (int nResults)
** Execute a protected call. Assumes that function is at L->Cstack.base and
** parameters are on top of it. Leave nResults on the stack.
*/
-int luaD_protectedrun (int nResults)
+int32 luaD_protectedrun (int32 nResults)
{
jmp_buf myErrorJmp;
- int status;
+ int32 status;
struct C_Lua_Stack oldCLS = L->Cstack;
jmp_buf *oldErr = L->errorJmp;
- int ci_len = L->ci - L->base_ci;
+ int32 ci_len = L->ci - L->base_ci;
L->errorJmp = &myErrorJmp;
if (setjmp(myErrorJmp) == 0) {
do_callinc(nResults);
@@ -409,9 +404,9 @@ int luaD_protectedrun (int nResults)
/*
** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load
*/
-static int protectedparser (ZIO *z, int bin)
+static int32 protectedparser (ZIO *z, int32 bin)
{
- volatile int status;
+ volatile int32 status;
TProtoFunc *volatile tf;
jmp_buf myErrorJmp;
jmp_buf *volatile oldErr = L->errorJmp;
@@ -435,16 +430,16 @@ static int protectedparser (ZIO *z, int bin)
}
-static int do_main (ZIO *z, int bin)
+static int32 do_main (ZIO *z, int32 bin)
{
- int status;
+ int32 status;
do {
- long old_blocks = (luaC_checkGC(), L->nblocks);
+ int32 old_blocks = (luaC_checkGC(), L->nblocks);
status = protectedparser(z, bin);
if (status == 1) return 1; /* error */
else if (status == 2) return 0; /* 'natural' end */
else {
- unsigned long newelems2 = 2*(L->nblocks-old_blocks);
+ int32 newelems2 = 2*(L->nblocks-old_blocks);
L->GCthreshold += newelems2;
status = luaD_protectedrun(MULT_RET);
L->GCthreshold -= newelems2;
@@ -465,12 +460,12 @@ void luaD_gcIM (TObject *o)
}
-int lua_dofile (char *filename)
+int32 lua_dofile (const char *filename)
{
ZIO z;
- int status;
- int c;
- int bin;
+ int32 status;
+ int32 c;
+ int32 bin;
FILE *f = (filename == NULL) ? stdin : fopen(filename, "r");
if (f == NULL)
return 2;
@@ -493,7 +488,7 @@ int lua_dofile (char *filename)
#define SSIZE_PREF "20"
-static void build_name (char *str, char *name) {
+static void build_name (const char *str, char *name) {
if (str == NULL || *str == ID_CHUNK)
strcpy(name, "(buffer)");
else {
@@ -508,15 +503,15 @@ static void build_name (char *str, char *name) {
}
-int lua_dostring (char *str) {
+int32 lua_dostring (const char *str) {
return lua_dobuffer(str, strlen(str), NULL);
}
-int lua_dobuffer (char *buff, int size, char *name) {
+int32 lua_dobuffer (const char *buff, int32 size, const char *name) {
char newname[SIZE_PREF+25];
ZIO z;
- int status;
+ int32 status;
if (name==NULL) {
build_name(buff, newname);
name = newname;
diff --git a/tools/lua/ldo.h b/tools/lua/ldo.h
index 7be1a0208..9e236430a 100644
--- a/tools/lua/ldo.h
+++ b/tools/lua/ldo.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: ldo.h 905 2008-07-20 21:08:22Z aquadran $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -8,8 +8,8 @@
#define ldo_h
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
+#include "lobject.h"
+#include "lstate.h"
#define MULT_RET 255
@@ -33,17 +33,17 @@
void luaD_init (void);
void luaD_initthr (void);
void luaD_adjusttop (StkId newtop);
-void luaD_openstack (int nelems);
-void luaD_lineHook (int line);
-void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn);
-void luaD_precall (TObject *f, StkId base, int nResults);
+void luaD_openstack (int32 nelems);
+void luaD_lineHook (int32 line);
+void luaD_callHook (StkId base, TProtoFunc *tf, int32 isreturn);
+void luaD_precall (TObject *f, StkId base, int32 nResults);
void luaD_postret (StkId firstResult);
-void luaD_call (StkId base, int nResults);
-void luaD_callTM (TObject *f, int nParams, int nResults);
-int luaD_protectedrun (int nResults);
+void luaD_call (StkId base, int32 nResults);
+void luaD_callTM (TObject *f, int32 nParams, int32 nResults);
+int32 luaD_protectedrun (int32 nResults);
void luaD_gcIM (TObject *o);
-void luaD_travstack (int (*fn)(TObject *));
-void luaD_checkstack (int n);
+void luaD_travstack (int32 (*fn)(TObject *));
+void luaD_checkstack (int32 n);
#endif
diff --git a/tools/lua/lfunc.cpp b/tools/lua/lfunc.cpp
index 48506f3a8..61ab888a0 100644
--- a/tools/lua/lfunc.cpp
+++ b/tools/lua/lfunc.cpp
@@ -1,22 +1,21 @@
/*
-** $Id$
+** $Id: lfunc.cpp 905 2008-07-20 21:08:22Z aquadran $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lstate.h>
+#include "lfunc.h"
+#include "lmem.h"
+#include "lstate.h"
#define gcsizeproto(p) 5 /* approximate "weight" for a prototype */
#define gcsizeclosure(c) 1 /* approximate "weight" for a closure */
-Closure *luaF_newclosure (int nelems)
+Closure *luaF_newclosure (int32 nelems)
{
Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject));
luaO_insertlist(&(L->rootcl), (GCnode *)c);
@@ -77,9 +76,9 @@ void luaF_freeclosure (Closure *l)
** Look for n-th local variable at line "line" in function "func".
** Returns NULL if not found.
*/
-char *luaF_getlocalname (TProtoFunc *func, int local_number, int line)
+char *luaF_getlocalname (TProtoFunc *func, int32 local_number, int32 line)
{
- int count = 0;
+ int32 count = 0;
char *varname = NULL;
LocVar *lv = func->locvars;
if (lv == NULL)
diff --git a/tools/lua/lfunc.h b/tools/lua/lfunc.h
index 4c57ceb40..28272465c 100644
--- a/tools/lua/lfunc.h
+++ b/tools/lua/lfunc.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lfunc.h 905 2008-07-20 21:08:22Z aquadran $
** Lua Function structures
** See Copyright Notice in lua.h
*/
@@ -8,16 +8,16 @@
#define lfunc_h
-#include <tools/lua/lobject.h>
+#include "lobject.h"
TProtoFunc *luaF_newproto (void);
-Closure *luaF_newclosure (int nelems);
+Closure *luaF_newclosure (int32 nelems);
void luaF_freeproto (TProtoFunc *l);
void luaF_freeclosure (Closure *l);
-char *luaF_getlocalname (TProtoFunc *func, int local_number, int line);
+char *luaF_getlocalname (TProtoFunc *func, int32 local_number, int32 line);
#endif
diff --git a/tools/lua/lgc.cpp b/tools/lua/lgc.cpp
index 4d23c2c0d..7c978f2cb 100644
--- a/tools/lua/lgc.cpp
+++ b/tools/lua/lgc.cpp
@@ -1,24 +1,24 @@
/*
-** $Id$
+** $Id: lgc.cpp 905 2008-07-20 21:08:22Z aquadran $
** Garbage Collector
** See Copyright Notice in lua.h
*/
-#include <tools/lua/ldo.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lgc.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/ltable.h>
-#include <tools/lua/ltm.h>
-#include <tools/lua/lua.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 "lua.h"
-static int markobject (TObject *o);
+static int32 markobject (TObject *o);
@@ -29,9 +29,9 @@ static int markobject (TObject *o);
*/
-int luaC_ref (TObject *o, int lock)
+int32 luaC_ref (TObject *o, int32 lock)
{
- int ref;
+ int32 ref;
if (ttype(o) == LUA_T_NIL)
ref = -1; /* special ref for nil */
else {
@@ -39,7 +39,7 @@ int luaC_ref (TObject *o, int lock)
if (L->refArray[ref].status == FREE)
goto found;
/* no more empty spaces */ {
- int oldSize = L->refSize;
+ int32 oldSize = L->refSize;
L->refSize = luaM_growvector(&L->refArray, L->refSize, struct ref,
refEM, MAX_INT);
for (ref=oldSize; ref<L->refSize; ref++)
@@ -53,14 +53,14 @@ int luaC_ref (TObject *o, int lock)
}
-void lua_unref (int ref)
+void lua_unref (int32 ref)
{
if (ref >= 0 && ref < L->refSize)
L->refArray[ref].status = FREE;
}
-TObject* luaC_getref (int ref)
+TObject* luaC_getref (int32 ref)
{
if (ref == -1)
return &luaO_nilobject;
@@ -74,14 +74,14 @@ TObject* luaC_getref (int ref)
static void travlock (void)
{
- int i;
+ int32 i;
for (i=0; i<L->refSize; i++)
if (L->refArray[i].status == LOCK)
markobject(&L->refArray[i].o);
}
-static int ismarked (TObject *o)
+static int32 ismarked (TObject *o)
{
/* valid only for locked objects */
switch (o->ttype) {
@@ -106,7 +106,7 @@ static int ismarked (TObject *o)
static void invalidaterefs (void)
{
- int i;
+ int32 i;
for (i=0; i<L->refSize; i++)
if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o))
L->refArray[i].status = COLLECTED;
@@ -167,7 +167,7 @@ static void protomark (TProtoFunc *f)
{
if (!f->head.marked) {
LocVar *v = f->locvars;
- int i;
+ int32 i;
f->head.marked = 1;
if (f->fileName)
strmark(f->fileName);
@@ -185,7 +185,7 @@ static void protomark (TProtoFunc *f)
static void closuremark (Closure *f)
{
if (!f->head.marked) {
- int i;
+ int32 i;
f->head.marked = 1;
for (i=f->nelems; i>=0; i--)
markobject(&f->consts[i]);
@@ -196,7 +196,7 @@ static void closuremark (Closure *f)
static void hashmark (Hash *h)
{
if (!h->head.marked) {
- int i;
+ int32 i;
h->head.marked = 1;
for (i=0; i<nhash(h); i++) {
Node *n = node(h,i);
@@ -222,7 +222,7 @@ static void globalmark (void)
}
-static int markobject (TObject *o)
+static int32 markobject (TObject *o)
{
switch (ttype(o)) {
case LUA_T_USERDATA: case LUA_T_STRING:
@@ -253,9 +253,9 @@ static void markall (void)
}
-long lua_collectgarbage (long limit)
+int32 lua_collectgarbage (int32 limit)
{
- unsigned long recovered = L->nblocks; /* to subtract nblocks after gc */
+ int32 recovered = L->nblocks; /* to subtract nblocks after gc */
Hash *freetable;
TaggedString *freestr;
TProtoFunc *freefunc;
diff --git a/tools/lua/lgc.h b/tools/lua/lgc.h
index d67e066ca..43e2fb4f1 100644
--- a/tools/lua/lgc.h
+++ b/tools/lua/lgc.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lgc.h 934 2008-07-26 18:06:34Z aquadran $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -8,12 +8,12 @@
#define lgc_h
-#include <tools/lua/lobject.h>
+#include "lobject.h"
void luaC_checkGC (void);
-TObject* luaC_getref (int ref);
-int luaC_ref (TObject *o, int lock);
+TObject* luaC_getref (int32 ref);
+int32 luaC_ref (TObject *o, int32 lock);
void luaC_hashcallIM (Hash *l);
void luaC_strcallIM (TaggedString *l);
diff --git a/tools/lua/liolib.cpp b/tools/lua/liolib.cpp
index 3777591b7..ffef2d551 100644
--- a/tools/lua/liolib.cpp
+++ b/tools/lua/liolib.cpp
@@ -1,36 +1,18 @@
/*
-** $Id$
+** $Id: liolib.cpp 942 2008-07-26 22:06:53Z aquadran $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
+#include "lauxlib.h"
+#include "lua.h"
+#include "luadebug.h"
+#include "lualib.h"
+
#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <time.h>
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/luadebug.h>
-#include <tools/lua/lualib.h>
-
-
-#ifndef OLD_ANSI
-#include <locale.h>
-#else
-#define setlocale(a,b) 0
-#define LC_ALL 0
-#define LC_COLLATE 0
-#define LC_CTYPE 0
-#define LC_MONETARY 0
-#define LC_NUMERIC 0
-#define LC_TIME 0
-#define strerror(e) "(no error message provided by operating system)"
-#endif
-
-
#define CLOSEDTAG 2
#define IOTAG 1
@@ -40,22 +22,16 @@
#define FOUTPUT "_OUTPUT"
-#ifdef POPEN
-FILE *popen();
-int pclose();
-#else
#define popen(x,y) NULL /* that is, popen always fails */
#define pclose(x) (-1)
-#endif
-
-static int gettag (int i)
+static int32 gettag (int32 i)
{
- return (int)lua_getnumber(lua_getparam(i));
+ return (int32)lua_getnumber(lua_getparam(i));
}
-static void pushresult (int i)
+static void pushresult (int32 i)
{
if (i)
lua_pushuserdata(NULL);
@@ -66,7 +42,7 @@ static void pushresult (int i)
}
-static int ishandler (lua_Object f)
+static int32 ishandler (lua_Object f)
{
if (lua_isuserdata(f)) {
if (lua_tag(f) == gettag(CLOSEDTAG))
@@ -76,7 +52,7 @@ static int ishandler (lua_Object f)
else return 0;
}
-static FILE *getfile (char *name)
+static FILE *getfile (const char *name)
{
lua_Object f = lua_getglobal(name);
if (!ishandler(f))
@@ -85,7 +61,7 @@ static FILE *getfile (char *name)
}
-static FILE *getfileparam (char *name, int *arg)
+static FILE *getfileparam (const char *name, int32 *arg)
{
lua_Object f = lua_getparam(*arg);
if (ishandler(f)) {
@@ -97,7 +73,7 @@ static FILE *getfileparam (char *name, int *arg)
}
-static void closefile (char *name)
+static void closefile (const char *name)
{
FILE *f = getfile(name);
if (f == stdin || f == stdout) return;
@@ -108,16 +84,16 @@ static void closefile (char *name)
}
-static void setfile (FILE *f, char *name, int tag)
+static void setfile (FILE *f, const char *name, int32 tag)
{
lua_pushusertag(f, tag);
lua_setglobal(name);
}
-static void setreturn (FILE *f, char *name)
+static void setreturn (FILE *f, const char *name)
{
- int tag = gettag(IOTAG);
+ int32 tag = gettag(IOTAG);
setfile(f, name, tag);
lua_pushusertag(f, tag);
}
@@ -134,8 +110,14 @@ static void io_readfrom (void)
else if (lua_tag(f) == gettag(IOTAG))
current = (FILE *)lua_getuserdata(f);
else {
- char *s = luaL_check_string(FIRSTARG);
- current = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
+ const char *s = luaL_check_string(FIRSTARG);
+ if (*s == '|')
+ current = popen(s+1, "r");
+ else {
+ current = fopen(s, "r");
+// if (current == NULL)
+// current = g_resourceloader->openNewStream(s);
+ }
if (current == NULL) {
pushresult(0);
return;
@@ -156,7 +138,7 @@ static void io_writeto (void)
else if (lua_tag(f) == gettag(IOTAG))
current = (FILE *)lua_getuserdata(f);
else {
- char *s = luaL_check_string(FIRSTARG);
+ const char *s = luaL_check_string(FIRSTARG);
current = (*s == '|') ? popen(s+1,"w") : fopen(s,"w");
if (current == NULL) {
pushresult(0);
@@ -169,7 +151,7 @@ static void io_writeto (void)
static void io_appendto (void)
{
- char *s = luaL_check_string(FIRSTARG);
+ const char *s = luaL_check_string(FIRSTARG);
FILE *fp = fopen (s, "a");
if (fp != NULL)
setreturn(fp, FOUTPUT);
@@ -181,9 +163,9 @@ static void io_appendto (void)
#define NEED_OTHER (EOF-1) /* just some flag different from EOF */
-static void read_until (FILE *f, int lim) {
- int l = 0;
- int c;
+static void read_until (FILE *f, int32 lim) {
+ int32 l = 0;
+ int32 c;
for (c = getc(f); c != EOF && c != lim; c = getc(f)) {
luaL_addchar(c);
l++;
@@ -193,18 +175,18 @@ static void read_until (FILE *f, int lim) {
}
static void io_read (void) {
- int arg = FIRSTARG;
+ int32 arg = FIRSTARG;
FILE *f = getfileparam(FINPUT, &arg);
- char *p = luaL_opt_string(arg, NULL);
+ const char *p = luaL_opt_string(arg, NULL);
luaL_resetbuffer();
if (p == NULL) /* default: read a line */
read_until(f, '\n');
else if (p[0] == '.' && p[1] == '*' && p[2] == 0) /* p = ".*" */
read_until(f, EOF);
else {
- int l = 0; /* number of chars read in buffer */
- int inskip = 0; /* to control {skips} */
- int c = NEED_OTHER;
+ int32 l = 0; /* number of chars read in buffer */
+ int32 inskip = 0; /* to control {skips} */
+ int32 c = NEED_OTHER;
while (*p) {
switch (*p) {
case '{':
@@ -218,8 +200,8 @@ static void io_read (void) {
p++;
continue;
default: {
- char *ep; /* get what is next */
- int m; /* match result */
+ const char *ep; /* get what is next */
+ int32 m; /* match result */
if (c == NEED_OTHER) c = getc(f);
if (c == EOF) {
luaI_singlematch(0, p, &ep); /* to set "ep" */
@@ -260,108 +242,45 @@ static void io_read (void) {
static void io_write (void)
{
- int arg = FIRSTARG;
+ int32 arg = FIRSTARG;
FILE *f = getfileparam(FOUTPUT, &arg);
- int status = 1;
- char *s;
- long l;
+ int32 status = 1;
+ const char *s;
+ int32 l;
while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL)
- status = status && (fwrite(s, 1, l, f) == (unsigned long)l);
+ status = status && (fwrite(s, 1, l, f) == (size_t)l);
pushresult(status);
}
-static void io_execute (void)
-{
- lua_pushnumber(system(luaL_check_string(1)));
-}
-
-
-static void io_remove (void)
-{
- pushresult(remove(luaL_check_string(1)) == 0);
-}
-
-
-static void io_rename (void)
-{
- pushresult(rename(luaL_check_string(1),
- luaL_check_string(2)) == 0);
-}
-
-
-static void io_tmpname (void)
-{
- lua_pushstring(tmpnam(NULL));
-}
-
-
-
-static void io_getenv (void)
-{
- lua_pushstring(getenv(luaL_check_string(1))); /* if NULL push nil */
-}
-
-
-static void io_clock (void) {
- lua_pushnumber(((double)clock())/CLOCKS_PER_SEC);
-}
-
-
-static void io_date (void)
-{
- time_t t;
- struct tm *tm;
- char *s = luaL_opt_string(1, "%c");
- char b[BUFSIZ];
- time(&t); tm = localtime(&t);
- if (strftime(b,sizeof(b),s,tm))
- lua_pushstring(b);
- else
- lua_error("invalid `date' format");
+static void io_date () {
+ time_t t;
+ struct tm *tm;
+ const char *s = luaL_opt_string(1, "%c");
+ char b[BUFSIZ];
+ time(&t); tm = localtime(&t);
+ if (strftime(b,sizeof(b),s,tm))
+ lua_pushstring(b);
+ else
+ lua_error("invalid `date' format");
}
-static void setloc (void)
-{
- static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC,
- LC_TIME};
- static char *catnames[] = {"all", "collate", "ctype", "monetary",
- "numeric", "time", NULL};
- int op = luaL_findstring(luaL_opt_string(2, "all"), catnames);
- luaL_arg_check(op != -1, 2, "invalid option");
- lua_pushstring(setlocale(cat[op], luaL_check_string(1)));
-}
-
-
-static void io_exit (void)
-{
- lua_Object o = lua_getparam(1);
- exit(lua_isnumber(o) ? (int)lua_getnumber(o) : 1);
-}
-
-
-static void io_debug (void)
-{
- while (1) {
- char buffer[250];
- fprintf(stderr, "lua_debug> ");
- if (fgets(buffer, sizeof(buffer), stdin) == 0) return;
- if (strcmp(buffer, "cont\n") == 0) return;
- lua_dostring(buffer);
- }
+static void io_exit () {
+ lua_Object o = lua_getparam(1);
+ exit((int)lua_isnumber(o) ? (int)lua_getnumber(o) : 1);
}
static void lua_printstack (FILE *f)
{
- int level = 1; /* skip level 0 (it's this function) */
+ int32 level = 1; /* skip level 0 (it's this function) */
lua_Object func;
while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
- char *name;
- int currentline;
- char *filename;
- int linedefined;
+ const char *name;
+ int32 currentline;
+ const char *filename;
+ int32 linedefined;
lua_funcinfo(func, &filename, &linedefined);
fprintf(f, (level==2) ? "Active Stack:\n\t" : "\t");
switch (*lua_getobjname(func, &name)) {
@@ -377,12 +296,12 @@ static void lua_printstack (FILE *f)
else if (linedefined < 0)
fprintf(f, "%s", filename);
else
- fprintf(f, "function (%s:%d)", filename, linedefined);
+ fprintf(f, "function (%s:%d)", filename, (int)linedefined);
filename = NULL;
}
}
if ((currentline = lua_currentline(func)) > 0)
- fprintf(f, " at line %d", currentline);
+ fprintf(f, " at line %d", (int)currentline);
if (filename)
fprintf(f, " [in file %s]", filename);
fprintf(f, "\n");
@@ -399,16 +318,8 @@ static void errorfb (void)
static struct luaL_reg iolib[] = {
-{"setlocale", setloc},
-{"execute", io_execute},
-{"remove", io_remove},
-{"rename", io_rename},
-{"tmpname", io_tmpname},
-{"getenv", io_getenv},
{"date", io_date},
-{"clock", io_clock},
{"exit", io_exit},
-{"debug", io_debug},
{"print_stack", errorfb}
};
@@ -422,9 +333,9 @@ static struct luaL_reg iolibtag[] = {
static void openwithtags (void)
{
- int iotag = lua_newtag();
- int closedtag = lua_newtag();
- unsigned int i;
+ int32 iotag = lua_newtag();
+ int32 closedtag = lua_newtag();
+ uint32 i;
for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) {
/* put both tags as upvalues for these functions */
lua_pushnumber(iotag);
diff --git a/tools/lua/llex.cpp b/tools/lua/llex.cpp
index bda627852..98eade1f5 100644
--- a/tools/lua/llex.cpp
+++ b/tools/lua/llex.cpp
@@ -1,26 +1,23 @@
/*
-** $Id$
+** $Id: llex.cpp 940 2008-07-26 19:30:44Z aquadran $
** Lexical Analizer
** See Copyright Notice in lua.h
*/
-#include <ctype.h>
-#include <string.h>
+#include "lauxlib.h"
+#include "llex.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lparser.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "luadebug.h"
+#include "lzio.h"
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/llex.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lparser.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/luadebug.h>
-#include <tools/lua/lzio.h>
-
-int lua_debug=0;
+int32 lua_debug=0;
#define next(LS) (LS->current = zgetc(LS->lex_z))
@@ -30,14 +27,14 @@ int lua_debug=0;
#define save_and_next(LS) (save(LS->current), next(LS))
-char *reserved [] = {"and", "do", "else", "elseif", "end", "function",
+const char *reserved [] = {"and", "do", "else", "elseif", "end", "function",
"if", "local", "nil", "not", "or", "repeat", "return", "then",
"until", "while"};
void luaX_init (void)
{
- unsigned int i;
+ uint32 i;
for (i=0; i<(sizeof(reserved)/sizeof(reserved[0])); i++) {
TaggedString *ts = luaS_new(reserved[i]);
ts->head.marked = FIRST_RESERVED+i; /* reserved word (always > 255) */
@@ -45,7 +42,7 @@ void luaX_init (void)
}
-void luaX_syntaxerror (LexState *ls, char *s, char *token) {
+void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
if (token[0] == 0)
token = "<eof>";
luaL_verror("%.100s;\n last token read: `%.50s' at line %d in chunk `%.50s'",
@@ -53,13 +50,13 @@ void luaX_syntaxerror (LexState *ls, char *s, char *token) {
}
-void luaX_error (LexState *ls, char *s) {
+void luaX_error (LexState *ls, const char *s) {
save(0);
luaX_syntaxerror(ls, s, luaL_buffer());
}
-void luaX_token2str (LexState * /*ls*/, int token, char *s) {
+void luaX_token2str (LexState * /*ls*/, int32 token, char *s) {
if (token < 255) {
s[0] = token;
s[1] = 0;
@@ -69,16 +66,16 @@ void luaX_token2str (LexState * /*ls*/, int token, char *s) {
}
-static void luaX_invalidchar (LexState *ls, int c) {
+static void luaX_invalidchar (LexState *ls, int32 c) {
char buff[10];
- sprintf(buff, "0x%X", c);
+ sprintf(buff, "0x%X", (int)c);
luaX_syntaxerror(ls, "invalid control char", buff);
}
static void firstline (LexState *LS)
{
- int c = zgetc(LS->lex_z);
+ int32 c = zgetc(LS->lex_z);
if (c == '#')
while ((c=zgetc(LS->lex_z)) != '\n' && c != EOZ) /* skip first line */;
zungetc(LS->lex_z);
@@ -115,12 +112,12 @@ static void skipspace (LexState *LS)
}
-static int checkcond (LexState *LS, char *buff)
+static int32 checkcond (LexState *LS, char *buff)
{
- static char *opts[] = {"nil", "1", NULL};
- int i = luaL_findstring(buff, opts);
+ static const char *opts[] = {"nil", "1", NULL};
+ int32 i = luaL_findstring(buff, opts);
if (i >= 0) return i;
- else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
+ else if (isalpha((byte)buff[0]) || buff[0] == '_')
return luaS_globaldefined(buff);
else {
luaX_syntaxerror(LS, "invalid $if condition", buff);
@@ -131,7 +128,7 @@ static int checkcond (LexState *LS, char *buff)
static void readname (LexState *LS, char *buff)
{
- int i = 0;
+ int32 i = 0;
skipspace(LS);
while (isalnum(LS->current) || LS->current == '_') {
if (i >= PRAGMASIZE) {
@@ -162,14 +159,14 @@ static void ifskip (LexState *LS)
static void inclinenumber (LexState *LS)
{
- static char *pragmas [] =
+ static const char *pragmas [] =
{"debug", "nodebug", "endinput", "end", "ifnot", "if", "else", NULL};
next(LS); /* skip '\n' */
++LS->linenumber;
if (LS->current == '$') { /* is a pragma? */
char buff[PRAGMASIZE+1];
- int ifnot = 0;
- int skip = LS->ifstate[LS->iflevel].skip;
+ int32 ifnot = 0;
+ int32 skip = LS->ifstate[LS->iflevel].skip;
next(LS); /* skip $ */
readname(LS, buff);
switch (luaL_findstring(buff, pragmas)) {
@@ -231,9 +228,9 @@ static void inclinenumber (LexState *LS)
-static int read_long_string (LexState *LS)
+static int32 read_long_string (LexState *LS)
{
- int cont = 0;
+ int32 cont = 0;
while (1) {
switch (LS->current) {
case EOZ:
@@ -269,7 +266,7 @@ static int read_long_string (LexState *LS)
}
-int luaX_lex (LexState *LS) {
+int32 luaX_lex (LexState *LS) {
double a;
luaL_resetbuffer();
while (1) {
@@ -320,7 +317,7 @@ int luaX_lex (LexState *LS) {
case '"':
case '\'': {
- int del = LS->current;
+ int32 del = LS->current;
save_and_next(LS);
while (LS->current != del) {
switch (LS->current) {
@@ -341,8 +338,8 @@ int luaX_lex (LexState *LS) {
case '\n': save('\n'); inclinenumber(LS); break;
default : {
if (isdigit(LS->current)) {
- int c = 0;
- int i = 0;
+ int32 c = 0;
+ int32 i = 0;
do {
c = 10*c + (LS->current-'0');
next(LS);
@@ -410,8 +407,8 @@ int luaX_lex (LexState *LS) {
save_and_next(LS);
}
if (toupper(LS->current) == 'E') {
- int e = 0;
- int neg;
+ int32 e = 0;
+ int32 neg;
double ea;
save_and_next(LS);
neg = (LS->current=='-');
@@ -439,7 +436,7 @@ int luaX_lex (LexState *LS) {
default:
if (LS->current != '_' && !isalpha(LS->current)) {
- int c = LS->current;
+ int32 c = LS->current;
if (iscntrl(c))
luaX_invalidchar(LS, c);
save_and_next(LS);
diff --git a/tools/lua/llex.h b/tools/lua/llex.h
index 9b66997b1..93e8ec8e9 100644
--- a/tools/lua/llex.h
+++ b/tools/lua/llex.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: llex.h 905 2008-07-20 21:08:22Z aquadran $
** Lexical Analizer
** See Copyright Notice in lua.h
*/
@@ -7,8 +7,8 @@
#ifndef llex_h
#define llex_h
-#include <tools/lua/lobject.h>
-#include <tools/lua/lzio.h>
+#include "lobject.h"
+#include "lzio.h"
#define FIRST_RESERVED 260
@@ -30,33 +30,33 @@ enum RESERVED {
/* "ifstate" keeps the state of each nested $if the lexical is dealing with. */
struct ifState {
- int elsepart; /* true if its in the $else part */
- int condition; /* true if $if condition is true */
- int skip; /* true if part must be skipped */
+ int32 elsepart; /* true if its in the $else part */
+ int32 condition; /* true if $if condition is true */
+ int32 skip; /* true if part must be skipped */
};
typedef struct LexState {
- int current; /* look ahead character */
- int token; /* look ahead token */
+ int32 current; /* look ahead character */
+ int32 token; /* look ahead token */
struct FuncState *fs; /* 'FuncState' is private for the parser */
union {
real r;
TaggedString *ts;
} seminfo; /* semantics information */
struct zio *lex_z; /* input stream */
- int linenumber; /* input line counter */
- int iflevel; /* level of nested $if's (for lexical analysis) */
+ int32 linenumber; /* input line counter */
+ int32 iflevel; /* level of nested $if's (for lexical analysis) */
struct ifState ifstate[MAX_IFS];
} LexState;
void luaX_init (void);
void luaX_setinput (LexState *LS, ZIO *z);
-int luaX_lex (LexState *LS);
-void luaX_syntaxerror (LexState *ls, char *s, char *token);
-void luaX_error (LexState *ls, char *s);
-void luaX_token2str (LexState *ls, int token, char *s);
+int32 luaX_lex (LexState *LS);
+void luaX_syntaxerror (LexState *ls, const char *s, const char *token);
+void luaX_error (LexState *ls, const char *s);
+void luaX_token2str (LexState *ls, int32 token, char *s);
#endif
diff --git a/tools/lua/lmathlib.cpp b/tools/lua/lmathlib.cpp
index c40125424..cb22df4d1 100644
--- a/tools/lua/lmathlib.cpp
+++ b/tools/lua/lmathlib.cpp
@@ -1,26 +1,21 @@
/*
-** $Id$
+** $Id: lmathlib.cpp 935 2008-07-26 18:11:55Z aquadran $
** Lua standard mathematical library
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <math.h>
+#include "lauxlib.h"
+#include "lua.h"
+#include "lualib.h"
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/lualib.h>
-
-#ifdef M_PI
-#define PI M_PI
-#else
-#define PI ((double)3.14159265358979323846)
+#ifndef LOCAL_PI
+#define LOCAL_PI (3.14159265358979323846)
#endif
-#define FROMRAD(a) ((a)*(180.0/PI))
-#define TORAD(a) ((a)*(PI/180.0))
+#define FROMRAD(a) ((a)*(180.0/LOCAL_PI))
+#define TORAD(a) ((a)*(LOCAL_PI/180.0))
static void math_abs (void)
@@ -107,12 +102,12 @@ static void math_exp (void)
static void math_deg (void)
{
- lua_pushnumber(luaL_check_number(1)*(180.0/PI));
+ lua_pushnumber(luaL_check_number(1)*(180.0/LOCAL_PI));
}
static void math_rad (void)
{
- lua_pushnumber(luaL_check_number(1)*(PI/180.0));
+ lua_pushnumber(luaL_check_number(1)*(LOCAL_PI/180.0));
}
static void math_frexp (void) {
@@ -122,14 +117,14 @@ static void math_frexp (void) {
}
static void math_ldexp (void) {
- lua_pushnumber(ldexp(luaL_check_number(1), (int)luaL_check_number(2)));
+ lua_pushnumber(ldexp(luaL_check_number(1), (int32)luaL_check_number(2)));
}
static void math_min (void)
{
- int i = 1;
+ int32 i = 1;
double dmin = luaL_check_number(i);
while (lua_getparam(++i) != LUA_NOOBJECT) {
double d = luaL_check_number(i);
@@ -142,7 +137,7 @@ static void math_min (void)
static void math_max (void)
{
- int i = 1;
+ int32 i = 1;
double dmax = luaL_check_number(i);
while (lua_getparam(++i) != LUA_NOOBJECT) {
double d = luaL_check_number(i);
@@ -162,7 +157,7 @@ static void math_random (void)
if (l == 0)
lua_pushnumber(r);
else
- lua_pushnumber((int)(r*l)+1);
+ lua_pushnumber((int32)(r*l)+1);
}
@@ -213,6 +208,6 @@ void lua_mathlibopen (void)
lua_pushcfunction(math_pow);
lua_pushnumber(0); /* to get its tag */
lua_settagmethod(lua_tag(lua_pop()), "pow");
- lua_pushnumber(PI); lua_setglobal("PI");
+ lua_pushnumber(LOCAL_PI); lua_setglobal("PI");
}
diff --git a/tools/lua/lmem.cpp b/tools/lua/lmem.cpp
index 72a474adb..9d03263cc 100644
--- a/tools/lua/lmem.cpp
+++ b/tools/lua/lmem.cpp
@@ -1,20 +1,19 @@
/*
-** $Id$
+** $Id: lmem.cpp 909 2008-07-20 21:37:09Z aquadran $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lua.h>
+#include "lmem.h"
+#include "lstate.h"
+#include "lua.h"
-int luaM_growaux (void **block, unsigned long nelems, int size,
- char *errormsg, unsigned long limit)
+int32 luaM_growaux (void **block, int32 nelems, int32 size,
+ const char *errormsg, int32 limit)
{
if (nelems >= limit)
lua_error(errormsg);
@@ -22,7 +21,7 @@ int luaM_growaux (void **block, unsigned long nelems, int size,
if (nelems > limit)
nelems = limit;
*block = luaM_realloc(*block, nelems*size);
- return (int)nelems;
+ return (int32)nelems;
}
@@ -35,18 +34,15 @@ int luaM_growaux (void **block, unsigned long nelems, int size,
** since realloc(NULL, s)==malloc(s) and realloc(b, 0)==free(b).
** But some systems (e.g. Sun OS) are not that ANSI...
*/
-void *luaM_realloc (void *block, unsigned long size)
+void *luaM_realloc (void *block, int32 size)
{
- size_t s = (size_t)size;
- if (s != size)
- lua_error("Allocation Error: Block too big");
if (size == 0) {
if (block) {
free(block);
}
return NULL;
}
- block = block ? realloc(block, s) : malloc(s);
+ block = block ? realloc(block, size) : malloc(size);
if (block == NULL)
lua_error(memEM);
return block;
@@ -64,14 +60,14 @@ void *luaM_realloc (void *block, unsigned long size)
#define MARK 55
-unsigned long numblocks = 0;
-unsigned long totalmem = 0;
+int32 numblocks = 0;
+int32 totalmem = 0;
static void *checkblock (void *block)
{
- unsigned long *b = (unsigned long *)((char *)block - HEADER);
- unsigned long size = *b;
+ int32 *b = (uint32 *)((char *)block - HEADER);
+ int32 size = *b;
LUA_ASSERT(*(((char *)b)+size+HEADER) == MARK,
"corrupted block");
numblocks--;
@@ -80,14 +76,14 @@ static void *checkblock (void *block)
}
-void *luaM_realloc (void *block, unsigned long size)
+void *luaM_realloc (void *block, int32 size)
{
- unsigned long realsize = HEADER+size+1;
+ int32 realsize = HEADER+size+1;
if (realsize != (size_t)realsize)
lua_error("Allocation Error: Block too big");
if (size == 0) { /* ANSI dosen't need this, but some machines... */
if (block) {
- unsigned long *b = (unsigned long *)((char *)block - HEADER);
+ int32 *b = (int32 *)((char *)block - HEADER);
memset(block, -1, *b); /* erase block */
block = checkblock(block);
free(block);
@@ -96,17 +92,17 @@ void *luaM_realloc (void *block, unsigned long size)
}
if (block) {
block = checkblock(block);
- block = (unsigned long *)realloc(block, realsize);
+ block = (int32 *)realloc(block, realsize);
}
else
- block = (unsigned long *)malloc(realsize);
+ block = (int32 *)malloc(realsize);
if (block == NULL)
lua_error(memEM);
totalmem += size;
numblocks++;
- *(unsigned long *)block = size;
+ *(int32 *)block = size;
*(((char *)block)+size+HEADER) = MARK;
- return (unsigned long *)((char *)block+HEADER);
+ return (int32 *)((char *)block+HEADER);
}
diff --git a/tools/lua/lmem.h b/tools/lua/lmem.h
index fa027193a..9ea3cbad6 100644
--- a/tools/lua/lmem.h
+++ b/tools/lua/lmem.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lmem.h 907 2008-07-20 21:22:53Z drmccoy $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -7,6 +7,8 @@
#ifndef lmem_h
#define lmem_h
+#include "common/sys.h"
+
#ifndef NULL
#define NULL 0
@@ -20,9 +22,9 @@
#define tableEM "table overflow"
#define memEM "not enough memory"
-void *luaM_realloc (void *oldblock, unsigned long size);
-int luaM_growaux (void **block, unsigned long nelems, int size,
- char *errormsg, unsigned long limit);
+void *luaM_realloc (void *oldblock, int32 size);
+int32 luaM_growaux (void **block, int32 nelems, int32 size,
+ const char *errormsg, int32 limit);
#define luaM_free(b) free((b))
#define luaM_malloc(t) malloc((t))
@@ -34,8 +36,8 @@ int luaM_growaux (void **block, unsigned long nelems, int size,
#ifdef DEBUG
-extern unsigned long numblocks;
-extern unsigned long totalmem;
+extern int32 numblocks;
+extern int32 totalmem;
#endif
diff --git a/tools/lua/lobject.cpp b/tools/lua/lobject.cpp
index 0d42012df..57c0d99f7 100644
--- a/tools/lua/lobject.cpp
+++ b/tools/lua/lobject.cpp
@@ -1,16 +1,14 @@
/*
-** $Id$
+** $Id: lobject.cpp 906 2008-07-20 21:18:18Z aquadran $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
+#include "lobject.h"
+#include "lua.h"
-#include <tools/lua/lobject.h>
-#include <tools/lua/lua.h>
-
-char *luaO_typenames[] = { /* ORDER LUA_T */
+const char *luaO_typenames[] = { /* ORDER LUA_T */
"userdata", "number", "string", "table", "function", "function", "task",
"nil", "function", "mark", "mark", "mark", "line", NULL
};
@@ -21,15 +19,15 @@ TObject luaO_nilobject = {LUA_T_NIL, {NULL}};
/* hash dimensions values */
-static long dimensions[] =
- {5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L,
- 12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L,
- 1644817L, 3289613L, 6579211L, 13158023L, MAX_INT};
+static int32 dimensions[] =
+ {5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421,
+ 12853, 25717, 51437, 102811, 205619, 411233, 822433,
+ 1644817, 3289613, 6579211, 13158023, MAX_INT};
-int luaO_redimension (int oldsize)
+int32 luaO_redimension (int32 oldsize)
{
- int i;
+ int32 i;
for (i=0; dimensions[i]<MAX_INT; i++) {
if (dimensions[i] > oldsize)
return dimensions[i];
@@ -39,7 +37,7 @@ int luaO_redimension (int oldsize)
}
-int luaO_equalObj (TObject *t1, TObject *t2)
+int32 luaO_equalObj (TObject *t1, TObject *t2)
{
if (ttype(t1) != ttype(t2)) return 0;
switch (ttype(t1)) {
@@ -64,21 +62,3 @@ void luaO_insertlist (GCnode *root, GCnode *node)
root->next = node;
node->marked = 0;
}
-
-#ifdef OLD_ANSI
-void luaO_memup (void *dest, void *src, int size)
-{
- char *d = dest;
- char *s = src;
- while (size--) d[size]=s[size];
-}
-
-void luaO_memdown (void *dest, void *src, int size)
-{
- char *d = dest;
- char *s = src;
- int i;
- for (i=0; i<size; i++) d[i]=s[i];
-}
-#endif
-
diff --git a/tools/lua/lobject.h b/tools/lua/lobject.h
index 43927db8c..dfa6bc53c 100644
--- a/tools/lua/lobject.h
+++ b/tools/lua/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lobject.h 905 2008-07-20 21:08:22Z aquadran $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -8,13 +8,11 @@
#define lobject_h
-#include <limits.h>
-
-#include <tools/lua/lua.h>
+#include "lua.h"
#ifdef DEBUG
-#include <tools/lua/lauxlib.h>
+#include "lauxlib.h"
#define LUA_INTERNALERROR(s) \
luaL_verror("INTERNAL ERROR - %s [%s:%d]",(s),__FILE__,__LINE__)
#define LUA_ASSERT(c,s) { if (!(c)) LUA_INTERNALERROR(s); }
@@ -40,19 +38,13 @@
typedef LUA_NUM_TYPE real;
#define Byte lua_Byte /* some systems have Byte as a predefined type */
-typedef unsigned char Byte; /* unsigned 8 bits */
-
+typedef byte Byte; /* unsigned 8 bits */
-#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
-/* maximum value of a word of 2 bytes (-2 for safety); must fit in an "int" */
-#if MAX_INT < 65534
-#define MAX_WORD MAX_INT
-#else
-#define MAX_WORD 65534
-#endif
+#define MAX_INT (2147483647-2) /* maximum value of an int (-2 for safety) */
+#define MAX_WORD 65534
-typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */
+typedef unsigned long IntPoint; /* unsigned with same size as a pointer (for hashing) */
/*
@@ -87,7 +79,7 @@ typedef union {
struct TProtoFunc *tf; /* LUA_T_PROTO, LUA_T_PMARK */
struct Closure *cl; /* LUA_T_CLOSURE, LUA_T_CLMARK */
struct Hash *a; /* LUA_T_ARRAY */
- int i; /* LUA_T_LINE */
+ int32 i; /* LUA_T_LINE */
} Value;
@@ -103,7 +95,7 @@ typedef struct TObject {
*/
typedef struct GCnode {
struct GCnode *next;
- int marked;
+ int32 marked;
} GCnode;
@@ -114,14 +106,14 @@ typedef struct GCnode {
typedef struct TaggedString {
GCnode head;
unsigned long hash;
- int constindex; /* hint to reuse constants (= -1 if this is a userdata) */
+ int32 constindex; /* hint to reuse constants (= -1 if this is a userdata) */
union {
struct {
TObject globalval;
- long len; /* if this is a string, here is its length */
+ int32 len; /* if this is a string, here is its length */
} s;
struct {
- int tag;
+ int32 tag;
void *v; /* if this is a userdata, here is its value */
} d;
} u;
@@ -137,16 +129,16 @@ typedef struct TaggedString {
typedef struct TProtoFunc {
GCnode head;
struct TObject *consts;
- int nconsts;
+ int32 nconsts;
Byte *code; /* ends with opcode ENDCODE */
- int lineDefined;
+ int32 lineDefined;
TaggedString *fileName;
struct LocVar *locvars; /* ends with line = -1 */
} TProtoFunc;
typedef struct LocVar {
TaggedString *varname; /* NULL signals end of scope */
- int line;
+ int32 line;
} LocVar;
@@ -171,7 +163,7 @@ typedef struct LocVar {
*/
typedef struct Closure {
GCnode head;
- int nelems; /* not included the first one (always the prototype) */
+ int32 nelems; /* not included the first one (always the prototype) */
TObject consts[1]; /* at least one for prototype */
} Closure;
@@ -185,27 +177,21 @@ typedef struct node {
typedef struct Hash {
GCnode head;
Node *node;
- int nhash;
- int nuse;
- int htag;
+ int32 nhash;
+ int32 nuse;
+ int32 htag;
} Hash;
-extern char *luaO_typenames[];
+extern const char *luaO_typenames[];
extern TObject luaO_nilobject;
-int luaO_equalObj (TObject *t1, TObject *t2);
-int luaO_redimension (int oldsize);
+int32 luaO_equalObj (TObject *t1, TObject *t2);
+int32 luaO_redimension (int32 oldsize);
void luaO_insertlist (GCnode *root, GCnode *node);
-#ifdef OLD_ANSI
-void luaO_memup (void *dest, void *src, int size);
-void luaO_memdown (void *dest, void *src, int size);
-#else
-#include <string.h>
#define luaO_memup(d,s,n) memmove(d,s,n)
#define luaO_memdown(d,s,n) memmove(d,s,n)
-#endif
#endif
diff --git a/tools/lua/lopcodes.h b/tools/lua/lopcodes.h
index 4468fa7fb..a39284f1f 100644
--- a/tools/lua/lopcodes.h
+++ b/tools/lua/lopcodes.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lopcodes.h 692 2006-02-09 23:57:31Z fingolfin $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
diff --git a/tools/lua/lparser.cpp b/tools/lua/lparser.cpp
index b96abeba1..60d4adc1f 100644
--- a/tools/lua/lparser.cpp
+++ b/tools/lua/lparser.cpp
@@ -1,25 +1,22 @@
/*
-** $Id$
+** $Id: lparser.cpp 940 2008-07-26 19:30:44Z aquadran $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/ldo.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/llex.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lopcodes.h>
-#include <tools/lua/lparser.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/luadebug.h>
-#include <tools/lua/lzio.h>
+#include "lauxlib.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "llex.h"
+#include "lmem.h"
+#include "lopcodes.h"
+#include "lparser.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "lua.h"
+#include "luadebug.h"
+#include "lzio.h"
/* for limit numbers in error messages */
@@ -52,7 +49,7 @@ typedef enum {VGLOBAL, VLOCAL, VDOT, VINDEXED, VEXP} varkind;
typedef struct {
varkind k;
- int info;
+ int32 info;
} vardesc;
@@ -63,8 +60,8 @@ typedef struct {
** where is its pc index of "nparam"
*/
typedef struct {
- int n;
- int pc; /* 0 if last expression is closed */
+ int32 n;
+ int32 pc; /* 0 if last expression is closed */
} listdesc;
@@ -75,8 +72,8 @@ typedef struct {
** or empty (k = ';' or '}')
*/
typedef struct {
- int n;
- int k;
+ int32 n;
+ int32 k;
} constdesc;
@@ -84,32 +81,32 @@ typedef struct {
typedef struct FuncState {
TProtoFunc *f; /* current function header */
struct FuncState *prev; /* enclosuring function */
- int pc; /* next position to code */
- int stacksize; /* number of values on activation register */
- int maxstacksize; /* maximum number of values on activation register */
- int nlocalvar; /* number of active local variables */
- int nupvalues; /* number of upvalues */
- int nvars; /* number of entries in f->locvars */
- int maxcode; /* size of f->code */
- int maxvars; /* size of f->locvars (-1 if no debug information) */
- int maxconsts; /* size of f->consts */
- int lastsetline; /* line where last SETLINE was issued */
+ int32 pc; /* next position to code */
+ int32 stacksize; /* number of values on activation register */
+ int32 maxstacksize; /* maximum number of values on activation register */
+ int32 nlocalvar; /* number of active local variables */
+ int32 nupvalues; /* number of upvalues */
+ int32 nvars; /* number of entries in f->locvars */
+ int32 maxcode; /* size of f->code */
+ int32 maxvars; /* size of f->locvars (-1 if no debug information) */
+ int32 maxconsts; /* size of f->consts */
+ int32 lastsetline; /* line where last SETLINE was issued */
vardesc upvalues[MAXUPVALUES]; /* upvalues */
TaggedString *localvar[MAXLOCALS]; /* store local variable names */
} FuncState;
-static int assignment (LexState *ls, vardesc *v, int nvars);
-static int cond (LexState *ls);
-static int funcname (LexState *ls, vardesc *v);
-static int funcparams (LexState *ls, int slf);
-static int listfields (LexState *ls);
-static int localnamelist (LexState *ls);
-static int optional (LexState *ls, int c);
-static int recfields (LexState *ls);
-static int stat (LexState *ls);
+static int32 assignment (LexState *ls, vardesc *v, int32 nvars);
+static int32 cond (LexState *ls);
+static int32 funcname (LexState *ls, vardesc *v);
+static int32 funcparams (LexState *ls, int32 slf);
+static int32 listfields (LexState *ls);
+static int32 localnamelist (LexState *ls);
+static int32 optional (LexState *ls, int32 c);
+static int32 recfields (LexState *ls);
+static int32 stat (LexState *ls);
static void block (LexState *ls);
-static void body (LexState *ls, int needself, int line);
+static void body (LexState *ls, int32 needself, int32 line);
static void chunk (LexState *ls);
static void constructor (LexState *ls);
static void decinit (LexState *ls, listdesc *d);
@@ -130,7 +127,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v);
-static void check_pc (FuncState *fs, int n) {
+static void check_pc (FuncState *fs, int32 n) {
if (fs->pc+n > fs->maxcode)
fs->maxcode = luaM_growvector(&fs->f->code, fs->maxcode,
Byte, codeEM, MAX_INT);
@@ -143,7 +140,7 @@ static void code_byte (FuncState *fs, Byte c) {
}
-static void deltastack (LexState *ls, int delta) {
+static void deltastack (LexState *ls, int32 delta) {
FuncState *fs = ls->fs;
fs->stacksize += delta;
if (fs->stacksize > fs->maxstacksize) {
@@ -154,8 +151,8 @@ static void deltastack (LexState *ls, int delta) {
}
-static int code_oparg_at (LexState *ls, int pc, OpCode op, int builtin,
- int arg, int delta) {
+static int32 code_oparg_at (LexState *ls, int32 pc, OpCode op, int32 builtin,
+ int32 arg, int32 delta) {
Byte *code = ls->fs->f->code;
deltastack(ls, delta);
if (arg < builtin) {
@@ -178,7 +175,7 @@ static int code_oparg_at (LexState *ls, int pc, OpCode op, int builtin,
}
-static int fix_opcode (LexState *ls, int pc, OpCode op, int builtin, int arg) {
+static int32 fix_opcode (LexState *ls, int32 pc, OpCode op, int32 builtin, int32 arg) {
FuncState *fs = ls->fs;
TProtoFunc *f = fs->f;
if (arg < builtin) { /* close space */
@@ -193,25 +190,25 @@ static int fix_opcode (LexState *ls, int pc, OpCode op, int builtin, int arg) {
return code_oparg_at(ls, pc, op, builtin, arg, 0) - 2;
}
-static void code_oparg (LexState *ls, OpCode op, int builtin, int arg,
- int delta) {
+static void code_oparg (LexState *ls, OpCode op, int32 builtin, int32 arg,
+ int32 delta) {
check_pc(ls->fs, 3); /* maximum code size */
ls->fs->pc += code_oparg_at(ls, ls->fs->pc, op, builtin, arg, delta);
}
-static void code_opcode (LexState *ls, OpCode op, int delta) {
+static void code_opcode (LexState *ls, OpCode op, int32 delta) {
deltastack(ls, delta);
code_byte(ls->fs, op);
}
-static void code_constant (LexState *ls, int c) {
+static void code_constant (LexState *ls, int32 c) {
code_oparg(ls, PUSHCONSTANT, 8, c, 1);
}
-static int next_constant (FuncState *fs) {
+static int32 next_constant (FuncState *fs) {
TProtoFunc *f = fs->f;
if (f->nconsts >= fs->maxconsts) {
fs->maxconsts = luaM_growvector(&f->consts, fs->maxconsts, TObject,
@@ -221,9 +218,9 @@ static int next_constant (FuncState *fs) {
}
-static int string_constant (FuncState *fs, TaggedString *s) {
+static int32 string_constant (FuncState *fs, TaggedString *s) {
TProtoFunc *f = fs->f;
- int c = s->constindex;
+ int32 c = s->constindex;
if (!(c < f->nconsts &&
ttype(&f->consts[c]) == LUA_T_STRING && tsvalue(&f->consts[c]) == s)) {
c = next_constant(fs);
@@ -241,11 +238,11 @@ static void code_string (LexState *ls, TaggedString *s) {
#define LIM 20
-static int real_constant (FuncState *fs, real r) {
+static int32 real_constant (FuncState *fs, real r) {
/* check whether 'r' has appeared within the last LIM entries */
TObject *cnt = fs->f->consts;
- int c = fs->f->nconsts;
- int lim = c < LIM ? 0 : c-LIM;
+ int32 c = fs->f->nconsts;
+ int32 lim = c < LIM ? 0 : c-LIM;
while (--c >= lim) {
if (ttype(&cnt[c]) == LUA_T_NUMBER && nvalue(&cnt[c]) == r)
return c;
@@ -260,21 +257,21 @@ static int real_constant (FuncState *fs, real r) {
static void code_number (LexState *ls, real f) {
- int i;
- if (f >= 0 && f <= (real)MAX_WORD && (real)(i=(int)f) == f)
+ int32 i;
+ if (f >= 0 && f <= (real)MAX_WORD && (real)(i=(int32)f) == f)
code_oparg(ls, PUSHNUMBER, 3, i, 1); /* f has a short integer value */
else
code_constant(ls, real_constant(ls->fs, f));
}
-static void flush_record (LexState *ls, int n) {
+static void flush_record (LexState *ls, int32 n) {
if (n > 0)
code_oparg(ls, SETMAP, 1, n-1, -2*n);
}
-static void flush_list (LexState *ls, int m, int n) {
+static void flush_list (LexState *ls, int32 m, int32 n) {
if (n == 0) return;
code_oparg(ls, SETLIST, 1, m, -n);
code_byte(ls->fs, n);
@@ -282,7 +279,7 @@ static void flush_list (LexState *ls, int m, int n) {
static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname,
- int line) {
+ int32 line) {
if (fs->maxvars != -1) { /* debug information? */
TProtoFunc *f = fs->f;
if (fs->nvars >= fs->maxvars)
@@ -295,12 +292,12 @@ static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname,
}
-static void luaI_unregisterlocalvar (FuncState *fs, int line) {
+static void luaI_unregisterlocalvar (FuncState *fs, int32 line) {
luaI_registerlocalvar(fs, NULL, line);
}
-static void store_localvar (LexState *ls, TaggedString *name, int n) {
+static void store_localvar (LexState *ls, TaggedString *name, int32 n) {
FuncState *fs = ls->fs;
if (fs->nlocalvar+n < MAXLOCALS)
fs->localvar[fs->nlocalvar+n] = name;
@@ -316,17 +313,17 @@ static void add_localvar (LexState *ls, TaggedString *name) {
}
-static int aux_localname (FuncState *fs, TaggedString *n) {
- int i;
+static int32 aux_localname (FuncState *fs, TaggedString *n) {
+ int32 i;
for (i=fs->nlocalvar-1; i >= 0; i--)
if (n == fs->localvar[i]) return i; /* local var index */
return -1; /* not found */
}
-static void singlevar (LexState *ls, TaggedString *n, vardesc *var, int prev) {
+static void singlevar (LexState *ls, TaggedString *n, vardesc *var, int32 prev) {
FuncState *fs = prev ? ls->fs->prev : ls->fs;
- int i = aux_localname(fs, n);
+ int32 i = aux_localname(fs, n);
if (i >= 0) { /* local value */
var->k = VLOCAL;
var->info = i;
@@ -342,10 +339,10 @@ static void singlevar (LexState *ls, TaggedString *n, vardesc *var, int prev) {
}
-static int indexupvalue (LexState *ls, TaggedString *n) {
+static int32 indexupvalue (LexState *ls, TaggedString *n) {
FuncState *fs = ls->fs;
vardesc v;
- int i;
+ int32 i;
singlevar(ls, n, &v, 1);
for (i=0; i<fs->nupvalues; i++) {
if (fs->upvalues[i].k == v.k && fs->upvalues[i].info == v.info)
@@ -361,7 +358,7 @@ static int indexupvalue (LexState *ls, TaggedString *n) {
static void pushupvalue (LexState *ls, TaggedString *n) {
- int i;
+ int32 i;
if (ls->fs->prev == NULL)
luaX_syntaxerror(ls, "cannot access upvalue in main", n->str);
if (aux_localname(ls->fs, n) >= 0)
@@ -380,7 +377,7 @@ static void check_debugline (LexState *ls) {
}
-static void adjuststack (LexState *ls, int n) {
+static void adjuststack (LexState *ls, int32 n) {
if (n > 0)
code_oparg(ls, POP, 2, n-1, -n);
else if (n < 0)
@@ -388,10 +385,10 @@ static void adjuststack (LexState *ls, int n) {
}
-static void close_exp (LexState *ls, int pc, int nresults) {
+static void close_exp (LexState *ls, int32 pc, int32 nresults) {
if (pc > 0) { /* expression is an open function call */
Byte *code = ls->fs->f->code;
- int nparams = code[pc]; /* save nparams */
+ int32 nparams = code[pc]; /* save nparams */
pc += fix_opcode(ls, pc-2, CALLFUNC, 2, nresults);
code[pc] = nparams; /* restore nparams */
if (nresults != MULT_RET)
@@ -401,8 +398,8 @@ static void close_exp (LexState *ls, int pc, int nresults) {
}
-static void adjust_mult_assign (LexState *ls, int nvars, listdesc *d) {
- int diff = d->n - nvars;
+static void adjust_mult_assign (LexState *ls, int32 nvars, listdesc *d) {
+ int32 diff = d->n - nvars;
if (d->pc == 0) { /* list is closed */
/* push or pop eventual difference between list lengths */
adjuststack(ls, diff);
@@ -421,7 +418,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, listdesc *d) {
}
-static void code_args (LexState *ls, int nparams, int dots) {
+static void code_args (LexState *ls, int32 nparams, int32 dots) {
FuncState *fs = ls->fs;
fs->nlocalvar += nparams; /* "self" may already be there */
nparams = fs->nlocalvar;
@@ -477,22 +474,22 @@ static void storevar (LexState *ls, vardesc *var) {
}
-static int fixJump (LexState *ls, int pc, OpCode op, int n) {
+static int32 fixJump (LexState *ls, int32 pc, OpCode op, int32 n) {
/* jump is relative to position following jump instruction */
return fix_opcode(ls, pc, op, 0, n-(pc+JMPSIZE));
}
-static void fix_upjmp (LexState *ls, OpCode op, int pos) {
- int delta = ls->fs->pc+JMPSIZE - pos; /* jump is relative */
+static void fix_upjmp (LexState *ls, OpCode op, int32 pos) {
+ int32 delta = ls->fs->pc+JMPSIZE - pos; /* jump is relative */
if (delta > 255) delta++;
code_oparg(ls, op, 0, delta, 0);
}
-static void codeIf (LexState *ls, int thenAdd, int elseAdd) {
+static void codeIf (LexState *ls, int32 thenAdd, int32 elseAdd) {
FuncState *fs = ls->fs;
- int elseinit = elseAdd+JMPSIZE;
+ int32 elseinit = elseAdd+JMPSIZE;
if (fs->pc == elseinit) { /* no else part */
fs->pc -= JMPSIZE;
elseinit = fs->pc;
@@ -505,8 +502,8 @@ static void codeIf (LexState *ls, int thenAdd, int elseAdd) {
static void func_onstack (LexState *ls, FuncState *func) {
FuncState *fs = ls->fs;
- int i;
- int c = next_constant(fs);
+ int32 i;
+ int32 c = next_constant(fs);
ttype(&fs->f->consts[c]) = LUA_T_PROTO;
fs->f->consts[c].value.tf = func->f;
if (func->nupvalues == 0)
@@ -560,11 +557,11 @@ static void close_func (LexState *ls) {
-static int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME,
+static int32 expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME,
LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';', EOS, ',', 0};
-static int is_in (int tok, int *toks) {
- int *t = toks;
+static int32 is_in (int32 tok, int32 *toks) {
+ int32 *t = toks;
while (*t) {
if (*t == tok)
return t-toks;
@@ -579,14 +576,14 @@ static void next (LexState *ls) {
}
-static void error_expected (LexState *ls, int token) {
+static void error_expected (LexState *ls, int32 token) {
char buff[100], t[TOKEN_LEN];
luaX_token2str(ls, token, t);
sprintf(buff, "`%s' expected", t);
luaX_error(ls, buff);
}
-static void error_unmatched (LexState *ls, int what, int who, int where) {
+static void error_unmatched (LexState *ls, int32 what, int32 who, int32 where) {
if (where == ls->linenumber)
error_expected(ls, what);
else {
@@ -595,18 +592,18 @@ static void error_unmatched (LexState *ls, int what, int who, int where) {
luaX_token2str(ls, what, t_what);
luaX_token2str(ls, who, t_who);
sprintf(buff, "`%s' expected (to close `%s' at line %d)",
- t_what, t_who, where);
+ t_what, t_who, (int)where);
luaX_error(ls, buff);
}
}
-static void check (LexState *ls, int c) {
+static void check (LexState *ls, int32 c) {
if (ls->token != c)
error_expected(ls, c);
next(ls);
}
-static void check_match (LexState *ls, int what, int who, int where) {
+static void check_match (LexState *ls, int32 what, int32 who, int32 where) {
if (ls->token != what)
error_unmatched(ls, what, who, where);
check_debugline(ls); /* to 'mark' the 'what' */
@@ -623,7 +620,7 @@ static TaggedString *checkname (LexState *ls) {
}
-static int optional (LexState *ls, int c) {
+static int32 optional (LexState *ls, int32 c) {
if (ls->token == c) {
next(ls);
return 1;
@@ -666,8 +663,8 @@ static void statlist (LexState *ls) {
}
}
-static int stat (LexState *ls) {
- int line = ls->linenumber; /* may be needed for error messages */
+static int32 stat (LexState *ls) {
+ int32 line = ls->linenumber; /* may be needed for error messages */
FuncState *fs = ls->fs;
switch (ls->token) {
case IF: { /* stat -> IF ifpart END */
@@ -679,8 +676,8 @@ static int stat (LexState *ls) {
case WHILE: { /* stat -> WHILE cond DO block END */
TProtoFunc *f = fs->f;
- int while_init = fs->pc;
- int cond_end, cond_size;
+ int32 while_init = fs->pc;
+ int32 cond_end, cond_size;
next(ls);
cond_end = cond(ls);
check(ls, DO);
@@ -703,7 +700,7 @@ static int stat (LexState *ls) {
}
case REPEAT: { /* stat -> REPEAT block UNTIL exp1 */
- int repeat_init = fs->pc;
+ int32 repeat_init = fs->pc;
next(ls);
block(ls);
check_match(ls, UNTIL, REPEAT, line);
@@ -714,7 +711,7 @@ static int stat (LexState *ls) {
}
case FUNCTION: { /* stat -> FUNCTION funcname body */
- int needself;
+ int32 needself;
vardesc v;
if (ls->fs->prev) /* inside other function? */
return 0;
@@ -728,7 +725,7 @@ static int stat (LexState *ls) {
case LOCAL: { /* stat -> LOCAL localnamelist decinit */
listdesc d;
- int nvars;
+ int32 nvars;
check_debugline(ls);
next(ls);
nvars = localnamelist(ls);
@@ -748,7 +745,7 @@ static int stat (LexState *ls) {
close_exp(ls, v.info, 0);
}
else {
- int left = assignment(ls, &v, 1); /* stat -> ['%'] NAME assignment */
+ int32 left = assignment(ls, &v, 1); /* stat -> ['%'] NAME assignment */
adjuststack(ls, left); /* remove eventual 'garbage' left on stack */
}
return 1;
@@ -764,19 +761,19 @@ static int stat (LexState *ls) {
}
}
-static int SaveWord (LexState *ls) {
- int res = ls->fs->pc;
+static int32 SaveWord (LexState *ls) {
+ int32 res = ls->fs->pc;
check_pc(ls->fs, JMPSIZE);
ls->fs->pc += JMPSIZE; /* open space */
return res;
}
-static int SaveWordPop (LexState *ls) {
+static int32 SaveWordPop (LexState *ls) {
deltastack(ls, -1); /* pop condition */
return SaveWord(ls);
}
-static int cond (LexState *ls) {
+static int32 cond (LexState *ls) {
/* cond -> exp1 */
exp1(ls);
return SaveWordPop(ls);
@@ -785,16 +782,16 @@ static int cond (LexState *ls) {
static void block (LexState *ls) {
/* block -> chunk */
FuncState *fs = ls->fs;
- int nlocalvar = fs->nlocalvar;
+ int32 nlocalvar = fs->nlocalvar;
chunk(ls);
adjuststack(ls, fs->nlocalvar - nlocalvar);
for (; fs->nlocalvar > nlocalvar; fs->nlocalvar--)
luaI_unregisterlocalvar(fs, ls->linenumber);
}
-static int funcname (LexState *ls, vardesc *v) {
+static int32 funcname (LexState *ls, vardesc *v) {
/* funcname -> NAME [':' NAME | '.' NAME] */
- int needself = 0;
+ int32 needself = 0;
singlevar(ls, checkname(ls), v, 0);
if (ls->token == ':' || ls->token == '.') {
needself = (ls->token == ':');
@@ -806,7 +803,7 @@ static int funcname (LexState *ls, vardesc *v) {
return needself;
}
-static void body (LexState *ls, int needself, int line) {
+static void body (LexState *ls, int32 needself, int32 line) {
/* body -> '(' parlist ')' chunk END */
FuncState newfs;
init_state(ls, &newfs, ls->fs->f->fileName);
@@ -824,8 +821,8 @@ static void body (LexState *ls, int needself, int line) {
static void ifpart (LexState *ls) {
/* ifpart -> cond THEN block [ELSE block | ELSEIF ifpart] */
- int c = cond(ls);
- int e;
+ int32 c = cond(ls);
+ int32 e;
check(ls, THEN);
block(ls);
e = SaveWord(ls);
@@ -872,10 +869,10 @@ static void ret (LexState *ls) {
*/
#define POW 13
-static int binop [] = {EQ, NE, '>', '<', LE, GE, CONC,
+static int32 binop [] = {EQ, NE, '>', '<', LE, GE, CONC,
'+', '-', '*', '/', '^', 0};
-static int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
+static int32 priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP,
LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP};
@@ -883,8 +880,8 @@ static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP,
#define MAXOPS 20
typedef struct {
- int ops[MAXOPS];
- int top;
+ int32 ops[MAXOPS];
+ int32 top;
} stack_op;
@@ -900,8 +897,8 @@ static void exp1 (LexState *ls) {
static void exp0 (LexState *ls, vardesc *v) {
exp2(ls, v);
while (ls->token == AND || ls->token == OR) {
- int is_and = (ls->token == AND);
- int pc;
+ int32 is_and = (ls->token == AND);
+ int32 pc;
lua_pushvar(ls, v);
next(ls);
pc = SaveWordPop(ls);
@@ -912,7 +909,7 @@ static void exp0 (LexState *ls, vardesc *v) {
}
-static void push (LexState *ls, stack_op *s, int op) {
+static void push (LexState *ls, stack_op *s, int32 op) {
if (s->top == MAXOPS)
luaX_error(ls, "expression too complex");
s->ops[s->top++] = op;
@@ -926,8 +923,8 @@ static void prefix (LexState *ls, stack_op *s) {
}
}
-static void pop_to (LexState *ls, stack_op *s, int prio) {
- int op;
+static void pop_to (LexState *ls, stack_op *s, int32 prio) {
+ int32 op;
while (s->top > 0 && priority[(op=s->ops[s->top-1])] >= prio) {
code_opcode(ls, opcodes[op], op<FIRSTBIN?0:-1);
s->top--;
@@ -936,7 +933,7 @@ static void pop_to (LexState *ls, stack_op *s, int prio) {
static void exp2 (LexState *ls, vardesc *v) {
stack_op s;
- int op;
+ int32 op;
s.top = 0;
prefix(ls, &s);
simpleexp(ls, v);
@@ -991,7 +988,7 @@ static void simpleexp (LexState *ls, vardesc *v) {
break;
case FUNCTION: { /* simpleexp -> FUNCTION body */
- int line = ls->linenumber;
+ int32 line = ls->linenumber;
next(ls);
body(ls, 0, line);
v->k = VEXP; v->info = 0;
@@ -1057,9 +1054,9 @@ static void var_or_func_tail (LexState *ls, vardesc *v) {
}
}
-static int funcparams (LexState *ls, int slf) {
+static int32 funcparams (LexState *ls, int32 slf) {
FuncState *fs = ls->fs;
- int nparams = 1; /* default value */
+ int32 nparams = 1; /* default value */
switch (ls->token) {
case '(': { /* funcparams -> '(' explist ')' */
listdesc e;
@@ -1122,8 +1119,8 @@ static void explist1 (LexState *ls, listdesc *d) {
}
static void parlist (LexState *ls) {
- int nparams = 0;
- int dots = 0;
+ int32 nparams = 0;
+ int32 dots = 0;
switch (ls->token) {
case DOTS: /* parlist -> DOTS */
next(ls);
@@ -1156,9 +1153,9 @@ static void parlist (LexState *ls) {
code_args(ls, nparams, dots);
}
-static int localnamelist (LexState *ls) {
+static int32 localnamelist (LexState *ls) {
/* localnamelist -> NAME {',' NAME} */
- int i = 1;
+ int32 i = 1;
store_localvar(ls, checkname(ls), 0);
while (ls->token == ',') {
next(ls);
@@ -1179,8 +1176,8 @@ static void decinit (LexState *ls, listdesc *d) {
}
}
-static int assignment (LexState *ls, vardesc *v, int nvars) {
- int left = 0;
+static int32 assignment (LexState *ls, vardesc *v, int32 nvars) {
+ int32 left = 0;
/* dotted variables <a.x> must be stored like regular indexed vars <a["x"]> */
if (v->k == VDOT) {
code_constant(ls, v->info);
@@ -1213,9 +1210,9 @@ static int assignment (LexState *ls, vardesc *v, int nvars) {
static void constructor (LexState *ls) {
/* constructor -> '{' part [';' part] '}' */
- int line = ls->linenumber;
- int pc = SaveWord(ls);
- int nelems;
+ int32 line = ls->linenumber;
+ int32 pc = SaveWord(ls);
+ int32 nelems;
constdesc cd;
deltastack(ls, 1);
check(ls, '{');
@@ -1281,9 +1278,9 @@ static void part (LexState *ls, constdesc *cd) {
}
}
-static int recfields (LexState *ls) {
+static int32 recfields (LexState *ls) {
/* recfields -> { ',' recfield } [','] */
- int n = 1; /* one has been read before */
+ int32 n = 1; /* one has been read before */
while (ls->token == ',') {
next(ls);
if (ls->token == ';' || ls->token == '}')
@@ -1297,9 +1294,9 @@ static int recfields (LexState *ls) {
return n;
}
-static int listfields (LexState *ls) {
+static int32 listfields (LexState *ls) {
/* listfields -> { ',' exp1 } [','] */
- int n = 1; /* one has been read before */
+ int32 n = 1; /* one has been read before */
while (ls->token == ',') {
next(ls);
if (ls->token == ';' || ls->token == '}')
diff --git a/tools/lua/lparser.h b/tools/lua/lparser.h
index 0657cf1a5..2559a23d3 100644
--- a/tools/lua/lparser.h
+++ b/tools/lua/lparser.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lparser.h 905 2008-07-20 21:08:22Z aquadran $
** Syntax analizer and code generator
** See Copyright Notice in lua.h
*/
@@ -7,11 +7,11 @@
#ifndef lparser_h
#define lparser_h
-#include <tools/lua/lobject.h>
-#include <tools/lua/lzio.h>
+#include "lobject.h"
+#include "lzio.h"
-void luaY_codedebugline (int line);
+void luaY_codedebugline (int32 line);
TProtoFunc *luaY_parser (ZIO *z);
void luaY_error (char *s);
void luaY_syntaxerror (char *s, char *token);
diff --git a/tools/lua/lrestore.cpp b/tools/lua/lrestore.cpp
index ed13fcdbb..422858e26 100644
--- a/tools/lua/lrestore.cpp
+++ b/tools/lua/lrestore.cpp
@@ -1,8 +1,3 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <search.h>
-#include <assert.h>
-
#include "ltask.h"
#include "lauxlib.h"
#include "lmem.h"
@@ -14,27 +9,139 @@
#include "lstring.h"
#include "lua.h"
-SaveRestoreCallback restoreCallback = NULL;
+#include "common/endian.h"
+
+RestoreCallback restoreCallbackPtr = NULL;
+
+static void restoreObjectValue(TObject *object, RestoreSint32 restoreSint32, RestoreUint32 restoreUint32) {
+ object->ttype = (lua_Type)restoreSint32();
+
+ switch (object->ttype) {
+ case LUA_T_NUMBER:
+ case LUA_T_TASK:
+ {
+ byte *udata = (byte *)(&object->value.n);
+ uint32 v = restoreUint32();
+ restoreUint32();
+#if defined(SYSTEM_LITTLE_ENDIAN)
+ byte b[4];
+ *(uint32 *)&b = v;
+ udata[0] = b[3];
+ udata[1] = b[2];
+ udata[2] = b[1];
+ udata[3] = b[0];
+#else
+ memcpy(&udata, &v, 4);
+#endif
+ }
+ break;
+ case LUA_T_NIL:
+ {
+ restoreUint32();
+ restoreUint32();
+ object->value.ts = NULL;
+ }
+ break;
+ case LUA_T_ARRAY:
+ {
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ object->value.a = (Hash *)makePointerFromId(ptr);
+ }
+ break;
+ case LUA_T_USERDATA:
+ case LUA_T_STRING:
+ {
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ object->value.ts = (TaggedString *)makePointerFromId(ptr);
+ }
+ break;
+ case LUA_T_PROTO:
+ case LUA_T_PMARK:
+ {
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ object->value.tf = (TProtoFunc *)makePointerFromId(ptr);
+ }
+ break;
+ case LUA_T_CPROTO:
+ case LUA_T_CMARK:
+ {
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ object->value.f = (lua_CFunction)makePointerFromId(ptr);
+ }
+ break;
+ case LUA_T_CLOSURE:
+ case LUA_T_CLMARK:
+ {
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ object->value.cl = (Closure *)makePointerFromId(ptr);
+ }
+ break;
+ case LUA_T_LINE:
+ {
+ object->value.i = restoreSint32();
+ restoreSint32();
+ }
+ break;
+ case MKID_BE('ACTR'):
+ case MKID_BE('COLR'):
+ case MKID_BE('STAT'):
+ case MKID_BE('FONT'):
+ case MKID_BE('VBUF'):
+ case MKID_BE('PRIM'):
+ case MKID_BE('TEXT'):
+ { // TODO
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ object->value.ts = (TaggedString *)makePointerFromId(ptr);
+ }
+ break;
+ default:
+ lua_error("saveObjectValue: Unsupported object type");
+ }
+}
struct ArrayIDObj {
void *object;
- unsigned int idObj;
+ PointerId idObj;
};
static int sortCallback(const void *id1, const void *id2) {
- if (((ArrayIDObj *)id1)->idObj > ((ArrayIDObj *)id2)->idObj) {
+#ifdef TARGET_64BITS
+ uint64 p1 = ((ArrayIDObj *)id1)->idObj.low | ((uint64)(((ArrayIDObj *)id1)->idObj.hi)) << 32;
+ uint64 p2 = ((ArrayIDObj *)id2)->idObj.low | ((uint64)(((ArrayIDObj *)id2)->idObj.hi)) << 32;
+ if (p1 > p2) {
+ return 1;
+ } else if (p1 < p2) {
+ return -1;
+ } else {
+ return 0;
+ }
+#else
+ if (((ArrayIDObj *)id1)->idObj.low > ((ArrayIDObj *)id2)->idObj.low) {
return 1;
- } else if (((ArrayIDObj *)id1)->idObj < ((ArrayIDObj *)id2)->idObj) {
+ } else if (((ArrayIDObj *)id1)->idObj.low < ((ArrayIDObj *)id2)->idObj.low) {
return -1;
} else {
return 0;
}
+#endif
}
-int arrayHashTablesCount = 0;
-int arrayProtoFuncsCount = 0;
-int arrayClosuresCount = 0;
-int arrayStringsCount = 0;
+int32 arrayHashTablesCount = 0;
+int32 arrayProtoFuncsCount = 0;
+int32 arrayClosuresCount = 0;
+int32 arrayStringsCount = 0;
ArrayIDObj *arrayStrings = NULL;
ArrayIDObj *arrayHashTables = NULL;
ArrayIDObj *arrayClosures = NULL;
@@ -43,23 +150,31 @@ static bool arraysAllreadySort = false;
static void recreateObj(TObject *obj) {
if (obj->ttype == LUA_T_CPROTO) {
- int some = ((int)(obj->value.f)) >> 16;
+#ifdef TARGET_64BITS
+ uint64 id = ((uint64)(obj->value.f)) >> 16;
+#else
+ uint32 id = ((uint32)(obj->value.f)) >> 16;
+#endif
luaL_libList *list = list_of_libs;
- while (list != NULL) {
- if (some == 0)
+ while (list) {
+ if (id == 0)
break;
- some--;
+ id--;
list = list->next;
}
- int numberFunc = (int)(obj->value.f) & 0xffff;
- if ((list != NULL) && (some == 0) && (numberFunc < list->number)) {
+#ifdef TARGET_64BITS
+ int32 numberFunc = (uint64)(obj->value.f) & 0xffff;
+#else
+ int32 numberFunc = (uint32)(obj->value.f) & 0xffff;
+#endif
+ if (list && id == 0 && numberFunc < list->number) {
obj->value.f = list->list[numberFunc].func;
} else {
obj->value.f = NULL;
assert(obj->value.f);
}
- } else if ((obj->ttype == LUA_T_NIL) || (obj->ttype == LUA_T_LINE) || (obj->ttype == LUA_T_NUMBER) ) {
+ } else if (obj->ttype == LUA_T_NIL || obj->ttype == LUA_T_LINE || obj->ttype == LUA_T_NUMBER) {
return;
} else {
if (obj->value.i == 0)
@@ -75,83 +190,98 @@ static void recreateObj(TObject *obj) {
ArrayIDObj *found;
ArrayIDObj tmpId;
-
- tmpId.idObj = obj->value.i;
tmpId.object = NULL;
- obj->value.i = 0;
switch (obj->ttype) {
case LUA_T_PMARK:
+ tmpId.idObj = makeIdFromPointer(obj->value.tf);
found = (ArrayIDObj *)bsearch(&tmpId, arrayProtoFuncs, arrayProtoFuncsCount, sizeof(ArrayIDObj), sortCallback);
+ assert(found);
+ obj->value.tf = (TProtoFunc *)found->object;
break;
case LUA_T_USERDATA:
+ tmpId.idObj = makeIdFromPointer(obj->value.ts);
found = (ArrayIDObj *)bsearch(&tmpId, arrayStrings, arrayStringsCount, sizeof(ArrayIDObj), sortCallback);
+ assert(found);
+ obj->value.ts = (TaggedString *)found->object;
break;
case LUA_T_PROTO:
+ tmpId.idObj = makeIdFromPointer(obj->value.tf);
found = (ArrayIDObj *)bsearch(&tmpId, arrayProtoFuncs, arrayProtoFuncsCount, sizeof(ArrayIDObj), sortCallback);
+ assert(found);
+ obj->value.tf = (TProtoFunc *)found->object;
break;
case LUA_T_CLOSURE:
+ tmpId.idObj = makeIdFromPointer(obj->value.cl);
found = (ArrayIDObj *)bsearch(&tmpId, arrayClosures, arrayClosuresCount, sizeof(ArrayIDObj), sortCallback);
+ assert(found);
+ obj->value.cl = (Closure *)found->object;
break;
case LUA_T_ARRAY:
+ tmpId.idObj = makeIdFromPointer(obj->value.a);
found = (ArrayIDObj *)bsearch(&tmpId, arrayHashTables, arrayHashTablesCount, sizeof(ArrayIDObj), sortCallback);
+ assert(found);
+ obj->value.a = (Hash *)found->object;
break;
case LUA_T_STRING:
+ tmpId.idObj = makeIdFromPointer(obj->value.ts);
found = (ArrayIDObj *)bsearch(&tmpId, arrayStrings, arrayStringsCount, sizeof(ArrayIDObj), sortCallback);
+ assert(found);
+ obj->value.ts = (TaggedString *)found->object;
break;
default:
+ obj->value.i = 0;
+ obj->value.ts = 0;
return;
}
-
- obj->value.i = (unsigned int)found->object;
}
}
-void lua_Restore(SaveRestoreFunc restoreFunc) {
+void lua_Restore(RestoreStream restoreStream, RestoreSint32 restoreSint32, RestoreUint32 restoreUint32) {
printf("lua_Restore() started.\n");
lua_close();
L = luaM_new(lua_State);
lua_resetglobals();
- restoreFunc(&arrayStringsCount, sizeof(int));
- restoreFunc(&arrayClosuresCount, sizeof(int));
- restoreFunc(&arrayHashTablesCount, sizeof(int));
- restoreFunc(&arrayProtoFuncsCount, sizeof(int));
- int rootGlobalCount;
- restoreFunc(&rootGlobalCount, sizeof(int));
+ arrayStringsCount = restoreSint32();
+ arrayClosuresCount = restoreSint32();
+ arrayHashTablesCount = restoreSint32();
+ arrayProtoFuncsCount = restoreSint32();
+ int32 rootGlobalCount = restoreSint32();
arrayStrings = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayStringsCount);
ArrayIDObj *arraysObj = arrayStrings;
- int maxStringsLength;
- restoreFunc(&maxStringsLength, sizeof(int));
+ int32 maxStringsLength;
+ maxStringsLength = restoreSint32();
char *tempStringBuffer = (char *)luaM_malloc(maxStringsLength);
- int i;
+ int32 i;
for (i = 0; i < arrayStringsCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
- int constIndex;
- restoreFunc(&constIndex, sizeof(int));
- lua_Type tag;
- restoreFunc(&tag, sizeof(int));
- void *value;
- restoreFunc(&value, sizeof(void *));
+ arraysObj->idObj.low = restoreSint32();
+ arraysObj->idObj.hi = restoreSint32();
+ int32 constIndex = restoreSint32();
+ lua_Type tag = (lua_Type)restoreSint32();
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
TaggedString *tempString;
if (constIndex != -1) {
- long length;
- restoreFunc(&length, sizeof(long));
- restoreFunc(tempStringBuffer, length);
+ int32 length = restoreSint32();
+ restoreStream(tempStringBuffer, length);
tempString = luaS_newlstr(tempStringBuffer, length);
tempString->u.s.globalval.ttype = tag;
- tempString->u.s.globalval.value.ts = (TaggedString *)value;
+ tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
} else {
if (tag == 0)
- tempString = luaS_createudata(value, LUA_ANYTAG);
+ tempString = luaS_createudata((void *)makePointerFromId(ptr), LUA_ANYTAG);
else
- tempString = luaS_createudata(value, tag);
- if (restoreCallback != NULL) {
- tempString->u.s.globalval.value.ts = (TaggedString *)restoreCallback(tempString->u.s.globalval.ttype, (int)tempString->u.s.globalval.value.ts, restoreFunc);
+ tempString = luaS_createudata((void *)makePointerFromId(ptr), tag);
+ if (restoreCallbackPtr) {
+ PointerId ptr = makeIdFromPointer(tempString->u.s.globalval.value.ts);
+ ptr = restoreCallbackPtr(tempString->u.s.globalval.ttype, ptr, restoreSint32);
+ tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
}
}
tempString->constindex = constIndex;
@@ -160,21 +290,20 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
}
luaM_free(tempStringBuffer);
- int l;
+ int32 l;
Closure *tempClosure;
arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayClosuresCount);
arrayClosures = arraysObj;
for (i = 0; i < arrayClosuresCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
- int countElements;
- restoreFunc(&countElements, sizeof(int));
+ arraysObj->idObj.low = restoreSint32();
+ arraysObj->idObj.hi = restoreSint32();
+ int32 countElements = restoreSint32();
tempClosure = (Closure *)luaM_malloc((countElements * sizeof(TObject)) + sizeof(Closure));
luaO_insertlist(&L->rootcl, (GCnode *)tempClosure);
tempClosure->nelems = countElements;
for (l = 0; l <= tempClosure->nelems; l++) {
- restoreFunc(&tempClosure->consts[l].ttype, sizeof(lua_Type));
- restoreFunc(&tempClosure->consts[l].value, sizeof(Value));
+ restoreObjectValue(&tempClosure->consts[l], restoreSint32, restoreUint32);
}
arraysObj->object = tempClosure;
arraysObj++;
@@ -184,19 +313,18 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayHashTablesCount);
arrayHashTables = arraysObj;
for (i = 0; i < arrayHashTablesCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
+ arraysObj->idObj.low = restoreSint32();
+ arraysObj->idObj.hi = restoreSint32();
tempHash = luaM_new(Hash);
- restoreFunc(&tempHash->nhash, sizeof(int));
- restoreFunc(&tempHash->nuse, sizeof(int));
- restoreFunc(&tempHash->htag, sizeof(int));
+ tempHash->nhash = restoreSint32();
+ tempHash->nuse = restoreSint32();
+ tempHash->htag = restoreSint32();
tempHash->node = hashnodecreate(tempHash->nhash);
luaO_insertlist(&L->roottable, (GCnode *)tempHash);
for (l = 0; l < tempHash->nuse; l++) {
- restoreFunc(&tempHash->node[l].ref.ttype, sizeof(lua_Type));
- restoreFunc(&tempHash->node[l].ref.value, sizeof(Value));
- restoreFunc(&tempHash->node[l].val.ttype, sizeof(lua_Type));
- restoreFunc(&tempHash->node[l].val.value, sizeof(Value));
+ restoreObjectValue(&tempHash->node[l].ref, restoreSint32, restoreUint32);
+ restoreObjectValue(&tempHash->node[l].val, restoreSint32, restoreUint32);
}
arraysObj->object = tempHash;
arraysObj++;
@@ -206,36 +334,40 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
arrayProtoFuncs = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayProtoFuncsCount);
arraysObj = arrayProtoFuncs;
for (i = 0; i < arrayProtoFuncsCount; i++) {
- restoreFunc(&arraysObj->idObj, sizeof(unsigned int));
+ arraysObj->idObj.low = restoreSint32();
+ arraysObj->idObj.hi = restoreSint32();
tempProtoFunc = luaM_new(TProtoFunc);
luaO_insertlist(&L->rootproto, (GCnode *)tempProtoFunc);
- restoreFunc(&tempProtoFunc->fileName, sizeof(TaggedString *));
- restoreFunc(&tempProtoFunc->lineDefined, sizeof(int));
- restoreFunc(&tempProtoFunc->nconsts, sizeof(int));
+ PointerId ptr;
+ ptr.low = restoreSint32();
+ ptr.hi = restoreSint32();
+ tempProtoFunc->fileName = (TaggedString *)makePointerFromId(ptr);
+ tempProtoFunc->lineDefined = restoreSint32();
+ tempProtoFunc->nconsts = restoreSint32();
tempProtoFunc->consts = (TObject *)luaM_malloc(tempProtoFunc->nconsts * sizeof(TObject));
for (l = 0; l < tempProtoFunc->nconsts; l++) {
- restoreFunc(&tempProtoFunc->consts[l].ttype, sizeof(lua_Type));
- restoreFunc(&tempProtoFunc->consts[l].value, sizeof(Value));
+ restoreObjectValue(&tempProtoFunc->consts[l], restoreSint32, restoreUint32);
}
- int countVariables;
- restoreFunc(&countVariables, sizeof(int));
- if (countVariables != 0) {
+ int32 countVariables = restoreSint32();
+ if (countVariables) {
tempProtoFunc->locvars = (LocVar *)luaM_malloc(countVariables * sizeof(LocVar));
} else {
tempProtoFunc->locvars = NULL;
}
for (l = 0; l < countVariables; l++) {
- restoreFunc(&tempProtoFunc->locvars[l].varname, sizeof(TaggedString *));
- restoreFunc(&tempProtoFunc->locvars[l].line, sizeof(int));
+ PointerId ptr;
+ ptr.low = restoreSint32();
+ ptr.hi = restoreSint32();
+ tempProtoFunc->locvars[l].varname = (TaggedString *)makePointerFromId(ptr);
+ tempProtoFunc->locvars[l].line = restoreSint32();
}
- int codeSize;
- restoreFunc(&codeSize, sizeof(int));
+ int32 codeSize = restoreSint32();
tempProtoFunc->code = (lua_Byte *)luaM_malloc(codeSize);
- restoreFunc(tempProtoFunc->code, codeSize);
+ restoreStream(tempProtoFunc->code, codeSize);
arraysObj->object = tempProtoFunc;
arraysObj++;
}
@@ -244,14 +376,14 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
stringtable *tempStringTable = &L->string_root[i];
for (l = 0; l < tempStringTable->size; l++) {
TaggedString *tempString = tempStringTable->hash[l];
- if ((tempString != NULL) && (tempString->constindex != -1) && (tempString != &EMPTY)) {
+ if (tempString && tempString->constindex != -1 && tempString != &EMPTY) {
recreateObj(&tempString->u.s.globalval);
}
}
}
tempProtoFunc = (TProtoFunc *)L->rootproto.next;
- while (tempProtoFunc != NULL) {
+ while (tempProtoFunc) {
TObject tempObj;
tempObj.value.ts = (TaggedString *)tempProtoFunc->fileName;
tempObj.ttype = LUA_T_STRING;
@@ -276,7 +408,7 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
}
tempHash = (Hash *)L->roottable.next;
- while (tempHash != NULL) {
+ while (tempHash) {
for (i = 0; i < tempHash->nuse; i++) {
recreateObj(&tempHash->node[i].ref);
recreateObj(&tempHash->node[i].val);
@@ -285,7 +417,7 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
tempHash->node = hashnodecreate(tempHash->nhash);
for (i = 0; i < tempHash->nuse; i++) {
Node *newNode = oldNode + i;
- if ((newNode->val.ttype != LUA_T_NIL) && (newNode->ref.ttype != LUA_T_NIL)) {
+ if (newNode->ref.ttype != LUA_T_NIL && newNode->val.ttype != LUA_T_NIL) {
*node(tempHash, present(tempHash, &newNode->ref)) = *newNode;
}
}
@@ -294,7 +426,7 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
}
tempClosure = (Closure *)L->rootcl.next;
- while (tempClosure != NULL) {
+ while (tempClosure) {
for (i = 0; i <= tempClosure->nelems; i++) {
recreateObj(&tempClosure->consts[i]);
}
@@ -306,7 +438,10 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
TObject tempObj;
TaggedString *tempString = NULL;
tempObj.ttype = LUA_T_STRING;
- restoreFunc(&tempObj.value, sizeof(TaggedString *));
+ PointerId ptr;
+ ptr.low = restoreSint32();
+ ptr.hi = restoreSint32();
+ tempObj.value.ts = (TaggedString *)makePointerFromId(ptr);
recreateObj(&tempObj);
tempString = (TaggedString *)tempObj.value.ts;
assert(tempString);
@@ -315,117 +450,114 @@ void lua_Restore(SaveRestoreFunc restoreFunc) {
}
tempListString->head.next = NULL;
- restoreFunc(&L->errorim.ttype, sizeof(lua_Type));
- restoreFunc(&L->errorim.value, sizeof(Value));
+ restoreObjectValue(&L->errorim, restoreSint32, restoreUint32);
recreateObj(&L->errorim);
- restoreFunc(&L->IMtable_size, sizeof(int));
+ L->IMtable_size = restoreSint32();
L->IMtable = (IM *)luaM_malloc(L->IMtable_size * sizeof(IM));
for (i = 0; i < L->IMtable_size; i++) {
IM *im = &L->IMtable[i];
for (l = 0; l < IM_N; l++) {
- restoreFunc(&im->int_method[l].ttype, sizeof(lua_Type));
- restoreFunc(&im->int_method[l].value, sizeof(Value));
+ restoreObjectValue(&im->int_method[l], restoreSint32, restoreUint32);
recreateObj(&im->int_method[l]);
}
}
- restoreFunc(&L->last_tag, sizeof(int));
- restoreFunc(&L->refSize, sizeof(int));
+ L->last_tag = restoreSint32();
+ L->refSize = restoreSint32();
L->refArray = (ref *)luaM_malloc(L->refSize * sizeof(ref));
for (i = 0; i < L->refSize; i++) {
- restoreFunc(&L->refArray[i].o.ttype, sizeof(lua_Type));
- restoreFunc(&L->refArray[i].o.value, sizeof(Value));
+ restoreObjectValue(&L->refArray[i].o, restoreSint32, restoreUint32);
recreateObj(&L->refArray[i].o);
- restoreFunc(&L->refArray[i].status, sizeof(Status));
+ L->refArray[i].status = (Status)restoreSint32();
}
- restoreFunc(&L->GCthreshold, sizeof(unsigned long));
- restoreFunc(&L->nblocks, sizeof(unsigned long));
+ L->GCthreshold = restoreSint32();
+ L->nblocks = restoreSint32();
- restoreFunc(&L->Mbuffsize, sizeof(int));
+ L->Mbuffsize = restoreSint32();
L->Mbuffer = (char *)luaM_malloc(L->Mbuffsize);
- restoreFunc(L->Mbuffer, L->Mbuffsize);
- int MbaseOffset;
- restoreFunc(&MbaseOffset, sizeof(int));
+ restoreStream(L->Mbuffer, L->Mbuffsize);
+ int32 MbaseOffset;
+ MbaseOffset = restoreSint32();
L->Mbuffbase = MbaseOffset + L->Mbuffer;
- restoreFunc(&L->Mbuffnext, sizeof(int));
+ L->Mbuffnext = restoreSint32();
- restoreFunc(&globalTaskSerialId, sizeof(int));
+ globalTaskSerialId = restoreSint32();
- int countTasks;
lua_Task *tempTask = NULL;
- restoreFunc(&countTasks, sizeof(int));
lua_Task *prevTask = L->root_task;
+ int32 countTasks = restoreSint32();
for (l = 0; l < countTasks; l++) {
tempTask = luaM_new(lua_Task);
memset(tempTask, 0, sizeof(lua_Task));
prevTask->next = tempTask;
prevTask = tempTask;
- int stackLastSize;
- restoreFunc(&stackLastSize, sizeof(int));
+ int32 stackLastSize = restoreSint32();
tempTask->stack.stack = (TObject *)luaM_malloc(stackLastSize * sizeof(TObject));
tempTask->stack.last = tempTask->stack.stack + stackLastSize - 1;
- int stackTopSize;
- restoreFunc(&stackTopSize, sizeof(int));
+ int32 stackTopSize = restoreSint32();
tempTask->stack.top = tempTask->stack.stack + stackTopSize;
for (i = 0; i < stackTopSize; i++) {
- restoreFunc(&tempTask->stack.stack[i].ttype, sizeof(lua_Type));
- restoreFunc(&tempTask->stack.stack[i].value, sizeof(Value));
+ restoreObjectValue(&tempTask->stack.stack[i], restoreSint32, restoreUint32);
recreateObj(&tempTask->stack.stack[i]);
}
- restoreFunc(&tempTask->Cstack.base, sizeof(StkId));
- restoreFunc(&tempTask->Cstack.lua2C, sizeof(StkId));
- restoreFunc(&tempTask->Cstack.num, sizeof(int));
+ tempTask->Cstack.base = restoreSint32();
+ tempTask->Cstack.lua2C = restoreSint32();
+ tempTask->Cstack.num = restoreSint32();
- restoreFunc(&tempTask->numCblocks, sizeof(int));
+ tempTask->numCblocks = restoreSint32();
for (i = 0; i < tempTask->numCblocks; i++) {
- restoreFunc(&tempTask->Cblocks[i].base, sizeof(StkId));
- restoreFunc(&tempTask->Cblocks[i].lua2C, sizeof(StkId));
- restoreFunc(&tempTask->Cblocks[i].num, sizeof(int));
+ tempTask->Cblocks[i].base = restoreSint32();
+ tempTask->Cblocks[i].lua2C = restoreSint32();
+ tempTask->Cblocks[i].num = restoreSint32();
}
- int pcOffset, taskCi;
- restoreFunc(&tempTask->base_ci_size, sizeof(int));
+ int32 pcOffset, taskCi;
+ tempTask->base_ci_size = restoreSint32();
tempTask->base_ci = (CallInfo *)luaM_malloc(tempTask->base_ci_size * sizeof(CallInfo));
memset(tempTask->base_ci, 0, sizeof(CallInfo) * tempTask->base_ci_size);
CallInfo *tempCi = tempTask->base_ci;
- int countCi = tempTask->base_ci_size / sizeof(CallInfo);
+ int32 countCi = tempTask->base_ci_size / sizeof(CallInfo);
for (i = 0; i < countCi; i++) {
TObject tempObj;
tempObj.ttype = LUA_T_CLOSURE;
- restoreFunc(&tempObj.value, sizeof(Closure *));
+ PointerId ptr;
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ tempObj.value.cl = (Closure *)makePointerFromId(ptr);
recreateObj(&tempObj);
tempCi->c = (Closure *)tempObj.value.cl;
tempObj.ttype = LUA_T_PROTO;
- restoreFunc(&tempObj.value, sizeof(TProtoFunc *));
+ ptr.low = restoreUint32();
+ ptr.hi = restoreUint32();
+ tempObj.value.tf = (TProtoFunc *)makePointerFromId(ptr);
recreateObj(&tempObj);
tempCi->tf = (TProtoFunc *)tempObj.value.tf;
- restoreFunc(&pcOffset, sizeof(int));
- if (pcOffset != 0)
+ pcOffset = restoreSint32();
+ if (pcOffset)
tempCi->pc = tempCi->tf->code + pcOffset;
else
tempCi->pc = NULL;
- restoreFunc(&tempCi->base, sizeof(StkId));
- restoreFunc(&tempCi->nResults, sizeof(int));
+ tempCi->base = restoreSint32();
+ tempCi->nResults = restoreSint32();
tempCi++;
}
- restoreFunc(&taskCi, sizeof(int));
+ taskCi = restoreSint32();
tempTask->ci = tempTask->base_ci + taskCi;
tempTask->end_ci = tempTask->base_ci + countCi;
- int Mbasepos;
- restoreFunc(&Mbasepos, sizeof(int));
+ int32 Mbasepos = restoreSint32();
tempTask->Mbuffbase = Mbasepos + tempTask->Mbuffer;
- restoreFunc(&tempTask->Mbuffnext, sizeof(int));
+ tempTask->Mbuffnext = restoreSint32();
- restoreFunc(&tempTask->Tstate, sizeof(TaskState));
- restoreFunc(&tempTask->id, sizeof(int));
+ tempTask->Tstate = (TaskState)restoreSint32();
+ tempTask->id = restoreSint32();
}
L->last_task = tempTask;
diff --git a/tools/lua/lsave.cpp b/tools/lua/lsave.cpp
index 362978563..577c94b03 100644
--- a/tools/lua/lsave.cpp
+++ b/tools/lua/lsave.cpp
@@ -1,8 +1,3 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <search.h>
-#include <assert.h>
-
#include "ltask.h"
#include "lauxlib.h"
#include "lmem.h"
@@ -12,32 +7,140 @@
#include "lvm.h"
#include "lopcodes.h"
#include "lstring.h"
+#include "lua.h"
+
+#include "common/endian.h"
+
+PointerId makeIdFromPointer(void *ptr) {
+ PointerId pointer;
+
+#ifdef TARGET_64BITS
+ uint64 v = (uint64)ptr;
+ pointer.low = v & 0xffffffff;
+ pointer.hi = v >> 32;
+#else
+ pointer.low = (uint32)ptr;
+ pointer.hi = 0;
+#endif
+
+ return pointer;
+}
+
+void *makePointerFromId(PointerId ptr) {
+ void *pointer;
+
+#ifdef TARGET_64BITS
+ uint64 v = ptr.low | ((uint64)ptr.hi << 32);
+ pointer = (void *)v;
+#else
+ pointer = (void *)ptr.low;
+#endif
-SaveRestoreCallback saveCallback = NULL;
-
-static void saveObjectValue(TObject *object, SaveRestoreFunc saveFunc) {
- saveFunc(&object->ttype, sizeof(lua_Type));
- if (object->ttype == LUA_T_CPROTO) {
- luaL_libList *list = list_of_libs;
- unsigned int idObj = 0;
- while (list != NULL) {
- for (int l = 0; l < list->number; l++) {
- if (list->list[l].func == object->value.f) {
- idObj = (idObj << 16) | l;
- saveFunc(&idObj, sizeof(unsigned int));
- return;
+ return pointer;
+}
+
+SaveCallback saveCallbackPtr = NULL;
+
+static void saveObjectValue(TObject *object, SaveSint32 saveSint32, SaveUint32 saveUint32) {
+ saveSint32(object->ttype);
+
+ switch (object->ttype) {
+ case LUA_T_CPROTO:
+ case LUA_T_CMARK:
+ {
+ luaL_libList *list = list_of_libs;
+ int32 idObj = 0;
+ while (list) {
+ for (int32 l = 0; l < list->number; l++) {
+ if (list->list[l].func == object->value.f) {
+ idObj = (idObj << 16) | l;
+ saveSint32(idObj);
+ saveSint32(0);
+ return;
+ }
+ }
+ list = list->next;
+ idObj++;
}
+ assert(0);
+ break;
}
- list = list->next;
- idObj++;
- }
- assert(0);
- } else {
- saveFunc(&object->value, sizeof(Value));
+ case LUA_T_NUMBER:
+ case LUA_T_TASK:
+ {
+ byte *udata = (byte *)(&object->value.n);
+ uint32 v;
+#if defined(SYSTEM_LITTLE_ENDIAN)
+ byte b[4];
+ b[0] = udata[3];
+ b[1] = udata[2];
+ b[2] = udata[1];
+ b[3] = udata[0];
+ v = *(uint32 *)b;
+#else
+ memcpy(&v, udata, 4);
+#endif
+ saveUint32(v);
+ saveUint32(0);
+ }
+ break;
+ case LUA_T_NIL:
+ {
+ saveUint32(0);
+ saveUint32(0);
+ }
+ break;
+ case LUA_T_ARRAY:
+ {
+ saveUint32(makeIdFromPointer(object->value.a).low);
+ saveUint32(makeIdFromPointer(object->value.a).hi);
+ }
+ break;
+ case LUA_T_USERDATA:
+ case LUA_T_STRING:
+ {
+ saveUint32(makeIdFromPointer(object->value.ts).low);
+ saveUint32(makeIdFromPointer(object->value.ts).hi);
+ }
+ break;
+ case LUA_T_PROTO:
+ case LUA_T_PMARK:
+ {
+ saveUint32(makeIdFromPointer(object->value.tf).low);
+ saveUint32(makeIdFromPointer(object->value.tf).hi);
+ }
+ break;
+ case LUA_T_CLOSURE:
+ case LUA_T_CLMARK:
+ {
+ saveUint32(makeIdFromPointer(object->value.cl).low);
+ saveUint32(makeIdFromPointer(object->value.cl).hi);
+ }
+ break;
+ case LUA_T_LINE:
+ {
+ saveSint32(object->value.i);
+ saveSint32(0);
+ }
+ break;
+ case MKID_BE('ACTR'):
+ case MKID_BE('COLR'):
+ case MKID_BE('STAT'):
+ case MKID_BE('FONT'):
+ case MKID_BE('VBUF'):
+ case MKID_BE('PRIM'):
+ case MKID_BE('TEXT'):
+ { // TODO
+ saveUint32(makeIdFromPointer(object->value.ts).low);
+ saveUint32(makeIdFromPointer(object->value.ts).hi);
+ }
+ break;
+ default:
+ lua_error("saveObjectValue: Unsupported object type");
}
}
-static int opcodeSizeTable[] = {
+static int32 opcodeSizeTable[] = {
1, 2, 1, 2, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1,
1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3,
1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -53,17 +156,20 @@ static int opcodeSizeTable[] = {
2, 3, 2, 3, 2, 3, 2, 1, 1, 3, 2, 2, 2, 2, 3, 2, 1, 1
};
-void lua_Save(SaveRestoreFunc saveFunc) {
+void lua_Save(SaveStream saveStream, SaveSint32 saveSint32, SaveUint32 saveUint32) {
printf("lua_Save() started.\n");
lua_collectgarbage(0);
- int i, l;
- int countElements = 0;
- int maxStringLength = 0;
+ int32 i, l;
+ int32 countElements = 0;
+ int32 maxStringLength = 0;
+
+
+ // Check for max length for strings and count them
for (i = 0; i < NUM_HASHS; i++) {
stringtable *tempStringTable = &L->string_root[i];
- for (int l = 0; l < tempStringTable->size; l++) {
- if ((tempStringTable->hash[l] != NULL) && (tempStringTable->hash[l] != &EMPTY)) {
+ for (int32 l = 0; l < tempStringTable->size; l++) {
+ if (tempStringTable->hash[l] && tempStringTable->hash[l] != &EMPTY) {
countElements++;
if (tempStringTable->hash[l]->constindex != -1) {
if (maxStringLength < tempStringTable->hash[l]->u.s.len) {
@@ -73,224 +179,242 @@ void lua_Save(SaveRestoreFunc saveFunc) {
}
}
}
+ // save number of strings
+ saveSint32(countElements);
- saveFunc(&countElements, sizeof(int));
- countElements = 0;
+ // save number of closures
+ countElements = 0;
GCnode *tempNode;
tempNode = L->rootcl.next;
- while (tempNode != NULL) {
+ while (tempNode) {
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
- countElements = 0;
+ saveSint32(countElements);
+ // save number of tables
+ countElements = 0;
tempNode = L->roottable.next;
- while (tempNode != NULL) {
+ while (tempNode) {
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
- countElements = 0;
+ saveSint32(countElements);
+ // save number of prototypes
+ countElements = 0;
tempNode = L->rootproto.next;
- while (tempNode != NULL) {
+ while (tempNode) {
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
- countElements = 0;
+ saveSint32(countElements);
+ // save number of global strings
+ countElements = 0;
tempNode = L->rootglobal.next;
- while (tempNode != NULL) {
+ while (tempNode) {
countElements++;
tempNode = tempNode->next;
}
- saveFunc(&countElements, sizeof(int));
+ saveSint32(countElements);
- saveFunc(&maxStringLength, sizeof(int));
+ // save maximum length for string
+ saveSint32(maxStringLength);
+ // save hash tables for strings and user data
TaggedString *tempString;
for (i = 0; i < NUM_HASHS; i++) {
stringtable *tempStringTable = &L->string_root[i];
for (l = 0; l < tempStringTable->size; l++) {
- if ((tempStringTable->hash[l] != NULL) && (tempStringTable->hash[l] != &EMPTY)) {
+ if (tempStringTable->hash[l] && tempStringTable->hash[l] != &EMPTY) {
tempString = tempStringTable->hash[l];
- saveFunc(&tempString, sizeof(TaggedString *));
- saveFunc(&tempString->constindex, sizeof(int));
+ saveUint32(makeIdFromPointer(tempString).low);
+ saveUint32(makeIdFromPointer(tempString).hi);
+ saveSint32(tempString->constindex);
if (tempString->constindex != -1) {
- saveObjectValue(&tempString->u.s.globalval, saveFunc);
- saveFunc(&tempString->u.s.len, sizeof(long));
- saveFunc(tempString->str, tempString->u.s.len);
- } else {
- if (saveCallback != NULL) {
- tempString->u.s.globalval.value.ts = (TaggedString *)saveCallback(tempString->u.s.globalval.ttype, (int)tempString->u.s.globalval.value.ts, saveFunc);
+ saveObjectValue(&tempString->u.s.globalval, saveSint32, saveUint32);
+ saveSint32(tempString->u.s.len);
+ saveStream(tempString->str, tempString->u.s.len);
+ } else {
+ if (saveCallbackPtr) {
+ PointerId ptr = makeIdFromPointer(tempString->u.s.globalval.value.ts);
+ ptr = saveCallbackPtr(tempString->u.s.globalval.ttype, ptr, saveSint32);
+ tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
}
- saveObjectValue(&tempString->u.s.globalval, saveFunc);
+ saveObjectValue(&tempString->u.s.globalval, saveSint32, saveUint32);
}
}
}
}
Closure *tempClosure = (Closure *)L->rootcl.next;
- while (tempClosure != NULL) {
- saveFunc(&tempClosure, sizeof(Closure *));
- saveFunc(&tempClosure->nelems, sizeof(int));
- for(i = 0; i <= tempClosure->nelems; i++) {
- saveObjectValue(&tempClosure->consts[i], saveFunc);
+ while (tempClosure) {
+ saveUint32(makeIdFromPointer(tempClosure).low);
+ saveUint32(makeIdFromPointer(tempClosure).hi);
+ saveSint32(tempClosure->nelems);
+ for (i = 0; i <= tempClosure->nelems; i++) {
+ saveObjectValue(&tempClosure->consts[i], saveSint32, saveUint32);
}
tempClosure = (Closure *)tempClosure->head.next;
}
Hash *tempHash = (Hash *)L->roottable.next;
- while (tempHash != NULL) {
- saveFunc(&tempHash, sizeof(Hash *));
- saveFunc(&tempHash->nhash, sizeof(unsigned int));
- int countUsedHash = 0;
+ while (tempHash) {
+ saveUint32(makeIdFromPointer(tempHash).low);
+ saveUint32(makeIdFromPointer(tempHash).hi);
+ saveSint32(tempHash->nhash);
+ int32 countUsedHash = 0;
for(i = 0; i < tempHash->nhash; i++) {
Node *newNode = &tempHash->node[i];
- if ((newNode->ref.ttype != LUA_T_NIL) && (newNode->val.ttype != LUA_T_NIL)) {
+ if (newNode->ref.ttype != LUA_T_NIL && newNode->val.ttype != LUA_T_NIL) {
countUsedHash++;
}
}
- saveFunc(&countUsedHash, sizeof(int));
- saveFunc(&tempHash->htag, sizeof(int));
+ saveSint32(countUsedHash);
+ saveSint32(tempHash->htag);
for (i = 0; i < tempHash->nhash; i++) {
Node *newNode = &tempHash->node[i];
- if ((newNode->val.ttype != LUA_T_NIL) && (newNode->ref.ttype != LUA_T_NIL)) {
- saveObjectValue(&tempHash->node[i].ref, saveFunc);
- saveObjectValue(&tempHash->node[i].val, saveFunc);
+ if (newNode->ref.ttype != LUA_T_NIL && newNode->val.ttype != LUA_T_NIL) {
+ saveObjectValue(&tempHash->node[i].ref, saveSint32, saveUint32);
+ saveObjectValue(&tempHash->node[i].val, saveSint32, saveUint32);
}
}
tempHash = (Hash *)tempHash->head.next;
}
TProtoFunc *tempProtoFunc = (TProtoFunc *)L->rootproto.next;
- while (tempProtoFunc != NULL) {
- saveFunc(&tempProtoFunc, sizeof(TProtoFunc *));
- saveFunc(&tempProtoFunc->fileName, sizeof(TaggedString *));
- saveFunc(&tempProtoFunc->lineDefined, sizeof(unsigned int));
- saveFunc(&tempProtoFunc->nconsts, sizeof(unsigned int));
+ while (tempProtoFunc) {
+ saveUint32(makeIdFromPointer(tempProtoFunc).low);
+ saveUint32(makeIdFromPointer(tempProtoFunc).hi);
+ saveUint32(makeIdFromPointer(tempProtoFunc->fileName).low);
+ saveUint32(makeIdFromPointer(tempProtoFunc->fileName).hi);
+ saveSint32(tempProtoFunc->lineDefined);
+ saveSint32(tempProtoFunc->nconsts);
for (i = 0; i < tempProtoFunc->nconsts; i++) {
- saveObjectValue(&tempProtoFunc->consts[i], saveFunc);
+ saveObjectValue(&tempProtoFunc->consts[i], saveSint32, saveUint32);
}
- int countVariables = 0;
+ int32 countVariables = 0;
if (tempProtoFunc->locvars) {
for (; tempProtoFunc->locvars[countVariables++].line != -1;) { }
}
- saveFunc(&countVariables, sizeof(int));
+ saveSint32(countVariables);
for (i = 0; i < countVariables; i++) {
- saveFunc(&tempProtoFunc->locvars[i].varname, sizeof(TaggedString *));
- saveFunc(&tempProtoFunc->locvars[i].line, sizeof(int));
+ saveUint32(makeIdFromPointer(tempProtoFunc->locvars[i].varname).low);
+ saveUint32(makeIdFromPointer(tempProtoFunc->locvars[i].varname).hi);
+ saveSint32(tempProtoFunc->locvars[i].line);
}
Byte *codePtr = tempProtoFunc->code + 2;
Byte *tmpPtr = codePtr;
- int opcodeId;
+ int32 opcodeId;
do {
opcodeId = *tmpPtr;
tmpPtr += opcodeSizeTable[opcodeId];
} while (opcodeId != ENDCODE);
- int codeSize = (tmpPtr - codePtr) + 2;
- saveFunc(&codeSize, sizeof(int));
- saveFunc(tempProtoFunc->code, codeSize);
+ int32 codeSize = (tmpPtr - codePtr) + 2;
+ saveSint32(codeSize);
+ saveStream(tempProtoFunc->code, codeSize);
tempProtoFunc = (TProtoFunc *)tempProtoFunc->head.next;
}
tempString = (TaggedString *)L->rootglobal.next;
- while (tempString != NULL) {
- saveFunc(&tempString, sizeof(TaggedString *));
+ while (tempString) {
+ saveUint32(makeIdFromPointer(tempString).low);
+ saveUint32(makeIdFromPointer(tempString).hi);
tempString = (TaggedString *)tempString->head.next;
}
- saveObjectValue(&L->errorim, saveFunc);
+ saveObjectValue(&L->errorim, saveSint32, saveUint32);
IM *tempIm = L->IMtable;
- saveFunc(&L->IMtable_size, sizeof(int));
+ saveSint32(L->IMtable_size);
for (i = 0; i < L->IMtable_size; i++) {
for (l = 0; l < IM_N; l++) {
- saveObjectValue(&tempIm->int_method[l], saveFunc);
+ saveObjectValue(&tempIm->int_method[l], saveSint32, saveUint32);
}
tempIm++;
}
- saveFunc(&L->last_tag, sizeof(int));
- saveFunc(&L->refSize, sizeof(int));
+ saveSint32(L->last_tag);
+ saveSint32(L->refSize);
for (i = 0 ; i < L->refSize; i++) {
- saveObjectValue(&L->refArray[i].o, saveFunc);
- saveFunc(&L->refArray[i].status, sizeof(Status));
+ saveObjectValue(&L->refArray[i].o, saveSint32, saveUint32);
+ saveSint32(L->refArray[i].status);
}
- saveFunc(&L->GCthreshold, sizeof(unsigned long));
- saveFunc(&L->nblocks, sizeof(unsigned long));
+ saveSint32(L->GCthreshold);
+ saveSint32(L->nblocks);
- saveFunc(&L->Mbuffsize, sizeof(int));
- saveFunc(L->Mbuffer, L->Mbuffsize);
- int MbaseOffset = L->Mbuffbase - L->Mbuffer;
- saveFunc(&MbaseOffset, sizeof(int));
- saveFunc(&L->Mbuffnext, sizeof(int));
+ saveSint32(L->Mbuffsize);
+ saveStream(L->Mbuffer, L->Mbuffsize);
+ int32 MbaseOffset = L->Mbuffbase - L->Mbuffer;
+ saveSint32(MbaseOffset);
+ saveSint32(L->Mbuffnext);
- saveFunc(&globalTaskSerialId, sizeof(int));
+ saveSint32(globalTaskSerialId);
- int countTasks = 0;
+ int32 countTasks = 0;
lua_Task *tempTask = L->root_task->next;
- while (tempTask != NULL) {
+ while (tempTask) {
countTasks++;
tempTask = tempTask->next;
}
- saveFunc(&countTasks, sizeof(int));
+ saveSint32(countTasks);
tempTask = L->root_task->next;
- while (tempTask != NULL) {
- int stackLastSize = (tempTask->stack.last - tempTask->stack.stack) + 1;
- saveFunc(&stackLastSize, sizeof(int));
- int stackTopSize = tempTask->stack.top - tempTask->stack.stack;
- saveFunc(&stackTopSize, sizeof(int));
+ while (tempTask) {
+ int32 stackLastSize = (tempTask->stack.last - tempTask->stack.stack) + 1;
+ saveSint32(stackLastSize);
+ int32 stackTopSize = tempTask->stack.top - tempTask->stack.stack;
+ saveSint32(stackTopSize);
for (i = 0; i < stackTopSize; i++) {
- saveObjectValue(&tempTask->stack.stack[i], saveFunc);
+ saveObjectValue(&tempTask->stack.stack[i], saveSint32, saveUint32);
}
- saveFunc(&tempTask->Cstack.base, sizeof(StkId));
- saveFunc(&tempTask->Cstack.lua2C, sizeof(StkId));
- saveFunc(&tempTask->Cstack.num, sizeof(int));
+ saveSint32(tempTask->Cstack.base);
+ saveSint32(tempTask->Cstack.lua2C);
+ saveSint32(tempTask->Cstack.num);
- saveFunc(&tempTask->numCblocks, sizeof(int));
+ saveSint32(tempTask->numCblocks);
for (i = 0; i < tempTask->numCblocks; i++) {
- saveFunc(&tempTask->Cblocks[i].base, sizeof(StkId));
- saveFunc(&tempTask->Cblocks[i].lua2C, sizeof(StkId));
- saveFunc(&tempTask->Cblocks[i].num, sizeof(int));
+ saveSint32(tempTask->Cblocks[i].base);
+ saveSint32(tempTask->Cblocks[i].lua2C);
+ saveSint32(tempTask->Cblocks[i].num);
}
- int pcOffset, taskCi = -1;
- saveFunc(&tempTask->base_ci_size, sizeof(int));
+ int32 pcOffset, taskCi = -1;
+ saveSint32(tempTask->base_ci_size);
assert(tempTask->base_ci);
CallInfo *tempCi = tempTask->base_ci;
- int countCi = tempTask->base_ci_size / sizeof(CallInfo);
+ int32 countCi = tempTask->base_ci_size / sizeof(CallInfo);
for (i = 0; i < countCi; i++) {
- saveFunc(&tempCi->c, sizeof(Closure *));
- saveFunc(&tempCi->tf, sizeof(TProtoFunc *));
- if ((tempCi->pc != NULL) && (tempTask->ci->tf != NULL))
+ saveUint32(makeIdFromPointer(tempCi->c).low);
+ saveUint32(makeIdFromPointer(tempCi->c).hi);
+ saveUint32(makeIdFromPointer(tempCi->tf).low);
+ saveUint32(makeIdFromPointer(tempCi->tf).hi);
+ if (tempCi->pc && tempTask->ci->tf)
pcOffset = tempCi->pc - tempCi->tf->code;
else
pcOffset = 0;
- saveFunc(&pcOffset, sizeof(int));
- saveFunc(&tempCi->base, sizeof(StkId));
- saveFunc(&tempCi->nResults, sizeof(int));
+ saveSint32(pcOffset);
+ saveSint32(tempCi->base);
+ saveSint32(tempCi->nResults);
if (tempCi == tempTask->ci)
taskCi = i;
tempCi++;
}
assert(taskCi != -1);
- saveFunc(&taskCi, sizeof(int));
+ saveSint32(taskCi);
MbaseOffset = tempTask->Mbuffbase - tempTask->Mbuffer;
- saveFunc(&MbaseOffset, sizeof(int));
- saveFunc(&tempTask->Mbuffnext, sizeof(int));
+ saveSint32(MbaseOffset);
+ saveSint32(tempTask->Mbuffnext);
- saveFunc(&tempTask->Tstate, sizeof(TaskState));
- saveFunc(&tempTask->id, sizeof(int));
+ saveSint32(tempTask->Tstate);
+ saveSint32(tempTask->id);
tempTask = tempTask->next;
}
diff --git a/tools/lua/lstate.cpp b/tools/lua/lstate.cpp
index 2f5448d34..2c6bd4d08 100644
--- a/tools/lua/lstate.cpp
+++ b/tools/lua/lstate.cpp
@@ -1,28 +1,27 @@
/*
-** $Id$
+** $Id: lstate.cpp 905 2008-07-20 21:08:22Z aquadran $
** Global State
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <tools/lua/lbuiltin.h>
-#include <tools/lua/ldo.h>
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lgc.h>
-#include <tools/lua/llex.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/ltable.h>
-#include <tools/lua/ltask.h>
-#include <tools/lua/ltm.h>
+#include "lbuiltin.h"
+#include "ldo.h"
+#include "lauxlib.h"
+#include "lfunc.h"
+#include "lgc.h"
+#include "llex.h"
+#include "lmem.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "ltask.h"
+#include "ltm.h"
lua_State *lua_state = NULL;
-int globalTaskSerialId;
+int32 globalTaskSerialId;
void stderrorim (void);
diff --git a/tools/lua/lstate.h b/tools/lua/lstate.h
index 659685cb1..2b7b1a0f4 100644
--- a/tools/lua/lstate.h
+++ b/tools/lua/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lstate.h 905 2008-07-20 21:08:22Z aquadran $
** Global State
** See Copyright Notice in lua.h
*/
@@ -9,8 +9,8 @@
#include <setjmp.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lua.h>
+#include "lobject.h"
+#include "lua.h"
#define MAX_C_BLOCKS 10
@@ -18,7 +18,7 @@
#define GARBAGE_BLOCK 150
-typedef int StkId; /* index to stack elements */
+typedef int32 StkId; /* index to stack elements */
struct Stack {
TObject *top;
@@ -30,13 +30,13 @@ struct C_Lua_Stack {
StkId base; /* when Lua calls C or C calls Lua, points to */
/* the first slot after the last parameter. */
StkId lua2C; /* points to first element of "array" lua2C */
- int num; /* size of "array" lua2C */
+ int32 num; /* size of "array" lua2C */
};
typedef struct {
- int size;
- int nuse; /* number of elements (including EMPTYs) */
+ int32 size;
+ int32 nuse; /* number of elements (including EMPTYs) */
TaggedString **hash;
} stringtable;
@@ -54,7 +54,7 @@ struct CallInfo {
TProtoFunc *tf; /* Set to NULL for C function */
StkId base;
Byte *pc;
- int nResults;
+ int32 nResults;
};
@@ -66,17 +66,17 @@ struct lua_Task {
jmp_buf *errorJmp;
struct CallInfo *ci;
struct CallInfo *base_ci;
- int base_ci_size;
+ int32 base_ci_size;
struct CallInfo *end_ci;
char *Mbuffer;
char *Mbuffbase;
- int Mbuffsize;
- int Mbuffnext;
+ int32 Mbuffsize;
+ int32 Mbuffnext;
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
- int numCblocks;
+ int32 numCblocks;
enum TaskState Tstate;
struct lua_Task *next;
- int id;
+ int32 id;
};
struct lua_State {
@@ -86,14 +86,14 @@ struct lua_State {
jmp_buf *errorJmp; /* current error recover point */
struct CallInfo *ci; /* call info for current function */
struct CallInfo *base_ci; /* array of CallInfo's */
- int base_ci_size;
+ int32 base_ci_size;
struct CallInfo *end_ci; /* points after end of ci array */
char *Mbuffer; /* global buffer */
char *Mbuffbase; /* current first position of Mbuffer */
- int Mbuffsize; /* size of Mbuffer */
- int Mbuffnext; /* next position to fill in Mbuffer */
+ int32 Mbuffsize; /* size of Mbuffer */
+ int32 Mbuffnext; /* next position to fill in Mbuffer */
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
- int numCblocks; /* number of nested Cblocks */
+ int32 numCblocks; /* number of nested Cblocks */
enum TaskState Tstate; /* state of current thread */
/* global state */
struct lua_Task *root_task; /* first task created */
@@ -106,18 +106,18 @@ struct lua_State {
GCnode rootglobal; /* list of strings with global values */
stringtable *string_root; /* array of hash tables for strings and udata */
struct IM *IMtable; /* table for tag methods */
- int IMtable_size; /* size of IMtable */
- int last_tag; /* last used tag in IMtable */
+ int32 IMtable_size; /* size of IMtable */
+ int32 last_tag; /* last used tag in IMtable */
struct ref *refArray; /* locked objects */
- int refSize; /* size of refArray */
- unsigned long GCthreshold;
- unsigned long nblocks; /* number of 'blocks' currently allocated */
+ int32 refSize; /* size of refArray */
+ int32 GCthreshold;
+ int32 nblocks; /* number of 'blocks' currently allocated */
};
extern lua_State *lua_state;
-extern int globalTaskSerialId;
+extern int32 globalTaskSerialId;
#define L lua_state
diff --git a/tools/lua/lstring.cpp b/tools/lua/lstring.cpp
index 47b24bc64..a9d74e809 100644
--- a/tools/lua/lstring.cpp
+++ b/tools/lua/lstring.cpp
@@ -1,18 +1,15 @@
/*
-** $Id$
+** $Id: lstring.cpp 905 2008-07-20 21:08:22Z aquadran $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <string.h>
-
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/lua.h>
+#include "lmem.h"
+#include "lobject.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "lua.h"
@@ -27,7 +24,7 @@ TaggedString EMPTY = {{NULL, 2}, 0L, 0,
void luaS_init (void)
{
- int i;
+ int32 i;
L->string_root = luaM_newvector(NUM_HASHS, stringtable);
for (i=0; i<NUM_HASHS; i++) {
L->string_root[i].size = 0;
@@ -37,19 +34,19 @@ void luaS_init (void)
}
-static unsigned long hash_s (char *s, long l)
+static uint32 hash_s (const char *s, int32 l)
{
- unsigned long h = 0;
+ uint32 h = 0;
while (l--)
- h = ((h<<5)-h)^(unsigned char)*(s++);
+ h = ((h<<5)-h)^(byte)*(s++);
return h;
}
-static int newsize (stringtable *tb)
+static int32 newsize (stringtable *tb)
{
- int size = tb->size;
- int realuse = 0;
- int i;
+ int32 size = tb->size;
+ int32 realuse = 0;
+ int32 i;
/* count how many entries are really in use */
for (i=0; i<size; i++)
if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY)
@@ -64,16 +61,16 @@ static int newsize (stringtable *tb)
static void grow (stringtable *tb)
{
- int ns = newsize(tb);
+ int32 ns = newsize(tb);
TaggedString **newhash = luaM_newvector(ns, TaggedString *);
- int i;
+ int32 i;
for (i=0; i<ns; i++)
newhash[i] = NULL;
/* rehash */
tb->nuse = 0;
for (i=0; i<tb->size; i++) {
if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) {
- int h = tb->hash[i]->hash%ns;
+ int32 h = tb->hash[i]->hash%ns;
while (newhash[h])
h = (h+1)%ns;
newhash[h] = tb->hash[i];
@@ -86,7 +83,7 @@ static void grow (stringtable *tb)
}
-static TaggedString *newone_s (char *str, long l, unsigned long h)
+static TaggedString *newone_s (const char *str, int32 l, uint32 h)
{
TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l);
memcpy(ts->str, str, l);
@@ -101,7 +98,7 @@ static TaggedString *newone_s (char *str, long l, unsigned long h)
return ts;
}
-static TaggedString *newone_u (char *buff, int tag, unsigned long h)
+static TaggedString *newone_u (char *buff, int32 tag, uint32 h)
{
TaggedString *ts = luaM_new(TaggedString);
ts->u.d.v = buff;
@@ -114,14 +111,14 @@ static TaggedString *newone_u (char *buff, int tag, unsigned long h)
return ts;
}
-static TaggedString *insert_s (char *str, long l, stringtable *tb)
+static TaggedString *insert_s (const char *str, int32 l, stringtable *tb)
{
TaggedString *ts;
- unsigned long h = hash_s(str, l);
- int size = tb->size;
- int i;
- int j = -1;
- if ((long)tb->nuse*3 >= (long)size*2) {
+ uint32 h = hash_s(str, l);
+ int32 size = tb->size;
+ int32 i;
+ int32 j = -1;
+ if ((int32)tb->nuse*3 >= size*2) {
grow(tb);
size = tb->size;
}
@@ -130,8 +127,7 @@ static TaggedString *insert_s (char *str, long l, stringtable *tb)
j = i;
else if (ts->constindex >= 0 &&
ts->u.s.len == l &&
- (memcmp(str, ts->str, l) == 0))
- return ts;
+ (memcmp(str, ts->str, l) == 0)) return ts;
if (++i == size) i=0;
}
/* not found */
@@ -143,14 +139,14 @@ static TaggedString *insert_s (char *str, long l, stringtable *tb)
return ts;
}
-static TaggedString *insert_u (void *buff, int tag, stringtable *tb)
+static TaggedString *insert_u (void *buff, int32 tag, stringtable *tb)
{
TaggedString *ts;
unsigned long h = (unsigned long)buff;
- int size = tb->size;
- int i;
- int j = -1;
- if ((long)tb->nuse*3 >= (long)size*2) {
+ int32 size = tb->size;
+ int32 i;
+ int32 j = -1;
+ if (tb->nuse*3 >= size*2) {
grow(tb);
size = tb->size;
}
@@ -172,23 +168,23 @@ static TaggedString *insert_u (void *buff, int tag, stringtable *tb)
return ts;
}
-TaggedString *luaS_createudata (void *udata, int tag)
+TaggedString *luaS_createudata (void *udata, int32 tag)
{
- return insert_u(udata, tag, &L->string_root[1%NUM_HASHS]);
+ return insert_u(udata, tag, &L->string_root[(unsigned long)udata%NUM_HASHS]);
}
-TaggedString *luaS_newlstr (char *str, long l)
+TaggedString *luaS_newlstr (const char *str, int32 l)
{
- int i = (l==0)?0:(unsigned char)str[0];
+ int32 i = (l==0)?0:(byte)str[0];
return insert_s(str, l, &L->string_root[i%NUM_HASHS]);
}
-TaggedString *luaS_new (char *str)
+TaggedString *luaS_new (const char *str)
{
return luaS_newlstr(str, strlen(str));
}
-TaggedString *luaS_newfixedstring (char *str)
+TaggedString *luaS_newfixedstring (const char *str)
{
TaggedString *ts = luaS_new(str);
if (ts->head.marked == 0)
@@ -226,11 +222,11 @@ static void remove_from_list (GCnode *l)
TaggedString *luaS_collector (void)
{
TaggedString *frees = NULL;
- int i;
+ int32 i;
remove_from_list(&(L->rootglobal));
for (i=0; i<NUM_HASHS; i++) {
stringtable *tb = &L->string_root[i];
- int j;
+ int32 j;
for (j=0; j<tb->size; j++) {
TaggedString *t = tb->hash[j];
if (t == NULL) continue;
@@ -250,11 +246,11 @@ TaggedString *luaS_collector (void)
TaggedString *luaS_collectudata (void)
{
TaggedString *frees = NULL;
- int i;
+ int32 i;
L->rootglobal.next = NULL; /* empty list of globals */
for (i=0; i<NUM_HASHS; i++) {
stringtable *tb = &L->string_root[i];
- int j;
+ int32 j;
for (j=0; j<tb->size; j++) {
TaggedString *t = tb->hash[j];
if (t == NULL || t == &EMPTY || t->constindex != -1)
@@ -270,10 +266,10 @@ TaggedString *luaS_collectudata (void)
void luaS_freeall (void)
{
- int i;
+ int32 i;
for (i=0; i<NUM_HASHS; i++) {
stringtable *tb = &L->string_root[i];
- int j;
+ int32 j;
for (j=0; j<tb->size; j++) {
TaggedString *t = tb->hash[j];
if (t == &EMPTY) continue;
@@ -295,7 +291,7 @@ void luaS_rawsetglobal (TaggedString *ts, TObject *newval)
}
-char *luaS_travsymbol (int (*fn)(TObject *))
+char *luaS_travsymbol (int32 (*fn)(TObject *))
{
TaggedString *g;
for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next)
@@ -305,7 +301,7 @@ char *luaS_travsymbol (int (*fn)(TObject *))
}
-int luaS_globaldefined (char *name)
+int32 luaS_globaldefined (const char *name)
{
TaggedString *ts = luaS_new(name);
return ts->u.s.globalval.ttype != LUA_T_NIL;
diff --git a/tools/lua/lstring.h b/tools/lua/lstring.h
index adddb0034..d5eb23da6 100644
--- a/tools/lua/lstring.h
+++ b/tools/lua/lstring.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lstring.h 905 2008-07-20 21:08:22Z aquadran $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -8,19 +8,19 @@
#define lstring_h
-#include <tools/lua/lobject.h>
+#include "lobject.h"
void luaS_init (void);
-TaggedString *luaS_createudata (void *udata, int tag);
+TaggedString *luaS_createudata (void *udata, int32 tag);
TaggedString *luaS_collector (void);
void luaS_free (TaggedString *l);
-TaggedString *luaS_newlstr (char *str, long l);
-TaggedString *luaS_new (char *str);
-TaggedString *luaS_newfixedstring (char *str);
+TaggedString *luaS_newlstr (const char *str, int32 l);
+TaggedString *luaS_new (const char *str);
+TaggedString *luaS_newfixedstring (const char *str);
void luaS_rawsetglobal (TaggedString *ts, TObject *newval);
-char *luaS_travsymbol (int (*fn)(TObject *));
-int luaS_globaldefined (char *name);
+char *luaS_travsymbol (int32 (*fn)(TObject *));
+int32 luaS_globaldefined (const char *name);
TaggedString *luaS_collectudata (void);
void luaS_freeall (void);
diff --git a/tools/lua/lstrlib.cpp b/tools/lua/lstrlib.cpp
index 8a68d69d4..e8e11a6cd 100644
--- a/tools/lua/lstrlib.cpp
+++ b/tools/lua/lstrlib.cpp
@@ -1,22 +1,17 @@
/*
-** $Id$
+** $Id: lstrlib.cpp 905 2008-07-20 21:08:22Z aquadran $
** Standard library for strings and pattern-matching
** See Copyright Notice in lua.h
*/
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "lauxlib.h"
+#include "lua.h"
+#include "lualib.h"
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lua.h>
-#include <tools/lua/lualib.h>
-
-static void addnchar (char *s, int n)
+static void addnchar (const char *s, int32 n)
{
char *b = luaL_openspace(n);
memcpy(b, s, n);
@@ -26,7 +21,7 @@ static void addnchar (char *s, int n)
static void str_len (void)
{
- long l;
+ int32 l;
luaL_check_lstr(1, &l);
lua_pushnumber(l);
}
@@ -38,7 +33,7 @@ static void closeandpush (void)
}
-static long posrelat (long pos, long len)
+static int32 posrelat (int32 pos, int32 len)
{
/* relative string position: negative means back from end */
return (pos>=0) ? pos : len+pos+1;
@@ -47,10 +42,10 @@ static long posrelat (long pos, long len)
static void str_sub (void)
{
- long l;
- char *s = luaL_check_lstr(1, &l);
- long start = posrelat((int)luaL_check_number(2), l);
- long end = posrelat((int)luaL_opt_number(3, -1), l);
+ int32 l;
+ const char *s = luaL_check_lstr(1, &l);
+ int32 start = posrelat((int32)luaL_check_number(2), l);
+ int32 end = posrelat((int32)luaL_opt_number(3, -1), l);
if (1 <= start && start <= end && end <= l)
lua_pushlstring(s+start-1, end-start+1);
else lua_pushstring("");
@@ -59,32 +54,32 @@ static void str_sub (void)
static void str_lower (void)
{
- long l;
- int i;
- char *s = luaL_check_lstr(1, &l);
+ int32 l;
+ int32 i;
+ const char *s = luaL_check_lstr(1, &l);
luaL_resetbuffer();
for (i=0; i<l; i++)
- luaL_addchar(tolower((unsigned char)(s[i])));
+ luaL_addchar(tolower((byte)(s[i])));
closeandpush();
}
static void str_upper (void)
{
- long l;
- int i;
- char *s = luaL_check_lstr(1, &l);
+ int32 l;
+ int32 i;
+ const char *s = luaL_check_lstr(1, &l);
luaL_resetbuffer();
for (i=0; i<l; i++)
- luaL_addchar(toupper((unsigned char)(s[i])));
+ luaL_addchar(toupper((byte)(s[i])));
closeandpush();
}
static void str_rep (void)
{
- long l;
- char *s = luaL_check_lstr(1, &l);
- int n = (int)luaL_check_number(2);
+ int32 l;
+ const char *s = luaL_check_lstr(1, &l);
+ int32 n = (int32)luaL_check_number(2);
luaL_resetbuffer();
while (n-- > 0)
addnchar(s, l);
@@ -94,20 +89,20 @@ static void str_rep (void)
static void str_byte (void)
{
- long l;
- char *s = luaL_check_lstr(1, &l);
- long pos = posrelat((int)luaL_opt_number(2, 1), l);
+ int32 l;
+ const char *s = luaL_check_lstr(1, &l);
+ int32 pos = posrelat((int32)luaL_opt_number(2, 1), l);
luaL_arg_check(0<pos && pos<=l, 2, "out of range");
- lua_pushnumber((unsigned char)s[pos-1]);
+ lua_pushnumber((byte)s[pos-1]);
}
static void str_char (void) {
- int i = 0;
+ int32 i = 0;
luaL_resetbuffer();
while (lua_getparam(++i) != LUA_NOOBJECT) {
double c = luaL_check_number(i);
- luaL_arg_check((unsigned char)c == c, i, "invalid value");
- luaL_addchar((int)c);
+ luaL_arg_check((byte)c == c, i, "invalid value");
+ luaL_addchar((int32)c);
}
closeandpush();
}
@@ -122,11 +117,11 @@ static void str_char (void) {
#define MAX_CAPT 9
struct Capture {
- int level; /* total number of captures (finished or unfinished) */
- char *src_end; /* end ('\0') of source string */
+ int32 level; /* total number of captures (finished or unfinished) */
+ const char *src_end; /* end ('\0') of source string */
struct {
- char *init;
- int len; /* -1 signals unfinished capture */
+ const char *init;
+ int32 len; /* -1 signals unfinished capture */
} capture[MAX_CAPT];
};
@@ -137,13 +132,13 @@ struct Capture {
static void push_captures (struct Capture *cap)
{
- int i;
+ int32 i;
for (i=0; i<cap->level; i++)
lua_pushlstring(cap->capture[i].init, cap->capture[i].len);
}
-static int check_cap (int l, struct Capture *cap)
+static int32 check_cap (int32 l, struct Capture *cap)
{
l -= '1';
if (!(0 <= l && l < cap->level && cap->capture[l].len != -1))
@@ -152,9 +147,9 @@ static int check_cap (int l, struct Capture *cap)
}
-static int capture_to_close (struct Capture *cap)
+static int32 capture_to_close (struct Capture *cap)
{
- int level = cap->level;
+ int32 level = cap->level;
for (level--; level>=0; level--)
if (cap->capture[level].len == -1) return level;
lua_error("invalid pattern capture");
@@ -162,16 +157,16 @@ static int capture_to_close (struct Capture *cap)
}
-static char *bracket_end (char *p)
+static const char *bracket_end (const char *p)
{
return (*p == 0) ? NULL : strchr((*p=='^') ? p+2 : p+1, ']');
}
-static int matchclass (int c, int cl)
+static int32 matchclass (int32 c, int32 cl)
{
- int res;
- switch (tolower(cl)) {
+ int32 res;
+ switch (tolower((int)cl)) {
case 'a' : res = isalpha(c); break;
case 'c' : res = iscntrl(c); break;
case 'd' : res = isdigit(c); break;
@@ -183,11 +178,11 @@ static int matchclass (int c, int cl)
case 'z' : res = (c == '\0'); break;
default: return (cl == c);
}
- return (islower((unsigned char)cl) ? res : !res);
+ return (islower((byte)cl) ? res : !res);
}
-int luaI_singlematch (int c, char *p, char **ep)
+int32 luaI_singlematch (int32 c, const char *p, const char **ep)
{
switch (*p) {
case '.': /* matches any char */
@@ -200,38 +195,38 @@ int luaI_singlematch (int c, char *p, char **ep)
if (*(++p) == '\0')
luaL_verror("incorrect pattern (ends with `%c')", ESC);
*ep = p+1;
- return matchclass(c, (unsigned char)*p);
+ return matchclass(c, (byte)*p);
case '[': {
- char *end = bracket_end(p+1);
- int sig = *(p+1) == '^' ? (p++, 0) : 1;
+ const char *end = bracket_end(p+1);
+ int32 sig = *(p+1) == '^' ? (p++, 0) : 1;
if (end == NULL) lua_error("incorrect pattern (missing `]')");
*ep = end+1;
while (++p < end) {
if (*p == ESC) {
- if (((p+1) < end) && matchclass(c, (unsigned char)*++p))
+ if (((p+1) < end) && matchclass(c, (byte)*++p))
return sig;
}
else if ((*(p+1) == '-') && (p+2 < end)) {
p+=2;
- if ((unsigned char)*(p-2) <= c && c <= (unsigned char)*p)
+ if ((byte)*(p-2) <= c && c <= (byte)*p)
return sig;
}
- else if ((unsigned char)*p == c) return sig;
+ else if ((byte)*p == c) return sig;
}
return !sig;
}
default:
*ep = p+1;
- return ((unsigned char)*p == c);
+ return ((byte)*p == c);
}
}
-static char *matchbalance (char *s, int b, int e, struct Capture *cap)
+static const char *matchbalance (const char *s, int32 b, int32 e, struct Capture *cap)
{
if (*s != b) return NULL;
else {
- int cont = 1;
+ int32 cont = 1;
while (++s < cap->src_end) {
if (*s == e) {
if (--cont == 0) return s+1;
@@ -243,13 +238,13 @@ static char *matchbalance (char *s, int b, int e, struct Capture *cap)
}
-static char *matchitem (char *s, char *p, struct Capture *cap, char **ep)
+static const char *matchitem (const char *s, const char *p, struct Capture *cap, const char **ep)
{
if (*p == ESC) {
p++;
- if (isdigit((unsigned char)*p)) { /* capture */
- int l = check_cap(*p, cap);
- int len = cap->capture[l].len;
+ if (isdigit((byte)*p)) { /* capture */
+ int32 l = check_cap(*p, cap);
+ int32 len = cap->capture[l].len;
*ep = p+1;
if (cap->src_end-s >= len && memcmp(cap->capture[l].init, s, len) == 0)
return s+len;
@@ -265,17 +260,17 @@ static char *matchitem (char *s, char *p, struct Capture *cap, char **ep)
else p--; /* and go through */
}
/* "luaI_singlematch" sets "ep" (so must be called even when *s == 0) */
- return (luaI_singlematch((unsigned char)*s, p, ep) && s<cap->src_end) ?
+ return (luaI_singlematch((byte)*s, p, ep) && s<cap->src_end) ?
s+1 : NULL;
}
-static char *match (char *s, char *p, struct Capture *cap)
+static const char *match (const char *s, const char *p, struct Capture *cap)
{
init: /* using goto's to optimize tail recursion */
switch (*p) {
case '(': { /* start capture */
- char *res;
+ const char *res;
if (cap->level >= MAX_CAPT) lua_error("too many captures");
cap->capture[cap->level].init = s;
cap->capture[cap->level].len = -1;
@@ -285,8 +280,8 @@ static char *match (char *s, char *p, struct Capture *cap)
return res;
}
case ')': { /* end capture */
- int l = capture_to_close(cap);
- char *res;
+ int32 l = capture_to_close(cap);
+ const char *res;
cap->capture[l].len = s - cap->capture[l].init; /* close capture */
if ((res = match(s, p+1, cap)) == NULL) /* match failed? */
cap->capture[l].len = -1; /* undo capture */
@@ -297,23 +292,23 @@ static char *match (char *s, char *p, struct Capture *cap)
return s;
/* else go through */
default: { /* it is a pattern item */
- char *ep; /* get what is next */
- char *s1 = matchitem(s, p, cap, &ep);
+ const char *ep; /* get what is next */
+ const char *s1 = matchitem(s, p, cap, &ep);
switch (*ep) {
case '*': { /* repetition */
- char *res;
+ const char *res;
if (s1 && s1>s && ((res=match(s1, p, cap)) != NULL))
return res;
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
}
case '?': { /* optional */
- char *res;
+ const char *res;
if (s1 && ((res=match(s1, ep+1, cap)) != NULL))
return res;
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
}
case '-': { /* repetition */
- char *res;
+ const char *res;
if ((res = match(s, ep+1, cap)) != NULL)
return res;
else if (s1 && s1>s) {
@@ -334,15 +329,15 @@ static char *match (char *s, char *p, struct Capture *cap)
static void str_find (void)
{
- long l;
- char *s = luaL_check_lstr(1, &l);
- char *p = luaL_check_string(2);
- long init = posrelat((int)luaL_opt_number(3, 1), l) - 1;
+ int32 l;
+ const char *s = luaL_check_lstr(1, &l);
+ const char *p = luaL_check_string(2);
+ int32 init = posrelat((int32)luaL_opt_number(3, 1), l) - 1;
struct Capture cap;
luaL_arg_check(0 <= init && init <= l, 3, "out of range");
if (lua_getparam(4) != LUA_NOOBJECT ||
strpbrk(p, SPECIALS) == NULL) { /* no special characters? */
- char *s2 = strstr(s+init, p);
+ const char *s2 = strstr(s+init, p);
if (s2) {
lua_pushnumber(s2-s+1);
lua_pushnumber(s2-s+strlen(p));
@@ -350,11 +345,11 @@ static void str_find (void)
}
}
else {
- int anchor = (*p == '^') ? (p++, 1) : 0;
- char *s1=s+init;
+ int32 anchor = (*p == '^') ? (p++, 1) : 0;
+ const char *s1=s+init;
cap.src_end = s+l;
do {
- char *res;
+ const char *res;
cap.level = 0;
if ((res=match(s1, p, &cap)) != NULL) {
lua_pushnumber(s1-s+1); /* start */
@@ -371,18 +366,18 @@ static void str_find (void)
static void add_s (lua_Object newp, struct Capture *cap)
{
if (lua_isstring(newp)) {
- char *news = lua_getstring(newp);
- int l = lua_strlen(newp);
- int i;
+ const char *news = lua_getstring(newp);
+ int32 l = lua_strlen(newp);
+ int32 i;
for (i=0; i<l; i++) {
if (news[i] != ESC)
luaL_addchar(news[i]);
else {
i++; /* skip ESC */
- if (!isdigit((unsigned char)news[i]))
+ if (!isdigit((byte)news[i]))
luaL_addchar(news[i]);
else {
- int level = check_cap(news[i], cap);
+ int32 level = check_cap(news[i], cap);
addnchar(cap->capture[level].init, cap->capture[level].len);
}
}
@@ -390,8 +385,8 @@ static void add_s (lua_Object newp, struct Capture *cap)
}
else { /* is a function */
lua_Object res;
- int status;
- int oldbuff;
+ int32 status;
+ int32 oldbuff;
lua_beginblock();
push_captures(cap);
/* function may use buffer, so save it and create a new one */
@@ -413,20 +408,20 @@ static void add_s (lua_Object newp, struct Capture *cap)
static void str_gsub (void)
{
- long srcl;
- char *src = luaL_check_lstr(1, &srcl);
- char *p = luaL_check_string(2);
+ int32 srcl;
+ const char *src = luaL_check_lstr(1, &srcl);
+ const char *p = luaL_check_string(2);
lua_Object newp = lua_getparam(3);
- int max_s = (int)luaL_opt_number(4, srcl+1);
- int anchor = (*p == '^') ? (p++, 1) : 0;
- int n = 0;
+ int32 max_s = (int32)luaL_opt_number(4, srcl+1);
+ int32 anchor = (*p == '^') ? (p++, 1) : 0;
+ int32 n = 0;
struct Capture cap;
luaL_arg_check(lua_isstring(newp) || lua_isfunction(newp), 3,
"string or function expected");
luaL_resetbuffer();
cap.src_end = src+srcl;
while (n < max_s) {
- char *e;
+ const char *e;
cap.level = 0;
e = match(src, p, &cap);
if (e) {
@@ -446,7 +441,7 @@ static void str_gsub (void)
}
-static void luaI_addquoted (char *s)
+static void luaI_addquoted (const char *s)
{
luaL_addchar('"');
for (; *s; s++) {
@@ -461,8 +456,8 @@ static void luaI_addquoted (char *s)
static void str_format (void)
{
- int arg = 1;
- char *strfrmt = luaL_check_string(arg);
+ int32 arg = 1;
+ const char *strfrmt = luaL_check_string(arg);
struct Capture cap;
cap.src_end = strfrmt+strlen(strfrmt)+1;
luaL_resetbuffer();
@@ -474,10 +469,10 @@ static void str_format (void)
else { /* format item */
char form[MAX_FORMAT]; /* store the format ('%...') */
char *buff;
- char *initf = strfrmt;
+ const char *initf = strfrmt;
form[0] = '%';
cap.level = 0;
- if (isdigit((unsigned char)initf[0]) && initf[1] == '$') {
+ if (isdigit((byte)initf[0]) && initf[1] == '$') {
arg = initf[0] - '0';
initf += 2; /* skip the 'n$' */
}
@@ -493,7 +488,7 @@ static void str_format (void)
luaI_addquoted(luaL_check_string(arg));
continue;
case 's': {
- char *s = luaL_check_string(arg);
+ const char *s = luaL_check_string(arg);
buff = luaL_openspace(strlen(s));
sprintf(buff, form, s);
break;
diff --git a/tools/lua/ltable.cpp b/tools/lua/ltable.cpp
index bf90162a3..6e6847f73 100644
--- a/tools/lua/ltable.cpp
+++ b/tools/lua/ltable.cpp
@@ -1,17 +1,17 @@
/*
-** $Id$
+** $Id: ltable.cpp 905 2008-07-20 21:08:22Z aquadran $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
#include <stdlib.h>
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/ltable.h>
-#include <tools/lua/lua.h>
+#include "lauxlib.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lstate.h"
+#include "ltable.h"
+#include "lua.h"
#define gcsize(n) (1+(n/16))
@@ -29,19 +29,44 @@
static long int hashindex (TObject *ref)
{
long int h;
+ switch (ttype(ref)) {
+ case LUA_T_NUMBER:
+ h = (long int)nvalue(ref);
+ break;
+ case LUA_T_STRING: case LUA_T_USERDATA:
+ h = (IntPoint)tsvalue(ref);
+ break;
+ case LUA_T_ARRAY:
+ h = (IntPoint)avalue(ref);
+ break;
+ case LUA_T_PROTO:
+ h = (IntPoint)tfvalue(ref);
+ break;
+ case LUA_T_CPROTO:
+ h = (IntPoint)fvalue(ref);
+ break;
+ case LUA_T_CLOSURE:
+ h = (IntPoint)clvalue(ref);
+ break;
+ case LUA_T_TASK:
+ h = (long int)nvalue(ref);
+ break;
+ default:
+ lua_error("unexpected type to index table");
h = 0; /* to avoid warnings */
+ }
return (h >= 0 ? h : -(h+1));
}
-int present (Hash *t, TObject *key)
+int32 present (Hash *t, TObject *key)
{
- int tsize = nhash(t);
+ int32 tsize = nhash(t);
long int h = hashindex(key);
- int h1 = h%tsize;
+ int32 h1 = h%tsize;
TObject *rf = ref(node(t, h1));
if (ttype(rf) != LUA_T_NIL && !luaO_equalObj(key, rf)) {
- int h2 = h%(tsize-2) + 1;
+ int32 h2 = h%(tsize-2) + 1;
do {
h1 += h2;
if (h1 >= tsize) h1 -= tsize;
@@ -55,10 +80,10 @@ int present (Hash *t, TObject *key)
/*
** Alloc a vector node
*/
-Node *hashnodecreate (int nhash)
+Node *hashnodecreate (int32 nhash)
{
Node *v = luaM_newvector(nhash, Node);
- int i;
+ int32 i;
for (i=0; i<nhash; i++)
ttype(ref(&v[i])) = LUA_T_NIL;
return v;
@@ -85,10 +110,10 @@ void luaH_free (Hash *frees)
}
-Hash *luaH_new (int nhash)
+Hash *luaH_new (int32 nhash)
{
Hash *t = luaM_new(Hash);
- nhash = luaO_redimension((int)((float)nhash/REHASH_LIMIT));
+ nhash = luaO_redimension((int32)((float)nhash/REHASH_LIMIT));
nodevector(t) = hashnodecreate(nhash);
nhash(t) = nhash;
nuse(t) = 0;
@@ -99,12 +124,12 @@ Hash *luaH_new (int nhash)
}
-static int newsize (Hash *t)
+static int32 newsize (Hash *t)
{
Node *v = t->node;
- int size = nhash(t);
- int realuse = 0;
- int i;
+ int32 size = nhash(t);
+ int32 realuse = 0;
+ int32 i;
for (i=0; i<size; i++) {
if (ttype(ref(v+i)) != LUA_T_NIL && ttype(val(v+i)) != LUA_T_NIL)
realuse++;
@@ -117,10 +142,10 @@ static int newsize (Hash *t)
static void rehash (Hash *t)
{
- int nold = nhash(t);
+ int32 nold = nhash(t);
Node *vold = nodevector(t);
- int nnew = newsize(t);
- int i;
+ int32 nnew = newsize(t);
+ int32 i;
nodevector(t) = hashnodecreate(nnew);
nhash(t) = nnew;
for (i=0; i<nold; i++) {
@@ -138,7 +163,7 @@ static void rehash (Hash *t)
*/
TObject *luaH_get (Hash *t, TObject *ref)
{
- int h = present(t, ref);
+ int32 h = present(t, ref);
if (ttype(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
else return NULL;
}
@@ -164,10 +189,10 @@ TObject *luaH_set (Hash *t, TObject *ref)
}
-static Node *hashnext (Hash *t, int i)
+static Node *hashnext (Hash *t, int32 i)
{
Node *n;
- int tsize = nhash(t);
+ int32 tsize = nhash(t);
if (i >= tsize)
return NULL;
n = node(t, i);
@@ -185,7 +210,7 @@ Node *luaH_next (TObject *o, TObject *r)
if (ttype(r) == LUA_T_NIL)
return hashnext(t, 0);
else {
- int i = present(t, r);
+ int32 i = present(t, r);
Node *n = node(t, i);
luaL_arg_check(ttype(ref(n))!=LUA_T_NIL && ttype(val(n))!=LUA_T_NIL,
2, "key not found");
diff --git a/tools/lua/ltable.h b/tools/lua/ltable.h
index 38aed7a52..02b4b54c7 100644
--- a/tools/lua/ltable.h
+++ b/tools/lua/ltable.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: ltable.h 905 2008-07-20 21:08:22Z aquadran $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -7,7 +7,7 @@
#ifndef ltable_h
#define ltable_h
-#include <tools/lua/lobject.h>
+#include "lobject.h"
#define node(t,i) (&(t)->node[i])
@@ -15,12 +15,12 @@
#define val(n) (&(n)->val)
#define nhash(t) ((t)->nhash)
-Hash *luaH_new (int nhash);
+Hash *luaH_new (int32 nhash);
void luaH_free (Hash *frees);
TObject *luaH_get (Hash *t, TObject *ref);
TObject *luaH_set (Hash *t, TObject *ref);
Node *luaH_next (TObject *o, TObject *r);
-Node *hashnodecreate (int nhash);
-int present (Hash *t, TObject *key);
+Node *hashnodecreate (int32 nhash);
+int32 present (Hash *t, TObject *key);
#endif
diff --git a/tools/lua/ltask.cpp b/tools/lua/ltask.cpp
index abfd672e5..2757dd006 100644
--- a/tools/lua/ltask.cpp
+++ b/tools/lua/ltask.cpp
@@ -1,18 +1,17 @@
#include <stdlib.h>
#include <stdio.h>
-#include <search.h>
-#include <tools/lua/ltask.h>
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/ldo.h>
-#include <tools/lua/lvm.h>
+#include "ltask.h"
+#include "lauxlib.h"
+#include "lmem.h"
+#include "ldo.h"
+#include "lvm.h"
void pause_scripts (void) {
struct lua_Task *t;
for (t = L->root_task->next; t != NULL; t = t->next) {
- if (t->Tstate != DONE)
+ if ((L->curr_task != t) && (t->Tstate != DONE))
t->Tstate = PAUSE;
}
}
@@ -21,7 +20,7 @@ void unpause_scripts (void) {
struct lua_Task *t;
for (t = L->root_task->next; t != NULL; t = t->next) {
- if (t->Tstate == PAUSE)
+ if ((L->curr_task != t) && (t->Tstate != DONE))
t->Tstate = YIELD;
}
}
@@ -33,6 +32,11 @@ void start_script (void) {
f = L->stack.stack + L->Cstack.lua2C;
if (ttype(f) == LUA_T_CLOSURE)
f = &clvalue(f)->consts[0];
+ // Start nothing? start_script gets called in this fashion
+ // by the scene in the scrimshaw parlor, if we just return
+ // immediately the game proceeds ok.
+ if (ttype(f) == LUA_T_NIL)
+ return;
if (ttype(f) != LUA_T_PROTO)
lua_error("can only start_script with a Lua function");
@@ -40,7 +44,7 @@ void start_script (void) {
new_task = luaI_newtask();
/* Put the function and arguments onto the new task's stack */
- for (int i = 0; i < old_task->Cstack.num; i++) {
+ for (int32 i = 0; i < old_task->Cstack.num; i++) {
*(L->stack.top) = *(old_task->stack.stack + old_task->Cstack.lua2C + i);
incr_top;
}
@@ -67,7 +71,7 @@ void start_script (void) {
void stop_script (void) {
struct lua_Task *prev, *t;
TObject *f = L->stack.stack + L->Cstack.lua2C;
- int match;
+ int32 match = 0;
if ((f == LUA_NOOBJECT) || (ttype(f) != LUA_T_CLOSURE && ttype(f) != LUA_T_PROTO && ttype(f) != LUA_T_TASK))
lua_error("Bad argument to stop_script");
@@ -82,7 +86,7 @@ void stop_script (void) {
match = (ttype(t->stack.stack) == LUA_T_PMARK && tfvalue(t->stack.stack) == tfvalue(f));
break;
case LUA_T_TASK:
- match = (t->id == (int)nvalue(f));
+ match = (t->id == (int32)nvalue(f));
break;
default: /* Shut up gcc */
break;
@@ -106,7 +110,7 @@ void stop_script (void) {
}
void next_script (void) {
- struct lua_Task *t, *prev;
+ struct lua_Task *t = NULL, *prev;
TObject *f = L->stack.stack + L->Cstack.lua2C;
if (f == LUA_NOOBJECT)
@@ -116,7 +120,7 @@ void next_script (void) {
if (ttype(f) == LUA_T_NIL) {
t = L->root_task;
} else if (ttype(f) == LUA_T_TASK) {
- int taskId = (int)nvalue(f);
+ int32 taskId = (int32)nvalue(f);
for (t = L->root_task->next; t != NULL; t = t->next) {
if (t->id == taskId)
break;
@@ -146,24 +150,24 @@ void identify_script (void) {
lua_error("Bad argument to identify_script");
}
- int taskId = (int)nvalue(f);
+ int32 taskId = (int32)nvalue(f);
for (t = L->root_task->next; t != NULL; t = t->next) {
- if (t->id == taskId)
- break;
- }
-
- if ((t == NULL) || (t->Tstate == DONE)) {
- ttype(L->stack.top) = LUA_T_NIL;
- } else {
- *L->stack.top = *t->stack.stack;
- }
- incr_top;
+ if (t->id == taskId)
+ break;
+ }
+
+ if ((t == NULL) || (t->Tstate == DONE)) {
+ ttype(L->stack.top) = LUA_T_NIL;
+ } else {
+ *L->stack.top = *t->stack.stack;
+ }
+ incr_top;
}
void find_script (void) {
- struct lua_Task *t, *foundTask = NULL;
+ struct lua_Task *t = NULL, *foundTask = NULL;
TObject *f = L->stack.stack + L->Cstack.lua2C;
- int countTasks = 0, taskId;
+ int32 countTasks = 0, taskId;
switch (ttype(f)) {
case LUA_T_CLOSURE:
@@ -185,7 +189,7 @@ void find_script (void) {
t = foundTask;
break;
case LUA_T_TASK:
- taskId = (int)nvalue(f);
+ taskId = (int32)nvalue(f);
for (t = L->root_task->next; t != NULL; t = t->next) {
if ((t->id == taskId) && (t->Tstate != DONE)) {
ttype(L->stack.top) = LUA_T_TASK;
@@ -242,9 +246,12 @@ void lua_runtasks (void) {
prev = L->root_task;
while ((t = prev->next) != NULL) {
- if (t->Tstate == PAUSE)
- continue;
luaI_switchtask(t);
+ // Tstate is not available until after switching tasks
+ if (t->Tstate == PAUSE) {
+ prev = t;
+ continue;
+ }
L->errorJmp = &myErrorJmp;
L->Tstate = RUN;
if (setjmp(myErrorJmp) == 0) {
@@ -256,7 +263,17 @@ void lua_runtasks (void) {
L->Tstate = DONE;
}
L->errorJmp = NULL;
- if (L->Tstate == DONE) { /* Remove from list of active tasks */
+ prev = t;
+ }
+ // Free the completed tasks
+ // This MUST occur after all the tasks have been run (not during)
+ // or else when one task is freed right after another the task
+ // execution gets hosed. Test Case: Switching between tw.set and
+ // tb.set in Rubacava causes a crash without this.
+ prev = L->root_task;
+ while ((t = prev->next) != NULL) {
+ luaI_switchtask(t);
+ if (L->Tstate == DONE) { // Remove from list of active tasks
luaI_switchtask(old_task);
prev->next = t->next;
t->next = NULL;
diff --git a/tools/lua/ltask.h b/tools/lua/ltask.h
index 4742f3b4c..730343f6f 100644
--- a/tools/lua/ltask.h
+++ b/tools/lua/ltask.h
@@ -1,10 +1,10 @@
#ifndef ltask_h
#define ltask_h
-#include <tools/lua/lua.h>
-#include <tools/lua/lstate.h>
+#include "lua.h"
+#include "lstate.h"
-extern int task_tag;
+extern int32 task_tag;
void start_script (void);
void stop_script (void);
diff --git a/tools/lua/ltm.cpp b/tools/lua/ltm.cpp
index 58d68e930..bbb5bab1a 100644
--- a/tools/lua/ltm.cpp
+++ b/tools/lua/ltm.cpp
@@ -1,31 +1,27 @@
/*
-** $Id$
+** $Id: ltm.cpp 913 2008-07-22 12:58:04Z aquadran $
** Tag methods
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+#include "lauxlib.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lstate.h"
+#include "ltm.h"
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/ltm.h>
-
-char *luaT_eventname[] = { /* ORDER IM */
+const char *luaT_eventname[] = { /* ORDER IM */
"gettable", "settable", "index", "getglobal", "setglobal", "add",
"sub", "mul", "div", "pow", "unm", "lt", "le", "gt", "ge",
"concat", "gc", "function", NULL
};
-static int luaI_checkevent (char *name, char *list[])
+static int32 luaI_checkevent (const char *name, const char *list[])
{
- int e = luaL_findstring(name, list);
+ int32 e = luaL_findstring(name, list);
if (e < 0)
luaL_verror("`%.50s' is not a valid event name", name);
return e;
@@ -48,15 +44,15 @@ static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */
};
-static int validevent (int t, int e)
+static int32 validevent (int32 t, int32 e)
{ /* ORDER LUA_T */
return (t < LUA_T_NIL) ? 1 : validevents[-t][e];
}
-static void init_entry (int tag)
+static void init_entry (int32 tag)
{
- int i;
+ int32 i;
for (i=0; i<IM_N; i++)
ttype(luaT_getim(tag, i)) = LUA_T_NIL;
}
@@ -64,16 +60,16 @@ static void init_entry (int tag)
void luaT_init (void)
{
- int t;
+ int32 t;
L->IMtable_size = NUM_TAGS*2;
L->last_tag = -(NUM_TAGS-1);
L->IMtable = luaM_newvector(L->IMtable_size, struct IM);
- for (t=L->last_tag; t<=0; t++)
+ for (t=-(L->IMtable_size-1); t<=0; t++)
init_entry(t);
}
-int lua_newtag (void)
+int32 lua_newtag (void)
{
--L->last_tag;
if ((-L->last_tag) >= L->IMtable_size)
@@ -84,22 +80,22 @@ int lua_newtag (void)
}
-static void checktag (int tag)
+static void checktag (int32 tag)
{
if (!(L->last_tag <= tag && tag <= 0))
luaL_verror("%d is not a valid tag", tag);
}
-void luaT_realtag (int tag)
+void luaT_realtag (int32 tag)
{
if (!(L->last_tag <= tag && tag < LUA_T_NIL))
luaL_verror("tag %d is not result of `newtag'", tag);
}
-int lua_copytagmethods (int tagto, int tagfrom)
+int32 lua_copytagmethods (int32 tagto, int32 tagfrom)
{
- int e;
+ int32 e;
checktag(tagto);
checktag(tagfrom);
for (e=0; e<IM_N; e++) {
@@ -110,14 +106,14 @@ int lua_copytagmethods (int tagto, int tagfrom)
}
-int luaT_efectivetag (TObject *o)
+int32 luaT_efectivetag (TObject *o)
{
- int t;
+ int32 t;
switch (t = ttype(o)) {
case LUA_T_ARRAY:
return o->value.a->htag;
case LUA_T_USERDATA: {
- int tag = o->value.ts->u.d.tag;
+ int32 tag = o->value.ts->u.d.tag;
return (tag >= 0) ? LUA_T_USERDATA : tag;
}
case LUA_T_CLOSURE:
@@ -133,9 +129,9 @@ int luaT_efectivetag (TObject *o)
}
-TObject *luaT_gettagmethod (int t, char *event)
+TObject *luaT_gettagmethod (int32 t, const char *event)
{
- int e = luaI_checkevent(event, luaT_eventname);
+ int32 e = luaI_checkevent(event, luaT_eventname);
checktag(t);
if (validevent(t, e))
return luaT_getim(t,e);
@@ -144,10 +140,10 @@ TObject *luaT_gettagmethod (int t, char *event)
}
-void luaT_settagmethod (int t, char *event, TObject *func)
+void luaT_settagmethod (int32 t, const char *event, TObject *func)
{
TObject temp = *func;
- int e = luaI_checkevent(event, luaT_eventname);
+ int32 e = luaI_checkevent(event, luaT_eventname);
checktag(t);
if (!validevent(t, e))
luaL_verror("settagmethod: cannot change tag method `%.20s' for tag %d",
@@ -157,13 +153,13 @@ void luaT_settagmethod (int t, char *event, TObject *func)
}
-char *luaT_travtagmethods (int (*fn)(TObject *))
+const char *luaT_travtagmethods (int32 (*fn)(TObject *))
{
- int e;
+ int32 e;
if (fn(&L->errorim))
return "error";
for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */
- int t;
+ int32 t;
for (t=0; t>=L->last_tag; t--)
if (fn(luaT_getim(t,e)))
return luaT_eventname[e];
@@ -178,7 +174,7 @@ char *luaT_travtagmethods (int (*fn)(TObject *))
*/
#ifdef LUA_COMPAT2_5
-#include <tools/lua/lapi.h>
+#include "lapi.h"
void errorFB (void)
{
@@ -201,7 +197,7 @@ void typeFB (void)
static void fillvalids (IMS e, TObject *func)
{
- int t;
+ int32 t;
for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++)
if (validevent(t, e))
*luaT_getim(t, e) = *func;
@@ -228,7 +224,7 @@ void luaT_setfallback (void)
replace = nilFB;
break;
case 2: { /* old arith fallback */
- int i;
+ int32 i;
oldfunc = *luaT_getim(LUA_T_NUMBER, IM_POW);
for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */
fillvalids(i, luaA_Address(func));
@@ -236,7 +232,7 @@ void luaT_setfallback (void)
break;
}
case 3: { /* old order fallback */
- int i;
+ int32 i;
oldfunc = *luaT_getim(LUA_T_NIL, IM_LT);
for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */
fillvalids(i, luaA_Address(func));
@@ -244,7 +240,7 @@ void luaT_setfallback (void)
break;
}
default: {
- int e;
+ int32 e;
if ((e = luaL_findstring(name, luaT_eventname)) >= 0) {
oldfunc = *luaT_getim(LUA_T_NIL, e);
fillvalids(e, luaA_Address(func));
diff --git a/tools/lua/ltm.h b/tools/lua/ltm.h
index 36b7cfa20..bbecfd1ec 100644
--- a/tools/lua/ltm.h
+++ b/tools/lua/ltm.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: ltm.h 905 2008-07-20 21:08:22Z aquadran $
** Tag methods
** See Copyright Notice in lua.h
*/
@@ -8,8 +8,8 @@
#define ltm_h
-#include <tools/lua/lobject.h>
-#include <tools/lua/lstate.h>
+#include "lobject.h"
+#include "lstate.h"
/*
* WARNING: if you change the order of this enumeration,
@@ -35,7 +35,7 @@ typedef enum {
IM_GC,
IM_FUNCTION
} eIMS;
-typedef int IMS;
+typedef int32 IMS;
#define IM_N 18
@@ -48,15 +48,15 @@ struct IM {
#define luaT_getim(tag,event) (&L->IMtable[-(tag)].int_method[event])
#define luaT_getimbyObj(o,e) (luaT_getim(luaT_efectivetag(o),(e)))
-extern char *luaT_eventname[];
+extern const char *luaT_eventname[];
void luaT_init (void);
-void luaT_realtag (int tag);
-int luaT_efectivetag (TObject *o);
-void luaT_settagmethod (int t, char *event, TObject *func);
-TObject *luaT_gettagmethod (int t, char *event);
-char *luaT_travtagmethods (int (*fn)(TObject *));
+void luaT_realtag (int32 tag);
+int32 luaT_efectivetag (TObject *o);
+void luaT_settagmethod (int32 t, const char *event, TObject *func);
+TObject *luaT_gettagmethod (int32 t, const char *event);
+const char *luaT_travtagmethods (int32 (*fn)(TObject *));
void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */
diff --git a/tools/lua/lua.h b/tools/lua/lua.h
index 754077184..b32cb98e6 100644
--- a/tools/lua/lua.h
+++ b/tools/lua/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lua.h 922 2008-07-25 22:21:04Z aquadran $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua at tecgraf.puc-rio.br
@@ -7,6 +7,7 @@
** See Copyright Notice at the end of this file
*/
+#include "common/sys.h"
#ifndef lua_h
#define lua_h
@@ -15,25 +16,38 @@
#define LUA_COPYRIGHT "Copyright (C) 1994-1998 TeCGraf, PUC-Rio"
#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
-
#define LUA_NOOBJECT 0
#define LUA_ANYTAG (-1)
-typedef void (*lua_CFunction) (void);
-typedef unsigned int lua_Object;
+typedef void (*lua_CFunction)(void);
+typedef uint32 lua_Object;
typedef struct lua_State lua_State;
extern lua_State *lua_state;
-typedef void (*SaveRestoreFunc)(void *, int);
-typedef int (*SaveRestoreCallback)(int, int, SaveRestoreFunc);
+struct PointerId {
+ uint32 low;
+ uint32 hi;
+};
+
+PointerId makeIdFromPointer(void *ptr);
+void *makePointerFromId(PointerId ptr);
+
+typedef void (*SaveStream)(void *, int32);
+typedef void (*SaveSint32)(int32);
+typedef void (*SaveUint32)(uint32);
+typedef void (*RestoreStream)(void *, int32);
+typedef int32 (*RestoreSint32)();
+typedef uint32 (*RestoreUint32)();
+typedef PointerId (*SaveCallback)(int32, PointerId, SaveSint32);
+typedef PointerId (*RestoreCallback)(int32, PointerId, RestoreSint32);
-extern SaveRestoreCallback saveCallback;
-extern SaveRestoreCallback restoreCallback;
+extern SaveCallback saveCallbackPtr;
+extern RestoreCallback restoreCallbackPtr;
-void lua_Save(SaveRestoreFunc);
-void lua_Restore(SaveRestoreFunc);
+void lua_Save(SaveStream, SaveSint32, SaveUint32);
+void lua_Restore(RestoreStream, RestoreSint32, RestoreUint32);
void lua_removelibslists(void);
@@ -41,74 +55,74 @@ void lua_open (void);
void lua_close (void);
lua_State *lua_setstate (lua_State *st);
-lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
-lua_Object lua_gettagmethod (int tag, char *event);
+lua_Object lua_settagmethod (int32 tag, const char *event); /* In: new method */
+lua_Object lua_gettagmethod (int32 tag, const char *event);
lua_Object lua_seterrormethod (void); /* In: new method */
-int lua_newtag (void);
-int lua_copytagmethods (int tagto, int tagfrom);
-void lua_settag (int tag); /* In: object */
+int32 lua_newtag (void);
+int32 lua_copytagmethods (int32 tagto, int32 tagfrom);
+void lua_settag (int32 tag); /* In: object */
-void lua_error (char *s);
-int lua_dofile (char *filename); /* Out: returns */
-int lua_dostring (char *string); /* Out: returns */
-int lua_dobuffer (char *buff, int size, char *name);
+void lua_error (const char *s);
+int32 lua_dofile (const char *filename); /* Out: returns */
+int32 lua_dostring (const char *string); /* Out: returns */
+int32 lua_dobuffer (const char *buff, int32 size, const char *name);
/* Out: returns */
-int lua_callfunction (lua_Object f);
+int32 lua_callfunction (lua_Object f);
/* In: parameters; Out: returns */
void lua_beginblock (void);
void lua_endblock (void);
-lua_Object lua_lua2C (int number);
+lua_Object lua_lua2C (int32 number);
#define lua_getparam(_) lua_lua2C(_)
#define lua_getresult(_) lua_lua2C(_)
-int lua_isnil (lua_Object object);
-int lua_istable (lua_Object object);
-int lua_isuserdata (lua_Object object);
-int lua_iscfunction (lua_Object object);
-int lua_isnumber (lua_Object object);
-int lua_isstring (lua_Object object);
-int lua_isfunction (lua_Object object);
+int32 lua_isnil (lua_Object object);
+int32 lua_istable (lua_Object object);
+int32 lua_isuserdata (lua_Object object);
+int32 lua_iscfunction (lua_Object object);
+int32 lua_isnumber (lua_Object object);
+int32 lua_isstring (lua_Object object);
+int32 lua_isfunction (lua_Object object);
double lua_getnumber (lua_Object object);
-char *lua_getstring (lua_Object object);
-long lua_strlen (lua_Object object);
+const char *lua_getstring (lua_Object object);
+int32 lua_strlen (lua_Object object);
lua_CFunction lua_getcfunction (lua_Object object);
void *lua_getuserdata (lua_Object object);
void lua_pushnil (void);
void lua_pushnumber (double n);
-void lua_pushlstring (char *s, long len);
-void lua_pushstring (char *s);
-void lua_pushcclosure (lua_CFunction fn, int n);
-void lua_pushusertag (void *u, int tag);
+void lua_pushlstring (const char *s, int32 len);
+void lua_pushstring (const char *s);
+void lua_pushcclosure (lua_CFunction fn, int32 n);
+void lua_pushusertag (void *u, int32 tag);
void lua_pushobject (lua_Object object);
lua_Object lua_pop (void);
-lua_Object lua_getglobal (char *name);
-lua_Object lua_rawgetglobal (char *name);
-void lua_setglobal (char *name); /* In: value */
-void lua_rawsetglobal (char *name); /* In: value */
+lua_Object lua_getglobal (const char *name);
+lua_Object lua_rawgetglobal (const char *name);
+void lua_setglobal (const char *name); /* In: value */
+void lua_rawsetglobal (const char *name); /* In: value */
void lua_settable (void); /* In: table, index, value */
void lua_rawsettable (void); /* In: table, index, value */
lua_Object lua_gettable (void); /* In: table, index */
lua_Object lua_rawgettable (void); /* In: table, index */
-int lua_tag (lua_Object object);
+int32 lua_tag (lua_Object object);
-int lua_ref (int lock); /* In: value */
-lua_Object lua_getref (int ref);
-void lua_unref (int ref);
+int32 lua_ref (int32 lock); /* In: value */
+lua_Object lua_getref (int32 ref);
+void lua_unref (int32 ref);
lua_Object lua_createtable (void);
-long lua_collectgarbage (long limit);
+int32 lua_collectgarbage (int32 limit);
void lua_runtasks (void);
@@ -117,13 +131,13 @@ void current_script (void);
/* =============================================================== */
/* some useful macros/derived functions */
-int (lua_call) (char *name);
+int32 (lua_call) (char *name);
#define lua_call(name) lua_callfunction(lua_getglobal(name))
-void (lua_pushref) (int ref);
+void (lua_pushref) (int32 ref);
#define lua_pushref(ref) lua_pushobject(lua_getref(ref))
-int (lua_refobject) (lua_Object o, int l);
+int32 (lua_refobject) (lua_Object o, int32 l);
#define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
void (lua_register) (char *n, lua_CFunction f);
@@ -135,7 +149,7 @@ void (lua_pushuserdata) (void *u);
void (lua_pushcfunction) (lua_CFunction f);
#define lua_pushcfunction(f) lua_pushcclosure(f, 0)
-int (lua_clonetag) (int t);
+int32 (lua_clonetag) (int32 t);
#define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
@@ -177,23 +191,23 @@ lua_Object lua_setfallback (char *event, lua_CFunction fallback);
/******************************************************************************
* Copyright (c) 1994-1998 TeCGraf, PUC-Rio. All rights reserved.
-*
+*
* Permission is hereby granted, without written agreement and without license
* or royalty fees, to use, copy, modify, and distribute this software and its
* documentation for any purpose, including commercial applications, subject to
* the following conditions:
-*
+*
* - The above copyright notice and this permission notice shall appear in all
* copies or substantial portions of this software.
-*
+*
* - 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 greatly
* appreciated (but it is not required).
-*
+*
* - Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
-*
+*
* The authors specifically disclaim any warranties, including, but not limited
* to, the implied warranties of merchantability and fitness for a particular
* purpose. The software provided hereunder is on an "as is" basis, and the
@@ -202,7 +216,7 @@ lua_Object lua_setfallback (char *event, lua_CFunction fallback);
* authors be held liable to any party for direct, indirect, special,
* incidental, or consequential damages arising out of the use of this software
* and its documentation.
-*
+*
* The Lua language and this implementation have been entirely designed and
* written by Waldemar Celes Filho, Roberto Ierusalimschy and
* Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
diff --git a/tools/lua/luadebug.h b/tools/lua/luadebug.h
index 442bf4053..54cac1b58 100644
--- a/tools/lua/luadebug.h
+++ b/tools/lua/luadebug.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: luadebug.h 905 2008-07-20 21:08:22Z aquadran $
** Debugging API
** See Copyright Notice in lua.h
*/
@@ -9,25 +9,25 @@
#define luadebug_h
-#include <tools/lua/lua.h>
+#include "lua.h"
typedef lua_Object lua_Function;
-typedef void (*lua_LHFunction) (int line);
-typedef void (*lua_CHFunction) (lua_Function func, char *file, int line);
+typedef void (*lua_LHFunction) (int32 line);
+typedef void (*lua_CHFunction) (lua_Function func, const char *file, int32 line);
-lua_Function lua_stackedfunction (int level);
-void lua_funcinfo (lua_Object func, char **filename, int *linedefined);
-int lua_currentline (lua_Function func);
-char *lua_getobjname (lua_Object o, char **name);
+lua_Function lua_stackedfunction (int32 level);
+void lua_funcinfo (lua_Object func, const char **filename, int32 *linedefined);
+int32 lua_currentline (lua_Function func);
+const char *lua_getobjname (lua_Object o, const char **name);
-lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
-int lua_setlocal (lua_Function func, int local_number);
+lua_Object lua_getlocal (lua_Function func, int32 local_number, char **name);
+int32 lua_setlocal (lua_Function func, int32 local_number);
extern lua_LHFunction lua_linehook;
extern lua_CHFunction lua_callhook;
-extern int lua_debug;
+extern int32 lua_debug;
#endif
diff --git a/tools/lua/lualib.h b/tools/lua/lualib.h
index c48465933..62ab6fa90 100644
--- a/tools/lua/lualib.h
+++ b/tools/lua/lualib.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lualib.h 905 2008-07-20 21:08:22Z aquadran $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
@@ -8,7 +8,7 @@
#ifndef lualib_h
#define lualib_h
-#include <tools/lua/lua.h>
+#include "lua.h"
void lua_iolibopen (void);
@@ -28,7 +28,7 @@ void lua_mathlibopen (void);
/* Auxiliary functions (private) */
-int luaI_singlematch (int c, char *p, char **ep);
+int32 luaI_singlematch (int32 c, const char *p, const char **ep);
#endif
diff --git a/tools/lua/lundump.cpp b/tools/lua/lundump.cpp
index f46327cfc..b2cad6e83 100644
--- a/tools/lua/lundump.cpp
+++ b/tools/lua/lundump.cpp
@@ -1,17 +1,14 @@
/*
-** $Id$
+** $Id: lundump.cpp 905 2008-07-20 21:08:22Z aquadran $
** load bytecodes from files
** See Copyright Notice in lua.h
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/lundump.h>
+#include "lauxlib.h"
+#include "lfunc.h"
+#include "lmem.h"
+#include "lstring.h"
+#include "lundump.h"
#define LoadBlock(b,size,Z) ezread(Z,b,size)
#define LoadNative(t,Z) LoadBlock(&t,sizeof(t),Z)
@@ -20,8 +17,8 @@
static float conv_float(const char *data) {
- const unsigned char *udata = (const unsigned char *)(data);
- unsigned char fdata[4];
+ const byte *udata = (const byte *)(data);
+ byte fdata[4];
fdata[0] = udata[3];
fdata[1] = udata[2];
fdata[2] = udata[1];
@@ -34,43 +31,43 @@ static void unexpectedEOZ(ZIO* Z)
luaL_verror("unexpected end of file in %s",zname(Z));
}
-static int ezgetc(ZIO* Z)
+static int32 ezgetc(ZIO* Z)
{
- int c=zgetc(Z);
+ int32 c=zgetc(Z);
if (c==EOZ) unexpectedEOZ(Z);
return c;
}
-static void ezread(ZIO* Z, void* b, int n)
+static void ezread(ZIO* Z, void* b, int32 n)
{
- int r=zread(Z,b,n);
+ int32 r=zread(Z,b,n);
if (r!=0) unexpectedEOZ(Z);
}
-static unsigned int LoadWord(ZIO* Z)
+static uint16 LoadWord(ZIO* Z)
{
- unsigned int hi=ezgetc(Z);
- unsigned int lo=ezgetc(Z);
+ uint16 hi=ezgetc(Z);
+ uint16 lo=ezgetc(Z);
return (hi<<8)|lo;
}
-static unsigned long LoadLong(ZIO* Z)
+static uint32 LoadLong(ZIO* Z)
{
- unsigned long hi=LoadWord(Z);
- unsigned long lo=LoadWord(Z);
+ uint32 hi=LoadWord(Z);
+ uint32 lo=LoadWord(Z);
return (hi<<16)|lo;
}
static float LoadFloat(ZIO* Z)
{
- unsigned long l=LoadLong(Z);
+ uint32 l=LoadLong(Z);
return conv_float((const char *)&l);
}
static Byte* LoadCode(ZIO* Z)
{
- unsigned long size=LoadLong(Z);
- unsigned int s=size;
+ int32 size=LoadLong(Z);
+ int32 s=size;
void* b;
if (s!=size) luaL_verror("code too long (%ld bytes) in %s",size,zname(Z));
b=luaM_malloc(size);
@@ -80,8 +77,8 @@ static Byte* LoadCode(ZIO* Z)
static TaggedString* LoadTString(ZIO* Z)
{
- int size=LoadWord(Z);
- int i;
+ int32 size=LoadWord(Z);
+ int32 i;
if (size==0)
return NULL;
else
@@ -96,7 +93,7 @@ static TaggedString* LoadTString(ZIO* Z)
static void LoadLocals(TProtoFunc* tf, ZIO* Z)
{
- int i,n=LoadWord(Z);
+ int32 i,n=LoadWord(Z);
if (n==0) return;
tf->locvars=luaM_newvector(n+1,LocVar);
for (i=0; i<n; i++)
@@ -112,7 +109,7 @@ static TProtoFunc* LoadFunction(ZIO* Z);
static void LoadConstants(TProtoFunc* tf, ZIO* Z)
{
- int i,n=LoadWord(Z);
+ int32 i,n=LoadWord(Z);
tf->nconsts=n;
if (n==0) return;
tf->consts=luaM_newvector(n,TObject);
@@ -120,23 +117,23 @@ static void LoadConstants(TProtoFunc* tf, ZIO* Z)
{
TObject* o=tf->consts+i;
ttype(o)=(lua_Type)-ezgetc(Z);
- switch (ttype(o))
+ switch ((uint32)ttype(o))
{
- case -'N':
+ case (uint32)-'N':
ttype(o)=LUA_T_NUMBER;
- case LUA_T_NUMBER:
+ case (uint32)LUA_T_NUMBER:
doLoadNumber(nvalue(o),Z);
break;
- case -'S':
+ case (uint32)-'S':
ttype(o)=LUA_T_STRING;
- case LUA_T_STRING:
+ case (uint32)LUA_T_STRING:
tsvalue(o)=LoadTString(Z);
break;
- case -'F':
+ case (uint32)-'F':
ttype(o)=LUA_T_PROTO;
- case LUA_T_PROTO:
+ case (uint32)LUA_T_PROTO:
break;
- case LUA_T_NIL:
+ case (uint32)LUA_T_NIL:
break;
default:
luaL_verror("bad constant #%d in %s: type=%d [%s]",
@@ -152,7 +149,7 @@ static void LoadSubfunctions(TProtoFunc* tf, ZIO* Z) {
t = ezgetc(Z);
switch (t) {
case '#': {
- int i = LoadWord(Z);
+ int32 i = LoadWord(Z);
if (ttype(tf->consts+i) != LUA_T_PROTO)
luaL_verror("trying to load function into nonfunction constant (type=%d)",
ttype(tf->consts+i));
@@ -181,7 +178,7 @@ static TProtoFunc* LoadFunction(ZIO* Z)
static void LoadSignature(ZIO* Z)
{
- char* s=SIGNATURE;
+ const char* s=SIGNATURE;
while (*s!=0 && ezgetc(Z)==*s)
++s;
if (*s!=0) luaL_verror("bad signature in %s",zname(Z));
@@ -189,7 +186,7 @@ static void LoadSignature(ZIO* Z)
static void LoadHeader(ZIO* Z)
{
- int version,id,sizeofR;
+ int32 version,id,sizeofR;
#if 0
real f=(real)-TEST_NUMBER,tf=(real)TEST_NUMBER;
#endif
@@ -233,7 +230,7 @@ static TProtoFunc* LoadChunk(ZIO* Z)
*/
TProtoFunc* luaU_undump1(ZIO* Z)
{
- int c=zgetc(Z);
+ int32 c=zgetc(Z);
if (c==ID_CHUNK)
return LoadChunk(Z);
else if (c!=EOZ)
diff --git a/tools/lua/lundump.h b/tools/lua/lundump.h
index 3c2c60143..54b18c5f8 100644
--- a/tools/lua/lundump.h
+++ b/tools/lua/lundump.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lundump.h 692 2006-02-09 23:57:31Z fingolfin $
** load pre-compiled Lua chunks
** See Copyright Notice in lua.h
*/
@@ -7,8 +7,8 @@
#ifndef lundump_h
#define lundump_h
-#include <tools/lua/lobject.h>
-#include <tools/lua/lzio.h>
+#include "lobject.h"
+#include "lzio.h"
TProtoFunc* luaU_undump1(ZIO* Z); /* load one chunk */
diff --git a/tools/lua/lvm.cpp b/tools/lua/lvm.cpp
index fa6348362..cc89b5d4b 100644
--- a/tools/lua/lvm.cpp
+++ b/tools/lua/lvm.cpp
@@ -1,34 +1,27 @@
/*
-** $Id$
+** $Id: lvm.cpp 940 2008-07-26 19:30:44Z aquadran $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
-#include <stdio.h>
-#include <string.h>
-
-#include <tools/lua/lauxlib.h>
-#include <tools/lua/ldo.h>
-#include <tools/lua/lfunc.h>
-#include <tools/lua/lgc.h>
-#include <tools/lua/lmem.h>
-#include <tools/lua/lopcodes.h>
-#include <tools/lua/lstate.h>
-#include <tools/lua/lstring.h>
-#include <tools/lua/ltable.h>
-#include <tools/lua/ltm.h>
-#include <tools/lua/luadebug.h>
-#include <tools/lua/lvm.h>
-
-#ifdef OLD_ANSI
-#define strcoll(a,b) strcmp(a,b)
-#endif
+#include "lauxlib.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "lgc.h"
+#include "lmem.h"
+#include "lopcodes.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "ltm.h"
+#include "luadebug.h"
+#include "lvm.h"
#define skip_word(pc) (pc+=2)
-#define get_word(pc) (*((unsigned short*)(pc)))
+#define get_word(pc) ((*((pc)+1)<<8)|(*(pc)))
#define next_word(pc) (pc+=2, get_word(pc-2))
@@ -44,7 +37,7 @@ static TaggedString *strconc (TaggedString *l, TaggedString *r)
}
-int luaV_tonumber (TObject *obj)
+int32 luaV_tonumber (TObject *obj)
{ /* LUA_NUMBER */
double t;
char c;
@@ -60,7 +53,7 @@ int luaV_tonumber (TObject *obj)
}
-int luaV_tostring (TObject *obj)
+int32 luaV_tostring (TObject *obj)
{ /* LUA_NUMBER */
/* The Lua scripts for Grim Fandango sometimes end up executing
str..nil. The nil shows up in the original engine as "(nil)"... */
@@ -74,9 +67,9 @@ int luaV_tostring (TObject *obj)
else {
char s[60];
real f = nvalue(obj);
- int i;
- if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f)
- sprintf (s, "%d", i);
+ int32 i;
+ if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int32)f) == f)
+ sprintf (s, "%d", (int)i);
else
sprintf (s, NUMBER_FMT, nvalue(obj));
tsvalue(obj) = luaS_new(s);
@@ -86,7 +79,7 @@ int luaV_tostring (TObject *obj)
}
-void luaV_closure (int nelems)
+void luaV_closure (int32 nelems)
{
if (nelems > 0) {
struct Stack *S = &L->stack;
@@ -111,7 +104,7 @@ void luaV_gettable (void)
if (ttype(S->top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */
im = luaT_getimbyObj(S->top-2, IM_GETTABLE);
else { /* object is a table... */
- int tg = (S->top-2)->value.a->htag;
+ int32 tg = (S->top-2)->value.a->htag;
im = luaT_getim(tg, IM_GETTABLE);
if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */
TObject *h = luaH_get(avalue(S->top-2), S->top-1);
@@ -143,7 +136,7 @@ void luaV_gettable (void)
** mode = 1: normal store (with tag methods)
** mode = 2: "deep L->stack.stack" store (with tag methods)
*/
-void luaV_settable (TObject *t, int mode)
+void luaV_settable (TObject *t, int32 mode)
{
struct Stack *S = &L->stack;
TObject *im = (mode == 0) ? NULL : luaT_getimbyObj(t, IM_SETTABLE);
@@ -206,7 +199,7 @@ void luaV_setglobal (TaggedString *ts)
}
-static void call_binTM (IMS event, char *msg)
+static void call_binTM (IMS event, const char *msg)
{
TObject *im = luaT_getimbyObj(L->stack.top-2, event);/* try first operand */
if (ttype(im) == LUA_T_NIL) {
@@ -228,10 +221,10 @@ static void call_arith (IMS event)
}
-static int strcomp (char *l, long ll, char *r, long lr)
+static int32 strcomp (char *l, int32 ll, char *r, int32 lr)
{
for (;;) {
- long temp = strcoll(l, r);
+ int32 temp = (int32)strcoll(l, r);
if (temp != 0) return temp;
/* strings are equal up to a '\0' */
temp = strlen(l); /* index of first '\0' in both strings */
@@ -251,11 +244,11 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
struct Stack *S = &L->stack;
TObject *l = S->top-2;
TObject *r = S->top-1;
- int result;
+ int32 result;
if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1;
else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
- result = strcomp(svalue(l), tsvalue(l)->u.s.len,
+ result = (int32)strcomp(svalue(l), tsvalue(l)->u.s.len,
svalue(r), tsvalue(r)->u.s.len);
else {
call_binTM(op, "unexpected type in comparison");
@@ -268,10 +261,10 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
}
-void luaV_pack (StkId firstel, int nvararg, TObject *tab)
+void luaV_pack (StkId firstel, int32 nvararg, TObject *tab)
{
TObject *firstelem = L->stack.stack+firstel;
- int i;
+ int32 i;
if (nvararg < 0) nvararg = 0;
avalue(tab) = luaH_new(nvararg+1); /* +1 for field 'n' */
ttype(tab) = LUA_T_ARRAY;
@@ -300,7 +293,7 @@ void luaV_pack (StkId firstel, int nvararg, TObject *tab)
StkId luaV_execute (struct CallInfo *ci)
{
/* Save index in case CallInfo array is realloc'd */
- int ci_index = ci - L->base_ci;
+ int32 ci_index = ci - L->base_ci;
struct Stack *S = &L->stack; /* to optimize */
Closure *cl;
TProtoFunc *tf;
@@ -316,7 +309,7 @@ StkId luaV_execute (struct CallInfo *ci)
pc = L->ci->pc;
consts = tf->consts;
while (1) {
- int aux;
+ int32 aux;
switch ((OpCode)(aux = *pc++)) {
case PUSHNIL0:
@@ -465,7 +458,7 @@ StkId luaV_execute (struct CallInfo *ci)
case SETLIST0:
aux = 0;
setlist: {
- int n = *(pc++);
+ int32 n = *(pc++);
TObject *arr = S->top-n-1;
for (; n; n--) {
ttype(S->top) = LUA_T_NUMBER;
@@ -515,7 +508,7 @@ StkId luaV_execute (struct CallInfo *ci)
break;
case EQOP: case NEQOP: {
- int res = luaO_equalObj(S->top-2, S->top-1);
+ int32 res = luaO_equalObj(S->top-2, S->top-1);
S->top--;
if (aux == NEQOP) res = !res;
ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
diff --git a/tools/lua/lvm.h b/tools/lua/lvm.h
index d15d1ddc1..306527012 100644
--- a/tools/lua/lvm.h
+++ b/tools/lua/lvm.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lvm.h 905 2008-07-20 21:08:22Z aquadran $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -8,22 +8,22 @@
#define lvm_h
-#include <tools/lua/ldo.h>
-#include <tools/lua/lobject.h>
+#include "ldo.h"
+#include "lobject.h"
#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (luaV_tonumber(o) != 0))
#define tostring(o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(o) != 0))
-void luaV_pack (StkId firstel, int nvararg, TObject *tab);
-int luaV_tonumber (TObject *obj);
-int luaV_tostring (TObject *obj);
+void luaV_pack (StkId firstel, int32 nvararg, TObject *tab);
+int32 luaV_tonumber (TObject *obj);
+int32 luaV_tostring (TObject *obj);
void luaV_gettable (void);
-void luaV_settable (TObject *t, int mode);
+void luaV_settable (TObject *t, int32 mode);
void luaV_getglobal (TaggedString *ts);
void luaV_setglobal (TaggedString *ts);
StkId luaV_execute (struct CallInfo *ci);
-void luaV_closure (int nelems);
+void luaV_closure (int32 nelems);
#endif
diff --git a/tools/lua/lzio.cpp b/tools/lua/lzio.cpp
index 228b0c78c..be49d6c8d 100644
--- a/tools/lua/lzio.cpp
+++ b/tools/lua/lzio.cpp
@@ -1,30 +1,26 @@
/*
-** $Id$
+** $Id: lzio.cpp 938 2008-07-26 19:11:23Z aquadran $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
-
-#include <stdio.h>
-#include <string.h>
-
-#include <tools/lua/lzio.h>
+#include "lzio.h"
/* ----------------------------------------------------- memory buffers --- */
-static int zmfilbuf (ZIO* /*z*/)
+static int32 zmfilbuf (ZIO* /*z*/)
{
return EOZ;
}
-ZIO* zmopen (ZIO* z, char* b, int size, char *name)
+ZIO* zmopen (ZIO* z, const char* b, int32 size, const char *name)
{
if (b==NULL) return NULL;
z->n=size;
- z->p= (unsigned char *)b;
+ z->p= (const byte *)b;
z->filbuf=zmfilbuf;
z->u=NULL;
z->name=name;
@@ -33,7 +29,7 @@ ZIO* zmopen (ZIO* z, char* b, int size, char *name)
/* ------------------------------------------------------------ strings --- */
-ZIO* zsopen (ZIO* z, char* s, char *name)
+ZIO* zsopen (ZIO* z, const char* s, const char *name)
{
if (s==NULL) return NULL;
return zmopen(z,s,strlen(s),name);
@@ -41,9 +37,9 @@ ZIO* zsopen (ZIO* z, char* s, char *name)
/* -------------------------------------------------------------- FILEs --- */
-static int zffilbuf (ZIO* z)
+static int32 zffilbuf (ZIO* z)
{
- int n=fread(z->buffer,1,ZBSIZE,(FILE *)z->u);
+ int32 n=fread(z->buffer,1,ZBSIZE,(FILE *)z->u);
if (n==0) return EOZ;
z->n=n-1;
z->p=z->buffer;
@@ -51,7 +47,7 @@ static int zffilbuf (ZIO* z)
}
-ZIO* zFopen (ZIO* z, FILE* f, char *name)
+ZIO* zFopen (ZIO* z, FILE* f, const char *name)
{
if (f==NULL) return NULL;
z->n=0;
@@ -64,10 +60,10 @@ ZIO* zFopen (ZIO* z, FILE* f, char *name)
/* --------------------------------------------------------------- read --- */
-int zread (ZIO *z, void *b, int n)
+int32 zread (ZIO *z, void *b, int32 n)
{
while (n) {
- int m;
+ int32 m;
if (z->n == 0) {
if (z->filbuf(z) == EOZ)
return n; /* retorna quantos faltaram ler */
diff --git a/tools/lua/lzio.h b/tools/lua/lzio.h
index 5d440283b..cc570a2b3 100644
--- a/tools/lua/lzio.h
+++ b/tools/lua/lzio.h
@@ -1,5 +1,5 @@
/*
-** $Id$
+** $Id: lzio.h 937 2008-07-26 18:26:48Z aquadran $
** Buffered streams
** See Copyright Notice in lua.h
*/
@@ -8,7 +8,7 @@
#ifndef lzio_h
#define lzio_h
-#include <stdio.h>
+#include <common/sys.h>
@@ -16,19 +16,18 @@
#define zFopen luaZ_Fopen
#define zsopen luaZ_sopen
#define zmopen luaZ_mopen
-#define zread luaZ_read
#define EOZ (-1) /* end of stream */
typedef struct zio ZIO;
-ZIO* zFopen (ZIO* z, FILE* f, char *name); /* open FILEs */
-ZIO* zsopen (ZIO* z, char* s, char *name); /* string */
-ZIO* zmopen (ZIO* z, char* b, int size, char *name); /* memory */
+ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */
+ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */
+ZIO* zmopen (ZIO* z, const char* b, int32 size, const char *name); /* memory */
-int zread (ZIO* z, void* b, int n); /* read next n bytes */
+int32 zread (ZIO* z, void* b, int32 n); /* read next n bytes */
-#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
+#define zgetc(z) (--(z)->n>=0 ? ((int32)*(z)->p++): (z)->filbuf(z))
#define zungetc(z) (++(z)->n,--(z)->p)
#define zname(z) ((z)->name)
@@ -38,12 +37,12 @@ int zread (ZIO* z, void* b, int n); /* read next n bytes */
#define ZBSIZE 256 /* buffer size */
struct zio {
- int n; /* bytes still unread */
- unsigned char* p; /* current position in buffer */
- int (*filbuf)(ZIO* z);
+ int32 n; /* bytes still unread */
+ const byte* p; /* current position in buffer */
+ int32 (*filbuf)(ZIO* z);
void* u; /* additional data */
- char *name;
- unsigned char buffer[ZBSIZE]; /* buffer */
+ const char *name;
+ byte buffer[ZBSIZE]; /* buffer */
};
diff --git a/tools/module.mk b/tools/module.mk
index a1307cc6c..7af2cbf94 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -39,10 +39,10 @@ clean-tools:
# Build rules for the tools
#
-tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
+tools/delua$(EXEEXT): tools/delua.o
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -Wall \
- -L$(srcdir)/common -Ltools/lua -llua -o $@ $<
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common -Ltools/lua -o $@ $< -llua
tools/mat2ppm$(EXEEXT): $(srcdir)/tools/mat2ppm.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: 70350b7fe71a1c9e77c1a597e133f765d9d2fc13
https://github.com/scummvm/scummvm-tools/commit/70350b7fe71a1c9e77c1a597e133f765d9d2fc13
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-08T11:24:16+02:00
Commit Message:
remove left over plugin code
Changed paths:
rules.mk
diff --git a/rules.mk b/rules.mk
index 0045e59ac..f8dfdd973 100644
--- a/rules.mk
+++ b/rules.mk
@@ -35,29 +35,6 @@ tools: $(TOOL-$(MODULE))
$(MODULE): $(TOOL-$(MODULE))
clean-tools: clean-$(MODULE)
-else
-ifdef PLUGIN
-################################################
-# Build rule for dynamic (loadable) plugins
-################################################
-PLUGIN-$(MODULE) := plugins/$(PLUGIN_PREFIX)$(notdir $(MODULE))$(PLUGIN_SUFFIX)
-$(PLUGIN-$(MODULE)): $(MODULE_OBJS-$(MODULE)) $(PLUGIN_EXTRA_DEPS)
- $(QUIET)$(MKDIR) plugins
- $(QUIET_PLUGIN)$(CXX) $(filter-out $(PLUGIN_EXTRA_DEPS),$+) $(PLUGIN_LDFLAGS) -o $@
-
-# Reset PLUGIN var
-PLUGIN:=
-
-# Add to "plugins" target
-plugins: $(PLUGIN-$(MODULE))
-
-# Add to the PLUGINS variable
-PLUGINS += $(PLUGIN-$(MODULE))
-
-# Pseudo target for comfort, allows for "make common", "make gui" etc.
-$(MODULE): $(PLUGIN-$(MODULE))
-clean-plugins: clean-$(MODULE)
-
else
################################################
# Build rule for static modules/plugins
@@ -76,7 +53,6 @@ $(MODULE_LIB-$(MODULE)): $(MODULE_OBJS-$(MODULE))
# Pseudo target for comfort, allows for "make common", "make gui" etc.
$(MODULE): $(MODULE_LIB-$(MODULE))
-endif # PLUGIN
endif # TOOL_EXECUTABLE
###############################################
Commit: 806994d44f162eba5ba509896850a4355ed728bf
https://github.com/scummvm/scummvm-tools/commit/806994d44f162eba5ba509896850a4355ed728bf
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-08T11:32:09+02:00
Commit Message:
Merge branch 'master' of github.com:residual/residual-tools
Changed paths:
tools/lua/lapi.cpp
tools/lua/lapi.h
tools/lua/lauxlib.cpp
tools/lua/lauxlib.h
tools/lua/lbuffer.cpp
tools/lua/lbuiltin.cpp
tools/lua/lbuiltin.h
tools/lua/ldo.cpp
tools/lua/ldo.h
tools/lua/lfunc.cpp
tools/lua/lfunc.h
tools/lua/lgc.cpp
tools/lua/lgc.h
tools/lua/liolib.cpp
tools/lua/llex.cpp
tools/lua/llex.h
tools/lua/lmathlib.cpp
tools/lua/lmem.cpp
tools/lua/lmem.h
tools/lua/lobject.cpp
tools/lua/lobject.h
tools/lua/lopcodes.h
tools/lua/lparser.cpp
tools/lua/lparser.h
tools/lua/lrestore.cpp
tools/lua/lsave.cpp
tools/lua/lstate.cpp
tools/lua/lstate.h
tools/lua/lstring.cpp
tools/lua/lstring.h
tools/lua/lstrlib.cpp
tools/lua/ltable.cpp
tools/lua/ltable.h
tools/lua/ltask.cpp
tools/lua/ltask.h
tools/lua/ltm.cpp
tools/lua/ltm.h
tools/lua/lua.h
tools/lua/luadebug.h
tools/lua/lualib.h
tools/lua/lundump.cpp
tools/lua/lundump.h
tools/lua/lvm.cpp
tools/lua/lvm.h
tools/lua/lzio.cpp
tools/lua/lzio.h
tools/module.mk
Commit: f341cc31893059d3ad9b7164aa4038f45f13c54f
https://github.com/scummvm/scummvm-tools/commit/f341cc31893059d3ad9b7164aa4038f45f13c54f
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-08T11:39:01+02:00
Commit Message:
make bulding create missing dirs
Changed paths:
Makefile.common
tools/lua/module.mk
diff --git a/Makefile.common b/Makefile.common
index 610a985d7..fb16b7b79 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -15,12 +15,11 @@ all: build
# Module settings
######################################################################
-MODULES := tools $(MODULES)
+MODULES := tools/lua tools $(MODULES)
# After the game specific modules follow the shared modules
-MODULES += \
- tools/lua
-# common \
+MODULES +=
+# common
######################################################################
# The build rules follow - normally you should have no need to
@@ -53,7 +52,7 @@ endif
endif
endif
-build: $(OBJS) $(MODULES)
+build: dirs $(OBJS) $(MODULES)
distclean: clean
$(RM) config.h config.mk config.log
diff --git a/tools/lua/module.mk b/tools/lua/module.mk
index 4e80862c4..4b46be619 100644
--- a/tools/lua/module.mk
+++ b/tools/lua/module.mk
@@ -26,3 +26,7 @@ MODULE_OBJS := \
# Include common rules
include $(srcdir)/rules.mk
+
+dirs:
+ $(QUIET)$(MKDIR) tools/lua
+ $(QUIET)$(MKDIR) tools/patchex
Commit: 6c686da6fe5a7520f0d575ad374ae660bc51bcf2
https://github.com/scummvm/scummvm-tools/commit/6c686da6fe5a7520f0d575ad374ae660bc51bcf2
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-09T12:01:05+02:00
Commit Message:
fix warnings
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index f78614737..ab58972ce 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -133,8 +133,8 @@ public:
return true;
}
void print(std::ostream &os) const {
- static char *specials = "\a\b\f\n\r\t\v\\\"";
- static char *special_text[] = {
+ static const char *specials = "\a\b\f\n\r\t\v\\\"";
+ static const char *special_text[] = {
"\\a", "\\b", "\\f", "\\n", "\\r", "\\t", "\\v", "\\\\", "\\\""
};
Commit: 150a69a59441c98de46f827193036d8ce8b47e54
https://github.com/scummvm/scummvm-tools/commit/150a69a59441c98de46f827193036d8ce8b47e54
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-04-09T12:08:10+02:00
Commit Message:
fix warnings
Changed paths:
tools/patchex/mspack.h
tools/patchex/patchex.cpp
diff --git a/tools/patchex/mspack.h b/tools/patchex/mspack.h
index 2a252d3ff..22f6fb69a 100644
--- a/tools/patchex/mspack.h
+++ b/tools/patchex/mspack.h
@@ -60,7 +60,7 @@ struct mspack_system {
int mode);
off_t (*tell)(struct mspack_file *file);
void (*message)(struct mspack_file *file,
- char *format,
+ const char *format,
...);
void * (*alloc)(struct mspack_system *self,
size_t bytes);
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index 42cd6ee54..28dd59ea4 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -211,7 +211,7 @@ static int res_write(struct mspack_file *file, void *buffer, int bytes) {
return -1;
}
-static void res_msg(struct mspack_file *file, char *format, ...) {
+static void res_msg(struct mspack_file *file, const char *format, ...) {
va_list ap;
if (file)
Commit: e45c177434ecc8f787b82d824883c43cf0df38e1
https://github.com/scummvm/scummvm-tools/commit/e45c177434ecc8f787b82d824883c43cf0df38e1
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-04-23T02:38:50+02:00
Commit Message:
Added EMI-support to unlab, use with unlab <filename> EMI
Changed paths:
tools/unlab.cpp
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index bf9341a9e..7752e1f11 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -28,11 +28,16 @@
#include <stdint.h>
#include <string.h>
+
+#define GT_GRIM 1
+#define GT_EMI 2
+
struct lab_header {
uint32_t magic;
uint32_t magic2;
uint32_t num_entries;
uint32_t string_table_size;
+ uint32_t string_table_offset;
};
struct lab_entry {
@@ -58,7 +63,15 @@ int main(int argc, char **argv) {
char *str_table;
uint32_t i;
off_t offset;
-
+ uint8_t g_type;
+
+ if(argc > 2 && !strcmp(argv[2],"EMI"))
+ g_type = GT_EMI;
+ else
+ g_type = GT_GRIM;
+
+ printf("g_type: %d",g_type);
+
infile = fopen(argv[1], "rb");
if (infile == 0) {
printf("can't open source file: %s\n", argv[1]);
@@ -67,22 +80,45 @@ int main(int argc, char **argv) {
fread(&head.magic, 1, 4, infile);
fread(&head.magic2, 1, 4, infile);
- uint32_t num, s_size;
+ uint32_t num, s_size, s_offset;
fread(&num, 1, 4, infile);
fread(&s_size, 1, 4, infile);
+ if(g_type == GT_EMI)
+ fread(&s_offset,1,4,infile);
head.num_entries = READ_LE_UINT32(&num);
head.string_table_size = READ_LE_UINT32(&s_size);
if (0 != memcmp(&head.magic, "LABN", 4)) {
printf("There is no LABN header in source file\n");
exit(1);
}
-
+
entries = (struct lab_entry *)malloc(head.num_entries * sizeof(struct lab_entry));
- fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
-
str_table = (char *)malloc(head.string_table_size);
- fread(str_table, 1, head.string_table_size, infile);
-
+ // Grim-stuff
+ if(g_type == GT_GRIM){
+ fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
+
+ fread(str_table, 1, head.string_table_size, infile);
+ }
+ // EMI-stuff
+ else if(g_type == GT_EMI){
+ // EMI has a string-table-offset
+ head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
+ // Find the string-table
+ fseek(infile, head.string_table_offset, SEEK_SET);
+ // Read the entire string table into str-table
+ fread(str_table, 1, head.string_table_size, infile);
+ fseek(infile, 20, SEEK_SET);
+
+ // Decrypt the string table
+ uint32_t j;
+ for (j = 0; j < head.string_table_size; j++)
+ if (str_table[j] != 0)
+ str_table[j] ^= 0x96;
+ fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
+
+ }
+
for (i = 0; i < head.num_entries; i++) {
outfile = fopen(str_table + READ_LE_UINT32(&entries[i].fname_offset), "wb");
offset = READ_LE_UINT32(&entries[i].start);
@@ -91,8 +127,9 @@ int main(int argc, char **argv) {
fread(buf, 1, READ_LE_UINT32(&entries[i].size), infile);
fwrite(buf, 1, READ_LE_UINT32(&entries[i].size), outfile);
fclose(outfile);
+
}
-
+
fclose(infile);
return 0;
}
Commit: 82ac4d35e2bc2531771e8787460cdbd83b282a3d
https://github.com/scummvm/scummvm-tools/commit/82ac4d35e2bc2531771e8787460cdbd83b282a3d
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-04-23T13:34:23+08:00
Commit Message:
Added EMI-support to unlab, use with unlab <filename> EMI
Changed paths:
tools/unlab.cpp
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index bf9341a9e..7752e1f11 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -28,11 +28,16 @@
#include <stdint.h>
#include <string.h>
+
+#define GT_GRIM 1
+#define GT_EMI 2
+
struct lab_header {
uint32_t magic;
uint32_t magic2;
uint32_t num_entries;
uint32_t string_table_size;
+ uint32_t string_table_offset;
};
struct lab_entry {
@@ -58,7 +63,15 @@ int main(int argc, char **argv) {
char *str_table;
uint32_t i;
off_t offset;
-
+ uint8_t g_type;
+
+ if(argc > 2 && !strcmp(argv[2],"EMI"))
+ g_type = GT_EMI;
+ else
+ g_type = GT_GRIM;
+
+ printf("g_type: %d",g_type);
+
infile = fopen(argv[1], "rb");
if (infile == 0) {
printf("can't open source file: %s\n", argv[1]);
@@ -67,22 +80,45 @@ int main(int argc, char **argv) {
fread(&head.magic, 1, 4, infile);
fread(&head.magic2, 1, 4, infile);
- uint32_t num, s_size;
+ uint32_t num, s_size, s_offset;
fread(&num, 1, 4, infile);
fread(&s_size, 1, 4, infile);
+ if(g_type == GT_EMI)
+ fread(&s_offset,1,4,infile);
head.num_entries = READ_LE_UINT32(&num);
head.string_table_size = READ_LE_UINT32(&s_size);
if (0 != memcmp(&head.magic, "LABN", 4)) {
printf("There is no LABN header in source file\n");
exit(1);
}
-
+
entries = (struct lab_entry *)malloc(head.num_entries * sizeof(struct lab_entry));
- fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
-
str_table = (char *)malloc(head.string_table_size);
- fread(str_table, 1, head.string_table_size, infile);
-
+ // Grim-stuff
+ if(g_type == GT_GRIM){
+ fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
+
+ fread(str_table, 1, head.string_table_size, infile);
+ }
+ // EMI-stuff
+ else if(g_type == GT_EMI){
+ // EMI has a string-table-offset
+ head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
+ // Find the string-table
+ fseek(infile, head.string_table_offset, SEEK_SET);
+ // Read the entire string table into str-table
+ fread(str_table, 1, head.string_table_size, infile);
+ fseek(infile, 20, SEEK_SET);
+
+ // Decrypt the string table
+ uint32_t j;
+ for (j = 0; j < head.string_table_size; j++)
+ if (str_table[j] != 0)
+ str_table[j] ^= 0x96;
+ fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
+
+ }
+
for (i = 0; i < head.num_entries; i++) {
outfile = fopen(str_table + READ_LE_UINT32(&entries[i].fname_offset), "wb");
offset = READ_LE_UINT32(&entries[i].start);
@@ -91,8 +127,9 @@ int main(int argc, char **argv) {
fread(buf, 1, READ_LE_UINT32(&entries[i].size), infile);
fwrite(buf, 1, READ_LE_UINT32(&entries[i].size), outfile);
fclose(outfile);
+
}
-
+
fclose(infile);
return 0;
}
Commit: ff0a995b757be72dc7ae3dd5d294c5ce622882d9
https://github.com/scummvm/scummvm-tools/commit/ff0a995b757be72dc7ae3dd5d294c5ce622882d9
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-04-30T01:15:34+02:00
Commit Message:
Initial work on tiles and sets for EMI
Changed paths:
A tools/setb2set.cpp
A tools/til2bmp.cpp
diff --git a/tools/setb2set.cpp b/tools/setb2set.cpp
new file mode 100644
index 000000000..ca052ec30
--- /dev/null
+++ b/tools/setb2set.cpp
@@ -0,0 +1,271 @@
+/*
+* TODO: Put GPL-license here
+* Thanks to klusark, for his work.
+* This version written by Einar Johan T. SÃmÃen
+*/
+
+#include <cassert>
+#include <cstdio>
+#include <cstdlib>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <sstream>
+
+using namespace std;
+
+typedef int uint32;
+
+enum SectorType{
+ camera,
+ chernobyl,
+ special,
+ walk
+};
+
+enum SectorVisibility{
+ visible
+};
+
+enum LightType{
+ omni,
+ direct
+};
+
+struct Section{
+ const char* buf;
+ float GetFloat()
+ {
+ float retVal = *(float*) buf;
+ buf+=4;
+ return retVal;
+ }
+ int GetInt()
+ {
+ int retVal = *(int*) buf;
+ buf+=4;
+ return retVal;
+ }
+ virtual uint32 load() = 0;
+ virtual string MakeVeryLongString() = 0;
+};
+
+struct Sector : public Section
+{
+ string name;
+ int ID; // byte;
+ SectorType type;
+ SectorVisibility visibility;
+ float height;
+ int numVertices; // byte;
+ float* vertices; // 3 * numVertices.
+ virtual uint32 load()
+ {
+ numVertices = GetInt();
+ vertices = new float[3*numVertices];
+ for(int i=0; i < numVertices; i++)
+ {
+ vertices[0+3*i]=GetFloat();
+ vertices[1+3*i]=GetFloat();
+ vertices[2+3*i]=GetFloat();
+ }
+ int nameLength = GetInt();
+ name = buf;
+ buf += nameLength;
+ ID = GetInt();
+ //visible = *buf;
+ buf+=1;
+ //type = *buf;
+ buf+=4;
+ int skip = (*(int*)buf); //64;
+ buf+= (skip+1)*4;
+ height = GetFloat();
+
+ return 12*numVertices + nameLength + skip*4 + 25;
+ }
+ virtual string MakeVeryLongString()
+ {
+ cout << "SECTOR-MAKESTRING";
+ return "";
+ }
+};
+
+struct Setup : public Section
+{
+ string name;
+ string background;
+ string zbuffer;
+ float* position;
+ float* interest;
+ float roll;
+ float fov;
+ float nclip;
+ float fclip;
+ virtual uint32 load()
+ {
+ cout << "Running setup-load";
+ name = buf; // Parse a string really
+ buf += 128;
+
+ // Skip an unknown number
+ buf += 4;
+
+ char title[128];
+
+ char in = 0;
+ int i = 0;
+ do {
+ in = *buf;
+ ++i;
+ ++buf;
+ }while(in);
+
+ position = new float[3];
+
+ position[0] = GetFloat();
+ position[1] = GetFloat();
+ position[2] = GetFloat();
+
+ interest = new float[3];
+
+ interest[0] = GetFloat();
+ interest[1] = GetFloat();
+ interest[2] = GetFloat();
+
+ roll = GetFloat();
+ fov = GetFloat();
+ nclip = GetFloat();
+ fclip = GetFloat();
+ // cout << MakeVeryLongString();
+
+ return 172+i;
+ }
+
+ virtual string MakeVeryLongString()
+ {
+ cout << "SETUP-MAKESTRING";
+ stringstream ss;
+ ss << "\tname\t" << name << "\n";
+ // background
+ // zbuffer
+ ss << "\tposition\t" << position[0] << "\t" << position[1] << "\t" << position[2] << "\n";
+ ss << "\tinterest\t" << interest[0] << "\t" << interest[1] << "\t" << interest[2] << "\n";
+ ss << "\troll\t" << roll << "\n";
+ ss << "\fov\t" << fov << "\n";
+ ss << "\tnclip\t" << nclip << "\n";
+ ss << "\tfclip\t" << fclip << "\n";
+
+ return ss.str();
+ }
+};
+
+struct Light : public Section
+{
+ string name;
+ LightType type;
+ float* position;
+ float* direction;
+ float intensity;
+ float umbraangla;
+ float penumbraangle;
+ int* color; // Byte
+ virtual uint32 load()
+ {
+ return 100; // Skipme
+ }
+ virtual string MakeVeryLongString()
+ {
+ cout << "LIGHT-MAKESTRING";
+ return "";
+ }
+};
+
+struct Set{
+ string setName;
+ uint32 numSetups;
+ uint32 numColormaps;
+ uint32 numLights;
+ uint32 numSectors;
+ vector<Section*> setups;
+ vector<string> colormaps;
+ vector<Section*> lights;
+ vector<Section*> sectors;
+ virtual string MakeVeryLongString()
+ {
+ stringstream ss;
+ // colormaps
+ ss << "section: colormaps\n"; // we don't have any.
+ // setups
+ ss << "section: setups\n";
+ vector<Section*>::iterator it;
+ cout << "Size of setups: " << setups.size();
+ for(it = setups.begin();it!=setups.end();++it)
+ {
+ cout << "HELLO";
+ ss << (*it)->MakeVeryLongString();
+ }
+ // lights
+ cout << "Size of lights: " << lights.size();
+ ss << "section: lights\n";
+ for(it = lights.begin();it!=lights.end();it++)
+ {
+ ss << (*it)->MakeVeryLongString();
+ }
+ // sectors
+ cout << "Size of sectors: " << sectors.size();
+ ss << "section: sectors\n";
+ for(it = sectors.begin();it!=sectors.end();it++)
+ {
+ cout << "HELLO";
+ ss << (*it)->MakeVeryLongString();
+ }
+ return ss.str();
+ }
+ Set(const char* buf)
+ {
+ numSetups = *(int*)buf;
+ buf += 4;
+ setups.reserve(numSetups);
+ cout << "We should have " << numSetups << "setups\n";
+ for(int i=0;i<numSetups;i++)
+ {
+ cout << "Adding the " << i << "th Setup\n";
+ setups[i]=new Setup();
+ setups[i]->buf = buf;
+ buf += setups[i]->load();
+ }
+ // Ignore all lights, since we don't know how to handle them
+ numLights = *(int*)buf;
+ buf+=4;
+
+ buf+= numLights*100;
+
+ numSectors = *(int*)buf;
+ buf+=4;
+ sectors.reserve(numSectors);
+ cout << "Numsectors: " << numSectors << endl;
+ for(int i=0;i<numSectors;i++)
+ {
+ sectors[i]=new Sector();
+ sectors[i]->buf = buf;
+ buf+= sectors[i]->load();
+ }
+ }
+};
+
+int main(int argc, char** argv){
+ char* buf;
+ FILE* f;
+
+ f = fopen(argv[1],"rb");
+ fseek(f,0,SEEK_END);
+ uint32 size = ftell(f);
+ buf = new char[size];
+ fseek(f,0,SEEK_SET);
+
+ int result = fread(buf,1,size,f);
+ assert(result==size);
+
+ Set* ourSet = new Set(buf);
+ cout << ourSet->MakeVeryLongString();
+}
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
new file mode 100644
index 000000000..3a9608a99
--- /dev/null
+++ b/tools/til2bmp.cpp
@@ -0,0 +1,273 @@
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <zlib.h>
+
+typedef unsigned int uint;
+
+struct BMPHeader
+{
+ //unsigned short bm;
+ unsigned int size;
+ unsigned int reserved;
+ unsigned int offset;
+ unsigned int headerSize;
+ int width;
+ int height;
+ unsigned int nplanesbpp;
+ unsigned int compress_type;
+ unsigned int bmp_bytesz;
+ int hres;
+ int vres;
+ unsigned int ncolors;
+ unsigned int nimpcolors;
+};
+
+
+class LucasBitMap
+{
+private:
+ inline uint size(){ return height*width*bpp; }
+public:
+ char* data;
+ unsigned int width, height, bpp;
+ ~LucasBitMap();
+ LucasBitMap() : data(0), width(0), height(0), bpp(4){}
+ LucasBitMap(char* data, uint width, uint height,uint bpp=4);
+ void MakeNewData();
+ void AdjustHeight(int newHeight);
+ void BGR2RGB();
+ void UpsideDown();
+ void AddToRightOfThis(LucasBitMap* bitmap);
+ void AddBelowThis(LucasBitMap* bitmap);
+ LucasBitMap* GetSubImage(int start, int end);
+ void WriteBMP(const char *name);
+};
+
+LucasBitMap::~LucasBitMap()
+{
+ delete data;
+}
+
+LucasBitMap::LucasBitMap(char* data, uint width, uint height,uint bpp)
+{
+ this->width = width;
+ this->height = height;
+ this->bpp = bpp;
+ MakeNewData();
+ memcpy(this->data,data,width*height*bpp);
+}
+
+
+void LucasBitMap::MakeNewData() // If it needs deletion, please do that before
+{
+ data = new char[width*height*bpp];
+}
+
+void LucasBitMap::WriteBMP(const char *name)
+{
+ std::fstream file(name, std::fstream::out | std::fstream::binary);
+ BMPHeader header;
+ int size = width*height*4;
+ //header.bm = 19778;
+ unsigned short bm = 19778;
+ file.write((char *)&bm, 2);
+ header.size = size+54;
+ header.reserved = 0;
+ header.width = width;
+ header.height = height;
+ header.offset = 54;
+ header.headerSize = 40;
+ header.nplanesbpp = 2097153;
+ header.compress_type = 0;
+ header.bmp_bytesz = 0;
+ header.hres = 2835;
+ header.vres = 2835;
+ header.ncolors = 0;
+ header.nimpcolors = 0;
+ file.write((char *)&header, sizeof(BMPHeader));
+ file.write(data, size);
+ file.close();
+}
+
+void LucasBitMap::AdjustHeight(int newHeight)
+{
+ UpsideDown();
+ height = newHeight;
+ char *newData = new char[size()];
+ memcpy(newData,data,size());
+ data = newData;
+ UpsideDown();
+}
+
+void LucasBitMap::BGR2RGB()
+{
+ int end = size();
+ for(int i=0;i<end;i+=4)
+ {
+ int temp = data[i+2];
+ data[i+2] = data[i];
+ data[i] = temp;
+ }
+}
+
+char* GetLine(int lineNum, char* data, unsigned int width)
+{
+ return data + (lineNum*(width*4));
+}
+
+void LucasBitMap::UpsideDown()
+{
+ unsigned lineLength = width*4;
+ char* fixedData = new char[size()];
+ for(int i=0;i<height;i++)
+ {
+ char* to = GetLine(i,fixedData, width);
+ char* from = GetLine(height-i-1,data, width);
+ memcpy(to,from,lineLength);
+ }
+ memcpy(data,fixedData,size());
+ delete fixedData;
+}
+
+void LucasBitMap::AddToRightOfThis(LucasBitMap* bitmap)
+{
+ if(height != bitmap->height)
+ std::cout << "WARNING, can't combine with differing heights\n";
+ int newSize = size() + bitmap->size();
+ char* dest = new char[newSize];
+ int newWidth = bitmap->width+width;
+ for(int i=0; i < height; i++)
+ {
+ char *part1 = GetLine(i,data,width);
+ char *part2 = GetLine(i,bitmap->data,bitmap->width);
+ char *to = GetLine(i, dest, newWidth);
+ memcpy(to,part1,width*4);
+ memcpy(to+width*4,part2,bitmap->width*4);
+ }
+ delete data;
+ width+=bitmap->width;
+ MakeNewData();
+ memcpy(data,dest,newSize);
+}
+
+void LucasBitMap::AddBelowThis(LucasBitMap* bitmap)
+{
+ if(width != bitmap->width)
+ std::cout << "WARNING, can't combine with differing widths\n";
+ int newSize = size() + bitmap->size();
+ char* dest = new char[newSize];
+
+ for(int i=0; i < bitmap->height; i++)
+ {
+ char* from = GetLine(i,bitmap->data,width);
+ char* to = GetLine(i,dest,width);
+ memcpy(to,from,width*4);
+ }
+
+ char *lowerFrom = dest + bitmap->size();
+ for(int i=0; i < height; i++)
+ {
+ char *from = GetLine(i,data,width);
+ char *to = GetLine(i,lowerFrom,width);
+ memcpy(to,from,width*4);
+ }
+ delete data;
+ height+=bitmap->height;
+ MakeNewData();
+ memcpy(data,dest,newSize);
+}
+
+LucasBitMap* LucasBitMap::GetSubImage(int start, int end)
+{
+ LucasBitMap *dest = new LucasBitMap();
+ dest->width = end-start;
+ dest->height = height;
+ dest->MakeNewData();
+ for(int i=0;i<height;i++)
+ {
+ char* from = GetLine(i,data,width);
+ char* to = GetLine(i,dest->data,dest->width);
+ memcpy(to,from+start*4,dest->width*4);
+ }
+ return dest;
+}
+
+
+void MakeTheBiggerPicture(LucasBitMap** bits, int numPieces, std::string name)
+{
+ // Get the parts that belong in the rightmost 128 pixels of the screen
+ // They are in tile 3, half each.
+ LucasBitMap* extra1 = bits[2]->GetSubImage(0,128);
+ LucasBitMap* extra2 = bits[2]->GetSubImage(128,256);
+
+ bits[0]->AddToRightOfThis(bits[1]);
+ bits[0]->AddToRightOfThis(extra1);
+ bits[3]->AddToRightOfThis(bits[4]);
+
+
+ bits[3]->AddToRightOfThis(extra2);
+ bits[3]->AdjustHeight(224);
+
+ delete bits[1];
+ delete bits[2];
+ delete bits[4];
+ delete extra1;
+ delete extra2;
+
+
+ bits[0]->AddBelowThis(bits[3]);
+ delete bits[3];
+
+ std::string filename = name+".bmp";
+ bits[0]->WriteBMP(filename.c_str());
+ delete bits[0];
+
+}
+
+void ProcessFile(std::fstream &til, const char* name)
+{
+ int id, bmoffset, rects, b, c;
+ til.read((char *)&id, 4);
+ til.read((char *)&bmoffset, 4);
+ til.read((char *)&rects, 4);
+ til.read((char *)&b, 4);
+ til.read((char *)&c, 4);
+
+ til.seekg(bmoffset+128, std::ios_base::beg);
+
+ int width = 0, height = 0;
+
+ LucasBitMap **allTheData = new LucasBitMap*[5];
+ int *sizes = new int[5];
+ for (int i = 0; i < 6; ++i) {
+ til.read((char *)&width, 4);
+ til.read((char *)&height, 4);
+ unsigned int size = width*height*4;
+ char *data = new char[size];
+ char name[32];
+ sprintf(name, "%d.bmp", i);
+
+ til.read(data, size);
+
+ allTheData[i] = new LucasBitMap(data, width, height);
+ allTheData[i]->BGR2RGB();
+ allTheData[i]->UpsideDown();
+
+ sizes[i] = size;
+ allTheData[i]->WriteBMP(name);
+ delete data;
+ }
+ MakeTheBiggerPicture(allTheData,5, name);
+
+}
+
+int main(int argc, char **argv)
+{
+ std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
+ if (!file.is_open()) {
+ std::cout << "Could not open file" << std::endl;
+ }
+ ProcessFile(file,argv[1]);
+ file.close();
+}
\ No newline at end of file
Commit: 5298d302fed505ae83b6b26570a4a4db2f1f08f1
https://github.com/scummvm/scummvm-tools/commit/5298d302fed505ae83b6b26570a4a4db2f1f08f1
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2011-04-30T07:16:52+08:00
Commit Message:
Added some information about the EMI setb format
Changed paths:
A formats/setb.txt
diff --git a/formats/setb.txt b/formats/setb.txt
new file mode 100644
index 000000000..e8e91c063
--- /dev/null
+++ b/formats/setb.txt
@@ -0,0 +1,33 @@
+int number of setups
+
+each setup {
+ a padded 128 byte string
+ an unknown integer
+ the null terminated name of the tile file
+ some floats assumed to be in this order {
+ position vector
+ interest vector
+ roll
+ fov
+ nclip
+ fclip
+ }
+}
+int number of lights
+each light {
+ 100 bytes that is curently unknown
+}
+
+int number of sectors
+each sector {
+ int number of vertecies
+ number of vertecies in vectors
+ int name length (includes null termination)
+ the name of the sector
+ int the id
+ bool visible
+ int type
+ int unknown, but tells how many extra bits there are
+ unknown*4 bytes of stuff
+ float the height
+}
\ No newline at end of file
Commit: 7c5578594398aac636a54d3a0dbe53b0482ca8a7
https://github.com/scummvm/scummvm-tools/commit/7c5578594398aac636a54d3a0dbe53b0482ca8a7
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2011-04-30T09:09:03+08:00
Commit Message:
Improved setb2set
Changed paths:
tools/setb2set.cpp
diff --git a/tools/setb2set.cpp b/tools/setb2set.cpp
index ca052ec30..9f507549b 100644
--- a/tools/setb2set.cpp
+++ b/tools/setb2set.cpp
@@ -16,83 +16,184 @@ using namespace std;
typedef int uint32;
-enum SectorType{
- camera,
- chernobyl,
- special,
- walk
+enum SectorType {
+ NoneType = 0,
+ WalkType = 0x1000,
+ FunnelType = 0x1100,
+ CameraType = 0x2000,
+ SpecialType = 0x4000,
+ HotType = 0x8000
};
-enum SectorVisibility{
- visible
-};
enum LightType{
omni,
direct
};
-struct Section{
- const char* buf;
- float GetFloat()
- {
- float retVal = *(float*) buf;
- buf+=4;
- return retVal;
- }
- int GetInt()
- {
- int retVal = *(int*) buf;
- buf+=4;
- return retVal;
- }
- virtual uint32 load() = 0;
- virtual string MakeVeryLongString() = 0;
+class Data {
+public:
+ Data(const char *data);
+ float GetFloat();
+ int GetInt();
+ bool GetBool();
+ string GetString(int length);
+ string GetNullTerminatedString();
+ void Skip(int val);
+private:
+ const char *buf;
};
-struct Sector : public Section
+Data::Data(const char *data)
+{
+ buf = data;
+}
+
+float Data::GetFloat()
+{
+ float retVal = *(float *) buf;
+ buf += 4;
+ return retVal;
+}
+
+int Data::GetInt()
+{
+ int retVal = *(int *) buf;
+ buf += 4;
+ return retVal;
+}
+
+bool Data::GetBool()
+{
+ bool retVal = *(bool *) buf;
+ buf += 1;
+ return retVal;
+}
+
+string Data::GetString(int length)
+{
+ //kind of a hack
+ string s = string(buf);
+ buf += length;
+ return s;
+}
+
+string Data::GetNullTerminatedString()
+{
+ string s = string(buf);
+ buf += s.length()+1;
+ return s;
+}
+
+void Data::Skip(int val)
{
+ buf += val;
+}
+
+struct Section {
+public:
+ Section(Data *data);
+ //virtual uint32 load() = 0;
+ virtual string ToString() = 0;
+protected:
+ Data *data;
+};
+
+Section::Section(Data *data)
+{
+ this->data = data;
+}
+
+class Sector : public Section
+{
+public:
+ Sector(Data *data);
+
+ virtual string ToString();
+private:
string name;
int ID; // byte;
SectorType type;
- SectorVisibility visibility;
float height;
int numVertices; // byte;
float* vertices; // 3 * numVertices.
- virtual uint32 load()
+ bool visible;
+};
+
+Sector::Sector(Data *data) : Section(data)
+{
+ numVertices = data->GetInt();
+ vertices = new float[3*numVertices];
+ for(int i=0; i < numVertices; i++)
{
- numVertices = GetInt();
- vertices = new float[3*numVertices];
- for(int i=0; i < numVertices; i++)
- {
- vertices[0+3*i]=GetFloat();
- vertices[1+3*i]=GetFloat();
- vertices[2+3*i]=GetFloat();
- }
- int nameLength = GetInt();
- name = buf;
- buf += nameLength;
- ID = GetInt();
- //visible = *buf;
- buf+=1;
- //type = *buf;
- buf+=4;
- int skip = (*(int*)buf); //64;
- buf+= (skip+1)*4;
- height = GetFloat();
-
- return 12*numVertices + nameLength + skip*4 + 25;
+ vertices[0+3*i] = data->GetFloat();
+ vertices[1+3*i] = data->GetFloat();
+ vertices[2+3*i] = data->GetFloat();
}
- virtual string MakeVeryLongString()
- {
- cout << "SECTOR-MAKESTRING";
- return "";
+ int nameLength = data->GetInt();
+
+ name = data->GetString(nameLength);
+ ID = data->GetInt();
+ visible = data->GetBool();
+ type = (SectorType)data->GetInt();
+ int skip = data->GetInt();
+ data->Skip(skip*4);
+ height = data->GetFloat();
+}
+
+string Sector::ToString()
+{
+ stringstream ss;
+ ss.precision(6);
+ ss.setf(ios::fixed,ios::floatfield);
+ ss << "\tsector\t" << name << endl;
+ ss << "\tID\t" << ID << endl;
+ ss << "\ttype\t";
+ switch (type) {
+ case WalkType:
+ ss << "walk";
+ break;
+ case FunnelType:
+ ss << "funnel";
+ break;
+ case CameraType:
+ ss << "camera";
+ break;
+ case SpecialType:
+ ss << "special";
+ break;
+ case HotType:
+ ss << "hot";
+ break;
+ };
+ ss << endl;
+ ss << "\tdefault visibility\t";
+ if (visible)
+ ss << "visible";
+ else
+ ss << "invisible";
+ ss << endl;
+ ss << "\theight\t" << height << endl;
+ ss << "\tnumvertices\t" << numVertices << endl;
+ ss << "\tvertices:\t\t";
+ for (int i = 0; i < numVertices*3; i+=3) {
+ if (i != 0)
+ ss << "\t\t\t\t";
+ ss << vertices[i] << "\t" << vertices[i+1] << "\t" << vertices[i+2] << endl;
}
-};
-struct Setup : public Section
+ return ss.str();
+}
+
+class Setup : public Section
{
+public:
+ Setup(Data *data);
+
+ virtual string ToString();
+private:
string name;
+ string tile;
string background;
string zbuffer;
float* position;
@@ -101,66 +202,61 @@ struct Setup : public Section
float fov;
float nclip;
float fclip;
- virtual uint32 load()
- {
- cout << "Running setup-load";
- name = buf; // Parse a string really
- buf += 128;
-
- // Skip an unknown number
- buf += 4;
-
- char title[128];
-
- char in = 0;
- int i = 0;
- do {
- in = *buf;
- ++i;
- ++buf;
- }while(in);
-
- position = new float[3];
-
- position[0] = GetFloat();
- position[1] = GetFloat();
- position[2] = GetFloat();
-
- interest = new float[3];
-
- interest[0] = GetFloat();
- interest[1] = GetFloat();
- interest[2] = GetFloat();
-
- roll = GetFloat();
- fov = GetFloat();
- nclip = GetFloat();
- fclip = GetFloat();
- // cout << MakeVeryLongString();
-
- return 172+i;
- }
-
- virtual string MakeVeryLongString()
- {
- cout << "SETUP-MAKESTRING";
- stringstream ss;
- ss << "\tname\t" << name << "\n";
- // background
- // zbuffer
- ss << "\tposition\t" << position[0] << "\t" << position[1] << "\t" << position[2] << "\n";
- ss << "\tinterest\t" << interest[0] << "\t" << interest[1] << "\t" << interest[2] << "\n";
- ss << "\troll\t" << roll << "\n";
- ss << "\fov\t" << fov << "\n";
- ss << "\tnclip\t" << nclip << "\n";
- ss << "\tfclip\t" << fclip << "\n";
-
- return ss.str();
- }
};
-struct Light : public Section
+Setup::Setup(Data *data) : Section(data)
{
+ name = data->GetString(128); // Parse a string really
+
+ // Skip an unknown number
+ int unknown = data->GetInt();
+
+
+ tile = data->GetNullTerminatedString();
+
+ position = new float[3];
+
+ position[0] = data->GetFloat();
+ position[1] = data->GetFloat();
+ position[2] = data->GetFloat();
+
+ interest = new float[3];
+
+ interest[0] = data->GetFloat();
+ interest[1] = data->GetFloat();
+ interest[2] = data->GetFloat();
+
+ roll = data->GetFloat();
+ fov = data->GetFloat();
+ nclip = data->GetFloat();
+ fclip = data->GetFloat();
+}
+
+string Setup::ToString()
+{
+ stringstream ss;
+ ss.precision(6);
+ ss.setf(ios::fixed,ios::floatfield);
+ ss << "\tname\t" << name << endl;
+ // background
+ // zbuffer
+ ss << "\tposition\t" << position[0] << "\t" << position[1] << "\t" << position[2] << endl;
+ ss << "\tinterest\t" << interest[0] << "\t" << interest[1] << "\t" << interest[2] << endl;
+ ss << "\troll\t" << roll << endl;
+ ss << "\tfov\t" << fov << endl;
+ ss << "\tnclip\t" << nclip << endl;
+ ss << "\tfclip\t" << fclip << endl;
+
+ return ss.str();
+}
+
+class Light : public Section
+{
+public:
+ Light(Data *data);
+ virtual string ToString();
+
+private:
string name;
LightType type;
float* position;
@@ -169,103 +265,98 @@ struct Light : public Section
float umbraangla;
float penumbraangle;
int* color; // Byte
- virtual uint32 load()
- {
- return 100; // Skipme
- }
- virtual string MakeVeryLongString()
- {
- cout << "LIGHT-MAKESTRING";
- return "";
- }
+
};
-struct Set{
+Light::Light(Data *data) : Section(data)
+{
+ data->Skip(100);
+}
+
+string Light::ToString()
+{
+ return "";
+}
+
+class Set {
+public:
+ virtual string ToString();
+ Set(Data *data);
+private:
string setName;
uint32 numSetups;
uint32 numColormaps;
uint32 numLights;
uint32 numSectors;
- vector<Section*> setups;
+ vector<Section *> setups;
vector<string> colormaps;
- vector<Section*> lights;
- vector<Section*> sectors;
- virtual string MakeVeryLongString()
- {
- stringstream ss;
- // colormaps
- ss << "section: colormaps\n"; // we don't have any.
- // setups
- ss << "section: setups\n";
- vector<Section*>::iterator it;
- cout << "Size of setups: " << setups.size();
- for(it = setups.begin();it!=setups.end();++it)
- {
- cout << "HELLO";
- ss << (*it)->MakeVeryLongString();
- }
- // lights
- cout << "Size of lights: " << lights.size();
- ss << "section: lights\n";
- for(it = lights.begin();it!=lights.end();it++)
- {
- ss << (*it)->MakeVeryLongString();
- }
- // sectors
- cout << "Size of sectors: " << sectors.size();
- ss << "section: sectors\n";
- for(it = sectors.begin();it!=sectors.end();it++)
- {
- cout << "HELLO";
- ss << (*it)->MakeVeryLongString();
- }
- return ss.str();
+ vector<Section *> lights;
+ vector<Section *> sectors;
+};
+
+Set::Set(Data *data)
+{
+ numSetups = data->GetInt();
+ setups.reserve(numSetups);
+ for(uint32 i = 0; i < numSetups; i++) {
+ setups.push_back(new Setup(data));
}
- Set(const char* buf)
- {
- numSetups = *(int*)buf;
- buf += 4;
- setups.reserve(numSetups);
- cout << "We should have " << numSetups << "setups\n";
- for(int i=0;i<numSetups;i++)
- {
- cout << "Adding the " << i << "th Setup\n";
- setups[i]=new Setup();
- setups[i]->buf = buf;
- buf += setups[i]->load();
- }
- // Ignore all lights, since we don't know how to handle them
- numLights = *(int*)buf;
- buf+=4;
-
- buf+= numLights*100;
-
- numSectors = *(int*)buf;
- buf+=4;
- sectors.reserve(numSectors);
- cout << "Numsectors: " << numSectors << endl;
- for(int i=0;i<numSectors;i++)
- {
- sectors[i]=new Sector();
- sectors[i]->buf = buf;
- buf+= sectors[i]->load();
- }
+
+ numLights = data->GetInt();
+ lights.reserve(numLights);
+ for(uint32 i = 0; i < numLights; i++) {
+ lights.push_back(new Light(data));
+ }
+
+ numSectors = data->GetInt();
+ sectors.reserve(numSectors);
+ for(uint32 i = 0; i < numSectors; i++) {
+ sectors.push_back(new Sector(data));
+ }
+}
+string Set::ToString()
+{
+ stringstream ss;
+ // colormaps
+ ss << "section: colormaps" << endl; // we don't have any.
+ // setups
+ ss << "section: setups" << endl;
+ vector<Section*>::iterator it;
+ ss << "\tnumsetups " << setups.size() << endl;
+ for(it = setups.begin(); it != setups.end(); ++it) {
+ ss << (*it)->ToString() << endl << endl;
}
-};
+ // lights
+ ss << "section: lights" << endl;
+ ss << "\tnumlights 0" << endl;
+ for(it = lights.begin();it!=lights.end();it++) {
+ ss << (*it)->ToString() << endl << endl;
+ }
+ // sectors
+ ss << "section: sectors\n";
+ for(it = sectors.begin(); it != sectors.end();it++) {
+ ss << (*it)->ToString() << endl << endl;
+ }
+ return ss.str();
+}
int main(int argc, char** argv){
+ if (argc < 2)
+ return 0;
char* buf;
FILE* f;
-
+
f = fopen(argv[1],"rb");
fseek(f,0,SEEK_END);
uint32 size = ftell(f);
buf = new char[size];
fseek(f,0,SEEK_SET);
-
+
int result = fread(buf,1,size,f);
assert(result==size);
-
- Set* ourSet = new Set(buf);
- cout << ourSet->MakeVeryLongString();
+ Data *data = new Data(buf);
+ Set* ourSet = new Set(data);
+ delete data;
+ delete buf;
+ cout << ourSet->ToString();
}
Commit: eee3f76b534b011877e8278e5b694fadeb113f71
https://github.com/scummvm/scummvm-tools/commit/eee3f76b534b011877e8278e5b694fadeb113f71
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-04-30T03:56:19+02:00
Commit Message:
Added rudimentary zlib-support to til2bmp, please change all of that to use residuals zlib-wrapper later
Changed paths:
tools/til2bmp.cpp
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index 3a9608a99..fb214db27 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -2,6 +2,7 @@
#include <iostream>
#include <string>
#include <zlib.h>
+#include <cassert>
typedef unsigned int uint;
@@ -41,7 +42,7 @@ public:
void AddToRightOfThis(LucasBitMap* bitmap);
void AddBelowThis(LucasBitMap* bitmap);
LucasBitMap* GetSubImage(int start, int end);
- void WriteBMP(const char *name);
+ void WriteBMP(std::string name);
};
LucasBitMap::~LucasBitMap()
@@ -64,9 +65,10 @@ void LucasBitMap::MakeNewData() // If it needs deletion, please do that before
data = new char[width*height*bpp];
}
-void LucasBitMap::WriteBMP(const char *name)
+void LucasBitMap::WriteBMP(std::string name)
{
- std::fstream file(name, std::fstream::out | std::fstream::binary);
+ std::cout << "WriteBMP("<<name<<")\n";
+ std::fstream file(name.c_str(), std::fstream::out | std::fstream::binary);
BMPHeader header;
int size = width*height*4;
//header.bm = 19778;
@@ -219,13 +221,13 @@ void MakeTheBiggerPicture(LucasBitMap** bits, int numPieces, std::string name)
bits[0]->AddBelowThis(bits[3]);
delete bits[3];
- std::string filename = name+".bmp";
+ std::string filename = name;
bits[0]->WriteBMP(filename.c_str());
delete bits[0];
}
-void ProcessFile(std::fstream &til, const char* name)
+void ProcessFile(std::fstream &til, std::string name)
{
int id, bmoffset, rects, b, c;
til.read((char *)&id, 4);
@@ -245,9 +247,9 @@ void ProcessFile(std::fstream &til, const char* name)
til.read((char *)&height, 4);
unsigned int size = width*height*4;
char *data = new char[size];
- char name[32];
- sprintf(name, "%d.bmp", i);
-
+ char name2[32];
+ sprintf(name2, "%d.bmp", i);
+
til.read(data, size);
allTheData[i] = new LucasBitMap(data, width, height);
@@ -255,19 +257,74 @@ void ProcessFile(std::fstream &til, const char* name)
allTheData[i]->UpsideDown();
sizes[i] = size;
- allTheData[i]->WriteBMP(name);
+ allTheData[i]->WriteBMP(name2);
delete data;
}
MakeTheBiggerPicture(allTheData,5, name);
}
+// Borrows heavily from zLibs HowTo-guide.
+std::string decompress(std::string filename)
+{
+ Bytef* buf;
+ FILE* f;
+ std::string outfileName = filename + std::string(".bmp");
+ std::cout << "Opening : " << filename << std::endl;
+ f = fopen(filename.c_str(),"rb");
+ fseek(f,0,SEEK_END);
+ uint size = ftell(f);
+ const unsigned int block = 8192*1024;
+ buf = new unsigned char[block];
+ fseek(f,0,SEEK_SET);
+
+ char* test= new char[5];
+ test[5]='\0';
+ fread(test,1,4,f);
+ fseek(f,0,SEEK_SET);
+
+ if(strcmp(test,"TIL0"))
+ {
+
+ int success = 0;
+ z_stream_s zStream;
+ zStream.next_in = Z_NULL;
+ zStream.avail_in = 0;
+ zStream.zalloc = Z_NULL;
+ zStream.zfree = Z_NULL;
+ zStream.opaque = Z_NULL;
+
+ FILE* of = fopen(outfileName.c_str(),"wb");
+
+ success = inflateInit2(&zStream, 16+MAX_WBITS);
+
+ unsigned char* dest = new unsigned char[block]; // Please don't tell me we have larger compression-ratios than this;
+ //do{
+ zStream.avail_in = fread(buf,1,block,f);
+ zStream.next_in = buf;
+
+ zStream.avail_out = block;
+ zStream.next_out = dest;
+
+ success = inflate(&zStream, Z_NO_FLUSH);
+
+ int wroteNum = fwrite(dest,1,block-zStream.avail_out,of);
+
+ if(success != Z_STREAM_END)
+ std::cout << "Oops, more than 8 MiB needed\n";
+ return outfileName;
+ }
+ else
+ return filename;
+}
int main(int argc, char **argv)
{
- std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
+ std::string outfileName = decompress(argv[1]);
+
+ std::fstream file(outfileName.c_str(), std::fstream::in|std::fstream::binary);
if (!file.is_open()) {
std::cout << "Could not open file" << std::endl;
}
- ProcessFile(file,argv[1]);
+ ProcessFile(file,outfileName);
file.close();
}
\ No newline at end of file
Commit: 5e6fce9790e063cf260eb92cf3c930b19fb9c574
https://github.com/scummvm/scummvm-tools/commit/5e6fce9790e063cf260eb92cf3c930b19fb9c574
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2011-04-30T16:29:42+08:00
Commit Message:
til2bmp:Improved decompression
Removed a large amount of memory leaks
Changed paths:
tools/til2bmp.cpp
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index fb214db27..54e98e685 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -3,6 +3,7 @@
#include <string>
#include <zlib.h>
#include <cassert>
+#include <sstream>
typedef unsigned int uint;
@@ -24,13 +25,14 @@ struct BMPHeader
unsigned int nimpcolors;
};
+Bytef *decompress(Bytef *in, int size, int &outsize);
class LucasBitMap
{
private:
inline uint size(){ return height*width*bpp; }
public:
- char* data;
+ char *data;
unsigned int width, height, bpp;
~LucasBitMap();
LucasBitMap() : data(0), width(0), height(0), bpp(4){}
@@ -47,7 +49,7 @@ public:
LucasBitMap::~LucasBitMap()
{
- delete data;
+ delete[] data;
}
LucasBitMap::LucasBitMap(char* data, uint width, uint height,uint bpp)
@@ -56,13 +58,13 @@ LucasBitMap::LucasBitMap(char* data, uint width, uint height,uint bpp)
this->height = height;
this->bpp = bpp;
MakeNewData();
- memcpy(this->data,data,width*height*bpp);
+ memcpy(this->data, data, size());
}
void LucasBitMap::MakeNewData() // If it needs deletion, please do that before
{
- data = new char[width*height*bpp];
+ data = new char[size()];
}
void LucasBitMap::WriteBMP(std::string name)
@@ -97,7 +99,8 @@ void LucasBitMap::AdjustHeight(int newHeight)
UpsideDown();
height = newHeight;
char *newData = new char[size()];
- memcpy(newData,data,size());
+ memcpy(newData, data, size());
+ delete[] data;
data = newData;
UpsideDown();
}
@@ -105,9 +108,9 @@ void LucasBitMap::AdjustHeight(int newHeight)
void LucasBitMap::BGR2RGB()
{
int end = size();
- for(int i=0;i<end;i+=4)
+ for(int i = 0; i < end; i += 4)
{
- int temp = data[i+2];
+ char temp = data[i+2];
data[i+2] = data[i];
data[i] = temp;
}
@@ -122,14 +125,14 @@ void LucasBitMap::UpsideDown()
{
unsigned lineLength = width*4;
char* fixedData = new char[size()];
- for(int i=0;i<height;i++)
+ for(uint i = 0; i < height; i++)
{
char* to = GetLine(i,fixedData, width);
char* from = GetLine(height-i-1,data, width);
memcpy(to,from,lineLength);
}
- memcpy(data,fixedData,size());
- delete fixedData;
+ memcpy(data, fixedData, size());
+ delete[] fixedData;
}
void LucasBitMap::AddToRightOfThis(LucasBitMap* bitmap)
@@ -139,7 +142,7 @@ void LucasBitMap::AddToRightOfThis(LucasBitMap* bitmap)
int newSize = size() + bitmap->size();
char* dest = new char[newSize];
int newWidth = bitmap->width+width;
- for(int i=0; i < height; i++)
+ for(uint i = 0; i < height; i++)
{
char *part1 = GetLine(i,data,width);
char *part2 = GetLine(i,bitmap->data,bitmap->width);
@@ -147,10 +150,11 @@ void LucasBitMap::AddToRightOfThis(LucasBitMap* bitmap)
memcpy(to,part1,width*4);
memcpy(to+width*4,part2,bitmap->width*4);
}
- delete data;
+ delete[] data;
width+=bitmap->width;
MakeNewData();
memcpy(data,dest,newSize);
+ delete[] dest;
}
void LucasBitMap::AddBelowThis(LucasBitMap* bitmap)
@@ -160,7 +164,7 @@ void LucasBitMap::AddBelowThis(LucasBitMap* bitmap)
int newSize = size() + bitmap->size();
char* dest = new char[newSize];
- for(int i=0; i < bitmap->height; i++)
+ for(uint i = 0; i < bitmap->height; i++)
{
char* from = GetLine(i,bitmap->data,width);
char* to = GetLine(i,dest,width);
@@ -168,16 +172,17 @@ void LucasBitMap::AddBelowThis(LucasBitMap* bitmap)
}
char *lowerFrom = dest + bitmap->size();
- for(int i=0; i < height; i++)
+ for(uint i=0; i < height; i++)
{
char *from = GetLine(i,data,width);
char *to = GetLine(i,lowerFrom,width);
memcpy(to,from,width*4);
}
- delete data;
+ delete[] data;
height+=bitmap->height;
MakeNewData();
memcpy(data,dest,newSize);
+ delete[] dest;
}
LucasBitMap* LucasBitMap::GetSubImage(int start, int end)
@@ -186,7 +191,7 @@ LucasBitMap* LucasBitMap::GetSubImage(int start, int end)
dest->width = end-start;
dest->height = height;
dest->MakeNewData();
- for(int i=0;i<height;i++)
+ for(uint i = 0; i < height; i++)
{
char* from = GetLine(i,data,width);
char* to = GetLine(i,dest->data,dest->width);
@@ -196,7 +201,7 @@ LucasBitMap* LucasBitMap::GetSubImage(int start, int end)
}
-void MakeTheBiggerPicture(LucasBitMap** bits, int numPieces, std::string name)
+void MakeTheBiggerPicture(LucasBitMap** bits, std::string name)
{
// Get the parts that belong in the rightmost 128 pixels of the screen
// They are in tile 3, half each.
@@ -221,34 +226,37 @@ void MakeTheBiggerPicture(LucasBitMap** bits, int numPieces, std::string name)
bits[0]->AddBelowThis(bits[3]);
delete bits[3];
- std::string filename = name;
- bits[0]->WriteBMP(filename.c_str());
+ bits[0]->WriteBMP(name.c_str());
delete bits[0];
}
-void ProcessFile(std::fstream &til, std::string name)
+void ProcessFile(const char *_data, int size, std::string name)
{
+ std::stringstream til;
+ int outsize = 0;
+ Bytef *data = decompress((Bytef *)_data, size, outsize);
+ til.write((const char *)data, outsize);
+ delete[] data;
int id, bmoffset, rects, b, c;
+
til.read((char *)&id, 4);
til.read((char *)&bmoffset, 4);
til.read((char *)&rects, 4);
til.read((char *)&b, 4);
til.read((char *)&c, 4);
- til.seekg(bmoffset+128, std::ios_base::beg);
+ til.seekg(bmoffset+128, std::ios::beg);
int width = 0, height = 0;
LucasBitMap **allTheData = new LucasBitMap*[5];
int *sizes = new int[5];
- for (int i = 0; i < 6; ++i) {
+ for (int i = 0; i < 5; ++i) {
til.read((char *)&width, 4);
til.read((char *)&height, 4);
unsigned int size = width*height*4;
char *data = new char[size];
- char name2[32];
- sprintf(name2, "%d.bmp", i);
til.read(data, size);
@@ -257,74 +265,68 @@ void ProcessFile(std::fstream &til, std::string name)
allTheData[i]->UpsideDown();
sizes[i] = size;
- allTheData[i]->WriteBMP(name2);
- delete data;
+ delete[] data;
}
- MakeTheBiggerPicture(allTheData,5, name);
-
+ MakeTheBiggerPicture(allTheData, name);
+ delete[] sizes;
+ delete[] allTheData;
}
-// Borrows heavily from zLibs HowTo-guide.
-std::string decompress(std::string filename)
+
+Bytef *decompress(Bytef *in, int size, int &outsize)
{
- Bytef* buf;
- FILE* f;
- std::string outfileName = filename + std::string(".bmp");
- std::cout << "Opening : " << filename << std::endl;
- f = fopen(filename.c_str(),"rb");
- fseek(f,0,SEEK_END);
- uint size = ftell(f);
const unsigned int block = 8192*1024;
- buf = new unsigned char[block];
- fseek(f,0,SEEK_SET);
-
- char* test= new char[5];
- test[5]='\0';
- fread(test,1,4,f);
- fseek(f,0,SEEK_SET);
-
- if(strcmp(test,"TIL0"))
- {
-
- int success = 0;
- z_stream_s zStream;
- zStream.next_in = Z_NULL;
- zStream.avail_in = 0;
- zStream.zalloc = Z_NULL;
- zStream.zfree = Z_NULL;
- zStream.opaque = Z_NULL;
-
- FILE* of = fopen(outfileName.c_str(),"wb");
-
- success = inflateInit2(&zStream, 16+MAX_WBITS);
+ int success = 0;
+ z_stream_s zStream;
+ zStream.next_in = Z_NULL;
+ zStream.avail_in = 0;
+ zStream.zalloc = Z_NULL;
+ zStream.zfree = Z_NULL;
+ zStream.opaque = Z_NULL;
+
+
+ success = inflateInit2(&zStream, 16+MAX_WBITS);
- unsigned char* dest = new unsigned char[block]; // Please don't tell me we have larger compression-ratios than this;
- //do{
- zStream.avail_in = fread(buf,1,block,f);
- zStream.next_in = buf;
+ Bytef *dest = new Bytef[block]; // Please don't tell me we have larger compression-ratios than this;
+
+ zStream.avail_in = size;
+ zStream.next_in = in;
- zStream.avail_out = block;
- zStream.next_out = dest;
+ zStream.avail_out = block;
+ zStream.next_out = dest;
- success = inflate(&zStream, Z_NO_FLUSH);
+ success = inflate(&zStream, Z_NO_FLUSH);
+
+ outsize = zStream.total_out;
- int wroteNum = fwrite(dest,1,block-zStream.avail_out,of);
- if(success != Z_STREAM_END)
- std::cout << "Oops, more than 8 MiB needed\n";
- return outfileName;
+ if(success != Z_STREAM_END) {
+ std::cout << "Oops, more than 8 MiB needed\n";
+ return 0;
}
- else
- return filename;
+ return dest;
}
+
int main(int argc, char **argv)
{
- std::string outfileName = decompress(argv[1]);
-
- std::fstream file(outfileName.c_str(), std::fstream::in|std::fstream::binary);
+ if (argc < 2) {
+ std::cout << "No Argument" << std::endl;
+ return 0;
+ }
+ std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
if (!file.is_open()) {
std::cout << "Could not open file" << std::endl;
}
- ProcessFile(file,outfileName);
+ std::string outname = argv[1];
+ outname += ".bmp";
+ file.seekg(0, std::ios::end);
+ int end = (int)file.tellg();
+ file.seekg(0, std::ios::beg);
+ char *data = new char[end];
+ file.read(data, end);
file.close();
-}
\ No newline at end of file
+
+ ProcessFile(data, end, outname);
+
+ delete[] data;
+}
Commit: bf791283b45f3208187e5fc51dc02b707a6198f1
https://github.com/scummvm/scummvm-tools/commit/bf791283b45f3208187e5fc51dc02b707a6198f1
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-04-30T18:08:38+02:00
Commit Message:
Major cleanup in TIL2BMP
Changed paths:
tools/til2bmp.cpp
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index 54e98e685..0f4091540 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -3,80 +3,56 @@
#include <string>
#include <zlib.h>
#include <cassert>
+#include <sys/types.h>
#include <sstream>
-typedef unsigned int uint;
-struct BMPHeader
-{
- //unsigned short bm;
- unsigned int size;
- unsigned int reserved;
- unsigned int offset;
- unsigned int headerSize;
- int width;
- int height;
- unsigned int nplanesbpp;
- unsigned int compress_type;
- unsigned int bmp_bytesz;
- int hres;
- int vres;
- unsigned int ncolors;
- unsigned int nimpcolors;
+struct BMPHeader{
+ uint size;
+ uint reserved;
+ uint offset;
+ uint headerSize;
+ int32_t width;
+ int32_t height;
+ uint nplanesbpp;
+ uint compress_type;
+ uint bmp_bytesz;
+ int32_t hres;
+ int32_t vres;
+ uint ncolors;
+ uint nimpcolors;
};
-Bytef *decompress(Bytef *in, int size, int &outsize);
+Bytef *decompress(Bytef *in, int size, uint &outsize);
-class LucasBitMap
-{
-private:
- inline uint size(){ return height*width*bpp; }
+class LucasBitMap{
public:
char *data;
- unsigned int width, height, bpp;
- ~LucasBitMap();
+ inline uint size(){ return height*width*bpp; }
+ uint width, height, bpp;
+ ~LucasBitMap(){ delete[] data; }
LucasBitMap() : data(0), width(0), height(0), bpp(4){}
- LucasBitMap(char* data, uint width, uint height,uint bpp=4);
- void MakeNewData();
- void AdjustHeight(int newHeight);
+ LucasBitMap(char* data, uint width, uint height,uint bpp=4, bool copy=true);
+ void MakeNewData(){ data = new char[size()]; }
void BGR2RGB();
- void UpsideDown();
- void AddToRightOfThis(LucasBitMap* bitmap);
- void AddBelowThis(LucasBitMap* bitmap);
- LucasBitMap* GetSubImage(int start, int end);
- void WriteBMP(std::string name);
+ void WriteBMP(const char* name);
};
-LucasBitMap::~LucasBitMap()
-{
- delete[] data;
-}
-
-LucasBitMap::LucasBitMap(char* data, uint width, uint height,uint bpp)
-{
- this->width = width;
- this->height = height;
- this->bpp = bpp;
- MakeNewData();
- memcpy(this->data, data, size());
-}
-
-
-void LucasBitMap::MakeNewData() // If it needs deletion, please do that before
-{
- data = new char[size()];
+LucasBitMap::LucasBitMap(char* data, uint width, uint height,uint bpp, bool copy) : width(width), height(height), bpp(bpp), data(data){
+ if(data==0)
+ MakeNewData();
+ else if(copy){
+ MakeNewData();
+ memcpy(this->data, data, size());
+ }
}
-void LucasBitMap::WriteBMP(std::string name)
-{
- std::cout << "WriteBMP("<<name<<")\n";
- std::fstream file(name.c_str(), std::fstream::out | std::fstream::binary);
+void LucasBitMap::WriteBMP(const char* name){
+ std::fstream file(name, std::fstream::out | std::fstream::binary);
BMPHeader header;
- int size = width*height*4;
- //header.bm = 19778;
unsigned short bm = 19778;
file.write((char *)&bm, 2);
- header.size = size+54;
+ header.size = size()+54;
header.reserved = 0;
header.width = width;
header.height = height;
@@ -90,156 +66,80 @@ void LucasBitMap::WriteBMP(std::string name)
header.ncolors = 0;
header.nimpcolors = 0;
file.write((char *)&header, sizeof(BMPHeader));
- file.write(data, size);
+ file.write(data, size());
file.close();
}
-void LucasBitMap::AdjustHeight(int newHeight)
-{
- UpsideDown();
- height = newHeight;
- char *newData = new char[size()];
- memcpy(newData, data, size());
- delete[] data;
- data = newData;
- UpsideDown();
-}
-
-void LucasBitMap::BGR2RGB()
-{
- int end = size();
- for(int i = 0; i < end; i += 4)
- {
+void LucasBitMap::BGR2RGB(){
+ uint end = size();
+ for(uint i = 0; i < end; i += 4){
char temp = data[i+2];
data[i+2] = data[i];
data[i] = temp;
}
}
-char* GetLine(int lineNum, char* data, unsigned int width)
-{
- return data + (lineNum*(width*4));
-}
-
-void LucasBitMap::UpsideDown()
-{
- unsigned lineLength = width*4;
- char* fixedData = new char[size()];
- for(uint i = 0; i < height; i++)
- {
- char* to = GetLine(i,fixedData, width);
- char* from = GetLine(height-i-1,data, width);
- memcpy(to,from,lineLength);
- }
- memcpy(data, fixedData, size());
- delete[] fixedData;
-}
-
-void LucasBitMap::AddToRightOfThis(LucasBitMap* bitmap)
-{
- if(height != bitmap->height)
- std::cout << "WARNING, can't combine with differing heights\n";
- int newSize = size() + bitmap->size();
- char* dest = new char[newSize];
- int newWidth = bitmap->width+width;
- for(uint i = 0; i < height; i++)
- {
- char *part1 = GetLine(i,data,width);
- char *part2 = GetLine(i,bitmap->data,bitmap->width);
- char *to = GetLine(i, dest, newWidth);
- memcpy(to,part1,width*4);
- memcpy(to+width*4,part2,bitmap->width*4);
- }
- delete[] data;
- width+=bitmap->width;
- MakeNewData();
- memcpy(data,dest,newSize);
- delete[] dest;
+char* GetLine(int lineNum, LucasBitMap* bit){
+ return bit->data + (lineNum*(bit->width*4));
}
-void LucasBitMap::AddBelowThis(LucasBitMap* bitmap)
-{
- if(width != bitmap->width)
- std::cout << "WARNING, can't combine with differing widths\n";
- int newSize = size() + bitmap->size();
- char* dest = new char[newSize];
-
- for(uint i = 0; i < bitmap->height; i++)
- {
- char* from = GetLine(i,bitmap->data,width);
- char* to = GetLine(i,dest,width);
- memcpy(to,from,width*4);
- }
-
- char *lowerFrom = dest + bitmap->size();
- for(uint i=0; i < height; i++)
- {
- char *from = GetLine(i,data,width);
- char *to = GetLine(i,lowerFrom,width);
- memcpy(to,from,width*4);
- }
- delete[] data;
- height+=bitmap->height;
- MakeNewData();
- memcpy(data,dest,newSize);
- delete[] dest;
+char* GetLine(int lineNum, char* data, unsigned int width){
+ return data + (lineNum*(width*4));
}
-LucasBitMap* LucasBitMap::GetSubImage(int start, int end)
-{
- LucasBitMap *dest = new LucasBitMap();
- dest->width = end-start;
- dest->height = height;
- dest->MakeNewData();
- for(uint i = 0; i < height; i++)
- {
- char* from = GetLine(i,data,width);
- char* to = GetLine(i,dest->data,dest->width);
- memcpy(to,from+start*4,dest->width*4);
+// Expects 5 LucasBitmaps, and returns a LucasBitmap untiled.
+LucasBitMap* MakeFullPicture(LucasBitMap** bits){
+ LucasBitMap* fullImage = new LucasBitMap(0,640,480);
+
+ char* target = fullImage->data;
+ for(int i=0;i<256;i++){
+ /* This can be modified to actually use the last 32 lines.
+ * We simply put the lower half on line 223 and down to line 32,
+ * then skip the last 32.
+ * While the upper half is put on line 479 and down to line 224.
+ */
+ if(i<224){ // Skip blank space
+ target=GetLine(223-i,fullImage);
+
+ memcpy(target,GetLine(i,bits[3]),256*4);
+ target += bits[3]->width*4;
+
+ memcpy(target,GetLine(i,bits[4]),256*4);
+ target += bits[4]->width*4;
+
+ memcpy(target,GetLine(i,bits[2])+128*4,128*4);
+ target += 4*bits[2]->width/2;
+ }
+
+ // Top half of course
+
+ target = GetLine(479-i,fullImage);
+
+ memcpy(target,GetLine(i,bits[0]),256*4);
+ target += bits[0]->width*4;
+
+ memcpy(target,GetLine(i,bits[1]),256*4);
+ target += bits[1]->width*4;
+
+ memcpy(target,GetLine(i,bits[2]),128*4);
+ target += 4*bits[2]->width/2;
}
- return dest;
-}
-
-
-void MakeTheBiggerPicture(LucasBitMap** bits, std::string name)
-{
- // Get the parts that belong in the rightmost 128 pixels of the screen
- // They are in tile 3, half each.
- LucasBitMap* extra1 = bits[2]->GetSubImage(0,128);
- LucasBitMap* extra2 = bits[2]->GetSubImage(128,256);
-
- bits[0]->AddToRightOfThis(bits[1]);
- bits[0]->AddToRightOfThis(extra1);
- bits[3]->AddToRightOfThis(bits[4]);
-
-
- bits[3]->AddToRightOfThis(extra2);
- bits[3]->AdjustHeight(224);
-
- delete bits[1];
- delete bits[2];
- delete bits[4];
- delete extra1;
- delete extra2;
-
-
- bits[0]->AddBelowThis(bits[3]);
- delete bits[3];
-
- bits[0]->WriteBMP(name.c_str());
- delete bits[0];
-
+
+ fullImage->BGR2RGB();
+
+ return fullImage;
}
-void ProcessFile(const char *_data, int size, std::string name)
-{
+void ProcessFile(const char *_data, uint size, std::string name){
std::stringstream til;
- int outsize = 0;
+ uint outsize = 0;
Bytef *data = decompress((Bytef *)_data, size, outsize);
+ if(!data)
+ return;
til.write((const char *)data, outsize);
delete[] data;
- int id, bmoffset, rects, b, c;
-
+ uint id, bmoffset, rects, b, c;
+
til.read((char *)&id, 4);
til.read((char *)&bmoffset, 4);
til.read((char *)&rects, 4);
@@ -248,77 +148,77 @@ void ProcessFile(const char *_data, int size, std::string name)
til.seekg(bmoffset+128, std::ios::beg);
- int width = 0, height = 0;
+ uint width = 0, height = 0;
LucasBitMap **allTheData = new LucasBitMap*[5];
- int *sizes = new int[5];
- for (int i = 0; i < 5; ++i) {
+
+ for (uint i = 0; i < 5; ++i) {
til.read((char *)&width, 4);
til.read((char *)&height, 4);
- unsigned int size = width*height*4;
+ uint size = width*height*4;
char *data = new char[size];
til.read(data, size);
- allTheData[i] = new LucasBitMap(data, width, height);
- allTheData[i]->BGR2RGB();
- allTheData[i]->UpsideDown();
-
- sizes[i] = size;
- delete[] data;
+ allTheData[i] = new LucasBitMap(data, width, height,4,false);
+
}
- MakeTheBiggerPicture(allTheData, name);
- delete[] sizes;
+ LucasBitMap* bit = MakeFullPicture(allTheData);
+ bit->WriteBMP(name.c_str());
+
+ delete bit;
delete[] allTheData;
}
-Bytef *decompress(Bytef *in, int size, int &outsize)
-{
- const unsigned int block = 8192*1024;
+Bytef *decompress(Bytef *in, int size, uint &outsize){
+ const uint block = 8*1024*1024;
+ Bytef *dest = new Bytef[block]; // 8 MiB ought to be enough.
+
int success = 0;
z_stream_s zStream;
+
zStream.next_in = Z_NULL;
zStream.avail_in = 0;
zStream.zalloc = Z_NULL;
zStream.zfree = Z_NULL;
zStream.opaque = Z_NULL;
-
-
+
success = inflateInit2(&zStream, 16+MAX_WBITS);
-
- Bytef *dest = new Bytef[block]; // Please don't tell me we have larger compression-ratios than this;
-
+ if(success!=Z_OK){
+ std::cout << "ZLIB failed to initialize\n";
+ return 0;
+ }
zStream.avail_in = size;
zStream.next_in = in;
-
zStream.avail_out = block;
zStream.next_out = dest;
-
+
success = inflate(&zStream, Z_NO_FLUSH);
-
+
outsize = zStream.total_out;
-
-
+
if(success != Z_STREAM_END) {
- std::cout << "Oops, more than 8 MiB needed\n";
+ std::cout << "ERROR: decompressed size bigger than 8 MiB\n";
return 0;
}
return dest;
}
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv){
if (argc < 2) {
std::cout << "No Argument" << std::endl;
return 0;
}
+
std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
if (!file.is_open()) {
std::cout << "Could not open file" << std::endl;
}
+
std::string outname = argv[1];
outname += ".bmp";
+
file.seekg(0, std::ios::end);
int end = (int)file.tellg();
file.seekg(0, std::ios::beg);
@@ -327,6 +227,6 @@ int main(int argc, char **argv)
file.close();
ProcessFile(data, end, outname);
-
+
delete[] data;
}
Commit: 421a0c559ba545257595840201dc5f74e8247822
https://github.com/scummvm/scummvm-tools/commit/421a0c559ba545257595840201dc5f74e8247822
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-05-01T18:31:24+02:00
Commit Message:
reorganize a bit
Changed paths:
R COPYING.GPL
R common/sys.h
R tools/lua/lrestore.cpp
R tools/lua/lsave.cpp
AUTHORS
COPYING.LGPL
configure
tools/lua/lmem.h
tools/lua/lua.h
tools/lua/lzio.h
tools/module.mk
diff --git a/AUTHORS b/AUTHORS
index 16f334693..b251e386d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -2,25 +2,24 @@ Residual Team
*************
Project Leader
--------------
- Pawel Kolodziejski
+ Pawel Kolodziejski
Engine Teams
------------
Grim:
- James Brown - Core developer
+ James Brown - Core developer (retired)
Giulio Camuffo - Core developer
- Pawel Kolodziejski - Core developer. SMUSH, iMUSE implemention
+ Pawel Kolodziejski - Core developer
Grim Contributors:
If you have contributed to this engine then you deserve to be on this
list. Contact us and we'll add you.
Torbjorn Andersson - Various code fixes
- Ori Avtalion - Lipsync, LAF support
+ Ori Avtalion - Lipsync, LAF support, various code fixes
Marcus Comstedt - Initial Dreamcast port
Andrea Corna - Improved font support, patch extractor
Jonathan Gray - Various code fixes
- Yaron Tausky - Fixes to subtitles
Vincent Hamm - Various engine code
Erich Hoover - x86-64 fixes, various fixes and comments, menu
support, improved state support
@@ -28,60 +27,19 @@ Residual Team
Joost Peters - Various code fixes
Christian Neumair - Various optimisation patches
Daniel Schepler - Initial engine codebase, LUA support
+ Einar Johan T. Somaen - A lot of play-testing
+ Yaron Tausky - Fixes to subtitles
Pino Toscano - Debian GNU/Linux package files
Lionel Ulmer - OpenGL optimisations
ScummVM code
************
- Residual use some ScummVM code. Copyrights for this code belongs to
- persons listed below. If you are missed in this list contact us and we'll
- add you.
+ Residual use a lot of ScummVM code. For list of authors look into
+ COPYRIGHT file.
- Torbjorn Andersson
- Chris Apers
- Bertrand Augereau
- Yotam Barnoy
- James Brown
- Jamieson Christian
- David Corrales-Lopez
- Oystein Eftevaag
- Robert Goeffringmann
- Paul Gilbert
- Jonathan Gray
- Vincent Hamm
- Ruediger Hanke
- Sven Hesse
- Matthew Hoops
- Max Horn
- Florian Kagerer
- Filippos Karapetis
- Oliver Kiehl
- Pawel Kolodziejski
- Andrew Kurushin
- Vicent Marti
- Claudio Matsuoka
- Gregory Montoir
- Kostas Nakos
- Chris Page
- Willem Jan Palenstijn
- Lars Persson
- Joost Peters
- Jordi Vilalta Prat
- Kari Salminen
- Eugene Sandulenko
- Johannes Schickel
- Ludvig Strigeus
- Lionel Ulmer
- Jody Northup
- Jordi Vilalta
- Robin Watts
- agent-q
- arisme
- peres
-
-Website (code)
-**************
- Fredrik Wendel
+Website code
+************
+ Fredrik Wendel
Special thanks to
*****************
diff --git a/COPYING.GPL b/COPYING.GPL
deleted file mode 100644
index b6f92f3db..000000000
--- a/COPYING.GPL
+++ /dev/null
@@ -1,340 +0,0 @@
- 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 Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 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.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/COPYING.LGPL b/COPYING.LGPL
index 00b4fedfe..6178d5217 100644
--- a/COPYING.LGPL
+++ b/COPYING.LGPL
@@ -1,3 +1,9 @@
+NOTE: Only certain parts of the Residual project are under the GNU LGPL.
+The majority of the files are under the GNU GPL. See the headers of the
+individual files to find out the exact license.
+
+
+
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
diff --git a/common/sys.h b/common/sys.h
deleted file mode 100644
index 5fb28f7f0..000000000
--- a/common/sys.h
+++ /dev/null
@@ -1,362 +0,0 @@
-/* Residual - A 3D game interpreter
- *
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
- * file distributed with this source distribution.
- *
- * 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.
- *
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/common/sys.h $
- * $Id: sys.h 1648 2010-01-23 09:56:04Z aquadran $
- *
- */
-
-#ifndef COMMON_SYS_H
-#define COMMON_SYS_H
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <assert.h>
-#include <ctype.h>
-#include <math.h>
-
-#ifndef _MSC_VER
-#include <dirent.h>
-#include <unistd.h>
-#endif
-
-#ifdef _MSC_VER
-#pragma once
-#pragma warning( disable : 4068 ) // turn off "unknown pragma" warning
-#pragma warning( disable : 4100 ) // turn off "unreferenced formal parameter" warning
-#pragma warning( disable : 4127 ) // turn off "conditional expression is constant" warning
-#pragma warning( disable : 4189 ) // turn off "local variable is initialized but not referenced" warning
-#pragma warning( disable : 4244 ) // turn off "conversion type" warning
-#pragma warning( disable : 4250 ) // turn off "inherits via dominance" warning
-#pragma warning( disable : 4505 ) // turn off "unreferenced local function has been removed" warning
-#pragma warning( disable : 4512 ) // turn off "assignment operator could not be generated" warning
-#pragma warning( disable : 4611 ) // turn off "interaction between '_setjmp' and C++ object destruction is non-portable" warning
-#pragma warning( disable : 4800 ) // turn off "forcing value to bool 'true' or 'false' (performance warning)"
-#pragma warning( disable : 4996 ) // turn off "This function or variable may be unsafe" warning
-
-// vsnprintf is already defined in Visual Studio 2008
-#if (_MSC_VER < 1500)
- #define vsnprintf _vsnprintf
-#endif
-
-#endif
-
-#ifndef LOCAL_PI
-#define LOCAL_PI 3.14159265358979323846
-#endif
-
-// Use config.h, generated by configure
-#if defined(HAVE_CONFIG_H)
-#include "config.h"
-#endif
-
-// In the following we configure various targets, in particular those
-// which can't use our "configure" tool and hence don't use config.h.
-//
-// Some #defines that occur here frequently:
-// SYSTEM_LITTLE_ENDIAN
-// - Define this on a little endian target
-// SYSTEM_BIG_ENDIAN
-// - Define this on a big endian target
-// SYSTEM_NEED_ALIGNMENT
-// - Define this if your system has problems reading e.g. an int32 from an odd address
-// SYSTEM_DONT_DEFINE_TYPES
-// - Define this if you need to provide your own typedefs, e.g. because your
-// system headers conflict with our typenames, or because you have odd
-// type requirements.
-// SMALL_SCREEN_DEVICE
-// - ...
-// ...
-
-// We define all types in config.h, so we don't want to typedef those types
-// here again!
-#ifdef HAVE_CONFIG_H
-#define SYSTEM_DONT_DEFINE_TYPES
-#endif
-
-
-//
-// By default we try to use pragma push/pop to ensure various structs we use
-// are "packed". If your compiler doesn't support this pragma, you are in for
-// a problem. If you are lucky, there is a compiler switch, or another pragma,
-// doing the same thing -- in that case, try to modify common/pack-begin.h and
-// common/pack-end.h accordingly. Or maybe your port simply *always* packs
-// everything, in which case you could #undefine SCUMMVM_USE_PRAGMA_PACK.
-//
-// If neither is possible, tough luck. Try to contact the team, maybe we can
-// come up with a solution, though I wouldn't hold my breath on it :-/.
-//
-#define SYSTEM_USE_PRAGMA_PACK
-
-
-#if defined(__SYMBIAN32__)
-
- #define SYSTEM_LITTLE_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-
- #define SMALL_SCREEN_DEVICE
-
- // Enable Symbians own datatypes
- // This is done for two reasons
- // a) uint is already defined by Symbians libc component
- // b) Symbian is using its "own" datatyping, and the Residual port
- // should follow this to ensure the best compability possible.
- #define SYSTEM_DONT_DEFINE_TYPES
- typedef unsigned char byte;
-
- typedef unsigned char uint8;
- typedef signed char int8;
-
- typedef unsigned short int uint16;
- typedef signed short int int16;
-
- typedef unsigned long int uint32;
- typedef signed long int int32;
-
-#elif defined(_WIN32_WCE)
-
- #define strcasecmp stricmp
- #define strncasecmp strnicmp
- #define snprintf _snprintf
-
- #define SYSTEM_LITTLE_ENDIAN
-
- #ifndef __GNUC__
- #define FORCEINLINE __forceinline
- #define NORETURN_PRE __declspec(noreturn)
- #endif
- #define PLUGIN_EXPORT __declspec(dllexport)
-
- #if _WIN32_WCE < 300
- #define SMALL_SCREEN_DEVICE
- #endif
-
-#elif defined(_MSC_VER)
-
- #define strcasecmp stricmp
- #define strncasecmp strnicmp
- #define snprintf _snprintf
-
- #define SYSTEM_LITTLE_ENDIAN
-
- #define FORCEINLINE __forceinline
- #define NORETURN_PRE __declspec(noreturn)
- #define PLUGIN_EXPORT __declspec(dllexport)
-
-
-#elif defined(__MINGW32__)
-
- #define strcasecmp stricmp
- #define strncasecmp strnicmp
-
- #define SYSTEM_LITTLE_ENDIAN
-
- #define PLUGIN_EXPORT __declspec(dllexport)
-
-#elif defined(UNIX)
-
- #ifndef CONFIG_H
- /* need this for the SDL_BYTEORDER define */
- #include <SDL_byteorder.h>
-
- #if SDL_BYTEORDER == SDL_LIL_ENDIAN
- #define SCUMM_LITTLE_ENDIAN
- #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
- #define SCUMM_BIG_ENDIAN
- #else
- #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
- #endif
- #endif
-
- // You need to set this manually if necessary
-// #define SYSTEM_NEED_ALIGNMENT
-
- #if defined(__DECCXX) // Assume alpha architecture
- #define INVERSE_MKID
- #define SYSTEM_NEED_ALIGNMENT
- #endif
-
-#elif defined(__PALMOS_TRAPS__) || defined (__PALMOS_ARMLET__)
-
-#ifdef __PALMOS_ARMLET__
- #include <extras_string.h>
-#endif
- #define SYSTEM_LITTLE_ENDIAN
-
- #define strcasecmp stricmp
- #define strncasecmp strnicmp
-
- #define SYSTEM_NEED_ALIGNMENT
- #define STRINGBUFLEN 256
-
- extern const char *RESIDUAL_SAVEPATH;
-
- #if !defined(COMPILE_ZODIAC) && !defined(COMPILE_OS5)
- # define NEWGUI_256
- #else
- # undef UNUSED
- #endif
-
-#elif defined(__DC__)
-
- #define SYSTEM_LITTLE_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-
-#elif defined(__GP32__)
-
- #define strcasecmp stricmp
- #define strncasecmp strnicmp
-
- #define SYSTEM_LITTLE_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-
- // Override typenames. uint is already defined by system header files.
- #define SYSTEM_DONT_DEFINE_TYPES
- typedef unsigned char byte;
-
- typedef unsigned char uint8;
- typedef signed char int8;
-
- typedef unsigned short int uint16;
- typedef signed short int int16;
-
- typedef unsigned long int uint32;
- typedef signed long int int32;
-
-#elif defined(__PLAYSTATION2__)
-
- #define SYSTEM_LITTLE_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-#elif defined(__N64__)
-
- #define SYSTEM_BIG_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-
- #define STRINGBUFLEN 256
-
- #define SYSTEM_DONT_DEFINE_TYPES
- typedef unsigned char byte;
-
- typedef unsigned char uint8;
- typedef signed char int8;
-
- typedef unsigned short int uint16;
- typedef signed short int int16;
-
- typedef unsigned int uint32;
- typedef signed int int32;
-
- typedef unsigned long long uint64;
- typedef signed long long int64;
-
-#elif defined(__PSP__)
-
- #define SYSTEM_LITTLE_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-
-#elif defined(__amigaos4__)
-
- #define SYSTEM_BIG_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-
-#elif defined (__DS__)
-
- #define strcasecmp stricmp
- #define strncasecmp strnicmp
-
- #define SYSTEM_NEED_ALIGNMENT
- #define SYSTEM_LITTLE_ENDIAN
-
- #include "nds/jtypes.h"
-
- #define SYSTEM_DONT_DEFINE_TYPES
-
- #define STRINGBUFLEN 256
- #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
-
-#elif defined(__WII__)
-
- #define SYSTEM_BIG_ENDIAN
- #define SYSTEM_NEED_ALIGNMENT
-
-#else
- #error No system type defined
-
-#endif
-
-
-//
-// GCC specific stuff
-//
-#if defined(__GNUC__)
- #define NORETURN __attribute__((__noreturn__))
- #define PACKED_STRUCT __attribute__((packed))
- #define GCC_PRINTF(x,y) __attribute__((format(printf, x, y)))
-#else
- #define PACKED_STRUCT
- #define GCC_PRINTF(x,y)
-#endif
-
-//
-// Fallbacks / default values for various special macros
-//
-#ifndef FORCEINLINE
-#define FORCEINLINE inline
-#endif
-
-#ifndef PLUGIN_EXPORT
-#define PLUGIN_EXPORT
-#endif
-
-#ifndef NORETURN_PRE
-#define NORETURN_PRE
-#endif
-
-#ifndef NORETURN_POST
-#define NORETURN_POST
-#endif
-
-#ifndef STRINGBUFLEN
-#define STRINGBUFLEN 1024
-#endif
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 256
-#endif
-
-
-//
-// Typedef our system types unless SYSTEM_DONT_DEFINE_TYPES is set.
-//
-#ifndef SYSTEM_DONT_DEFINE_TYPES
- typedef unsigned char byte;
- typedef unsigned char uint8;
- typedef signed char int8;
- typedef unsigned short uint16;
- typedef signed short int16;
- typedef unsigned int uint32;
- typedef signed int int32;
- typedef unsigned int uint;
-#endif
-
-
-#endif // COMMON_SYS_H
diff --git a/configure b/configure
index 5db961905..e72ea1565 100755
--- a/configure
+++ b/configure
@@ -862,12 +862,12 @@ fi
#
case $_endian in
big)
- add_line_to_config_h '/* #define SYSTEM_LITTLE_ENDIAN */'
- add_line_to_config_h '#define SYSTEM_BIG_ENDIAN'
+ add_line_to_config_h '/* #define SCUMM_LITTLE_ENDIAN */'
+ add_line_to_config_h '#define SCUMM_BIG_ENDIAN'
;;
little)
- add_line_to_config_h '#define SYSTEM_LITTLE_ENDIAN'
- add_line_to_config_h '/* #define SYSTEM_BIG_ENDIAN */'
+ add_line_to_config_h '#define SCUMM_LITTLE_ENDIAN'
+ add_line_to_config_h '/* #define SCUMM_BIG_ENDIAN */'
;;
*)
exit 1
@@ -876,7 +876,7 @@ esac
add_to_config_h_if_yes $_have_x86 '#define HAVE_X86'
-add_to_config_h_if_yes $_need_memalign '#define SYSTEM_NEED_ALIGNMENT'
+add_to_config_h_if_yes $_need_memalign '#define SCUMM_NEED_ALIGNMENT'
#
# Check whether to enable a verbose build
diff --git a/tools/lua/lmem.h b/tools/lua/lmem.h
index 9ea3cbad6..12671acd8 100644
--- a/tools/lua/lmem.h
+++ b/tools/lua/lmem.h
@@ -7,7 +7,7 @@
#ifndef lmem_h
#define lmem_h
-#include "common/sys.h"
+#include "common/scummsys.h"
#ifndef NULL
diff --git a/tools/lua/lrestore.cpp b/tools/lua/lrestore.cpp
deleted file mode 100644
index 422858e26..000000000
--- a/tools/lua/lrestore.cpp
+++ /dev/null
@@ -1,579 +0,0 @@
-#include "ltask.h"
-#include "lauxlib.h"
-#include "lmem.h"
-#include "ldo.h"
-#include "ltm.h"
-#include "ltable.h"
-#include "lvm.h"
-#include "lopcodes.h"
-#include "lstring.h"
-#include "lua.h"
-
-#include "common/endian.h"
-
-RestoreCallback restoreCallbackPtr = NULL;
-
-static void restoreObjectValue(TObject *object, RestoreSint32 restoreSint32, RestoreUint32 restoreUint32) {
- object->ttype = (lua_Type)restoreSint32();
-
- switch (object->ttype) {
- case LUA_T_NUMBER:
- case LUA_T_TASK:
- {
- byte *udata = (byte *)(&object->value.n);
- uint32 v = restoreUint32();
- restoreUint32();
-#if defined(SYSTEM_LITTLE_ENDIAN)
- byte b[4];
- *(uint32 *)&b = v;
- udata[0] = b[3];
- udata[1] = b[2];
- udata[2] = b[1];
- udata[3] = b[0];
-#else
- memcpy(&udata, &v, 4);
-#endif
- }
- break;
- case LUA_T_NIL:
- {
- restoreUint32();
- restoreUint32();
- object->value.ts = NULL;
- }
- break;
- case LUA_T_ARRAY:
- {
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- object->value.a = (Hash *)makePointerFromId(ptr);
- }
- break;
- case LUA_T_USERDATA:
- case LUA_T_STRING:
- {
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- object->value.ts = (TaggedString *)makePointerFromId(ptr);
- }
- break;
- case LUA_T_PROTO:
- case LUA_T_PMARK:
- {
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- object->value.tf = (TProtoFunc *)makePointerFromId(ptr);
- }
- break;
- case LUA_T_CPROTO:
- case LUA_T_CMARK:
- {
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- object->value.f = (lua_CFunction)makePointerFromId(ptr);
- }
- break;
- case LUA_T_CLOSURE:
- case LUA_T_CLMARK:
- {
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- object->value.cl = (Closure *)makePointerFromId(ptr);
- }
- break;
- case LUA_T_LINE:
- {
- object->value.i = restoreSint32();
- restoreSint32();
- }
- break;
- case MKID_BE('ACTR'):
- case MKID_BE('COLR'):
- case MKID_BE('STAT'):
- case MKID_BE('FONT'):
- case MKID_BE('VBUF'):
- case MKID_BE('PRIM'):
- case MKID_BE('TEXT'):
- { // TODO
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- object->value.ts = (TaggedString *)makePointerFromId(ptr);
- }
- break;
- default:
- lua_error("saveObjectValue: Unsupported object type");
- }
-}
-
-struct ArrayIDObj {
- void *object;
- PointerId idObj;
-};
-
-static int sortCallback(const void *id1, const void *id2) {
-#ifdef TARGET_64BITS
- uint64 p1 = ((ArrayIDObj *)id1)->idObj.low | ((uint64)(((ArrayIDObj *)id1)->idObj.hi)) << 32;
- uint64 p2 = ((ArrayIDObj *)id2)->idObj.low | ((uint64)(((ArrayIDObj *)id2)->idObj.hi)) << 32;
- if (p1 > p2) {
- return 1;
- } else if (p1 < p2) {
- return -1;
- } else {
- return 0;
- }
-#else
- if (((ArrayIDObj *)id1)->idObj.low > ((ArrayIDObj *)id2)->idObj.low) {
- return 1;
- } else if (((ArrayIDObj *)id1)->idObj.low < ((ArrayIDObj *)id2)->idObj.low) {
- return -1;
- } else {
- return 0;
- }
-#endif
-}
-
-int32 arrayHashTablesCount = 0;
-int32 arrayProtoFuncsCount = 0;
-int32 arrayClosuresCount = 0;
-int32 arrayStringsCount = 0;
-ArrayIDObj *arrayStrings = NULL;
-ArrayIDObj *arrayHashTables = NULL;
-ArrayIDObj *arrayClosures = NULL;
-ArrayIDObj *arrayProtoFuncs = NULL;
-static bool arraysAllreadySort = false;
-
-static void recreateObj(TObject *obj) {
- if (obj->ttype == LUA_T_CPROTO) {
-#ifdef TARGET_64BITS
- uint64 id = ((uint64)(obj->value.f)) >> 16;
-#else
- uint32 id = ((uint32)(obj->value.f)) >> 16;
-#endif
- luaL_libList *list = list_of_libs;
- while (list) {
- if (id == 0)
- break;
- id--;
- list = list->next;
- }
-
-#ifdef TARGET_64BITS
- int32 numberFunc = (uint64)(obj->value.f) & 0xffff;
-#else
- int32 numberFunc = (uint32)(obj->value.f) & 0xffff;
-#endif
- if (list && id == 0 && numberFunc < list->number) {
- obj->value.f = list->list[numberFunc].func;
- } else {
- obj->value.f = NULL;
- assert(obj->value.f);
- }
- } else if (obj->ttype == LUA_T_NIL || obj->ttype == LUA_T_LINE || obj->ttype == LUA_T_NUMBER) {
- return;
- } else {
- if (obj->value.i == 0)
- return;
-
- if (!arraysAllreadySort) {
- arraysAllreadySort = true;
- qsort(arrayHashTables, arrayHashTablesCount, sizeof(ArrayIDObj), sortCallback);
- qsort(arrayProtoFuncs, arrayProtoFuncsCount, sizeof(ArrayIDObj), sortCallback);
- qsort(arrayClosures, arrayClosuresCount, sizeof(ArrayIDObj), sortCallback);
- qsort(arrayStrings, arrayStringsCount, sizeof(ArrayIDObj), sortCallback);
- }
-
- ArrayIDObj *found;
- ArrayIDObj tmpId;
- tmpId.object = NULL;
-
- switch (obj->ttype) {
- case LUA_T_PMARK:
- tmpId.idObj = makeIdFromPointer(obj->value.tf);
- found = (ArrayIDObj *)bsearch(&tmpId, arrayProtoFuncs, arrayProtoFuncsCount, sizeof(ArrayIDObj), sortCallback);
- assert(found);
- obj->value.tf = (TProtoFunc *)found->object;
- break;
- case LUA_T_USERDATA:
- tmpId.idObj = makeIdFromPointer(obj->value.ts);
- found = (ArrayIDObj *)bsearch(&tmpId, arrayStrings, arrayStringsCount, sizeof(ArrayIDObj), sortCallback);
- assert(found);
- obj->value.ts = (TaggedString *)found->object;
- break;
- case LUA_T_PROTO:
- tmpId.idObj = makeIdFromPointer(obj->value.tf);
- found = (ArrayIDObj *)bsearch(&tmpId, arrayProtoFuncs, arrayProtoFuncsCount, sizeof(ArrayIDObj), sortCallback);
- assert(found);
- obj->value.tf = (TProtoFunc *)found->object;
- break;
- case LUA_T_CLOSURE:
- tmpId.idObj = makeIdFromPointer(obj->value.cl);
- found = (ArrayIDObj *)bsearch(&tmpId, arrayClosures, arrayClosuresCount, sizeof(ArrayIDObj), sortCallback);
- assert(found);
- obj->value.cl = (Closure *)found->object;
- break;
- case LUA_T_ARRAY:
- tmpId.idObj = makeIdFromPointer(obj->value.a);
- found = (ArrayIDObj *)bsearch(&tmpId, arrayHashTables, arrayHashTablesCount, sizeof(ArrayIDObj), sortCallback);
- assert(found);
- obj->value.a = (Hash *)found->object;
- break;
- case LUA_T_STRING:
- tmpId.idObj = makeIdFromPointer(obj->value.ts);
- found = (ArrayIDObj *)bsearch(&tmpId, arrayStrings, arrayStringsCount, sizeof(ArrayIDObj), sortCallback);
- assert(found);
- obj->value.ts = (TaggedString *)found->object;
- break;
- default:
- obj->value.i = 0;
- obj->value.ts = 0;
- return;
- }
- }
-}
-
-void lua_Restore(RestoreStream restoreStream, RestoreSint32 restoreSint32, RestoreUint32 restoreUint32) {
- printf("lua_Restore() started.\n");
-
- lua_close();
- L = luaM_new(lua_State);
- lua_resetglobals();
-
- arrayStringsCount = restoreSint32();
- arrayClosuresCount = restoreSint32();
- arrayHashTablesCount = restoreSint32();
- arrayProtoFuncsCount = restoreSint32();
- int32 rootGlobalCount = restoreSint32();
-
- arrayStrings = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayStringsCount);
- ArrayIDObj *arraysObj = arrayStrings;
- int32 maxStringsLength;
- maxStringsLength = restoreSint32();
- char *tempStringBuffer = (char *)luaM_malloc(maxStringsLength);
-
- int32 i;
- for (i = 0; i < arrayStringsCount; i++) {
- arraysObj->idObj.low = restoreSint32();
- arraysObj->idObj.hi = restoreSint32();
- int32 constIndex = restoreSint32();
- lua_Type tag = (lua_Type)restoreSint32();
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
-
- TaggedString *tempString;
- if (constIndex != -1) {
- int32 length = restoreSint32();
- restoreStream(tempStringBuffer, length);
- tempString = luaS_newlstr(tempStringBuffer, length);
- tempString->u.s.globalval.ttype = tag;
- tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
- } else {
- if (tag == 0)
- tempString = luaS_createudata((void *)makePointerFromId(ptr), LUA_ANYTAG);
- else
- tempString = luaS_createudata((void *)makePointerFromId(ptr), tag);
- if (restoreCallbackPtr) {
- PointerId ptr = makeIdFromPointer(tempString->u.s.globalval.value.ts);
- ptr = restoreCallbackPtr(tempString->u.s.globalval.ttype, ptr, restoreSint32);
- tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
- }
- }
- tempString->constindex = constIndex;
- arraysObj->object = tempString;
- arraysObj++;
- }
- luaM_free(tempStringBuffer);
-
- int32 l;
- Closure *tempClosure;
- arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayClosuresCount);
- arrayClosures = arraysObj;
- for (i = 0; i < arrayClosuresCount; i++) {
- arraysObj->idObj.low = restoreSint32();
- arraysObj->idObj.hi = restoreSint32();
- int32 countElements = restoreSint32();
- tempClosure = (Closure *)luaM_malloc((countElements * sizeof(TObject)) + sizeof(Closure));
- luaO_insertlist(&L->rootcl, (GCnode *)tempClosure);
-
- tempClosure->nelems = countElements;
- for (l = 0; l <= tempClosure->nelems; l++) {
- restoreObjectValue(&tempClosure->consts[l], restoreSint32, restoreUint32);
- }
- arraysObj->object = tempClosure;
- arraysObj++;
- }
-
- Hash *tempHash;
- arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayHashTablesCount);
- arrayHashTables = arraysObj;
- for (i = 0; i < arrayHashTablesCount; i++) {
- arraysObj->idObj.low = restoreSint32();
- arraysObj->idObj.hi = restoreSint32();
- tempHash = luaM_new(Hash);
- tempHash->nhash = restoreSint32();
- tempHash->nuse = restoreSint32();
- tempHash->htag = restoreSint32();
- tempHash->node = hashnodecreate(tempHash->nhash);
- luaO_insertlist(&L->roottable, (GCnode *)tempHash);
-
- for (l = 0; l < tempHash->nuse; l++) {
- restoreObjectValue(&tempHash->node[l].ref, restoreSint32, restoreUint32);
- restoreObjectValue(&tempHash->node[l].val, restoreSint32, restoreUint32);
- }
- arraysObj->object = tempHash;
- arraysObj++;
- }
-
- TProtoFunc *tempProtoFunc;
- arrayProtoFuncs = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayProtoFuncsCount);
- arraysObj = arrayProtoFuncs;
- for (i = 0; i < arrayProtoFuncsCount; i++) {
- arraysObj->idObj.low = restoreSint32();
- arraysObj->idObj.hi = restoreSint32();
- tempProtoFunc = luaM_new(TProtoFunc);
- luaO_insertlist(&L->rootproto, (GCnode *)tempProtoFunc);
- PointerId ptr;
- ptr.low = restoreSint32();
- ptr.hi = restoreSint32();
- tempProtoFunc->fileName = (TaggedString *)makePointerFromId(ptr);
- tempProtoFunc->lineDefined = restoreSint32();
- tempProtoFunc->nconsts = restoreSint32();
- tempProtoFunc->consts = (TObject *)luaM_malloc(tempProtoFunc->nconsts * sizeof(TObject));
-
- for (l = 0; l < tempProtoFunc->nconsts; l++) {
- restoreObjectValue(&tempProtoFunc->consts[l], restoreSint32, restoreUint32);
- }
-
- int32 countVariables = restoreSint32();
- if (countVariables) {
- tempProtoFunc->locvars = (LocVar *)luaM_malloc(countVariables * sizeof(LocVar));
- } else {
- tempProtoFunc->locvars = NULL;
- }
-
- for (l = 0; l < countVariables; l++) {
- PointerId ptr;
- ptr.low = restoreSint32();
- ptr.hi = restoreSint32();
- tempProtoFunc->locvars[l].varname = (TaggedString *)makePointerFromId(ptr);
- tempProtoFunc->locvars[l].line = restoreSint32();
- }
-
- int32 codeSize = restoreSint32();
- tempProtoFunc->code = (lua_Byte *)luaM_malloc(codeSize);
- restoreStream(tempProtoFunc->code, codeSize);
- arraysObj->object = tempProtoFunc;
- arraysObj++;
- }
-
- for (i = 0; i < NUM_HASHS; i++) {
- stringtable *tempStringTable = &L->string_root[i];
- for (l = 0; l < tempStringTable->size; l++) {
- TaggedString *tempString = tempStringTable->hash[l];
- if (tempString && tempString->constindex != -1 && tempString != &EMPTY) {
- recreateObj(&tempString->u.s.globalval);
- }
- }
- }
-
- tempProtoFunc = (TProtoFunc *)L->rootproto.next;
- while (tempProtoFunc) {
- TObject tempObj;
- tempObj.value.ts = (TaggedString *)tempProtoFunc->fileName;
- tempObj.ttype = LUA_T_STRING;
- recreateObj(&tempObj);
- tempProtoFunc->fileName = (TaggedString *)tempObj.value.ts;
-
- for (i = 0; i < tempProtoFunc->nconsts; i++) {
- recreateObj(&tempProtoFunc->consts[i]);
- }
-
- if (tempProtoFunc->locvars) {
- i = 0;
- for (i = 0; tempProtoFunc->locvars[i].line != -1; i++) {
- TObject tempObj2;
- tempObj2.value.ts = tempProtoFunc->locvars[i].varname;
- tempObj2.ttype = LUA_T_STRING;
- recreateObj(&tempObj2);
- tempProtoFunc->locvars[i].varname = (TaggedString *)tempObj2.value.ts;
- }
- }
- tempProtoFunc = (TProtoFunc *)tempProtoFunc->head.next;
- }
-
- tempHash = (Hash *)L->roottable.next;
- while (tempHash) {
- for (i = 0; i < tempHash->nuse; i++) {
- recreateObj(&tempHash->node[i].ref);
- recreateObj(&tempHash->node[i].val);
- }
- Node *oldNode = tempHash->node;
- tempHash->node = hashnodecreate(tempHash->nhash);
- for (i = 0; i < tempHash->nuse; i++) {
- Node *newNode = oldNode + i;
- if (newNode->ref.ttype != LUA_T_NIL && newNode->val.ttype != LUA_T_NIL) {
- *node(tempHash, present(tempHash, &newNode->ref)) = *newNode;
- }
- }
- luaM_free(oldNode);
- tempHash = (Hash *)tempHash->head.next;
- }
-
- tempClosure = (Closure *)L->rootcl.next;
- while (tempClosure) {
- for (i = 0; i <= tempClosure->nelems; i++) {
- recreateObj(&tempClosure->consts[i]);
- }
- tempClosure = (Closure *)tempClosure->head.next;
- }
-
- TaggedString *tempListString = (TaggedString *)&(L->rootglobal);
- for (i = 0; i < rootGlobalCount; i++) {
- TObject tempObj;
- TaggedString *tempString = NULL;
- tempObj.ttype = LUA_T_STRING;
- PointerId ptr;
- ptr.low = restoreSint32();
- ptr.hi = restoreSint32();
- tempObj.value.ts = (TaggedString *)makePointerFromId(ptr);
- recreateObj(&tempObj);
- tempString = (TaggedString *)tempObj.value.ts;
- assert(tempString);
- tempListString->head.next = (GCnode *)tempString;
- tempListString = tempString;
- }
- tempListString->head.next = NULL;
-
- restoreObjectValue(&L->errorim, restoreSint32, restoreUint32);
- recreateObj(&L->errorim);
-
- L->IMtable_size = restoreSint32();
- L->IMtable = (IM *)luaM_malloc(L->IMtable_size * sizeof(IM));
- for (i = 0; i < L->IMtable_size; i++) {
- IM *im = &L->IMtable[i];
- for (l = 0; l < IM_N; l++) {
- restoreObjectValue(&im->int_method[l], restoreSint32, restoreUint32);
- recreateObj(&im->int_method[l]);
- }
- }
-
- L->last_tag = restoreSint32();
- L->refSize = restoreSint32();
- L->refArray = (ref *)luaM_malloc(L->refSize * sizeof(ref));
- for (i = 0; i < L->refSize; i++) {
- restoreObjectValue(&L->refArray[i].o, restoreSint32, restoreUint32);
- recreateObj(&L->refArray[i].o);
- L->refArray[i].status = (Status)restoreSint32();
- }
-
- L->GCthreshold = restoreSint32();
- L->nblocks = restoreSint32();
-
- L->Mbuffsize = restoreSint32();
- L->Mbuffer = (char *)luaM_malloc(L->Mbuffsize);
- restoreStream(L->Mbuffer, L->Mbuffsize);
- int32 MbaseOffset;
- MbaseOffset = restoreSint32();
- L->Mbuffbase = MbaseOffset + L->Mbuffer;
- L->Mbuffnext = restoreSint32();
-
- globalTaskSerialId = restoreSint32();
-
- lua_Task *tempTask = NULL;
- lua_Task *prevTask = L->root_task;
- int32 countTasks = restoreSint32();
- for (l = 0; l < countTasks; l++) {
- tempTask = luaM_new(lua_Task);
- memset(tempTask, 0, sizeof(lua_Task));
- prevTask->next = tempTask;
- prevTask = tempTask;
-
- int32 stackLastSize = restoreSint32();
- tempTask->stack.stack = (TObject *)luaM_malloc(stackLastSize * sizeof(TObject));
- tempTask->stack.last = tempTask->stack.stack + stackLastSize - 1;
-
- int32 stackTopSize = restoreSint32();
- tempTask->stack.top = tempTask->stack.stack + stackTopSize;
- for (i = 0; i < stackTopSize; i++) {
- restoreObjectValue(&tempTask->stack.stack[i], restoreSint32, restoreUint32);
- recreateObj(&tempTask->stack.stack[i]);
- }
-
- tempTask->Cstack.base = restoreSint32();
- tempTask->Cstack.lua2C = restoreSint32();
- tempTask->Cstack.num = restoreSint32();
-
- tempTask->numCblocks = restoreSint32();
- for (i = 0; i < tempTask->numCblocks; i++) {
- tempTask->Cblocks[i].base = restoreSint32();
- tempTask->Cblocks[i].lua2C = restoreSint32();
- tempTask->Cblocks[i].num = restoreSint32();
- }
-
- int32 pcOffset, taskCi;
- tempTask->base_ci_size = restoreSint32();
- tempTask->base_ci = (CallInfo *)luaM_malloc(tempTask->base_ci_size * sizeof(CallInfo));
- memset(tempTask->base_ci, 0, sizeof(CallInfo) * tempTask->base_ci_size);
- CallInfo *tempCi = tempTask->base_ci;
- int32 countCi = tempTask->base_ci_size / sizeof(CallInfo);
- for (i = 0; i < countCi; i++) {
- TObject tempObj;
- tempObj.ttype = LUA_T_CLOSURE;
- PointerId ptr;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- tempObj.value.cl = (Closure *)makePointerFromId(ptr);
- recreateObj(&tempObj);
- tempCi->c = (Closure *)tempObj.value.cl;
- tempObj.ttype = LUA_T_PROTO;
- ptr.low = restoreUint32();
- ptr.hi = restoreUint32();
- tempObj.value.tf = (TProtoFunc *)makePointerFromId(ptr);
- recreateObj(&tempObj);
- tempCi->tf = (TProtoFunc *)tempObj.value.tf;
-
- pcOffset = restoreSint32();
- if (pcOffset)
- tempCi->pc = tempCi->tf->code + pcOffset;
- else
- tempCi->pc = NULL;
-
- tempCi->base = restoreSint32();
- tempCi->nResults = restoreSint32();
- tempCi++;
- }
- taskCi = restoreSint32();
- tempTask->ci = tempTask->base_ci + taskCi;
- tempTask->end_ci = tempTask->base_ci + countCi;
-
- int32 Mbasepos = restoreSint32();
- tempTask->Mbuffbase = Mbasepos + tempTask->Mbuffer;
- tempTask->Mbuffnext = restoreSint32();
-
- tempTask->Tstate = (TaskState)restoreSint32();
- tempTask->id = restoreSint32();
- }
- L->last_task = tempTask;
-
- arraysAllreadySort = false;
- arrayStringsCount = 0;
- arrayHashTablesCount = 0;
- arrayClosuresCount = 0;
- arrayProtoFuncsCount = 0;
- luaM_free(arrayClosures);
- luaM_free(arrayStrings);
- luaM_free(arrayHashTables);
- luaM_free(arrayProtoFuncs);
- arrayHashTables = NULL;
- arrayClosures = NULL;
- arrayProtoFuncs = NULL;
- arrayStrings = NULL;
-
- printf("lua_Restore() finished.\n");
-}
diff --git a/tools/lua/lsave.cpp b/tools/lua/lsave.cpp
deleted file mode 100644
index 577c94b03..000000000
--- a/tools/lua/lsave.cpp
+++ /dev/null
@@ -1,423 +0,0 @@
-#include "ltask.h"
-#include "lauxlib.h"
-#include "lmem.h"
-#include "ldo.h"
-#include "ltm.h"
-#include "ltable.h"
-#include "lvm.h"
-#include "lopcodes.h"
-#include "lstring.h"
-#include "lua.h"
-
-#include "common/endian.h"
-
-PointerId makeIdFromPointer(void *ptr) {
- PointerId pointer;
-
-#ifdef TARGET_64BITS
- uint64 v = (uint64)ptr;
- pointer.low = v & 0xffffffff;
- pointer.hi = v >> 32;
-#else
- pointer.low = (uint32)ptr;
- pointer.hi = 0;
-#endif
-
- return pointer;
-}
-
-void *makePointerFromId(PointerId ptr) {
- void *pointer;
-
-#ifdef TARGET_64BITS
- uint64 v = ptr.low | ((uint64)ptr.hi << 32);
- pointer = (void *)v;
-#else
- pointer = (void *)ptr.low;
-#endif
-
- return pointer;
-}
-
-SaveCallback saveCallbackPtr = NULL;
-
-static void saveObjectValue(TObject *object, SaveSint32 saveSint32, SaveUint32 saveUint32) {
- saveSint32(object->ttype);
-
- switch (object->ttype) {
- case LUA_T_CPROTO:
- case LUA_T_CMARK:
- {
- luaL_libList *list = list_of_libs;
- int32 idObj = 0;
- while (list) {
- for (int32 l = 0; l < list->number; l++) {
- if (list->list[l].func == object->value.f) {
- idObj = (idObj << 16) | l;
- saveSint32(idObj);
- saveSint32(0);
- return;
- }
- }
- list = list->next;
- idObj++;
- }
- assert(0);
- break;
- }
- case LUA_T_NUMBER:
- case LUA_T_TASK:
- {
- byte *udata = (byte *)(&object->value.n);
- uint32 v;
-#if defined(SYSTEM_LITTLE_ENDIAN)
- byte b[4];
- b[0] = udata[3];
- b[1] = udata[2];
- b[2] = udata[1];
- b[3] = udata[0];
- v = *(uint32 *)b;
-#else
- memcpy(&v, udata, 4);
-#endif
- saveUint32(v);
- saveUint32(0);
- }
- break;
- case LUA_T_NIL:
- {
- saveUint32(0);
- saveUint32(0);
- }
- break;
- case LUA_T_ARRAY:
- {
- saveUint32(makeIdFromPointer(object->value.a).low);
- saveUint32(makeIdFromPointer(object->value.a).hi);
- }
- break;
- case LUA_T_USERDATA:
- case LUA_T_STRING:
- {
- saveUint32(makeIdFromPointer(object->value.ts).low);
- saveUint32(makeIdFromPointer(object->value.ts).hi);
- }
- break;
- case LUA_T_PROTO:
- case LUA_T_PMARK:
- {
- saveUint32(makeIdFromPointer(object->value.tf).low);
- saveUint32(makeIdFromPointer(object->value.tf).hi);
- }
- break;
- case LUA_T_CLOSURE:
- case LUA_T_CLMARK:
- {
- saveUint32(makeIdFromPointer(object->value.cl).low);
- saveUint32(makeIdFromPointer(object->value.cl).hi);
- }
- break;
- case LUA_T_LINE:
- {
- saveSint32(object->value.i);
- saveSint32(0);
- }
- break;
- case MKID_BE('ACTR'):
- case MKID_BE('COLR'):
- case MKID_BE('STAT'):
- case MKID_BE('FONT'):
- case MKID_BE('VBUF'):
- case MKID_BE('PRIM'):
- case MKID_BE('TEXT'):
- { // TODO
- saveUint32(makeIdFromPointer(object->value.ts).low);
- saveUint32(makeIdFromPointer(object->value.ts).hi);
- }
- break;
- default:
- lua_error("saveObjectValue: Unsupported object type");
- }
-}
-
-static int32 opcodeSizeTable[] = {
- 1, 2, 1, 2, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1,
- 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3,
- 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1,
- 3, 2, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 3, 1, 2, 3, 2, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 1, 1,
- 3, 2, 2, 2, 2, 3, 2, 1, 1, 1, 2, 1, 2, 1, 1, 1, 3, 2, 1, 1,
- 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2,
- 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3,
- 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 3, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 3, 2, 4, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 3, 2, 3,
- 2, 3, 2, 3, 2, 3, 2, 1, 1, 3, 2, 2, 2, 2, 3, 2, 1, 1
-};
-
-void lua_Save(SaveStream saveStream, SaveSint32 saveSint32, SaveUint32 saveUint32) {
- printf("lua_Save() started.\n");
-
- lua_collectgarbage(0);
- int32 i, l;
- int32 countElements = 0;
- int32 maxStringLength = 0;
-
-
- // Check for max length for strings and count them
- for (i = 0; i < NUM_HASHS; i++) {
- stringtable *tempStringTable = &L->string_root[i];
- for (int32 l = 0; l < tempStringTable->size; l++) {
- if (tempStringTable->hash[l] && tempStringTable->hash[l] != &EMPTY) {
- countElements++;
- if (tempStringTable->hash[l]->constindex != -1) {
- if (maxStringLength < tempStringTable->hash[l]->u.s.len) {
- maxStringLength = tempStringTable->hash[l]->u.s.len;
- }
- }
- }
- }
- }
- // save number of strings
- saveSint32(countElements);
-
-
- // save number of closures
- countElements = 0;
- GCnode *tempNode;
- tempNode = L->rootcl.next;
- while (tempNode) {
- countElements++;
- tempNode = tempNode->next;
- }
- saveSint32(countElements);
-
- // save number of tables
- countElements = 0;
- tempNode = L->roottable.next;
- while (tempNode) {
- countElements++;
- tempNode = tempNode->next;
- }
- saveSint32(countElements);
-
- // save number of prototypes
- countElements = 0;
- tempNode = L->rootproto.next;
- while (tempNode) {
- countElements++;
- tempNode = tempNode->next;
- }
- saveSint32(countElements);
-
- // save number of global strings
- countElements = 0;
- tempNode = L->rootglobal.next;
- while (tempNode) {
- countElements++;
- tempNode = tempNode->next;
- }
- saveSint32(countElements);
-
- // save maximum length for string
- saveSint32(maxStringLength);
-
- // save hash tables for strings and user data
- TaggedString *tempString;
- for (i = 0; i < NUM_HASHS; i++) {
- stringtable *tempStringTable = &L->string_root[i];
- for (l = 0; l < tempStringTable->size; l++) {
- if (tempStringTable->hash[l] && tempStringTable->hash[l] != &EMPTY) {
- tempString = tempStringTable->hash[l];
- saveUint32(makeIdFromPointer(tempString).low);
- saveUint32(makeIdFromPointer(tempString).hi);
- saveSint32(tempString->constindex);
- if (tempString->constindex != -1) {
- saveObjectValue(&tempString->u.s.globalval, saveSint32, saveUint32);
- saveSint32(tempString->u.s.len);
- saveStream(tempString->str, tempString->u.s.len);
- } else {
- if (saveCallbackPtr) {
- PointerId ptr = makeIdFromPointer(tempString->u.s.globalval.value.ts);
- ptr = saveCallbackPtr(tempString->u.s.globalval.ttype, ptr, saveSint32);
- tempString->u.s.globalval.value.ts = (TaggedString *)makePointerFromId(ptr);
- }
- saveObjectValue(&tempString->u.s.globalval, saveSint32, saveUint32);
- }
- }
- }
- }
-
- Closure *tempClosure = (Closure *)L->rootcl.next;
- while (tempClosure) {
- saveUint32(makeIdFromPointer(tempClosure).low);
- saveUint32(makeIdFromPointer(tempClosure).hi);
- saveSint32(tempClosure->nelems);
- for (i = 0; i <= tempClosure->nelems; i++) {
- saveObjectValue(&tempClosure->consts[i], saveSint32, saveUint32);
- }
- tempClosure = (Closure *)tempClosure->head.next;
- }
-
- Hash *tempHash = (Hash *)L->roottable.next;
- while (tempHash) {
- saveUint32(makeIdFromPointer(tempHash).low);
- saveUint32(makeIdFromPointer(tempHash).hi);
- saveSint32(tempHash->nhash);
- int32 countUsedHash = 0;
- for(i = 0; i < tempHash->nhash; i++) {
- Node *newNode = &tempHash->node[i];
- if (newNode->ref.ttype != LUA_T_NIL && newNode->val.ttype != LUA_T_NIL) {
- countUsedHash++;
- }
- }
- saveSint32(countUsedHash);
- saveSint32(tempHash->htag);
- for (i = 0; i < tempHash->nhash; i++) {
- Node *newNode = &tempHash->node[i];
- if (newNode->ref.ttype != LUA_T_NIL && newNode->val.ttype != LUA_T_NIL) {
- saveObjectValue(&tempHash->node[i].ref, saveSint32, saveUint32);
- saveObjectValue(&tempHash->node[i].val, saveSint32, saveUint32);
- }
- }
- tempHash = (Hash *)tempHash->head.next;
- }
-
- TProtoFunc *tempProtoFunc = (TProtoFunc *)L->rootproto.next;
- while (tempProtoFunc) {
- saveUint32(makeIdFromPointer(tempProtoFunc).low);
- saveUint32(makeIdFromPointer(tempProtoFunc).hi);
- saveUint32(makeIdFromPointer(tempProtoFunc->fileName).low);
- saveUint32(makeIdFromPointer(tempProtoFunc->fileName).hi);
- saveSint32(tempProtoFunc->lineDefined);
- saveSint32(tempProtoFunc->nconsts);
- for (i = 0; i < tempProtoFunc->nconsts; i++) {
- saveObjectValue(&tempProtoFunc->consts[i], saveSint32, saveUint32);
- }
- int32 countVariables = 0;
- if (tempProtoFunc->locvars) {
- for (; tempProtoFunc->locvars[countVariables++].line != -1;) { }
- }
-
- saveSint32(countVariables);
- for (i = 0; i < countVariables; i++) {
- saveUint32(makeIdFromPointer(tempProtoFunc->locvars[i].varname).low);
- saveUint32(makeIdFromPointer(tempProtoFunc->locvars[i].varname).hi);
- saveSint32(tempProtoFunc->locvars[i].line);
- }
-
- Byte *codePtr = tempProtoFunc->code + 2;
- Byte *tmpPtr = codePtr;
- int32 opcodeId;
- do {
- opcodeId = *tmpPtr;
- tmpPtr += opcodeSizeTable[opcodeId];
- } while (opcodeId != ENDCODE);
- int32 codeSize = (tmpPtr - codePtr) + 2;
- saveSint32(codeSize);
- saveStream(tempProtoFunc->code, codeSize);
- tempProtoFunc = (TProtoFunc *)tempProtoFunc->head.next;
- }
-
- tempString = (TaggedString *)L->rootglobal.next;
- while (tempString) {
- saveUint32(makeIdFromPointer(tempString).low);
- saveUint32(makeIdFromPointer(tempString).hi);
- tempString = (TaggedString *)tempString->head.next;
- }
-
- saveObjectValue(&L->errorim, saveSint32, saveUint32);
-
- IM *tempIm = L->IMtable;
- saveSint32(L->IMtable_size);
- for (i = 0; i < L->IMtable_size; i++) {
- for (l = 0; l < IM_N; l++) {
- saveObjectValue(&tempIm->int_method[l], saveSint32, saveUint32);
- }
- tempIm++;
- }
-
- saveSint32(L->last_tag);
- saveSint32(L->refSize);
- for (i = 0 ; i < L->refSize; i++) {
- saveObjectValue(&L->refArray[i].o, saveSint32, saveUint32);
- saveSint32(L->refArray[i].status);
- }
-
- saveSint32(L->GCthreshold);
- saveSint32(L->nblocks);
-
- saveSint32(L->Mbuffsize);
- saveStream(L->Mbuffer, L->Mbuffsize);
- int32 MbaseOffset = L->Mbuffbase - L->Mbuffer;
- saveSint32(MbaseOffset);
- saveSint32(L->Mbuffnext);
-
- saveSint32(globalTaskSerialId);
-
- int32 countTasks = 0;
- lua_Task *tempTask = L->root_task->next;
- while (tempTask) {
- countTasks++;
- tempTask = tempTask->next;
- }
- saveSint32(countTasks);
-
- tempTask = L->root_task->next;
- while (tempTask) {
- int32 stackLastSize = (tempTask->stack.last - tempTask->stack.stack) + 1;
- saveSint32(stackLastSize);
- int32 stackTopSize = tempTask->stack.top - tempTask->stack.stack;
- saveSint32(stackTopSize);
- for (i = 0; i < stackTopSize; i++) {
- saveObjectValue(&tempTask->stack.stack[i], saveSint32, saveUint32);
- }
-
- saveSint32(tempTask->Cstack.base);
- saveSint32(tempTask->Cstack.lua2C);
- saveSint32(tempTask->Cstack.num);
-
- saveSint32(tempTask->numCblocks);
- for (i = 0; i < tempTask->numCblocks; i++) {
- saveSint32(tempTask->Cblocks[i].base);
- saveSint32(tempTask->Cblocks[i].lua2C);
- saveSint32(tempTask->Cblocks[i].num);
- }
-
- int32 pcOffset, taskCi = -1;
- saveSint32(tempTask->base_ci_size);
- assert(tempTask->base_ci);
- CallInfo *tempCi = tempTask->base_ci;
- int32 countCi = tempTask->base_ci_size / sizeof(CallInfo);
- for (i = 0; i < countCi; i++) {
- saveUint32(makeIdFromPointer(tempCi->c).low);
- saveUint32(makeIdFromPointer(tempCi->c).hi);
- saveUint32(makeIdFromPointer(tempCi->tf).low);
- saveUint32(makeIdFromPointer(tempCi->tf).hi);
- if (tempCi->pc && tempTask->ci->tf)
- pcOffset = tempCi->pc - tempCi->tf->code;
- else
- pcOffset = 0;
- saveSint32(pcOffset);
- saveSint32(tempCi->base);
- saveSint32(tempCi->nResults);
- if (tempCi == tempTask->ci)
- taskCi = i;
- tempCi++;
- }
- assert(taskCi != -1);
- saveSint32(taskCi);
-
- MbaseOffset = tempTask->Mbuffbase - tempTask->Mbuffer;
- saveSint32(MbaseOffset);
- saveSint32(tempTask->Mbuffnext);
-
- saveSint32(tempTask->Tstate);
- saveSint32(tempTask->id);
-
- tempTask = tempTask->next;
- }
-
- printf("lua_Save() finished.\n");
-}
diff --git a/tools/lua/lua.h b/tools/lua/lua.h
index b32cb98e6..aeb5233be 100644
--- a/tools/lua/lua.h
+++ b/tools/lua/lua.h
@@ -7,7 +7,7 @@
** See Copyright Notice at the end of this file
*/
-#include "common/sys.h"
+#include "common/scummsys.h"
#ifndef lua_h
#define lua_h
diff --git a/tools/lua/lzio.h b/tools/lua/lzio.h
index cc570a2b3..6b1ecccd9 100644
--- a/tools/lua/lzio.h
+++ b/tools/lua/lzio.h
@@ -8,7 +8,7 @@
#ifndef lzio_h
#define lzio_h
-#include <common/sys.h>
+#include "common/scummsys.h"
diff --git a/tools/module.mk b/tools/module.mk
index 7af2cbf94..0e7ef19d3 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -39,7 +39,7 @@ clean-tools:
# Build rules for the tools
#
-tools/delua$(EXEEXT): tools/delua.o
+tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common -Ltools/lua -o $@ $< -llua
Commit: 695baa76f3427478993bbea74bac543abb6fdfbf
https://github.com/scummvm/scummvm-tools/commit/695baa76f3427478993bbea74bac543abb6fdfbf
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-05-01T18:48:50+02:00
Commit Message:
added missing files
Changed paths:
A COPYING
A COPYRIGHT
A common/endian.h
A common/scummsys.h
diff --git a/COPYING b/COPYING
new file mode 100644
index 000000000..b6f92f3db
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ 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 Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 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.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/COPYRIGHT b/COPYRIGHT
new file mode 100644
index 000000000..69247ad7e
--- /dev/null
+++ b/COPYRIGHT
@@ -0,0 +1,241 @@
+Residual
+Copyright (C) 2003-2011 by the following:
+
+If you have contributed to this project then you deserve to be on this
+list. Contact us (see: AUTHORS) and we'll add you.
+
+Torbjorn Andersson
+Ori Avtalion
+James Brown
+Giulio Camuffo
+Marcus Comstedt
+Andrea Corna
+Jonathan Gray
+Vincent Hamm
+Erich Hoover
+Travis Howell
+Pawel Kolodziejski
+Joost Peters
+Christian Neumair
+Daniel Schepler
+Yaron Tausky
+Pino Toscano
+Lionel Ulmer
+
+
+
+ScummVM
+Copyright (C) 2001-2011 by the following:
+
+If you have contributed to this project then you deserve to be on this
+list. Contact us (see: AUTHORS) and we'll add you.
+
+Tore Anderson
+Torbjorn Andersson
+Chris Apers
+Ori Avtalion
+Nicolas Bacca
+Fabio Battaglia
+Bastien Bouclet
+Arnaud Boutonne
+Jurgen Braam
+Ralph Brorsen
+James Brown
+Stuart Caie
+Jamieson Christian
+Marcus Comstedt
+Paolo Costabel
+Thierry Crozat
+Ivan Dubrov
+Frantisek Dufka
+Oystein Eftevaag
+Kovacs Endre Janos
+David Eriksson
+Jerome Fisher
+Stuart George
+Paul Gilbert
+Robert Goeffringmann
+Jonathan Gray
+Benjamin Haisch
+Vincent Hamm
+Sven Hesse
+Jochen Hoenicke
+Matthew Hoops
+Max Horn
+Travis Howell
+Janne Huttunen
+Felix Jakschitsch
+Jeroen Janssen
+Willem Jan Palenstijn
+Florian Kagerer
+Filippos Karapetis
+Andreas Karlsson
+Oliver Kiehl
+Martin Kiewitz
+Pawel Kolodziejski
+Mutwin Kraus
+Andrew Kurushin
+Angus Lees
+Claudio Matsuoka
+Thomas Mayer
+Alyssa Milburn
+Neil Millstone
+Gregory Montoir
+Kostas Nakos
+Mikesch Nepomuk
+Nicolas Noble
+Lars Persson
+Joost Peters
+Tim Phillips
+Edward Rudd
+Eugene Sandulenko
+Johannes Schickel
+Won Star
+Ludvig Strigeus
+Keith Scroggins
+David Symonds
+Jordi Vilalta
+Robin Watts
+John Willis
+Jezar
+n0p
+peres
+Quietust
+
+
+Patches contributed by:
+
+Laura Abbott "sageofminerva"
+Vikram Aggarwal "youngelf"
+the rara avis "theraraavis"
+Dieter Baron "dillo"
+Alban Bedel "albeu"
+Bodo Bellut "bellut"
+Bramvandijk "bramvandijk"
+Andreas Bierfert "awjb"
+Elio Blanca "eblanca76"
+David Breakey "dbreakey"
+Robert Buchholz "prendi"
+Rainer Canavan "canavan"
+Mathieu Carot "yokna"
+Stefano Ceccherini "jackburton"
+Travis S Coady "theealien"
+Josh Coalson "jcoalson"
+Thomas Combeleran "hibernatus"
+Kees Cook "keescook"
+Carlos Corbacho "cathectic"
+Roberto Costa "fiix76"
+dc france "erwan2004"
+dewt "mncl"
+Martin Doucha "next_ghost"
+Michael Drueing "doc_wagon"
+Michael du Breuil "WickedShell"
+dubsdj
+Matthew Duggan "stauff1"
+Olivier Duverne "richiefs"
+Andrei Dziahel "develop7"
+John Eckerdal "johneck"
+Thomas Fach-Pedersen "madm00se"
+Florent "flobo"
+Florob "florob"
+Mike Frysinger "vapier"
+Chris Gelatt "kreeblah"
+Jens Georg "phako"
+Nicolas George "cigaes"
+Jonathan Gevaryahu "lord_nightmare"
+Tobias Gruetzmacher "tobig"
+Damien Guard "damienguard"
+Tobias Gunkel "tobigun"
+Matti Hamalainen "ccrtnsp"
+Matt Hargett "matt_hargett"
+Stefan Haubenthal "polluks"
+Alexander Holler "holler"
+Falk Hueffner "mellum"
+Casey Hutchinson "nnooiissee"
+j0tt
+Gregor Jasny "gjasny"
+Jellby "jellby"
+Joerg "macdrega"
+Matt Johnson "mattjon"
+Nicolas Joly "njoly"
+KeithS "keithscr"
+Sam Kenny "sam_k"
+Koen Kooi "koenkooi"
+Zygmunt Krynicki "zygoon"
+Janne Kujanpaa "jukuja"
+Jay Lanagan "r0ni"
+Norbert Lange "nolange"
+Manuel Lauss "mlau2"
+Rolf Leggewie "leggewie"
+Duncan Lock "dflock"
+Mark Lodato "itsr0y"
+Fridvin Logi "phillip_j_fry"
+Lostech "lostech"
+Georg Lukas "ge0rg"
+Michael Madsen "pidgeot"
+Dmitry Marakasov "amdmi3"
+Alejandro Marzini "vgvgf"
+Connor McLeod "mcleod2032"
+Mickey McMurray "metafox"
+Vladimir Menshakov "megath"
+Adam Metcalf "gamblore"
+Frank Meyering "frank_m24"
+Gael Le Migno "kilobug"
+Andy Molloy "maloi"
+Sean Murrau "lightcast"
+Armin Mueller "arm_in"
+Andrea Musuruane "musuruan"
+KO Myung-Hun "lvzuufx"
+Markus Napp "meist3r"
+Peter Naulls "pnaulls"
+Christian Neumair "mannythegnome"
+Nicos "anarxia"
+Juha Niemimaki "capehill"
+Markus Niemisto "niemisto"
+ole
+Chris Paras "paras_rasmatazz"
+Aubin Paul "outlyer"
+Vincent Pelletier "subdino"
+phi1
+Pix2 "pix2"
+Carsten Pohl "carstenpohl"
+Markus Pyykko "mankeli"
+Richard "trinity78"
+Felix Riemann "kirschsaft"
+Thomas Richter "thorfdbg"
+Timo Roehling "t1m0"
+Andreas Roever "roever"
+Jonathan Rogers "jonner"
+Marek Roth "logicdeluxe"
+Uwe Ryssel "uweryssel"
+Simon Sawatzki "simsaw"
+Scarlatti "escarlate"
+Daniel Schepler "dschepler"
+Florian Schmitt "fatpenguin"
+Mark Schreiber "mark7"
+Ben Shadwick "benshadwick"
+Jean-Yves Simon "lethalwp"
+Andrej Sinicyn "andrej4000"
+Andre Souza "luke_br"
+spookypeanut "spookypeanut"
+Steve Stavropoulos "isnothere"
+Daniel Steinberger "amorphousshape"
+Sven Strothoff "dataslayer"
+Andrea Suatoni "mrhandler"
+tbcarey
+Tim "tipabu"
+Luigi Toscano "ltosky"
+Xavier Trochu "xtrochu"
+Michal Tulacek "tutchek"
+Michael Udaltsov "cccp99"
+Kristof Vansant "lupusbe"
+Tim Walters "realmz"
+David Weinehall "weine"
+Eric A. Welsh "eweish42"
+Yudhi Widyatama "yudhi97"
+Robert Wohlrab "moshroum"
+Xanathar "xanathar"
+Grant Yeager "glo_kidd"
+Benjamin W. Zale "junior_aepi"
+Yotam Barnoy "bluddy"
+
diff --git a/common/endian.h b/common/endian.h
new file mode 100644
index 000000000..87e279ac4
--- /dev/null
+++ b/common/endian.h
@@ -0,0 +1,415 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMMON_ENDIAN_H
+#define COMMON_ENDIAN_H
+
+#include "common/scummsys.h"
+
+/**
+ * \file endian.h
+ * Endian conversion and byteswap conversion functions or macros
+ *
+ * SWAP_BYTES_??(a) - inverse byte order
+ * SWAP_CONSTANT_??(a) - inverse byte order, implemented as macro.
+ * Use with compiletime-constants only, the result will be a compiletime-constant aswell.
+ * Unlike most other functions these can be used for eg. switch-case labels
+ *
+ * READ_UINT??(a) - read native value from pointer a
+ * READ_??_UINT??(a) - read LE/BE value from pointer a and convert it to native
+ * WRITE_??_UINT??(a, v) - write native value v to pointer a with LE/BE encoding
+ * TO_??_??(a) - convert native value v to LE/BE
+ * FROM_??_??(a) - convert LE/BE value v to native
+ * CONSTANT_??_??(a) - convert LE/BE value v to native, implemented as macro.
+ * Use with compiletime-constants only, the result will be a compiletime-constant aswell.
+ * Unlike most other functions these can be used for eg. switch-case labels
+ */
+
+// Sanity check
+#if !defined(SCUMM_LITTLE_ENDIAN) && !defined(SCUMM_BIG_ENDIAN)
+# error No endianness defined
+#endif
+
+#define SWAP_CONSTANT_32(a) \
+ ((uint32)((((a) >> 24) & 0x00FF) | \
+ (((a) >> 8) & 0xFF00) | \
+ (((a) & 0xFF00) << 8) | \
+ (((a) & 0x00FF) << 24) ))
+
+#define SWAP_CONSTANT_16(a) \
+ ((uint16)((((a) >> 8) & 0x00FF) | \
+ (((a) << 8) & 0xFF00) ))
+
+/**
+ * Swap the bytes in a 32 bit word in order to convert LE encoded data to BE
+ * and vice versa.
+ */
+
+// machine/compiler-specific variants come first, fallback last
+
+// Test for GCC and if the target has the MIPS rel.2 instructions (we know the psp does)
+#if defined(__GNUC__) && (defined(__psp__) || defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2))
+
+ FORCEINLINE uint32 SWAP_BYTES_32(const uint32 a) {
+ if (__builtin_constant_p(a)) {
+ return SWAP_CONSTANT_32(a);
+ } else {
+ uint32 result;
+# if defined(__psp__)
+ // use special allegrex instruction
+ __asm__ ("wsbw %0,%1" : "=r" (result) : "r" (a));
+# else
+ __asm__ ("wsbh %0,%1\n"
+ "rotr %0,%0,16" : "=r" (result) : "r" (a));
+# endif
+ return result;
+ }
+ }
+
+// Test for GCC >= 4.3.0 as this version added the bswap builtin
+#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+
+ FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) {
+ return __builtin_bswap32(a);
+ }
+
+// test for MSVC 7 or newer
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
+
+ FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) {
+ return _byteswap_ulong(a);
+ }
+
+// generic fallback
+#else
+
+ inline uint32 SWAP_BYTES_32(uint32 a) {
+ const uint16 low = (uint16)a, high = (uint16)(a >> 16);
+ return ((uint32)(uint16)((low >> 8) | (low << 8)) << 16)
+ | (uint16)((high >> 8) | (high << 8));
+ }
+#endif
+
+/**
+ * Swap the bytes in a 16 bit word in order to convert LE encoded data to BE
+ * and vice versa.
+ */
+
+// compilerspecific variants come first, fallback last
+
+// Test for GCC and if the target has the MIPS rel.2 instructions (we know the psp does)
+#if defined(__GNUC__) && (defined(__psp__) || defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2))
+
+ FORCEINLINE uint16 SWAP_BYTES_16(const uint16 a) {
+ if (__builtin_constant_p(a)) {
+ return SWAP_CONSTANT_16(a);
+ } else {
+ uint16 result;
+ __asm__ ("wsbh %0,%1" : "=r" (result) : "r" (a));
+ return result;
+ }
+ }
+#else
+
+ inline uint16 SWAP_BYTES_16(const uint16 a) {
+ return (a >> 8) | (a << 8);
+ }
+#endif
+
+
+/**
+ * A wrapper macro used around four character constants, like 'DATA', to
+ * ensure portability. Typical usage: MKTAG('D','A','T','A').
+ *
+ * Why is this necessary? The C/C++ standard does not define the endianess to
+ * be used for character constants. Hence if one uses multi-byte character
+ * constants, a potential portability problem opens up.
+ */
+#define MKTAG(a0,a1,a2,a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
+
+// Functions for reading/writing native Integers,
+// this transparently handles the need for alignment
+
+#if !defined(SCUMM_NEED_ALIGNMENT)
+
+ FORCEINLINE uint16 READ_UINT16(const void *ptr) {
+ return *(const uint16 *)(ptr);
+ }
+
+ FORCEINLINE uint32 READ_UINT32(const void *ptr) {
+ return *(const uint32 *)(ptr);
+ }
+
+ FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) {
+ *(uint16 *)(ptr) = value;
+ }
+
+ FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) {
+ *(uint32 *)(ptr) = value;
+ }
+
+// test for GCC >= 4.0. these implementations will automatically use CPU-specific
+// instructions for unaligned data when they are available (eg. MIPS)
+#elif defined(__GNUC__) && (__GNUC__ >= 4)
+
+ FORCEINLINE uint16 READ_UINT16(const void *ptr) {
+ struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__));
+ return ((const Unaligned16 *)ptr)->val;
+ }
+
+ FORCEINLINE uint32 READ_UINT32(const void *ptr) {
+ struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__));
+ return ((const Unaligned32 *)ptr)->val;
+ }
+
+ FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) {
+ struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__));
+ ((Unaligned16 *)ptr)->val = value;
+ }
+
+ FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) {
+ struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__));
+ ((Unaligned32 *)ptr)->val = value;
+ }
+
+// use software fallback by loading each byte explicitely
+#else
+
+# if defined(SCUMM_LITTLE_ENDIAN)
+
+ inline uint16 READ_UINT16(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[1] << 8) | b[0];
+ }
+ inline uint32 READ_UINT32(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | (b[0]);
+ }
+ inline void WRITE_UINT16(void *ptr, uint16 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 0);
+ b[1] = (uint8)(value >> 8);
+ }
+ inline void WRITE_UINT32(void *ptr, uint32 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 0);
+ b[1] = (uint8)(value >> 8);
+ b[2] = (uint8)(value >> 16);
+ b[3] = (uint8)(value >> 24);
+ }
+
+# elif defined(SCUMM_BIG_ENDIAN)
+
+ inline uint16 READ_UINT16(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[0] << 8) | b[1];
+ }
+ inline uint32 READ_UINT32(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | (b[3]);
+ }
+ inline void WRITE_UINT16(void *ptr, uint16 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 8);
+ b[1] = (uint8)(value >> 0);
+ }
+ inline void WRITE_UINT32(void *ptr, uint32 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 24);
+ b[1] = (uint8)(value >> 16);
+ b[2] = (uint8)(value >> 8);
+ b[3] = (uint8)(value >> 0);
+ }
+
+# endif
+
+#endif
+
+
+// Map Funtions for reading/writing BE/LE integers depending on native endianess
+#if defined(SCUMM_LITTLE_ENDIAN)
+
+ #define READ_LE_UINT16(a) READ_UINT16(a)
+ #define READ_LE_UINT32(a) READ_UINT32(a)
+
+ #define WRITE_LE_UINT16(a, v) WRITE_UINT16(a, v)
+ #define WRITE_LE_UINT32(a, v) WRITE_UINT32(a, v)
+
+ #define FROM_LE_32(a) ((uint32)(a))
+ #define FROM_LE_16(a) ((uint16)(a))
+
+ #define FROM_BE_32(a) SWAP_BYTES_32(a)
+ #define FROM_BE_16(a) SWAP_BYTES_16(a)
+
+ #define TO_LE_32(a) ((uint32)(a))
+ #define TO_LE_16(a) ((uint16)(a))
+
+ #define TO_BE_32(a) SWAP_BYTES_32(a)
+ #define TO_BE_16(a) SWAP_BYTES_16(a)
+
+ #define CONSTANT_LE_32(a) ((uint32)(a))
+ #define CONSTANT_LE_16(a) ((uint16)(a))
+
+ #define CONSTANT_BE_32(a) SWAP_CONSTANT_32(a)
+ #define CONSTANT_BE_16(a) SWAP_CONSTANT_16(a)
+
+// if the unaligned load and the byteswap take alot instructions its better to directly read and invert
+# if defined(SCUMM_NEED_ALIGNMENT) && !defined(__mips__)
+
+ inline uint16 READ_BE_UINT16(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[0] << 8) | b[1];
+ }
+ inline uint32 READ_BE_UINT32(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | (b[3]);
+ }
+ inline void WRITE_BE_UINT16(void *ptr, uint16 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 8);
+ b[1] = (uint8)(value >> 0);
+ }
+ inline void WRITE_BE_UINT32(void *ptr, uint32 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 24);
+ b[1] = (uint8)(value >> 16);
+ b[2] = (uint8)(value >> 8);
+ b[3] = (uint8)(value >> 0);
+ }
+# else
+
+ inline uint16 READ_BE_UINT16(const void *ptr) {
+ return SWAP_BYTES_16(READ_UINT16(ptr));
+ }
+ inline uint32 READ_BE_UINT32(const void *ptr) {
+ return SWAP_BYTES_32(READ_UINT32(ptr));
+ }
+ inline void WRITE_BE_UINT16(void *ptr, uint16 value) {
+ WRITE_UINT16(ptr, SWAP_BYTES_16(value));
+ }
+ inline void WRITE_BE_UINT32(void *ptr, uint32 value) {
+ WRITE_UINT32(ptr, SWAP_BYTES_32(value));
+ }
+
+# endif // if defined(SCUMM_NEED_ALIGNMENT)
+
+#elif defined(SCUMM_BIG_ENDIAN)
+
+ #define READ_BE_UINT16(a) READ_UINT16(a)
+ #define READ_BE_UINT32(a) READ_UINT32(a)
+
+ #define WRITE_BE_UINT16(a, v) WRITE_UINT16(a, v)
+ #define WRITE_BE_UINT32(a, v) WRITE_UINT32(a, v)
+
+ #define FROM_LE_32(a) SWAP_BYTES_32(a)
+ #define FROM_LE_16(a) SWAP_BYTES_16(a)
+
+ #define FROM_BE_32(a) ((uint32)(a))
+ #define FROM_BE_16(a) ((uint16)(a))
+
+ #define TO_LE_32(a) SWAP_BYTES_32(a)
+ #define TO_LE_16(a) SWAP_BYTES_16(a)
+
+ #define TO_BE_32(a) ((uint32)(a))
+ #define TO_BE_16(a) ((uint16)(a))
+
+ #define CONSTANT_LE_32(a) SWAP_CONSTANT_32(a)
+ #define CONSTANT_LE_16(a) SWAP_CONSTANT_16(a)
+
+ #define CONSTANT_BE_32(a) ((uint32)(a))
+ #define CONSTANT_BE_16(a) ((uint16)(a))
+
+// if the unaligned load and the byteswap take alot instructions its better to directly read and invert
+# if defined(SCUMM_NEED_ALIGNMENT) && !defined(__mips__)
+
+ inline uint16 READ_LE_UINT16(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[1] << 8) | b[0];
+ }
+ inline uint32 READ_LE_UINT32(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | (b[0]);
+ }
+ inline void WRITE_LE_UINT16(void *ptr, uint16 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 0);
+ b[1] = (uint8)(value >> 8);
+ }
+ inline void WRITE_LE_UINT32(void *ptr, uint32 value) {
+ uint8 *b = (uint8 *)ptr;
+ b[0] = (uint8)(value >> 0);
+ b[1] = (uint8)(value >> 8);
+ b[2] = (uint8)(value >> 16);
+ b[3] = (uint8)(value >> 24);
+ }
+# else
+
+ inline uint16 READ_LE_UINT16(const void *ptr) {
+ return SWAP_BYTES_16(READ_UINT16(ptr));
+ }
+ inline uint32 READ_LE_UINT32(const void *ptr) {
+ return SWAP_BYTES_32(READ_UINT32(ptr));
+ }
+ inline void WRITE_LE_UINT16(void *ptr, uint16 value) {
+ WRITE_UINT16(ptr, SWAP_BYTES_16(value));
+ }
+ inline void WRITE_LE_UINT32(void *ptr, uint32 value) {
+ WRITE_UINT32(ptr, SWAP_BYTES_32(value));
+ }
+
+# endif // if defined(SCUMM_NEED_ALIGNMENT)
+
+#endif // if defined(SCUMM_LITTLE_ENDIAN)
+
+inline uint32 READ_LE_UINT24(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[2] << 16) | (b[1] << 8) | (b[0]);
+}
+
+inline uint32 READ_BE_UINT24(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
+ return (b[0] << 16) | (b[1] << 8) | (b[2]);
+}
+
+#if defined(SCUMM_BIG_ENDIAN)
+
+inline float get_float(const char *data) {
+ const unsigned char *udata = reinterpret_cast<const unsigned char *>(data);
+ unsigned char fdata[4];
+ fdata[0] = udata[3];
+ fdata[1] = udata[2];
+ fdata[2] = udata[1];
+ fdata[3] = udata[0];
+ return *(reinterpret_cast<const float *>(fdata));
+}
+
+#else
+
+inline float get_float(const char *data) {
+ return *(reinterpret_cast<const float *>(data));
+}
+#endif
+
+#endif
diff --git a/common/scummsys.h b/common/scummsys.h
new file mode 100644
index 000000000..aa074bfa7
--- /dev/null
+++ b/common/scummsys.h
@@ -0,0 +1,444 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMMON_SCUMMSYS_H
+#define COMMON_SCUMMSYS_H
+
+
+#if defined(_WIN32_WCE) && _WIN32_WCE < 300
+ #define NONSTANDARD_PORT
+#endif
+
+#if defined(NONSTANDARD_PORT)
+
+ // Ports which need to perform #includes and #defines visible in
+ // virtually all the source of ScummVM should do so by providing a
+ // "portdefs.h" header file (and not by directly modifying this
+ // header file).
+ #include <portdefs.h>
+#else // defined(NONSTANDARD_PORT)
+
+ #if defined(WIN32)
+
+ #ifdef _MSC_VER
+ // vsnprintf is already defined in Visual Studio 2008
+ #if (_MSC_VER < 1500)
+ #define vsnprintf _vsnprintf
+ #endif
+ #endif
+
+ #if !defined(_WIN32_WCE)
+
+ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+ #define NOGDICAPMASKS
+ #define OEMRESOURCE
+ #define NONLS
+ #define NOICONS
+ #define NOMCX
+ #define NOPROFILER
+ #define NOKANJI
+ #define NOSERVICE
+ #define NOMETAFILE
+ #define NOCOMM
+ #define NOCRYPT
+ #define NOIME
+ #define NOATOM
+ #define NOCTLMGR
+ #define NOCLIPBOARD
+ #define NOMEMMGR
+ #define NOSYSMETRICS
+ #define NOMENUS
+ #define NOOPENFILE
+ #define NOWH
+ #define NOSOUND
+ #define NODRAWTEXT
+
+ #endif
+
+ #if defined(ARRAYSIZE)
+ // VS2005beta2 introduces new stuff in winnt.h
+ #undef ARRAYSIZE
+ #endif
+
+ #endif
+
+ #if defined(__QNXNTO__)
+ #include <strings.h> /* For strcasecmp */
+ #endif
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <stdarg.h>
+ #include <assert.h>
+ #include <ctype.h>
+ // MSVC does not define M_PI, M_SQRT2 and other math defines by default.
+ // _USE_MATH_DEFINES must be defined in order to have these defined, thus
+ // we enable it here. For more information, check:
+ // http://msdn.microsoft.com/en-us/library/4hwaceh6(v=VS.100).aspx
+ #define _USE_MATH_DEFINES
+ #include <math.h>
+
+#endif
+
+
+
+// Use config.h, generated by configure
+#if defined(HAVE_CONFIG_H)
+#include "config.h"
+#endif
+
+// make sure we really are compiling for WIN32
+#ifndef WIN32
+#undef _MSC_VER
+#endif
+
+
+// In the following we configure various targets, in particular those
+// which can't use our "configure" tool and hence don't use config.h.
+//
+// Some #defines that occur here frequently:
+// SCUMM_LITTLE_ENDIAN
+// - Define this on a little endian target
+// SCUMM_BIG_ENDIAN
+// - Define this on a big endian target
+// SCUMM_NEED_ALIGNMENT
+// - Define this if your system has problems reading e.g. an int32 from an odd address
+// SCUMMVM_DONT_DEFINE_TYPES
+// - Define this if you need to provide your own typedefs, e.g. because your
+// system headers conflict with our typenames, or because you have odd
+// type requirements.
+// SMALL_SCREEN_DEVICE
+// - ...
+// ...
+
+// We define all types in config.h, so we don't want to typedef those types
+// here again!
+#ifdef HAVE_CONFIG_H
+#define SCUMMVM_DONT_DEFINE_TYPES
+#endif
+
+
+//
+// By default we try to use pragma push/pop to ensure various structs we use
+// are "packed". If your compiler doesn't support this pragma, you are in for
+// a problem. If you are lucky, there is a compiler switch, or another pragma,
+// doing the same thing -- in that case, try to modify common/pack-begin.h and
+// common/pack-end.h accordingly. Or maybe your port simply *always* packs
+// everything, in which case you could #undefine SCUMMVM_USE_PRAGMA_PACK.
+//
+// If neither is possible, tough luck. Try to contact the team, maybe we can
+// come up with a solution, though I wouldn't hold my breath on it :-/.
+//
+#define SCUMMVM_USE_PRAGMA_PACK
+
+
+#if defined(__SYMBIAN32__)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #define SCUMM_LITTLE_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+ #define SMALL_SCREEN_DEVICE
+
+ // Enable Symbians own datatypes
+ // This is done for two reasons
+ // a) uint is already defined by Symbians libc component
+ // b) Symbian is using its "own" datatyping, and the Scummvm port
+ // should follow this to ensure the best compability possible.
+ #define SCUMMVM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short int uint16;
+ typedef signed short int int16;
+
+ typedef unsigned long int uint32;
+ typedef signed long int int32;
+
+#elif defined(_WIN32_WCE)
+
+ #define scumm_stricmp stricmp
+ #define scumm_strnicmp _strnicmp
+ #define snprintf _snprintf
+
+ #define SCUMM_LITTLE_ENDIAN
+
+ #ifndef __GNUC__
+ #define FORCEINLINE __forceinline
+ #define NORETURN_PRE __declspec(noreturn)
+ #endif
+ #define PLUGIN_EXPORT __declspec(dllexport)
+
+ #if _WIN32_WCE < 300
+ #define SMALL_SCREEN_DEVICE
+ #endif
+
+#elif defined(_MSC_VER)
+
+ #define scumm_stricmp stricmp
+ #define scumm_strnicmp _strnicmp
+ #define snprintf _snprintf
+
+ #define SCUMM_LITTLE_ENDIAN
+
+ #define FORCEINLINE __forceinline
+ #define NORETURN_PRE __declspec(noreturn)
+ #define PLUGIN_EXPORT __declspec(dllexport)
+
+
+#elif defined(__MINGW32__)
+
+ #define scumm_stricmp stricmp
+ #define scumm_strnicmp strnicmp
+
+ #define SCUMM_LITTLE_ENDIAN
+
+ #define PLUGIN_EXPORT __declspec(dllexport)
+
+#elif defined(UNIX)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #ifndef CONFIG_H
+ /* need this for the SDL_BYTEORDER define */
+ #include <SDL_byteorder.h>
+
+ #if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ #define SCUMM_LITTLE_ENDIAN
+ #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
+ #define SCUMM_BIG_ENDIAN
+ #else
+ #error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
+ #endif
+ #endif
+
+ // You need to set this manually if necessary
+// #define SCUMM_NEED_ALIGNMENT
+
+ // Very BAD hack following, used to avoid triggering an assert in uClibc dingux library
+ // "toupper" when pressing keyboard function keys.
+ #if defined(DINGUX)
+ #undef toupper
+ #define toupper(c) (((c & 0xFF) >= 97) && ((c & 0xFF) <= 122) ? ((c & 0xFF) - 32) : (c & 0xFF))
+ #endif
+
+#elif defined(__DC__)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #define SCUMM_LITTLE_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+#elif defined(__GP32__)
+
+ #define scumm_stricmp stricmp
+ #define scumm_strnicmp strnicmp
+
+ #define SCUMM_LITTLE_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+ // Override typenames. uint is already defined by system header files.
+ #define SCUMMVM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short int uint16;
+ typedef signed short int int16;
+
+ typedef unsigned long int uint32;
+ typedef signed long int int32;
+
+#elif defined(__PLAYSTATION2__)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #define SCUMM_LITTLE_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+#elif defined(__N64__)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #define SCUMM_BIG_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+ #define STRINGBUFLEN 256
+
+ #define SCUMMVM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+
+ typedef unsigned char uint8;
+ typedef signed char int8;
+
+ typedef unsigned short int uint16;
+ typedef signed short int int16;
+
+ typedef unsigned int uint32;
+ typedef signed int int32;
+
+ typedef unsigned long long uint64;
+ typedef signed long long int64;
+
+#elif defined(__PSP__)
+
+ #include <malloc.h>
+ #include "backends/platform/psp/memory.h"
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #define SCUMM_LITTLE_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+ /* to make an efficient, inlined memcpy implementation */
+ #define memcpy(dst, src, size) psp_memcpy(dst, src, size)
+
+#elif defined(__amigaos4__)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #define SCUMM_BIG_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+#elif defined (__DS__)
+
+ #define scumm_stricmp stricmp
+ #define scumm_strnicmp strnicmp
+
+ #define SCUMM_NEED_ALIGNMENT
+ #define SCUMM_LITTLE_ENDIAN
+
+ #define SCUMMVM_DONT_DEFINE_TYPES
+
+ #define STRINGBUFLEN 256
+// #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
+
+#elif defined(__WII__)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #define SCUMM_BIG_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
+
+#else
+ #error No system type defined
+
+#endif
+
+
+//
+// GCC specific stuff
+//
+#if defined(__GNUC__)
+ #define NORETURN_POST __attribute__((__noreturn__))
+ #define PACKED_STRUCT __attribute__((__packed__))
+ #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y)))
+
+ #if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+ #define FORCEINLINE inline __attribute__((__always_inline__))
+ #endif
+#elif defined(__INTEL_COMPILER)
+ #define NORETURN_POST __attribute__((__noreturn__))
+ #define PACKED_STRUCT __attribute__((__packed__))
+ #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y)))
+#else
+ #define PACKED_STRUCT
+ #define GCC_PRINTF(x,y)
+#endif
+
+
+//
+// Fallbacks / default values for various special macros
+//
+#ifndef FORCEINLINE
+#define FORCEINLINE inline
+#endif
+
+#ifndef PLUGIN_EXPORT
+#define PLUGIN_EXPORT
+#endif
+
+#ifndef NORETURN_PRE
+#define NORETURN_PRE
+#endif
+
+#ifndef NORETURN_POST
+#define NORETURN_POST
+#endif
+
+#ifndef STRINGBUFLEN
+#define STRINGBUFLEN 1024
+#endif
+
+#ifndef LOCAL_PI
+#define LOCAL_PI 3.14159265358979323846
+#endif
+
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 256
+#endif
+
+
+//
+// Typedef our system types unless SCUMMVM_DONT_DEFINE_TYPES is set.
+//
+#ifndef SCUMMVM_DONT_DEFINE_TYPES
+ typedef unsigned char byte;
+ typedef unsigned char uint8;
+ typedef signed char int8;
+ typedef unsigned short uint16;
+ typedef signed short int16;
+ typedef unsigned int uint32;
+ typedef signed int int32;
+ typedef unsigned int uint;
+#endif
+
+
+
+//
+// Overlay color type (FIXME: shouldn't be declared here)
+//
+#if defined(NEWGUI_256)
+ // 256 color only on PalmOS
+ typedef byte OverlayColor;
+#else
+ // 15/16 bit color mode everywhere else...
+ typedef uint16 OverlayColor;
+#endif
+
+#endif
Commit: 3fdcb4cbac415e8ddd1c2b0b8790e2287f7a8535
https://github.com/scummvm/scummvm-tools/commit/3fdcb4cbac415e8ddd1c2b0b8790e2287f7a8535
Author: Quoth (el.quotho at gmail.com)
Date: 2011-05-04T23:15:00+08:00
Commit Message:
Compilation fixes: removed references to non-existent icon object in
MinGW builds; renamed variable TMP to TMPR to allow compilation with
GCC 4.4.0+
Changed paths:
configure
diff --git a/configure b/configure
old mode 100755
new mode 100644
index e72ea1565..c07640861
--- a/configure
+++ b/configure
@@ -115,9 +115,9 @@ cc_check() {
echo "$CXX $TMPC -o $TMPO$HOSTEXEEXT $@" >> "$TMPLOG"
rm -f "$TMPO$HOSTEXEEXT"
( $CXX $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
- TMP="$?"
+ TMPR="$?"
echo >> "$TMPLOG"
- return "$TMP"
+ return "$TMPR"
}
#
@@ -648,27 +648,27 @@ EOF
#
echo_n "Type with 1 byte... "
type_1_byte=`find_type_with_size 1`
-TMP="$?"
+TMPR="$?"
echo "$type_1_byte"
-test $TMP -eq 0 || exit 1 # check exit code of subshell
+test $TMPR -eq 0 || exit 1 # check exit code of subshell
echo_n "Type with 2 bytes... "
type_2_byte=`find_type_with_size 2`
-TMP="$?"
+TMPR="$?"
echo "$type_2_byte"
-test $TMP -eq 0 || exit 1 # check exit code of subshell
+test $TMPR -eq 0 || exit 1 # check exit code of subshell
echo_n "Type with 4 bytes... "
type_4_byte=`find_type_with_size 4`
-TMP="$?"
+TMPR="$?"
echo "$type_4_byte"
-test $TMP -eq 0 || exit 1 # check exit code of subshell
+test $TMPR -eq 0 || exit 1 # check exit code of subshell
echo_n "Type with 8 bytes... "
type_8_byte=`find_type_with_size 8`
-TMP="$?"
+TMPR="$?"
echo "$type_8_byte"
-if test $TMP -eq 0; then
+if test $TMPR -eq 0; then
_def_64bit_type_signed="typedef signed $type_8_byte int64;"
_def_64bit_type_unsigned="typedef unsigned $type_8_byte uint64;"
fi
@@ -746,7 +746,6 @@ case $_host_os in
mingw*)
DEFINES="$DEFINES -DWIN32 -D__USE_MINGW_ANSI_STDIO=0"
LIBS="$LIBS -lmingw32 -lwinmm"
- OBJS="$OBJS residualico.o"
;;
cygwin*)
echo ERROR: Cygwin building is not supported by ScummVM anymore. Consider using MinGW.
Commit: fc21f2dacc6b997245a66b86d660cebdcdd5486a
https://github.com/scummvm/scummvm-tools/commit/fc21f2dacc6b997245a66b86d660cebdcdd5486a
Author: Quoth (el.quotho at gmail.com)
Date: 2011-05-04T23:15:49+08:00
Commit Message:
Added .gitignore for residual-tools
Changed paths:
A .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..73e9be9bf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,19 @@
+
+*.a
+*.o
+*.exe
+
+.deps
+/config.h
+/config.log
+/config.mk
+/.cproject
+/.project
+/.settings
+
+#Ignore thumbnails created by Windows
+Thumbs.db
+
+#Ignore default Visual Studio build folders
+[Dd]ebug/
+[Rr]elease/
Commit: 1d7b07df045d5a97073fdee6bf1684f791909d66
https://github.com/scummvm/scummvm-tools/commit/1d7b07df045d5a97073fdee6bf1684f791909d66
Author: Pawel Kolodziejski (aquadran at xtr.net.pl)
Date: 2011-05-04T10:17:09-07:00
Commit Message:
Merge pull request #3 from somaen/EMI.
EMI: TIL2BMP tool.
Changed paths:
A formats/setb.txt
A tools/setb2set.cpp
A tools/til2bmp.cpp
Commit: be62b2db97ea7d7fd2ba560509b7ebbee9191643
https://github.com/scummvm/scummvm-tools/commit/be62b2db97ea7d7fd2ba560509b7ebbee9191643
Author: Pawel Kolodziejski (aquadran at xtr.net.pl)
Date: 2011-05-04T10:17:53-07:00
Commit Message:
Merge pull request #2 from elQuotho/master.
MinGW/Win32 compilation fixes
Changed paths:
A .gitignore
configure
Commit: 2a770f78297a2c26840194c08d7892fa86dfd11b
https://github.com/scummvm/scummvm-tools/commit/2a770f78297a2c26840194c08d7892fa86dfd11b
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2011-05-08T15:47:28+02:00
Commit Message:
set exec for configure
Changed paths:
configure
diff --git a/configure b/configure
old mode 100644
new mode 100755
Commit: fbd3640d60a589d820f3c3dba2dc633c914a0bff
https://github.com/scummvm/scummvm-tools/commit/fbd3640d60a589d820f3c3dba2dc633c914a0bff
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2011-05-09T00:10:31+08:00
Commit Message:
til2bmp: fixed some typing and fixed some memory leaks
Changed paths:
tools/til2bmp.cpp
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index 0f4091540..12ba9d4a4 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -5,40 +5,41 @@
#include <cassert>
#include <sys/types.h>
#include <sstream>
+#include <stdint.h>
struct BMPHeader{
- uint size;
- uint reserved;
- uint offset;
- uint headerSize;
+ uint32_t size;
+ uint32_t reserved;
+ uint32_t offset;
+ uint32_t headerSize;
int32_t width;
int32_t height;
- uint nplanesbpp;
- uint compress_type;
- uint bmp_bytesz;
+ uint32_t nplanesbpp;
+ uint32_t compress_type;
+ uint32_t bmp_bytesz;
int32_t hres;
int32_t vres;
- uint ncolors;
- uint nimpcolors;
+ uint32_t ncolors;
+ uint32_t nimpcolors;
};
-Bytef *decompress(Bytef *in, int size, uint &outsize);
+Bytef *decompress(Bytef *in, int size, uint32_t &outsize);
class LucasBitMap{
public:
char *data;
- inline uint size(){ return height*width*bpp; }
- uint width, height, bpp;
+ inline uint32_t size(){ return height*width*bpp; }
+ uint32_t width, height, bpp;
~LucasBitMap(){ delete[] data; }
LucasBitMap() : data(0), width(0), height(0), bpp(4){}
- LucasBitMap(char* data, uint width, uint height,uint bpp=4, bool copy=true);
+ LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp=4, bool copy=true);
void MakeNewData(){ data = new char[size()]; }
void BGR2RGB();
void WriteBMP(const char* name);
};
-LucasBitMap::LucasBitMap(char* data, uint width, uint height,uint bpp, bool copy) : width(width), height(height), bpp(bpp), data(data){
+LucasBitMap::LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp, bool copy) : width(width), height(height), bpp(bpp), data(data){
if(data==0)
MakeNewData();
else if(copy){
@@ -71,8 +72,8 @@ void LucasBitMap::WriteBMP(const char* name){
}
void LucasBitMap::BGR2RGB(){
- uint end = size();
- for(uint i = 0; i < end; i += 4){
+ uint32_t end = size();
+ for(uint32_t i = 0; i < end; i += 4){
char temp = data[i+2];
data[i+2] = data[i];
data[i] = temp;
@@ -130,15 +131,15 @@ LucasBitMap* MakeFullPicture(LucasBitMap** bits){
return fullImage;
}
-void ProcessFile(const char *_data, uint size, std::string name){
+void ProcessFile(const char *_data, uint32_t size, std::string name){
std::stringstream til;
- uint outsize = 0;
+ uint32_t outsize = 0;
Bytef *data = decompress((Bytef *)_data, size, outsize);
if(!data)
return;
til.write((const char *)data, outsize);
delete[] data;
- uint id, bmoffset, rects, b, c;
+ uint32_t id, bmoffset, rects, b, c;
til.read((char *)&id, 4);
til.read((char *)&bmoffset, 4);
@@ -148,14 +149,14 @@ void ProcessFile(const char *_data, uint size, std::string name){
til.seekg(bmoffset+128, std::ios::beg);
- uint width = 0, height = 0;
+ uint32_t width = 0, height = 0;
LucasBitMap **allTheData = new LucasBitMap*[5];
- for (uint i = 0; i < 5; ++i) {
+ for (uint32_t i = 0; i < 5; ++i) {
til.read((char *)&width, 4);
til.read((char *)&height, 4);
- uint size = width*height*4;
+ uint32_t size = width*height*4;
char *data = new char[size];
til.read(data, size);
@@ -166,13 +167,17 @@ void ProcessFile(const char *_data, uint size, std::string name){
LucasBitMap* bit = MakeFullPicture(allTheData);
bit->WriteBMP(name.c_str());
+ for (uint32_t i = 0; i < 5; ++i) {
+ delete allTheData[i];
+ }
+
delete bit;
delete[] allTheData;
}
-Bytef *decompress(Bytef *in, int size, uint &outsize){
- const uint block = 8*1024*1024;
+Bytef *decompress(Bytef *in, int size, uint32_t &outsize){
+ const uint32_t block = 8*1024*1024;
Bytef *dest = new Bytef[block]; // 8 MiB ought to be enough.
int success = 0;
@@ -214,6 +219,7 @@ int main(int argc, char **argv){
std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
if (!file.is_open()) {
std::cout << "Could not open file" << std::endl;
+ return 0;
}
std::string outname = argv[1];
Commit: 1d7b4d0792e3b5ae31774f626d1f699b982354b4
https://github.com/scummvm/scummvm-tools/commit/1d7b4d0792e3b5ae31774f626d1f699b982354b4
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-05-09T00:10:32+08:00
Commit Message:
TIL2BMP: Cleanup, now uses _notation for fields
Changed paths:
tools/til2bmp.cpp
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index 12ba9d4a4..795f17807 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -6,7 +6,7 @@
#include <sys/types.h>
#include <sstream>
#include <stdint.h>
-
+//#include "common/endian.h"
struct BMPHeader{
uint32_t size;
@@ -28,23 +28,23 @@ Bytef *decompress(Bytef *in, int size, uint32_t &outsize);
class LucasBitMap{
public:
- char *data;
- inline uint32_t size(){ return height*width*bpp; }
- uint32_t width, height, bpp;
- ~LucasBitMap(){ delete[] data; }
- LucasBitMap() : data(0), width(0), height(0), bpp(4){}
+ char *_data;
+ inline uint32_t size(){ return _height*_width*_bpp; }
+ uint32_t _width, _height, _bpp;
+ ~LucasBitMap(){ delete[] _data; }
+ LucasBitMap() : _data(0), _width(0), _height(0), _bpp(4){}
LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp=4, bool copy=true);
- void MakeNewData(){ data = new char[size()]; }
+ void MakeNewData(){ _data = new char[size()]; }
void BGR2RGB();
void WriteBMP(const char* name);
};
-LucasBitMap::LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp, bool copy) : width(width), height(height), bpp(bpp), data(data){
+LucasBitMap::LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp, bool copy) : _data(data), _width(width), _height(height), _bpp(bpp){
if(data==0)
MakeNewData();
else if(copy){
MakeNewData();
- memcpy(this->data, data, size());
+ memcpy(_data, data, size());
}
}
@@ -55,8 +55,8 @@ void LucasBitMap::WriteBMP(const char* name){
file.write((char *)&bm, 2);
header.size = size()+54;
header.reserved = 0;
- header.width = width;
- header.height = height;
+ header.width = _width;
+ header.height = _height;
header.offset = 54;
header.headerSize = 40;
header.nplanesbpp = 2097153;
@@ -67,21 +67,21 @@ void LucasBitMap::WriteBMP(const char* name){
header.ncolors = 0;
header.nimpcolors = 0;
file.write((char *)&header, sizeof(BMPHeader));
- file.write(data, size());
+ file.write(_data, size());
file.close();
}
void LucasBitMap::BGR2RGB(){
uint32_t end = size();
for(uint32_t i = 0; i < end; i += 4){
- char temp = data[i+2];
- data[i+2] = data[i];
- data[i] = temp;
+ char temp = _data[i+2];
+ _data[i+2] = _data[i];
+ _data[i] = temp;
}
}
char* GetLine(int lineNum, LucasBitMap* bit){
- return bit->data + (lineNum*(bit->width*4));
+ return bit->_data + (lineNum*(bit->_width*4));
}
char* GetLine(int lineNum, char* data, unsigned int width){
@@ -92,7 +92,9 @@ char* GetLine(int lineNum, char* data, unsigned int width){
LucasBitMap* MakeFullPicture(LucasBitMap** bits){
LucasBitMap* fullImage = new LucasBitMap(0,640,480);
- char* target = fullImage->data;
+ const int tWidth = 256*bits[0]->_bpp; // All of them should have the same bpp. (32)
+
+ char* target = fullImage->_data;
for(int i=0;i<256;i++){
/* This can be modified to actually use the last 32 lines.
* We simply put the lower half on line 223 and down to line 32,
@@ -102,28 +104,28 @@ LucasBitMap* MakeFullPicture(LucasBitMap** bits){
if(i<224){ // Skip blank space
target=GetLine(223-i,fullImage);
- memcpy(target,GetLine(i,bits[3]),256*4);
- target += bits[3]->width*4;
+ memcpy(target,GetLine(i,bits[3]),tWidth);
+ target += bits[3]->_width*4;
- memcpy(target,GetLine(i,bits[4]),256*4);
- target += bits[4]->width*4;
+ memcpy(target,GetLine(i,bits[4]),tWidth);
+ target += bits[4]->_width*4;
- memcpy(target,GetLine(i,bits[2])+128*4,128*4);
- target += 4*bits[2]->width/2;
+ memcpy(target,GetLine(i,bits[2])+128*4,tWidth);
+ target += 4*bits[2]->_width/2;
}
// Top half of course
target = GetLine(479-i,fullImage);
- memcpy(target,GetLine(i,bits[0]),256*4);
- target += bits[0]->width*4;
+ memcpy(target,GetLine(i,bits[0]),tWidth);
+ target += bits[0]->_width*4;
- memcpy(target,GetLine(i,bits[1]),256*4);
- target += bits[1]->width*4;
+ memcpy(target,GetLine(i,bits[1]),tWidth);
+ target += bits[1]->_width*4;
memcpy(target,GetLine(i,bits[2]),128*4);
- target += 4*bits[2]->width/2;
+ target += 4*bits[2]->_width/2;
}
fullImage->BGR2RGB();
Commit: d48c8f8618ca55e2c5643dbea274606dc7085f9c
https://github.com/scummvm/scummvm-tools/commit/d48c8f8618ca55e2c5643dbea274606dc7085f9c
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-05-09T00:10:32+08:00
Commit Message:
First version of meshb2obj.cpp
Changed paths:
A tools/meshb2obj.cpp
diff --git a/tools/meshb2obj.cpp b/tools/meshb2obj.cpp
new file mode 100644
index 000000000..dd03011bf
--- /dev/null
+++ b/tools/meshb2obj.cpp
@@ -0,0 +1,97 @@
+#include <fstream>
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char **argv) {
+ if(argc<2){
+ std::cout << "Error: filename not specified" << std::endl;
+ return 0;
+ }
+ std::string filename=argv[1];
+
+ std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!file.is_open()){
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+ int strLength = 0;
+
+ file.read((char*)&strLength,4);
+
+ char* readString = new char[64];
+ file.read(readString,strLength);
+
+ // Then a list of textures 48 bytes later
+ int numTextures = 0;
+ file.seekg(48,ios::cur);
+ file.read((char*)&numTextures,4);
+
+ char **texNames = new char*[numTextures];
+ for(int i=0;i<numTextures;i++){
+ file.read((char*)&strLength,4);
+ texNames[i] = new char[strLength];
+ file.read(texNames[i],strLength);
+ // Every texname seems to be followed by 4 0-bytes
+ file.seekg(4,ios::cur);
+ }
+ for(int i=0;i<numTextures;i++){
+ std::cout << "# TexName " << texNames[i] << std::endl;
+ }
+ // 4 unknown bytes - usually with value 19
+ file.seekg(4,ios::cur);
+ /*
+ Then follows the weird padding.
+ */
+
+ // Should create an empty mtl
+ std::cout << "mtllib quit.mtl"<<std::endl<<"o Arrow"<<std::endl;
+ // Vertices
+ // file.seekg(283);
+ int numVertices;
+ file.read((char*)&numVertices,4);
+ std::cout << "#File has " << numVertices << " Vertices" << std::endl;
+
+ //file.seekg(287);
+ float x = 0, y = 0, z = 0;
+
+ for (int i = 0; i < numVertices; ++i) {
+ file.read((char *)&x, 4);
+ file.read((char *)&y, 4);
+ file.read((char *)&z, 4);
+ std::cout << "v " << x << " " << y << " " << z << std::endl;
+ }
+
+ for (int i = 0; i < numVertices; ++i) {
+ file.read((char *)&x, 4);
+ file.read((char *)&y, 4);
+ file.read((char *)&z, 4);
+ std::cout << "vn " << x << " " << y << " " << z << std::endl;
+ }
+
+ // Actually, this file has 6*4*numVertices floats in this block.
+ std::cout<<"usemtl (null)"<<std::endl;
+ // And then another block of unknowns
+ // Faces
+ // The head of this section needs quite a bit of rechecking
+ file.seekg(36335);
+ int faceLength = 0;
+ for(int j=0;j<numTextures+1;j++){
+ file.read((char*)&faceLength,4);
+ short x = 0, y = 0, z = 0;
+ cout << "g " << j << endl;
+ for (int i = 0; i < faceLength; i+=3) {
+ file.read((char *)&x, 2);
+ file.read((char *)&y, 2);
+ file.read((char *)&z, 2);
+ ++x;
+ ++y;
+ ++z;
+ std::cout << "f " << x << "//" << x << " " << y << "//" << y << " " << z << "//" << z << std::endl;
+ }
+ // 12 bytes of unknown
+ file.seekg(12,ios::cur);
+ }
+}
\ No newline at end of file
Commit: b0860a1c5e5740a654ac5009c6fc14ee493905ab
https://github.com/scummvm/scummvm-tools/commit/b0860a1c5e5740a654ac5009c6fc14ee493905ab
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-05-09T00:10:32+08:00
Commit Message:
PS2 TILE-support, and some endianness-fixes
Changed paths:
tools/module.mk
tools/til2bmp.cpp
diff --git a/tools/module.mk b/tools/module.mk
index 0e7ef19d3..373397d82 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -15,6 +15,7 @@ TOOLS := \
tools/imc2wav$(EXEEXT) \
tools/int2flt$(EXEEXT) \
tools/set2fig$(EXEEXT) \
+ tools/til2bmp$(EXEEXT) \
tools/unlab$(EXEEXT) \
tools/vima$(EXEEXT) \
tools/patchex/patchex$(EXEEXT)
@@ -64,6 +65,10 @@ tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
+tools/til2bmp$(EXEEXT): $(srcdir)/tools/til2bmp.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) -Wall -lz -I. -o $@ $<
+
tools/unlab$(EXEEXT): $(srcdir)/tools/unlab.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index 795f17807..29aa4f0f5 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -6,7 +6,30 @@
#include <sys/types.h>
#include <sstream>
#include <stdint.h>
-//#include "common/endian.h"
+#include <cstdio>
+#include <cstring>
+#include "common/endian.h"
+
+/*
+This tool converts EMI-TILEs into BMP-files, and supports both the format used in the Windows
+Demo, as well as the PS2-format, it's worth to note that Windows uses 32-bit Bitmaps, while
+PS2 uses 16-bit bitmaps, this tool currently converts both to 32-bit BMPs, for convenience,
+since it's much easier to swap RGB to BGR that way. I might add down-converting back to 16-bit
+when I get the time. The upconverting-function MAY be off by a bit, but as far as I could understand,
+the PS2-format uses 16-bit, with alpha-bit first, then 5 bits per channel.
+
+The current implementation also has a few limitation w.r.t. if there should be TILEs that aren't 640x480.
+
+Also, I _THINK_ that it should work on Big-Endian-systems now, but I haven't gotten around to testing that yet.
+
+Usage:
+til2bmp <filename> [PS2]
+
+By default, windows-style 32-bit will try to be extracted, use PS2-flag for 16-bit operation.
+
+somaen.
+*/
+
struct BMPHeader{
uint32_t size;
@@ -34,11 +57,59 @@ public:
~LucasBitMap(){ delete[] _data; }
LucasBitMap() : _data(0), _width(0), _height(0), _bpp(4){}
LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp=4, bool copy=true);
- void MakeNewData(){ _data = new char[size()]; }
+ void MakeNewData(){
+ printf("Size: %d Bpp: %d Width: %d Height: %d\n",size(),_bpp,_width,_height);
+ _data = new char[size()];
+
+ }
void BGR2RGB();
+ void MoreBits();
+ void LessBits();
void WriteBMP(const char* name);
};
+void LucasBitMap::LessBits(){
+ printf("Not implemented\n");
+}
+
+void LucasBitMap::MoreBits(){
+ if(_bpp==2){
+ char* newData = new char[_width*_height*4];
+ char* to = newData;
+ char red=0,green=0,blue=0;
+ for(unsigned int i=0;i<_height;i++){
+ for(unsigned int j=0;j<_width;j++){
+ char byte2 = _data[i*_width*_bpp+j*2];
+ char byte1 = _data[i*_width*_bpp+j*2+1];
+ // Probably Alpha, then 555.
+ // Red
+ red = (byte1>>2)&31;
+ red = red << 3 | red >> 2;
+ // Green
+ char green1 = (byte1&3);
+ char green2 = (((byte2)>>5)&7);
+ char green3 = green1 << 3 | green2;
+ green = green3 << 3 | green3 >> 2 ;
+ // Blue
+ blue = (byte2)&31;
+ blue = blue << 3 | blue >> 2;
+ // Some more magic to stretch the values TODO
+ *to = red;
+ to++;
+ *to = green;
+ to++;
+ *to = blue;
+ to++;
+ *to = 0;
+ to++;
+ }
+ }
+ delete _data;
+ _data = newData;
+ _bpp=4;
+ }
+}
+
LucasBitMap::LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp, bool copy) : _data(data), _width(width), _height(height), _bpp(bpp){
if(data==0)
MakeNewData();
@@ -51,48 +122,57 @@ LucasBitMap::LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bp
void LucasBitMap::WriteBMP(const char* name){
std::fstream file(name, std::fstream::out | std::fstream::binary);
BMPHeader header;
- unsigned short bm = 19778;
- file.write((char *)&bm, 2);
- header.size = size()+54;
- header.reserved = 0;
- header.width = _width;
- header.height = _height;
- header.offset = 54;
- header.headerSize = 40;
- header.nplanesbpp = 2097153;
- header.compress_type = 0;
- header.bmp_bytesz = 0;
- header.hres = 2835;
- header.vres = 2835;
- header.ncolors = 0;
- header.nimpcolors = 0;
+ unsigned short bm = TO_LE_16(19778);
+ file.write((char*)&bm, 2);
+ header.size = TO_LE_32(size()+54);
+ header.reserved = TO_LE_32(0);
+ header.width = TO_LE_32(_width);
+ header.height = TO_LE_32(_height);
+ header.offset = TO_LE_32(54);
+ header.headerSize = TO_LE_32(40);
+if(_bpp==4)
+ header.nplanesbpp = TO_LE_32(2097153);
+else if(_bpp==2)
+ header.nplanesbpp = TO_LE_32(1048577);
+ header.compress_type = TO_LE_32(0);
+ header.bmp_bytesz = TO_LE_32(0);
+ header.hres = TO_LE_32(2835);
+ header.vres = TO_LE_32(2835);
+ header.ncolors = TO_LE_32(0);
+ header.nimpcolors = TO_LE_32(0);
file.write((char *)&header, sizeof(BMPHeader));
file.write(_data, size());
file.close();
}
void LucasBitMap::BGR2RGB(){
- uint32_t end = size();
- for(uint32_t i = 0; i < end; i += 4){
- char temp = _data[i+2];
- _data[i+2] = _data[i];
- _data[i] = temp;
+ if(_bpp==4){
+ uint32_t end = size();
+ for(uint32_t i = 0; i < end; i += 4){
+ char temp = _data[i+2];
+ _data[i+2] = _data[i];
+ _data[i] = temp;
+ }
+ }else if(_bpp==2){
+ MoreBits();
}
}
char* GetLine(int lineNum, LucasBitMap* bit){
- return bit->_data + (lineNum*(bit->_width*4));
+ int bpp = bit->_bpp;
+ return bit->_data + (lineNum*(bit->_width*bpp));
}
-char* GetLine(int lineNum, char* data, unsigned int width){
- return data + (lineNum*(width*4));
+char* GetLine(int lineNum, char* data, unsigned int width,int bpp){
+ return data + (lineNum*(width*bpp));
}
// Expects 5 LucasBitmaps, and returns a LucasBitmap untiled.
LucasBitMap* MakeFullPicture(LucasBitMap** bits){
- LucasBitMap* fullImage = new LucasBitMap(0,640,480);
+ LucasBitMap* fullImage = new LucasBitMap(0,640,480,bits[0]->_bpp);
const int tWidth = 256*bits[0]->_bpp; // All of them should have the same bpp. (32)
+ int bpp = bits[0]->_bpp;
char* target = fullImage->_data;
for(int i=0;i<256;i++){
@@ -105,13 +185,13 @@ LucasBitMap* MakeFullPicture(LucasBitMap** bits){
target=GetLine(223-i,fullImage);
memcpy(target,GetLine(i,bits[3]),tWidth);
- target += bits[3]->_width*4;
-
+ target += bits[3]->_width*bpp;
+
memcpy(target,GetLine(i,bits[4]),tWidth);
- target += bits[4]->_width*4;
+ target += bits[4]->_width*bpp;
- memcpy(target,GetLine(i,bits[2])+128*4,tWidth);
- target += 4*bits[2]->_width/2;
+ memcpy(target,GetLine(i,bits[2])+128*bpp,128*bpp);
+ target += bpp*bits[2]->_width/2;
}
// Top half of course
@@ -119,23 +199,23 @@ LucasBitMap* MakeFullPicture(LucasBitMap** bits){
target = GetLine(479-i,fullImage);
memcpy(target,GetLine(i,bits[0]),tWidth);
- target += bits[0]->_width*4;
+ target += bits[0]->_width*bpp;
memcpy(target,GetLine(i,bits[1]),tWidth);
- target += bits[1]->_width*4;
+ target += bits[1]->_width*bpp;
+
+ memcpy(target,GetLine(i,bits[2]),128*bpp);
+ target += bpp*bits[2]->_width/2;
- memcpy(target,GetLine(i,bits[2]),128*4);
- target += 4*bits[2]->_width/2;
}
-
fullImage->BGR2RGB();
return fullImage;
}
-void ProcessFile(const char *_data, uint32_t size, std::string name){
+void ProcessFile(const char *_data, uint32_t size, std::string name, bool ps2=false){
std::stringstream til;
- uint32_t outsize = 0;
+ uint32_t outsize = 0, bpp = 4;
Bytef *data = decompress((Bytef *)_data, size, outsize);
if(!data)
return;
@@ -143,11 +223,20 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
delete[] data;
uint32_t id, bmoffset, rects, b, c;
+ if(ps2){
+ printf("PS2 Mode\n");
+ bpp = 2;
+ }
til.read((char *)&id, 4);
+ FROM_LE_32(id);
til.read((char *)&bmoffset, 4);
+ FROM_LE_32(bmoffset);
til.read((char *)&rects, 4);
+ FROM_LE_32(rects);
til.read((char *)&b, 4);
+ FROM_LE_32(b);
til.read((char *)&c, 4);
+ FROM_LE_32(c);
til.seekg(bmoffset+128, std::ios::beg);
@@ -157,14 +246,17 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
for (uint32_t i = 0; i < 5; ++i) {
til.read((char *)&width, 4);
+ FROM_LE_32(width);
til.read((char *)&height, 4);
- uint32_t size = width*height*4;
+ FROM_LE_32(height);
+ uint32_t size = width*height*bpp;
char *data = new char[size];
-
+ char *outnamet = new char[64];
+ sprintf(outnamet,"%d.bmp",i);
til.read(data, size);
- allTheData[i] = new LucasBitMap(data, width, height,4,false);
-
+ allTheData[i] = new LucasBitMap(data, width, height,bpp,false);
+// allTheData[i]->WriteBMP(outnamet);
}
LucasBitMap* bit = MakeFullPicture(allTheData);
bit->WriteBMP(name.c_str());
@@ -215,8 +307,13 @@ Bytef *decompress(Bytef *in, int size, uint32_t &outsize){
int main(int argc, char **argv){
if (argc < 2) {
std::cout << "No Argument" << std::endl;
+ std::cout << "Usage: til2bmp <filename> [PS2]" << std::endl;
return 0;
}
+ // Cheap fix to support PS2
+ bool ps2=false;
+ if(argc>2)
+ ps2 = true;
std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
if (!file.is_open()) {
@@ -233,8 +330,7 @@ int main(int argc, char **argv){
char *data = new char[end];
file.read(data, end);
file.close();
-
- ProcessFile(data, end, outname);
+ ProcessFile(data, end, outname,ps2);
delete[] data;
}
Commit: eb11ddae637a7aaadf921bbe687cec74bac51638
https://github.com/scummvm/scummvm-tools/commit/eb11ddae637a7aaadf921bbe687cec74bac51638
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-05-09T00:10:32+08:00
Commit Message:
TIL: Added bpp-detection
Changed paths:
tools/til2bmp.cpp
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index 29aa4f0f5..f0d93a91a 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -23,9 +23,7 @@ The current implementation also has a few limitation w.r.t. if there should be T
Also, I _THINK_ that it should work on Big-Endian-systems now, but I haven't gotten around to testing that yet.
Usage:
-til2bmp <filename> [PS2]
-
-By default, windows-style 32-bit will try to be extracted, use PS2-flag for 16-bit operation.
+til2bmp <filename>
somaen.
*/
@@ -93,7 +91,7 @@ void LucasBitMap::MoreBits(){
// Blue
blue = (byte2)&31;
blue = blue << 3 | blue >> 2;
- // Some more magic to stretch the values TODO
+ // Some more magic to stretch the values
*to = red;
to++;
*to = green;
@@ -213,7 +211,7 @@ LucasBitMap* MakeFullPicture(LucasBitMap** bits){
return fullImage;
}
-void ProcessFile(const char *_data, uint32_t size, std::string name, bool ps2=false){
+void ProcessFile(const char *_data, uint32_t size, std::string name){
std::stringstream til;
uint32_t outsize = 0, bpp = 4;
Bytef *data = decompress((Bytef *)_data, size, outsize);
@@ -221,12 +219,8 @@ void ProcessFile(const char *_data, uint32_t size, std::string name, bool ps2=fa
return;
til.write((const char *)data, outsize);
delete[] data;
- uint32_t id, bmoffset, rects, b, c;
-
- if(ps2){
- printf("PS2 Mode\n");
- bpp = 2;
- }
+ uint32_t id, bmoffset, rects, b, c, numImages;
+
til.read((char *)&id, 4);
FROM_LE_32(id);
til.read((char *)&bmoffset, 4);
@@ -237,9 +231,25 @@ void ProcessFile(const char *_data, uint32_t size, std::string name, bool ps2=fa
FROM_LE_32(b);
til.read((char *)&c, 4);
FROM_LE_32(c);
-
+
+// We want to actually read numImages and bpp
+ til.seekg(bmoffset+16,std::ios::beg);
+ til.read((char*)&numImages, 4);
+ FROM_LE_32(numImages);
+
+ if(numImages < 5){
+ printf("This tile has less than 5 tiles, I don't know how to parse it\n");
+ }
+
+ til.seekg(16,std::ios::cur);
+ til.read((char*) &bpp, 4);
+ FROM_LE_32(bpp);
+ bpp = bpp/8;
+
+ printf("Detected %d bpp\n",bpp*8);
+
til.seekg(bmoffset+128, std::ios::beg);
-
+
uint32_t width = 0, height = 0;
LucasBitMap **allTheData = new LucasBitMap*[5];
@@ -330,7 +340,7 @@ int main(int argc, char **argv){
char *data = new char[end];
file.read(data, end);
file.close();
- ProcessFile(data, end, outname,ps2);
+ ProcessFile(data, end, outname);
delete[] data;
}
Commit: 6762dc02e9fc78aae94f708d60c7a0fdeb68c670
https://github.com/scummvm/scummvm-tools/commit/6762dc02e9fc78aae94f708d60c7a0fdeb68c670
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-05-09T19:01:48+08:00
Commit Message:
Removed fixed offset of Grimfandango updater
Changed paths:
tools/patchex/patchex.cpp
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index 28dd59ea4..96348aea9 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -52,9 +52,8 @@ const char *kLanguages_code[] = { "US", "FR", "GE", "IT", "PT", "SP", NULL };
#define RAND_A (0x343FD)
#define RAND_B (0x269EC3)
#define CODE_TABLE_SIZE (0x100)
-#define CONTAINER_OFFSET (0x1C000)
-#define CABINET_OFFSET (CONTAINER_OFFSET + 8)
#define CONTAINER_MAGIC "1CNT"
+#define CABINET_MAGIC "MSCF"
#define BUFFER_SIZE 102400
char lang[3];
@@ -77,6 +76,7 @@ struct mspack_file_p {
FILE *fh;
const char *name;
uint16 *CodeTable;
+ off_t cabinet_offset;
};
uint16 *create_dec_table(uint32 key) {
@@ -99,6 +99,7 @@ static struct mspack_file *res_open(struct mspack_system *handle, const char *fi
struct mspack_file_p *fh;
const char *fmode;
uint32 magic, key;
+ uint8 count;
switch (mode) {
case MSPACK_SYS_OPEN_READ: fmode = "rb"; break;
@@ -121,13 +122,26 @@ static struct mspack_file *res_open(struct mspack_system *handle, const char *fi
if (mode != MSPACK_SYS_OPEN_READ)
return (struct mspack_file *)fh;
- handle->seek((struct mspack_file *)fh, (off_t)CONTAINER_OFFSET, MSPACK_SYS_SEEK_START);
- uint8 count = handle->read((struct mspack_file *) fh, &magic, 4);
-
- if (count == 4 && memcmp(&magic, CONTAINER_MAGIC, 4) == 0) {
- handle->read((struct mspack_file *)fh, &key, 4);
- key = READ_LE_UINT32(&key);
- fh->CodeTable = create_dec_table(key);
+ //Search for data
+ while(!feof(fh->fh)) {
+ //Check for content signature
+ count = handle->read((struct mspack_file *) fh, &magic, 4);
+ if (count == 4 && memcmp(&magic, CONTAINER_MAGIC, 4) == 0) {
+ handle->read((struct mspack_file *)fh, &key, 4);
+ key = READ_LE_UINT32(&key);
+ fh->CodeTable = create_dec_table(key);
+ fh->cabinet_offset = ftell(fh->fh);
+
+ //Check for cabinet signature
+ count = handle->read((struct mspack_file *) fh, &magic, 4);
+ if (count == 4 && memcmp(&magic, CABINET_MAGIC, 4) == 0) {
+ break;
+ } else {
+ free(fh->CodeTable);
+ fh->CodeTable = NULL;
+ continue;
+ }
+ }
}
handle->seek((struct mspack_file *)fh, (off_t) 0, MSPACK_SYS_SEEK_START);
@@ -154,7 +168,7 @@ static int res_seek(struct mspack_file *file, off_t offset, int mode) {
case MSPACK_SYS_SEEK_START:
mode = SEEK_SET;
if (handle->CodeTable)
- offset += (CONTAINER_OFFSET + 8);
+ offset += handle->cabinet_offset;
break;
case MSPACK_SYS_SEEK_CUR: mode = SEEK_CUR; break;
case MSPACK_SYS_SEEK_END: mode = SEEK_END; break;
@@ -171,7 +185,7 @@ static off_t res_tell(struct mspack_file *file) {
if (handle) {
off_t offset = ftell(handle->fh);
if (handle->CodeTable)
- offset -= CABINET_OFFSET;
+ offset -= handle->cabinet_offset;
return offset;
} else
return 0;
Commit: 6e19011a8e564b50f1242fe9cc8885f93e0d1173
https://github.com/scummvm/scummvm-tools/commit/6e19011a8e564b50f1242fe9cc8885f93e0d1173
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-05-09T19:01:48+08:00
Commit Message:
Removed all files action
Changed paths:
tools/patchex/patchex.cpp
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index 96348aea9..ba5206656 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -267,7 +267,7 @@ void extract_cabinet(char *filename, unsigned int lenght) {
int count;
original_executable = res_open(&res_system, filename, MSPACK_SYS_OPEN_READ);
- destination_cabinet = res_open(&res_system, "gfupd101.cab", MSPACK_SYS_OPEN_WRITE);
+ destination_cabinet = res_open(&res_system, "original.cab", MSPACK_SYS_OPEN_WRITE);
buffer = res_alloc(NULL, BUFFER_SIZE);
copied_bytes = 0;
@@ -277,22 +277,14 @@ void extract_cabinet(char *filename, unsigned int lenght) {
res_write(destination_cabinet, buffer, count);
copied_bytes += count;
}
- printf("Update cabinet extracted as gfupd101.cab.\n");
+ printf("Update cabinet extracted as original.cab.\n");
res_free(buffer);
res_close(original_executable);
res_close(destination_cabinet);
}
-char *filter_none(struct mscabd_file *file) {
- char *filename;
-
- filename = (char *)malloc(strlen(file->filename) + 1);
- strcpy(filename, file->filename);
- return filename;
-}
-
-char *filter_localised(struct mscabd_file *file) {
+char *file_filter(struct mscabd_file *file) {
char *filename, file_lang[3];
filename = (char *)malloc(strlen(file->filename) + 1);
@@ -303,13 +295,13 @@ char *filter_localised(struct mscabd_file *file) {
return NULL;
}
-void extract_files(struct mscab_decompressor *cabd, struct mscabd_cabinet *cab, char *(* filter) (struct mscabd_file *)) {
+void extract_files(struct mscab_decompressor *cabd, struct mscabd_cabinet *cab) {
unsigned int files_extracted = 0;
struct mscabd_file *file;
char *filename;
for (file = cab->files; file; file = file->next) {
- if ((filename = filter(file))) {
+ if ((filename = file_filter(file))) {
if (cabd->extract(cabd, file, filename) != MSPACK_ERR_OK) {
printf("Extract error on %s!\n", file->filename);
continue;
@@ -334,13 +326,13 @@ int main(int argc, char *argv[]) {
// Argument checks and usage display
if (argc != 3) {
- printf("Usage: patchex gfupd101.exe LanguageCode/SpecialAction\n");
+ printf("Usage: patchex PATCH_EXECUTABLE LANGUAGE\n");
+ printf("Extract update files of game update from PATCH_EXECUTABLE (e.g. gfupd101.exe) in a specified LANGUAGE.\n");
+ printf("Please be sure that the update contains this language.\n");
printf("Available languages:\n");
for (i = 0; kLanguages_code[i]; i++)
printf("-%s (%s)\n", kLanguages_ext[i], kLanguages_code[i]);
- printf("Special actions:\n");
- printf("- ALL: Extracts all files with their original names.\n");
- printf("- CABINET: Extracts only the cabinet\n");
+ printf("Alternately original archive could be extracted as original.cab with CABINET keyword insted of language.\n");
exit(1);
}
@@ -351,12 +343,6 @@ int main(int argc, char *argv[]) {
action = CABINET_ACTION;
}
- // All languages check
- if (strcasecmp("ALL", argv[2]) == 0) {
- printf("All languages selected\n");
- action = ALL_LANGUAGES_ACTION;
- }
-
// Language check
for(i = 0; kLanguages_code[i]; i++)
if (strcasecmp(kLanguages_code[i], argv[2]) == 0 || strcasecmp(kLanguages_ext[i], argv[2]) == 0) {
@@ -368,7 +354,7 @@ int main(int argc, char *argv[]) {
// Unknown action
if (action == UNKNOWN_ACTION) {
- printf("Unknown language or action!\n");
+ printf("Unknown language!\n");
exit(1);
}
@@ -378,14 +364,8 @@ int main(int argc, char *argv[]) {
if ((cab = cabd->open(cabd, argv[1])) != MSPACK_ERR_OK) {
if (action == CABINET_ACTION)
extract_cabinet(argv[1], cab->length);
- else {
- switch (action) {
- case ALL_LANGUAGES_ACTION: filter = &filter_none; break;
- case LOCALISED_ACTION: filter = &filter_localised; break;
- default: printf("Internal error!\n"); exit(1); break;
- }
- extract_files(cabd, cab, filter);
- }
+ else if (action == LOCALISED_ACTION)
+ extract_files(cabd, cab);
cabd->close(cabd, cab);
} else
printf("Unable to open %s!\n", argv[1]);
Commit: 5c21186d177da545ec561d6c02da97ab23e6fcba
https://github.com/scummvm/scummvm-tools/commit/5c21186d177da545ec561d6c02da97ab23e6fcba
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-05-09T19:01:57+08:00
Commit Message:
Introduced support for EMI
Changed paths:
tools/patchex/patchex.cpp
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index ba5206656..b4f14c8f4 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -41,12 +41,14 @@
#include "tools/patchex/mspack.h"
// Command line actions
-enum act { UNKNOWN_ACTION, CABINET_ACTION, ALL_LANGUAGES_ACTION, LOCALISED_ACTION};
+enum act { UNKNOWN_ACTION, CABINET_ACTION, LOCALISED_ACTION};
// Languages codes
-#define LANG_ALL "@@"
+#define LANG_ALL1 "@@"
+#define LANG_ALL2 "Common"
const char *kLanguages_ext[] = { "English", "French", "German", "Italian", "Portuguese", "Spanish", NULL};
-const char *kLanguages_code[] = { "US", "FR", "GE", "IT", "PT", "SP", NULL };
+const char *kLanguages_code1[] = { "US", "FR", "GE", "IT", "PT", "SP", NULL };
+const char *kLanguages_code2[] = { "Eng", "Fra", "Deu", "Ita", "Brz", "Esp", NULL };
// Extraction constans
#define RAND_A (0x343FD)
@@ -56,7 +58,7 @@ const char *kLanguages_code[] = { "US", "FR", "GE", "IT", "PT", "SP", NULL };
#define CABINET_MAGIC "MSCF"
#define BUFFER_SIZE 102400
-char lang[3];
+unsigned int lang;
// Some useful type and function
typedef unsigned char byte;
@@ -284,15 +286,43 @@ void extract_cabinet(char *filename, unsigned int lenght) {
res_close(destination_cabinet);
}
-char *file_filter(struct mscabd_file *file) {
- char *filename, file_lang[3];
+char *file_filter(const struct mscabd_file *file) {
+ char *filename;
+ unsigned int filename_size;
+
+ filename_size = strlen(file->filename);
- filename = (char *)malloc(strlen(file->filename) + 1);
- sscanf(file->filename, "%2s_%s",file_lang, filename);
- if (strcmp(file_lang, lang) == 0 || strcmp(file_lang, LANG_ALL) == 0)
- return filename;
- else
+ //Skip executables
+ char *ext = file->filename + (filename_size - 3);
+ if (strcasecmp(ext, "exe") == 0 || strcasecmp(ext, "dll") == 0) {
return NULL;
+ }
+
+ filename = (char *)malloc(filename_size + 1);
+
+ //Old-style localization (Grimfandango)
+ if (filename_size > 3 && file->filename[2] == '_') {
+ char file_lang[3];
+ sscanf(file->filename, "%2s_%s",file_lang, filename);
+ if (strcmp(file_lang, kLanguages_code1[lang]) == 0 || strcmp(file_lang, LANG_ALL1) == 0)
+ return filename;
+ }
+
+ //Folder-style localization (EMI)
+ unsigned int lcode_size_com, lcode_size_loc;
+ lcode_size_com = strlen(LANG_ALL2);
+ lcode_size_loc = strlen(kLanguages_code2[lang]);
+ if ((filename_size > lcode_size_com && strncmp(file->filename, LANG_ALL2, lcode_size_com - 1) == 0) ||
+ (filename_size > lcode_size_loc && strncmp(file->filename, kLanguages_code2[lang], lcode_size_loc) == 0) ) {
+ char *fn = rindex(file->filename, '\\') + 1;
+ if (fn != NULL) {
+ strcpy(filename, fn);
+ return filename;
+ }
+ }
+
+ free(filename);
+ return NULL;
}
void extract_files(struct mscab_decompressor *cabd, struct mscabd_cabinet *cab) {
@@ -312,7 +342,7 @@ void extract_files(struct mscab_decompressor *cabd, struct mscabd_cabinet *cab)
}
}
- printf("%d file extracted.\n", files_extracted);
+ printf("%d file(s) extracted.\n", files_extracted);
}
int main(int argc, char *argv[]) {
@@ -330,8 +360,8 @@ int main(int argc, char *argv[]) {
printf("Extract update files of game update from PATCH_EXECUTABLE (e.g. gfupd101.exe) in a specified LANGUAGE.\n");
printf("Please be sure that the update contains this language.\n");
printf("Available languages:\n");
- for (i = 0; kLanguages_code[i]; i++)
- printf("-%s (%s)\n", kLanguages_ext[i], kLanguages_code[i]);
+ for (i = 0; kLanguages_code1[i]; i++)
+ printf("- %s\n", kLanguages_ext[i]);
printf("Alternately original archive could be extracted as original.cab with CABINET keyword insted of language.\n");
exit(1);
}
@@ -344,10 +374,10 @@ int main(int argc, char *argv[]) {
}
// Language check
- for(i = 0; kLanguages_code[i]; i++)
- if (strcasecmp(kLanguages_code[i], argv[2]) == 0 || strcasecmp(kLanguages_ext[i], argv[2]) == 0) {
+ for(i = 0; kLanguages_code1[i]; i++)
+ if (strncasecmp(kLanguages_ext[i], argv[2], strlen(argv[2])) == 0) {
printf("%s selected.\n", kLanguages_ext[i]);
- strcpy(lang, kLanguages_code[i]);
+ lang = i;
action = LOCALISED_ACTION;
break;
}
Commit: d7738bf13bea8382ac0073e4a11934d45065a7bb
https://github.com/scummvm/scummvm-tools/commit/d7738bf13bea8382ac0073e4a11934d45065a7bb
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-05-09T19:02:07+08:00
Commit Message:
Skips some other binary files
Changed paths:
tools/patchex/patchex.cpp
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index b4f14c8f4..e86828bf8 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -87,7 +87,7 @@ uint16 *create_dec_table(uint32 key) {
unsigned int i;
value = key;
- dectable = (uint16 *)malloc( CODE_TABLE_SIZE * 2);
+ dectable = (uint16 *)malloc(CODE_TABLE_SIZE * 2);
for (i = 0; i < CODE_TABLE_SIZE; i++) {
value = RAND_A * value + RAND_B;
@@ -292,9 +292,12 @@ char *file_filter(const struct mscabd_file *file) {
filename_size = strlen(file->filename);
- //Skip executables
+ //Skip executables and libries
char *ext = file->filename + (filename_size - 3);
- if (strcasecmp(ext, "exe") == 0 || strcasecmp(ext, "dll") == 0) {
+ if (strcasecmp(ext, "exe") == 0 ||
+ strcasecmp(ext, "dll") == 0 ||
+ strcasecmp(ext, "flt") == 0 ||
+ strcasecmp(ext, "asi") == 0) {
return NULL;
}
@@ -368,7 +371,7 @@ int main(int argc, char *argv[]) {
// Actions check
// Cabinet check
- if (strcasecmp("CABINET", argv[2]) == 0) {
+ if (strncasecmp("CABINET", argv[2], strlen(argv[2])) == 0) {
printf("Cabinet extraction selected\n");
action = CABINET_ACTION;
}
Commit: 19839b809f271f3813fbd32ddc3375c9893f4c86
https://github.com/scummvm/scummvm-tools/commit/19839b809f271f3813fbd32ddc3375c9893f4c86
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-05-09T19:02:07+08:00
Commit Message:
Removed some useless functions
Changed paths:
tools/patchex/cabd.cpp
tools/patchex/mspack.h
tools/patchex/mszipd.cpp
tools/patchex/patchex.cpp
diff --git a/tools/patchex/cabd.cpp b/tools/patchex/cabd.cpp
index 653a254bb..55ad226c8 100644
--- a/tools/patchex/cabd.cpp
+++ b/tools/patchex/cabd.cpp
@@ -74,7 +74,7 @@ struct mscab_decompressor *
{
struct mscab_decompressor_p *handle = NULL;
- if ((handle = (mscab_decompressor_p *)sys->alloc(sys, sizeof(struct mscab_decompressor_p)))) {
+ if ((handle = (mscab_decompressor_p *)malloc(sizeof(struct mscab_decompressor_p)))) {
handle->base.open = &cabd_open;
handle->base.close = &cabd_close;
handle->base.extract = &cabd_extract;
@@ -97,9 +97,9 @@ void mspack_destroy_cab_decompressor(struct mscab_decompressor *base) {
cabd_free_decomp(handle);
if (handle->d) {
if (handle->d->infh) sys->close(handle->d->infh);
- sys->free(handle->d);
+ free(handle->d);
}
- sys->free(handle);
+ free(handle);
}
}
@@ -116,7 +116,7 @@ static struct mscabd_cabinet *cabd_open(struct mscab_decompressor *base,
sys = handle->system;
if ((fh = sys->open(sys, filename, MSPACK_SYS_OPEN_READ))) {
- if ((cab = (mscabd_cabinet_p *)sys->alloc(sys, sizeof(struct mscabd_cabinet_p)))) {
+ if ((cab = (mscabd_cabinet_p *)malloc(sizeof(struct mscabd_cabinet_p)))) {
cab->base.filename = filename;
error = cabd_read_headers(sys, fh, cab, (off_t) 0, 0);
if (error) {
@@ -155,8 +155,8 @@ static void cabd_close(struct mscab_decompressor *base,
/* free files */
for (fi = origcab->files; fi; fi = nfi) {
nfi = fi->next;
- sys->free(fi->filename);
- sys->free(fi);
+ free(fi->filename);
+ free(fi);
}
for (fol = origcab->folders; fol; fol = nfol) {
@@ -165,37 +165,37 @@ static void cabd_close(struct mscab_decompressor *base,
if (handle->d && (handle->d->folder == (struct mscabd_folder_p *) fol)) {
if (handle->d->infh) sys->close(handle->d->infh);
cabd_free_decomp(handle);
- sys->free(handle->d);
+ free(handle->d);
handle->d = NULL;
}
for (dat = ((struct mscabd_folder_p *)fol)->data.next; dat; dat = ndat) {
ndat = dat->next;
- sys->free(dat);
+ free(dat);
}
- sys->free(fol);
+ free(fol);
}
for (cab = origcab; cab; cab = ncab) {
ncab = cab->prevcab;
- sys->free(cab->prevname);
- sys->free(cab->nextname);
- sys->free(cab->previnfo);
- sys->free(cab->nextinfo);
- if (cab != origcab) sys->free(cab);
+ free(cab->prevname);
+ free(cab->nextname);
+ free(cab->previnfo);
+ free(cab->nextinfo);
+ if (cab != origcab) free(cab);
}
for (cab = origcab->nextcab; cab; cab = ncab) {
ncab = cab->nextcab;
- sys->free(cab->prevname);
- sys->free(cab->nextname);
- sys->free(cab->previnfo);
- sys->free(cab->nextinfo);
- sys->free(cab);
+ free(cab->prevname);
+ free(cab->nextname);
+ free(cab->previnfo);
+ free(cab->nextinfo);
+ free(cab);
}
cab = origcab->next;
- sys->free(origcab);
+ free(origcab);
origcab = cab;
}
@@ -238,18 +238,18 @@ static int cabd_read_headers(struct mspack_system *sys,
num_folders = EndGetI16(&buf[cfhead_NumFolders]);
if (num_folders == 0) {
- if (!quiet) sys->message(fh, "no folders in cabinet.");
+ if (!quiet) fprintf(stderr, "no folders in cabinet.");
return MSPACK_ERR_DATAFORMAT;
}
num_files = EndGetI16(&buf[cfhead_NumFiles]);
if (num_files == 0) {
- if (!quiet) sys->message(fh, "no files in cabinet.");
+ if (!quiet) fprintf(stderr, "no files in cabinet.");
return MSPACK_ERR_DATAFORMAT;
}
if ((buf[cfhead_MajorVersion] != 1) && (buf[cfhead_MinorVersion] != 3)) {
- if (!quiet) sys->message(fh, "WARNING; cabinet version is not 1.3");
+ if (!quiet) fprintf(stderr, "WARNING; cabinet version is not 1.3");
}
cab->base.flags = EndGetI16(&buf[cfhead_Flags]);
@@ -262,7 +262,7 @@ static int cabd_read_headers(struct mspack_system *sys,
cab->block_resv = buf[cfheadext_DataReserved];
if (cab->base.header_resv > 60000) {
- if (!quiet) sys->message(fh, "WARNING; reserved header > 60000.");
+ if (!quiet) fprintf(stderr, "WARNING; reserved header > 60000.");
}
if (cab->base.header_resv) {
@@ -297,7 +297,7 @@ static int cabd_read_headers(struct mspack_system *sys,
}
}
- if (!(fol = (struct mscabd_folder_p *)sys->alloc(sys, sizeof(struct mscabd_folder_p)))) {
+ if (!(fol = (struct mscabd_folder_p *)malloc(sizeof(struct mscabd_folder_p)))) {
return MSPACK_ERR_NOMEMORY;
}
fol->base.next = NULL;
@@ -320,7 +320,7 @@ static int cabd_read_headers(struct mspack_system *sys,
return MSPACK_ERR_READ;
}
- if (!(file = (struct mscabd_file *)sys->alloc(sys, sizeof(struct mscabd_file)))) {
+ if (!(file = (struct mscabd_file *)malloc(sizeof(struct mscabd_file)))) {
return MSPACK_ERR_NOMEMORY;
}
@@ -336,7 +336,7 @@ static int cabd_read_headers(struct mspack_system *sys,
file->folder = ifol;
if (!ifol) {
- sys->free(file);
+ free(file);
return MSPACK_ERR_DATAFORMAT;
}
}
@@ -374,7 +374,7 @@ static int cabd_read_headers(struct mspack_system *sys,
file->filename = cabd_read_string(sys, fh, cab, &x);
if (x) {
- sys->free(file);
+ free(file);
return x;
}
@@ -409,12 +409,12 @@ static char *cabd_read_string(struct mspack_system *sys,
return NULL;
}
- if (!(str = (char *)sys->alloc(sys, len))) {
+ if (!(str = (char *)malloc(len))) {
*error = MSPACK_ERR_NOMEMORY;
return NULL;
}
- sys->copy(&buf[0], str, len);
+ memcpy(str, &buf[0], len);
*error = MSPACK_ERR_OK;
return str;
}
@@ -437,13 +437,13 @@ static int cabd_extract(struct mscab_decompressor *base,
if ((!fol) || (fol->merge_prev) ||
(((file->offset + file->length) / CAB_BLOCKMAX) > fol->base.num_blocks))
{
- sys->message(NULL, "ERROR; file \"%s\" cannot be extracted, "
+ fprintf(stderr, "ERROR; file \"%s\" cannot be extracted, "
"cabinet set is incomplete.", file->filename);
return handle->error = MSPACK_ERR_DATAFORMAT;
}
if (!handle->d) {
- handle->d = (mscabd_decompress_state *)sys->alloc(sys, sizeof(struct mscabd_decompress_state));
+ handle->d = (mscabd_decompress_state *)malloc(sizeof(struct mscabd_decompress_state));
if (!handle->d) return handle->error = MSPACK_ERR_NOMEMORY;
handle->d->folder = NULL;
handle->d->data = NULL;
@@ -556,7 +556,7 @@ static int cabd_sys_read(struct mspack_file *file, void *buffer, int bytes) {
if (avail) {
if (avail > todo) avail = todo;
- sys->copy(handle->d->i_ptr, buf, (size_t) avail);
+ memcpy(buf, handle->d->i_ptr, (size_t) avail);
handle->d->i_ptr += avail;
buf += avail;
todo -= avail;
@@ -573,8 +573,7 @@ static int cabd_sys_read(struct mspack_file *file, void *buffer, int bytes) {
if (handle->d->block >= handle->d->folder->base.num_blocks) {
} else {
if (outlen != CAB_BLOCKMAX) {
- handle->system->message(handle->d->infh,
- "WARNING; non-maximal data block");
+ fprintf(stderr, "WARNING; non-maximal data block");
}
}
}
@@ -630,7 +629,7 @@ static int cabd_sys_read_block(struct mspack_system *sys,
unsigned int sum2 = cabd_checksum(d->i_end, (unsigned int) len, 0);
if (cabd_checksum(&hdr[4], 4, sum2) != cksum) {
if (!ignore_cksum) return MSPACK_ERR_CHECKSUM;
- sys->message(d->infh, "WARNING; bad block checksum found");
+ fprintf(stderr, "WARNING; bad block checksum found");
}
}
diff --git a/tools/patchex/mspack.h b/tools/patchex/mspack.h
index 22f6fb69a..af84a67b1 100644
--- a/tools/patchex/mspack.h
+++ b/tools/patchex/mspack.h
@@ -59,15 +59,6 @@ struct mspack_system {
off_t offset,
int mode);
off_t (*tell)(struct mspack_file *file);
- void (*message)(struct mspack_file *file,
- const char *format,
- ...);
- void * (*alloc)(struct mspack_system *self,
- size_t bytes);
- void (*free)(void *ptr);
- void (*copy)(void *src,
- void *dest,
- size_t bytes);
void *null_ptr;
};
diff --git a/tools/patchex/mszipd.cpp b/tools/patchex/mszipd.cpp
index c80a82d59..c218d48fc 100644
--- a/tools/patchex/mszipd.cpp
+++ b/tools/patchex/mszipd.cpp
@@ -252,11 +252,11 @@ static int zip_read_lens(struct mszipd_stream *zip) {
}
i = lit_codes;
- zip->sys->copy(&lens[0], &zip->LITERAL_len[0], i);
+ memcpy(&zip->LITERAL_len[0], &lens[0], i);
while (i < MSZIP_LITERAL_MAXSYMBOLS) zip->LITERAL_len[i++] = 0;
i = dist_codes;
- zip->sys->copy(&lens[lit_codes], &zip->DISTANCE_len[0], i);
+ memcpy(&zip->DISTANCE_len[0], &lens[lit_codes], i);
while (i < MSZIP_DISTANCE_MAXSYMBOLS) zip->DISTANCE_len[i++] = 0;
STORE_BITS;
@@ -314,7 +314,7 @@ static int inflate(struct mszipd_stream *zip) {
if (this_run > (MSZIP_FRAME_SIZE - zip->window_posn))
this_run = MSZIP_FRAME_SIZE - zip->window_posn;
- zip->sys->copy(i_ptr, &zip->window[zip->window_posn], this_run);
+ memcpy(&zip->window[zip->window_posn], i_ptr, this_run);
zip->window_posn += this_run;
i_ptr += this_run;
length -= this_run;
@@ -457,13 +457,13 @@ struct mszipd_stream *mszipd_init(struct mspack_system *system,
input_buffer_size = (input_buffer_size + 1) & -2;
if (!input_buffer_size) return NULL;
- if (!(zip = (mszipd_stream *)system->alloc(system, sizeof(struct mszipd_stream)))) {
+ if (!(zip = (mszipd_stream *)malloc(sizeof(struct mszipd_stream)))) {
return NULL;
}
- zip->inbuf = (unsigned char *)system->alloc(system, (size_t) input_buffer_size);
+ zip->inbuf = (unsigned char *)malloc((size_t) input_buffer_size);
if (!zip->inbuf) {
- system->free(zip);
+ free(zip);
return NULL;
}
@@ -520,7 +520,7 @@ int mszipd_decompress(struct mszipd_stream *zip, off_t out_bytes) {
STORE_BITS;
if ((error = inflate(zip))) {
if (zip->repair_mode) {
- zip->sys->message(NULL, "MSZIP error, %u bytes of data lost.",
+ fprintf(stderr, "MSZIP error, %u bytes of data lost.",
MSZIP_FRAME_SIZE - zip->bytes_output);
for (i = zip->bytes_output; i < MSZIP_FRAME_SIZE; i++) {
zip->window[i] = '\0';
@@ -556,7 +556,7 @@ void mszipd_free(struct mszipd_stream *zip) {
struct mspack_system *sys;
if (zip) {
sys = zip->sys;
- sys->free(zip->inbuf);
- sys->free(zip);
+ free(zip->inbuf);
+ free(zip);
}
}
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index e86828bf8..ac4b95d23 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -227,39 +227,9 @@ static int res_write(struct mspack_file *file, void *buffer, int bytes) {
return -1;
}
-static void res_msg(struct mspack_file *file, const char *format, ...) {
- va_list ap;
-
- if (file)
- fprintf(stderr, "%s: ", ((struct mspack_file_p *)file)->name);
- va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
- fputc((int) '\n', stderr);
- fflush(stderr);
-}
-
-static void *res_alloc(struct mspack_system *, size_t bytes) {
- void *memory;
- memory = malloc(bytes);
- if (memory == NULL) {
- printf("Insufficient memory!\n");
- exit(1);
- } else
- return memory;
-}
-
-static void res_free(void *buffer) {
- free(buffer);
-}
-
-static void res_copy(void *src, void *dest, size_t bytes) {
- memcpy(dest, src, bytes);
-}
-
static struct mspack_system res_system = {
&res_open, &res_close, &res_read, &res_write, &res_seek,
- &res_tell, &res_msg, &res_alloc, &res_free, &res_copy, NULL
+ &res_tell, NULL
};
void extract_cabinet(char *filename, unsigned int lenght) {
@@ -271,7 +241,7 @@ void extract_cabinet(char *filename, unsigned int lenght) {
original_executable = res_open(&res_system, filename, MSPACK_SYS_OPEN_READ);
destination_cabinet = res_open(&res_system, "original.cab", MSPACK_SYS_OPEN_WRITE);
- buffer = res_alloc(NULL, BUFFER_SIZE);
+ buffer = malloc(BUFFER_SIZE);
copied_bytes = 0;
while (copied_bytes < lenght) {
@@ -281,7 +251,7 @@ void extract_cabinet(char *filename, unsigned int lenght) {
}
printf("Update cabinet extracted as original.cab.\n");
- res_free(buffer);
+ free(buffer);
res_close(original_executable);
res_close(destination_cabinet);
}
Commit: 12f37562909dc472a920ca3f63f150d4ca2b564e
https://github.com/scummvm/scummvm-tools/commit/12f37562909dc472a920ca3f63f150d4ca2b564e
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2011-05-20T01:33:09+08:00
Commit Message:
unlab: Fixed some crashes and reduced memory leaks.
Memory is now only allocated if needed.
Changed paths:
tools/unlab.cpp
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 7752e1f11..955aba981 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -62,19 +62,25 @@ int main(int argc, char **argv) {
struct lab_entry *entries;
char *str_table;
uint32_t i;
- off_t offset;
+ uint32_t offset;
uint8_t g_type;
-
- if(argc > 2 && !strcmp(argv[2],"EMI"))
+
+ if (argc < 2) {
+ printf("No file specified\n");
+ exit(1);
+ }
+
+ if(argc > 2 && !strcmp(argv[2], "EMI")) {
+ printf("Opening file with EMI format.\n");
g_type = GT_EMI;
- else
+ } else {
+ printf("Opening file with GRIM format.\n");
g_type = GT_GRIM;
-
- printf("g_type: %d",g_type);
-
+ }
+
infile = fopen(argv[1], "rb");
if (infile == 0) {
- printf("can't open source file: %s\n", argv[1]);
+ printf("Can not open source file: %s\n", argv[1]);
exit(1);
}
@@ -91,17 +97,19 @@ int main(int argc, char **argv) {
printf("There is no LABN header in source file\n");
exit(1);
}
-
+
entries = (struct lab_entry *)malloc(head.num_entries * sizeof(struct lab_entry));
str_table = (char *)malloc(head.string_table_size);
+ if (!str_table || !entries) {
+ printf("Could not allocate memory\n");
+ exit(1);
+ }
// Grim-stuff
- if(g_type == GT_GRIM){
+ if(g_type == GT_GRIM) {
fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
-
+
fread(str_table, 1, head.string_table_size, infile);
- }
- // EMI-stuff
- else if(g_type == GT_EMI){
+ } else if(g_type == GT_EMI) { // EMI-stuff
// EMI has a string-table-offset
head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
// Find the string-table
@@ -109,27 +117,52 @@ int main(int argc, char **argv) {
// Read the entire string table into str-table
fread(str_table, 1, head.string_table_size, infile);
fseek(infile, 20, SEEK_SET);
-
+
// Decrypt the string table
uint32_t j;
for (j = 0; j < head.string_table_size; j++)
if (str_table[j] != 0)
str_table[j] ^= 0x96;
fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
-
+
+ }
+ // allocate a 1mb buffer to start with
+ uint32_t bufSize = 1024*1024;
+ char *buf = (char *)malloc(bufSize);
+ if (!buf) {
+ printf("Could not allocate memory\n");
+ exit(1);
}
-
for (i = 0; i < head.num_entries; i++) {
- outfile = fopen(str_table + READ_LE_UINT32(&entries[i].fname_offset), "wb");
+ const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
+ outfile = fopen(fname, "wb");
+ if (!outfile) {
+ printf("Could not open file: %s\n", fname);
+ continue;
+ }
offset = READ_LE_UINT32(&entries[i].start);
- char *buf = (char *)malloc(READ_LE_UINT32(&entries[i].size));
+ uint32_t size = READ_LE_UINT32(&entries[i].size);
+ if (bufSize < size) {
+ bufSize = size;
+ char *newBuf = (char *)realloc(buf, bufSize);
+ if (!newBuf) {
+ printf("Could not reallocate memory\n");
+ exit(1);
+ } else {
+ buf = newBuf;
+ }
+ }
+
fseek(infile, offset, SEEK_SET);
fread(buf, 1, READ_LE_UINT32(&entries[i].size), infile);
fwrite(buf, 1, READ_LE_UINT32(&entries[i].size), outfile);
fclose(outfile);
-
+
}
-
+ free(buf);
+ free(entries);
+ free(str_table);
+
fclose(infile);
return 0;
}
Commit: 916b1c62c3b2a72e4ff1c770e66ba856ce5e22ab
https://github.com/scummvm/scummvm-tools/commit/916b1c62c3b2a72e4ff1c770e66ba856ce5e22ab
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-05-21T02:41:39+08:00
Commit Message:
Cleanup in style, added Meshb to configure, and fixed til2bmp-compile-flags
Changed paths:
tools/meshb2obj.cpp
tools/module.mk
tools/til2bmp.cpp
diff --git a/tools/meshb2obj.cpp b/tools/meshb2obj.cpp
index dd03011bf..d40a1183d 100644
--- a/tools/meshb2obj.cpp
+++ b/tools/meshb2obj.cpp
@@ -1,3 +1,23 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
#include <fstream>
#include <string>
#include <iostream>
@@ -5,7 +25,7 @@
using namespace std;
int main(int argc, char **argv) {
- if(argc<2){
+ if(argc < 2){
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
@@ -19,39 +39,39 @@ int main(int argc, char **argv) {
}
int strLength = 0;
- file.read((char*)&strLength,4);
+ file.read((char*)&strLength, 4);
char* readString = new char[64];
- file.read(readString,strLength);
+ file.read(readString, strLength);
// Then a list of textures 48 bytes later
int numTextures = 0;
- file.seekg(48,ios::cur);
- file.read((char*)&numTextures,4);
+ file.seekg(48, ios::cur);
+ file.read((char*)&numTextures, 4);
char **texNames = new char*[numTextures];
- for(int i=0;i<numTextures;i++){
- file.read((char*)&strLength,4);
+ for(int i=0;i<numTextures; i++){
+ file.read((char*)&strLength, 4);
texNames[i] = new char[strLength];
- file.read(texNames[i],strLength);
+ file.read(texNames[i], strLength);
// Every texname seems to be followed by 4 0-bytes
- file.seekg(4,ios::cur);
+ file.seekg(4, ios::cur);
}
- for(int i=0;i<numTextures;i++){
+ for(int i = 0;i < numTextures;i++){
std::cout << "# TexName " << texNames[i] << std::endl;
}
// 4 unknown bytes - usually with value 19
- file.seekg(4,ios::cur);
- /*
- Then follows the weird padding.
- */
+ file.seekg(4, ios::cur);
+/*
+ * Then follows the weird padding.
+ */
// Should create an empty mtl
- std::cout << "mtllib quit.mtl"<<std::endl<<"o Arrow"<<std::endl;
+ std::cout << "mtllib quit.mtl" << std::endl << "o Arrow"<< std::endl;
// Vertices
// file.seekg(283);
int numVertices;
- file.read((char*)&numVertices,4);
+ file.read((char*)&numVertices, 4);
std::cout << "#File has " << numVertices << " Vertices" << std::endl;
//file.seekg(287);
@@ -63,7 +83,7 @@ int main(int argc, char **argv) {
file.read((char *)&z, 4);
std::cout << "v " << x << " " << y << " " << z << std::endl;
}
-
+// Vertice-normals?
for (int i = 0; i < numVertices; ++i) {
file.read((char *)&x, 4);
file.read((char *)&y, 4);
@@ -78,8 +98,8 @@ int main(int argc, char **argv) {
// The head of this section needs quite a bit of rechecking
file.seekg(36335);
int faceLength = 0;
- for(int j=0;j<numTextures+1;j++){
- file.read((char*)&faceLength,4);
+ for(int j = 0;j < numTextures + 1; j++){
+ file.read((char*)&faceLength, 4);
short x = 0, y = 0, z = 0;
cout << "g " << j << endl;
for (int i = 0; i < faceLength; i+=3) {
@@ -92,6 +112,6 @@ int main(int argc, char **argv) {
std::cout << "f " << x << "//" << x << " " << y << "//" << y << " " << z << "//" << z << std::endl;
}
// 12 bytes of unknown
- file.seekg(12,ios::cur);
+ file.seekg(12, ios::cur);
}
-}
\ No newline at end of file
+}
diff --git a/tools/module.mk b/tools/module.mk
index 373397d82..3de372c14 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -14,6 +14,7 @@ TOOLS := \
tools/delua$(EXEEXT) \
tools/imc2wav$(EXEEXT) \
tools/int2flt$(EXEEXT) \
+ tools/meshb2obj$(EXEEXT) \
tools/set2fig$(EXEEXT) \
tools/til2bmp$(EXEEXT) \
tools/unlab$(EXEEXT) \
@@ -61,13 +62,19 @@ tools/int2flt$(EXEEXT): $(srcdir)/tools/int2flt.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
+tools/meshb2obj$(EXEEXT): $(srcdir)/tools/meshb2obj.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common -o $@ $<
+
tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
tools/til2bmp$(EXEEXT): $(srcdir)/tools/til2bmp.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -lz -I. -o $@ $<
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common -lz -o $@ $<
tools/unlab$(EXEEXT): $(srcdir)/tools/unlab.cpp
$(MKDIR) tools/$(DEPDIR)
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index f0d93a91a..3a93e2413 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -1,3 +1,23 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
#include <fstream>
#include <iostream>
#include <string>
@@ -81,15 +101,15 @@ void LucasBitMap::MoreBits(){
char byte1 = _data[i*_width*_bpp+j*2+1];
// Probably Alpha, then 555.
// Red
- red = (byte1>>2)&31;
+ red = (byte1 >> 2) & 31;
red = red << 3 | red >> 2;
// Green
- char green1 = (byte1&3);
- char green2 = (((byte2)>>5)&7);
+ char green1 = (byte1 & 3);
+ char green2 = (((byte2) >> 5) & 7);
char green3 = green1 << 3 | green2;
green = green3 << 3 | green3 >> 2 ;
// Blue
- blue = (byte2)&31;
+ blue = (byte2) & 31;
blue = blue << 3 | blue >> 2;
// Some more magic to stretch the values
*to = red;
@@ -104,12 +124,12 @@ void LucasBitMap::MoreBits(){
}
delete _data;
_data = newData;
- _bpp=4;
+ _bpp = 4;
}
}
LucasBitMap::LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp, bool copy) : _data(data), _width(width), _height(height), _bpp(bpp){
- if(data==0)
+ if(data == 0)
MakeNewData();
else if(copy){
MakeNewData();
@@ -122,15 +142,15 @@ void LucasBitMap::WriteBMP(const char* name){
BMPHeader header;
unsigned short bm = TO_LE_16(19778);
file.write((char*)&bm, 2);
- header.size = TO_LE_32(size()+54);
+ header.size = TO_LE_32(size() + 54);
header.reserved = TO_LE_32(0);
header.width = TO_LE_32(_width);
header.height = TO_LE_32(_height);
header.offset = TO_LE_32(54);
header.headerSize = TO_LE_32(40);
-if(_bpp==4)
+if(_bpp == 4)
header.nplanesbpp = TO_LE_32(2097153);
-else if(_bpp==2)
+else if(_bpp == 2)
header.nplanesbpp = TO_LE_32(1048577);
header.compress_type = TO_LE_32(0);
header.bmp_bytesz = TO_LE_32(0);
@@ -144,11 +164,11 @@ else if(_bpp==2)
}
void LucasBitMap::BGR2RGB(){
- if(_bpp==4){
+ if(_bpp == 4){
uint32_t end = size();
for(uint32_t i = 0; i < end; i += 4){
- char temp = _data[i+2];
- _data[i+2] = _data[i];
+ char temp = _data[i + 2];
+ _data[i + 2] = _data[i];
_data[i] = temp;
}
}else if(_bpp==2){
@@ -158,52 +178,52 @@ void LucasBitMap::BGR2RGB(){
char* GetLine(int lineNum, LucasBitMap* bit){
int bpp = bit->_bpp;
- return bit->_data + (lineNum*(bit->_width*bpp));
+ return bit->_data + (lineNum*(bit->_width * bpp));
}
char* GetLine(int lineNum, char* data, unsigned int width,int bpp){
- return data + (lineNum*(width*bpp));
+ return data + (lineNum * (width * bpp));
}
// Expects 5 LucasBitmaps, and returns a LucasBitmap untiled.
LucasBitMap* MakeFullPicture(LucasBitMap** bits){
- LucasBitMap* fullImage = new LucasBitMap(0,640,480,bits[0]->_bpp);
+ LucasBitMap* fullImage = new LucasBitMap(0, 640, 480, bits[0]->_bpp);
- const int tWidth = 256*bits[0]->_bpp; // All of them should have the same bpp. (32)
+ const int tWidth = 256 * bits[0]->_bpp; // All of them should have the same bpp. (32)
int bpp = bits[0]->_bpp;
char* target = fullImage->_data;
- for(int i=0;i<256;i++){
+ for(int i = 0;i < 256;i++){
/* This can be modified to actually use the last 32 lines.
* We simply put the lower half on line 223 and down to line 32,
* then skip the last 32.
* While the upper half is put on line 479 and down to line 224.
*/
- if(i<224){ // Skip blank space
- target=GetLine(223-i,fullImage);
+ if(i < 224){ // Skip blank space
+ target = GetLine(223 - i,fullImage);
- memcpy(target,GetLine(i,bits[3]),tWidth);
- target += bits[3]->_width*bpp;
+ memcpy(target, GetLine(i, bits[3]), tWidth);
+ target += bits[3]->_width * bpp;
- memcpy(target,GetLine(i,bits[4]),tWidth);
- target += bits[4]->_width*bpp;
+ memcpy(target, GetLine(i, bits[4]), tWidth);
+ target += bits[4]->_width * bpp;
memcpy(target,GetLine(i,bits[2])+128*bpp,128*bpp);
- target += bpp*bits[2]->_width/2;
+ target += bpp * bits[2]->_width / 2;
}
// Top half of course
- target = GetLine(479-i,fullImage);
+ target = GetLine(479-i, fullImage);
- memcpy(target,GetLine(i,bits[0]),tWidth);
- target += bits[0]->_width*bpp;
+ memcpy(target, GetLine(i, bits[0]), tWidth);
+ target += bits[0]->_width * bpp;
- memcpy(target,GetLine(i,bits[1]),tWidth);
- target += bits[1]->_width*bpp;
+ memcpy(target, GetLine(i, bits[1]), tWidth);
+ target += bits[1]->_width * bpp;
- memcpy(target,GetLine(i,bits[2]),128*bpp);
- target += bpp*bits[2]->_width/2;
+ memcpy(target,GetLine(i, bits[2]), 128 * bpp);
+ target += bpp * bits[2]->_width / 2;
}
fullImage->BGR2RGB();
@@ -233,7 +253,7 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
FROM_LE_32(c);
// We want to actually read numImages and bpp
- til.seekg(bmoffset+16,std::ios::beg);
+ til.seekg(bmoffset + 16,std::ios::beg);
til.read((char*)&numImages, 4);
FROM_LE_32(numImages);
@@ -244,11 +264,11 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
til.seekg(16,std::ios::cur);
til.read((char*) &bpp, 4);
FROM_LE_32(bpp);
- bpp = bpp/8;
+ bpp = bpp / 8;
printf("Detected %d bpp\n",bpp*8);
- til.seekg(bmoffset+128, std::ios::beg);
+ til.seekg(bmoffset + 128, std::ios::beg);
uint32_t width = 0, height = 0;
@@ -266,7 +286,6 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
til.read(data, size);
allTheData[i] = new LucasBitMap(data, width, height,bpp,false);
-// allTheData[i]->WriteBMP(outnamet);
}
LucasBitMap* bit = MakeFullPicture(allTheData);
bit->WriteBMP(name.c_str());
@@ -281,7 +300,7 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
Bytef *decompress(Bytef *in, int size, uint32_t &outsize){
- const uint32_t block = 8*1024*1024;
+ const uint32_t block = 8 * 1024 * 1024;
Bytef *dest = new Bytef[block]; // 8 MiB ought to be enough.
int success = 0;
@@ -294,7 +313,7 @@ Bytef *decompress(Bytef *in, int size, uint32_t &outsize){
zStream.opaque = Z_NULL;
success = inflateInit2(&zStream, 16+MAX_WBITS);
- if(success!=Z_OK){
+ if(success != Z_OK){
std::cout << "ZLIB failed to initialize\n";
return 0;
}
@@ -322,7 +341,7 @@ int main(int argc, char **argv){
}
// Cheap fix to support PS2
bool ps2=false;
- if(argc>2)
+ if(argc > 2)
ps2 = true;
std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
Commit: 7dfe443bc39f8d42a36e67a62f9fe96029d883cf
https://github.com/scummvm/scummvm-tools/commit/7dfe443bc39f8d42a36e67a62f9fe96029d883cf
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-07-19T22:49:18+02:00
Commit Message:
TIL2BMP: Complete Big-Endian support
Changed paths:
tools/til2bmp.cpp
diff --git a/tools/til2bmp.cpp b/tools/til2bmp.cpp
index 3a93e2413..19c14034c 100644
--- a/tools/til2bmp.cpp
+++ b/tools/til2bmp.cpp
@@ -242,20 +242,20 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
uint32_t id, bmoffset, rects, b, c, numImages;
til.read((char *)&id, 4);
- FROM_LE_32(id);
+ id = FROM_LE_32(id);
til.read((char *)&bmoffset, 4);
- FROM_LE_32(bmoffset);
+ bmoffset = FROM_LE_32(bmoffset);
til.read((char *)&rects, 4);
- FROM_LE_32(rects);
+ rects = FROM_LE_32(rects);
til.read((char *)&b, 4);
- FROM_LE_32(b);
+ b = FROM_LE_32(b);
til.read((char *)&c, 4);
- FROM_LE_32(c);
+ c = FROM_LE_32(c);
// We want to actually read numImages and bpp
til.seekg(bmoffset + 16,std::ios::beg);
til.read((char*)&numImages, 4);
- FROM_LE_32(numImages);
+ numImages = FROM_LE_32(numImages);
if(numImages < 5){
printf("This tile has less than 5 tiles, I don't know how to parse it\n");
@@ -263,7 +263,7 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
til.seekg(16,std::ios::cur);
til.read((char*) &bpp, 4);
- FROM_LE_32(bpp);
+ bpp = FROM_LE_32(bpp);
bpp = bpp / 8;
printf("Detected %d bpp\n",bpp*8);
@@ -276,9 +276,9 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
for (uint32_t i = 0; i < 5; ++i) {
til.read((char *)&width, 4);
- FROM_LE_32(width);
+ width = FROM_LE_32(width);
til.read((char *)&height, 4);
- FROM_LE_32(height);
+ height = FROM_LE_32(height);
uint32_t size = width*height*bpp;
char *data = new char[size];
char *outnamet = new char[64];
Commit: c73855b6e92f8b37d38116d3913951c209f08732
https://github.com/scummvm/scummvm-tools/commit/c73855b6e92f8b37d38116d3913951c209f08732
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-07-27T00:15:13+02:00
Commit Message:
Add labcopy
Changed paths:
A tools/labcopy.cpp
tools/module.mk
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
new file mode 100644
index 000000000..347cd7582
--- /dev/null
+++ b/tools/labcopy.cpp
@@ -0,0 +1,135 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+/*labcopy.cpp
+ quick & dirty LAB file copier based on residual code.
+
+ Adapted from code posted on residual forum by Joost Peters
+ http://residual.scummvm.org/viewtopic.php?t=91
+*/
+
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include "common/endian.h"
+
+#define BUFFER_SIZE 102400
+FILE *inLab = NULL, *outLab = NULL;
+
+bool copyLab(long lenght = 0) {
+ void *buffer;
+ long copied_bytes, count;
+
+ if (lenght == 0) {
+ fseek(inLab, 0L, SEEK_END);
+ lenght = ftell(inLab);
+ }
+
+ buffer = malloc(BUFFER_SIZE);
+ copied_bytes = 0;
+ fseek(inLab, 0, SEEK_SET);
+
+ while (copied_bytes < lenght) {
+ count = (long)fread(buffer, 1, BUFFER_SIZE, inLab);
+ fwrite(buffer, count, 1, outLab);
+ copied_bytes += count;
+ if(ferror(inLab) != 0 || ferror(outLab) != 0) {
+ free(buffer);
+ return false;
+ }
+ }
+
+ free(buffer);
+ return true;
+}
+
+long getLabSize() {
+ long total_size = 0;
+ char header[16], binary_entry[16];
+ int num_entries, string_table_size;
+
+ fseek(inLab, 0, SEEK_SET);
+
+ fread(header, 16, 1, inLab);
+ if (READ_BE_UINT32(header) != MKTAG('L','A','B','N'))
+ return -1;
+
+ num_entries = READ_LE_UINT32(header + 8);
+ string_table_size = READ_LE_UINT32(header + 12);
+
+ total_size = 16 + num_entries * 16 + string_table_size;
+
+ for (int i = 0; i < num_entries; i++) {
+ fread(binary_entry, 16, 1, inLab);
+ total_size += READ_LE_UINT32(binary_entry + 8);
+ }
+
+ return total_size;
+}
+
+void cleanup() {
+ if (inLab)
+ fclose(inLab);
+
+ if (outLab)
+ fclose(outLab);
+}
+
+int main(int argc, char *argv[]) {
+ long labSize;
+
+ atexit(cleanup);
+
+ //Argument checks and usage display
+ if (argc != 3) {
+ printf("Usage: labcopy original.lab destination.lab\n");
+ printf("Copy original.lab from Grimfandango cd with illegal-toc protection.\n");
+ return 1;
+ }
+
+ //Files opening
+ inLab = fopen(argv[1], "rb");
+ if (!inLab) {
+ printf("Couldn't open %s!\n", argv[1]);
+ return 1;
+ }
+
+ outLab = fopen(argv[2], "wb");
+ if (!outLab) {
+ printf("Couldn't write to %s!\n", argv[2]);
+ return 1;
+ }
+
+ //Get the correct lab size
+ labSize = getLabSize();
+ if (labSize < 0) {
+ printf("%s isn't a valid .lab file!\n", argv[1]);
+ return 1;
+ }
+
+ //Lab copying
+ if (!copyLab(labSize)) {
+ printf("I/O error!\n");
+ return 1;
+ }
+
+ printf("%s successfully copied to %s.\n", argv[1], argv[2]);
+ return 0;
+}
diff --git a/tools/module.mk b/tools/module.mk
index 3de372c14..02403b283 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -19,6 +19,7 @@ TOOLS := \
tools/til2bmp$(EXEEXT) \
tools/unlab$(EXEEXT) \
tools/vima$(EXEEXT) \
+ tools/labcopy$(EXEEXT) \
tools/patchex/patchex$(EXEEXT)
# below not added as it depends for ppm, bpm library
@@ -84,6 +85,11 @@ tools/vima$(EXEEXT): $(srcdir)/tools/vima.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
+tools/labcopy$(EXEEXT): $(srcdir)/tools/labcopy.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -Wall \
+ -L$(srcdir)/common -o $@ $<
+
tools/patchex/patchex$(EXEEXT): tools/patchex/patchex.o tools/patchex/mszipd.o tools/patchex/cabd.o
$(MKDIR) tools/patchex/$(DEPDIR)
$(CXX) $(CFLAGS) tools/patchex/mszipd.o tools/patchex/cabd.o -Wall -o $@ $<
Commit: 0b97532b54aeabed333cc096d59e92b7d82de9be
https://github.com/scummvm/scummvm-tools/commit/0b97532b54aeabed333cc096d59e92b7d82de9be
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-07-28T09:44:46+02:00
Commit Message:
MESHB2OBJ: Added offset-data to properly decipher faces for MI4-Demo
Changed paths:
tools/meshb2obj.cpp
diff --git a/tools/meshb2obj.cpp b/tools/meshb2obj.cpp
index d40a1183d..04a3917e0 100644
--- a/tools/meshb2obj.cpp
+++ b/tools/meshb2obj.cpp
@@ -90,16 +90,18 @@ int main(int argc, char **argv) {
file.read((char *)&z, 4);
std::cout << "vn " << x << " " << y << " " << z << std::endl;
}
-
+ file.seekg(numVertices * 12,ios::cur);
// Actually, this file has 6*4*numVertices floats in this block.
std::cout<<"usemtl (null)"<<std::endl;
// And then another block of unknowns
// Faces
// The head of this section needs quite a bit of rechecking
- file.seekg(36335);
+ int numFaces = 0;
+ file.read((char *) &numFaces, 4);
+ file.seekg(8,ios::cur);
int faceLength = 0;
- for(int j = 0;j < numTextures + 1; j++){
- file.read((char*)&faceLength, 4);
+ for(int j = 0;j < numFaces; j++){
+ file.read((char*)&faceLength,4);
short x = 0, y = 0, z = 0;
cout << "g " << j << endl;
for (int i = 0; i < faceLength; i+=3) {
Commit: efd293da4af884c9b60facd62f24cb046b53f14b
https://github.com/scummvm/scummvm-tools/commit/efd293da4af884c9b60facd62f24cb046b53f14b
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-07-28T09:46:40+02:00
Commit Message:
MESHB2OBJ: Formatting
Changed paths:
tools/meshb2obj.cpp
diff --git a/tools/meshb2obj.cpp b/tools/meshb2obj.cpp
index 04a3917e0..b09ba7731 100644
--- a/tools/meshb2obj.cpp
+++ b/tools/meshb2obj.cpp
@@ -29,11 +29,11 @@ int main(int argc, char **argv) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
- std::string filename=argv[1];
+ std::string filename = argv[1];
std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
- if (!file.is_open()){
+ if (!file.is_open()) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
@@ -50,7 +50,7 @@ int main(int argc, char **argv) {
file.read((char*)&numTextures, 4);
char **texNames = new char*[numTextures];
- for(int i=0;i<numTextures; i++){
+ for(int i = 0;i < numTextures; i++) {
file.read((char*)&strLength, 4);
texNames[i] = new char[strLength];
file.read(texNames[i], strLength);
@@ -67,7 +67,7 @@ int main(int argc, char **argv) {
*/
// Should create an empty mtl
- std::cout << "mtllib quit.mtl" << std::endl << "o Arrow"<< std::endl;
+ std::cout << "mtllib quit.mtl" << std::endl << "o Arrow" << std::endl;
// Vertices
// file.seekg(283);
int numVertices;
@@ -90,21 +90,21 @@ int main(int argc, char **argv) {
file.read((char *)&z, 4);
std::cout << "vn " << x << " " << y << " " << z << std::endl;
}
- file.seekg(numVertices * 12,ios::cur);
+ file.seekg(numVertices * 12, ios::cur);
// Actually, this file has 6*4*numVertices floats in this block.
- std::cout<<"usemtl (null)"<<std::endl;
+ std::cout << "usemtl (null)"<< std::endl;
// And then another block of unknowns
// Faces
// The head of this section needs quite a bit of rechecking
int numFaces = 0;
file.read((char *) &numFaces, 4);
- file.seekg(8,ios::cur);
+ file.seekg(8, ios::cur);
int faceLength = 0;
for(int j = 0;j < numFaces; j++){
- file.read((char*)&faceLength,4);
+ file.read((char*)&faceLength, 4);
short x = 0, y = 0, z = 0;
cout << "g " << j << endl;
- for (int i = 0; i < faceLength; i+=3) {
+ for (int i = 0; i < faceLength; i += 3) {
file.read((char *)&x, 2);
file.read((char *)&y, 2);
file.read((char *)&z, 2);
Commit: f2b774c1ffe24d7cf48ca1309bcd957d184d2a52
https://github.com/scummvm/scummvm-tools/commit/f2b774c1ffe24d7cf48ca1309bcd957d184d2a52
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-07-28T02:02:12-07:00
Commit Message:
Merge pull request #10 from somaen/meshb
MESHB2OBJ: Fixed offsets to work with more files
Changed paths:
tools/meshb2obj.cpp
Commit: 62ed95e05c75057d00d2dd7821f082c1511de502
https://github.com/scummvm/scummvm-tools/commit/62ed95e05c75057d00d2dd7821f082c1511de502
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-07-28T02:02:57-07:00
Commit Message:
Merge pull request #8 from somaen/endianness
TIL2BMP: Complete Big-Endian support
Changed paths:
tools/til2bmp.cpp
Commit: 6bc6873afb72b5903b8882f9f45f8aa51afc5b5b
https://github.com/scummvm/scummvm-tools/commit/6bc6873afb72b5903b8882f9f45f8aa51afc5b5b
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-07-28T12:20:58+02:00
Commit Message:
Fix labcopy
Changed paths:
tools/labcopy.cpp
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
index 347cd7582..21f832f30 100644
--- a/tools/labcopy.cpp
+++ b/tools/labcopy.cpp
@@ -35,7 +35,7 @@ FILE *inLab = NULL, *outLab = NULL;
bool copyLab(long lenght = 0) {
void *buffer;
- long copied_bytes, count;
+ long copied_bytes, count, remBytes;
if (lenght == 0) {
fseek(inLab, 0L, SEEK_END);
@@ -47,7 +47,8 @@ bool copyLab(long lenght = 0) {
fseek(inLab, 0, SEEK_SET);
while (copied_bytes < lenght) {
- count = (long)fread(buffer, 1, BUFFER_SIZE, inLab);
+ remBytes = lenght - copied_bytes;
+ count = (long)fread(buffer, 1, (remBytes < BUFFER_SIZE) ? remBytes : BUFFER_SIZE, inLab);
fwrite(buffer, count, 1, outLab);
copied_bytes += count;
if(ferror(inLab) != 0 || ferror(outLab) != 0) {
Commit: 2a5281ada7554f76e04a1b1e7b6862b4687a9143
https://github.com/scummvm/scummvm-tools/commit/2a5281ada7554f76e04a1b1e7b6862b4687a9143
Author: Pawel Kolodziejski (aquadran at xtr.net.pl)
Date: 2011-07-28T05:48:37-07:00
Commit Message:
Merge pull request #9 from YakBizzarro/labcopy
Add labcopy tool
Changed paths:
A tools/labcopy.cpp
tools/module.mk
Commit: 20cab0f50ee7949672fc26a1b49d59d9273c2cbb
https://github.com/scummvm/scummvm-tools/commit/20cab0f50ee7949672fc26a1b49d59d9273c2cbb
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-07-28T23:00:21+02:00
Commit Message:
Patchex: fixed the extraction of the whole cabinet and some possible memory-leaks. Simplified a bit the command line.
Changed paths:
tools/patchex/patchex.cpp
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index ac4b95d23..16de3eff2 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -39,40 +39,22 @@
#include <sys/types.h>
#include "tools/patchex/mspack.h"
-
-// Command line actions
-enum act { UNKNOWN_ACTION, CABINET_ACTION, LOCALISED_ACTION};
+#include "common/endian.h"
// Languages codes
-#define LANG_ALL1 "@@"
-#define LANG_ALL2 "Common"
+#define LANG_ALL "@@"
const char *kLanguages_ext[] = { "English", "French", "German", "Italian", "Portuguese", "Spanish", NULL};
-const char *kLanguages_code1[] = { "US", "FR", "GE", "IT", "PT", "SP", NULL };
-const char *kLanguages_code2[] = { "Eng", "Fra", "Deu", "Ita", "Brz", "Esp", NULL };
+const char *kLanguages_code[] = { "US", "FR", "GE", "IT", "PT", "SP", NULL };
// Extraction constans
-#define RAND_A (0x343FD)
-#define RAND_B (0x269EC3)
+#define RAND_A (0x343FD)
+#define RAND_B (0x269EC3)
#define CODE_TABLE_SIZE (0x100)
-#define CONTAINER_MAGIC "1CNT"
-#define CABINET_MAGIC "MSCF"
#define BUFFER_SIZE 102400
-unsigned int lang;
-
-// Some useful type and function
-typedef unsigned char byte;
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
-typedef signed char int8;
-typedef signed short int16;
-typedef signed int int32;
-
-uint32 READ_LE_UINT32(const void *ptr) {
- const uint8 *b = (const uint8 *)ptr;
- return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
-}
+int lang = -1;
+struct mscab_decompressor *cabd = NULL;
+struct mscabd_cabinet *cab = NULL;
struct mspack_file_p {
FILE *fh;
@@ -100,7 +82,8 @@ uint16 *create_dec_table(uint32 key) {
static struct mspack_file *res_open(struct mspack_system *handle, const char *filename, int mode) {
struct mspack_file_p *fh;
const char *fmode;
- uint32 magic, key;
+ char magic[4];
+ uint32 key;
uint8 count;
switch (mode) {
@@ -127,16 +110,16 @@ static struct mspack_file *res_open(struct mspack_system *handle, const char *fi
//Search for data
while(!feof(fh->fh)) {
//Check for content signature
- count = handle->read((struct mspack_file *) fh, &magic, 4);
- if (count == 4 && memcmp(&magic, CONTAINER_MAGIC, 4) == 0) {
+ count = handle->read((struct mspack_file *) fh, magic, 4);
+ if (count == 4 && READ_BE_UINT32(magic) == MKTAG('1','C','N','T')) {
handle->read((struct mspack_file *)fh, &key, 4);
key = READ_LE_UINT32(&key);
fh->CodeTable = create_dec_table(key);
fh->cabinet_offset = ftell(fh->fh);
//Check for cabinet signature
- count = handle->read((struct mspack_file *) fh, &magic, 4);
- if (count == 4 && memcmp(&magic, CABINET_MAGIC, 4) == 0) {
+ count = handle->read((struct mspack_file *) fh, magic, 4);
+ if (count == 4 && READ_BE_UINT32(magic) == MKTAG('M','S','C','F')) {
break;
} else {
free(fh->CodeTable);
@@ -235,8 +218,8 @@ static struct mspack_system res_system = {
void extract_cabinet(char *filename, unsigned int lenght) {
struct mspack_file *original_executable, *destination_cabinet;
void *buffer;
- unsigned int copied_bytes;
- int count;
+ unsigned int copied_bytes, remBytes;
+ int count, writeResult;
original_executable = res_open(&res_system, filename, MSPACK_SYS_OPEN_READ);
destination_cabinet = res_open(&res_system, "original.cab", MSPACK_SYS_OPEN_WRITE);
@@ -245,9 +228,17 @@ void extract_cabinet(char *filename, unsigned int lenght) {
copied_bytes = 0;
while (copied_bytes < lenght) {
- count = res_read(original_executable, buffer, BUFFER_SIZE);
- res_write(destination_cabinet, buffer, count);
+ remBytes = lenght - copied_bytes;
+ count = res_read(original_executable, buffer, (remBytes < BUFFER_SIZE) ? remBytes : BUFFER_SIZE);
+ writeResult = res_write(destination_cabinet, buffer, count);
copied_bytes += count;
+ if (count < 0 || writeResult < 0) {
+ printf("I/O Error!\n");
+ free(buffer);
+ res_close(original_executable);
+ res_close(destination_cabinet);
+ exit(1);
+ }
}
printf("Update cabinet extracted as original.cab.\n");
@@ -262,7 +253,9 @@ char *file_filter(const struct mscabd_file *file) {
filename_size = strlen(file->filename);
- //Skip executables and libries
+ /*Skip executables and libraries
+ * These files are useless for Residual and a proper extraction of these
+ * requires sub-folder support, so it isn't implemented. */
char *ext = file->filename + (filename_size - 3);
if (strcasecmp(ext, "exe") == 0 ||
strcasecmp(ext, "dll") == 0 ||
@@ -273,27 +266,29 @@ char *file_filter(const struct mscabd_file *file) {
filename = (char *)malloc(filename_size + 1);
+ /*Folder-style localization (EMI). Because EMI updates aren't multi-language,
+ * every file is extracted (except for Win's binaries). Subfolders are ignored.*/
+ char *fn = strchr(file->filename, '\\');
+ if (fn != NULL && fn[0] != 0) {
+ strcpy(filename, fn + 1);
+ return filename;
+ }
+
//Old-style localization (Grimfandango)
+ if (lang == -1) {
+ printf("No language specified or unknown language!\n");
+ free(filename);
+ exit(1);
+ }
+
if (filename_size > 3 && file->filename[2] == '_') {
char file_lang[3];
sscanf(file->filename, "%2s_%s",file_lang, filename);
- if (strcmp(file_lang, kLanguages_code1[lang]) == 0 || strcmp(file_lang, LANG_ALL1) == 0)
+ if (strcmp(file_lang, kLanguages_code[lang]) == 0 || strcmp(file_lang, LANG_ALL) == 0)
return filename;
}
- //Folder-style localization (EMI)
- unsigned int lcode_size_com, lcode_size_loc;
- lcode_size_com = strlen(LANG_ALL2);
- lcode_size_loc = strlen(kLanguages_code2[lang]);
- if ((filename_size > lcode_size_com && strncmp(file->filename, LANG_ALL2, lcode_size_com - 1) == 0) ||
- (filename_size > lcode_size_loc && strncmp(file->filename, kLanguages_code2[lang], lcode_size_loc) == 0) ) {
- char *fn = rindex(file->filename, '\\') + 1;
- if (fn != NULL) {
- strcpy(filename, fn);
- return filename;
- }
- }
-
+ //Cleanup
free(filename);
return NULL;
}
@@ -307,6 +302,7 @@ void extract_files(struct mscab_decompressor *cabd, struct mscabd_cabinet *cab)
if ((filename = file_filter(file))) {
if (cabd->extract(cabd, file, filename) != MSPACK_ERR_OK) {
printf("Extract error on %s!\n", file->filename);
+ free(filename);
continue;
}
printf("%s extracted as %s\n", file->filename, filename);
@@ -318,65 +314,70 @@ void extract_files(struct mscab_decompressor *cabd, struct mscabd_cabinet *cab)
printf("%d file(s) extracted.\n", files_extracted);
}
+void cleanup() {
+ if (cabd) {
+ if (cab)
+ cabd->close(cabd, cab);
+ mspack_destroy_cab_decompressor(cabd);
+ }
+}
+
int main(int argc, char *argv[]) {
- struct mscab_decompressor *cabd;
- struct mscabd_cabinet *cab;
int i;
- enum act action;
- char *(*filter) (struct mscabd_file *);
-
- action = UNKNOWN_ACTION;
+ unsigned int length;
+ bool wholeCabinet = false;
// Argument checks and usage display
- if (argc != 3) {
- printf("Usage: patchex PATCH_EXECUTABLE LANGUAGE\n");
- printf("Extract update files of game update from PATCH_EXECUTABLE (e.g. gfupd101.exe) in a specified LANGUAGE.\n");
- printf("Please be sure that the update contains this language.\n");
+ if (argc < 2) {
+ printf("Usage: patchex PATCH_EXECUTABLE [LANGUAGE]\n\n");
+ printf("Extract update files of game update from PATCH_EXECUTABLE\n");
+ printf("-For GrimFandango (gfupd101.exe) you must specify a language,\n");
+ printf("-For Monkey Island (MonkeyUpdate[_LANG].exe) this parameter is ignored,\n");
+ printf("please select the update executable according to your version.\n");
printf("Available languages:\n");
- for (i = 0; kLanguages_code1[i]; i++)
+ for (i = 0; kLanguages_code[i]; i++)
printf("- %s\n", kLanguages_ext[i]);
- printf("Alternately original archive could be extracted as original.cab with CABINET keyword insted of language.\n");
+ printf("Alternately original archive could be extracted as original.cab with CABINET keyword instead of language.\n");
exit(1);
}
- // Actions check
- // Cabinet check
- if (strncasecmp("CABINET", argv[2], strlen(argv[2])) == 0) {
- printf("Cabinet extraction selected\n");
- action = CABINET_ACTION;
- }
-
- // Language check
- for(i = 0; kLanguages_code1[i]; i++)
- if (strncasecmp(kLanguages_ext[i], argv[2], strlen(argv[2])) == 0) {
- printf("%s selected.\n", kLanguages_ext[i]);
- lang = i;
- action = LOCALISED_ACTION;
- break;
+ if (argc == 3) {
+ // Cabinet check
+ if (strncasecmp("CABINET", argv[2], strlen(argv[2])) == 0) {
+ printf("Cabinet extraction selected\n");
+ wholeCabinet = true;
}
- // Unknown action
- if (action == UNKNOWN_ACTION) {
- printf("Unknown language!\n");
- exit(1);
+ // Language check
+ for(i = 0; kLanguages_code[i]; i++)
+ if (strncasecmp(kLanguages_ext[i], argv[2], strlen(argv[2])) == 0) {
+ printf("%s selected.\n", kLanguages_ext[i]);
+ lang = i;
+ break;
+ }
}
-
- // Extraction !
- if ((cabd = mspack_create_cab_decompressor(&res_system)) != MSPACK_ERR_OK) {
- if ((cab = cabd->open(cabd, argv[1])) != MSPACK_ERR_OK) {
- if (action == CABINET_ACTION)
- extract_cabinet(argv[1], cab->length);
- else if (action == LOCALISED_ACTION)
- extract_files(cabd, cab);
- cabd->close(cabd, cab);
- } else
- printf("Unable to open %s!\n", argv[1]);
- mspack_destroy_cab_decompressor(cabd);
- } else {
+ //Initializations
+ atexit(cleanup);
+ if ((cabd = mspack_create_cab_decompressor(&res_system)) == NULL) {
printf("Internal error!\n");
exit(1);
}
+ cab = cabd->open(cabd, argv[1]);
+ if (cabd->last_error(cabd) != MSPACK_ERR_OK) {
+ printf("Unable to open %s!\n", argv[1]);
+ exit(1);
+ }
+
+ //Extraction !
+ if (wholeCabinet) {
+ length = cab->length;
+ cabd->close(cabd, cab);
+ cab = NULL;
+ extract_cabinet(argv[1], length);
+ } else
+ extract_files(cabd, cab);
+
return 0;
}
Commit: f7f7edc4bb5a3aa0b60557ab470eb6b8d546059d
https://github.com/scummvm/scummvm-tools/commit/f7f7edc4bb5a3aa0b60557ab470eb6b8d546059d
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-07-28T14:31:31-07:00
Commit Message:
Merge pull request #11 from YakBizzarro/patchex-clean
Patchex: Various fixes
Changed paths:
tools/patchex/patchex.cpp
Commit: aef9a068e445291d6e5f6ceffb40223c03b39e04
https://github.com/scummvm/scummvm-tools/commit/aef9a068e445291d6e5f6ceffb40223c03b39e04
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-11T01:36:25+02:00
Commit Message:
Initial commit of new EMI-tools
Changed paths:
A tools/emi/animb2txt.cpp
A tools/emi/filetools.h
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
new file mode 100644
index 000000000..4395f7dca
--- /dev/null
+++ b/tools/emi/animb2txt.cpp
@@ -0,0 +1,100 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
+// Based on Benjamin Haischs filetype-information.
+
+#include <fstream>
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+struct Vector3d {
+ float x;
+ float y;
+ float z;
+};
+
+std::string readString(std::fstream& file) {
+ int strLength = 0;
+ file.read((char*)&strLength, 4);
+ char* readString = new char[strLength];
+ file.read(readString, strLength);
+
+ std::string retVal(readString);
+ delete readString;
+
+ return retVal;
+}
+
+float readFloat(std::fstream& file) {
+ float retVal = 0.0f;
+ file.read((char*)&retVal, 4);
+ return retVal;
+}
+
+int readInt(std::fstream& file) {
+ int retVal = 0.0f;
+ file.read((char*)&retVal, 4);
+ return retVal;
+}
+
+Vector3d *readVector3d(std::fstream& file) {
+ Vector3d *vec3d = new Vector3d();
+ vec3d->x = readFloat(file);
+ vec3d->y = readFloat(file);
+ vec3d->z = readFloat(file);
+ return vec3d;
+}
+
+int main(int argc, char **argv) {
+ if(argc < 2){
+ std::cout << "Error: filename not specified" << std::endl;
+ return 0;
+ }
+ std::string filename = argv[1];
+
+ std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!file.is_open()) {
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+ std::string animName = readString(file);
+ float duration = readFloat(file);
+ int bones = readInt(file);
+ float time = 0.0f;
+ Vector3d *vec3d;
+ for (int i = 0; i < bones; i++) {
+ std::string boneName = readString(file);
+ int operation = readInt(file);
+ int unknown1 = readInt(file);
+ int unknown2 = readInt(file);
+ int numKeyframes = readInt(file);
+ if (operation == 3) { // Translation
+ vec3d = readVector3d(file);
+ } else if (operation == 4) { // Rotation
+
+ }
+ if (operation == 3 || operation == 4) {
+ time = readFloat(file);
+ }
+ }
+}
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
new file mode 100644
index 000000000..2c99005c4
--- /dev/null
+++ b/tools/emi/filetools.h
@@ -0,0 +1,63 @@
+#ifndef FILETOOLS_H
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
+
+#define FILETOOLS_H
+
+struct Vector3d {
+ float x;
+ float y;
+ float z;
+};
+
+std::string readString(std::fstream& file) {
+ int strLength = 0;
+ file.read((char*)&strLength, 4);
+ char* readString = new char[strLength];
+ file.read(readString, strLength);
+
+ std::string retVal(readString);
+ delete readString;
+
+ return retVal;
+}
+
+float readFloat(std::fstream& file) {
+ float retVal = 0.0f;
+ file.read((char*)&retVal, 4);
+ return retVal;
+}
+
+int readInt(std::fstream& file) {
+ int retVal = 0.0f;
+ file.read((char*)&retVal, 4);
+ return retVal;
+}
+
+Vector3d *readVector3d(std::fstream& file) {
+ Vector3d *vec3d = new Vector3d();
+ vec3d->x = readFloat(file);
+ vec3d->y = readFloat(file);
+ vec3d->z = readFloat(file);
+ return vec3d;
+}
+
+#endif
Commit: 8e2afdaedfae25e5e045b21a8e2500f827e226d5
https://github.com/scummvm/scummvm-tools/commit/8e2afdaedfae25e5e045b21a8e2500f827e226d5
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-11T01:37:59+02:00
Commit Message:
Added Meshb2obj to EMI-tools
Changed paths:
A tools/emi/meshb2obj.cpp
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
new file mode 100644
index 000000000..5254c0419
--- /dev/null
+++ b/tools/emi/meshb2obj.cpp
@@ -0,0 +1,159 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
+#include <fstream>
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char **argv) {
+ if(argc < 2){
+ std::cout << "Error: filename not specified" << std::endl;
+ return 0;
+ }
+ std::string filename = argv[1];
+
+ std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!file.is_open()) {
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+ int strLength = 0;
+
+ file.read((char*)&strLength, 4);
+
+ char* readString = new char[64];
+ file.read(readString, strLength);
+ // Unknown vector3d
+
+ // Then a list of textures 48 bytes later
+ int numTextures = 0;
+ file.seekg(48, ios::cur);
+ file.read((char*)&numTextures, 4);
+
+ char **texNames = new char*[numTextures];
+ for(int i = 0;i < numTextures; i++) {
+ file.read((char*)&strLength, 4);
+ texNames[i] = new char[strLength];
+ file.read(texNames[i], strLength);
+ // Every texname seems to be followed by 4 0-bytes
+ file.seekg(4, ios::cur);
+ }
+ for(int i = 0;i < numTextures;i++){
+ std::cout << "# TexName " << texNames[i] << std::endl;
+ }
+ // 4 unknown bytes - usually with value 19
+ file.seekg(4, ios::cur);
+/*
+ * Then follows the weird padding.
+ */
+
+ // Should create an empty mtl
+ std::cout << "mtllib quit.mtl" << std::endl << "o Arrow" << std::endl;
+
+ int numVertices;
+ file.read((char*)&numVertices, 4);
+ std::cout << "#File has " << numVertices << " Vertices" << std::endl;
+
+ float x = 0, y = 0, z = 0;
+
+ // Vertices
+ for (int i = 0; i < numVertices; ++i) {
+ file.read((char *)&x, 4);
+ file.read((char *)&y, 4);
+ file.read((char *)&z, 4);
+ std::cout << "v " << x << " " << y << " " << z << std::endl;
+ }
+ // Vertex-normals
+ for (int i = 0; i < numVertices; ++i) {
+ file.read((char *)&x, 4);
+ file.read((char *)&y, 4);
+ file.read((char *)&z, 4);
+ std::cout << "vn " << x << " " << y << " " << z << std::endl;
+ }
+ // Color map-data, dunno how to interpret them right now.
+ file.seekg(numVertices * 4, ios::cur);
+ for (int i = 0; i < numVertices; ++i) {
+ file.read((char *)&x, 4);
+ file.read((char *)&y, 4);
+ std::cout << "vt " << x << " " << y << " " << z << std::endl;
+ }
+
+ std::cout << "usemtl (null)"<< std::endl;
+
+ // Faces
+ // The head of this section needs quite a bit of rechecking
+ int numFaces = 0;
+ int hasTexture = 0;
+ int texID = 0;
+ int flags = 0;
+ file.read((char *) &numFaces, 4);
+ //file.seekg(8, ios::cur);
+ int faceLength = 0;
+ for(int j = 0;j < numFaces; j++){
+ file.read((char*)&flags, 4);
+ file.read((char*)&hasTexture, 4);
+ if(hasTexture)
+ file.read((char*)&texID, 4);
+ file.read((char*)&faceLength, 4);
+ std::cout << "#Face-header: flags: " << flags << " hasTexture: " << hasTexture
+ << " texId: " << texID << " faceLength: " << faceLength << std::endl;
+ short x = 0, y = 0, z = 0;
+ cout << "g " << j << endl;
+ for (int i = 0; i < faceLength; i += 3) {
+ file.read((char *)&x, 2);
+ file.read((char *)&y, 2);
+ file.read((char *)&z, 2);
+ ++x;
+ ++y;
+ ++z;
+ std::cout << "f " << x << "//" << x << " " << y << "//" << y << " " << z << "//" << z << std::endl;
+ }
+ }
+ int hasBones = 0;
+ file.read((char*)&hasBones, 4);
+
+ if (hasBones == 1) {
+ int numBones = 0;
+ file.read((char*)&numBones, 4);
+ char **boneNames = new char*[numBones];
+ for(int i = 0;i < numBones; i++) {
+ file.read((char*)&strLength, 4);
+ boneNames[i] = new char[strLength];
+ file.read(boneNames[i], strLength);
+ std::cout << "# BoneName " << boneNames[i] << std::endl;
+ }
+
+ int numBoneData = 0;
+ int unknownVal = 0;
+ int boneDatanum;
+ float boneDataWgt;
+ file.read((char*)&numBoneData, 4);
+ for(int i = 0;i < numBoneData; i++) {
+ file.read((char*)&unknownVal, 4);
+ file.read((char*)&boneDatanum, 4);
+ file.read((char*)&boneDataWgt, 4);
+ std::cout << "# BoneData: Unknown: " << unknownVal << " boneNum: "
+ << boneDatanum << " weight: " << boneDataWgt << std::endl;
+ }
+ }
+}
Commit: 249931064af8d2f7a6905abacd63cb73281d4518
https://github.com/scummvm/scummvm-tools/commit/249931064af8d2f7a6905abacd63cb73281d4518
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-11T01:38:47+02:00
Commit Message:
Added sklb2txt to EMI-tools
Changed paths:
A tools/emi/sklb2txt.cpp
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
new file mode 100644
index 000000000..36648a19e
--- /dev/null
+++ b/tools/emi/sklb2txt.cpp
@@ -0,0 +1,59 @@
+#include <fstream>
+#include <string>
+#include <iostream>
+
+// Based on Benjamin Haischs work on sklb-files.
+
+using namespace std;
+
+int main(int argc, char **argv) {
+ if(argc<2){
+ std::cout << "Error: filename not specified" << std::endl;
+ return 0;
+ }
+ std::string filename=argv[1];
+
+ std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!file.is_open()){
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+ int strLength = 0;
+ int numBones = 0;
+
+ file.read((char*)&numBones,4);
+
+
+ char boneString[32];
+ char parentString[32];
+
+ float x = 0, y = 0, z = 0, angle = 0;
+ // Bones are listed in the same order as in the meshb.
+ for(int i=0;i<numBones;i++){
+ file.read((char*)&boneString,32);
+ file.read((char*)&parentString,32);
+
+ std::cout << "# BoneName " << boneString << "\twith parent: " << parentString << "\t";
+ //file.seekg(28,ios::cur);
+ std::cout << " position: ";
+ file.read((char*)&x,4);
+ file.read((char*)&y,4);
+ file.read((char*)&z,4);
+ std::cout << x << " " << y << " " << z << " ";
+ std::cout << " rotation: ";
+ file.read((char*)&x,4);
+ file.read((char*)&y,4);
+ file.read((char*)&z,4);
+ std::cout << x << " " << y << " " << z << " angle: ";
+ file.read((char*)&angle,4);
+ std::cout << angle << std::endl;
+
+ }
+ /*
+ The last 28 bytes are, by looking at guy.sklb:
+ INT(0) <-- This has another value for 1 entry in el1.sklb.
+ INT(0) <-- except for the second entry, pelvis.
+
+ */
+}
\ No newline at end of file
Commit: a6daa890acf98537f507838d80ca2280028fe2a7
https://github.com/scummvm/scummvm-tools/commit/a6daa890acf98537f507838d80ca2280028fe2a7
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-11T02:00:09+02:00
Commit Message:
Cleanup in MESHB/SKLB/ANIMB-converters
Changed paths:
A tools/emi/til2bmp.cpp
R tools/til2bmp.cpp
tools/emi/animb2txt.cpp
tools/emi/filetools.h
tools/emi/meshb2obj.cpp
tools/emi/sklb2txt.cpp
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 4395f7dca..083c422d8 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -23,47 +23,10 @@
#include <fstream>
#include <string>
#include <iostream>
+#include "filetools.h"
using namespace std;
-struct Vector3d {
- float x;
- float y;
- float z;
-};
-
-std::string readString(std::fstream& file) {
- int strLength = 0;
- file.read((char*)&strLength, 4);
- char* readString = new char[strLength];
- file.read(readString, strLength);
-
- std::string retVal(readString);
- delete readString;
-
- return retVal;
-}
-
-float readFloat(std::fstream& file) {
- float retVal = 0.0f;
- file.read((char*)&retVal, 4);
- return retVal;
-}
-
-int readInt(std::fstream& file) {
- int retVal = 0.0f;
- file.read((char*)&retVal, 4);
- return retVal;
-}
-
-Vector3d *readVector3d(std::fstream& file) {
- Vector3d *vec3d = new Vector3d();
- vec3d->x = readFloat(file);
- vec3d->y = readFloat(file);
- vec3d->z = readFloat(file);
- return vec3d;
-}
-
int main(int argc, char **argv) {
if(argc < 2){
std::cout << "Error: filename not specified" << std::endl;
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index 2c99005c4..db1898786 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -22,10 +22,19 @@
#define FILETOOLS_H
+#include <fstream>
+#include <string>
+#include <sstream>
+
struct Vector3d {
float x;
float y;
float z;
+ std::string toString() {
+ std::stringstream ss;
+ ss << x << " " << y << " " << z;
+ return ss.str();
+ }
};
std::string readString(std::fstream& file) {
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index 5254c0419..8211d3f73 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -21,8 +21,7 @@
#include <fstream>
#include <string>
#include <iostream>
-
-using namespace std;
+#include "filetools.h"
int main(int argc, char **argv) {
if(argc < 2){
@@ -39,30 +38,25 @@ int main(int argc, char **argv) {
}
int strLength = 0;
- file.read((char*)&strLength, 4);
-
- char* readString = new char[64];
- file.read(readString, strLength);
+ std::string nameString = readString(file);
// Unknown vector3d
// Then a list of textures 48 bytes later
- int numTextures = 0;
- file.seekg(48, ios::cur);
- file.read((char*)&numTextures, 4);
- char **texNames = new char*[numTextures];
+ file.seekg(48, std::ios::cur);
+ int numTextures = readInt(file);
+
+ std::string *texNames = new std::string[numTextures];
for(int i = 0;i < numTextures; i++) {
- file.read((char*)&strLength, 4);
- texNames[i] = new char[strLength];
- file.read(texNames[i], strLength);
+ texNames[i] = readString(file);
// Every texname seems to be followed by 4 0-bytes
- file.seekg(4, ios::cur);
+ file.seekg(4, std::ios::cur);
}
for(int i = 0;i < numTextures;i++){
std::cout << "# TexName " << texNames[i] << std::endl;
}
// 4 unknown bytes - usually with value 19
- file.seekg(4, ios::cur);
+ file.seekg(4, std::ios::cur);
/*
* Then follows the weird padding.
*/
@@ -70,28 +64,26 @@ int main(int argc, char **argv) {
// Should create an empty mtl
std::cout << "mtllib quit.mtl" << std::endl << "o Arrow" << std::endl;
- int numVertices;
- file.read((char*)&numVertices, 4);
+ int numVertices = readInt(file);
std::cout << "#File has " << numVertices << " Vertices" << std::endl;
float x = 0, y = 0, z = 0;
// Vertices
+ Vector3d *vec;
for (int i = 0; i < numVertices; ++i) {
- file.read((char *)&x, 4);
- file.read((char *)&y, 4);
- file.read((char *)&z, 4);
- std::cout << "v " << x << " " << y << " " << z << std::endl;
+ vec = readVector3d(file);
+ std::cout << "v " << vec->x << " " << vec->y << " " << vec->z << std::endl;
+ delete vec;
}
// Vertex-normals
for (int i = 0; i < numVertices; ++i) {
- file.read((char *)&x, 4);
- file.read((char *)&y, 4);
- file.read((char *)&z, 4);
- std::cout << "vn " << x << " " << y << " " << z << std::endl;
+ vec = readVector3d(file);
+ std::cout << "vn " << vec->x << " " << vec->y << " " << vec->z << std::endl;
+ delete vec;
}
// Color map-data, dunno how to interpret them right now.
- file.seekg(numVertices * 4, ios::cur);
+ file.seekg(numVertices * 4, std::ios::cur);
for (int i = 0; i < numVertices; ++i) {
file.read((char *)&x, 4);
file.read((char *)&y, 4);
@@ -107,18 +99,17 @@ int main(int argc, char **argv) {
int texID = 0;
int flags = 0;
file.read((char *) &numFaces, 4);
- //file.seekg(8, ios::cur);
int faceLength = 0;
for(int j = 0;j < numFaces; j++){
- file.read((char*)&flags, 4);
- file.read((char*)&hasTexture, 4);
+ flags = readInt(file);
+ hasTexture = readInt(file);
if(hasTexture)
- file.read((char*)&texID, 4);
- file.read((char*)&faceLength, 4);
+ texID = readInt(file);
+ faceLength = readInt(file);
std::cout << "#Face-header: flags: " << flags << " hasTexture: " << hasTexture
<< " texId: " << texID << " faceLength: " << faceLength << std::endl;
short x = 0, y = 0, z = 0;
- cout << "g " << j << endl;
+ std::cout << "g " << j << std::endl;
for (int i = 0; i < faceLength; i += 3) {
file.read((char *)&x, 2);
file.read((char *)&y, 2);
@@ -133,8 +124,7 @@ int main(int argc, char **argv) {
file.read((char*)&hasBones, 4);
if (hasBones == 1) {
- int numBones = 0;
- file.read((char*)&numBones, 4);
+ int numBones = readInt(file);
char **boneNames = new char*[numBones];
for(int i = 0;i < numBones; i++) {
file.read((char*)&strLength, 4);
@@ -143,15 +133,14 @@ int main(int argc, char **argv) {
std::cout << "# BoneName " << boneNames[i] << std::endl;
}
- int numBoneData = 0;
+ int numBoneData = readInt(file);
int unknownVal = 0;
int boneDatanum;
float boneDataWgt;
- file.read((char*)&numBoneData, 4);
for(int i = 0;i < numBoneData; i++) {
- file.read((char*)&unknownVal, 4);
- file.read((char*)&boneDatanum, 4);
- file.read((char*)&boneDataWgt, 4);
+ unknownVal = readInt(file);
+ boneDatanum = readInt(file);
+ boneDataWgt = readFloat(file);
std::cout << "# BoneData: Unknown: " << unknownVal << " boneNum: "
<< boneDatanum << " weight: " << boneDataWgt << std::endl;
}
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
index 36648a19e..56b66e5de 100644
--- a/tools/emi/sklb2txt.cpp
+++ b/tools/emi/sklb2txt.cpp
@@ -1,7 +1,7 @@
#include <fstream>
#include <string>
#include <iostream>
-
+#include "filetools.h"
// Based on Benjamin Haischs work on sklb-files.
using namespace std;
@@ -20,33 +20,29 @@ int main(int argc, char **argv) {
return 0;
}
int strLength = 0;
- int numBones = 0;
-
- file.read((char*)&numBones,4);
-
+ int numBones = readInt(file);
char boneString[32];
char parentString[32];
float x = 0, y = 0, z = 0, angle = 0;
// Bones are listed in the same order as in the meshb.
- for(int i=0;i<numBones;i++){
+ Vector3d *vec = 0;
+ for(int i=0;i<numBones;i++) {
file.read((char*)&boneString,32);
file.read((char*)&parentString,32);
std::cout << "# BoneName " << boneString << "\twith parent: " << parentString << "\t";
//file.seekg(28,ios::cur);
std::cout << " position: ";
- file.read((char*)&x,4);
- file.read((char*)&y,4);
- file.read((char*)&z,4);
- std::cout << x << " " << y << " " << z << " ";
+ vec = readVector3d(file);
+ std::cout << vec->toString();
+ delete vec;
std::cout << " rotation: ";
- file.read((char*)&x,4);
- file.read((char*)&y,4);
- file.read((char*)&z,4);
- std::cout << x << " " << y << " " << z << " angle: ";
- file.read((char*)&angle,4);
+ vec = readVector3d(file);
+ std::cout << vec->toString();
+ delete vec;
+ angle = readFloat(file);
std::cout << angle << std::endl;
}
diff --git a/tools/til2bmp.cpp b/tools/emi/til2bmp.cpp
similarity index 100%
rename from tools/til2bmp.cpp
rename to tools/emi/til2bmp.cpp
Commit: 0c4fcddb29a2be8d1263f5f5c45b86d63b2d66c5
https://github.com/scummvm/scummvm-tools/commit/0c4fcddb29a2be8d1263f5f5c45b86d63b2d66c5
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-11T02:00:29+02:00
Commit Message:
Added MESHB/SKLB/ANIMB-converters to module.mk
Changed paths:
tools/module.mk
diff --git a/tools/module.mk b/tools/module.mk
index 02403b283..ef3555b64 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -63,16 +63,26 @@ tools/int2flt$(EXEEXT): $(srcdir)/tools/int2flt.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
-tools/meshb2obj$(EXEEXT): $(srcdir)/tools/meshb2obj.cpp
+tools/meshb2obj$(EXEEXT): $(srcdir)/tools/emi/meshb2obj.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common -o $@ $<
-
+
+tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common -o $@ $<
+
+tools/sklb2txt$(EXEEXT): $(srcdir)/tools/emi/sklb2txt.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common -o $@ $<
+
tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
-tools/til2bmp$(EXEEXT): $(srcdir)/tools/til2bmp.cpp
+tools/til2bmp$(EXEEXT): $(srcdir)/tools/emi/til2bmp.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common -lz -o $@ $<
Commit: 5b23a6b8bfdc88778a8fbe13902702da4c776430
https://github.com/scummvm/scummvm-tools/commit/5b23a6b8bfdc88778a8fbe13902702da4c776430
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-13T12:22:19+02:00
Commit Message:
EMI: Cleaned tools
Changed paths:
R tools/meshb2obj.cpp
tools/emi/animb2txt.cpp
tools/emi/meshb2obj.cpp
tools/emi/sklb2txt.cpp
tools/module.mk
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 083c422d8..461b90724 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -43,6 +43,7 @@ int main(int argc, char **argv) {
std::string animName = readString(file);
float duration = readFloat(file);
int bones = readInt(file);
+ std::cout << "animName: " << animName << " duration: " << duration << " bones: " << bones << std::endl;
float time = 0.0f;
Vector3d *vec3d;
for (int i = 0; i < bones; i++) {
@@ -59,5 +60,7 @@ int main(int argc, char **argv) {
if (operation == 3 || operation == 4) {
time = readFloat(file);
}
+ std::cout << "Bone: " << i << " Operation: " << operation << " Unknown1: " << unknown1 <<
+ " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
}
}
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index 8211d3f73..baccdd85e 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -137,11 +137,14 @@ int main(int argc, char **argv) {
int unknownVal = 0;
int boneDatanum;
float boneDataWgt;
+ int vertex = 0;
for(int i = 0;i < numBoneData; i++) {
unknownVal = readInt(file);
boneDatanum = readInt(file);
boneDataWgt = readFloat(file);
- std::cout << "# BoneData: Unknown: " << unknownVal << " boneNum: "
+ if(unknownVal)
+ vertex++;
+ std::cout << "# BoneData: Vertex: " << vertex << " boneNum: "
<< boneDatanum << " weight: " << boneDataWgt << std::endl;
}
}
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
index 56b66e5de..e167d8377 100644
--- a/tools/emi/sklb2txt.cpp
+++ b/tools/emi/sklb2txt.cpp
@@ -19,13 +19,12 @@ int main(int argc, char **argv) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
- int strLength = 0;
int numBones = readInt(file);
char boneString[32];
char parentString[32];
-
- float x = 0, y = 0, z = 0, angle = 0;
+
+ float angle = 0;
// Bones are listed in the same order as in the meshb.
Vector3d *vec = 0;
for(int i=0;i<numBones;i++) {
@@ -52,4 +51,4 @@ int main(int argc, char **argv) {
INT(0) <-- except for the second entry, pelvis.
*/
-}
\ No newline at end of file
+}
diff --git a/tools/meshb2obj.cpp b/tools/meshb2obj.cpp
deleted file mode 100644
index b09ba7731..000000000
--- a/tools/meshb2obj.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-* $URL:
-* $Id:
-*
-*/
-
-#include <fstream>
-#include <string>
-#include <iostream>
-
-using namespace std;
-
-int main(int argc, char **argv) {
- if(argc < 2){
- std::cout << "Error: filename not specified" << std::endl;
- return 0;
- }
- std::string filename = argv[1];
-
- std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
-
- if (!file.is_open()) {
- std::cout << "Unable to open file " << filename << std::endl;
- return 0;
- }
- int strLength = 0;
-
- file.read((char*)&strLength, 4);
-
- char* readString = new char[64];
- file.read(readString, strLength);
-
- // Then a list of textures 48 bytes later
- int numTextures = 0;
- file.seekg(48, ios::cur);
- file.read((char*)&numTextures, 4);
-
- char **texNames = new char*[numTextures];
- for(int i = 0;i < numTextures; i++) {
- file.read((char*)&strLength, 4);
- texNames[i] = new char[strLength];
- file.read(texNames[i], strLength);
- // Every texname seems to be followed by 4 0-bytes
- file.seekg(4, ios::cur);
- }
- for(int i = 0;i < numTextures;i++){
- std::cout << "# TexName " << texNames[i] << std::endl;
- }
- // 4 unknown bytes - usually with value 19
- file.seekg(4, ios::cur);
-/*
- * Then follows the weird padding.
- */
-
- // Should create an empty mtl
- std::cout << "mtllib quit.mtl" << std::endl << "o Arrow" << std::endl;
- // Vertices
- // file.seekg(283);
- int numVertices;
- file.read((char*)&numVertices, 4);
- std::cout << "#File has " << numVertices << " Vertices" << std::endl;
-
- //file.seekg(287);
- float x = 0, y = 0, z = 0;
-
- for (int i = 0; i < numVertices; ++i) {
- file.read((char *)&x, 4);
- file.read((char *)&y, 4);
- file.read((char *)&z, 4);
- std::cout << "v " << x << " " << y << " " << z << std::endl;
- }
-// Vertice-normals?
- for (int i = 0; i < numVertices; ++i) {
- file.read((char *)&x, 4);
- file.read((char *)&y, 4);
- file.read((char *)&z, 4);
- std::cout << "vn " << x << " " << y << " " << z << std::endl;
- }
- file.seekg(numVertices * 12, ios::cur);
- // Actually, this file has 6*4*numVertices floats in this block.
- std::cout << "usemtl (null)"<< std::endl;
- // And then another block of unknowns
- // Faces
- // The head of this section needs quite a bit of rechecking
- int numFaces = 0;
- file.read((char *) &numFaces, 4);
- file.seekg(8, ios::cur);
- int faceLength = 0;
- for(int j = 0;j < numFaces; j++){
- file.read((char*)&faceLength, 4);
- short x = 0, y = 0, z = 0;
- cout << "g " << j << endl;
- for (int i = 0; i < faceLength; i += 3) {
- file.read((char *)&x, 2);
- file.read((char *)&y, 2);
- file.read((char *)&z, 2);
- ++x;
- ++y;
- ++z;
- std::cout << "f " << x << "//" << x << " " << y << "//" << y << " " << z << "//" << z << std::endl;
- }
- // 12 bytes of unknown
- file.seekg(12, ios::cur);
- }
-}
diff --git a/tools/module.mk b/tools/module.mk
index ef3555b64..04e625e57 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -15,6 +15,8 @@ TOOLS := \
tools/imc2wav$(EXEEXT) \
tools/int2flt$(EXEEXT) \
tools/meshb2obj$(EXEEXT) \
+ tools/sklb2txt$(EXEEXT) \
+ tools/animb2txt$(EXEEXT) \
tools/set2fig$(EXEEXT) \
tools/til2bmp$(EXEEXT) \
tools/unlab$(EXEEXT) \
Commit: 5a60992303a8b97249252e52b8fd1dff05812f91
https://github.com/scummvm/scummvm-tools/commit/5a60992303a8b97249252e52b8fd1dff05812f91
Author: somaen (einarjohan at somadalen.com)
Date: 2011-08-13T03:24:33-07:00
Commit Message:
Merge pull request #12 from somaen/emi-tools
EMI Tools
Changed paths:
A tools/emi/animb2txt.cpp
A tools/emi/filetools.h
A tools/emi/meshb2obj.cpp
A tools/emi/sklb2txt.cpp
A tools/emi/til2bmp.cpp
R tools/meshb2obj.cpp
R tools/til2bmp.cpp
tools/module.mk
Commit: a1cc6e9780dc3828916e78556129703acfa0455e
https://github.com/scummvm/scummvm-tools/commit/a1cc6e9780dc3828916e78556129703acfa0455e
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-13T12:30:50+02:00
Commit Message:
Moved SetB2Set into tools/emi
Changed paths:
A tools/emi/setb2set.cpp
R tools/setb2set.cpp
tools/module.mk
diff --git a/tools/setb2set.cpp b/tools/emi/setb2set.cpp
similarity index 100%
rename from tools/setb2set.cpp
rename to tools/emi/setb2set.cpp
diff --git a/tools/module.mk b/tools/module.mk
index 04e625e57..c24acb8e4 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -17,6 +17,7 @@ TOOLS := \
tools/meshb2obj$(EXEEXT) \
tools/sklb2txt$(EXEEXT) \
tools/animb2txt$(EXEEXT) \
+ tools/setb2set$(EXEEXT) \
tools/set2fig$(EXEEXT) \
tools/til2bmp$(EXEEXT) \
tools/unlab$(EXEEXT) \
@@ -75,6 +76,11 @@ tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common -o $@ $<
+tools/setb2set$(EXEEXT): $(srcdir)/tools/emi/setb2set.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common -o $@ $<
+
tools/sklb2txt$(EXEEXT): $(srcdir)/tools/emi/sklb2txt.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
Commit: 9ba04d48f152ad9b472a26d3d3b1849abe17020d
https://github.com/scummvm/scummvm-tools/commit/9ba04d48f152ad9b472a26d3d3b1849abe17020d
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-14T17:47:07+02:00
Commit Message:
MESHB2OBJ: Added decoding colors, and the header
Changed paths:
tools/emi/filetools.h
tools/emi/meshb2obj.cpp
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index db1898786..f4275e118 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -37,6 +37,18 @@ struct Vector3d {
}
};
+struct Vector4d {
+ float x;
+ float y;
+ float z;
+ float w;
+ std::string toString() {
+ std::stringstream ss;
+ ss << x << " " << y << " " << z << " " << w;
+ return ss.str();
+ }
+};
+
std::string readString(std::fstream& file) {
int strLength = 0;
file.read((char*)&strLength, 4);
@@ -56,11 +68,17 @@ float readFloat(std::fstream& file) {
}
int readInt(std::fstream& file) {
- int retVal = 0.0f;
+ int retVal = 0;
file.read((char*)&retVal, 4);
return retVal;
}
+int readByte(std::fstream& file) {
+ char retVal = 0;
+ file.read((char*)&retVal, 1);
+ return retVal;
+}
+
Vector3d *readVector3d(std::fstream& file) {
Vector3d *vec3d = new Vector3d();
vec3d->x = readFloat(file);
@@ -69,4 +87,13 @@ Vector3d *readVector3d(std::fstream& file) {
return vec3d;
}
+Vector4d *readVector4d(std::fstream& file) {
+ Vector4d *vec4d = new Vector4d();
+ vec4d->x = readFloat(file);
+ vec4d->y = readFloat(file);
+ vec4d->z = readFloat(file);
+ vec4d->w = readFloat(file);
+ return vec4d;
+}
+
#endif
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index baccdd85e..b5d7e0d04 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -40,16 +40,29 @@ int main(int argc, char **argv) {
std::string nameString = readString(file);
// Unknown vector3d
-
+ Vector4d *vec4d;
+ Vector3d *vec3d;
// Then a list of textures 48 bytes later
-
- file.seekg(48, std::ios::cur);
+ vec4d = readVector4d(file);
+ std::cout << "# Spheredata: " << vec4d->toString() << std::endl;
+ delete vec4d;
+ vec3d = readVector3d(file);
+ std::cout << "# Boxdata: " << vec3d->toString();
+ delete vec3d;
+ vec3d = readVector3d(file);
+ std::cout << vec3d->toString() << std::endl;
+ delete vec3d;
+
+ int numTexSets = readInt(file);
+ int setType = readInt(file);
+ std::cout << "# NumTexSets: " << numTexSets << " setType: " << setType << std::endl;
int numTextures = readInt(file);
std::string *texNames = new std::string[numTextures];
for(int i = 0;i < numTextures; i++) {
texNames[i] = readString(file);
- // Every texname seems to be followed by 4 0-bytes
+ // Every texname seems to be followed by 4 0-bytes (Ref mk1.mesh,
+ // this is intentional)
file.seekg(4, std::ios::cur);
}
for(int i = 0;i < numTextures;i++){
@@ -67,8 +80,8 @@ int main(int argc, char **argv) {
int numVertices = readInt(file);
std::cout << "#File has " << numVertices << " Vertices" << std::endl;
- float x = 0, y = 0, z = 0;
-
+ float x = 0, y = 0;
+ int r = 0, g = 0, b = 0, a = 0;
// Vertices
Vector3d *vec;
for (int i = 0; i < numVertices; ++i) {
@@ -83,11 +96,18 @@ int main(int argc, char **argv) {
delete vec;
}
// Color map-data, dunno how to interpret them right now.
- file.seekg(numVertices * 4, std::ios::cur);
+ for (int i = 0; i < numVertices; ++i) {
+ r = readByte(file);
+ g = readByte(file);
+ b = readByte(file);
+ a = readByte(file);
+ std::cout << "# R: " << r << " G: " << g << " B: " << b << " A: " << a << std::endl;
+ }
+ // Texture-vertices
for (int i = 0; i < numVertices; ++i) {
file.read((char *)&x, 4);
file.read((char *)&y, 4);
- std::cout << "vt " << x << " " << y << " " << z << std::endl;
+ std::cout << "vt " << x << " " << y << std::endl;
}
std::cout << "usemtl (null)"<< std::endl;
Commit: b605a50a1e15f9b7f8004cd1463f758e014b2585
https://github.com/scummvm/scummvm-tools/commit/b605a50a1e15f9b7f8004cd1463f758e014b2585
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-14T17:51:54+02:00
Commit Message:
MESHB2OBJ: Cleanup
Changed paths:
tools/emi/meshb2obj.cpp
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index b5d7e0d04..a74e411b8 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -39,10 +39,10 @@ int main(int argc, char **argv) {
int strLength = 0;
std::string nameString = readString(file);
- // Unknown vector3d
+
Vector4d *vec4d;
Vector3d *vec3d;
- // Then a list of textures 48 bytes later
+
vec4d = readVector4d(file);
std::cout << "# Spheredata: " << vec4d->toString() << std::endl;
delete vec4d;
@@ -70,9 +70,6 @@ int main(int argc, char **argv) {
}
// 4 unknown bytes - usually with value 19
file.seekg(4, std::ios::cur);
-/*
- * Then follows the weird padding.
- */
// Should create an empty mtl
std::cout << "mtllib quit.mtl" << std::endl << "o Arrow" << std::endl;
@@ -83,17 +80,16 @@ int main(int argc, char **argv) {
float x = 0, y = 0;
int r = 0, g = 0, b = 0, a = 0;
// Vertices
- Vector3d *vec;
for (int i = 0; i < numVertices; ++i) {
- vec = readVector3d(file);
- std::cout << "v " << vec->x << " " << vec->y << " " << vec->z << std::endl;
- delete vec;
+ vec3d = readVector3d(file);
+ std::cout << "v " << vec3d->x << " " << vec3d->y << " " << vec3d->z << std::endl;
+ delete vec3d;
}
// Vertex-normals
for (int i = 0; i < numVertices; ++i) {
- vec = readVector3d(file);
- std::cout << "vn " << vec->x << " " << vec->y << " " << vec->z << std::endl;
- delete vec;
+ vec3d = readVector3d(file);
+ std::cout << "vn " << vec3d->x << " " << vec3d->y << " " << vec3d->z << std::endl;
+ delete vec3d;
}
// Color map-data, dunno how to interpret them right now.
for (int i = 0; i < numVertices; ++i) {
Commit: c7d2a86bc4613a14559f78323f921f2705996c22
https://github.com/scummvm/scummvm-tools/commit/c7d2a86bc4613a14559f78323f921f2705996c22
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-23T01:44:57+02:00
Commit Message:
EMI: Add simple meshb-renderer, depends on GLFW
Changed paths:
A tools/emi/lab.h
A tools/emi/model.h
A tools/emi/renderModel.cpp
tools/emi/filetools.h
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index f4275e118..c70c9c9db 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -26,6 +26,28 @@
#include <string>
#include <sstream>
+template<typename T>
+struct Vector3 {
+ T _x;
+ T _y;
+ T _z;
+ void setVal(T x, T y, T z) {
+ _x = x;
+ _y = y;
+ _z = z;
+ }
+};
+
+struct Vector2d {
+ float x;
+ float y;
+ std::string toString() {
+ std::stringstream ss;
+ ss << x << " " << y;
+ return ss.str();
+ }
+};
+
struct Vector3d {
float x;
float y;
@@ -49,7 +71,7 @@ struct Vector4d {
}
};
-std::string readString(std::fstream& file) {
+std::string readString(std::istream& file) {
int strLength = 0;
file.read((char*)&strLength, 4);
char* readString = new char[strLength];
@@ -61,33 +83,50 @@ std::string readString(std::fstream& file) {
return retVal;
}
-float readFloat(std::fstream& file) {
+float readFloat(std::istream& file) {
float retVal = 0.0f;
file.read((char*)&retVal, 4);
return retVal;
}
-int readInt(std::fstream& file) {
+int readInt(std::istream& file) {
int retVal = 0;
file.read((char*)&retVal, 4);
return retVal;
}
-int readByte(std::fstream& file) {
+short readShort(std::istream& file) {
+ short retVal = 0;
+ file.read((char*)&retVal, 2);
+ return retVal;
+}
+
+int readByte(std::istream& file) {
char retVal = 0;
file.read((char*)&retVal, 1);
return retVal;
}
-Vector3d *readVector3d(std::fstream& file) {
- Vector3d *vec3d = new Vector3d();
- vec3d->x = readFloat(file);
- vec3d->y = readFloat(file);
- vec3d->z = readFloat(file);
+Vector2d *readVector2d(std::istream& file, int count=1) {
+ Vector2d *vec2d = new Vector2d[count];
+ for (int i = 0; i < count; i++) {
+ vec2d[i].x = readFloat(file);
+ vec2d[i].y = readFloat(file);
+ }
+ return vec2d;
+}
+
+Vector3d *readVector3d(std::istream& file, int count=1) {
+ Vector3d *vec3d = new Vector3d[count];
+ for (int i = 0; i < count; i++) {
+ vec3d[i].x = readFloat(file);
+ vec3d[i].y = readFloat(file);
+ vec3d[i].z = readFloat(file);
+ }
return vec3d;
}
-Vector4d *readVector4d(std::fstream& file) {
+Vector4d *readVector4d(std::istream& file) {
Vector4d *vec4d = new Vector4d();
vec4d->x = readFloat(file);
vec4d->y = readFloat(file);
diff --git a/tools/emi/lab.h b/tools/emi/lab.h
new file mode 100644
index 000000000..028cbbb2d
--- /dev/null
+++ b/tools/emi/lab.h
@@ -0,0 +1,84 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
+#ifndef LAB_H
+#define LAB_H
+
+#include <string>
+#include <iostream>
+
+#define GT_GRIM 1
+#define GT_EMI 2
+
+struct lab_header {
+ uint32_t magic;
+ uint32_t magic2;
+ uint32_t num_entries;
+ uint32_t string_table_size;
+ uint32_t string_table_offset;
+};
+
+struct lab_entry {
+ uint32_t fname_offset;
+ uint32_t start;
+ uint32_t size;
+ uint32_t reserved;
+};
+
+uint16_t READ_LE_UINT16(const void *ptr) {
+ const uint8_t *b = (const uint8_t *)ptr;
+ return (b[1] << 8) + b[0];
+}
+uint32_t READ_LE_UINT32(const void *ptr) {
+ const uint8_t *b = (const uint8_t *)ptr;
+ return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
+}
+
+class Lab {
+ std::string _filename;
+ uint8_t g_type;
+ uint32_t i;
+ uint32_t offset;
+ uint32_t bufSize;
+ lab_header head;
+ lab_entry *entries;
+ char *buf;
+ char *str_table;
+ FILE *infile;
+ void Load(std::string filename);
+public:
+ Lab(std::string filename) : _filename(filename) {
+ // allocate a 1mb buffer to start with
+ bufSize = 1024*1024;
+ buf = (char *)malloc(bufSize);
+ Load(filename);
+ }
+ ~Lab() {
+ free(buf);
+ delete[] str_table;
+ delete[] entries;
+ }
+
+ std::istream *getFile(std::string filename);
+};
+
+std::istream *getFile(std::string filename, Lab* lab);
+
+#endif
diff --git a/tools/emi/model.h b/tools/emi/model.h
new file mode 100644
index 000000000..6e54f9349
--- /dev/null
+++ b/tools/emi/model.h
@@ -0,0 +1,91 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
+#ifndef MODEL_H
+#define MODEL_H
+
+#include <string>
+#include <stdint.h>
+
+struct Colormap {
+ unsigned char r, g, b, a;
+};
+
+class Mesh;
+class Lab;
+
+class Material {
+ uint32_t *_texIDs;
+ uint32_t _numTextures;
+ Lab *_lab;
+ void loadTGATexture(std::string filename);
+ void loadSURTexture(std::string filename);
+public:
+ Material() { _lab = 0; }
+ void setLab(Lab *lab) { _lab = lab; }
+ void loadTexture(std::string filename);
+ void bindTexture(int index = 0);
+};
+
+class MeshFace {
+ Vector3<int> *_indexes;
+ uint32_t _faceLength;
+ uint32_t _numFaces;
+ uint32_t _hasTexture;
+ uint32_t _texID;
+ uint32_t _flags;
+ Mesh *_parent;
+public:
+ MeshFace() : _numFaces(0), _hasTexture(0), _texID(0), _flags(0) { }
+ void loadFace(std::istream *file);
+ void setParent(Mesh *m) { _parent = m; }
+ void render();
+};
+
+class Mesh {
+ int _numVertices;
+ Vector3d *_vertices;
+ Vector3d *_normals;
+ Colormap *_colorMap;
+ Vector2d *_texVerts;
+
+ // Stuff I dont know how to use:
+ Vector4d *_sphereData;
+ Vector3d *_boxData;
+ Vector3d *_boxData2;
+ int _numTexSets;
+ int _setType;
+
+ uint32_t _numFaces;
+ MeshFace *_faces;
+ uint32_t _numTextures;
+ std::string *_texNames;
+ Material *_mats;
+ Lab *_lab;
+public:
+ Mesh() { _lab = 0; }
+ void setLab(Lab *lab) { _lab = lab; }
+ void setTex(int index) { _mats[index].bindTexture(); }
+ void loadMesh(std::string fileName);
+ void prepare();
+ void render();
+};
+
+#endif
diff --git a/tools/emi/renderModel.cpp b/tools/emi/renderModel.cpp
new file mode 100644
index 000000000..23085db2b
--- /dev/null
+++ b/tools/emi/renderModel.cpp
@@ -0,0 +1,408 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <cassert>
+#include <cstdio>
+#include <ctime>
+#include <cstring> // for lab
+#include <cstdlib>
+#include <GL/glfw.h>
+#include "filetools.h"
+#include "model.h"
+#include "lab.h"
+
+using namespace std;
+
+/*
+ * Model-viewer for EMI, usage:
+ * renderModel [labName] [mesh-name]
+ *
+ * If no labName is specified, then all files will be searched for
+ * in the current working directory.
+ *
+ * This is quite possibly not endian-safe yet, and requires GLFW for
+ * rendering. (And is thus not built by default)
+ */
+
+
+void Lab::Load(string filename) {
+ g_type = GT_EMI;
+
+ infile = fopen(filename.c_str(), "rb");
+ if (infile == 0) {
+ cout << "Can not open source file: " << filename << endl;
+ exit(1);
+ }
+
+ fread(&head.magic, 1, 4, infile);
+ fread(&head.magic2, 1, 4, infile);
+ uint32_t num, s_size, s_offset;
+ fread(&num, 1, 4, infile);
+ fread(&s_size, 1, 4, infile);
+ if(g_type == GT_EMI)
+ fread(&s_offset,1,4,infile);
+ head.num_entries = READ_LE_UINT32(&num);
+ head.string_table_size = READ_LE_UINT32(&s_size);
+ if (0 != memcmp(&head.magic, "LABN", 4)) {
+ cout << "There is no LABN header in source lab-file\n";
+ exit(1);
+ }
+
+ entries = new lab_entry[head.num_entries];
+ str_table = new char[head.string_table_size];
+ if (!str_table || !entries) {
+ cout << "Could not allocate memory\n";
+ exit(1);
+ }
+ // Grim-stuff
+ if(g_type == GT_GRIM) {
+ fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
+
+ fread(str_table, 1, head.string_table_size, infile);
+
+ } else if(g_type == GT_EMI) { // EMI-stuff
+ // EMI has a string-table-offset
+ head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
+ // Find the string-table
+ fseek(infile, head.string_table_offset, SEEK_SET);
+ // Read the entire string table into str-table
+ fread(str_table, 1, head.string_table_size, infile);
+ fseek(infile, 20, SEEK_SET);
+
+ // Decrypt the string table
+ uint32_t j;
+ for (j = 0; j < head.string_table_size; j++)
+ if (str_table[j] != 0)
+ str_table[j] ^= 0x96;
+ fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
+ }
+}
+
+std::istream* Lab::getFile(string filename) {
+ if (!buf) {
+ printf("Could not allocate memory\n");
+ exit(1);
+ }
+ for (i = 0; i < head.num_entries; i++) {
+ const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
+ string test = string(fname);
+ if (test != filename)
+ continue;
+ else
+ {
+ offset = READ_LE_UINT32(&entries[i].start);
+ uint32_t size = READ_LE_UINT32(&entries[i].size);
+ if (bufSize < size) {
+ bufSize = size;
+ char *newBuf = (char *)realloc(buf, bufSize);
+ if (!newBuf) {
+ printf("Could not reallocate memory\n");
+ exit(1);
+ } else {
+ buf = newBuf;
+ }
+ }
+ std::fstream *_stream;
+ _stream = new std::fstream(_filename.c_str(), std::ios::in | std::ios::binary);
+ _stream->seekg(offset, ios::beg);
+ return _stream;
+ }
+ }
+ cout << "Lookup for " << filename << " failed " << endl;
+ return 0;
+}
+
+istream *getFile(string filename, Lab* lab) {
+ istream *_stream;
+ if (lab) {
+ return lab->getFile(filename);
+ } else {
+ _stream = new std::fstream(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!((std::fstream*)_stream)->is_open()) {
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+ return _stream;
+ }
+}
+
+void Material::bindTexture(int index) {
+ glBindTexture(GL_TEXTURE_2D, _texIDs[index]);
+ glEnable(GL_TEXTURE_2D);
+}
+
+void Material::loadTexture(string filename) {
+ string s = filename.substr(filename.length()-3);
+ if (s == "sur")
+ loadSURTexture(filename);
+ else
+ loadTGATexture(filename);
+}
+
+void Material::loadSURTexture(string filename) {
+ istream *file = getFile(filename, _lab);
+
+ _texIDs = new uint[1]; // TODO: Handle the rest of the sur-items.
+
+ string data;
+ getline(*file, data);
+ getline(*file, data);
+ getline(*file, data);
+ *file >> data;
+ cout << "Only reading first surface-TGA for " << filename << endl;
+ *file >> data;
+
+ string test = data;//.substr(5);
+ test[3] = '\\';
+ delete file;
+ loadTGATexture(test);
+}
+
+// TODO: This needs a bit more specific handling for indexes
+void Material::loadTGATexture(string filename) {
+ std::istream *file = getFile(filename, _lab);
+
+ if (!((fstream*)file)->is_open()) {
+ std::cout << "Unable to open file " << filename << std::endl;
+ return;
+ }
+
+ _texIDs = new uint[1];
+ glGenTextures(1, _texIDs);
+
+ file->seekg(2, std::ios::cur);
+ char type = readByte(*file);
+ assert(type == 2);
+
+
+ int width, height = 0;
+ int bpp;
+ file->seekg(9, std::ios::cur);
+
+ width = readShort(*file);
+ height = readShort(*file);
+ bpp = readByte(*file);
+ file->seekg(1, std::ios::cur);
+ if(bpp!=24)
+ cout << bpp <<" BPP " << endl;
+ int len = width * height * bpp/8;
+ char *newData = new char[len];
+ char *target = newData + len - width * bpp/8;
+ for (int i = 0; i < height; i++) {
+ file->read(target, width*(bpp/8));
+ target -= width * (bpp/8);
+ }
+ glBindTexture(GL_TEXTURE_2D, _texIDs[0]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, newData);
+ delete newData;
+}
+
+void Mesh::loadMesh(string filename) {
+ std::istream *file = getFile(filename, _lab);
+
+ int strLength = 0;
+
+ std::string nameString = readString(*file);
+
+ _sphereData = readVector4d(*file);
+ std::cout << "# Spheredata: " << _sphereData->toString() << std::endl;
+ _boxData = readVector3d(*file);
+ _boxData2 = readVector3d(*file);
+ std::cout << "# Boxdata: " << _boxData->toString()
+ << _boxData2->toString() << std::endl;
+
+ _numTexSets = readInt(*file);
+ _setType = readInt(*file);
+ std::cout << "# NumTexSets: " << _numTexSets << " setType: " << _setType << std::endl;
+ _numTextures = readInt(*file);
+
+ _texNames = new string[_numTextures];
+
+ for(int i = 0;i < _numTextures; i++) {
+ _texNames[i] = readString(*file);
+ // Every texname seems to be followed by 4 0-bytes (Ref mk1.mesh,
+ // this is intentional)
+ file->seekg(4, std::ios::cur);
+ }
+
+ // 4 unknown bytes - usually with value 19
+ file->seekg(4, std::ios::cur);
+
+ _numVertices = readInt(*file);
+ std::cout << "#File has " << _numVertices << " Vertices" << std::endl;
+
+ float x = 0, y = 0;
+ int r = 0, g = 0, b = 0, a = 0;
+ // Vertices
+ _vertices = readVector3d(*file, _numVertices);
+ _normals = readVector3d(*file, _numVertices);
+ _colorMap = new Colormap[_numVertices];
+ for (int i = 0; i < _numVertices; ++i) {
+ _colorMap[i].r = readByte(*file) ;
+ _colorMap[i].g = readByte(*file) ;
+ _colorMap[i].b = readByte(*file) ;
+ _colorMap[i].a = readByte(*file) ;
+ }
+ _texVerts = readVector2d(*file, _numVertices);
+
+ // Faces
+
+ file->read((char *) &_numFaces, 4);
+ _faces = new MeshFace[_numFaces];
+ int faceLength = 0;
+ for(int j = 0;j < _numFaces; j++) {
+ _faces[j].setParent(this);
+ _faces[j].loadFace(file);
+ }
+
+ int hasBones = 0;
+ file->read((char*)&hasBones, 4);
+/* Add bones later when everything else works.
+ if (hasBones == 1) {
+ int numBones = readInt(file);
+ char **boneNames = new char*[numBones];
+ for(int i = 0;i < numBones; i++) {
+ file.read((char*)&strLength, 4);
+ boneNames[i] = new char[strLength];
+ file.read(boneNames[i], strLength);
+ std::cout << "# BoneName " << boneNames[i] << std::endl;
+ }
+
+ int numBoneData = readInt(file);
+ int unknownVal = 0;
+ int boneDatanum;
+ float boneDataWgt;
+ int vertex = 0;
+ for(int i = 0;i < numBoneData; i++) {
+ unknownVal = readInt(file);
+ boneDatanum = readInt(file);
+ boneDataWgt = readFloat(file);
+ if(unknownVal)
+ vertex++;
+ std::cout << "# BoneData: Vertex: " << vertex << " boneNum: "
+ << boneDatanum << " weight: " << boneDataWgt << std::endl;
+ }
+ }*/
+ delete file;
+}
+
+void Mesh::prepare() {
+ _mats = new Material[_numTextures];
+ for (int i = 0; i < _numTextures; i++) {
+ _mats[i].setLab(_lab);
+ _mats[i].loadTexture(_texNames[i]);
+ }
+}
+
+void MeshFace::render() {
+ if(_hasTexture) {
+ _parent->setTex(_texID);
+ }
+ glDrawElements(GL_TRIANGLES, _faceLength * 3, GL_UNSIGNED_INT, _indexes);
+}
+
+void Mesh::render() {
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ glVertexPointer(3, GL_FLOAT, 0, _vertices);
+ glTexCoordPointer(2, GL_FLOAT, 0, _texVerts);
+ glNormalPointer(GL_FLOAT, 0, _normals);
+ glColorPointer(4, GL_UNSIGNED_BYTE, 0, _colorMap);
+
+ for(int i = 0; i < _numFaces; i++) {
+ _faces[i].render();
+ }
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_NORMAL_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+}
+
+void MeshFace::loadFace(std::istream *file) {
+ _flags = readInt(*file);
+ _hasTexture = readInt(*file);
+ if(_hasTexture > 1) {
+ cout << "We have this many textures: " << _hasTexture << endl;
+ }
+ if(_hasTexture)
+ _texID = readInt(*file);
+ _faceLength = readInt(*file);
+ short x = 0, y = 0, z = 0;
+ _indexes = new Vector3<int>[_faceLength];
+
+ for (int i = 0; i < _faceLength; i += 3) {
+ file->read((char *)&x, 2);
+ file->read((char *)&y, 2);
+ file->read((char *)&z, 2);
+ _indexes[i].setVal(x,y,z);
+ }
+}
+
+void renderInit() {
+ glClearColor(0.2f,0.2f,0.2f,0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+}
+
+Mesh m;
+
+void renderLoop() {
+ float rot = 0.5f;
+ while(true) {
+ renderInit();
+ glTranslatef(0.0,-0.9f, 0.0f);
+ glRotatef(rot,0.0f,0.1f,0.0f);
+ rot+=0.1f;
+ m.render();
+ glFlush();
+ glfwSwapBuffers();
+ usleep(5000);
+ }
+}
+
+int main(int argc, char **argv) {
+ if (argc > 2) {
+ cout << "Using LAB!" << endl;
+ Lab *lab = new Lab(string(argv[1]));
+ m.setLab(lab);
+ m.loadMesh(argv[2]);
+ } else {
+ m.loadMesh(argv[1]);
+ }
+ glfwInit();
+ glfwOpenWindow(1024, 768, 8, 8, 8, 8, 8, 8, GLFW_WINDOW);
+ m.prepare();
+ glEnable(GL_DEPTH_TEST);
+ renderLoop();
+
+ return 0;
+}
Commit: 432505aa6515fa5e3b2c31164ce4d18f1028a50f
https://github.com/scummvm/scummvm-tools/commit/432505aa6515fa5e3b2c31164ce4d18f1028a50f
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-23T01:46:02+02:00
Commit Message:
ANIMB: Add a bit more
Changed paths:
tools/emi/animb2txt.cpp
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 461b90724..4a2fde2fd 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -46,21 +46,31 @@ int main(int argc, char **argv) {
std::cout << "animName: " << animName << " duration: " << duration << " bones: " << bones << std::endl;
float time = 0.0f;
Vector3d *vec3d;
+ Vector4d *vec4d;
for (int i = 0; i < bones; i++) {
std::string boneName = readString(file);
int operation = readInt(file);
int unknown1 = readInt(file);
int unknown2 = readInt(file);
int numKeyframes = readInt(file);
+ std::cout << "Bone: " << boneName << " Operation: " << operation << " Unknown1: " << unknown1 <<
+ " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
+
if (operation == 3) { // Translation
- vec3d = readVector3d(file);
+ for(int i = 0; i < numKeyframes; i++) {
+ time = readFloat(file);
+ vec3d = readVector3d(file);
+ std::cout << "Time : " << time << " Vector: " << vec3d->toString() << std::endl;
+ delete vec3d;
+ }
} else if (operation == 4) { // Rotation
-
- }
- if (operation == 3 || operation == 4) {
- time = readFloat(file);
+ for(int i = 0; i < numKeyframes; i++) {
+ time = readFloat(file);
+ vec4d = readVector4d(file);
+ std::cout << "Time : " << time << " Vector: " << vec4d->toString() << std::endl;
+ delete vec4d;
+ }
}
- std::cout << "Bone: " << i << " Operation: " << operation << " Unknown1: " << unknown1 <<
- " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
+
}
}
Commit: ac1e31b18561437e70e6a41ebaee7267d856a485
https://github.com/scummvm/scummvm-tools/commit/ac1e31b18561437e70e6a41ebaee7267d856a485
Author: Einar Johan T. Sømåen (einarjohants at gmail.com)
Date: 2011-08-24T03:07:26+02:00
Commit Message:
EMI: Add Skeleton/Animation loading to renderModel
Changed paths:
tools/emi/filetools.h
tools/emi/model.h
tools/emi/renderModel.cpp
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index c70c9c9db..b3ad3d481 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -71,18 +71,6 @@ struct Vector4d {
}
};
-std::string readString(std::istream& file) {
- int strLength = 0;
- file.read((char*)&strLength, 4);
- char* readString = new char[strLength];
- file.read(readString, strLength);
-
- std::string retVal(readString);
- delete readString;
-
- return retVal;
-}
-
float readFloat(std::istream& file) {
float retVal = 0.0f;
file.read((char*)&retVal, 4);
@@ -107,7 +95,27 @@ int readByte(std::istream& file) {
return retVal;
}
-Vector2d *readVector2d(std::istream& file, int count=1) {
+std::string readString(std::istream& file) {
+ int strLength = 0;
+ file.read((char*)&strLength, 4);
+ char* readString = new char[strLength];
+ file.read(readString, strLength);
+
+ std::string retVal(readString);
+ delete readString;
+
+ return retVal;
+}
+
+std::string readCString(std::istream &file, int len) {
+ char *str = new char[len];
+ file.read(str, len);
+ std::string retVal = std::string(str);
+ delete[] str;
+ return retVal;
+}
+
+Vector2d *readVector2d(std::istream& file, int count = 1) {
Vector2d *vec2d = new Vector2d[count];
for (int i = 0; i < count; i++) {
vec2d[i].x = readFloat(file);
@@ -116,7 +124,7 @@ Vector2d *readVector2d(std::istream& file, int count=1) {
return vec2d;
}
-Vector3d *readVector3d(std::istream& file, int count=1) {
+Vector3d *readVector3d(std::istream& file, int count = 1) {
Vector3d *vec3d = new Vector3d[count];
for (int i = 0; i < count; i++) {
vec3d[i].x = readFloat(file);
diff --git a/tools/emi/model.h b/tools/emi/model.h
index 6e54f9349..c8f965189 100644
--- a/tools/emi/model.h
+++ b/tools/emi/model.h
@@ -23,6 +23,8 @@
#include <string>
#include <stdint.h>
+#include <map>
+#include <vector>
struct Colormap {
unsigned char r, g, b, a;
@@ -59,6 +61,61 @@ public:
void render();
};
+class Keyframe {
+public:
+ float _time;
+ Vector3d *_vec3d;
+ Vector4d *_vec4d;
+};
+
+class KeyframeList {
+public:
+ Keyframe *_frames;
+ int _numFrames;
+ float _time;
+ int _operation;
+ KeyframeList(int num, int op) : _numFrames(num), _operation(op) {
+ _frames = new Keyframe[_numFrames];
+ }
+};
+
+class Bone {
+ std::string _name;
+ Bone *_parent;
+ Bone *_child;
+ Bone *_sibling;
+ Vector3d *_pos;
+ Vector3d *_rot;
+ float _angle;
+ std::vector<int> _verts;
+ std::vector<float> _wgts;
+ KeyframeList *_keyframes;
+public:
+ Bone() : _parent(0), _child(0), _sibling(0), _angle(0.0f), _keyframes(0) {}
+ void addParent(Bone *node);
+ void addChild(Bone *node);
+ void addSibling(Bone *node);
+ bool hasSibling(Bone *node);
+ bool hasChild(Bone *node);
+ void setName(std::string name) { _name = name; }
+ void setPos(Vector3d *pos) { _pos = pos; }
+ void setRot(Vector3d *rot) { _rot = rot; }
+ void setAngle(float angle) { _angle = angle; }
+ void addVertex(int num, float wgt);
+ void setKeyFrames(KeyframeList* keyframes) { _keyframes = keyframes; }
+
+ std::string getName() { return _name; }
+};
+
+class Animation {
+public:
+ std::string _name;
+ float _timelen;
+ int _numBones;
+ int _numKeyFrames;
+ std::vector<Bone*> _bones;
+};
+
class Mesh {
int _numVertices;
Vector3d *_vertices;
@@ -66,6 +123,20 @@ class Mesh {
Colormap *_colorMap;
Vector2d *_texVerts;
+ uint32_t _numFaces;
+ MeshFace *_faces;
+ uint32_t _numTextures;
+ std::string *_texNames;
+ Material *_mats;
+
+ Bone *_bones;
+ int _numBones;
+ std::map<std::string, Bone*> _boneMap;
+
+ Animation *_anim;
+
+ Lab *_lab;
+
// Stuff I dont know how to use:
Vector4d *_sphereData;
Vector3d *_boxData;
@@ -73,17 +144,13 @@ class Mesh {
int _numTexSets;
int _setType;
- uint32_t _numFaces;
- MeshFace *_faces;
- uint32_t _numTextures;
- std::string *_texNames;
- Material *_mats;
- Lab *_lab;
public:
Mesh() { _lab = 0; }
void setLab(Lab *lab) { _lab = lab; }
void setTex(int index) { _mats[index].bindTexture(); }
void loadMesh(std::string fileName);
+ void loadSkeleton(std::string filename);
+ void loadAnimation(std::string filename);
void prepare();
void render();
};
diff --git a/tools/emi/renderModel.cpp b/tools/emi/renderModel.cpp
index 23085db2b..f5bb3bda8 100644
--- a/tools/emi/renderModel.cpp
+++ b/tools/emi/renderModel.cpp
@@ -35,10 +35,10 @@ using namespace std;
/*
* Model-viewer for EMI, usage:
- * renderModel [labName] [mesh-name]
+ * renderModel [labName] [mesh-name] [skel-name]
*
* If no labName is specified, then all files will be searched for
- * in the current working directory.
+ * in the current working directory. (and no skeleton will be loaded)
*
* This is quite possibly not endian-safe yet, and requires GLFW for
* rendering. (And is thus not built by default)
@@ -147,6 +147,51 @@ istream *getFile(string filename, Lab* lab) {
}
}
+bool Bone::hasChild(Bone *node) {
+ if (!_child)
+ return false;
+ if (_child == node)
+ return true;
+ else
+ return _child->hasSibling(node);
+}
+
+bool Bone::hasSibling(Bone *node) {
+ if (!_sibling)
+ return false;
+ if (_sibling == node)
+ return true;
+ else
+ return _sibling->hasSibling(node);
+}
+
+void Bone::addChild(Bone *node) {
+ if (!_child) {
+ _child = node;
+ _child->addParent(this);
+ } else {
+ _child->addSibling(node);
+ }
+}
+
+void Bone::addSibling(Bone *node) {
+ if (!_sibling) {
+ _sibling = node;
+ _sibling->addParent(this);
+ } else {
+ _sibling->addSibling(node);
+ }
+}
+
+void Bone::addParent(Bone *node) {
+ _parent = node;
+}
+
+void Bone::addVertex(int num, float wgt) {
+ _verts.push_back(num);
+ _verts.push_back(wgt);
+}
+
void Material::bindTexture(int index) {
glBindTexture(GL_TEXTURE_2D, _texIDs[index]);
glEnable(GL_TEXTURE_2D);
@@ -222,6 +267,34 @@ void Material::loadTGATexture(string filename) {
delete newData;
}
+void MeshFace::loadFace(std::istream *file) {
+ _flags = readInt(*file);
+ _hasTexture = readInt(*file);
+ if(_hasTexture > 1) {
+ cout << "We have this many textures: " << _hasTexture << endl;
+ }
+ if(_hasTexture)
+ _texID = readInt(*file);
+ _faceLength = readInt(*file);
+ short x = 0, y = 0, z = 0;
+ _indexes = new Vector3<int>[_faceLength];
+
+ for (int i = 0; i < _faceLength; i += 3) {
+ file->read((char *)&x, 2);
+ file->read((char *)&y, 2);
+ file->read((char *)&z, 2);
+ _indexes[i].setVal(x,y,z);
+ }
+}
+
+void MeshFace::render() {
+ if(_hasTexture) {
+ _parent->setTex(_texID);
+ }
+ glDrawElements(GL_TRIANGLES, _faceLength * 3, GL_UNSIGNED_INT, _indexes);
+}
+
+
void Mesh::loadMesh(string filename) {
std::istream *file = getFile(filename, _lab);
@@ -282,35 +355,124 @@ void Mesh::loadMesh(string filename) {
int hasBones = 0;
file->read((char*)&hasBones, 4);
-/* Add bones later when everything else works.
+
if (hasBones == 1) {
- int numBones = readInt(file);
- char **boneNames = new char*[numBones];
- for(int i = 0;i < numBones; i++) {
- file.read((char*)&strLength, 4);
- boneNames[i] = new char[strLength];
- file.read(boneNames[i], strLength);
- std::cout << "# BoneName " << boneNames[i] << std::endl;
+ _numBones = readInt(*file);
+ _bones = new Bone[_numBones];
+ for(int i = 0;i < _numBones; i++) {
+ _bones[i].setName(readString(*file));
+ _boneMap[_bones[i].getName()] = _bones + i;
}
- int numBoneData = readInt(file);
+ int numBoneData = readInt(*file);
int unknownVal = 0;
int boneDatanum;
float boneDataWgt;
int vertex = 0;
for(int i = 0;i < numBoneData; i++) {
- unknownVal = readInt(file);
- boneDatanum = readInt(file);
- boneDataWgt = readFloat(file);
+ unknownVal = readInt(*file);
+ boneDatanum = readInt(*file);
+ boneDataWgt = readFloat(*file);
if(unknownVal)
vertex++;
- std::cout << "# BoneData: Vertex: " << vertex << " boneNum: "
- << boneDatanum << " weight: " << boneDataWgt << std::endl;
+ _bones[boneDatanum].addVertex(vertex, boneDataWgt);
}
- }*/
+ }
delete file;
}
+void Mesh::loadSkeleton(std::string filename) {
+ std::istream *file = getFile(filename, _lab);
+
+ int numBones = readInt(*file);
+
+ string boneName;
+ string parentName;
+ Bone *bone;
+ Bone *parent;
+ float angle = 0.0f;
+ // Bones are listed in the same order as in the meshb.
+ Vector3d *vec = 0;
+ for(int i = 0;i < numBones; i++) {
+ boneName = readCString(*file,32);
+ parentName = readCString(*file,32);
+
+ bone = _boneMap[boneName];
+
+
+ /* for (int j = 0; j < _numBones; j++) {
+ if (_bones[j].getName() == boneName) {
+ bone = _bones + j;
+ break;
+ }
+ }*/
+ if (parentName != "no_parent") {
+ /* for (int j = 0; j < _numBones; j++) {
+ if (_bones[j].getName() == parentName) {
+ parent = _bones + j;
+ break;
+ }
+ }*/
+ parent = _boneMap[parentName];
+
+ assert(parent != 0);
+ assert(bone != 0);
+
+ if (!parent->hasChild(bone))
+ parent->addChild(bone);
+ }
+ bone->setPos(readVector3d(*file));
+ bone->setRot(readVector3d(*file));
+ bone->setAngle(readFloat(*file));
+ }
+}
+
+void Mesh::loadAnimation(std::string filename) {
+ std::istream *file = getFile(filename, _lab);
+
+ _anim = new Animation();
+ _anim->_name = readString(*file);
+
+
+ _anim->_timelen = readFloat(*file);
+ _anim->_numBones = readInt(*file);
+ std::cout << "animName: " << _anim->_name << " duration: " << _anim->_timelen << " bones: " << _anim->_numBones << std::endl;
+ float time = 0.0f;
+
+ KeyframeList *keyList;
+ Keyframe *key;
+ Bone *bone;
+
+ for (int i = 0; i < _anim->_numBones; i++) {
+ std::string boneName = readString(*file);
+ int operation = readInt(*file);
+ int unknown1 = readInt(*file);
+ int unknown2 = readInt(*file);
+ int numKeyframes = readInt(*file);
+
+ bone = _boneMap[boneName];
+ keyList = new KeyframeList(numKeyframes, operation);
+
+ std::cout << "Bone: " << boneName << " Operation: " << operation << " Unknown1: " << unknown1 <<
+ " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
+
+ if (operation == 3) { // Translation
+ for(int i = 0; i < numKeyframes; i++) {
+ key = keyList->_frames + i;
+ key->_time = readFloat(*file);
+ key->_vec3d = readVector3d(*file);
+ }
+ } else if (operation == 4) { // Rotation
+ for(int i = 0; i < numKeyframes; i++) {
+ key = keyList->_frames + i;
+ key->_time = readFloat(*file);
+ key->_vec4d = readVector4d(*file);
+ }
+ }
+
+ }
+}
+
void Mesh::prepare() {
_mats = new Material[_numTextures];
for (int i = 0; i < _numTextures; i++) {
@@ -319,13 +481,6 @@ void Mesh::prepare() {
}
}
-void MeshFace::render() {
- if(_hasTexture) {
- _parent->setTex(_texID);
- }
- glDrawElements(GL_TRIANGLES, _faceLength * 3, GL_UNSIGNED_INT, _indexes);
-}
-
void Mesh::render() {
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
@@ -347,26 +502,6 @@ void Mesh::render() {
glDisableClientState(GL_COLOR_ARRAY);
}
-void MeshFace::loadFace(std::istream *file) {
- _flags = readInt(*file);
- _hasTexture = readInt(*file);
- if(_hasTexture > 1) {
- cout << "We have this many textures: " << _hasTexture << endl;
- }
- if(_hasTexture)
- _texID = readInt(*file);
- _faceLength = readInt(*file);
- short x = 0, y = 0, z = 0;
- _indexes = new Vector3<int>[_faceLength];
-
- for (int i = 0; i < _faceLength; i += 3) {
- file->read((char *)&x, 2);
- file->read((char *)&y, 2);
- file->read((char *)&z, 2);
- _indexes[i].setVal(x,y,z);
- }
-}
-
void renderInit() {
glClearColor(0.2f,0.2f,0.2f,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -397,7 +532,12 @@ int main(int argc, char **argv) {
m.loadMesh(argv[2]);
} else {
m.loadMesh(argv[1]);
+ } if (argc > 3) {
+ m.loadSkeleton(argv[3]);
+ } if (argc > 4) {
+ m.loadAnimation(argv[4]);
}
+
glfwInit();
glfwOpenWindow(1024, 768, 8, 8, 8, 8, 8, 8, GLFW_WINDOW);
m.prepare();
Commit: 1dcb74fa2861e172ed8d546c04808e045b65fec4
https://github.com/scummvm/scummvm-tools/commit/1dcb74fa2861e172ed8d546c04808e045b65fec4
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-09-01T06:06:02+02:00
Commit Message:
EMI: Add cosb2cos
Changed paths:
A tools/emi/cosb2cos.cpp
tools/module.mk
diff --git a/tools/emi/cosb2cos.cpp b/tools/emi/cosb2cos.cpp
new file mode 100644
index 000000000..ac32c86ec
--- /dev/null
+++ b/tools/emi/cosb2cos.cpp
@@ -0,0 +1,181 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+* $URL:
+* $Id:
+*
+*/
+
+#include <fstream>
+#include <string>
+#include <iostream>
+#include <vector>
+#include "filetools.h"
+
+std::vector<std::string> g_tag;
+
+std::string getTag(std::string str) {
+ if (str.at(0) != '!')
+ std::cout << "Erroneous Tag\n";
+ std::string tag = str.substr(1,4);
+ return tag;
+}
+
+std::string getCompName(std::string str) {
+ return str.substr(5);
+}
+
+void pushtag(std::string tag) {
+ std::vector<std::string>::iterator it;
+ for (it = g_tag.begin(); it != g_tag.end(); it++) {
+ if (*it == tag)
+ return;
+ }
+ g_tag.push_back(tag);
+}
+
+struct TrackKey {
+ float _time;
+ float _value;
+
+ void readFromFile(std::istream &file) {
+ _time = readFloat(file);
+ _value = readFloat(file);
+ }
+};
+
+struct ChoreTrack {
+ std::string _tag;
+ std::string _trackName;
+ int _hash;
+ int _parentID;
+ int _numKeys;
+ TrackKey *_keys;
+
+ void readFromFile(std::istream &file) {
+ // Split this into tag & name later.
+ _trackName = readString(file);
+ _tag = getTag(_trackName);
+ _trackName = getCompName(_trackName);
+ _hash = readInt(file);
+ _parentID = readInt(file);
+ _numKeys = readInt(file);
+
+ pushtag(_tag);
+
+ _keys = new TrackKey[_numKeys];
+ for (int k = 0; k < _numKeys; k++) {
+ _keys[k].readFromFile(file);
+ }
+ }
+ void printComponent(int &count) {
+ std::cout << count << "\t" << _tag << "\t" << _hash << "\t" <<_parentID << "\t" << _trackName << std::endl;
+ }
+};
+
+struct Chore {
+ std::string _choreName;
+ float _length;
+ int _numTracks;
+ ChoreTrack *_tracks;
+
+ void readFromFile(std::istream &file) {
+ _choreName = readString(file);
+ _length = readFloat(file);
+ _numTracks = readInt(file);
+ _tracks = new ChoreTrack[_numTracks];
+
+ for (int j = 0; j < _numTracks; j++) {
+ _tracks[j].readFromFile(file);
+ }
+ }
+
+ void printComponents(int &count) {
+ for (int i = 0; i < _numTracks; i++) {
+ _tracks[i].printComponent(count);
+ count++;
+ }
+ }
+
+ void print(int count) {
+ std::cout << count << "\t" << _length << "\t" << _numTracks << "\t" << _choreName << std::endl;
+ }
+};
+
+struct Costume {
+ int _numChores;
+ Chore *_chores;
+
+ void readFromFile(std::istream &file) {
+ _numChores = readInt(file);
+
+ _chores = new Chore[_numChores];
+
+ for (int i = 0; i < _numChores; i++) {
+ _chores[i].readFromFile(file);
+ }
+
+ }
+
+ void print() {
+ std::cout << "section: tags\n";
+ std::cout << "\tnumtags " << g_tag.size() << std::endl;
+ int i = 0;
+ std::vector<std::string>::iterator it = g_tag.begin();
+ for(; it != g_tag.end(); it++) {
+ std::cout << i++ << "\t" << *it << std::endl;
+ }
+ std::cout << std::endl;
+ std::cout << "section: components\n";
+ std::cout << "\tnumcomponents: x\n";
+
+ int count = 0;
+ for (int i = 0; i < _numChores; i++) {
+ _chores[i].printComponents(count);
+ }
+ std::cout << std::endl;
+ std::cout << "section: chores\n";
+ std::cout << "\tnumchores: x\n";
+ count = 0;
+ for (int i = 0; i < _numChores; i++) {
+ _chores[i].print(count);
+ count++;
+ }
+ std::cout << std::endl;
+ std::cout << "section: keys\n";
+ std::cout << "\tnumkeys: x\n";
+ // TODO
+ }
+};
+
+int main(int argc, char **argv) {
+ if(argc < 2){
+ std::cout << "Error: filename not specified" << std::endl;
+ return 0;
+ }
+ std::string filename = argv[1];
+
+ std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!file.is_open()) {
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+
+ Costume c;
+ c.readFromFile(file);
+ c.print();
+
+}
diff --git a/tools/module.mk b/tools/module.mk
index c24acb8e4..30a97b2bc 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -14,6 +14,7 @@ TOOLS := \
tools/delua$(EXEEXT) \
tools/imc2wav$(EXEEXT) \
tools/int2flt$(EXEEXT) \
+ tools/cosb2cos$(EXEEXT) \
tools/meshb2obj$(EXEEXT) \
tools/sklb2txt$(EXEEXT) \
tools/animb2txt$(EXEEXT) \
@@ -66,6 +67,11 @@ tools/int2flt$(EXEEXT): $(srcdir)/tools/int2flt.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
+tools/cosb2cos$(EXEEXT): $(srcdir)/tools/emi/cosb2cos.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common -o $@ $<
+
tools/meshb2obj$(EXEEXT): $(srcdir)/tools/emi/meshb2obj.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
Commit: 8e1dd319db1b9db5200a0b8935b55c09c92246d7
https://github.com/scummvm/scummvm-tools/commit/8e1dd319db1b9db5200a0b8935b55c09c92246d7
Author: Einar Johan Trøan Sømåen (somaen at PowerYoda-2.local)
Date: 2011-09-04T03:30:33+02:00
Commit Message:
Made Filetools endian-safe
Changed paths:
tools/emi/filetools.h
tools/emi/lab.h
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index b3ad3d481..3f4990873 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -1,4 +1,3 @@
-#ifndef FILETOOLS_H
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
@@ -19,12 +18,13 @@
*
*/
-
+#ifndef FILETOOLS_H
#define FILETOOLS_H
#include <fstream>
#include <string>
#include <sstream>
+#include "common/endian.h"
template<typename T>
struct Vector3 {
@@ -74,19 +74,20 @@ struct Vector4d {
float readFloat(std::istream& file) {
float retVal = 0.0f;
file.read((char*)&retVal, 4);
+ retVal = get_float((char *) &retVal);
return retVal;
}
int readInt(std::istream& file) {
int retVal = 0;
file.read((char*)&retVal, 4);
- return retVal;
+ return FROM_LE_32(retVal);
}
short readShort(std::istream& file) {
short retVal = 0;
file.read((char*)&retVal, 2);
- return retVal;
+ return FROM_LE_16(retVal);
}
int readByte(std::istream& file) {
@@ -96,8 +97,7 @@ int readByte(std::istream& file) {
}
std::string readString(std::istream& file) {
- int strLength = 0;
- file.read((char*)&strLength, 4);
+ int strLength = readInt(file);
char* readString = new char[strLength];
file.read(readString, strLength);
diff --git a/tools/emi/lab.h b/tools/emi/lab.h
index 028cbbb2d..8ad1e2043 100644
--- a/tools/emi/lab.h
+++ b/tools/emi/lab.h
@@ -42,15 +42,6 @@ struct lab_entry {
uint32_t reserved;
};
-uint16_t READ_LE_UINT16(const void *ptr) {
- const uint8_t *b = (const uint8_t *)ptr;
- return (b[1] << 8) + b[0];
-}
-uint32_t READ_LE_UINT32(const void *ptr) {
- const uint8_t *b = (const uint8_t *)ptr;
- return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
-}
-
class Lab {
std::string _filename;
uint8_t g_type;
Commit: ddefca720c40dc086298ca02aa05160282511999
https://github.com/scummvm/scummvm-tools/commit/ddefca720c40dc086298ca02aa05160282511999
Author: Einar Johan Trøan Sømåen (somaen at PowerYoda-2.local)
Date: 2011-09-04T03:32:02+02:00
Commit Message:
Separated Lab-class from renderModel
Changed paths:
A tools/emi/lab.cpp
tools/emi/renderModel.cpp
diff --git a/tools/emi/lab.cpp b/tools/emi/lab.cpp
new file mode 100644
index 000000000..e59c44d14
--- /dev/null
+++ b/tools/emi/lab.cpp
@@ -0,0 +1,140 @@
+/* Residual - A 3D game interpreter
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+
+ * 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
+ *
+ * $URL:
+ * $Id:
+ *
+ */
+
+#include <cstring>
+#include <cstdlib>
+#include <cstdio>
+#include <cassert>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include "lab.h"
+
+// TODO: Use common/endian for this
+uint16_t READ_LE_UINT16(const void *ptr) {
+ const uint8_t *b = (const uint8_t *)ptr;
+ return (b[1] << 8) + b[0];
+}
+
+uint32_t READ_LE_UINT32(const void *ptr) {
+ const uint8_t *b = (const uint8_t *)ptr;
+ return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
+}
+
+void Lab::Load(std::string filename) {
+ g_type = GT_EMI; // FIXME, detect game-type properly.
+
+ infile = fopen(filename.c_str(), "rb");
+ if (infile == 0) {
+ std::cout << "Can not open source file: " << filename << std::endl;
+ exit(1);
+ }
+
+ fread(&head.magic, 1, 4, infile);
+ fread(&head.magic2, 1, 4, infile);
+ uint32_t num, s_size, s_offset;
+ fread(&num, 1, 4, infile);
+ fread(&s_size, 1, 4, infile);
+ if(g_type == GT_EMI)
+ fread(&s_offset,1,4,infile);
+ head.num_entries = READ_LE_UINT32(&num);
+ head.string_table_size = READ_LE_UINT32(&s_size);
+ if (0 != memcmp(&head.magic, "LABN", 4)) {
+ std::cout << "There is no LABN header in source lab-file\n";
+ exit(1);
+ }
+
+ entries = new lab_entry[head.num_entries];
+ str_table = new char[head.string_table_size];
+ if (!str_table || !entries) {
+ std::cout << "Could not allocate memory\n";
+ exit(1);
+ }
+ // Grim-stuff
+ if(g_type == GT_GRIM) {
+ fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
+
+ fread(str_table, 1, head.string_table_size, infile);
+
+ } else if(g_type == GT_EMI) { // EMI-stuff
+ // EMI has a string-table-offset
+ head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
+ // Find the string-table
+ fseek(infile, head.string_table_offset, SEEK_SET);
+ // Read the entire string table into str-table
+ fread(str_table, 1, head.string_table_size, infile);
+ fseek(infile, 20, SEEK_SET);
+
+ // Decrypt the string table
+ uint32_t j;
+ for (j = 0; j < head.string_table_size; j++)
+ if (str_table[j] != 0)
+ str_table[j] ^= 0x96;
+ fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
+ }
+}
+
+std::istream* Lab::getFile(std::string filename) {
+ if (!buf) {
+ printf("Could not allocate memory\n");
+ exit(1);
+ }
+ for (i = 0; i < head.num_entries; i++) {
+ const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
+ std::string test = std::string(fname);
+ if (test != filename)
+ continue;
+ else
+ {
+ offset = READ_LE_UINT32(&entries[i].start);
+ uint32_t size = READ_LE_UINT32(&entries[i].size);
+ if (bufSize < size) {
+ bufSize = size;
+ char *newBuf = (char *)realloc(buf, bufSize);
+ if (!newBuf) {
+ printf("Could not reallocate memory\n");
+ exit(1);
+ } else {
+ buf = newBuf;
+ }
+ }
+ std::fstream *stream;
+ stream = new std::fstream(_filename.c_str(), std::ios::in | std::ios::binary);
+ stream->seekg(offset, std::ios::beg);
+ return stream;
+ }
+ }
+ return NULL;
+}
+
+std::istream *getFile(std::string filename, Lab* lab) {
+ std::istream *stream;
+ if (lab) {
+ return lab->getFile(filename);
+ } else {
+ stream = new std::fstream(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!((std::fstream*)stream)->is_open()) {
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+ return stream;
+ }
+}
\ No newline at end of file
diff --git a/tools/emi/renderModel.cpp b/tools/emi/renderModel.cpp
index f5bb3bda8..918a820f5 100644
--- a/tools/emi/renderModel.cpp
+++ b/tools/emi/renderModel.cpp
@@ -44,109 +44,6 @@ using namespace std;
* rendering. (And is thus not built by default)
*/
-
-void Lab::Load(string filename) {
- g_type = GT_EMI;
-
- infile = fopen(filename.c_str(), "rb");
- if (infile == 0) {
- cout << "Can not open source file: " << filename << endl;
- exit(1);
- }
-
- fread(&head.magic, 1, 4, infile);
- fread(&head.magic2, 1, 4, infile);
- uint32_t num, s_size, s_offset;
- fread(&num, 1, 4, infile);
- fread(&s_size, 1, 4, infile);
- if(g_type == GT_EMI)
- fread(&s_offset,1,4,infile);
- head.num_entries = READ_LE_UINT32(&num);
- head.string_table_size = READ_LE_UINT32(&s_size);
- if (0 != memcmp(&head.magic, "LABN", 4)) {
- cout << "There is no LABN header in source lab-file\n";
- exit(1);
- }
-
- entries = new lab_entry[head.num_entries];
- str_table = new char[head.string_table_size];
- if (!str_table || !entries) {
- cout << "Could not allocate memory\n";
- exit(1);
- }
- // Grim-stuff
- if(g_type == GT_GRIM) {
- fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
-
- fread(str_table, 1, head.string_table_size, infile);
-
- } else if(g_type == GT_EMI) { // EMI-stuff
- // EMI has a string-table-offset
- head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
- // Find the string-table
- fseek(infile, head.string_table_offset, SEEK_SET);
- // Read the entire string table into str-table
- fread(str_table, 1, head.string_table_size, infile);
- fseek(infile, 20, SEEK_SET);
-
- // Decrypt the string table
- uint32_t j;
- for (j = 0; j < head.string_table_size; j++)
- if (str_table[j] != 0)
- str_table[j] ^= 0x96;
- fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
- }
-}
-
-std::istream* Lab::getFile(string filename) {
- if (!buf) {
- printf("Could not allocate memory\n");
- exit(1);
- }
- for (i = 0; i < head.num_entries; i++) {
- const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
- string test = string(fname);
- if (test != filename)
- continue;
- else
- {
- offset = READ_LE_UINT32(&entries[i].start);
- uint32_t size = READ_LE_UINT32(&entries[i].size);
- if (bufSize < size) {
- bufSize = size;
- char *newBuf = (char *)realloc(buf, bufSize);
- if (!newBuf) {
- printf("Could not reallocate memory\n");
- exit(1);
- } else {
- buf = newBuf;
- }
- }
- std::fstream *_stream;
- _stream = new std::fstream(_filename.c_str(), std::ios::in | std::ios::binary);
- _stream->seekg(offset, ios::beg);
- return _stream;
- }
- }
- cout << "Lookup for " << filename << " failed " << endl;
- return 0;
-}
-
-istream *getFile(string filename, Lab* lab) {
- istream *_stream;
- if (lab) {
- return lab->getFile(filename);
- } else {
- _stream = new std::fstream(filename.c_str(), std::ios::in | std::ios::binary);
-
- if (!((std::fstream*)_stream)->is_open()) {
- std::cout << "Unable to open file " << filename << std::endl;
- return 0;
- }
- return _stream;
- }
-}
-
bool Bone::hasChild(Bone *node) {
if (!_child)
return false;
Commit: 762d977fc718bdd6d77e6eb0e0b24154e55c0ebf
https://github.com/scummvm/scummvm-tools/commit/762d977fc718bdd6d77e6eb0e0b24154e55c0ebf
Author: Einar Johan Trøan Sømåen (somaen at PowerYoda-2.local)
Date: 2011-09-04T03:32:40+02:00
Commit Message:
MESHB: Added support for reading directly from LAB-files
Changed paths:
tools/emi/meshb2obj.cpp
tools/module.mk
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index a74e411b8..646cbea50 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -22,87 +22,97 @@
#include <string>
#include <iostream>
#include "filetools.h"
+#include "lab.h"
int main(int argc, char **argv) {
- if(argc < 2){
+ if (argc < 2) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
- std::string filename = argv[1];
- std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+ Lab *lab = NULL;
+ std::string filename;
- if (!file.is_open()) {
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab);
+
+ if (!file) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
int strLength = 0;
- std::string nameString = readString(file);
+ std::string nameString = readString(*file);
Vector4d *vec4d;
Vector3d *vec3d;
- vec4d = readVector4d(file);
+ vec4d = readVector4d(*file);
std::cout << "# Spheredata: " << vec4d->toString() << std::endl;
delete vec4d;
- vec3d = readVector3d(file);
+ vec3d = readVector3d(*file);
std::cout << "# Boxdata: " << vec3d->toString();
delete vec3d;
- vec3d = readVector3d(file);
+ vec3d = readVector3d(*file);
std::cout << vec3d->toString() << std::endl;
delete vec3d;
- int numTexSets = readInt(file);
- int setType = readInt(file);
+ int numTexSets = readInt(*file);
+ int setType = readInt(*file);
std::cout << "# NumTexSets: " << numTexSets << " setType: " << setType << std::endl;
- int numTextures = readInt(file);
+ int numTextures = readInt(*file);
std::string *texNames = new std::string[numTextures];
for(int i = 0;i < numTextures; i++) {
- texNames[i] = readString(file);
+ texNames[i] = readString(*file);
// Every texname seems to be followed by 4 0-bytes (Ref mk1.mesh,
// this is intentional)
- file.seekg(4, std::ios::cur);
+ readInt(*file);
}
for(int i = 0;i < numTextures;i++){
std::cout << "# TexName " << texNames[i] << std::endl;
}
// 4 unknown bytes - usually with value 19
- file.seekg(4, std::ios::cur);
+ readInt(*file);
// Should create an empty mtl
std::cout << "mtllib quit.mtl" << std::endl << "o Arrow" << std::endl;
- int numVertices = readInt(file);
+ int numVertices = readInt(*file);
std::cout << "#File has " << numVertices << " Vertices" << std::endl;
float x = 0, y = 0;
int r = 0, g = 0, b = 0, a = 0;
// Vertices
for (int i = 0; i < numVertices; ++i) {
- vec3d = readVector3d(file);
+ vec3d = readVector3d(*file);
std::cout << "v " << vec3d->x << " " << vec3d->y << " " << vec3d->z << std::endl;
delete vec3d;
}
// Vertex-normals
for (int i = 0; i < numVertices; ++i) {
- vec3d = readVector3d(file);
+ vec3d = readVector3d(*file);
std::cout << "vn " << vec3d->x << " " << vec3d->y << " " << vec3d->z << std::endl;
delete vec3d;
}
// Color map-data, dunno how to interpret them right now.
for (int i = 0; i < numVertices; ++i) {
- r = readByte(file);
- g = readByte(file);
- b = readByte(file);
- a = readByte(file);
+ r = readByte(*file);
+ g = readByte(*file);
+ b = readByte(*file);
+ a = readByte(*file);
std::cout << "# R: " << r << " G: " << g << " B: " << b << " A: " << a << std::endl;
}
// Texture-vertices
for (int i = 0; i < numVertices; ++i) {
- file.read((char *)&x, 4);
- file.read((char *)&y, 4);
+ x = readFloat(*file);
+ y = readFloat(*file);
std::cout << "vt " << x << " " << y << std::endl;
}
@@ -114,50 +124,46 @@ int main(int argc, char **argv) {
int hasTexture = 0;
int texID = 0;
int flags = 0;
- file.read((char *) &numFaces, 4);
+ numFaces = readInt(*file);
int faceLength = 0;
- for(int j = 0;j < numFaces; j++){
- flags = readInt(file);
- hasTexture = readInt(file);
+ for(int j = 0; j < numFaces; j++){
+ flags = readInt(*file);
+ hasTexture = readInt(*file);
if(hasTexture)
- texID = readInt(file);
- faceLength = readInt(file);
+ texID = readInt(*file);
+ faceLength = readInt(*file);
std::cout << "#Face-header: flags: " << flags << " hasTexture: " << hasTexture
<< " texId: " << texID << " faceLength: " << faceLength << std::endl;
short x = 0, y = 0, z = 0;
std::cout << "g " << j << std::endl;
for (int i = 0; i < faceLength; i += 3) {
- file.read((char *)&x, 2);
- file.read((char *)&y, 2);
- file.read((char *)&z, 2);
- ++x;
- ++y;
- ++z;
+ x = readShort(*file) + 1;
+ y = readShort(*file) + 1;
+ z = readShort(*file) + 1;
std::cout << "f " << x << "//" << x << " " << y << "//" << y << " " << z << "//" << z << std::endl;
}
}
- int hasBones = 0;
- file.read((char*)&hasBones, 4);
+ int hasBones = readInt(*file);
if (hasBones == 1) {
- int numBones = readInt(file);
+ int numBones = readInt(*file);
char **boneNames = new char*[numBones];
for(int i = 0;i < numBones; i++) {
- file.read((char*)&strLength, 4);
+ strLength = readInt(*file);
boneNames[i] = new char[strLength];
- file.read(boneNames[i], strLength);
+ file->read(boneNames[i], strLength);
std::cout << "# BoneName " << boneNames[i] << std::endl;
}
- int numBoneData = readInt(file);
+ int numBoneData = readInt(*file);
int unknownVal = 0;
int boneDatanum;
float boneDataWgt;
int vertex = 0;
for(int i = 0;i < numBoneData; i++) {
- unknownVal = readInt(file);
- boneDatanum = readInt(file);
- boneDataWgt = readFloat(file);
+ unknownVal = readInt(*file);
+ boneDatanum = readInt(*file);
+ boneDataWgt = readFloat(*file);
if(unknownVal)
vertex++;
std::cout << "# BoneData: Vertex: " << vertex << " boneNum: "
diff --git a/tools/module.mk b/tools/module.mk
index 30a97b2bc..e01ab9c39 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -39,6 +39,7 @@ tools: $(TOOLS)
clean-tools:
-$(RM) $(TOOLS)
+ -$(RM) tools/emi/*.o
-$(RM) tools/patchex/*.o
-$(RM) -r tools/patchex/.deps
@@ -72,10 +73,10 @@ tools/cosb2cos$(EXEEXT): $(srcdir)/tools/emi/cosb2cos.cpp
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common -o $@ $<
-tools/meshb2obj$(EXEEXT): $(srcdir)/tools/emi/meshb2obj.cpp
+tools/meshb2obj$(EXEEXT): $(srcdir)/tools/emi/meshb2obj.o $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $<
tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: de0411d517ece78e5b9c02bd5d421595fdae158d
https://github.com/scummvm/scummvm-tools/commit/de0411d517ece78e5b9c02bd5d421595fdae158d
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-09-05T17:30:37+02:00
Commit Message:
TIL2BMP: Add support for reading directly from LAB-files
Changed paths:
tools/emi/lab.cpp
tools/emi/lab.h
tools/emi/til2bmp.cpp
tools/module.mk
diff --git a/tools/emi/lab.cpp b/tools/emi/lab.cpp
index e59c44d14..4b1ac0099 100644
--- a/tools/emi/lab.cpp
+++ b/tools/emi/lab.cpp
@@ -91,11 +91,7 @@ void Lab::Load(std::string filename) {
}
}
-std::istream* Lab::getFile(std::string filename) {
- if (!buf) {
- printf("Could not allocate memory\n");
- exit(1);
- }
+int Lab::getIndex(std::string filename) {
for (i = 0; i < head.num_entries; i++) {
const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
std::string test = std::string(fname);
@@ -103,27 +99,49 @@ std::istream* Lab::getFile(std::string filename) {
continue;
else
{
- offset = READ_LE_UINT32(&entries[i].start);
- uint32_t size = READ_LE_UINT32(&entries[i].size);
- if (bufSize < size) {
- bufSize = size;
- char *newBuf = (char *)realloc(buf, bufSize);
- if (!newBuf) {
- printf("Could not reallocate memory\n");
- exit(1);
- } else {
- buf = newBuf;
- }
+ return i;
+ }
+ }
+ return -1;
+}
+
+std::istream* Lab::getFile(std::string filename) {
+ if (!buf) {
+ printf("Could not allocate memory\n");
+ exit(1);
+ }
+ int index = getIndex(filename);
+ if (index == -1) {
+ return NULL;
+ } else {
+ offset = READ_LE_UINT32(&entries[i].start);
+ uint32_t size = READ_LE_UINT32(&entries[i].size);
+ if (bufSize < size) {
+ bufSize = size;
+ char *newBuf = (char *)realloc(buf, bufSize);
+ if (!newBuf) {
+ printf("Could not reallocate memory\n");
+ exit(1);
+ } else {
+ buf = newBuf;
}
- std::fstream *stream;
- stream = new std::fstream(_filename.c_str(), std::ios::in | std::ios::binary);
- stream->seekg(offset, std::ios::beg);
- return stream;
}
+ std::fstream *stream;
+ stream = new std::fstream(_filename.c_str(), std::ios::in | std::ios::binary);
+ stream->seekg(offset, std::ios::beg);
+ return stream;
}
+
return NULL;
}
+int Lab::getLength(std::string filename) {
+ int index = getIndex(filename);
+ if (index == -1)
+ return 0;
+ return entries[i].size;
+}
+
std::istream *getFile(std::string filename, Lab* lab) {
std::istream *stream;
if (lab) {
@@ -137,4 +155,23 @@ std::istream *getFile(std::string filename, Lab* lab) {
}
return stream;
}
-}
\ No newline at end of file
+}
+
+std::istream *getFile(std::string filename, Lab* lab, int& length) {
+ std::istream *stream;
+ if (lab) {
+ length = lab->getLength(filename);
+ return lab->getFile(filename);
+ } else {
+ stream = new std::fstream(filename.c_str(), std::ios::in | std::ios::binary);
+
+ if (!((std::fstream*)stream)->is_open()) {
+ std::cout << "Unable to open file " << filename << std::endl;
+ return 0;
+ }
+ stream->seekg(0, std::ios::end);
+ length = (int)stream->tellg();
+ stream->seekg(0, std::ios::beg);
+ return stream;
+ }
+}
diff --git a/tools/emi/lab.h b/tools/emi/lab.h
index 8ad1e2043..5d4348945 100644
--- a/tools/emi/lab.h
+++ b/tools/emi/lab.h
@@ -68,8 +68,11 @@ public:
}
std::istream *getFile(std::string filename);
+ int getIndex(std::string filename);
+ int getLength(std::string filename);
};
std::istream *getFile(std::string filename, Lab* lab);
+std::istream *getFile(std::string filename, Lab* lab, int& length);
#endif
diff --git a/tools/emi/til2bmp.cpp b/tools/emi/til2bmp.cpp
index 19c14034c..f6c6dee08 100644
--- a/tools/emi/til2bmp.cpp
+++ b/tools/emi/til2bmp.cpp
@@ -29,6 +29,7 @@
#include <cstdio>
#include <cstring>
#include "common/endian.h"
+#include "lab.h"
/*
This tool converts EMI-TILEs into BMP-files, and supports both the format used in the Windows
@@ -336,30 +337,35 @@ Bytef *decompress(Bytef *in, int size, uint32_t &outsize){
int main(int argc, char **argv){
if (argc < 2) {
std::cout << "No Argument" << std::endl;
- std::cout << "Usage: til2bmp <filename> [PS2]" << std::endl;
+ std::cout << "Usage: til2bmp [labfilename] <filename>" << std::endl;
return 0;
}
- // Cheap fix to support PS2
- bool ps2=false;
- if(argc > 2)
- ps2 = true;
- std::fstream file(argv[1], std::fstream::in|std::fstream::binary);
- if (!file.is_open()) {
+ Lab *lab = NULL;
+ std::string filename;
+ int length = 0;
+
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab, length);
+
+ if (!file) {
std::cout << "Could not open file" << std::endl;
return 0;
}
- std::string outname = argv[1];
+ std::string outname = filename;
outname += ".bmp";
- file.seekg(0, std::ios::end);
- int end = (int)file.tellg();
- file.seekg(0, std::ios::beg);
- char *data = new char[end];
- file.read(data, end);
- file.close();
- ProcessFile(data, end, outname);
+ char *data = new char[length];
+ file->read(data, length);
+ delete file;
+ ProcessFile(data, length, outname);
delete[] data;
}
diff --git a/tools/module.mk b/tools/module.mk
index e01ab9c39..b3f1fb309 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -97,10 +97,10 @@ tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
-tools/til2bmp$(EXEEXT): $(srcdir)/tools/emi/til2bmp.cpp
+tools/til2bmp$(EXEEXT): $(srcdir)/tools/emi/til2bmp.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -lz -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -lz -o $@ $<
tools/unlab$(EXEEXT): $(srcdir)/tools/unlab.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: bbbb3f330e2348a5506d468e903ed318d117024c
https://github.com/scummvm/scummvm-tools/commit/bbbb3f330e2348a5506d468e903ed318d117024c
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-09-05T17:47:26+02:00
Commit Message:
SETB2SET: Add support for reading directly from LAB-files
Changed paths:
tools/emi/setb2set.cpp
tools/module.mk
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index 9f507549b..9db4e02d7 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -11,6 +11,7 @@
#include <fstream>
#include <vector>
#include <sstream>
+#include "lab.h"
using namespace std;
@@ -343,17 +344,28 @@ string Set::ToString()
int main(int argc, char** argv){
if (argc < 2)
return 0;
- char* buf;
- FILE* f;
-
- f = fopen(argv[1],"rb");
- fseek(f,0,SEEK_END);
- uint32 size = ftell(f);
- buf = new char[size];
- fseek(f,0,SEEK_SET);
-
- int result = fread(buf,1,size,f);
- assert(result==size);
+ Lab *lab = NULL;
+ std::string filename;
+ int length = 0;
+
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab, length);
+
+ if (!file) {
+ std::cout << "Could not open file" << std::endl;
+ return 0;
+ }
+
+ char *buf = new char[length];
+ file->read(buf, length);
+ delete file;
+
Data *data = new Data(buf);
Set* ourSet = new Set(data);
delete data;
diff --git a/tools/module.mk b/tools/module.mk
index b3f1fb309..bedad4538 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -83,10 +83,10 @@ tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common -o $@ $<
-tools/setb2set$(EXEEXT): $(srcdir)/tools/emi/setb2set.cpp
+tools/setb2set$(EXEEXT): $(srcdir)/tools/emi/setb2set.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $<
tools/sklb2txt$(EXEEXT): $(srcdir)/tools/emi/sklb2txt.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: 2ed3136db3bb114ca761b82047a8ff732fc8c390
https://github.com/scummvm/scummvm-tools/commit/2ed3136db3bb114ca761b82047a8ff732fc8c390
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-09-05T17:54:05+02:00
Commit Message:
SKLB2TXT: Add support for reading directly from LAB
Changed paths:
tools/emi/sklb2txt.cpp
tools/module.mk
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
index e167d8377..3fa95e156 100644
--- a/tools/emi/sklb2txt.cpp
+++ b/tools/emi/sklb2txt.cpp
@@ -2,24 +2,34 @@
#include <string>
#include <iostream>
#include "filetools.h"
+#include "lab.h"
// Based on Benjamin Haischs work on sklb-files.
using namespace std;
int main(int argc, char **argv) {
- if(argc<2){
+ if (argc < 2) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
- std::string filename=argv[1];
- std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+ Lab *lab = NULL;
+ std::string filename;
- if (!file.is_open()){
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab);
+
+ if (!file) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
- int numBones = readInt(file);
+ int numBones = readInt(*file);
char boneString[32];
char parentString[32];
@@ -28,27 +38,20 @@ int main(int argc, char **argv) {
// Bones are listed in the same order as in the meshb.
Vector3d *vec = 0;
for(int i=0;i<numBones;i++) {
- file.read((char*)&boneString,32);
- file.read((char*)&parentString,32);
+ file->read((char*)&boneString,32);
+ file->read((char*)&parentString,32);
std::cout << "# BoneName " << boneString << "\twith parent: " << parentString << "\t";
- //file.seekg(28,ios::cur);
std::cout << " position: ";
- vec = readVector3d(file);
+ vec = readVector3d(*file);
std::cout << vec->toString();
delete vec;
std::cout << " rotation: ";
- vec = readVector3d(file);
+ vec = readVector3d(*file);
std::cout << vec->toString();
delete vec;
- angle = readFloat(file);
+ angle = readFloat(*file);
std::cout << angle << std::endl;
}
- /*
- The last 28 bytes are, by looking at guy.sklb:
- INT(0) <-- This has another value for 1 entry in el1.sklb.
- INT(0) <-- except for the second entry, pelvis.
-
- */
}
diff --git a/tools/module.mk b/tools/module.mk
index bedad4538..f7dcdd798 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -88,10 +88,10 @@ tools/setb2set$(EXEEXT): $(srcdir)/tools/emi/setb2set.cpp $(srcdir)/tools/emi/la
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common tools/emi/lab.o -o $@ $<
-tools/sklb2txt$(EXEEXT): $(srcdir)/tools/emi/sklb2txt.cpp
+tools/sklb2txt$(EXEEXT): $(srcdir)/tools/emi/sklb2txt.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $<
tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: 7ce032d4f545cc1397f052ab29abdff73b245a8d
https://github.com/scummvm/scummvm-tools/commit/7ce032d4f545cc1397f052ab29abdff73b245a8d
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-09-05T17:58:12+02:00
Commit Message:
ANIMB2TXT: Add support for reading directly from LAB-files
Changed paths:
tools/emi/animb2txt.cpp
tools/module.mk
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 4a2fde2fd..cfefd6764 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -24,49 +24,59 @@
#include <string>
#include <iostream>
#include "filetools.h"
+#include "lab.h"
using namespace std;
int main(int argc, char **argv) {
- if(argc < 2){
+ if (argc < 2) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
- std::string filename = argv[1];
- std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
+ Lab *lab = NULL;
+ std::string filename;
- if (!file.is_open()) {
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab);
+
+ if (!file) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
- std::string animName = readString(file);
- float duration = readFloat(file);
- int bones = readInt(file);
+ std::string animName = readString(*file);
+ float duration = readFloat(*file);
+ int bones = readInt(*file);
std::cout << "animName: " << animName << " duration: " << duration << " bones: " << bones << std::endl;
float time = 0.0f;
Vector3d *vec3d;
Vector4d *vec4d;
for (int i = 0; i < bones; i++) {
- std::string boneName = readString(file);
- int operation = readInt(file);
- int unknown1 = readInt(file);
- int unknown2 = readInt(file);
- int numKeyframes = readInt(file);
+ std::string boneName = readString(*file);
+ int operation = readInt(*file);
+ int unknown1 = readInt(*file);
+ int unknown2 = readInt(*file);
+ int numKeyframes = readInt(*file);
std::cout << "Bone: " << boneName << " Operation: " << operation << " Unknown1: " << unknown1 <<
" Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
if (operation == 3) { // Translation
for(int i = 0; i < numKeyframes; i++) {
- time = readFloat(file);
- vec3d = readVector3d(file);
+ time = readFloat(*file);
+ vec3d = readVector3d(*file);
std::cout << "Time : " << time << " Vector: " << vec3d->toString() << std::endl;
delete vec3d;
}
} else if (operation == 4) { // Rotation
for(int i = 0; i < numKeyframes; i++) {
- time = readFloat(file);
- vec4d = readVector4d(file);
+ time = readFloat(*file);
+ vec4d = readVector4d(*file);
std::cout << "Time : " << time << " Vector: " << vec4d->toString() << std::endl;
delete vec4d;
}
diff --git a/tools/module.mk b/tools/module.mk
index f7dcdd798..00852de93 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -78,10 +78,10 @@ tools/meshb2obj$(EXEEXT): $(srcdir)/tools/emi/meshb2obj.o $(srcdir)/tools/emi/la
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common tools/emi/lab.o -o $@ $<
-tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp
+tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $<
tools/setb2set$(EXEEXT): $(srcdir)/tools/emi/setb2set.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
Commit: 911e67bf41a58a1abb4c4a452f72a24d762c9193
https://github.com/scummvm/scummvm-tools/commit/911e67bf41a58a1abb4c4a452f72a24d762c9193
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-09-05T18:12:36+02:00
Commit Message:
UNLAB: Add automatic detection of EMI-labs, thanks to bgbennyboy
Changed paths:
tools/unlab.cpp
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 955aba981..e45c453a4 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -70,14 +70,6 @@ int main(int argc, char **argv) {
exit(1);
}
- if(argc > 2 && !strcmp(argv[2], "EMI")) {
- printf("Opening file with EMI format.\n");
- g_type = GT_EMI;
- } else {
- printf("Opening file with GRIM format.\n");
- g_type = GT_GRIM;
- }
-
infile = fopen(argv[1], "rb");
if (infile == 0) {
printf("Can not open source file: %s\n", argv[1]);
@@ -89,8 +81,16 @@ int main(int argc, char **argv) {
uint32_t num, s_size, s_offset;
fread(&num, 1, 4, infile);
fread(&s_size, 1, 4, infile);
- if(g_type == GT_EMI)
- fread(&s_offset,1,4,infile);
+
+ uint32_t typeTest = 0;
+ fread(&typeTest,1,4,infile);
+ if (typeTest == 0) { // First entry of the table has offset 0 for Grim
+ g_type = GT_GRIM;
+ fseek(infile, -4, SEEK_CUR);
+ } else { // EMI has an offset instead.
+ s_offset = typeTest;
+ g_type = GT_EMI;
+ }
head.num_entries = READ_LE_UINT32(&num);
head.string_table_size = READ_LE_UINT32(&s_size);
if (0 != memcmp(&head.magic, "LABN", 4)) {
Commit: 7d91ece4136c787fc627755a0c65d5b1b6df4966
https://github.com/scummvm/scummvm-tools/commit/7d91ece4136c787fc627755a0c65d5b1b6df4966
Author: Vincent Pelletier (plr.vincent at gmail.com)
Date: 2011-09-10T21:44:37+02:00
Commit Message:
Fix type names.
Changed paths:
tools/emi/lab.cpp
tools/emi/lab.h
diff --git a/tools/emi/lab.cpp b/tools/emi/lab.cpp
index 4b1ac0099..5bb0cbbd1 100644
--- a/tools/emi/lab.cpp
+++ b/tools/emi/lab.cpp
@@ -28,13 +28,13 @@
#include "lab.h"
// TODO: Use common/endian for this
-uint16_t READ_LE_UINT16(const void *ptr) {
- const uint8_t *b = (const uint8_t *)ptr;
+uint16 READ_LE_UINT16(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
return (b[1] << 8) + b[0];
}
-uint32_t READ_LE_UINT32(const void *ptr) {
- const uint8_t *b = (const uint8_t *)ptr;
+uint32 READ_LE_UINT32(const void *ptr) {
+ const uint8 *b = (const uint8 *)ptr;
return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
}
@@ -49,7 +49,7 @@ void Lab::Load(std::string filename) {
fread(&head.magic, 1, 4, infile);
fread(&head.magic2, 1, 4, infile);
- uint32_t num, s_size, s_offset;
+ uint32 num, s_size, s_offset;
fread(&num, 1, 4, infile);
fread(&s_size, 1, 4, infile);
if(g_type == GT_EMI)
@@ -83,7 +83,7 @@ void Lab::Load(std::string filename) {
fseek(infile, 20, SEEK_SET);
// Decrypt the string table
- uint32_t j;
+ uint32 j;
for (j = 0; j < head.string_table_size; j++)
if (str_table[j] != 0)
str_table[j] ^= 0x96;
@@ -115,7 +115,7 @@ std::istream* Lab::getFile(std::string filename) {
return NULL;
} else {
offset = READ_LE_UINT32(&entries[i].start);
- uint32_t size = READ_LE_UINT32(&entries[i].size);
+ uint32 size = READ_LE_UINT32(&entries[i].size);
if (bufSize < size) {
bufSize = size;
char *newBuf = (char *)realloc(buf, bufSize);
diff --git a/tools/emi/lab.h b/tools/emi/lab.h
index 5d4348945..4fb8541e4 100644
--- a/tools/emi/lab.h
+++ b/tools/emi/lab.h
@@ -21,6 +21,7 @@
#ifndef LAB_H
#define LAB_H
+#include "config.h"
#include <string>
#include <iostream>
@@ -28,26 +29,26 @@
#define GT_EMI 2
struct lab_header {
- uint32_t magic;
- uint32_t magic2;
- uint32_t num_entries;
- uint32_t string_table_size;
- uint32_t string_table_offset;
+ uint32 magic;
+ uint32 magic2;
+ uint32 num_entries;
+ uint32 string_table_size;
+ uint32 string_table_offset;
};
struct lab_entry {
- uint32_t fname_offset;
- uint32_t start;
- uint32_t size;
- uint32_t reserved;
+ uint32 fname_offset;
+ uint32 start;
+ uint32 size;
+ uint32 reserved;
};
class Lab {
std::string _filename;
- uint8_t g_type;
- uint32_t i;
- uint32_t offset;
- uint32_t bufSize;
+ uint8 g_type;
+ uint32 i;
+ uint32 offset;
+ uint32 bufSize;
lab_header head;
lab_entry *entries;
char *buf;
Commit: ba1f40ae4ae54fab0105f5feadb471fe4cfed57c
https://github.com/scummvm/scummvm-tools/commit/ba1f40ae4ae54fab0105f5feadb471fe4cfed57c
Author: Vincent Pelletier (plr.vincent at gmail.com)
Date: 2011-09-10T21:45:25+02:00
Commit Message:
Remove unneeded type definition.
Changed paths:
tools/emi/setb2set.cpp
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index 9db4e02d7..e9048fb27 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -15,8 +15,6 @@
using namespace std;
-typedef int uint32;
-
enum SectorType {
NoneType = 0,
WalkType = 0x1000,
Commit: 9c7a84ea072e72b2c1e741a110ff491947673515
https://github.com/scummvm/scummvm-tools/commit/9c7a84ea072e72b2c1e741a110ff491947673515
Author: somaen (einarjohan at somadalen.com)
Date: 2011-09-10T12:48:08-07:00
Commit Message:
Merge pull request #15 from vpelletier/master
Fix build
Changed paths:
tools/emi/lab.cpp
tools/emi/lab.h
tools/emi/setb2set.cpp
Commit: 1520a2ff965689615981af7461751d31b075d291
https://github.com/scummvm/scummvm-tools/commit/1520a2ff965689615981af7461751d31b075d291
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-09-18T22:02:17+02:00
Commit Message:
Fix reading from a cd with bad sectores
Changed paths:
tools/labcopy.cpp
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
index 21f832f30..df690b44f 100644
--- a/tools/labcopy.cpp
+++ b/tools/labcopy.cpp
@@ -33,9 +33,10 @@
#define BUFFER_SIZE 102400
FILE *inLab = NULL, *outLab = NULL;
-bool copyLab(long lenght = 0) {
+int copyLab(long lenght = 0) {
void *buffer;
- long copied_bytes, count, remBytes;
+ long copied_bytes, count, bytesToRead, pos;
+ int retCod = 0;
if (lenght == 0) {
fseek(inLab, 0L, SEEK_END);
@@ -47,18 +48,29 @@ bool copyLab(long lenght = 0) {
fseek(inLab, 0, SEEK_SET);
while (copied_bytes < lenght) {
- remBytes = lenght - copied_bytes;
- count = (long)fread(buffer, 1, (remBytes < BUFFER_SIZE) ? remBytes : BUFFER_SIZE, inLab);
+ bytesToRead = (lenght - copied_bytes < BUFFER_SIZE) ? lenght - copied_bytes : BUFFER_SIZE;
+ pos = ftell(inLab);
+ count = (long)fread(buffer, 1, bytesToRead, inLab);
+
+ //If we get an input error, we skip this block
+ if(ferror(inLab) != 0) {
+ clearerr(inLab);
+ fseek(inLab, pos + bytesToRead, SEEK_SET);
+ count = bytesToRead;
+ memset (buffer, 0, BUFFER_SIZE);
+ retCod = 1;
+ }
+
fwrite(buffer, count, 1, outLab);
copied_bytes += count;
- if(ferror(inLab) != 0 || ferror(outLab) != 0) {
+ if(ferror(outLab) != 0) {
free(buffer);
- return false;
+ return -1;
}
}
free(buffer);
- return true;
+ return retCod;
}
long getLabSize() {
@@ -95,6 +107,7 @@ void cleanup() {
int main(int argc, char *argv[]) {
long labSize;
+ int retCod;
atexit(cleanup);
@@ -126,11 +139,18 @@ int main(int argc, char *argv[]) {
}
//Lab copying
- if (!copyLab(labSize)) {
- printf("I/O error!\n");
- return 1;
+ retCod = copyLab(labSize);
+ switch(retCod) {
+ case 0:
+ printf("%s successfully copied to %s.\n", argv[1], argv[2]);
+ return 0;
+ case 1:
+ printf("%s copied to %s, but with some read errors.\n", argv[1], argv[2]);
+ printf("On some version (e.g. the German one) this is due to copy-protection\n");
+ printf("and this message can be safely ignored. Otherwise check your disk.\n");
+ return 0;
+ case -1:
+ printf("Output error!\n");
+ return 1;
}
-
- printf("%s successfully copied to %s.\n", argv[1], argv[2]);
- return 0;
}
Commit: 0ca90f1cf78eac7b4181efc5bf3b34a1ebe97e90
https://github.com/scummvm/scummvm-tools/commit/0ca90f1cf78eac7b4181efc5bf3b34a1ebe97e90
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-09-19T03:20:32-07:00
Commit Message:
Merge pull request #16 from YakBizzarro/labcopy-badsector
LABCOPY: Fix reading from a cd with bad sectores
Changed paths:
tools/labcopy.cpp
Commit: 5bb712c6c9595fefd5c5ac66a12ed0b875d20d99
https://github.com/scummvm/scummvm-tools/commit/5bb712c6c9595fefd5c5ac66a12ed0b875d20d99
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-09-22T23:41:58+02:00
Commit Message:
LABCOPY: Proper handling of bad-sectors
Changed paths:
tools/labcopy.cpp
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
index df690b44f..03da5a7aa 100644
--- a/tools/labcopy.cpp
+++ b/tools/labcopy.cpp
@@ -30,85 +30,100 @@
#include <cstring>
#include "common/endian.h"
-#define BUFFER_SIZE 102400
+#define BUFFER_SIZE 0x100000
FILE *inLab = NULL, *outLab = NULL;
+void *buffer = NULL;
-int copyLab(long lenght = 0) {
- void *buffer;
- long copied_bytes, count, bytesToRead, pos;
- int retCod = 0;
-
- if (lenght == 0) {
- fseek(inLab, 0L, SEEK_END);
- lenght = ftell(inLab);
- }
+struct lab_entry {
+ uint32 fname_offset;
+ uint32 start;
+ uint32 size;
+ uint32 reserved;
+};
+
+
+bool copyFile(uint32 offset, uint32 lenght) {
+ uint32 copied_bytes, count, bytesToRead;
- buffer = malloc(BUFFER_SIZE);
copied_bytes = 0;
- fseek(inLab, 0, SEEK_SET);
+ fseek(inLab, offset, SEEK_SET);
+ fseek(outLab, offset, SEEK_SET);
while (copied_bytes < lenght) {
bytesToRead = (lenght - copied_bytes < BUFFER_SIZE) ? lenght - copied_bytes : BUFFER_SIZE;
- pos = ftell(inLab);
- count = (long)fread(buffer, 1, bytesToRead, inLab);
-
- //If we get an input error, we skip this block
- if(ferror(inLab) != 0) {
- clearerr(inLab);
- fseek(inLab, pos + bytesToRead, SEEK_SET);
- count = bytesToRead;
- memset (buffer, 0, BUFFER_SIZE);
- retCod = 1;
- }
-
+ count = (uint32)fread(buffer, 1, bytesToRead, inLab);
fwrite(buffer, count, 1, outLab);
copied_bytes += count;
- if(ferror(outLab) != 0) {
- free(buffer);
- return -1;
- }
+ if(ferror(inLab) != 0 || ferror(outLab) != 0)
+ return false;
}
- free(buffer);
- return retCod;
+ return true;
}
-long getLabSize() {
- long total_size = 0;
- char header[16], binary_entry[16];
- int num_entries, string_table_size;
+bool copyLab() {
+ char header[16];
+ uint32 num_entries, string_table_size;
+ char *string_table;
+ lab_entry *lab_entries;
+ //Read and parse header
fseek(inLab, 0, SEEK_SET);
-
fread(header, 16, 1, inLab);
- if (READ_BE_UINT32(header) != MKTAG('L','A','B','N'))
- return -1;
+ if (READ_BE_UINT32(header) != MKTAG('L','A','B','N')) {
+ printf("This isn't a valid .lab file!\n");
+ exit(1);
+ }
num_entries = READ_LE_UINT32(header + 8);
string_table_size = READ_LE_UINT32(header + 12);
- total_size = 16 + num_entries * 16 + string_table_size;
-
- for (int i = 0; i < num_entries; i++) {
- fread(binary_entry, 16, 1, inLab);
- total_size += READ_LE_UINT32(binary_entry + 8);
- }
+ //Read files entries
+ lab_entries = (lab_entry *)calloc(sizeof(lab_entry), num_entries);
+ fread(lab_entries, 1, num_entries * sizeof(struct lab_entry), inLab);
- return total_size;
+ //Read string table
+ string_table = (char *)malloc(string_table_size);
+ fread(string_table, 1, string_table_size, inLab);
+
+ //Write out new lab
+ fwrite(header, 16, 1, outLab);
+ fwrite(lab_entries, sizeof(struct lab_entry), num_entries, outLab);
+ fwrite(string_table, string_table_size, 1, outLab);
+
+ //Check for errors
+ if(ferror(inLab) != 0 || ferror(outLab) != 0) {
+ free(lab_entries);
+ free(string_table);
+ return false;
+ }
+
+ //Copy the files, except cp_0_intha.bm
+ for (uint32 i = 0; i < num_entries; i++)
+ if(strcmp(string_table + READ_LE_UINT32(&lab_entries[i].fname_offset), "cp_0_intha.bm") != 0)
+ if (!copyFile(lab_entries[i].start, lab_entries[i].size)) {
+ free(lab_entries);
+ free(string_table);
+ return false;
+ }
+
+ free(lab_entries);
+ free(string_table);
+ return true;
}
void cleanup() {
if (inLab)
fclose(inLab);
-
+
if (outLab)
fclose(outLab);
+
+ if (buffer)
+ free(buffer);
}
int main(int argc, char *argv[]) {
- long labSize;
- int retCod;
-
atexit(cleanup);
//Argument checks and usage display
@@ -131,26 +146,17 @@ int main(int argc, char *argv[]) {
return 1;
}
- //Get the correct lab size
- labSize = getLabSize();
- if (labSize < 0) {
- printf("%s isn't a valid .lab file!\n", argv[1]);
+ buffer = malloc(BUFFER_SIZE);
+ if (!buffer) {
+ printf("Unable to allocate memory!\n");
return 1;
}
- //Lab copying
- retCod = copyLab(labSize);
- switch(retCod) {
- case 0:
- printf("%s successfully copied to %s.\n", argv[1], argv[2]);
- return 0;
- case 1:
- printf("%s copied to %s, but with some read errors.\n", argv[1], argv[2]);
- printf("On some version (e.g. the German one) this is due to copy-protection\n");
- printf("and this message can be safely ignored. Otherwise check your disk.\n");
- return 0;
- case -1:
- printf("Output error!\n");
- return 1;
+ if (!copyLab()) {
+ printf("I/O error!\n");
+ return 1;
}
+
+ printf("%s successfully copied to %s.\n", argv[1], argv[2]);
+ return 0;
}
Commit: 17ac5cdc14d241981d4f84392116e09b26c87af8
https://github.com/scummvm/scummvm-tools/commit/17ac5cdc14d241981d4f84392116e09b26c87af8
Author: somaen (einarjohan at somadalen.com)
Date: 2011-10-12T05:44:35-07:00
Commit Message:
Merge pull request #17 from YakBizzarro/labcopy-rewrite
LABCOPY: Proper handling of bad-sectors
Changed paths:
tools/labcopy.cpp
Commit: ea82f02f6ed6b9d093a8cc1b7e0b0bf839fc5624
https://github.com/scummvm/scummvm-tools/commit/ea82f02f6ed6b9d093a8cc1b7e0b0bf839fc5624
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-10-21T16:03:56+02:00
Commit Message:
New mklab tool to build lab files.
Changed paths:
A tools/mklab.cpp
tools/module.mk
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
new file mode 100644
index 000000000..25fa9e586
--- /dev/null
+++ b/tools/mklab.cpp
@@ -0,0 +1,245 @@
+/* Residual - A 3D game interpreter
+ *
+ * Residual is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the AUTHORS
+ * file distributed with this source distribution.
+ *
+ * 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
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+
+#define GT_GRIM 1
+#define GT_EMI 2
+
+typedef struct {
+ uint32_t magic;
+ uint32_t magic2;
+ uint32_t num_entries;
+ uint32_t string_table_size;
+ uint32_t string_table_offset;
+} lab_header;
+
+typedef struct {
+ uint32_t fname_offset;
+ uint32_t start;
+ uint32_t size;
+ uint32_t reserved;
+} lab_entry;
+
+uint32_t READ_LE_UINT32(const void *ptr) {
+ const uint8_t *b = (const uint8_t *)ptr;
+ return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
+}
+
+void WRITE_LE_UINT16(void *ptr, uint16_t value) {
+ uint8_t *b = (uint8_t *)ptr;
+ b[0] = (uint8_t)(value >> 0);
+ b[1] = (uint8_t)(value >> 8);
+}
+void WRITE_LE_UINT32(void *ptr, uint32_t value) {
+ uint8_t *b = (uint8_t *)ptr;
+ b[0] = (uint8_t)(value >> 0);
+ b[1] = (uint8_t)(value >> 8);
+ b[2] = (uint8_t)(value >> 16);
+ b[3] = (uint8_t)(value >> 24);
+}
+
+void write(FILE *file, uint16_t value) {
+ char v[2];
+ WRITE_LE_UINT16(&v, value);
+ fwrite(&v, 1, 2, file);
+}
+
+void write(FILE *file, uint32_t value) {
+ char v[4];
+ WRITE_LE_UINT32(&v, value);
+ fwrite(&v, 1, 4, file);
+}
+
+void usage() {
+ printf("Usage: mklab --grim/--emi DIRECTORY FILE\n");
+}
+
+void help() {
+ usage();
+ printf("Create a lab file containing all the files into the specified directory\n\n");
+ printf("\t--grim\tCreate a Grim-compatible lab.\n");
+ printf("\t--emi\tCreate an EMI-compatible lab.\n");
+ printf("\t--help\tPrint this help.\n");
+ exit(0);
+}
+
+int main(int argc, char **argv) {
+ if (argc > 1 && !strcmp(argv[1], "--help")) {
+ help();
+ }
+
+ if (argc < 4) {
+ usage();
+ exit(1);
+ }
+
+ const char *type = argv[1];
+ const char *dirname = argv[2];
+ const char *out = argv[3];
+
+ uint8_t g_type;
+ if (!strcmp(type, "--grim")) {
+ g_type = GT_GRIM;
+ } else if (!strcmp(type, "--emi")) {
+ g_type = GT_EMI;
+ } else {
+ usage();
+ exit(1);
+ }
+
+ lab_header head;
+
+ DIR *dir = opendir(dirname);
+ if (dir == 0) {
+ printf("Can not open source dir: %s\n", argv[1]);
+ exit(2);
+ }
+
+ head.num_entries = 0;
+ head.string_table_size = 0;
+ struct dirent *dirfile;
+ while ((dirfile = readdir(dir))) {
+ if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
+ continue;
+
+ ++head.num_entries;
+ head.string_table_size += strlen(dirfile->d_name) + 1;
+ }
+// printf("%d files, string table of size %d\n", head.num_entries, head.string_table_size);
+
+ lab_entry *entries = (lab_entry *)malloc(head.num_entries * sizeof(lab_entry));
+ char *str_table = (char *)malloc(head.string_table_size);
+ if (!str_table || !entries) {
+ printf("Could not allocate memory\n");
+ exit(3);
+ }
+
+ uint32_t offset = 16 + head.num_entries * sizeof(lab_entry) + head.string_table_size + 16;
+ uint32_t num_entry = 0;
+ uint32_t name_offset = 0;
+ char *str_offset = str_table;
+ rewinddir(dir);
+ while ((dirfile = readdir(dir))) {
+ if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
+ continue;
+
+ lab_entry &entry = entries[num_entry++];
+
+ WRITE_LE_UINT32(&entry.fname_offset, name_offset);
+ WRITE_LE_UINT32(&entry.start, offset);
+ entry.reserved = 0; //What is this??
+
+ strcpy(str_offset, dirfile->d_name);
+ str_offset[strlen(dirfile->d_name)] = 0;
+ name_offset += strlen(dirfile->d_name) + 1;
+ str_offset = str_table + name_offset;
+
+ char *path = (char *)malloc(strlen(dirfile->d_name) + strlen(dirname) + 2);
+ strcpy(path, dirname);
+ path[strlen(dirname)] = '/';
+ strcpy(path + strlen(dirname) + 1, dirfile->d_name);
+
+ struct stat st;
+ stat(path, &st);
+
+ // printf("entry of file %s, at offset %d and of size %d\n", path, offset, st.st_size);
+ free(path);
+
+ offset += st.st_size;
+ WRITE_LE_UINT32(&entry.size, st.st_size);
+ }
+ closedir(dir);
+
+ // Open the output file after we've finished with the dir, so that we're sure
+ // we don't include the lab into itself if it was asked to be created into the same dir.
+ FILE *outfile = fopen(out, "wb");
+ if (!outfile) {
+ printf("Could not open file %s for writing\n", argv[2]);
+ exit(2);
+ }
+
+ fwrite("LABN", 1, 4, outfile);
+ fwrite(" ", 1, 4, outfile); //version
+ write(outfile, head.num_entries);
+ write(outfile, head.string_table_size);
+
+ if (g_type == GT_GRIM) {
+ uint32_t s_offset = 0; // First entry of the table has offset 0 for Grim
+ fwrite(&s_offset, 1, 4, outfile);
+ fseek(outfile, -4, SEEK_CUR);
+ } else { // EMI has an offset instead.
+ write(outfile, 20 + head.num_entries * sizeof(lab_entry) + 0x13d0f);
+ }
+
+ fwrite(entries, 1, head.num_entries * sizeof(lab_entry), outfile);
+ if (g_type == GT_GRIM) {
+ fwrite(str_table, 1, head.string_table_size, outfile);
+ } else {
+ char *s = (char *)malloc(head.string_table_size);
+ memset(s, 0, head.string_table_size);
+ for (uint32_t j = 0; j < head.string_table_size; j++) {
+ if (str_table[j] != 0)
+ s[j] = str_table[j] ^ 0x96;
+ }
+ fwrite(s, 1, head.string_table_size, outfile);
+ }
+
+ for (uint32_t i = 0; i < head.num_entries; ++i) {
+ lab_entry &entry = entries[i];
+ const char *fname = str_table + READ_LE_UINT32(&entry.fname_offset);
+
+ char *path = (char *)malloc(strlen(fname) + strlen(dirname) + 2);
+ strcpy(path, dirname);
+ path[strlen(dirname)] = '/';
+ strcpy(path + strlen(dirname) + 1, fname);
+
+ FILE *file = fopen(path, "rb");
+ free(path);
+
+ offset = READ_LE_UINT32(&entry.start);
+ uint32_t size = READ_LE_UINT32(&entry.size);
+
+ char *buf = (char *)malloc(size);
+
+// printf("writing file %s, at offset %d and of size %d\n", fname, offset, size);
+
+ fread(buf, 1, size, file);
+ fseek(outfile, offset, SEEK_SET);
+ fwrite(buf, 1, size, outfile);
+
+ free(buf);
+ fclose(file);
+ }
+
+ fclose(outfile);
+ free(entries);
+ free(str_table);
+
+ return 0;
+}
diff --git a/tools/module.mk b/tools/module.mk
index 00852de93..c679b1182 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -22,6 +22,7 @@ TOOLS := \
tools/set2fig$(EXEEXT) \
tools/til2bmp$(EXEEXT) \
tools/unlab$(EXEEXT) \
+ tools/mklab$(EXEEXT) \
tools/vima$(EXEEXT) \
tools/labcopy$(EXEEXT) \
tools/patchex/patchex$(EXEEXT)
@@ -100,12 +101,16 @@ tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
tools/til2bmp$(EXEEXT): $(srcdir)/tools/emi/til2bmp.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -lz -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -lz -o $@ $<
tools/unlab$(EXEEXT): $(srcdir)/tools/unlab.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
+tools/mklab$(EXEEXT): $(srcdir)/tools/mklab.cpp
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) -Wall -o $@ $<
+
tools/vima$(EXEEXT): $(srcdir)/tools/vima.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -o $@ $<
Commit: 56e19ba76a26321669d9728384b6577d0b34d228
https://github.com/scummvm/scummvm-tools/commit/56e19ba76a26321669d9728384b6577d0b34d228
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-10-23T06:43:43-07:00
Commit Message:
Merge pull request #18 from giucam/master
New mklab tool to build lab files
Changed paths:
A tools/mklab.cpp
tools/module.mk
Commit: 37966e3efdcaecf2578e0497bcff174f183de248
https://github.com/scummvm/scummvm-tools/commit/37966e3efdcaecf2578e0497bcff174f183de248
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-10-28T15:24:36+02:00
Commit Message:
MKLAB: Fix ambiguous overload. Fix #19
Changed paths:
tools/mklab.cpp
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index 25fa9e586..ae28cf1d8 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -64,13 +64,13 @@ void WRITE_LE_UINT32(void *ptr, uint32_t value) {
b[3] = (uint8_t)(value >> 24);
}
-void write(FILE *file, uint16_t value) {
+void writeUint16(FILE *file, uint16_t value) {
char v[2];
WRITE_LE_UINT16(&v, value);
fwrite(&v, 1, 2, file);
}
-void write(FILE *file, uint32_t value) {
+void writeUint32(FILE *file, uint32_t value) {
char v[4];
WRITE_LE_UINT32(&v, value);
fwrite(&v, 1, 4, file);
@@ -186,15 +186,15 @@ int main(int argc, char **argv) {
fwrite("LABN", 1, 4, outfile);
fwrite(" ", 1, 4, outfile); //version
- write(outfile, head.num_entries);
- write(outfile, head.string_table_size);
+ writeUint32(outfile, head.num_entries);
+ writeUint32(outfile, head.string_table_size);
if (g_type == GT_GRIM) {
uint32_t s_offset = 0; // First entry of the table has offset 0 for Grim
fwrite(&s_offset, 1, 4, outfile);
fseek(outfile, -4, SEEK_CUR);
} else { // EMI has an offset instead.
- write(outfile, 20 + head.num_entries * sizeof(lab_entry) + 0x13d0f);
+ writeUint32(outfile, 20 + head.num_entries * sizeof(lab_entry) + 0x13d0f);
}
fwrite(entries, 1, head.num_entries * sizeof(lab_entry), outfile);
Commit: 2b968f37bf808d444d5a6ee37118145ed01b7b4c
https://github.com/scummvm/scummvm-tools/commit/2b968f37bf808d444d5a6ee37118145ed01b7b4c
Author: Einar Johan T. SømaÌen (einarjohants at gmail.com)
Date: 2011-11-22T04:14:53+01:00
Commit Message:
BUILD: Patch from Kirben, fixes mingw build
Changed paths:
configure
tools/module.mk
diff --git a/configure b/configure
index c07640861..1159cb94e 100755
--- a/configure
+++ b/configure
@@ -745,6 +745,7 @@ case $_host_os in
;;
mingw*)
DEFINES="$DEFINES -DWIN32 -D__USE_MINGW_ANSI_STDIO=0"
+ LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
LIBS="$LIBS -lmingw32 -lwinmm"
;;
cygwin*)
diff --git a/tools/module.mk b/tools/module.mk
index c679b1182..d889ad864 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -51,77 +51,77 @@ clean-tools:
tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -Ltools/lua -o $@ $< -llua
+ -L$(srcdir)/common -Ltools/lua -o $@ $< $(LDFLAGS) -llua
tools/mat2ppm$(EXEEXT): $(srcdir)/tools/mat2ppm.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -lppm -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -lppm -o $@ $< $(LDFLAGS)
tools/bmtoppm$(EXEEXT): $(srcdir)/tools/bmtoppm.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -lppm -lpbm -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -lppm -lpbm -o $@ $< $(LDFLAGS)
tools/imc2wav$(EXEEXT): $(srcdir)/tools/imc2wav.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
tools/int2flt$(EXEEXT): $(srcdir)/tools/int2flt.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
tools/cosb2cos$(EXEEXT): $(srcdir)/tools/emi/cosb2cos.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -o $@ $<
+ -L$(srcdir)/common -o $@ $< $(LDFLAGS)
tools/meshb2obj$(EXEEXT): $(srcdir)/tools/emi/meshb2obj.o $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
tools/setb2set$(EXEEXT): $(srcdir)/tools/emi/setb2set.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
tools/sklb2txt$(EXEEXT): $(srcdir)/tools/emi/sklb2txt.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
tools/til2bmp$(EXEEXT): $(srcdir)/tools/emi/til2bmp.cpp $(srcdir)/tools/emi/lab.o
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -lz -o $@ $<
+ -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS) -lz
tools/unlab$(EXEEXT): $(srcdir)/tools/unlab.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
tools/mklab$(EXEEXT): $(srcdir)/tools/mklab.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
tools/vima$(EXEEXT): $(srcdir)/tools/vima.cpp
$(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $<
+ $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
tools/labcopy$(EXEEXT): $(srcdir)/tools/labcopy.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -Wall \
- -L$(srcdir)/common -o $@ $<
+ -L$(srcdir)/common -o $@ $< $(LDFLAGS)
tools/patchex/patchex$(EXEEXT): tools/patchex/patchex.o tools/patchex/mszipd.o tools/patchex/cabd.o
$(MKDIR) tools/patchex/$(DEPDIR)
- $(CXX) $(CFLAGS) tools/patchex/mszipd.o tools/patchex/cabd.o -Wall -o $@ $<
+ $(CXX) $(CFLAGS) tools/patchex/mszipd.o tools/patchex/cabd.o -Wall -o $@ $< $(LDFLAGS)
.PHONY: clean-tools tools
Commit: d75d0f138aa1e262b86971f70d66488a85a1b0f2
https://github.com/scummvm/scummvm-tools/commit/d75d0f138aa1e262b86971f70d66488a85a1b0f2
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-11-28T21:54:49+01:00
Commit Message:
Add lua bytecode generator (luac)
Changed paths:
A tools/luac/dump.c
A tools/luac/luac.c
A tools/luac/opcode.c
A tools/luac/opt.c
A tools/luac/print.c
tools/module.mk
diff --git a/tools/luac/dump.c b/tools/luac/dump.c
new file mode 100644
index 000000000..010bcf09f
--- /dev/null
+++ b/tools/luac/dump.c
@@ -0,0 +1,143 @@
+/*
+** $Id$
+** save bytecodes to file
+** See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "luac.h"
+#include "common/endian.h"
+
+#define NotWord(x) ((unsigned short)x!=x)
+#define DumpBlock(b,size,D) fwrite(b,size,1,D)
+#define DumpNative(t,D) DumpBlock(&t,sizeof(t),D)
+
+static void DumpWord(int i, FILE* D) {
+ byte out[2];
+ WRITE_BE_UINT16(out, i);
+ DumpBlock(out,2,D);
+}
+
+static void DumpLong(long i, FILE* D) {
+ byte out[4];
+ WRITE_BE_UINT32(out, i);
+ DumpBlock(out,4,D);
+}
+
+/* LUA_NUMBER */
+/* assumes sizeof(long)==4 and sizeof(float)==4 (IEEE) */
+static void DumpFloat(float f, FILE* D) {
+ byte *fdata = (byte *)(&f);
+
+ fputc(fdata[3],D);
+ fputc(fdata[2],D);
+ fputc(fdata[1],D);
+ fputc(fdata[0],D);
+}
+
+static void DumpCode(TProtoFunc* tf, FILE* D) {
+ int size=CodeSize(tf);
+ if (NotWord(size))
+ fprintf(stderr,"luac: warning: "
+ "\"%s\":%d code too long for 16-bit machines (%d bytes)\n",
+ fileName(tf),tf->lineDefined,size);
+ DumpLong(size,D);
+ DumpBlock(tf->code,size,D);
+}
+
+static void DumpString(char* s, int size, FILE* D) {
+ if (s == NULL)
+ DumpWord(0,D);
+ else {
+ if (NotWord(size))
+ luaL_verror("string too long (%d bytes): \"%.32s...\"",size,s);
+ DumpWord(size,D);
+ for(int i = 0; i < size; ++i)
+ fputc(s[i] ^ 0xFF, D);
+ }
+}
+
+static void DumpTString(TaggedString* s, FILE* D) {
+ if (s == NULL) DumpString(NULL,0,D); else DumpString(s->str,s->u.s.len+1,D);
+}
+
+static void DumpLocals(TProtoFunc* tf, FILE* D) {
+ int n;
+ LocVar* lv;
+ for (n=0,lv=tf->locvars; lv && lv->line>=0; lv++) ++n;
+ DumpWord(n,D);
+ for (lv=tf->locvars; lv && lv->line>=0; lv++) {
+ DumpWord(lv->line,D);
+ DumpTString(lv->varname,D);
+ }
+}
+
+static void DumpFunction(TProtoFunc* tf, FILE* D);
+
+static void DumpSubFunctions(TProtoFunc* tf, FILE* D) {
+ int i,n;
+ n = tf->nconsts;
+ for (i=0; i<n; i++) {
+ TObject* o=tf->consts+i;
+ if (ttype(o) == LUA_T_PROTO) {
+ fputc('#',D);
+ DumpWord(i,D);
+ DumpFunction(tfvalue(o),D);
+ }
+ }
+ fputc('$',D);
+}
+
+static void DumpConstants(TProtoFunc* tf, FILE* D) {
+ int i,n;
+ n = tf->nconsts;
+ DumpWord(n,D);
+ for (i=0; i<n; i++) {
+ TObject* o=tf->consts+i;
+ switch (ttype(o)) {
+ case LUA_T_NUMBER:
+ fputc('N',D);
+ DumpNumber(nvalue(o),D);
+ break;
+ case LUA_T_STRING:
+ fputc('S',D);
+ DumpTString(tsvalue(o),D);
+ break;
+ case LUA_T_PROTO:
+ fputc('F',D);
+ break;
+ case LUA_T_NIL:
+ fputc(-ttype(o),D);
+ break;
+ default: /* cannot happen */
+ luaL_verror("cannot dump constant #%d: type=%d [%s]",
+ i,ttype(o),luaO_typename(o));
+ break;
+ }
+ }
+}
+
+static void DumpFunction(TProtoFunc* tf, FILE* D) {
+ DumpWord(tf->lineDefined,D);
+ DumpTString(tf->fileName,D);
+ DumpCode(tf,D);
+ DumpConstants(tf,D);
+ DumpLocals(tf,D);
+ DumpSubFunctions(tf,D);
+}
+
+static void DumpHeader(TProtoFunc* Main, FILE* D) {
+ real t=TEST_NUMBER;
+ fputc(ID_CHUNK,D);
+ fputs(SIGNATURE,D);
+ fputc(VERSION,D);
+ fputc(sizeof(t),D);
+ fputc(ID_NUMBER,D);
+ DumpBlock("\x0A\xBF\x17",3,D); //Instead TEST_NUMBER, it dumps the same sequence found in GF scripts
+}
+
+void DumpChunk(TProtoFunc* Main, FILE* D) {
+ DumpHeader(Main,D);
+ DumpFunction(Main,D);
+}
diff --git a/tools/luac/luac.c b/tools/luac/luac.c
new file mode 100644
index 000000000..3a7b0e974
--- /dev/null
+++ b/tools/luac/luac.c
@@ -0,0 +1,184 @@
+/*
+** $Id$
+** lua compiler (saves bytecodes to files; also list binary files)
+** See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "luac.h"
+#include "lparser.h"
+#include "lzio.h"
+#include "luadebug.h"
+
+#define OUTPUT "luac.out" /* default output file */
+
+extern void DumpChunk(TProtoFunc* Main, FILE* D);
+extern void PrintChunk(TProtoFunc* Main);
+extern void OptChunk(TProtoFunc* Main);
+
+static FILE* efopen(char* name, const char* mode);
+static void doit(int undump, char* filename);
+
+static int listing=0; /* list bytecodes? */
+static int debugging=0; /* debug? */
+static int dumping=1; /* dump bytecodes? */
+static int undumping=0; /* undump bytecodes? */
+static int optimizing=0; /* optimize? */
+static int parsing=0; /* parse only? */
+static int verbose=0; /* tell user what is done */
+static FILE* D; /* output file */
+
+static void usage(void)
+{
+ fprintf(stderr,"usage: "
+ "luac [-c | -u] [-D name] [-d] [-l] [-o output] [-O] [-p] [-q] [-v] [-V] [files]\n"
+ " -c\tcompile (default)\n"
+ " -u\tundump\n"
+ " -d\tgenerate debugging information\n"
+ " -D\tpredefine symbol for conditional compilation\n"
+ " -l\tlist (default for -u)\n"
+ " -o\toutput file for -c (default is \"" OUTPUT "\")\n"
+ " -O\toptimize\n"
+ " -p\tparse only\n"
+ " -q\tquiet (default for -c)\n"
+ " -v\tshow version information\n"
+ " -V\tverbose\n"
+ " -\tcompile \"stdin\"\n"
+ );
+ exit(1);
+}
+
+#define IS(s) (strcmp(argv[i],s)==0)
+
+int main(int argc, char* argv[])
+{
+ char* d=OUTPUT; /* output file name */
+ int i;
+ lua_open();
+ for (i=1; i<argc; i++)
+ {
+ if (argv[i][0]!='-') /* end of options */
+ break;
+ else if (IS("-")) /* use stdin */
+ break;
+ else if (IS("-c")) /* compile (and dump) */
+ {
+ dumping=1;
+ undumping=0;
+ }
+ else if (IS("-D")) /* $define */
+ {
+ TaggedString* s=luaS_new(argv[++i]);
+ s->u.s.globalval.ttype=LUA_T_NUMBER;
+ s->u.s.globalval.value.n=1;
+ }
+ else if (IS("-d")) /* debug */
+ debugging=1;
+ else if (IS("-l")) /* list */
+ listing=1;
+ else if (IS("-o")) /* output file */
+ d=argv[++i];
+ else if (IS("-O")) /* optimize */
+ optimizing=1;
+ else if (IS("-p")) /* parse only */
+ {
+ dumping=0;
+ parsing=1;
+ }
+ else if (IS("-q")) /* quiet */
+ listing=0;
+ else if (IS("-u")) /* undump */
+ {
+ dumping=0;
+ undumping=1;
+ listing=1;
+ }
+ else if (IS("-v")) /* show version */
+ printf("%s %s\n(written by %s)\n\n",LUA_VERSION,LUA_COPYRIGHT,LUA_AUTHORS);
+ else if (IS("-V")) /* verbose */
+ verbose=1;
+ else /* unknown option */
+ usage();
+ }
+ --i; /* fake new argv[0] */
+ argc-=i;
+ argv+=i;
+ if (dumping || parsing)
+ {
+ if (argc<2) usage();
+ if (dumping)
+ {
+ for (i=1; i<argc; i++) /* play safe with output file */
+ if (IS(d)) luaL_verror("will not overwrite input file \"%s\"",d);
+ D=efopen(d,"wb"); /* must open in binary mode */
+#if ID_NUMBER==ID_NATIVE
+ if (verbose) fprintf(stderr,"luac: warning: "
+ "saving numbers in native format. file may not be portable.\n");
+#endif
+ }
+ for (i=1; i<argc; i++) doit(0,IS("-")? NULL : argv[i]);
+ if (dumping) fclose(D);
+ }
+ if (undumping)
+ {
+ if (argc<2)
+ doit(1,OUTPUT);
+ else
+ for (i=1; i<argc; i++) doit(1,IS("-")? NULL : argv[i]);
+ }
+ return 0;
+}
+
+static void do_compile(ZIO* z)
+{
+ TProtoFunc* Main;
+ if (optimizing) lua_debug=0; /* set debugging before parsing */
+ if (debugging) lua_debug=1;
+ Main=luaY_parser(z);
+ if (optimizing) OptChunk(Main);
+ if (listing) PrintChunk(Main);
+ if (dumping) DumpChunk(Main,D);
+}
+
+static void do_undump(ZIO* z)
+{
+ while (1)
+ {
+ TProtoFunc* Main=luaU_undump1(z);
+ if (Main==NULL) break;
+ if (optimizing) OptChunk(Main);
+ if (listing) PrintChunk(Main);
+ }
+}
+
+static void doit(int undump, char* filename)
+{
+ FILE* f;
+ ZIO z;
+ if (filename==NULL)
+ {
+ f=stdin; filename="(stdin)";
+ }
+ else
+ {
+ f=efopen(filename, undump ? "rb" : "r");
+ }
+ zFopen(&z,f,filename);
+ if (verbose) fprintf(stderr,"%s\n",filename);
+ if (undump) do_undump(&z); else do_compile(&z);
+ if (f!=stdin) fclose(f);
+}
+
+static FILE* efopen(char* name, const char* mode)
+{
+ FILE* f=fopen(name,mode);
+ if (f==NULL)
+ {
+ fprintf(stderr,"luac: cannot open %sput file ",mode[0]=='r' ? "in" : "out");
+ perror(name);
+ exit(1);
+ }
+ return f;
+}
diff --git a/tools/luac/opcode.c b/tools/luac/opcode.c
new file mode 100644
index 000000000..52ab8b7b0
--- /dev/null
+++ b/tools/luac/opcode.c
@@ -0,0 +1,87 @@
+/*
+** $Id$
+** opcode information
+** See Copyright Notice in lua.h
+*/
+
+#include "luac.h"
+
+static Opcode Info[]= /* ORDER lopcodes.h */
+{
+#include "opcode.h"
+};
+
+#define NOPCODES (sizeof(Info)/sizeof(Info[0]))
+
+int OpcodeInfo(TProtoFunc* tf, Byte* p, Opcode* I, char* xFILE, int xLINE)
+{
+ Opcode OP;
+ Byte* code=tf->code;
+ int op=*p;
+ if (p==code)
+ {
+ OP.name="STACK";
+ OP.size=1;
+ OP.op=STACK;
+ OP.op_class=STACK;
+ OP.arg=op;
+ }
+ else if (p==code+1)
+ {
+ OP.size=1;
+ if (op>=ZEROVARARG)
+ {
+ OP.name="VARARGS";
+ OP.op=VARARGS;
+ OP.op_class=VARARGS;
+ OP.arg=op-ZEROVARARG;
+ }
+ else
+ {
+ OP.name="ARGS";
+ OP.op=ARGS;
+ OP.op_class=ARGS;
+ OP.arg=op;
+ }
+ }
+ else if (op==NOP)
+ {
+ OP.name="NOP";
+ OP.size=1;
+ OP.op=NOP;
+ OP.op_class=NOP;
+ }
+ else if (op>=NOPCODES) /* cannot happen */
+ {
+ luaL_verror("internal error at %s:%d: bad opcode %d at %d in tf=%p",
+ xFILE, xLINE,op,(int)(p-code),tf);
+ return 0;
+ }
+ else
+ {
+ OP=Info[op];
+ if (op==SETLIST || op==CLOSURE || op==CALLFUNC)
+ {
+ OP.arg=p[1];
+ OP.arg2=p[2];
+ }
+ else if (OP.size==2) OP.arg=p[1];
+ else if (OP.size>=3) OP.arg=(p[1]<<8)+p[2];
+ if (op==SETLISTW) OP.arg2=p[3];
+ }
+ *I=OP;
+ return OP.size;
+}
+
+int CodeSize(TProtoFunc* tf)
+{
+ Byte* code=tf->code;
+ Byte* p=code;
+ while (1)
+ {
+ Opcode OP;
+ p+=INFO(tf,p,&OP);
+ if (OP.op==ENDCODE) break;
+ }
+ return p-code;
+}
diff --git a/tools/luac/opt.c b/tools/luac/opt.c
new file mode 100644
index 000000000..8fc0e8f6a
--- /dev/null
+++ b/tools/luac/opt.c
@@ -0,0 +1,228 @@
+/*
+** $Id$
+** optimize bytecodes
+** See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "luac.h"
+#include "lmem.h"
+
+static void FixConstants(TProtoFunc* tf, int* C)
+{
+ Byte* code=tf->code;
+ Byte* p=code;
+ while (1)
+ {
+ Opcode OP;
+ int n=INFO(tf,p,&OP);
+ int op=OP.op_class;
+ int i=OP.arg;
+ if (op==ENDCODE) break;
+ if ( op==PUSHCONSTANT || op==GETDOTTED || op==PUSHSELF ||
+ op==GETGLOBAL || op==SETGLOBAL)
+ {
+ int j=C[i];
+ if (j==i)
+ ;
+ else if (n==1)
+ {
+ p[0]=op+j+1;
+ }
+ else if (n==2)
+ {
+ if (j<8) { p[0]=op+j+1; p[1]=NOP; } else p[1]=j;
+ }
+ else
+ {
+ if (j<=255)
+ {
+ p[0]=op;
+ p[1]=j;
+ p[2]=NOP;
+ }
+ else
+ {
+ p[1]= 0x0000FF & (j>>8);
+ p[2]= 0x0000FF & j;
+ }
+ }
+ }
+ p+=n;
+ }
+}
+
+static TProtoFunc* TF;
+
+static int compare(const void* a, const void *b)
+{
+ int ia=*(int*)a;
+ int ib=*(int*)b;
+ int t;
+ TObject* oa=TF->consts+ia;
+ TObject* ob=TF->consts+ib;
+ t=ttype(oa)-ttype(ob); if (t) return t;
+ t=oa->value.i-ob->value.i; if (t) return t;
+ return ia-ib;
+}
+
+static void OptConstants(TProtoFunc* tf)
+{
+ static int* C=NULL;
+ static int* D=NULL;
+ int i,k;
+ int n=tf->nconsts;
+ if (n==0) return;
+ C=luaM_reallocvector(C,n,int);
+ D=luaM_reallocvector(D,n,int);
+ for (i=0; i<n; i++) C[i]=D[i]=i; /* group duplicates */
+ TF=tf; qsort(C,n,sizeof(C[0]),compare);
+ k=C[0]; /* build duplicate table */
+ for (i=1; i<n; i++)
+ {
+ int j=C[i];
+ TObject* oa=tf->consts+k;
+ TObject* ob=tf->consts+j;
+ if (ttype(oa)==ttype(ob) && oa->value.i==ob->value.i) D[j]=k; else k=j;
+ }
+ k=0; /* build rename map & pack constants */
+ for (i=0; i<n; i++)
+ {
+ if (D[i]==i) { tf->consts[k]=tf->consts[i]; C[i]=k++; } else C[i]=C[D[i]];
+ }
+ if (k>=n) return;
+printf("\t\"%s\":%d reduced constants from %d to %d\n",
+ tf->fileName->str,tf->lineDefined,n,k);
+ tf->nconsts=k;
+ FixConstants(tf,C);
+}
+
+static int NoDebug(TProtoFunc* tf)
+{
+ Byte* code=tf->code;
+ Byte* p=code;
+ int nop=0;
+ while (1) /* change SETLINE to NOP */
+ {
+ Opcode OP;
+ int n=INFO(tf,p,&OP);
+ int op=OP.op_class;
+ if (op==ENDCODE) break;
+ if (op==NOP) ++nop;
+ if (op==SETLINE) { nop+=n; memset(p,NOP,n); }
+ p+=n;
+ }
+ return nop;
+}
+
+static int FixJump(TProtoFunc* tf, Byte* a, Byte* b)
+{
+ Byte* p;
+ int nop=0;
+ for (p=a; p<b; )
+ {
+ Opcode OP;
+ int n=INFO(tf,p,&OP);
+ int op=OP.op_class;
+ if (op==ENDCODE) break;
+ if (op==NOP) ++nop;
+ p+=n;
+ }
+ return nop;
+}
+
+static void FixJumps(TProtoFunc* tf)
+{
+ Byte* code=tf->code;
+ Byte* p=code;
+ while (1)
+ {
+ Opcode OP;
+ int n=INFO(tf,p,&OP);
+ int op=OP.op_class;
+ int i=OP.arg;
+ int nop;
+ if (op==ENDCODE) break;
+ nop=0;
+ if (op==IFTUPJMP || op==IFFUPJMP) nop=FixJump(tf,p-i+n,p); else
+ if (op==ONTJMP || op==ONFJMP || op==JMP || op==IFFJMP) nop=FixJump(tf,p,p+i+n);
+ if (nop>0)
+ {
+ int j=i-nop;
+ if (n==2)
+ p[1]=j;
+ else
+#if 0
+ {
+ if (j<=255) /* does NOT work for nested loops */
+ {
+ if (op==IFTUPJMP || op==IFFUPJMP) --j;
+ p[0]=OP.op-1; /* *JMP and *JMPW are consecutive */
+ p[1]=j;
+ p[2]=NOP;
+ }
+ else
+#endif
+ {
+ p[1]= 0x0000FF & (j>>8);
+ p[2]= 0x0000FF & j;
+ }
+#if 0
+ }
+#endif
+ }
+ p+=n;
+ }
+}
+
+static void PackCode(TProtoFunc* tf)
+{
+ Byte* code=tf->code;
+ Byte* p=code;
+ Byte* q=code;
+ while (1)
+ {
+ Opcode OP;
+ int n=INFO(tf,p,&OP);
+ int op=OP.op_class;
+ if (op!=NOP) { memcpy(q,p,n); q+=n; }
+ p+=n;
+ if (op==ENDCODE) break;
+ }
+printf("\t\"%s\":%d reduced code from %d to %d\n",
+ tf->fileName->str,tf->lineDefined,(int)(p-code),(int)(q-code));
+}
+
+static void OptCode(TProtoFunc* tf)
+{
+ int nop=NoDebug(tf);
+ if (nop==0) return; /* cannot improve code */
+ FixJumps(tf);
+ PackCode(tf);
+}
+
+static void OptFunction(TProtoFunc* tf);
+
+static void OptFunctions(TProtoFunc* tf)
+{
+ int i,n=tf->nconsts;
+ for (i=0; i<n; i++)
+ {
+ TObject* o=tf->consts+i;
+ if (ttype(o)==LUA_T_PROTO) OptFunction(tfvalue(o));
+ }
+}
+
+static void OptFunction(TProtoFunc* tf)
+{
+ tf->locvars=NULL; /* remove local variables table */
+ OptConstants(tf);
+ OptCode(tf);
+ OptFunctions(tf);
+}
+
+void OptChunk(TProtoFunc* Main)
+{
+ OptFunction(Main);
+}
diff --git a/tools/luac/print.c b/tools/luac/print.c
new file mode 100644
index 000000000..c1e74b8ab
--- /dev/null
+++ b/tools/luac/print.c
@@ -0,0 +1,233 @@
+/*
+** $Id$
+** print bytecodes
+** See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "luac.h"
+
+#ifdef DEBUG
+void PrintConstant1(TProtoFunc* tf, int i)
+{
+ TObject* o=tf->consts+i;
+ printf("%6d ",i);
+ if (i<0 || i>=tf->nconsts)
+ printf("(bad constant #%d: max=%d)",i,tf->nconsts);
+ else
+ switch (ttype(o))
+ {
+ case LUA_T_NUMBER:
+ printf("N " NUMBER_FMT "\n",nvalue(o)); /* LUA_NUMBER */
+ break;
+ case LUA_T_STRING:
+ printf("S %p\t\"%s\"\n",(void*)tsvalue(o),svalue(o));
+ break;
+ case LUA_T_PROTO:
+ printf("F %p\n",(void*)tfvalue(o));
+ break;
+ default: /* cannot happen */
+ printf("? %d\n",ttype(o));
+ break;
+ }
+}
+
+static void PrintConstants(TProtoFunc* tf)
+{
+ int i,n=tf->nconsts;
+ printf("constants (%d):\n",n);
+ for (i=0; i<n; i++) PrintConstant1(tf,i);
+}
+#endif
+
+static void PrintConstant(TProtoFunc* tf, int i)
+{
+ if (i<0 || i>=tf->nconsts)
+ printf("(bad constant #%d: max=%d)",i,tf->nconsts);
+ else
+ {
+ TObject* o=tf->consts+i;
+ switch (ttype(o))
+ {
+ case LUA_T_NUMBER:
+ printf(NUMBER_FMT,nvalue(o)); /* LUA_NUMBER */
+ break;
+ case LUA_T_STRING:
+ printf("\"%s\"",svalue(o));
+ break;
+ case LUA_T_PROTO:
+ printf("function at %p",(void*)tfvalue(o));
+ break;
+ case LUA_T_NIL:
+ printf("(nil)");
+ break;
+ default: /* cannot happen */
+ printf("(bad constant #%d: type=%d [%s])\n",i,ttype(o),luaO_typename(o));
+ break;
+ }
+ }
+}
+
+#define VarStr(i) svalue(tf->consts+i)
+
+static void PrintCode(TProtoFunc* tf)
+{
+ Byte* code=tf->code;
+ Byte* p=code;
+ int line=0;
+ while (1)
+ {
+ Opcode OP;
+ int n=INFO(tf,p,&OP);
+ int op=OP.op;
+ int i=OP.arg;
+ printf("%6d ",(int)(p-code));
+ {
+ Byte* q=p;
+ int j=n;
+ while (j--) printf("%02X",*q++);
+ }
+ printf("%*s%-13s",2*(5-n),"",OP.name);
+
+ if (n!=1 || op<0) printf("\t%d",i); else if (i>=0) printf("\t");
+
+ switch (OP.op_class)
+ {
+
+ case ENDCODE:
+ printf("\n");
+ return;
+
+ case CLOSURE:
+ printf(" %d",OP.arg2);
+ case PUSHCONSTANT:
+ case GETDOTTED:
+ case PUSHSELF:
+ printf("\t; ");
+ PrintConstant(tf,i);
+ break;
+
+ case PUSHLOCAL:
+ case SETLOCAL:
+ {
+ char* s=luaF_getlocalname(tf,i+1,line);
+ if (s) printf("\t; %s",s);
+ break;
+ }
+
+ case GETGLOBAL:
+ case SETGLOBAL:
+ printf("\t; %s",VarStr(i));
+ break;
+
+ case SETLIST:
+ case CALLFUNC:
+ if (n>=3) printf(" %d",OP.arg2);
+ break;
+
+ case SETLINE:
+ printf("\t; \"%s\":%d",fileName(tf),line=i);
+ break;
+
+/* suggested by Norman Ramsey <nr at cs.virginia.edu> */
+ case IFTUPJMP:
+ case IFFUPJMP:
+ i=-i;
+ case ONTJMP:
+ case ONFJMP:
+ case JMP:
+ case IFFJMP:
+ printf("\t; to %d",(int)(p-code)+i+n);
+ break;
+
+ }
+ printf("\n");
+ p+=n;
+ }
+}
+
+static void PrintLocals(TProtoFunc* tf)
+{
+ LocVar* v=tf->locvars;
+ int n,i=0;
+ if (v==NULL || v->varname==NULL) return;
+ n=tf->code[1]; if (n>=ZEROVARARG) n-=ZEROVARARG;
+
+ printf("locals:");
+ if (n>0)
+ {
+ for (i=0; i<n; v++,i++) printf(" %s",v->varname->str);
+ }
+ if (v->varname!=NULL)
+ {
+ for (; v->line>=0; v++)
+ {
+ if (v->varname==NULL)
+ {
+ printf(")"); --i;
+ }
+ else
+ {
+ printf(" (%s",v->varname->str); i++;
+ }
+ }
+ i-=n;
+ while (i--) printf(")");
+ }
+ printf("\n");
+}
+
+static void PrintHeader(TProtoFunc* tf, TProtoFunc* Main, int at)
+{
+ int size=CodeSize(tf);
+ if (IsMain(tf))
+ printf("\nmain of \"%s\" (%d bytes at %p)\n",fileName(tf),size,(void*)tf);
+ else if (Main)
+ {
+ printf("\nfunction defined at \"%s\":%d (%d bytes at %p); used at ",
+ fileName(tf),tf->lineDefined,size,(void*)tf);
+ if (IsMain(Main))
+ printf("main");
+ else
+ printf("%p",(void*)Main);
+ printf("+%d\n",at);
+ }
+}
+
+static void PrintFunction(TProtoFunc* tf, TProtoFunc* Main, int at);
+
+static void PrintFunctions(TProtoFunc* Main)
+{
+ Byte* code=Main->code;
+ Byte* p=code;
+ while (1)
+ {
+ Opcode OP;
+ int n=INFO(Main,p,&OP);
+ if (OP.op_class==ENDCODE) break;
+ if (OP.op_class==PUSHCONSTANT || OP.op_class==CLOSURE)
+ {
+ int i=OP.arg;
+ TObject* o=Main->consts+i;
+ if (ttype(o)==LUA_T_PROTO) PrintFunction(tfvalue(o),Main,(int)(p-code));
+ }
+ p+=n;
+ }
+}
+
+static void PrintFunction(TProtoFunc* tf, TProtoFunc* Main, int at)
+{
+ PrintHeader(tf,Main,at);
+ PrintLocals(tf);
+ PrintCode(tf);
+#ifdef DEBUG
+ PrintConstants(tf);
+#endif
+ PrintFunctions(tf);
+}
+
+void PrintChunk(TProtoFunc* Main)
+{
+ PrintFunction(Main,0,0);
+}
diff --git a/tools/module.mk b/tools/module.mk
index d889ad864..047d64389 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -25,6 +25,7 @@ TOOLS := \
tools/mklab$(EXEEXT) \
tools/vima$(EXEEXT) \
tools/labcopy$(EXEEXT) \
+ tools/luac/luac$(EXEEXT) \
tools/patchex/patchex$(EXEEXT)
# below not added as it depends for ppm, bpm library
@@ -43,6 +44,8 @@ clean-tools:
-$(RM) tools/emi/*.o
-$(RM) tools/patchex/*.o
-$(RM) -r tools/patchex/.deps
+ -$(RM) -r tools/luac/*.o
+ -$(RM) -r tools/luac/.deps
#
# Build rules for the tools
@@ -53,6 +56,17 @@ tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
-L$(srcdir)/common -Ltools/lua -o $@ $< $(LDFLAGS) -llua
+#g++ -DHAVE_CONFIG_H -DUNIX -I. -I./tools/luac -I ./tools/lua -c -o tools/luac/print.o tools/luac/print.c
+
+tools/luac/luac$(EXEEXT):
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/dump.o tools/luac/dump.c
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/luac.o tools/luac/luac.c
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/opcode.o tools/luac/opcode.c
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/opt.o tools/luac/opt.c
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/print.o tools/luac/print.c
+ $(MKDIR) tools/luac/$(DEPDIR)
+ $(CXX) $(CFLAGS) tools/luac/dump.o tools/luac/luac.o tools/luac/opcode.o tools/luac/opt.o tools/luac/print.o -Wall -L$(srcdir)/tools/lua -llua -o $@ $< $(LDFLAGS)
+
tools/mat2ppm$(EXEEXT): $(srcdir)/tools/mat2ppm.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) -Wall -lppm -o $@ $< $(LDFLAGS)
Commit: 1da34cde0cdd7bb7ef15dee741f7aa3045cf113c
https://github.com/scummvm/scummvm-tools/commit/1da34cde0cdd7bb7ef15dee741f7aa3045cf113c
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-11-30T06:55:33-08:00
Commit Message:
Merge pull request #20 from YakBizzarro/luac
Add lua bytecode generator (luac)
Changed paths:
A tools/luac/dump.c
A tools/luac/luac.c
A tools/luac/opcode.c
A tools/luac/opt.c
A tools/luac/print.c
tools/module.mk
Commit: 2d83a6abdf043fd7f0fd5b8f4ac35eab592c96c2
https://github.com/scummvm/scummvm-tools/commit/2d83a6abdf043fd7f0fd5b8f4ac35eab592c96c2
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2011-12-14T17:34:25+01:00
Commit Message:
Added missing headers, fixed endianess bug and fixed string-releated warnings
Changed paths:
A tools/luac/luac.h
A tools/luac/opcode.h
tools/luac/dump.c
tools/luac/luac.c
tools/luac/opcode.c
diff --git a/tools/luac/dump.c b/tools/luac/dump.c
index 010bcf09f..0487fa146 100644
--- a/tools/luac/dump.c
+++ b/tools/luac/dump.c
@@ -7,7 +7,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "luac.h"
-#include "common/endian.h"
#define NotWord(x) ((unsigned short)x!=x)
#define DumpBlock(b,size,D) fwrite(b,size,1,D)
diff --git a/tools/luac/luac.c b/tools/luac/luac.c
index 3a7b0e974..b904b4868 100644
--- a/tools/luac/luac.c
+++ b/tools/luac/luac.c
@@ -18,8 +18,8 @@ extern void DumpChunk(TProtoFunc* Main, FILE* D);
extern void PrintChunk(TProtoFunc* Main);
extern void OptChunk(TProtoFunc* Main);
-static FILE* efopen(char* name, const char* mode);
-static void doit(int undump, char* filename);
+static FILE* efopen(const char* name, const char* mode);
+static void doit(int undump, const char* filename);
static int listing=0; /* list bytecodes? */
static int debugging=0; /* debug? */
@@ -54,7 +54,7 @@ static void usage(void)
int main(int argc, char* argv[])
{
- char* d=OUTPUT; /* output file name */
+ const char* d = OUTPUT; /* output file name */
int i;
lua_open();
for (i=1; i<argc; i++)
@@ -153,26 +153,29 @@ static void do_undump(ZIO* z)
}
}
-static void doit(int undump, char* filename)
-{
- FILE* f;
- ZIO z;
- if (filename==NULL)
- {
- f=stdin; filename="(stdin)";
- }
- else
- {
- f=efopen(filename, undump ? "rb" : "r");
- }
- zFopen(&z,f,filename);
- if (verbose) fprintf(stderr,"%s\n",filename);
- if (undump) do_undump(&z); else do_compile(&z);
- if (f!=stdin) fclose(f);
+static void doit(int undump, const char* filename) {
+ FILE* f;
+ ZIO z;
+ char *fn;
+ if (filename==NULL) {
+ fn = (char *)"(stdin)";
+ f = stdin;
+ } else {
+ fn = (char *)filename;
+ f = efopen(fn, undump ? "rb" : "r");
+ }
+ zFopen(&z,f,fn);
+ if (verbose)
+ fprintf(stderr,"%s\n",fn);
+ if (undump)
+ do_undump(&z);
+ else
+ do_compile(&z);
+ if (f != stdin)
+ fclose(f);
}
-static FILE* efopen(char* name, const char* mode)
-{
+static FILE* efopen(const char* name, const char* mode) {
FILE* f=fopen(name,mode);
if (f==NULL)
{
diff --git a/tools/luac/luac.h b/tools/luac/luac.h
new file mode 100644
index 000000000..3e7e8d9eb
--- /dev/null
+++ b/tools/luac/luac.h
@@ -0,0 +1,34 @@
+/*
+** $Id$
+** definitions for luac
+** See Copyright Notice in lua.h
+*/
+
+#include "lauxlib.h"
+#include "lfunc.h"
+#include "lobject.h"
+#include "lopcodes.h"
+#include "lstring.h"
+#include "lundump.h"
+#include "common/endian.h"
+
+typedef struct
+{
+ const char* name;
+ int size;
+ int op;
+ int op_class;
+ int arg;
+ int arg2;
+} Opcode;
+
+int OpcodeInfo(TProtoFunc* tf, Byte* p, Opcode* I, const char* xFILE, int xLINE);
+int CodeSize(TProtoFunc* tf);
+
+#define INFO(tf,p,I) OpcodeInfo(tf,p,I,__FILE__,__LINE__)
+#define fileName(tf) ( (tf->fileName)==NULL ? NULL : tf->fileName->str )
+
+#define NOP 255
+#define STACK -1
+#define ARGS -2
+#define VARARGS -3
diff --git a/tools/luac/opcode.c b/tools/luac/opcode.c
index 52ab8b7b0..aed496786 100644
--- a/tools/luac/opcode.c
+++ b/tools/luac/opcode.c
@@ -6,15 +6,14 @@
#include "luac.h"
-static Opcode Info[]= /* ORDER lopcodes.h */
+static const Opcode Info[]= /* ORDER lopcodes.h */
{
#include "opcode.h"
};
#define NOPCODES (sizeof(Info)/sizeof(Info[0]))
-int OpcodeInfo(TProtoFunc* tf, Byte* p, Opcode* I, char* xFILE, int xLINE)
-{
+int OpcodeInfo(TProtoFunc* tf, Byte* p, Opcode* I, const char* xFILE, int xLINE) {
Opcode OP;
Byte* code=tf->code;
int op=*p;
@@ -65,9 +64,9 @@ int OpcodeInfo(TProtoFunc* tf, Byte* p, Opcode* I, char* xFILE, int xLINE)
OP.arg=p[1];
OP.arg2=p[2];
}
- else if (OP.size==2) OP.arg=p[1];
- else if (OP.size>=3) OP.arg=(p[1]<<8)+p[2];
- if (op==SETLISTW) OP.arg2=p[3];
+ else if (OP.size == 2) OP.arg = p[1];
+ else if (OP.size >= 3) OP.arg = READ_LE_UINT16(p + 1);
+ if (op == SETLISTW) OP.arg2 = p[3];
}
*I=OP;
return OP.size;
diff --git a/tools/luac/opcode.h b/tools/luac/opcode.h
new file mode 100644
index 000000000..6bc608669
--- /dev/null
+++ b/tools/luac/opcode.h
@@ -0,0 +1,135 @@
+/*
+** $Id$
+** opcode info to be #included into opcode.c
+** extracted automatically from lopcodes.h by mkopcodeh
+** See Copyright Notice in lua.h
+*/
+{ "ENDCODE", 1, ENDCODE, ENDCODE, ENDCODE-ENDCODE-1, 0 },
+{ "PUSHNIL", 2, PUSHNIL, PUSHNIL, PUSHNIL-PUSHNIL-1, 0 },
+{ "PUSHNIL0", 1, PUSHNIL0, PUSHNIL, PUSHNIL0-PUSHNIL-1, 0 },
+{ "PUSHNUMBER", 2, PUSHNUMBER, PUSHNUMBER, PUSHNUMBER-PUSHNUMBER-1, 0 },
+{ "PUSHNUMBER0", 1, PUSHNUMBER0, PUSHNUMBER, PUSHNUMBER0-PUSHNUMBER-1, 0 },
+{ "PUSHNUMBER1", 1, PUSHNUMBER1, PUSHNUMBER, PUSHNUMBER1-PUSHNUMBER-1, 0 },
+{ "PUSHNUMBER2", 1, PUSHNUMBER2, PUSHNUMBER, PUSHNUMBER2-PUSHNUMBER-1, 0 },
+{ "PUSHNUMBERW", 3, PUSHNUMBERW, PUSHNUMBER, PUSHNUMBERW-PUSHNUMBER-1, 0 },
+{ "PUSHCONSTANT", 2, PUSHCONSTANT, PUSHCONSTANT, PUSHCONSTANT-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT0", 1, PUSHCONSTANT0, PUSHCONSTANT, PUSHCONSTANT0-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT1", 1, PUSHCONSTANT1, PUSHCONSTANT, PUSHCONSTANT1-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT2", 1, PUSHCONSTANT2, PUSHCONSTANT, PUSHCONSTANT2-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT3", 1, PUSHCONSTANT3, PUSHCONSTANT, PUSHCONSTANT3-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT4", 1, PUSHCONSTANT4, PUSHCONSTANT, PUSHCONSTANT4-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT5", 1, PUSHCONSTANT5, PUSHCONSTANT, PUSHCONSTANT5-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT6", 1, PUSHCONSTANT6, PUSHCONSTANT, PUSHCONSTANT6-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANT7", 1, PUSHCONSTANT7, PUSHCONSTANT, PUSHCONSTANT7-PUSHCONSTANT-1, 0 },
+{ "PUSHCONSTANTW", 3, PUSHCONSTANTW, PUSHCONSTANT, PUSHCONSTANTW-PUSHCONSTANT-1, 0 },
+{ "PUSHUPVALUE", 2, PUSHUPVALUE, PUSHUPVALUE, PUSHUPVALUE-PUSHUPVALUE-1, 0 },
+{ "PUSHUPVALUE0", 1, PUSHUPVALUE0, PUSHUPVALUE, PUSHUPVALUE0-PUSHUPVALUE-1, 0 },
+{ "PUSHUPVALUE1", 1, PUSHUPVALUE1, PUSHUPVALUE, PUSHUPVALUE1-PUSHUPVALUE-1, 0 },
+{ "PUSHLOCAL", 2, PUSHLOCAL, PUSHLOCAL, PUSHLOCAL-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL0", 1, PUSHLOCAL0, PUSHLOCAL, PUSHLOCAL0-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL1", 1, PUSHLOCAL1, PUSHLOCAL, PUSHLOCAL1-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL2", 1, PUSHLOCAL2, PUSHLOCAL, PUSHLOCAL2-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL3", 1, PUSHLOCAL3, PUSHLOCAL, PUSHLOCAL3-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL4", 1, PUSHLOCAL4, PUSHLOCAL, PUSHLOCAL4-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL5", 1, PUSHLOCAL5, PUSHLOCAL, PUSHLOCAL5-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL6", 1, PUSHLOCAL6, PUSHLOCAL, PUSHLOCAL6-PUSHLOCAL-1, 0 },
+{ "PUSHLOCAL7", 1, PUSHLOCAL7, PUSHLOCAL, PUSHLOCAL7-PUSHLOCAL-1, 0 },
+{ "GETGLOBAL", 2, GETGLOBAL, GETGLOBAL, GETGLOBAL-GETGLOBAL-1, 0 },
+{ "GETGLOBAL0", 1, GETGLOBAL0, GETGLOBAL, GETGLOBAL0-GETGLOBAL-1, 0 },
+{ "GETGLOBAL1", 1, GETGLOBAL1, GETGLOBAL, GETGLOBAL1-GETGLOBAL-1, 0 },
+{ "GETGLOBAL2", 1, GETGLOBAL2, GETGLOBAL, GETGLOBAL2-GETGLOBAL-1, 0 },
+{ "GETGLOBAL3", 1, GETGLOBAL3, GETGLOBAL, GETGLOBAL3-GETGLOBAL-1, 0 },
+{ "GETGLOBAL4", 1, GETGLOBAL4, GETGLOBAL, GETGLOBAL4-GETGLOBAL-1, 0 },
+{ "GETGLOBAL5", 1, GETGLOBAL5, GETGLOBAL, GETGLOBAL5-GETGLOBAL-1, 0 },
+{ "GETGLOBAL6", 1, GETGLOBAL6, GETGLOBAL, GETGLOBAL6-GETGLOBAL-1, 0 },
+{ "GETGLOBAL7", 1, GETGLOBAL7, GETGLOBAL, GETGLOBAL7-GETGLOBAL-1, 0 },
+{ "GETGLOBALW", 3, GETGLOBALW, GETGLOBAL, GETGLOBALW-GETGLOBAL-1, 0 },
+{ "GETTABLE", 1, GETTABLE, GETTABLE, GETTABLE-GETTABLE-1, 0 },
+{ "GETDOTTED", 2, GETDOTTED, GETDOTTED, GETDOTTED-GETDOTTED-1, 0 },
+{ "GETDOTTED0", 1, GETDOTTED0, GETDOTTED, GETDOTTED0-GETDOTTED-1, 0 },
+{ "GETDOTTED1", 1, GETDOTTED1, GETDOTTED, GETDOTTED1-GETDOTTED-1, 0 },
+{ "GETDOTTED2", 1, GETDOTTED2, GETDOTTED, GETDOTTED2-GETDOTTED-1, 0 },
+{ "GETDOTTED3", 1, GETDOTTED3, GETDOTTED, GETDOTTED3-GETDOTTED-1, 0 },
+{ "GETDOTTED4", 1, GETDOTTED4, GETDOTTED, GETDOTTED4-GETDOTTED-1, 0 },
+{ "GETDOTTED5", 1, GETDOTTED5, GETDOTTED, GETDOTTED5-GETDOTTED-1, 0 },
+{ "GETDOTTED6", 1, GETDOTTED6, GETDOTTED, GETDOTTED6-GETDOTTED-1, 0 },
+{ "GETDOTTED7", 1, GETDOTTED7, GETDOTTED, GETDOTTED7-GETDOTTED-1, 0 },
+{ "GETDOTTEDW", 3, GETDOTTEDW, GETDOTTED, GETDOTTEDW-GETDOTTED-1, 0 },
+{ "PUSHSELF", 2, PUSHSELF, PUSHSELF, PUSHSELF-PUSHSELF-1, 0 },
+{ "PUSHSELF0", 1, PUSHSELF0, PUSHSELF, PUSHSELF0-PUSHSELF-1, 0 },
+{ "PUSHSELF1", 1, PUSHSELF1, PUSHSELF, PUSHSELF1-PUSHSELF-1, 0 },
+{ "PUSHSELF2", 1, PUSHSELF2, PUSHSELF, PUSHSELF2-PUSHSELF-1, 0 },
+{ "PUSHSELF3", 1, PUSHSELF3, PUSHSELF, PUSHSELF3-PUSHSELF-1, 0 },
+{ "PUSHSELF4", 1, PUSHSELF4, PUSHSELF, PUSHSELF4-PUSHSELF-1, 0 },
+{ "PUSHSELF5", 1, PUSHSELF5, PUSHSELF, PUSHSELF5-PUSHSELF-1, 0 },
+{ "PUSHSELF6", 1, PUSHSELF6, PUSHSELF, PUSHSELF6-PUSHSELF-1, 0 },
+{ "PUSHSELF7", 1, PUSHSELF7, PUSHSELF, PUSHSELF7-PUSHSELF-1, 0 },
+{ "PUSHSELFW", 3, PUSHSELFW, PUSHSELF, PUSHSELFW-PUSHSELF-1, 0 },
+{ "CREATEARRAY", 2, CREATEARRAY, CREATEARRAY, CREATEARRAY-CREATEARRAY-1, 0 },
+{ "CREATEARRAY0", 1, CREATEARRAY0, CREATEARRAY, CREATEARRAY0-CREATEARRAY-1, 0 },
+{ "CREATEARRAY1", 1, CREATEARRAY1, CREATEARRAY, CREATEARRAY1-CREATEARRAY-1, 0 },
+{ "CREATEARRAYW", 3, CREATEARRAYW, CREATEARRAY, CREATEARRAYW-CREATEARRAY-1, 0 },
+{ "SETLOCAL", 2, SETLOCAL, SETLOCAL, SETLOCAL-SETLOCAL-1, 0 },
+{ "SETLOCAL0", 1, SETLOCAL0, SETLOCAL, SETLOCAL0-SETLOCAL-1, 0 },
+{ "SETLOCAL1", 1, SETLOCAL1, SETLOCAL, SETLOCAL1-SETLOCAL-1, 0 },
+{ "SETLOCAL2", 1, SETLOCAL2, SETLOCAL, SETLOCAL2-SETLOCAL-1, 0 },
+{ "SETLOCAL3", 1, SETLOCAL3, SETLOCAL, SETLOCAL3-SETLOCAL-1, 0 },
+{ "SETLOCAL4", 1, SETLOCAL4, SETLOCAL, SETLOCAL4-SETLOCAL-1, 0 },
+{ "SETLOCAL5", 1, SETLOCAL5, SETLOCAL, SETLOCAL5-SETLOCAL-1, 0 },
+{ "SETLOCAL6", 1, SETLOCAL6, SETLOCAL, SETLOCAL6-SETLOCAL-1, 0 },
+{ "SETLOCAL7", 1, SETLOCAL7, SETLOCAL, SETLOCAL7-SETLOCAL-1, 0 },
+{ "SETGLOBAL", 2, SETGLOBAL, SETGLOBAL, SETGLOBAL-SETGLOBAL-1, 0 },
+{ "SETGLOBAL0", 1, SETGLOBAL0, SETGLOBAL, SETGLOBAL0-SETGLOBAL-1, 0 },
+{ "SETGLOBAL1", 1, SETGLOBAL1, SETGLOBAL, SETGLOBAL1-SETGLOBAL-1, 0 },
+{ "SETGLOBAL2", 1, SETGLOBAL2, SETGLOBAL, SETGLOBAL2-SETGLOBAL-1, 0 },
+{ "SETGLOBAL3", 1, SETGLOBAL3, SETGLOBAL, SETGLOBAL3-SETGLOBAL-1, 0 },
+{ "SETGLOBAL4", 1, SETGLOBAL4, SETGLOBAL, SETGLOBAL4-SETGLOBAL-1, 0 },
+{ "SETGLOBAL5", 1, SETGLOBAL5, SETGLOBAL, SETGLOBAL5-SETGLOBAL-1, 0 },
+{ "SETGLOBAL6", 1, SETGLOBAL6, SETGLOBAL, SETGLOBAL6-SETGLOBAL-1, 0 },
+{ "SETGLOBAL7", 1, SETGLOBAL7, SETGLOBAL, SETGLOBAL7-SETGLOBAL-1, 0 },
+{ "SETGLOBALW", 3, SETGLOBALW, SETGLOBAL, SETGLOBALW-SETGLOBAL-1, 0 },
+{ "SETTABLE0", 1, SETTABLE0, SETTABLE0, SETTABLE0-SETTABLE0-1, 0 },
+{ "SETTABLE", 2, SETTABLE, SETTABLE, SETTABLE-SETTABLE-1, 0 },
+{ "SETLIST", 3, SETLIST, SETLIST, SETLIST-SETLIST-1, 0 },
+{ "SETLIST0", 2, SETLIST0, SETLIST, SETLIST0-SETLIST-1, 0 },
+{ "SETLISTW", 4, SETLISTW, SETLIST, SETLISTW-SETLIST-1, 0 },
+{ "SETMAP", 2, SETMAP, SETMAP, SETMAP-SETMAP-1, 0 },
+{ "SETMAP0", 1, SETMAP0, SETMAP, SETMAP0-SETMAP-1, 0 },
+{ "EQOP", 1, EQOP, EQOP, EQOP-EQOP-1, 0 },
+{ "NEQOP", 1, NEQOP, NEQOP, NEQOP-NEQOP-1, 0 },
+{ "LTOP", 1, LTOP, LTOP, LTOP-LTOP-1, 0 },
+{ "LEOP", 1, LEOP, LEOP, LEOP-LEOP-1, 0 },
+{ "GTOP", 1, GTOP, GTOP, GTOP-GTOP-1, 0 },
+{ "GEOP", 1, GEOP, GEOP, GEOP-GEOP-1, 0 },
+{ "ADDOP", 1, ADDOP, ADDOP, ADDOP-ADDOP-1, 0 },
+{ "SUBOP", 1, SUBOP, SUBOP, SUBOP-SUBOP-1, 0 },
+{ "MULTOP", 1, MULTOP, MULTOP, MULTOP-MULTOP-1, 0 },
+{ "DIVOP", 1, DIVOP, DIVOP, DIVOP-DIVOP-1, 0 },
+{ "POWOP", 1, POWOP, POWOP, POWOP-POWOP-1, 0 },
+{ "CONCOP", 1, CONCOP, CONCOP, CONCOP-CONCOP-1, 0 },
+{ "MINUSOP", 1, MINUSOP, MINUSOP, MINUSOP-MINUSOP-1, 0 },
+{ "NOTOP", 1, NOTOP, NOTOP, NOTOP-NOTOP-1, 0 },
+{ "ONTJMP", 2, ONTJMP, ONTJMP, ONTJMP-ONTJMP-1, 0 },
+{ "ONTJMPW", 3, ONTJMPW, ONTJMP, ONTJMPW-ONTJMP-1, 0 },
+{ "ONFJMP", 2, ONFJMP, ONFJMP, ONFJMP-ONFJMP-1, 0 },
+{ "ONFJMPW", 3, ONFJMPW, ONFJMP, ONFJMPW-ONFJMP-1, 0 },
+{ "JMP", 2, JMP, JMP, JMP-JMP-1, 0 },
+{ "JMPW", 3, JMPW, JMP, JMPW-JMP-1, 0 },
+{ "IFFJMP", 2, IFFJMP, IFFJMP, IFFJMP-IFFJMP-1, 0 },
+{ "IFFJMPW", 3, IFFJMPW, IFFJMP, IFFJMPW-IFFJMP-1, 0 },
+{ "IFTUPJMP", 2, IFTUPJMP, IFTUPJMP, IFTUPJMP-IFTUPJMP-1, 0 },
+{ "IFTUPJMPW", 3, IFTUPJMPW, IFTUPJMP, IFTUPJMPW-IFTUPJMP-1, 0 },
+{ "IFFUPJMP", 2, IFFUPJMP, IFFUPJMP, IFFUPJMP-IFFUPJMP-1, 0 },
+{ "IFFUPJMPW", 3, IFFUPJMPW, IFFUPJMP, IFFUPJMPW-IFFUPJMP-1, 0 },
+{ "CLOSURE", 3, CLOSURE, CLOSURE, CLOSURE-CLOSURE-1, 0 },
+{ "CLOSURE0", 2, CLOSURE0, CLOSURE, CLOSURE0-CLOSURE-1, 0 },
+{ "CLOSURE1", 2, CLOSURE1, CLOSURE, CLOSURE1-CLOSURE-1, 0 },
+{ "CALLFUNC", 3, CALLFUNC, CALLFUNC, CALLFUNC-CALLFUNC-1, 0 },
+{ "CALLFUNC0", 2, CALLFUNC0, CALLFUNC, CALLFUNC0-CALLFUNC-1, 0 },
+{ "CALLFUNC1", 2, CALLFUNC1, CALLFUNC, CALLFUNC1-CALLFUNC-1, 0 },
+{ "RETCODE", 2, RETCODE, RETCODE, RETCODE-RETCODE-1, 0 },
+{ "SETLINE", 2, SETLINE, SETLINE, SETLINE-SETLINE-1, 0 },
+{ "SETLINEW", 3, SETLINEW, SETLINE, SETLINEW-SETLINE-1, 0 },
+{ "POP", 2, POP, POP, POP-POP-1, 0 },
+{ "POP0", 1, POP0, POP, POP0-POP-1, 0 },
+{ "POP1", 1, POP1, POP, POP1-POP-1, 0 },
Commit: 42c30cf73bdca802e0ec07e0df8ecda0a3aa6e06
https://github.com/scummvm/scummvm-tools/commit/42c30cf73bdca802e0ec07e0df8ecda0a3aa6e06
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2011-12-14T09:00:10-08:00
Commit Message:
Merge pull request #21 from YakBizzarro/luac
Fixs for luac
Changed paths:
A tools/luac/luac.h
A tools/luac/opcode.h
tools/luac/dump.c
tools/luac/luac.c
tools/luac/opcode.c
Commit: ed3785a76bb7e23cb435ecc4e9f70f246abbb453
https://github.com/scummvm/scummvm-tools/commit/ed3785a76bb7e23cb435ecc4e9f70f246abbb453
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2012-01-06T11:55:13+01:00
Commit Message:
rename to ResidualVM
Changed paths:
A tools/lua/README.residualvm
R tools/lua/README.residual
AUTHORS
COPYING.LGPL
COPYRIGHT
Makefile
Makefile.common
common/endian.h
common/scummsys.h
configure
ports.mk
rules.mk
tools/bmtoppm.cpp
tools/delua.cpp
tools/emi/animb2txt.cpp
tools/emi/cosb2cos.cpp
tools/emi/filetools.h
tools/emi/lab.cpp
tools/emi/lab.h
tools/emi/meshb2obj.cpp
tools/emi/model.h
tools/emi/renderModel.cpp
tools/emi/til2bmp.cpp
tools/imc2wav.cpp
tools/int2flt.cpp
tools/mat2ppm.cpp
tools/module.mk
tools/patchex/cab.h
tools/patchex/cabd.cpp
tools/patchex/mspack.h
tools/patchex/mszip.h
tools/patchex/mszipd.cpp
tools/patchex/patchex.cpp
tools/set2fig.cpp
tools/unlab.cpp
tools/vima.cpp
diff --git a/AUTHORS b/AUTHORS
index b251e386d..8f56cf182 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,4 +1,4 @@
-Residual Team
+ResidualVM Team
*************
Project Leader
--------------
@@ -34,7 +34,7 @@ Residual Team
ScummVM code
************
- Residual use a lot of ScummVM code. For list of authors look into
+ ResidualVM use a lot of ScummVM code. For list of authors look into
COPYRIGHT file.
Website code
diff --git a/COPYING.LGPL b/COPYING.LGPL
index 6178d5217..b485d85f0 100644
--- a/COPYING.LGPL
+++ b/COPYING.LGPL
@@ -1,4 +1,4 @@
-NOTE: Only certain parts of the Residual project are under the GNU LGPL.
+NOTE: Only certain parts of the ResidualVM project are under the GNU LGPL.
The majority of the files are under the GNU GPL. See the headers of the
individual files to find out the exact license.
diff --git a/COPYRIGHT b/COPYRIGHT
index 69247ad7e..f66175104 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1,5 +1,5 @@
-Residual
-Copyright (C) 2003-2011 by the following:
+ResidualVM
+Copyright (C) 2003-2012 by the following:
If you have contributed to this project then you deserve to be on this
list. Contact us (see: AUTHORS) and we'll add you.
diff --git a/Makefile b/Makefile
index 9af412932..c88e6951a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,3 @@
-# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/Makefile $
-# $Id: Makefile 1595 2009-10-05 08:50:25Z aquadran $
#######################################################################
# Default compilation parameters. Normally don't edit these #
@@ -61,7 +59,7 @@ ZIP ?= zip -q
# Misc stuff - you should never have to edit this #
#######################################################################
-EXECUTABLE := residual$(EXEEXT)
+EXECUTABLE := residualvm$(EXEEXT)
include $(srcdir)/Makefile.common
diff --git a/Makefile.common b/Makefile.common
index fb16b7b79..f1fc5176e 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -1,11 +1,9 @@
# This file is used by Makefile and declares common build rules,
# a list of common object files etc.
#
-# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/Makefile.common $
-# $Id: Makefile.common 1635 2010-01-21 19:25:03Z aquadran $
######################################################################
-# The default build target: just build the residual executable
+# The default build target: just build the residualvm executable
######################################################################
all: build
@@ -124,7 +122,7 @@ endif
# Distribution settings
######################################################################
-DISTNAME := residual-tools
+DISTNAME := residualvm-tools
DISTDIR := dist
$(DISTDIR)/$(DISTNAME).tar.gz: $(VERFILE)
diff --git a/common/endian.h b/common/endian.h
index 87e279ac4..88ba9e3e7 100644
--- a/common/endian.h
+++ b/common/endian.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
#ifndef COMMON_ENDIAN_H
diff --git a/common/scummsys.h b/common/scummsys.h
index aa074bfa7..73ccf9e97 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -18,9 +18,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * $URL$
- * $Id$
- *
*/
#ifndef COMMON_SCUMMSYS_H
diff --git a/configure b/configure
index 1159cb94e..a3de08e68 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# configure -- custom configure script for Residual.
+# configure -- custom configure script for ResidualVM.
#
# Residual is the legal property of its developers, whose names
# are too numerous to list here. Please refer to the AUTHORS
@@ -20,8 +20,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/configure $
-# $Id: configure 1650 2010-01-24 08:26:36Z aquadran $
# Save the current environment variables for next runs
SAVED_CONFIGFLAGS=$@
@@ -85,8 +83,8 @@ _strip=strip
_ar="ar cru"
_as="as"
_windres=windres
-_win32path="C:/residual-tools"
-_aos4path="Games:Residual-tools"
+_win32path="C:/residualvm-tools"
+_aos4path="Games:ResidualVM-tools"
_staticlibpath=/sw
_prefix=/usr/local
# For cross compiling
@@ -101,9 +99,9 @@ _port_mk="ports.mk"
# Determine a tmp file name, using mktemp(1) when available.
if type mktemp > /dev/null 2>&1 ; then
- TMPO=`mktemp /tmp/residual-conf.XXXXXXXXXX`
+ TMPO=`mktemp /tmp/residualvm-conf.XXXXXXXXXX`
else
- TMPO=./residual-conf
+ TMPO=./residualvm-conf
fi
TMPC=${TMPO}.cpp
TMPLOG=config.log
@@ -245,8 +243,8 @@ Configuration:
-h, --help display this help and exit
Installation directories:
- --prefix=DIR use this prefix for installing Residual [/usr/local]
- --bindir=DIR directory to install the residual binary in [PREFIX/bin]
+ --prefix=DIR use this prefix for installing ResidualVM [/usr/local]
+ --bindir=DIR directory to install the residualvm binary in [PREFIX/bin]
--mandir=DIR directory to install the manpage in [PREFIX/share/man]
--datadir=DIR directory to install the data files in [PREFIX/share]
--libdir=DIR directory to install the plugins in [PREFIX/lib]
@@ -749,7 +747,7 @@ case $_host_os in
LIBS="$LIBS -lmingw32 -lwinmm"
;;
cygwin*)
- echo ERROR: Cygwin building is not supported by ScummVM anymore. Consider using MinGW.
+ echo ERROR: Cygwin building is not supported by ResidualVM anymore. Consider using MinGW.
exit 1
;;
os2-emx*)
diff --git a/ports.mk b/ports.mk
index b22534118..c3e151c73 100644
--- a/ports.mk
+++ b/ports.mk
@@ -1,9 +1,6 @@
# This file contains port specific Makefile rules. It is automatically
# included by the default (main) Makefile.
#
-# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/ports.mk $
-# $Id: ports.mk 1635 2010-01-21 19:25:03Z aquadran $
-
#
# UNIX specific
@@ -11,16 +8,16 @@
install: all
$(INSTALL) -d "$(DESTDIR)$(BINDIR)"
$(INSTALL) -c -s -m 755 "./$(EXECUTABLE)" "$(DESTDIR)$(BINDIR)/$(EXECUTABLE)"
- $(INSTALL) -d "$(DESTDIR)$(PREFIX)/share/doc/residual-tools/"
- $(INSTALL) -c -m 644 $(DIST_FILES_DOCS) "$(DESTDIR)$(PREFIX)/share/doc/residual-tools/"
- $(INSTALL) -d "$(DESTDIR)$(DATADIR)/residual-tools/"
- $(INSTALL) -c -m 644 $(DIST_FILES_THEMES) "$(DESTDIR)$(DATADIR)/residual-tools/"
- #$(INSTALL) -c -m 644 $(DIST_FILES_ENGINEDATA) "$(DESTDIR)$(DATADIR)/residual-tools/"
+ $(INSTALL) -d "$(DESTDIR)$(PREFIX)/share/doc/residualvm-tools/"
+ $(INSTALL) -c -m 644 $(DIST_FILES_DOCS) "$(DESTDIR)$(PREFIX)/share/doc/residualvm-tools/"
+ $(INSTALL) -d "$(DESTDIR)$(DATADIR)/residualvm-tools/"
+ $(INSTALL) -c -m 644 $(DIST_FILES_THEMES) "$(DESTDIR)$(DATADIR)/residualvm-tools/"
+ #$(INSTALL) -c -m 644 $(DIST_FILES_ENGINEDATA) "$(DESTDIR)$(DATADIR)/residualvm-tools/"
uninstall:
rm -f "$(DESTDIR)$(BINDIR)/$(EXECUTABLE)"
- rm -rf "$(DESTDIR)$(PREFIX)/share/doc/residual-tools/"
- rm -rf "$(DESTDIR)$(DATADIR)/residual-tools/"
+ rm -rf "$(DESTDIR)$(PREFIX)/share/doc/residualvm-tools/"
+ rm -rf "$(DESTDIR)$(DATADIR)/residualvm-tools/"
#
diff --git a/rules.mk b/rules.mk
index f8dfdd973..6223c323c 100644
--- a/rules.mk
+++ b/rules.mk
@@ -1,8 +1,5 @@
###############################################
# Common build rules, used by the sub modules and their module.mk files
-#
-# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/rules.mk $
-# $Id: rules.mk 1566 2009-08-22 18:06:11Z salty-horse $
###############################################
diff --git a/tools/bmtoppm.cpp b/tools/bmtoppm.cpp
index 725664098..45025fe3a 100644
--- a/tools/bmtoppm.cpp
+++ b/tools/bmtoppm.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/bmtoppm.cpp $
-* $Id: bmtoppm.cpp 1375 2009-05-27 07:35:32Z aquadran $
-*
*/
#include <stdio.h>
diff --git a/tools/delua.cpp b/tools/delua.cpp
index ab58972ce..ace200e78 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -18,9 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL$
- * $Id$
- *
*/
#include <tools/lua/lua.h>
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index cfefd6764..aa5284de2 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
// Based on Benjamin Haischs filetype-information.
diff --git a/tools/emi/cosb2cos.cpp b/tools/emi/cosb2cos.cpp
index ac32c86ec..ad5bdf130 100644
--- a/tools/emi/cosb2cos.cpp
+++ b/tools/emi/cosb2cos.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
#include <fstream>
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index 3f4990873..89576e7e7 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
#ifndef FILETOOLS_H
diff --git a/tools/emi/lab.cpp b/tools/emi/lab.cpp
index 5bb0cbbd1..5eca05834 100644
--- a/tools/emi/lab.cpp
+++ b/tools/emi/lab.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL:
- * $Id:
- *
*/
#include <cstring>
diff --git a/tools/emi/lab.h b/tools/emi/lab.h
index 4fb8541e4..4bbc4cc98 100644
--- a/tools/emi/lab.h
+++ b/tools/emi/lab.h
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
#ifndef LAB_H
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index 646cbea50..32852e7ca 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
#include <fstream>
diff --git a/tools/emi/model.h b/tools/emi/model.h
index c8f965189..82502f104 100644
--- a/tools/emi/model.h
+++ b/tools/emi/model.h
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
#ifndef MODEL_H
diff --git a/tools/emi/renderModel.cpp b/tools/emi/renderModel.cpp
index 918a820f5..7fa13fef3 100644
--- a/tools/emi/renderModel.cpp
+++ b/tools/emi/renderModel.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
#include <iostream>
diff --git a/tools/emi/til2bmp.cpp b/tools/emi/til2bmp.cpp
index f6c6dee08..07fa6a5ff 100644
--- a/tools/emi/til2bmp.cpp
+++ b/tools/emi/til2bmp.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL:
-* $Id:
-*
*/
#include <fstream>
diff --git a/tools/imc2wav.cpp b/tools/imc2wav.cpp
index 8b837749b..f3e6348d1 100644
--- a/tools/imc2wav.cpp
+++ b/tools/imc2wav.cpp
@@ -18,9 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/imc2wav.cpp $
- * $Id: imc2wav.cpp 1375 2009-05-27 07:35:32Z aquadran $
- *
*/
#include <cstdio>
diff --git a/tools/int2flt.cpp b/tools/int2flt.cpp
index 4dbbfe219..220ba85b1 100644
--- a/tools/int2flt.cpp
+++ b/tools/int2flt.cpp
@@ -18,9 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/int2flt.cpp $
- * $Id: int2flt.cpp 1359 2009-05-26 14:04:08Z aquadran $
- *
*/
#include <stdio.h>
diff --git a/tools/lua/README.residual b/tools/lua/README.residualvm
similarity index 98%
rename from tools/lua/README.residual
rename to tools/lua/README.residualvm
index 0fd760a66..3e4362910 100644
--- a/tools/lua/README.residual
+++ b/tools/lua/README.residualvm
@@ -1,4 +1,4 @@
-This is a modified version of Lua 3.1 intended for use with Residual.
+This is a modified version of Lua 3.1 intended for use with ResidualVM.
The major changes made from the original version of Lua 3.1 are:
* Changed the binary file loader to read the file format from Lua 3.1alpha2.
diff --git a/tools/mat2ppm.cpp b/tools/mat2ppm.cpp
index 16206c272..037b8fea2 100644
--- a/tools/mat2ppm.cpp
+++ b/tools/mat2ppm.cpp
@@ -18,9 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/mat2ppm.cpp $
-* $Id: mat2ppm.cpp 1375 2009-05-27 07:35:32Z aquadran $
-*
*/
#include <stdio.h>
diff --git a/tools/module.mk b/tools/module.mk
index 047d64389..0a685615b 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -1,5 +1,3 @@
-# $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/module.mk $
-# $Id: module.mk 1426 2009-05-31 08:59:56Z aquadran $
MODULE := tools
diff --git a/tools/patchex/cab.h b/tools/patchex/cab.h
index 7fb0ab931..7924a8d98 100644
--- a/tools/patchex/cab.h
+++ b/tools/patchex/cab.h
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL $
- * $Id $
- *
*/
/* This file is part of libmspack.
diff --git a/tools/patchex/cabd.cpp b/tools/patchex/cabd.cpp
index 55ad226c8..7fe8d2c16 100644
--- a/tools/patchex/cabd.cpp
+++ b/tools/patchex/cabd.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/patchex/cabd.cpp $
- * $Id: cabd.cpp 1475 2009-06-18 14:12:27Z aquadran $
- *
*/
/* This file is part of libmspack.
diff --git a/tools/patchex/mspack.h b/tools/patchex/mspack.h
index af84a67b1..21d35a865 100644
--- a/tools/patchex/mspack.h
+++ b/tools/patchex/mspack.h
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/patchex/mspack.h $
- * $Id: mspack.h 1359 2009-05-26 14:04:08Z aquadran $
- *
*/
/* libmspack -- a library for working with Microsoft compression formats.
diff --git a/tools/patchex/mszip.h b/tools/patchex/mszip.h
index a48c85cea..a78536199 100644
--- a/tools/patchex/mszip.h
+++ b/tools/patchex/mszip.h
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/patchex/mszip.h $
- * $Id: mszip.h 1475 2009-06-18 14:12:27Z aquadran $
- *
*/
/* This file is part of libmspack.
diff --git a/tools/patchex/mszipd.cpp b/tools/patchex/mszipd.cpp
index c218d48fc..307605e09 100644
--- a/tools/patchex/mszipd.cpp
+++ b/tools/patchex/mszipd.cpp
@@ -13,9 +13,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/patchex/mszipd.cpp $
- * $Id: mszipd.cpp 1475 2009-06-18 14:12:27Z aquadran $
- *
*/
/* This file is part of libmspack.
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index 16de3eff2..1dbb72dbb 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -13,15 +13,12 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/patchex/patchex.cpp $
- * $Id: patchex.cpp 1475 2009-06-18 14:12:27Z aquadran $
- *
*/
/* Patch extractor
* (C) 2008 Andrea Corna
*
- * This source code is adopted and striped for Residual project.
+ * This source code is adopted and striped for ResidualVM project.
*
* res_system functions are taken from system.c written by Stuart Caie
* from libmspack (http://www.cabextract.org.uk/libmspack/).
@@ -254,7 +251,7 @@ char *file_filter(const struct mscabd_file *file) {
filename_size = strlen(file->filename);
/*Skip executables and libraries
- * These files are useless for Residual and a proper extraction of these
+ * These files are useless for ResidualVM and a proper extraction of these
* requires sub-folder support, so it isn't implemented. */
char *ext = file->filename + (filename_size - 3);
if (strcasecmp(ext, "exe") == 0 ||
diff --git a/tools/set2fig.cpp b/tools/set2fig.cpp
index 9274dc19b..29cfd46bc 100644
--- a/tools/set2fig.cpp
+++ b/tools/set2fig.cpp
@@ -18,9 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
-* $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/set2fig.cpp $
-* $Id: set2fig.cpp 1375 2009-05-27 07:35:32Z aquadran $
-*
*/
// Utility to dump drawing of the sectors in a set file to an xfig file
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index e45c453a4..f5ff32932 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -18,9 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/unlab.cpp $
- * $Id: unlab.cpp 1374 2009-05-27 07:20:49Z aquadran $
- *
*/
#include <stdlib.h>
diff --git a/tools/vima.cpp b/tools/vima.cpp
index 5c51778b6..eedba5ddc 100644
--- a/tools/vima.cpp
+++ b/tools/vima.cpp
@@ -18,9 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
- * $URL: https://residual.svn.sourceforge.net/svnroot/residual/residual/trunk/tools/vima.cpp $
- * $Id: vima.cpp 1359 2009-05-26 14:04:08Z aquadran $
- *
*/
#include <stdint.h>
Commit: 849f793bd2fd55fcb791a257f907278f221fad95
https://github.com/scummvm/scummvm-tools/commit/849f793bd2fd55fcb791a257f907278f221fad95
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2012-01-06T12:30:01+01:00
Commit Message:
sync with main credits
Changed paths:
AUTHORS
COPYRIGHT
diff --git a/AUTHORS b/AUTHORS
index 8f56cf182..846e863c8 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,7 +9,9 @@ ResidualVM Team
Grim:
James Brown - Core developer (retired)
Giulio Camuffo - Core developer
- Pawel Kolodziejski - Core developer
+ Pawel Kolodziejski - Core developer (suspended)
+ Einar Johan T. Somaae - Initial EMI support, various code fixes and
+ improvements
Grim Contributors:
If you have contributed to this engine then you deserve to be on this
@@ -17,24 +19,40 @@ ResidualVM Team
Torbjorn Andersson - Various code fixes
Ori Avtalion - Lipsync, LAF support, various code fixes
+ Robert Biro - Fixes to antiliasing
+ Bastien Bouclet - Various fixes to engine
Marcus Comstedt - Initial Dreamcast port
- Andrea Corna - Improved font support, patch extractor
+ Andrea Corna - Improved font support, patch extractor, few
+ code improvements
Jonathan Gray - Various code fixes
- Vincent Hamm - Various engine code
- Erich Hoover - x86-64 fixes, various fixes and comments, menu
- support, improved state support
+ Vincent Hamm - Various engine code fixes and improvements
+ Sven Hesse - Various compilation fixes
+ Matthew Hoops - Some engine improvements, some work on EMI
+ support
+ Erich Hoover - x86-64 fixes, various code fixes and
+ improvements
+ Max Horn - Minor code fixes
Travis Howell - Various code fixes, Windows port
+ Filippos Karapetis - Compilation fixes
Joost Peters - Various code fixes
+ George Macon - Compilation fixes
+ Josh Matthews - Few fixes to engine
+ Matthieu Milan - Few code improvements
Christian Neumair - Various optimisation patches
+ Vincent Pelletier - Various engine improvementts and code fixes
Daniel Schepler - Initial engine codebase, LUA support
- Einar Johan T. Somaen - A lot of play-testing
Yaron Tausky - Fixes to subtitles
+ Joel Teichroeb - Initial EMI support, various code fixes and
+ improvements
+ Julien Templier - create_project tool
Pino Toscano - Debian GNU/Linux package files
Lionel Ulmer - OpenGL optimisations
+ Joni Vahamaki - A lot engine improvements and fixes
+ JenniBee - Compilation fixes
ScummVM code
************
- ResidualVM use a lot of ScummVM code. For list of authors look into
+ Residual use a lot of ScummVM code. For a list of authors look into
COPYRIGHT file.
Website code
diff --git a/COPYRIGHT b/COPYRIGHT
index f66175104..4e57d9ff3 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -6,26 +6,38 @@ list. Contact us (see: AUTHORS) and we'll add you.
Torbjorn Andersson
Ori Avtalion
+Robert Biro
+Bastien Bouclet
James Brown
Giulio Camuffo
Marcus Comstedt
Andrea Corna
Jonathan Gray
Vincent Hamm
+Sven Hesse
+Matthew Hoops
Erich Hoover
+Max Horn
Travis Howell
+Filippos Karapetis
Pawel Kolodziejski
Joost Peters
+George Macon
+Matthieu Milan
Christian Neumair
+Vincent Pelletier
Daniel Schepler
Yaron Tausky
+Joel Teichroeb
+Julien Templier
Pino Toscano
Lionel Ulmer
-
+Joni Vahamaki
+JenniBee
ScummVM
-Copyright (C) 2001-2011 by the following:
+Copyright (C) 2001-2012 by the following:
If you have contributed to this project then you deserve to be on this
list. Contact us (see: AUTHORS) and we'll add you.
@@ -66,10 +78,10 @@ Travis Howell
Janne Huttunen
Felix Jakschitsch
Jeroen Janssen
-Willem Jan Palenstijn
Florian Kagerer
Filippos Karapetis
Andreas Karlsson
+Ismail Khatib
Oliver Kiehl
Martin Kiewitz
Pawel Kolodziejski
@@ -84,6 +96,7 @@ Gregory Montoir
Kostas Nakos
Mikesch Nepomuk
Nicolas Noble
+Willem Jan Palenstijn
Lars Persson
Joost Peters
Tim Phillips
@@ -238,4 +251,3 @@ Xanathar "xanathar"
Grant Yeager "glo_kidd"
Benjamin W. Zale "junior_aepi"
Yotam Barnoy "bluddy"
-
Commit: 9cf3335afc36f3c3ce52677d80cd69dc46c43761
https://github.com/scummvm/scummvm-tools/commit/9cf3335afc36f3c3ce52677d80cd69dc46c43761
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-01-07T11:51:48+01:00
Commit Message:
DELUA: Parse correctly NOP opcode and fix a crash with EMI scripts
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index ace200e78..8000b1958 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -37,6 +37,8 @@
#include <list>
#include <set>
+#define NOP 255
+
// Provide debug.cpp functions which don't call SDL_Quit.
void warning(const char *fmt, ...) {
fprintf(stderr, "WARNING: ");
@@ -63,23 +65,20 @@ void decompile(std::ostream &os, TProtoFunc *tf, std::string indent_str,
Expression **upvals, int num_upvals);
std::string localname(TProtoFunc *tf, int n) {
- LocVar *l = tf->locvars;
- if (l != NULL)
- for (int i = 0; i < n; i++, l++)
- if (l->varname == NULL) {
- l = NULL;
- break;
- }
- if (l != NULL)
- return l->varname->str;
- else {
- std::ostringstream s;
- if (n < tf->code[1])
- s << "arg" << n + 1;
- else
- s << "local" << n - tf->code[1] + 1;
- return s.str();
- }
+ LocVar *l = tf->locvars;
+
+ if (l != NULL) {
+ for (int i = 0; i < n && l->line != -1; ++i, ++l);
+
+ if (l->varname != NULL)
+ return l->varname->str;
+ }
+ std::ostringstream s;
+ if (n < tf->code[1])
+ s << "arg" << n + 1;
+ else
+ s << "local" << n - tf->code[1] + 1;
+ return s.str();
}
class Expression {
@@ -538,6 +537,13 @@ int instr_lens[] = {
1, 1 // POP0,1
};
+int get_instr_len(Byte opc) {
+ if (opc == NOP)
+ return 1;
+ else
+ return instr_lens[opc];
+}
+
bool Decompiler::is_expr_opc(Byte opc) {
if (opc >= PUSHNIL && opc <= CREATEARRAYW)
return true;
@@ -560,7 +566,7 @@ void Decompiler::get_else_part(Byte *start, Byte *&if_part_end,
else_part_end = NULL;
for (Byte *instr_scan = start; instr_scan < if_part_end;
- instr_scan += instr_lens[*instr_scan])
+ instr_scan += get_instr_len(*instr_scan))
last_instr = instr_scan;
if (last_instr != NULL &&
(*last_instr == JMP || *last_instr == JMPW)) {
@@ -580,7 +586,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
std::map<Byte *, Byte *> rev_iffupjmp_map;
for (Byte *scan = start; end == NULL || scan < end;
- scan += instr_lens[*scan]) {
+ scan += get_instr_len(*scan)) {
if (*scan == IFFUPJMP)
rev_iffupjmp_map[scan + 2 - scan[1]] = scan;
else if (*scan == IFFUPJMPW)
@@ -627,7 +633,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
Decompiler indented_dc = *this;
indented_dc.indent_str += std::string(4, ' ');
indented_dc.break_pos = rev_iffupjmp_map[start];
- indented_dc.break_pos += instr_lens[*indented_dc.break_pos];
+ indented_dc.break_pos += get_instr_len(*indented_dc.break_pos);
indented_dc.decompileRange(start, rev_iffupjmp_map[start]);
Expression *e = stk->top(); stk->pop();
@@ -1023,7 +1029,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
// otherwise, must be the start of a while statement
Byte *while_cond_end;
for (while_cond_end = dest; end == NULL || while_cond_end < end;
- while_cond_end += instr_lens[*while_cond_end])
+ while_cond_end += get_instr_len(*while_cond_end))
if (*while_cond_end == IFTUPJMP || *while_cond_end == IFTUPJMPW)
break;
if (end != NULL && while_cond_end >= end) {
@@ -1042,7 +1048,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
// decompile the while body
Decompiler indented_dc = *this;
indented_dc.indent_str += std::string(4, ' ');
- indented_dc.break_pos = while_cond_end + instr_lens[*while_cond_end];
+ indented_dc.break_pos = while_cond_end + get_instr_len(*while_cond_end);
indented_dc.decompileRange(start, dest);
*os << indent_str << "end\n";
@@ -1084,7 +1090,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
Byte *instr_scan = start;
while (is_expr_opc(*instr_scan) &&
(end == NULL || instr_scan < else_part_end))
- instr_scan += instr_lens[*instr_scan];
+ instr_scan += get_instr_len(*instr_scan);
if ((end == NULL || instr_scan < else_part_end) &&
(*instr_scan == IFFJMP || *instr_scan == IFFJMPW)) {
// OK, first line will be if, check if it will go all
@@ -1226,6 +1232,8 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
delete stk->top(); stk->pop();
}
break;
+ case NOP:
+ break;
default:
*os << indent_str << "error: unrecognized opcode "
Commit: c38acc9209db0ac9090d566c2df70cf76bcfd3d7
https://github.com/scummvm/scummvm-tools/commit/c38acc9209db0ac9090d566c2df70cf76bcfd3d7
Author: Einar Johan Trøan Sømåen (einarjohan at somadalen.com)
Date: 2012-01-07T04:30:12-08:00
Commit Message:
Merge pull request #22 from YakBizzarro/delua-fix
DELUA: Parse correctly NOP opcode and fix a crash with EMI scripts
Changed paths:
tools/delua.cpp
Commit: 0b6f79dc6001f316456ffdc176588b730d0a06c2
https://github.com/scummvm/scummvm-tools/commit/0b6f79dc6001f316456ffdc176588b730d0a06c2
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2012-02-21T17:49:53-08:00
Commit Message:
MKLAB: Add support for subdirectories and fix the version number for EMI
Changed paths:
tools/mklab.cpp
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index ae28cf1d8..8d96c2c4d 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -89,6 +89,76 @@ void help() {
exit(0);
}
+static char *appendPath(const char *name, const char *dir) {
+ int namelen = strlen(name);
+ int dirlen = strlen(dir);
+ char *path = (char *)malloc(namelen + dirlen + 2);
+ strcpy(path, dir);
+ path[dirlen] = '/';
+ strcpy(path + dirlen + 1, name);
+ return path;
+}
+
+static void countFiles(lab_header *head, DIR *dir, const char *dirname, int additionalLen) {
+ struct dirent *dirfile;
+ while ((dirfile = readdir(dir))) {
+ if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
+ continue;
+
+ if (dirfile->d_type == S_IFDIR) {
+ char *d = appendPath(dirfile->d_name, dirname);
+ DIR *subdir = opendir(d);
+ countFiles(head, subdir, d, additionalLen + strlen(dirfile->d_name) + 1);
+ free(d);
+ closedir(subdir);
+ } else {
+ ++head->num_entries;
+ head->string_table_size += strlen(dirfile->d_name) + 1 + additionalLen;
+ }
+ }
+}
+
+static void createEntries(DIR *dir, lab_entry *entries, char *str_table, const char *dirname, uint32_t &offset) {
+ static uint32_t num_entry = 0;
+ static uint32_t name_offset = 0;
+ static char *str_offset = str_table;
+ struct dirent *dirfile;
+ while ((dirfile = readdir(dir))) {
+ if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
+ continue;
+
+ if (dirfile->d_type == S_IFDIR) {
+ char *d = appendPath(dirfile->d_name, dirname);
+ DIR *subdir = opendir(d);
+ createEntries(subdir, entries, str_table, d, offset);
+ free(d);
+ closedir(subdir);
+ } else {
+ lab_entry &entry = entries[num_entry++];
+
+ WRITE_LE_UINT32(&entry.fname_offset, name_offset);
+ WRITE_LE_UINT32(&entry.start, offset);
+ entry.reserved = 0; //What is this??
+
+ char *path = appendPath(dirfile->d_name, dirname);
+ char *name = strchr(path, '/') + 1;
+ strcpy(str_offset, name);
+ str_offset[strlen(name)] = 0;
+ name_offset += strlen(name) + 1;
+ str_offset = str_table + name_offset;
+
+ struct stat st;
+ stat(path, &st);
+
+ // printf("entry of file %s, at offset %d and of size %d\n", path, offset, st.st_size);
+ free(path);
+
+ offset += st.st_size;
+ WRITE_LE_UINT32(&entry.size, st.st_size);
+ }
+ }
+}
+
int main(int argc, char **argv) {
if (argc > 1 && !strcmp(argv[1], "--help")) {
help();
@@ -113,24 +183,19 @@ int main(int argc, char **argv) {
exit(1);
}
- lab_header head;
-
DIR *dir = opendir(dirname);
if (dir == 0) {
- printf("Can not open source dir: %s\n", argv[1]);
+ printf("Can not open source dir: %s\n", dirname);
exit(2);
}
+ lab_header head;
+
head.num_entries = 0;
head.string_table_size = 0;
- struct dirent *dirfile;
- while ((dirfile = readdir(dir))) {
- if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
- continue;
- ++head.num_entries;
- head.string_table_size += strlen(dirfile->d_name) + 1;
- }
+ countFiles(&head, dir, dirname, 0);
+
// printf("%d files, string table of size %d\n", head.num_entries, head.string_table_size);
lab_entry *entries = (lab_entry *)malloc(head.num_entries * sizeof(lab_entry));
@@ -140,52 +205,27 @@ int main(int argc, char **argv) {
exit(3);
}
- uint32_t offset = 16 + head.num_entries * sizeof(lab_entry) + head.string_table_size + 16;
- uint32_t num_entry = 0;
- uint32_t name_offset = 0;
- char *str_offset = str_table;
rewinddir(dir);
- while ((dirfile = readdir(dir))) {
- if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
- continue;
-
- lab_entry &entry = entries[num_entry++];
-
- WRITE_LE_UINT32(&entry.fname_offset, name_offset);
- WRITE_LE_UINT32(&entry.start, offset);
- entry.reserved = 0; //What is this??
-
- strcpy(str_offset, dirfile->d_name);
- str_offset[strlen(dirfile->d_name)] = 0;
- name_offset += strlen(dirfile->d_name) + 1;
- str_offset = str_table + name_offset;
-
- char *path = (char *)malloc(strlen(dirfile->d_name) + strlen(dirname) + 2);
- strcpy(path, dirname);
- path[strlen(dirname)] = '/';
- strcpy(path + strlen(dirname) + 1, dirfile->d_name);
-
- struct stat st;
- stat(path, &st);
-
- // printf("entry of file %s, at offset %d and of size %d\n", path, offset, st.st_size);
- free(path);
+ uint32_t offset = 16 + head.num_entries * sizeof(lab_entry) + head.string_table_size + 16;
+ createEntries(dir, entries, str_table, dirname, offset);
- offset += st.st_size;
- WRITE_LE_UINT32(&entry.size, st.st_size);
- }
closedir(dir);
// Open the output file after we've finished with the dir, so that we're sure
// we don't include the lab into itself if it was asked to be created into the same dir.
FILE *outfile = fopen(out, "wb");
if (!outfile) {
- printf("Could not open file %s for writing\n", argv[2]);
+ printf("Could not open file %s for writing\n", out);
exit(2);
}
fwrite("LABN", 1, 4, outfile);
- fwrite(" ", 1, 4, outfile); //version
+ if (g_type == GT_GRIM) {
+ fwrite(" ", 1, 4, outfile); //version
+ } else {
+ //EMI expects this as the version number.
+ fwrite("\x00\x00\x01\x00", 1, 4, outfile);
+ }
writeUint32(outfile, head.num_entries);
writeUint32(outfile, head.string_table_size);
@@ -208,24 +248,34 @@ int main(int argc, char **argv) {
s[j] = str_table[j] ^ 0x96;
}
fwrite(s, 1, head.string_table_size, outfile);
+ free(s);
}
+ uint32_t bufsize = 1024*1024;
+ char *buf = (char *)malloc(bufsize);
+
for (uint32_t i = 0; i < head.num_entries; ++i) {
lab_entry &entry = entries[i];
const char *fname = str_table + READ_LE_UINT32(&entry.fname_offset);
- char *path = (char *)malloc(strlen(fname) + strlen(dirname) + 2);
- strcpy(path, dirname);
- path[strlen(dirname)] = '/';
- strcpy(path + strlen(dirname) + 1, fname);
+ char *path = appendPath(fname, dirname);
FILE *file = fopen(path, "rb");
free(path);
- offset = READ_LE_UINT32(&entry.start);
+ uint32_t offset = READ_LE_UINT32(&entry.start);
uint32_t size = READ_LE_UINT32(&entry.size);
- char *buf = (char *)malloc(size);
+ if (size > bufsize) {
+ char *newbuf = (char *)realloc(buf, size);
+ if (!newbuf) {
+ free(buf);
+ printf("Could not allocate memory\n");
+ exit(3);
+ }
+ bufsize = size;
+ buf = newbuf;
+ }
// printf("writing file %s, at offset %d and of size %d\n", fname, offset, size);
@@ -233,11 +283,11 @@ int main(int argc, char **argv) {
fseek(outfile, offset, SEEK_SET);
fwrite(buf, 1, size, outfile);
- free(buf);
fclose(file);
}
fclose(outfile);
+ free(buf);
free(entries);
free(str_table);
Commit: c804c97a0de40d24c42b8e7eecf71b0722fc5814
https://github.com/scummvm/scummvm-tools/commit/c804c97a0de40d24c42b8e7eecf71b0722fc5814
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2012-02-21T19:26:16-08:00
Commit Message:
UNLAB: Support creating directories on windows
Changed paths:
tools/unlab.cpp
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index f5ff32932..ea3d3baf4 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -25,6 +25,10 @@
#include <stdint.h>
#include <string.h>
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
#define GT_GRIM 1
#define GT_EMI 2
@@ -53,6 +57,17 @@ uint32_t READ_LE_UINT32(const void *ptr) {
return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
}
+static void createDirectoryStructure(char *name) {
+#ifdef WIN32
+ char *dir = strrchr(name, '\\');
+ if (dir) {
+ dir[0] = 0;
+ CreateDirectory(name, NULL);
+ dir[0] = '\\';
+ }
+#endif
+}
+
int main(int argc, char **argv) {
FILE *infile, *outfile;
struct lab_header head;
@@ -80,7 +95,7 @@ int main(int argc, char **argv) {
fread(&s_size, 1, 4, infile);
uint32_t typeTest = 0;
- fread(&typeTest,1,4,infile);
+ fread(&typeTest, 1, 4, infile);
if (typeTest == 0) { // First entry of the table has offset 0 for Grim
g_type = GT_GRIM;
fseek(infile, -4, SEEK_CUR);
@@ -131,7 +146,8 @@ int main(int argc, char **argv) {
exit(1);
}
for (i = 0; i < head.num_entries; i++) {
- const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
+ char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
+ createDirectoryStructure(fname);
outfile = fopen(fname, "wb");
if (!outfile) {
printf("Could not open file: %s\n", fname);
Commit: 28623c4542d6176d9275b15f2a019cb2a31c4d4b
https://github.com/scummvm/scummvm-tools/commit/28623c4542d6176d9275b15f2a019cb2a31c4d4b
Author: PaweÅ KoÅodziejski (aquadran at xtr.net.pl)
Date: 2012-02-21T22:02:35-08:00
Commit Message:
Merge pull request #23 from klusark/master
MKLAB: Add support for subdirectories and fix the version number for EMI
Changed paths:
tools/mklab.cpp
tools/unlab.cpp
Commit: 810f0b948f79f87d3009d3657fe8032311f4dc9d
https://github.com/scummvm/scummvm-tools/commit/810f0b948f79f87d3009d3657fe8032311f4dc9d
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-03-11T17:30:03+01:00
Commit Message:
ALL: update credits
Changed paths:
AUTHORS
diff --git a/AUTHORS b/AUTHORS
index 846e863c8..720e80750 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,29 +1,33 @@
-ResidualVM Team
-*************
+ResidualVM
+**********
Project Leader
--------------
Pawel Kolodziejski
- Engine Teams
- ------------
- Grim:
- James Brown - Core developer (retired)
+ Teams
+ -----
+ Grim Team:
+ James Brown - Core developer (retired)
Giulio Camuffo - Core developer
Pawel Kolodziejski - Core developer (suspended)
- Einar Johan T. Somaae - Initial EMI support, various code fixes and
+ Einar Johan T. Somaen - Initial EMI support, various code fixes and
improvements
- Grim Contributors:
- If you have contributed to this engine then you deserve to be on this
- list. Contact us and we'll add you.
+ Myst 3 Team:
+ Bastien Bouclet - Core developer
+
+ Contributors
+ ------------
+ If you have contributed to this engine then you deserve to be on this
+ list. Contact us and we'll add you.
+ Grim:
Torbjorn Andersson - Various code fixes
Ori Avtalion - Lipsync, LAF support, various code fixes
Robert Biro - Fixes to antiliasing
Bastien Bouclet - Various fixes to engine
Marcus Comstedt - Initial Dreamcast port
- Andrea Corna - Improved font support, patch extractor, few
- code improvements
+ Andrea Corna - Patcher module, various engine improvements
Jonathan Gray - Various code fixes
Vincent Hamm - Various engine code fixes and improvements
Sven Hesse - Various compilation fixes
@@ -33,16 +37,17 @@ ResidualVM Team
improvements
Max Horn - Minor code fixes
Travis Howell - Various code fixes, Windows port
+ Guillem Jover - Few code improvements
Filippos Karapetis - Compilation fixes
Joost Peters - Various code fixes
George Macon - Compilation fixes
Josh Matthews - Few fixes to engine
- Matthieu Milan - Few code improvements
+ Matthieu Milan - Various engine improvements
Christian Neumair - Various optimisation patches
- Vincent Pelletier - Various engine improvementts and code fixes
+ Vincent Pelletier - Various engine improvements and code fixes
Daniel Schepler - Initial engine codebase, LUA support
Yaron Tausky - Fixes to subtitles
- Joel Teichroeb - Initial EMI support, various code fixes and
+ Joel Teichroeb - Initial EMI support, various engine fixes and
improvements
Julien Templier - create_project tool
Pino Toscano - Debian GNU/Linux package files
@@ -50,9 +55,12 @@ ResidualVM Team
Joni Vahamaki - A lot engine improvements and fixes
JenniBee - Compilation fixes
+ Myst 3:
+ Matthew Hoops - Various engine improvements and code fixes
+
ScummVM code
************
- Residual use a lot of ScummVM code. For a list of authors look into
+ ResidualVM use a lot of ScummVM code. For a list of authors look into
COPYRIGHT file.
Website code
Commit: b2a33fe8d5d80426eece0e4204cfe252ba984c3f
https://github.com/scummvm/scummvm-tools/commit/b2a33fe8d5d80426eece0e4204cfe252ba984c3f
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-03-11T17:30:36+01:00
Commit Message:
ALL: update credits
Changed paths:
COPYRIGHT
diff --git a/COPYRIGHT b/COPYRIGHT
index 4e57d9ff3..d56434bc3 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -27,6 +27,7 @@ Matthieu Milan
Christian Neumair
Vincent Pelletier
Daniel Schepler
+Einar Johan Soemaaen
Yaron Tausky
Joel Teichroeb
Julien Templier
Commit: 2923e83a2392047af615ee237377d99a83a30546
https://github.com/scummvm/scummvm-tools/commit/2923e83a2392047af615ee237377d99a83a30546
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-03-11T17:38:39+01:00
Commit Message:
ALL: sync common files
Changed paths:
COPYING
config.guess
config.sub
diff --git a/COPYING b/COPYING
index b6f92f3db..00ccfbb62 100644
--- a/COPYING
+++ b/COPYING
@@ -1,8 +1,8 @@
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
+ 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.
@@ -15,7 +15,7 @@ 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
+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
@@ -303,10 +303,9 @@ the "copyright" line and a pointer to where the full notice is found.
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
-
+ 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.
@@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
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
+library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
diff --git a/config.guess b/config.guess
index 64cae2741..43f0cdbcf 100755
--- a/config.guess
+++ b/config.guess
@@ -1,10 +1,10 @@
#! /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, 2009
-# Free Software Foundation, Inc.
+# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+# 2011 Free Software Foundation, Inc.
-timestamp='2009-12-13'
+timestamp='2011-10-01'
# 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
@@ -56,8 +56,9 @@ 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, 2009 Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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."
@@ -180,7 +181,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
fi
;;
*)
- os=netbsd
+ os=netbsd
;;
esac
# The OS release
@@ -223,7 +224,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
;;
*5.*)
- UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+ UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
;;
esac
# According to Compaq, /usr/sbin/psrinfo has been available on
@@ -269,7 +270,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# 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 ;;
+ # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
+ exitcode=$?
+ trap '' 0
+ exit $exitcode ;;
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
@@ -295,7 +299,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
echo s390-ibm-zvmoe
exit ;;
*:OS400:*:*)
- echo powerpc-ibm-os400
+ echo powerpc-ibm-os400
exit ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
@@ -394,23 +398,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# 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}
+ echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
echo m68k-atari-mint${UNAME_RELEASE}
- exit ;;
+ exit ;;
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
- echo m68k-atari-mint${UNAME_RELEASE}
+ echo m68k-atari-mint${UNAME_RELEASE}
exit ;;
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
- echo m68k-milan-mint${UNAME_RELEASE}
- exit ;;
+ echo m68k-milan-mint${UNAME_RELEASE}
+ exit ;;
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
- echo m68k-hades-mint${UNAME_RELEASE}
- exit ;;
+ echo m68k-hades-mint${UNAME_RELEASE}
+ exit ;;
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
- echo m68k-unknown-mint${UNAME_RELEASE}
- exit ;;
+ echo m68k-unknown-mint${UNAME_RELEASE}
+ exit ;;
m68k:machten:*:*)
echo m68k-apple-machten${UNAME_RELEASE}
exit ;;
@@ -480,8 +484,8 @@ EOF
echo m88k-motorola-sysv3
exit ;;
AViiON:dgux:*:*)
- # DG/UX returns AViiON for all architectures
- UNAME_PROCESSOR=`/usr/bin/uname -p`
+ # 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 ] || \
@@ -494,7 +498,7 @@ EOF
else
echo i586-dg-dgux${UNAME_RELEASE}
fi
- exit ;;
+ exit ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit ;;
@@ -551,7 +555,7 @@ EOF
echo rs6000-ibm-aix3.2
fi
exit ;;
- *:AIX:*:[456])
+ *:AIX:*:[4567])
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
@@ -594,52 +598,52 @@ EOF
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" ;;
+ 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
+ esac ;;
+ esac
fi
if [ "${HP_ARCH}" = "" ]; then
eval $set_cc_for_build
- sed 's/^ //' << EOF >$dummy.c
+ sed 's/^ //' << EOF >$dummy.c
- #define _HPUX_SOURCE
- #include <stdlib.h>
- #include <unistd.h>
+ #define _HPUX_SOURCE
+ #include <stdlib.h>
+ #include <unistd.h>
- int main ()
- {
- #if defined(_SC_KERNEL_BITS)
- long bits = sysconf(_SC_KERNEL_BITS);
- #endif
- long cpu = sysconf (_SC_CPU_VERSION);
+ 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);
- }
+ 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
@@ -730,22 +734,22 @@ EOF
exit ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
- exit ;;
+ exit ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
- exit ;;
+ exit ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
- exit ;;
+ exit ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
- exit ;;
+ exit ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
- exit ;;
+ exit ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
@@ -769,14 +773,14 @@ EOF
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 ;;
+ 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}"
+ 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}
@@ -788,13 +792,12 @@ EOF
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:FreeBSD:*:*)
- case ${UNAME_MACHINE} in
- pc98)
- echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+ UNAME_PROCESSOR=`/usr/bin/uname -p`
+ case ${UNAME_PROCESSOR} in
amd64)
echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
*)
- echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+ echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
esac
exit ;;
i*:CYGWIN*:*)
@@ -804,14 +807,14 @@ EOF
echo ${UNAME_MACHINE}-pc-mingw32
exit ;;
i*:windows32*:*)
- # uname -m includes "-pc" on this system.
- echo ${UNAME_MACHINE}-mingw32
+ # uname -m includes "-pc" on this system.
+ echo ${UNAME_MACHINE}-mingw32
exit ;;
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
*:Interix*:*)
- case ${UNAME_MACHINE} in
+ case ${UNAME_MACHINE} in
x86)
echo i586-pc-interix${UNAME_RELEASE}
exit ;;
@@ -866,7 +869,7 @@ EOF
EV6) UNAME_MACHINE=alphaev6 ;;
EV67) UNAME_MACHINE=alphaev67 ;;
EV68*) UNAME_MACHINE=alphaev68 ;;
- esac
+ esac
objdump --private-headers /bin/sh | grep -q ld.so.1
if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
@@ -878,7 +881,13 @@ EOF
then
echo ${UNAME_MACHINE}-unknown-linux-gnu
else
- echo ${UNAME_MACHINE}-unknown-linux-gnueabi
+ if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
+ | grep -q __ARM_PCS_VFP
+ then
+ echo ${UNAME_MACHINE}-unknown-linux-gnueabi
+ else
+ echo ${UNAME_MACHINE}-unknown-linux-gnueabihf
+ fi
fi
exit ;;
avr32*:Linux:*:*)
@@ -891,7 +900,10 @@ EOF
echo crisv32-axis-linux-gnu
exit ;;
frv:Linux:*:*)
- echo frv-unknown-linux-gnu
+ echo frv-unknown-linux-gnu
+ exit ;;
+ hexagon:Linux:*:*)
+ echo hexagon-unknown-linux-gnu
exit ;;
i*86:Linux:*:*)
LIBC=gnu
@@ -959,7 +971,7 @@ EOF
echo ${UNAME_MACHINE}-ibm-linux
exit ;;
sh64*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
sh*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
@@ -967,6 +979,9 @@ EOF
sparc:Linux:*:* | sparc64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
+ tile*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
+ exit ;;
vax:Linux:*:*)
echo ${UNAME_MACHINE}-dec-linux-gnu
exit ;;
@@ -974,7 +989,7 @@ EOF
echo x86_64-unknown-linux-gnu
exit ;;
xtensa*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
+ echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
i*86:DYNIX/ptx:4*:*)
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
@@ -983,11 +998,11 @@ EOF
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,
+ # 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.
+ # Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit ;;
i*86:OS/2:*:*)
@@ -1019,7 +1034,7 @@ EOF
fi
exit ;;
i*86:*:5:[678]*)
- # UnixWare 7.x, OpenUNIX and OpenServer 6.
+ # UnixWare 7.x, OpenUNIX and OpenServer 6.
case `/bin/uname -X | grep "^Machine"` in
*486*) UNAME_MACHINE=i486 ;;
*Pentium) UNAME_MACHINE=i586 ;;
@@ -1047,13 +1062,13 @@ EOF
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.
+ # 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 ;;
+ exit ;;
Intel:Mach:3*:*)
echo i386-pc-mach3
exit ;;
@@ -1088,8 +1103,8 @@ EOF
/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; } ;;
+ /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 \
@@ -1132,10 +1147,10 @@ EOF
echo ns32k-sni-sysv
fi
exit ;;
- PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
- # says <Richard.M.Bartel at ccMail.Census.GOV>
- echo i586-unisys-sysv4
- exit ;;
+ PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+ # says <Richard.M.Bartel at ccMail.Census.GOV>
+ echo i586-unisys-sysv4
+ exit ;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes <hewes at openmarket.com>.
# How about differentiating between stratus architectures? -djm
@@ -1161,11 +1176,11 @@ EOF
exit ;;
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then
- echo mips-nec-sysv${UNAME_RELEASE}
+ echo mips-nec-sysv${UNAME_RELEASE}
else
- echo mips-unknown-sysv${UNAME_RELEASE}
+ echo mips-unknown-sysv${UNAME_RELEASE}
fi
- exit ;;
+ exit ;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
echo powerpc-be-beos
exit ;;
@@ -1230,6 +1245,9 @@ EOF
*:QNX:*:4*)
echo i386-pc-qnx
exit ;;
+ NEO-?:NONSTOP_KERNEL:*:*)
+ echo neo-tandem-nsk${UNAME_RELEASE}
+ exit ;;
NSE-?:NONSTOP_KERNEL:*:*)
echo nse-tandem-nsk${UNAME_RELEASE}
exit ;;
@@ -1275,13 +1293,13 @@ EOF
echo pdp10-unknown-its
exit ;;
SEI:*:*:SEIUX)
- echo mips-sei-seiux${UNAME_RELEASE}
+ 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`
+ UNAME_MACHINE=`(uname -p) 2>/dev/null`
case "${UNAME_MACHINE}" in
A*) echo alpha-dec-vms ; exit ;;
I*) echo ia64-dec-vms ; exit ;;
@@ -1321,11 +1339,11 @@ main ()
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
- "4"
+ "4"
#else
- ""
+ ""
#endif
- ); exit (0);
+ ); exit (0);
#endif
#endif
diff --git a/config.sub b/config.sub
index 110a68e34..5b8736823 100755
--- a/config.sub
+++ b/config.sub
@@ -1,10 +1,10 @@
#! /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, 2009
-# Free Software Foundation, Inc.
+# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+# 2011 Free Software Foundation, Inc.
-timestamp='2009-12-13'
+timestamp='2011-10-08'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@@ -75,8 +75,9 @@ Report bugs and patches to <config-patches at gnu.org>."
version="\
GNU config.sub ($timestamp)
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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."
@@ -123,8 +124,9 @@ esac
# 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* | \
+ nto-qnx* | linux-gnu* | linux-android* | 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
@@ -156,8 +158,8 @@ case $os in
os=
basic_machine=$1
;;
- -bluegene*)
- os=-cnk
+ -bluegene*)
+ os=-cnk
;;
-sim | -cisco | -oki | -wec | -winbond)
os=
@@ -173,10 +175,10 @@ case $os in
os=-chorusos
basic_machine=$1
;;
- -chorusrdb)
- os=-chorusrdb
+ -chorusrdb)
+ os=-chorusrdb
basic_machine=$1
- ;;
+ ;;
-hiux*)
os=-hiuxwe2
;;
@@ -249,13 +251,17 @@ case $basic_machine in
| 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 \
+ | be32 | be64 \
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
+ | epiphany \
| fido | fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+ | hexagon \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
+ | le32 | le64 \
| lm32 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
| maxq | mb | microblaze | mcore | mep | metag \
@@ -281,11 +287,13 @@ case $basic_machine in
| moxie \
| mt \
| msp430 \
+ | nds32 | nds32le | nds32be \
| nios | nios2 \
| ns16k | ns32k \
+ | open8 \
| or32 \
| pdp10 | pdp11 | pj | pjl \
- | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
+ | powerpc | powerpc64 | powerpc64le | powerpcle \
| pyramid \
| rx \
| score \
@@ -293,15 +301,24 @@ case $basic_machine in
| sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
- | spu | strongarm \
- | tahoe | thumb | tic4x | tic80 | tron \
+ | spu \
+ | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
| ubicom32 \
- | v850 | v850e \
+ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
| we32k \
- | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
+ | x86 | xc16x | xstormy16 | xtensa \
| z8k | z80)
basic_machine=$basic_machine-unknown
;;
+ c54x)
+ basic_machine=tic54x-unknown
+ ;;
+ c55x)
+ basic_machine=tic55x-unknown
+ ;;
+ c6x)
+ basic_machine=tic6x-unknown
+ ;;
m6811 | m68hc11 | m6812 | m68hc12 | picochip)
# Motorola 68HC11/12.
basic_machine=$basic_machine-unknown
@@ -313,6 +330,18 @@ case $basic_machine in
basic_machine=mt-unknown
;;
+ strongarm | thumb | xscale)
+ basic_machine=arm-unknown
+ ;;
+
+ xscaleeb)
+ basic_machine=armeb-unknown
+ ;;
+
+ xscaleel)
+ basic_machine=armel-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.
@@ -332,16 +361,19 @@ case $basic_machine in
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* | avr32-* \
+ | be32-* | be64-* \
| bfin-* | bs2000-* \
- | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
+ | c[123]* | c30-* | [cjt]90-* | c4x-* \
| 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-* \
+ | hexagon-* \
| i*86-* | i860-* | i960-* | ia64-* \
| ip2k-* | iq2000-* \
+ | le32-* | le64-* \
| lm32-* \
| m32c-* | m32r-* | m32rle-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
@@ -367,25 +399,29 @@ case $basic_machine in
| mmix-* \
| mt-* \
| msp430-* \
+ | nds32-* | nds32le-* | nds32be-* \
| nios-* | nios2-* \
| none-* | np1-* | ns16k-* | ns32k-* \
+ | open8-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
- | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
+ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
| pyramid-* \
| romp-* | rs6000-* | rx-* \
| 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-* \
+ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+ | tahoe-* \
+ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+ | tile*-* \
| tron-* \
| ubicom32-* \
- | v850-* | v850e-* | vax-* \
+ | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
+ | vax-* \
| we32k-* \
- | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
+ | x86-* | x86_64-* | xc16x-* | xps100-* \
| xstormy16-* | xtensa*-* \
| ymp-* \
| z8k-* | z80-*)
@@ -410,7 +446,7 @@ case $basic_machine in
basic_machine=a29k-amd
os=-udi
;;
- abacus)
+ abacus)
basic_machine=abacus-unknown
;;
adobe68k)
@@ -480,11 +516,20 @@ case $basic_machine in
basic_machine=powerpc-ibm
os=-cnk
;;
+ c54x-*)
+ basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ c55x-*)
+ basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ c6x-*)
+ basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
c90)
basic_machine=c90-cray
os=-unicos
;;
- cegcc)
+ cegcc)
basic_machine=arm-unknown
os=-cegcc
;;
@@ -516,7 +561,7 @@ case $basic_machine in
basic_machine=craynv-cray
os=-unicosmp
;;
- cr16)
+ cr16 | cr16-*)
basic_machine=cr16-unknown
os=-elf
;;
@@ -732,7 +777,7 @@ case $basic_machine in
basic_machine=ns32k-utek
os=-sysv
;;
- microblaze)
+ microblaze)
basic_machine=microblaze-xilinx
;;
mingw32)
@@ -775,6 +820,10 @@ case $basic_machine in
basic_machine=i370-ibm
os=-mvs
;;
+ nacl)
+ basic_machine=le32-unknown
+ os=-nacl
+ ;;
ncr3000)
basic_machine=i486-ncr
os=-sysv4
@@ -839,6 +888,12 @@ case $basic_machine in
np1)
basic_machine=np1-gould
;;
+ neo-tandem)
+ basic_machine=neo-tandem
+ ;;
+ nse-tandem)
+ basic_machine=nse-tandem
+ ;;
nsr-tandem)
basic_machine=nsr-tandem
;;
@@ -921,9 +976,10 @@ case $basic_machine in
;;
power) basic_machine=power-ibm
;;
- ppc) basic_machine=powerpc-unknown
+ ppc | ppcbe) basic_machine=powerpc-unknown
;;
- ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ppc-* | ppcbe-*)
+ basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
@@ -1017,6 +1073,9 @@ case $basic_machine in
basic_machine=i860-stratus
os=-sysv4
;;
+ strongarm-* | thumb-*)
+ basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
sun2)
basic_machine=m68000-sun
;;
@@ -1073,20 +1132,8 @@ case $basic_machine in
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
+ basic_machine=$basic_machine-unknown
os=-linux-gnu
;;
tx39)
@@ -1156,6 +1203,9 @@ case $basic_machine in
xps | xps100)
basic_machine=xps100-honeywell
;;
+ xscale-* | xscalee[bl]-*)
+ basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+ ;;
ymp)
basic_machine=ymp-cray
os=-unicos
@@ -1253,11 +1303,11 @@ esac
if [ x"$os" != x"" ]
then
case $os in
- # First match some system type aliases
- # that might get confused with valid system types.
+ # First match some system type aliases
+ # that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception.
- -auroraux)
- os=-auroraux
+ -auroraux)
+ os=-auroraux
;;
-solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'`
@@ -1294,7 +1344,8 @@ case $os in
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* | -cegcc* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
- | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
+ | -mingw32* | -linux-gnu* | -linux-android* \
+ | -linux-newlib* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
@@ -1341,7 +1392,7 @@ case $os in
-opened*)
os=-openedition
;;
- -os400*)
+ -os400*)
os=-os400
;;
-wince*)
@@ -1390,7 +1441,7 @@ case $os in
-sinix*)
os=-sysv4
;;
- -tpf*)
+ -tpf*)
os=-tpf
;;
-triton*)
@@ -1435,6 +1486,8 @@ case $os in
-dicos*)
os=-dicos
;;
+ -nacl*)
+ ;;
-none)
;;
*)
@@ -1457,10 +1510,10 @@ else
# system, and we'll never get to this point.
case $basic_machine in
- score-*)
+ score-*)
os=-elf
;;
- spu-*)
+ spu-*)
os=-elf
;;
*-acorn)
@@ -1472,8 +1525,17 @@ case $basic_machine in
arm*-semi)
os=-aout
;;
- c4x-* | tic4x-*)
- os=-coff
+ c4x-* | tic4x-*)
+ os=-coff
+ ;;
+ tic54x-*)
+ os=-coff
+ ;;
+ tic55x-*)
+ os=-coff
+ ;;
+ tic6x-*)
+ os=-coff
;;
# This must come before the *-dec entry.
pdp10-*)
@@ -1500,7 +1562,7 @@ case $basic_machine in
m68*-cisco)
os=-aout
;;
- mep-*)
+ mep-*)
os=-elf
;;
mips*-cisco)
@@ -1527,7 +1589,7 @@ case $basic_machine in
*-ibm)
os=-aix
;;
- *-knuth)
+ *-knuth)
os=-mmixware
;;
*-wec)
Commit: d5b080659415e574aa7c54a4288e47a20c4da7bb
https://github.com/scummvm/scummvm-tools/commit/d5b080659415e574aa7c54a4288e47a20c4da7bb
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-03-11T17:44:41+01:00
Commit Message:
ALL: sync common files
Changed paths:
A NEWS
Makefile
Makefile.common
diff --git a/Makefile b/Makefile
index c88e6951a..c79fd51b5 100644
--- a/Makefile
+++ b/Makefile
@@ -23,8 +23,8 @@ ifeq "$(HAVE_GCC)" "1"
# Turn off some annoying and not-so-useful warnings
CXXFLAGS+= -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder
# Enable even more warnings...
- CXXFLAGS+= -Wpointer-arith -Wcast-qual -Wcast-align
- CXXFLAGS+= -Wshadow -Wimplicit -Wnon-virtual-dtor -Wwrite-strings
+ CXXFLAGS+= -Wpointer-arith -Wcast-qual
+ CXXFLAGS+= -Wshadow -Wnon-virtual-dtor -Wwrite-strings
# Currently we disable this gcc flag, since it will also warn in cases,
# where using GCC_PRINTF (means: __attribute__((format(printf, x, y))))
@@ -32,14 +32,25 @@ ifeq "$(HAVE_GCC)" "1"
# being helpful.
#CXXFLAGS+= -Wmissing-format-attribute
- # Disable RTTI and exceptions, and enabled checking of pointers returned by "new"
- CXXFLAGS+= -fno-exceptions -fcheck-new
+ # Disable exceptions, ResidualVM use RTTI:
+ CXXFLAGS+= -fno-exceptions
- # There is a nice extra warning that flags variables that are potentially
- # used before being initialized. Very handy to catch a certain kind of
- # bugs. Unfortunately, it only works when optimizations are turned on,
- # which is why we normally don't use it.
- #CXXFLAGS+= -O -Wuninitialized
+ifneq "$(HAVE_CLANG)" "1"
+ # enable checking of pointers returned by "new", but only when we do not
+ # build with clang
+ CXXFLAGS+= -fcheck-new
+endif
+endif
+
+ifeq "$(HAVE_CLANG)" "1"
+ CXXFLAGS+= -Wno-conversion -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-four-char-constants
+endif
+
+ifeq "$(HAVE_ICC)" "1"
+ # Disable some warnings:
+ # 161: unrecognized #pragma
+ # 1899: multicharacter character literal (potential portability problem)
+ CXXFLAGS+= -diag-disable 161,1899
endif
#######################################################################
@@ -59,7 +70,7 @@ ZIP ?= zip -q
# Misc stuff - you should never have to edit this #
#######################################################################
-EXECUTABLE := residualvm$(EXEEXT)
+EXECUTABLE := $(EXEPRE)residualvm$(EXEEXT)
include $(srcdir)/Makefile.common
@@ -79,4 +90,3 @@ endif
ifneq ($(origin port_mk), undefined)
include $(srcdir)/$(port_mk)
endif
-
diff --git a/Makefile.common b/Makefile.common
index f1fc5176e..9d6f2318d 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -34,18 +34,28 @@ CPPFLAGS := $(DEFINES) $(INCLUDES)
DEPDIRS = $(addsuffix $(DEPDIR),$(MODULE_DIRS))
DEPFILES =
+# Make base/version.o depend on all other object files. This way if anything is
+# changed, it causes version.cpp to be recompiled. This in turn ensures that
+# the build date in gScummVMBuildDate is correct.
+base/version.o: $(filter-out base/libbase.a,$(OBJS))
+
+ifdef USE_ELF_LOADER
+backends/plugins/elf/version.o: $(filter-out base/libbase.a,$(filter-out backends/libbackends.a,$(OBJS)))
+endif
+
# Replace regular output with quiet messages
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifneq ($(VERBOSE_BUILD),1)
ifneq ($(VERBOSE_BUILD),yes)
-QUIET_CXX = @echo ' ' C++ ' ' $@;
-QUIET_AS = @echo ' ' AS ' ' $@;
-QUIET_NASM = @echo ' ' NASM ' ' $@;
-QUIET_AR = @echo ' ' AR ' ' $@;
-QUIET_RANLIB = @echo ' ' RANLIB ' ' $@;
-QUIET_PLUGIN = @echo ' ' PLUGIN ' ' $@;
-QUIET_LINK = @echo ' ' LINK ' ' $@;
-QUIET = @
+QUIET_CXX = @echo ' ' C++ ' ' $@;
+QUIET_AS = @echo ' ' AS ' ' $@;
+QUIET_NASM = @echo ' ' NASM ' ' $@;
+QUIET_AR = @echo ' ' AR ' ' $@;
+QUIET_RANLIB = @echo ' ' RANLIB ' ' $@;
+QUIET_PLUGIN = @echo ' ' PLUGIN ' ' $@;
+QUIET_LINK = @echo ' ' LINK ' ' $@;
+QUIET_WINDRES = @echo ' ' WINDRES '' $@;
+QUIET = @
endif
endif
endif
@@ -80,15 +90,26 @@ ifdef CXX_UPDATE_DEP_FLAG
%.o: %.m
$(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
- $(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(OBJCFLAGS) -c $(<) -o $*.o
+ $(QUIET_CXX)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CPPFLAGS) $(OBJCFLAGS) -c $(<) -o $*.o
+
+# Build rule for assembler files with preprocessing
+%.o: %.S
+ $(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
+ $(QUIET_AS)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(ASFLAGS) -c $(<) -o $*.o
else
# Dumb compile rule, for C++ compilers that don't allow dependency tracking or
# where it is broken (such as GCC 2.95).
.cpp.o:
+ $(QUIET)$(MKDIR) $(*D)
$(QUIET_CXX)$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+# Build rule for assembler files with preprocessing
+%.o: %.S
+ $(QUIET)$(MKDIR) $(*D)
+ $(QUIET_AS)$(CXX) $(ASFLAGS) -c $(<) -o $*.o
+
endif
# Build rule for assembler files
@@ -96,16 +117,11 @@ endif
$(QUIET)$(MKDIR) $(*D)
$(QUIET_AS)$(AS) $(ASFLAGS) $(<) -o $*.o
-# Build rule for assembler files with preprocessing
-%.o: %.S
- $(QUIET)$(MKDIR) $(*D)/$(DEPDIR)
- $(QUIET_AS)$(CXX) $(CXX_UPDATE_DEP_FLAG) $(ASFLAGS) -c $(<) -o $*.o
-
-ifdef HAVE_NASM
+ifdef USE_NASM
# Build rule for NASM assembler files
%.o: %.asm
$(QUIET)$(MKDIR) $(*D)
- $(QUIET_NASM)$(NASM) -O1 $(NASMFLAGS) -g -o $*.o $(<)
+ $(QUIET_NASM)$(NASM) $(NASMFLAGS) -o $*.o $(<)
endif
# Include the dependency tracking files.
@@ -117,13 +133,69 @@ endif
.PHONY: $(wildcard $(addsuffix /*.d,$(DEPDIRS))) $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES))) \
$(srcdir)/$(port_mk) $(srcdir)/rules.mk
+######################################################################
+# Get the current version information
+######################################################################
+
+VERSION = $(shell grep SCUMMVM_VERSION "${srcdir}/base/internal_version.h" | cut -d\" -f2)
+VER_MAJOR = $(shell echo $(VERSION) | cut -d. -f 1)
+VER_MINOR = $(shell echo $(VERSION) | cut -d. -f 2)
+VER_PATCH = $(shell echo $(VERSION) | cut -d. -f 3 | cut -c1)
+VER_EXTRA = $(shell echo $(VERSION) | cut -d. -f 3 | cut -c2-)
+
+
+######################################################################
+# Get git's working copy information
+######################################################################
+
+ifneq ($(shell cd $(srcdir); git rev-parse --verify HEAD 1>/dev/null 2>&1 || echo "error"),error)
+GITROOT := $(srcdir)
+ifeq ($(origin VER_REV), undefined)
+# Are there uncommitted changes? (describe --dirty is only available since 1.6.6)
+VER_DIRTY := $(shell cd $(srcdir); git update-index --refresh --unmerged 1>/dev/null 2>&1; git diff-index --quiet HEAD || echo "-dirty")
+# Get the working copy base revision
+#ResidualVM: --always
+VER_REV := $(shell cd $(srcdir); git describe --always --match desc/\* | cut -d '-' -f 2-)$(VER_DIRTY)
+endif
+else
+GITROOT := git://github.com/residualvm/residualvm-tools.git
+endif
+
+# Define the Subversion revision if available, either autodetected or
+# specified by the user, but only for base/version.cpp.
+ifneq ($(origin VER_REV), undefined)
+base/version.o: CXXFLAGS:=$(CXXFLAGS) -DSCUMMVM_REVISION=\"$(VER_REV)\"
+endif
######################################################################
# Distribution settings
######################################################################
-DISTNAME := residualvm-tools
+ifeq ($(VER_EXTRA),git)
+ifeq ($(origin VER_REV), undefined)
+DISTVERSION = $(shell date '+%Y-%m-%d')
+else
+DISTVERSION = git$(VER_REV)
+endif
+else
+DISTVERSION = $(VERSION)
+endif
+
+DISTNAME := residualvm-tools-$(DISTVERSION)
DISTDIR := dist
+VERFILE := $(DISTDIR)/$(DISTNAME)/base/internal_version.h
+
+# TODO git via $(GITROOT)
+$(VERFILE): $(srcdir)/base/internal_version.h
+ @$(RM_REC) $(DISTDIR)
+ @$(MKDIR) $(DISTDIR)
+ svn export $(SVNROOT) $(DISTDIR)/$(DISTNAME)
+ifneq ($(origin VER_REV), undefined)
+ @# Use the current SVN revision as a default for the snapshot sources
+ @svn cat $(SVNROOT)/base/internal_version.h | sed -e \
+ "s/^#define SCUMMVM_REVISION$$/#define SCUMMVM_REVISION \"$(VER_REV)\"/g" \
+ > $(VERFILE)
+endif
$(DISTDIR)/$(DISTNAME).tar.gz: $(VERFILE)
cd $(DISTDIR); tar zcf $(DISTNAME).tar.gz $(DISTNAME)
@@ -141,4 +213,7 @@ dist-src: \
@#RPM-src?
@#DEB-src?
+# Common files
+DIST_FILES_DOCS:=$(addprefix $(srcdir)/,AUTHORS COPYING COPYING.LGPL COPYRIGHT NEWS README)
+
.PHONY: all clean distclean dist-src
diff --git a/NEWS b/NEWS
new file mode 100644
index 000000000..e69de29bb
Commit: 9dca2bd418e20d900ab51b095c2428f25e67da5a
https://github.com/scummvm/scummvm-tools/commit/9dca2bd418e20d900ab51b095c2428f25e67da5a
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-03-18T17:00:49+01:00
Commit Message:
ALL: update tools
Changed paths:
A base/internal_version.h
.gitignore
AUTHORS
Makefile
common/endian.h
common/scummsys.h
configure
rules.mk
diff --git a/.gitignore b/.gitignore
index 73e9be9bf..d1b28158e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,24 @@
*.o
*.exe
+animb2txt
+bmtoppm
+cosb2cos
+delua
+imc2wav
+int2flt
+labcopy
+meshb2obj
+mklab
+set2fig
+setb2set
+sklb2txt
+til2bmp
+unlab
+vima
+luac
+patchex
+
.deps
/config.h
/config.log
diff --git a/AUTHORS b/AUTHORS
index 720e80750..527f0179e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -77,3 +77,6 @@ Special thanks to
Bret Mogilefsky, for managing to create a SPUTM-style 3D LUA engine, and
avoiding the horrible hack it could have been.
+ Benjamin Haisch, for emimeshviewer, which our EMI code borrows heavily
+ from.
+
diff --git a/Makefile b/Makefile
index c79fd51b5..b84a55c47 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ srcdir ?= .
DEFINES := -DHAVE_CONFIG_H
LDFLAGS :=
-INCLUDES := -I. -I$(srcdir)
+INCLUDES := -I. -I$(srcdir) -I$(srcdir)/engines
LIBS :=
OBJS :=
DEPDIR := .deps
diff --git a/base/internal_version.h b/base/internal_version.h
new file mode 100644
index 000000000..c6aaf1845
--- /dev/null
+++ b/base/internal_version.h
@@ -0,0 +1,19 @@
+#ifndef INCLUDED_FROM_BASE_VERSION_CPP
+#error This file may only be included by base/version.cpp
+#endif
+
+// Reads revision number from file
+// (this is used when building with Visual Studio)
+#ifdef SCUMMVM_INTERNAL_REVISION
+#include "internal_revision.h"
+#endif
+
+#ifdef RELEASE_BUILD
+#undef SCUMMVM_REVISION
+#endif
+
+#ifndef SCUMMVM_REVISION
+#define SCUMMVM_REVISION
+#endif
+
+#define SCUMMVM_VERSION "git" SCUMMVM_REVISION
diff --git a/common/endian.h b/common/endian.h
index 88ba9e3e7..5fc54e97b 100644
--- a/common/endian.h
+++ b/common/endian.h
@@ -146,51 +146,57 @@
*/
#define MKTAG(a0,a1,a2,a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
-// Functions for reading/writing native Integers,
-// this transparently handles the need for alignment
-
-#if !defined(SCUMM_NEED_ALIGNMENT)
+// Functions for reading/writing native integers.
+// They also transparently handle the need for alignment.
+
+// Test for GCC >= 4.0. These implementations will automatically use
+// CPU-specific instructions for unaligned data when they are available (eg.
+// MIPS). See also this email thread on scummvm-devel for details:
+// <http://thread.gmane.org/gmane.games.devel.scummvm/8063>
+//
+// Moreover, we activate this code for GCC >= 3.3 but *only* if unaligned access
+// is allowed.
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 && !defined(SCUMM_NEED_ALIGNMENT)))
FORCEINLINE uint16 READ_UINT16(const void *ptr) {
- return *(const uint16 *)(ptr);
+ struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__));
+ return ((const Unaligned16 *)ptr)->val;
}
FORCEINLINE uint32 READ_UINT32(const void *ptr) {
- return *(const uint32 *)(ptr);
+ struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__));
+ return ((const Unaligned32 *)ptr)->val;
}
FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) {
- *(uint16 *)(ptr) = value;
+ struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__));
+ ((Unaligned16 *)ptr)->val = value;
}
FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) {
- *(uint32 *)(ptr) = value;
+ struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__));
+ ((Unaligned32 *)ptr)->val = value;
}
-// test for GCC >= 4.0. these implementations will automatically use CPU-specific
-// instructions for unaligned data when they are available (eg. MIPS)
-#elif defined(__GNUC__) && (__GNUC__ >= 4)
+#elif !defined(SCUMM_NEED_ALIGNMENT)
FORCEINLINE uint16 READ_UINT16(const void *ptr) {
- struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__));
- return ((const Unaligned16 *)ptr)->val;
+ return *(const uint16 *)(ptr);
}
FORCEINLINE uint32 READ_UINT32(const void *ptr) {
- struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__));
- return ((const Unaligned32 *)ptr)->val;
+ return *(const uint32 *)(ptr);
}
FORCEINLINE void WRITE_UINT16(void *ptr, uint16 value) {
- struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__));
- ((Unaligned16 *)ptr)->val = value;
+ *(uint16 *)(ptr) = value;
}
FORCEINLINE void WRITE_UINT32(void *ptr, uint32 value) {
- struct Unaligned32 { uint32 val; } __attribute__ ((__packed__, __may_alias__));
- ((Unaligned32 *)ptr)->val = value;
+ *(uint32 *)(ptr) = value;
}
+
// use software fallback by loading each byte explicitely
#else
@@ -390,6 +396,7 @@ inline uint32 READ_BE_UINT24(const void *ptr) {
return (b[0] << 16) | (b[1] << 8) | (b[2]);
}
+// ResidualVM specific:
#if defined(SCUMM_BIG_ENDIAN)
inline float get_float(const char *data) {
diff --git a/common/scummsys.h b/common/scummsys.h
index 73ccf9e97..39650ce1f 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -40,10 +40,42 @@
#if defined(WIN32)
#ifdef _MSC_VER
- // vsnprintf is already defined in Visual Studio 2008
- #if (_MSC_VER < 1500)
- #define vsnprintf _vsnprintf
- #endif
+
+ // FIXME: The placement of the workaround functions for MSVC below
+ // require us to include stdio.h and stdarg.h for MSVC here. This
+ // is not exactly nice...
+ // We should think of a better way of doing this.
+ #include <stdio.h>
+ #include <stdarg.h>
+
+ // MSVC's vsnprintf is either non-existant (2003) or bugged since it
+ // does not always include a terminating NULL (2005+). To work around
+ // that we fix up the _vsnprintf included. Note that the return value
+ // will still not match C99's specs!
+ inline int vsnprintf_msvc(char *str, size_t size, const char *format, va_list args) {
+ // We do not pass size - 1 here, to ensure we would get the same
+ // return value as when we would use _vsnprintf directly, since
+ // for example Common::String::format relies on this.
+ int retValue = _vsnprintf(str, size, format, args);
+ str[size - 1] = 0;
+ return retValue;
+ }
+
+ #define vsnprintf vsnprintf_msvc
+
+ // Visual Studio does not include snprintf in its standard C library.
+ // Instead it includes a function called _snprintf with somewhat
+ // similar semantics. The minor difference is that the return value in
+ // case the formatted string exceeds the buffer size is different.
+ // A much more dangerous one is that _snprintf does not always include
+ // a terminating null (Whoops!). Instead we map to our fixed vsnprintf.
+ inline int snprintf(char *str, size_t size, const char *format, ...) {
+ va_list args;
+ va_start(args, format);
+ int len = vsnprintf(str, size, format, args);
+ va_end(args);
+ return len;
+ }
#endif
#if !defined(_WIN32_WCE)
@@ -98,6 +130,15 @@
#define _USE_MATH_DEFINES
#include <math.h>
+ // FIXME: We sadly can't assume standard C++ headers to be present on every
+ // system we support, so we should get rid of this. The solution should be to
+ // write a simple placement new on our own. It might be noteworthy we can't
+ // easily do that for systems which do have a <new>, since it might clash with
+ // the default definition otherwise!
+ // Symbian does not have <new> but the new operator
+ #if !defined(__SYMBIAN32__)
+ #include <new>
+ #endif
#endif
@@ -107,11 +148,6 @@
#include "config.h"
#endif
-// make sure we really are compiling for WIN32
-#ifndef WIN32
-#undef _MSC_VER
-#endif
-
// In the following we configure various targets, in particular those
// which can't use our "configure" tool and hence don't use config.h.
@@ -123,20 +159,10 @@
// - Define this on a big endian target
// SCUMM_NEED_ALIGNMENT
// - Define this if your system has problems reading e.g. an int32 from an odd address
-// SCUMMVM_DONT_DEFINE_TYPES
-// - Define this if you need to provide your own typedefs, e.g. because your
-// system headers conflict with our typenames, or because you have odd
-// type requirements.
// SMALL_SCREEN_DEVICE
// - ...
// ...
-// We define all types in config.h, so we don't want to typedef those types
-// here again!
-#ifdef HAVE_CONFIG_H
-#define SCUMMVM_DONT_DEFINE_TYPES
-#endif
-
//
// By default we try to use pragma push/pop to ensure various structs we use
@@ -151,82 +177,36 @@
//
#define SCUMMVM_USE_PRAGMA_PACK
+//
+// Determine the host endianess and whether memory alignment is required.
+//
+#if !defined(HAVE_CONFIG_H)
-#if defined(__SYMBIAN32__)
-
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-
- #define SCUMM_LITTLE_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
- #define SMALL_SCREEN_DEVICE
-
- // Enable Symbians own datatypes
- // This is done for two reasons
- // a) uint is already defined by Symbians libc component
- // b) Symbian is using its "own" datatyping, and the Scummvm port
- // should follow this to ensure the best compability possible.
- #define SCUMMVM_DONT_DEFINE_TYPES
- typedef unsigned char byte;
-
- typedef unsigned char uint8;
- typedef signed char int8;
-
- typedef unsigned short int uint16;
- typedef signed short int int16;
-
- typedef unsigned long int uint32;
- typedef signed long int int32;
-
-#elif defined(_WIN32_WCE)
-
- #define scumm_stricmp stricmp
- #define scumm_strnicmp _strnicmp
- #define snprintf _snprintf
-
- #define SCUMM_LITTLE_ENDIAN
-
- #ifndef __GNUC__
- #define FORCEINLINE __forceinline
- #define NORETURN_PRE __declspec(noreturn)
- #endif
- #define PLUGIN_EXPORT __declspec(dllexport)
-
- #if _WIN32_WCE < 300
- #define SMALL_SCREEN_DEVICE
- #endif
-
-#elif defined(_MSC_VER)
-
- #define scumm_stricmp stricmp
- #define scumm_strnicmp _strnicmp
- #define snprintf _snprintf
-
- #define SCUMM_LITTLE_ENDIAN
-
- #define FORCEINLINE __forceinline
- #define NORETURN_PRE __declspec(noreturn)
- #define PLUGIN_EXPORT __declspec(dllexport)
-
-
-#elif defined(__MINGW32__)
+ #if defined(__DC__) || \
+ defined(__DS__) || \
+ defined(__GP32__) || \
+ defined(IPHONE) || \
+ defined(__PLAYSTATION2__) || \
+ defined(__PSP__) || \
+ defined(__SYMBIAN32__)
- #define scumm_stricmp stricmp
- #define scumm_strnicmp strnicmp
+ #define SCUMM_LITTLE_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
- #define SCUMM_LITTLE_ENDIAN
+ #elif defined(_WIN32_WCE) || defined(_MSC_VER) || defined(__MINGW32__)
- #define PLUGIN_EXPORT __declspec(dllexport)
+ #define SCUMM_LITTLE_ENDIAN
-#elif defined(UNIX)
+ #elif defined(__amigaos4__) || defined(__N64__) || defined(__WII__)
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
+ #define SCUMM_BIG_ENDIAN
+ #define SCUMM_NEED_ALIGNMENT
- #ifndef CONFIG_H
- /* need this for the SDL_BYTEORDER define */
- #include <SDL_byteorder.h>
+ #elif defined(SDL_BACKEND)
+ // On SDL based ports, we try to use SDL_BYTEORDER to determine the
+ // endianess. We explicitly do this as the *last* thing we try, so that
+ // platform specific settings have precedence.
+ #include <SDL_endian.h>
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define SCUMM_LITTLE_ENDIAN
@@ -235,171 +215,96 @@
#else
#error Neither SDL_BIG_ENDIAN nor SDL_LIL_ENDIAN is set.
#endif
+
+ #else
+
+ #error No system type defined, host endianess unknown.
+
#endif
+#endif
+
- // You need to set this manually if necessary
-// #define SCUMM_NEED_ALIGNMENT
+//
+// Some more system specific settings.
+// TODO/FIXME: All of these should be moved to backend specific files (such as portdefs.h)
+//
+#if defined(DINGUX)
// Very BAD hack following, used to avoid triggering an assert in uClibc dingux library
// "toupper" when pressing keyboard function keys.
- #if defined(DINGUX)
#undef toupper
#define toupper(c) (((c & 0xFF) >= 97) && ((c & 0xFF) <= 122) ? ((c & 0xFF) - 32) : (c & 0xFF))
- #endif
-
-#elif defined(__DC__)
-
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-
- #define SCUMM_LITTLE_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
-#elif defined(__GP32__)
-
- #define scumm_stricmp stricmp
- #define scumm_strnicmp strnicmp
-
- #define SCUMM_LITTLE_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
- // Override typenames. uint is already defined by system header files.
- #define SCUMMVM_DONT_DEFINE_TYPES
- typedef unsigned char byte;
-
- typedef unsigned char uint8;
- typedef signed char int8;
-
- typedef unsigned short int uint16;
- typedef signed short int int16;
-
- typedef unsigned long int uint32;
- typedef signed long int int32;
-
-#elif defined(__PLAYSTATION2__)
-
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-
- #define SCUMM_LITTLE_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
-#elif defined(__N64__)
-
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-
- #define SCUMM_BIG_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
- #define STRINGBUFLEN 256
-
- #define SCUMMVM_DONT_DEFINE_TYPES
- typedef unsigned char byte;
-
- typedef unsigned char uint8;
- typedef signed char int8;
-
- typedef unsigned short int uint16;
- typedef signed short int int16;
-
- typedef unsigned int uint32;
- typedef signed int int32;
-
- typedef unsigned long long uint64;
- typedef signed long long int64;
#elif defined(__PSP__)
#include <malloc.h>
#include "backends/platform/psp/memory.h"
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-
- #define SCUMM_LITTLE_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
/* to make an efficient, inlined memcpy implementation */
#define memcpy(dst, src, size) psp_memcpy(dst, src, size)
-#elif defined(__amigaos4__)
-
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-
- #define SCUMM_BIG_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
-#elif defined (__DS__)
-
- #define scumm_stricmp stricmp
- #define scumm_strnicmp strnicmp
-
- #define SCUMM_NEED_ALIGNMENT
- #define SCUMM_LITTLE_ENDIAN
-
- #define SCUMMVM_DONT_DEFINE_TYPES
-
- #define STRINGBUFLEN 256
-// #define printf(fmt, ...) consolePrintf(fmt, ##__VA_ARGS__)
-
-#elif defined(__WII__)
-
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-
- #define SCUMM_BIG_ENDIAN
- #define SCUMM_NEED_ALIGNMENT
-
-#else
- #error No system type defined
-
#endif
//
-// GCC specific stuff
+// Fallbacks / default values for various special macros
//
-#if defined(__GNUC__)
- #define NORETURN_POST __attribute__((__noreturn__))
- #define PACKED_STRUCT __attribute__((__packed__))
- #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y)))
-
- #if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
- #define FORCEINLINE inline __attribute__((__always_inline__))
+#ifndef GCC_PRINTF
+ #if defined(__GNUC__) || defined(__INTEL_COMPILER)
+ #define GCC_PRINTF(x,y) __attribute__((__format__(__printf__, x, y)))
+ #else
+ #define GCC_PRINTF(x,y)
#endif
-#elif defined(__INTEL_COMPILER)
- #define NORETURN_POST __attribute__((__noreturn__))
- #define PACKED_STRUCT __attribute__((__packed__))
- #define GCC_PRINTF(x,y) __attribute__((__format__(printf, x, y)))
-#else
- #define PACKED_STRUCT
- #define GCC_PRINTF(x,y)
#endif
+#ifndef PACKED_STRUCT
+ #if defined(__GNUC__) || defined(__INTEL_COMPILER)
+ #define PACKED_STRUCT __attribute__((__packed__))
+ #else
+ #define PACKED_STRUCT
+ #endif
+#endif
-//
-// Fallbacks / default values for various special macros
-//
#ifndef FORCEINLINE
-#define FORCEINLINE inline
+ #if defined(_MSC_VER)
+ #define FORCEINLINE __forceinline
+ #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+ #define FORCEINLINE inline __attribute__((__always_inline__))
+ #else
+ #define FORCEINLINE inline
+ #endif
#endif
#ifndef PLUGIN_EXPORT
-#define PLUGIN_EXPORT
+ #if defined(_MSC_VER) || defined(_WIN32_WCE) || defined(__MINGW32__)
+ #define PLUGIN_EXPORT __declspec(dllexport)
+ #else
+ #define PLUGIN_EXPORT
+ #endif
#endif
#ifndef NORETURN_PRE
-#define NORETURN_PRE
+ #if defined(_MSC_VER)
+ #define NORETURN_PRE __declspec(noreturn)
+ #else
+ #define NORETURN_PRE
+ #endif
#endif
#ifndef NORETURN_POST
-#define NORETURN_POST
+ #if defined(__GNUC__) || defined(__INTEL_COMPILER)
+ #define NORETURN_POST __attribute__((__noreturn__))
+ #else
+ #define NORETURN_POST
+ #endif
#endif
#ifndef STRINGBUFLEN
-#define STRINGBUFLEN 1024
+ #if defined(__N64__) || defined(__DS__)
+ #define STRINGBUFLEN 256
+ #else
+ #define STRINGBUFLEN 1024
+ #endif
#endif
#ifndef LOCAL_PI
@@ -410,11 +315,25 @@
#define MAXPATHLEN 256
#endif
+#ifndef scumm_va_copy
+ #if defined(va_copy)
+ #define scumm_va_copy va_copy
+ #elif defined(__va_copy)
+ #define scumm_va_copy __va_copy
+ #elif defined(_MSC_VER) || defined (__SYMBIAN32__)
+ #define scumm_va_copy(dst, src) ((dst) = (src))
+ #else
+ #error scumm_va_copy undefined for this port
+ #endif
+#endif
+
+
//
-// Typedef our system types unless SCUMMVM_DONT_DEFINE_TYPES is set.
+// Typedef our system types unless they have already been defined by config.h,
+// or SCUMMVM_DONT_DEFINE_TYPES is set.
//
-#ifndef SCUMMVM_DONT_DEFINE_TYPES
+#if !defined(HAVE_CONFIG_H) && !defined(SCUMMVM_DONT_DEFINE_TYPES)
typedef unsigned char byte;
typedef unsigned char uint8;
typedef signed char int8;
@@ -426,16 +345,11 @@
#endif
-
//
// Overlay color type (FIXME: shouldn't be declared here)
//
-#if defined(NEWGUI_256)
- // 256 color only on PalmOS
- typedef byte OverlayColor;
-#else
- // 15/16 bit color mode everywhere else...
- typedef uint16 OverlayColor;
-#endif
+typedef uint16 OverlayColor;
+
+//#include "common/forbidden.h"
#endif
diff --git a/configure b/configure
index a3de08e68..6ab09f78f 100755
--- a/configure
+++ b/configure
@@ -1,9 +1,9 @@
#!/bin/sh
#
-# configure -- custom configure script for ResidualVM.
+# configure -- custom configure script for ScummVM.
#
-# Residual is the legal property of its developers, whose names
-# are too numerous to list here. Please refer to the AUTHORS
+# ScummVM is the legal property of its developers, whose names
+# are too numerous to list here. Please refer to the COPYRIGHT
# file distributed with this source distribution.
#
# This program is free software; you can redistribute it and/or
@@ -65,18 +65,61 @@ get_var() {
#
# Default settings
#
+#ResidualVM defaults: mpeg2=auto, faad=no, opengles=no
+#mt32emu=no, translation=no
+#
# Default lib behaviour yes/no/auto
_vorbis=auto
_tremor=auto
+_tremolo=no
_flac=auto
_mad=auto
+_alsa=auto
+_seq_midi=auto
+_timidity=auto
+_zlib=auto
+_sparkle=auto
+_png=no
+_mpeg2=auto
+_theoradec=auto
+_faad=no
+_fluidsynth=auto
+_opengl=auto
+_opengles=no
+_readline=auto
+_freetype2=auto
+_taskbar=yes
+_updates=no
+_libunity=auto
# Default option behaviour yes/no
_debug_build=auto
_release_build=auto
-_endian=unknown
-_need_memalign=no
-_have_x86=no
+_optimizations=auto
_verbose_build=no
+_text_console=no
+_mt32emu=no
+_build_scalers=yes
+_build_hq_scalers=yes
+_enable_prof=no
+_global_constructors=no
+_bink=yes
+# Default vkeybd/keymapper options
+_vkeybd=no
+_keymapper=no
+# GUI translation options
+_translation=no
+# Default platform settings
+_backend=sdl
+_16bit=auto
+_savegame_timestamp=auto
+_dynamic_modules=no
+_elf_loader=no
+_plugins_default=static
+_plugin_prefix=
+_plugin_suffix=
+_nasm=auto
+_optimization_level=
+_default_optimization_level=-O2
# Default commands
_ranlib=ranlib
_strip=strip
@@ -85,8 +128,42 @@ _as="as"
_windres=windres
_win32path="C:/residualvm-tools"
_aos4path="Games:ResidualVM-tools"
+_stagingpath="staging"
_staticlibpath=/sw
-_prefix=/usr/local
+_sdlconfig=sdl-config
+_freetypeconfig=freetype-config
+_sdlpath="$PATH"
+_freetypepath="$PATH"
+_nasmpath="$PATH"
+NASMFLAGS=""
+NASM=""
+_tainted_build=no
+# The following variables are automatically detected, and should not
+# be modified otherwise. Consider them read-only.
+_posix=no
+_endian=unknown
+_need_memalign=yes
+_have_x86=no
+
+
+
+# Directories for installing ScummVM.
+# This list is closely based on what GNU autoconf does,
+# although the default value for datadir differs.
+# Like GNU autoconf, we distinguish datadir and datarootdir
+# to make it possible to change e.g. the location of the
+# man pages independently of that of the engine data files,
+# which are placed inside $datadir/residualvm
+prefix=NONE
+exec_prefix=NONE
+bindir='${exec_prefix}/bin'
+libdir='${exec_prefix}/lib'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}/residualvm'
+mandir='${datarootdir}/man'
+docdir='${datarootdir}/doc/residualvm'
+#localedir='${datarootdir}/locale'
+
# For cross compiling
_host=""
_host_cpu=""
@@ -97,27 +174,52 @@ _host_alias=""
_srcdir=`dirname $0`
_port_mk="ports.mk"
-# Determine a tmp file name, using mktemp(1) when available.
-if type mktemp > /dev/null 2>&1 ; then
- TMPO=`mktemp /tmp/residualvm-conf.XXXXXXXXXX`
-else
- TMPO=./residualvm-conf
-fi
+# Use temp files in the build directory
+TMPO=./residualvm-conf
TMPC=${TMPO}.cpp
TMPLOG=config.log
-cc_check() {
+cc_check_no_clean() {
echo >> "$TMPLOG"
cat "$TMPC" >> "$TMPLOG"
echo >> "$TMPLOG"
- echo "$CXX $TMPC -o $TMPO$HOSTEXEEXT $@" >> "$TMPLOG"
+ echo "$CXX $LDFLAGS $CXXFLAGS $TMPC -o $TMPO$HOSTEXEEXT $@" >> "$TMPLOG"
rm -f "$TMPO$HOSTEXEEXT"
- ( $CXX $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
+ ( $CXX $LDFLAGS $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
TMPR="$?"
+ echo "return code: $TMPR" >> "$TMPLOG"
echo >> "$TMPLOG"
return "$TMPR"
}
+cc_check_clean() {
+ rm -rf $TMPC $TMPO $TMPO.o $TMPO.dSYM $TMPO$HOSTEXEEXT "$@"
+}
+
+cc_check() {
+ cc_check_no_clean "$@"
+ TMPR="$?"
+ cc_check_clean
+ return "$TMPR"
+}
+
+cc_check_define() {
+cat > $TMPC << EOF
+int main(void) {
+ #ifndef $1
+ syntax error
+ #endif
+ return 0;
+}
+EOF
+ cc_check -c
+ return $?
+}
+
+gcc_get_define() {
+ echo "" | $CXX -dM -E - | fgrep "$1" | head -n1 | cut -d ' ' -f 3-
+}
+
#
# Function to provide echo -n for bourne shells that don't have it
#
@@ -141,6 +243,10 @@ add_line_to_config_h() {
'"$1"
}
+# Conditionally add a line of data to config.h. Takes two parameters:
+# The first one can be set to 'no' to "comment out" the line, i.e.
+# make it ineffective, use 'yes' otherwise.
+# The second param is the line to insert.
add_to_config_h_if_yes() {
if test "$1" = yes ; then
add_line_to_config_h "$2"
@@ -161,15 +267,28 @@ add_to_config_mk_if_yes() {
fi
}
-# Conditionally add a line of data to config.mk. Takes two parameters:
-# The first one can be set to 'yes' to "comment out" the line, i.e.
-# make it ineffective, use 'no' otherwise.
-# The second param is the line to insert.
-add_to_config_mk_if_no() {
- if test "$1" = no ; then
- add_line_to_config_mk "$2"
+# Conditionally add a '#define' line to config.h. Takes two parameters:
+# The first one can be set to 'yes' or 'no'. If 'yes' is used, then
+# the line "#define $2" is added to config.h, otherwise "#undef $2".
+define_in_config_h_if_yes() {
+ if test "$1" = yes ; then
+ add_line_to_config_h "#define $2"
else
- add_line_to_config_mk "# $2"
+ add_line_to_config_h "#undef $2"
+ fi
+}
+
+# Conditionally add definitions to config.h and config.mk. Takes two parameters:
+# The first one can be set to 'yes' or 'no'. If 'yes' is used, then
+# the line "#define $2" is added to config.h and "$2 = 1" to config.mk.
+# Otherwise "#undef $2" is added to config.h and "# $2 = 1" to config.mk
+define_in_config_if_yes() {
+ if test "$1" = yes ; then
+ add_line_to_config_h "#define $2"
+ add_line_to_config_mk "$2 = 1"
+ else
+ add_line_to_config_h "#undef $2"
+ add_line_to_config_mk "# $2 = 1"
fi
}
@@ -178,21 +297,18 @@ add_to_config_mk_if_no() {
#
get_system_exe_extension() {
case $1 in
- mingw* | *os2-emx | wince)
- _exeext=".exe"
- ;;
arm-riscos)
_exeext=",ff8"
;;
- gp2xwiz-linux)
- _exeext=".wiz"
- ;;
- gp2x-linux)
- _exeext=".gp2x"
- ;;
- dreamcast | wii | gamecube | nds | psp | ps2)
+ dreamcast | ds | gamecube | n64 | ps2 | psp | wii)
_exeext=".elf"
;;
+ gph-linux)
+ _exeext=".gph"
+ ;;
+ mingw* | *os2-emx | wince)
+ _exeext=".exe"
+ ;;
*)
_exeext=""
;;
@@ -205,14 +321,19 @@ get_system_exe_extension() {
# Show the configure help line for an option
option_help() {
+ if test "${3}" != "" ; then
+ tmpopt_prefix="${3}"
+ else
+ tmpopt_prefix="--"
+ fi
tmpopt=`echo $1 | sed 's/_/-/g'`
- option=`echo "--${tmpopt} " | sed "s/\(.\{23\}\).*/\1/"`
+ option=`echo "${tmpopt_prefix}${tmpopt} " | sed "s/\(.\{23\}\).*/\1/"`
echo " ${option} ${2}"
}
# Show an error about an unknown option
option_error() {
- echo "error: unrecognised option: $ac_option
+ echo "error: unrecognized option: $ac_option
Try \`$0 --help' for more information." >&2
exit 1
}
@@ -226,6 +347,11 @@ echo "Configure run on" `date` > $TMPLOG
#
# Check any parameters we received
#
+# TODO:
+# * Change --disable-mad / --enable-mad to the way it's done in autoconf:
+# That is, --without-mad / --with-mad=/prefix/to/mad. Useful for people
+# who have Mad/Vorbis/ALSA installed in a non-standard locations.
+#
for parm in "$@" ; do
if test "$parm" = "--help" || test "$parm" = "-help" || test "$parm" = "-h" ; then
@@ -240,24 +366,44 @@ for parm in "$@" ; do
Usage: $0 [OPTIONS]...
Configuration:
- -h, --help display this help and exit
+ -h, --help display this help and exit
+ --backend=BACKEND backend to build (sdl, null) [sdl]
Installation directories:
- --prefix=DIR use this prefix for installing ResidualVM [/usr/local]
- --bindir=DIR directory to install the residualvm binary in [PREFIX/bin]
- --mandir=DIR directory to install the manpage in [PREFIX/share/man]
- --datadir=DIR directory to install the data files in [PREFIX/share]
- --libdir=DIR directory to install the plugins in [PREFIX/lib]
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [/usr/local]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [PREFIX]
+
+By default, \`make install' will install all the files in
+\`/usr/local/bin', \`/usr/local/lib' etc. You can specify
+an installation prefix other than \`/usr/local' 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]
+ --libdir=DIR object code libraries [EPREFIX/lib]
+ --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
+ --datadir=DIR read-only architecture-independent data
+ [DATAROOTDIR/residualvm]
+ --mandir=DIR man documentation [DATAROOTDIR/man]
+ --docdir=DIR documentation root [DATAROOTDIR/doc/residualvm]
Special configuration feature:
- --host=HOST cross-compile to target HOST (arm-linux, ...)
+ --host=HOST cross-compile to target HOST (arm-linux, ...)
Optional Features:
--disable-debug disable building with debugging symbols
--enable-Werror treat warnings as errors
- --enable-profiling enable building with gprof profile information
- --enable-release set flags to build release binary
- --enable-verbose-build enable regular echoing of commands during build process
+ --enable-release enable building in release mode (this activates
+ optimizations)
+ --enable-release-mode enable building in release mode (without optimizations)
+ --enable-optimizations enable optimizations
+ --enable-profiling enable profiling
+ --enable-verbose-build enable regular echoing of commands during build
+ process
Optional Libraries:
--with-ogg-prefix=DIR Prefix where libogg is installed (optional)
@@ -274,6 +420,8 @@ Optional Libraries:
--disable-flac disable FLAC support [autodetect]
--with-zlib-prefix=DIR Prefix where zlib is installed (optional)
+ --disable-zlib disable zlib (compression) support [autodetect]
+
Some influential environment variables:
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -290,8 +438,6 @@ EOF
fi
done # for parm in ...
-DEBFLAGS="-g"
-
for ac_option in $@; do
case "$ac_option" in
--enable-vorbis) _vorbis=yes ;;
@@ -302,7 +448,6 @@ for ac_option in $@; do
--disable-flac) _flac=no ;;
--enable-mad) _mad=yes ;;
--disable-mad) _mad=no ;;
-
--enable-verbose-build) _verbose_build=yes ;;
--with-ogg-prefix=*)
arg=`echo $ac_option | cut -d '=' -f 2`
@@ -335,20 +480,36 @@ for ac_option in $@; do
ZLIB_LIBS="-L$arg/lib"
;;
--enable-debug)
- # debug is enabled by default
+ _debug_build=yes
;;
--disable-debug)
- DEBFLAGS=""
+ _debug_build=no
;;
--enable-Werror)
CXXFLAGS="$CXXFLAGS -Werror"
;;
+ --enable-release-mode)
+ _release_build=yes
+ ;;
+ --disable-release-mode)
+ _release_build=no
+ ;;
--enable-release)
- DEBFLAGS="-O2 -Wuninitialized"
+ _release_build=yes
+ _optimizations=yes
+ ;;
+ --disable-release)
+ _release_build=no
+ _optimizations=no
+ ;;
+ --enable-optimizations)
+ _optimizations=yes
+ ;;
+ --disable-optimizations)
+ _optimizations=no
;;
--enable-profiling)
- CXXFLAGS="$CXXFLAGS -pg"
- LDFLAGS="$LDFLAGS -pg"
+ _enable_prof=yes
;;
--with-staticlib-prefix=*)
_staticlibpath=`echo $ac_option | cut -d '=' -f 2`
@@ -357,19 +518,28 @@ for ac_option in $@; do
_host=`echo $ac_option | cut -d '=' -f 2`
;;
--prefix=*)
- _prefix=`echo $ac_option | cut -d '=' -f 2`
+ prefix=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --exec-prefix=*)
+ exec_prefix=`echo $ac_option | cut -d '=' -f 2`
;;
--bindir=*)
- _bindir=`echo $ac_option | cut -d '=' -f 2`
+ bindir=`echo $ac_option | cut -d '=' -f 2`
;;
- --mandir=*)
- _mandir=`echo $ac_option | cut -d '=' -f 2`
+ --libdir=*)
+ libdir=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --datarootdir=*)
+ datarootdir=`echo $ac_option | cut -d '=' -f 2`
;;
--datadir=*)
- _datadir=`echo $ac_option | cut -d '=' -f 2`
+ datadir=`echo $ac_option | cut -d '=' -f 2`
;;
- --libdir=*)
- _libdir=`echo $ac_option | cut -d '=' -f 2`
+ --mandir=*)
+ mandir=`echo $ac_option | cut -d '=' -f 2`
+ ;;
+ --docdir=*)
+ docdir=`echo $ac_option | cut -d '=' -f 2`
;;
*)
option_error
@@ -377,17 +547,180 @@ for ac_option in $@; do
esac;
done;
-CXXFLAGS="$CXXFLAGS $DEBFLAGS"
-
guessed_host=`$_srcdir/config.guess`
get_system_exe_extension $guessed_host
NATIVEEXEEXT=$_exeext
case $_host in
+android | android-v7a)
+ _host_os=android
+ _host_cpu=arm
+ _host_alias=arm-linux-androideabi
+ ;;
+arm-riscos)
+ _host_os=riscos
+ _host_cpu=arm
+ ;;
+bada)
+ _host_os=bada
+ if test "$_debug_build" = yes; then
+ _host_cpu=i686
+ _host_alias=i686-mingw32
+ else
+ _host_cpu=arm
+ _host_alias=arm-samsung-nucleuseabi
+ fi
+ ;;
+caanoo)
+ _host_os=gph-linux
+ _host_cpu=arm
+ _host_alias=arm-none-linux-gnueabi
+ ;;
+dingux)
+ _host_os=linux
+ _host_cpu=mipsel
+ _host_alias=mipsel-linux
+ ;;
+dreamcast)
+ _host_os=dreamcast
+ _host_cpu=sh
+ _host_alias=sh-elf
+ CXXFLAGS="$CXXFLAGS -ml -m4-single-only"
+ LDFLAGS="$LDFLAGS -ml -m4-single-only"
+ ;;
+ds)
+ _host_os=ds
+ _host_cpu=arm
+ _host_alias=arm-eabi
+ ;;
+gamecube)
+ _host_os=gamecube
+ _host_cpu=ppc
+ _host_alias=powerpc-gekko
+ ;;
+gp2x)
+ _host_os=gph-linux
+ _host_cpu=arm
+ _host_alias=arm-open2x-linux
+ ;;
+gp2xwiz)
+ _host_os=gph-linux
+ _host_cpu=arm
+ _host_alias=arm-open2x-linux
+ ;;
i586-mingw32msvc)
_host_os=mingw32msvc
_host_cpu=i586
;;
+iphone)
+ _host_os=iphone
+ _host_cpu=arm
+ _host_alias=arm-apple-darwin9
+ ;;
+linupy)
+ _host_os=linux
+ _host_cpu=arm
+ ;;
+maemo)
+ _host_os=maemo
+ _host_cpu=arm
+ _host_alias=arm-linux
+
+ # The prefix is always the same on Maemo so we hardcode the default
+ # here. It is still possible to define a custom prefix which is
+ # needed when packaging the app with a user-specific app ID.
+ test "x$prefix" = xNONE && prefix=/opt/scummvm
+ # Maemo apps are installed into app-specific directories. The
+ # default directory structure of ScummVM makes no sense here so we
+ # hardcode Maemo specific directories here.
+ datarootdir='${prefix}/share'
+ datadir=/opt/scummvm/share
+ docdir='${datarootdir}/doc/scummvm'
+ ;;
+motoezx)
+ _host_os=linux
+ _host_cpu=arm
+ _host_alias=arm-linux-gnu
+ ;;
+motomagx)
+ _host_os=linux
+ _host_cpu=arm
+ _host_alias=arm-linux-gnueabi
+ ;;
+n64)
+ _host_os=n64
+ _host_cpu=mips
+ _host_alias=mips64
+ ;;
+neuros)
+ _host_os=linux
+ _host_cpu=arm
+ ;;
+openpandora)
+ _host_os=linux
+ _host_cpu=arm
+ _host_alias=arm-angstrom-linux-gnueabi
+ ;;
+ppc-amigaos)
+ _host_os=amigaos
+ _host_cpu=ppc
+ ;;
+ps2)
+ _host_os=ps2
+ _host_cpu=mips64r5900el
+ _host_alias=ee
+ ;;
+ps3)
+ _host_os=ps3
+ _host_cpu=ppc
+ _host_alias=powerpc64-ps3-elf
+
+ # The prefix is always the same on PS3 so we hardcode the default
+ # here. It is still possible to define a custom prefix which is
+ # needed when packaging the app with a user-specific app ID.
+ test "x$prefix" = xNONE && prefix=/dev_hdd0/game/SCUM12000/USRDIR
+ # PS3 apps are installed into app-specific directories. The
+ # default directory structure of ScummVM makes no sense here so we
+ # hardcode PS3 specific directories here.
+ datarootdir='${prefix}/data'
+ datadir='${datarootdir}'
+ docdir='${prefix}/doc'
+ ;;
+psp)
+ _host_os=psp
+ _host_cpu=mipsallegrexel
+ _host_alias=psp
+ ;;
+samsungtv)
+ _host_os=linux
+ _host_cpu=arm
+ _host_alias=arm-linux-gnueabi
+ ;;
+webos)
+ _host_os=webos
+ _host_cpu=arm
+ _host_alias=arm-none-linux-gnueabi
+ # The prefix is always the same on WebOS so we hardcode the default
+ # here. It is still possible to define a custom prefix which is
+ # needed when packaging the app with a user-specific app ID.
+ test "x$prefix" = xNONE && prefix=/media/cryptofs/apps/usr/palm/applications/org.residualvm.residualvm
+ # WebOS apps are installed into app-specific directories. The
+ # default directory structure of ScummVM makes no sense here so we
+ # hardcode WebOS specific directories here.
+ datarootdir='${prefix}/data'
+ datadir='${datarootdir}'
+ docdir='${prefix}/doc'
+ ;;
+wii)
+ _host_os=wii
+ _host_cpu=ppc
+ _host_alias=powerpc-gekko
+ ;;
+wince)
+ _host_os=wince
+ _host_cpu=arm
+ _host_alias=arm-mingw32ce
+ ;;
*)
if test -n "$_host"; then
guessed_host=`$_srcdir/config.sub $_host`
@@ -409,20 +742,56 @@ else
_windres=$_host_alias-windres
fi
+#
+# Determine extra build flags for debug and/or release builds
+#
+
+case $_host in
+caanoo | gp2x | gp2xwiz | openpandora | ps2)
+ if test "$_debug_build" = auto; then
+ # If you want to debug one of these platforms, use '--disable-release --enable-debug'
+ _debug_build=no
+ fi
+
+ if test "$_release_build" = auto; then
+ # Enable release build by default.
+ _release_build=yes
+ fi
+
+ if test "$_optimizations" = auto; then
+ # Enable optimizations by default.
+ _optimizations=yes
+ fi
+ ;;
+esac
+
+if test "$_debug_build" != no; then
+ # debug mode not explicitly disabled -> compile with -g
+ CXXFLAGS="$CXXFLAGS -g"
+fi
+
+if test "$_release_build" = yes; then
+ # Add a define, which indicates we are doing
+ # an build for a release version.
+ DEFINES="$DEFINES -DRELEASE_BUILD"
+fi
+
+
#
# Determine extension used for executables
#
-get_system_exe_extension $_host_os
+get_system_exe_extension $_host_os
+HOSTEXEPRE=
HOSTEXEEXT=$_exeext
#
# Determine separator used for $PATH
#
case $_host_os in
-os2-emx* )
+os2-emx*)
SEPARATOR=";"
;;
-* )
+*)
SEPARATOR=":"
;;
esac
@@ -431,6 +800,69 @@ esac
# Platform specific sanity checks
#
case $_host_os in
+android)
+ if test -z "$ANDROID_SDK"; then
+ echo "Please set ANDROID_SDK in your environment. export ANDROID_SDK=<path to Android SDK>"
+ exit 1
+ fi
+ if test -z "$ANDROID_NDK"; then
+ echo "Please set ANDROID_NDK in your environment. export ANDROID_NDK=<path to Android NDK>"
+ exit 1
+ fi
+ ;;
+bada)
+ if test -z "$BADA_SDK"; then
+ echo "Please set BADA_SDK in your environment. export BADA_SDK=<path to Bada SDK>"
+ exit 1
+ fi
+ ;;
+ds | gamecube | wii)
+ if test -z "$DEVKITPRO"; then
+ echo "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to devkitPRO>"
+ exit 1
+ fi
+ ;;
+n64)
+ if test -z "$N64SDK"; then
+ echo "Please set N64SDK in your environment. export N64SDK=<path to n64 sdk>"
+ exit 1
+ fi
+ ;;
+ps2)
+ if test -z "$PS2SDK"; then
+ echo "Please set PS2SDK in your environment. export PS2SDK=<path to ps2 sdk>"
+ exit 1
+ fi
+ ;;
+ps3)
+ if test -z "$PS3DEV"; then
+ echo "Please set PS3DEV in your environment. export PS3DEV=<path to ps3 toolchain>"
+ exit 1
+ fi
+ ;;
+psp)
+ if test -z "$PSPDEV"; then
+ PSPDEV=`psp-config --pspdev-path`
+ fi
+ # TODO: Should we also insist on a valid PSPDEV value?
+ if test -z "$PSPSDK"; then
+ PSPSDK=`psp-config --pspsdk-path`
+ fi
+ if test -z "$PSPSDK"; then
+ echo "Please set PSPSDK in your environment. export PSPSDK=<path to psp sdk>"
+ exit 1
+ fi
+ ;;
+webos)
+ if test -z "$WEBOS_SDK"; then
+ echo "Please set WEBOS_SDK in your environment. export WEBOS_SDK=<path to WebOS SDK>"
+ exit 1
+ fi
+ if test -z "$WEBOS_PDK"; then
+ echo "Please set WEBOS_PDK in your environment. export WEBOS_PDK=<path to WebOS PDK>"
+ exit 1
+ fi
+ ;;
*)
;;
esac
@@ -442,18 +874,20 @@ echo_n "Looking for C++ compiler... "
# Check whether the given command is a working C++ compiler
test_compiler() {
- cat <<EOF >tmp_cxx_compiler.cpp
+ cat > tmp_cxx_compiler.cpp << EOF
class Foo { int a; };
int main(int argc, char **argv) {
Foo *a = new Foo(); delete a; return 0;
}
EOF
+ echo "testing compiler: $1" >> "$TMPLOG"
+
if test -n "$_host"; then
# In cross-compiling mode, we cannot run the result
- eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$HOSTEXEEXT -c tmp_cxx_compiler.cpp" 2> /dev/null && rm -f tmp_cxx_compiler$HOSTEXEEXT tmp_cxx_compiler.cpp
+ eval "$1 $CXXFLAGS $LDFLAGS -o $TMPO.o -c tmp_cxx_compiler.cpp" 2> /dev/null && cc_check_clean tmp_cxx_compiler.cpp
else
- eval "$1 $CXXFLAGS $LDFLAGS -o tmp_cxx_compiler$HOSTEXEEXT tmp_cxx_compiler.cpp" 2> /dev/null && eval "./tmp_cxx_compiler$HOSTEXEEXT 2> /dev/null" && rm -rf tmp_cxx_compiler$HOSTEXEEXT tmp_cxx_compiler.dSYM tmp_cxx_compiler.cpp
+ eval "$1 $CXXFLAGS $LDFLAGS -o $TMPO$HOSTEXEEXT tmp_cxx_compiler.cpp" 2> /dev/null && eval "$TMPO$HOSTEXEEXT 2> /dev/null" && cc_check_clean tmp_cxx_compiler.cpp
fi
}
@@ -472,9 +906,12 @@ else
CXX=
for compiler in $compilers; do
if test_compiler $compiler; then
+ echo "success testing compiler: $compiler" >> "$TMPLOG"
CXX=$compiler
echo $CXX
break
+ else
+ echo "failure testing compiler: $compiler" >> "$TMPLOG"
fi
done
fi
@@ -492,10 +929,49 @@ LD=$CXX
#
echocheck "compiler version"
+# We first check whether we have an Intel compiler here, since the Intel compiler
+# can also fake itself as an gcc (to ease compatibility with common Linux etc.
+# programs).
+have_icc=no
+cc_check_define __INTEL_COMPILER && have_icc=yes
+
+if test "$have_icc" = yes; then
+ add_line_to_config_mk 'HAVE_ICC = 1'
+
+ # Make ICC error our on unknown command line options instead of printing
+ # a warning. This is for example required to make the -Wglobal-destructors
+ # detection work correctly.
+ CXXFLAGS="$CXXFLAGS -diag-error 10006,10148"
+fi
+
have_gcc=no
-cxx_version=`( $CXX -dumpversion ) 2>&1`
-if test "$?" -gt 0; then
- # TODO: Big scary warning about unsupported Compilers
+cc_check_define __GNUC__ && have_gcc=yes
+
+if test "$have_gcc" = yes; then
+ add_line_to_config_mk 'HAVE_GCC = 1'
+ _cxx_major=`gcc_get_define __GNUC__`
+ _cxx_minor=`gcc_get_define __GNUC_MINOR__`
+ cxx_version="`( $CXX -dumpversion ) 2>&1`"
+
+ if test -n "`gcc_get_define __clang__`"; then
+ add_line_to_config_mk 'HAVE_CLANG = 1'
+ fi
+
+ if test "$_cxx_major" -eq 2 && test "$_cxx_minor" -ge 95 || \
+ test "$_cxx_major" -gt 2 ; then
+ cxx_version="$cxx_version, ok"
+ cxx_verc_fail=no
+ else
+ cxx_version="$cxx_version, bad"
+ cxx_verc_fail=yes
+ fi
+elif test "$have_icc" = yes; then
+ cxx_version="`( $CXX -dumpversion ) 2>/dev/null`"
+ _cxx_major="`echo "${cxx_version}" | sed -ne 's/\([0-9][0-9]*\)\..*/\1/gp'`"
+ _cxx_minor="`echo "${cxx_version}" | sed -ne 's/[0-9][0-9]*\.\([0-9][0-9]*\)/\1/gp'`"
+ cxx_version="ICC $cxx_version, ok"
+else
+ # TODO: Big scary warning about unsupported compilers
cxx_version=`( $CXX -version ) 2>&1`
if test "$?" -eq 0; then
cxx_version="`echo "${cxx_version}" | sed -ne 's/^.*[^0-9]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/gp'`"
@@ -509,46 +985,15 @@ if test "$?" -gt 0; then
cxx_verc_fail=yes
echo found non-gcc compiler version ${cxx_version}
fi
-else
- add_line_to_config_mk 'HAVE_GCC = 1'
- have_gcc=yes
-fi
-if test "$have_gcc" = yes; then
- case $cxx_version in
- 2.95.[2-9]|2.95.[2-9][-.]*|3.[0-9]|3.[0-9].[0-9]|3.[0-9].[0-9][-.]*|4.[0-9]|4.[0-9].[0-9]|4.[0-9].[0-9][-.]*)
- _cxx_major=`echo $cxx_version | cut -d '.' -f 1`
- _cxx_minor=`echo $cxx_version | cut -d '.' -f 2`
- cxx_version="$cxx_version, ok"
- cxx_verc_fail=no
- ;;
- # whacky beos version strings
- 2.9-beos-991026*|2.9-beos-000224*)
- _cxx_major=2
- _cxx_minor=95
- cxx_version="$cxx_version, ok"
- cxx_verc_fail=no
- ;;
- 3_4)
- _cxx_major=3
- _cxx_minor=4
- ;;
- 'not found')
- cxx_verc_fail=yes
- ;;
- *)
- cxx_version="$cxx_version, bad"
- cxx_verc_fail=yes
- ;;
- esac
-else
case $_host_os in
irix*)
case $cxx_version in
7.4.4*)
- # We just assume this is SGI MipsPRO
+ # We just assume this is SGI MIPSpro
_cxx_major=7
_cxx_minor=4
+ cxx_verc_fail=no
add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MDupdate "$(*D)/$(DEPDIR)/$(*F).d"'
add_line_to_config_mk '-include Makedepend'
;;
@@ -558,16 +1003,18 @@ else
;;
esac
;;
- *)
+ *)
cxx_version="$cxx_version, bad"
cxx_verc_fail=yes
;;
esac
-
fi
echo "$cxx_version"
+#
+# Bail out now if no useable compiler was found.
+#
if test "$cxx_verc_fail" = yes ; then
echo
echo "The version of your compiler is not supported at this time"
@@ -575,34 +1022,107 @@ if test "$cxx_verc_fail" = yes ; then
exit 1
fi
+#
+# Setup compiler specific CXXFLAGS now that we know the compiler version.
+# Foremost, this means enabling various warnings.
+# In addition, we set CXX_UPDATE_DEP_FLAG for GCC >= 3.0 and for ICC.
+#
+if test "$have_gcc" = yes ; then
+ if test "$_cxx_major" -ge "3" ; then
+ case $_host_os in
+ # newlib-based system include files suppress non-C89 function
+ # declarations under __STRICT_ANSI__
+ amigaos* | android | bada | dreamcast | ds | gamecube | mingw* | n64 | psp | ps2 | ps3 | wii | wince )
+ ;;
+ *)
+ CXXFLAGS="$CXXFLAGS -ansi"
+ ;;
+ esac
+ CXXFLAGS="$CXXFLAGS -W -Wno-unused-parameter"
+ add_line_to_config_mk 'HAVE_GCC3 = 1'
+ add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
+ fi;
+
+ if test "$_cxx_major" -eq 4 && test "$_cxx_minor" -ge 3 || \
+ test "$_cxx_major" -gt 4 ; then
+ CXXFLAGS="$CXXFLAGS -Wno-empty-body"
+ else
+ CXXFLAGS="$CXXFLAGS -Wconversion"
+ fi;
+elif test "$have_icc" = yes ; then
+ add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
+fi;
+
+# By default, we add -pedantic to the CXXFLAGS to catch some potentially
+# non-portable constructs, like use of GNU extensions.
+# However, some platforms use GNU extensions in system header files, so
+# for these we must not use -pedantic.
+case $_host_os in
+android | gamecube | psp | wii | webos)
+ ;;
+*)
+ # ICC does not support pedantic, while GCC and clang do.
+ if test "$have_icc" = no ; then
+ CXXFLAGS="$CXXFLAGS -pedantic"
+ fi
+ ;;
+esac
+
+# If possible, we want to use -Wglobal-constructors
+# However, not all compilers support that, so check whether the active one does.
+echocheck "whether -Wglobal-constructors work"
+cat > $TMPC << EOF
+int main() { return 0; }
+EOF
+cc_check -Wglobal-constructors && _global_constructors=yes
+
+if test "$_global_constructors" = yes; then
+ CXXFLAGS="$CXXFLAGS -Wglobal-constructors"
+fi
+echo $_global_constructors
+
#
# Check for endianness
#
echo_n "Checking endianness... "
-cat <<EOF >tmp_endianness_check.cpp
-short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
-short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+cat > tmp_endianness_check.cpp << EOF
+unsigned short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+unsigned short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
void _ascii() { char* s = (char*) ascii_mm; s = (char*) ascii_ii; }
-short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
-short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+unsigned short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+unsigned short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
void _ebcdic() { char* s = (char*) ebcdic_mm; s = (char*) ebcdic_ii; }
int main() { _ascii (); _ebcdic (); return 0; }
EOF
-$CXX $CXXFLAGS -c -o tmp_endianness_check.o tmp_endianness_check.cpp
-if strings tmp_endianness_check.o | grep BIGenDianSyS >/dev/null; then
+$CXX $CXXFLAGS -c -o $TMPO.o tmp_endianness_check.cpp
+if strings $TMPO.o | grep BIGenDianSyS >/dev/null; then
_endian=big
-else
+elif strings $TMPO.o | grep LiTTleEnDian >/dev/null; then
_endian=little
fi
echo $_endian;
-rm -f tmp_endianness_check.o tmp_endianness_check.cpp
+cc_check_clean tmp_endianness_check.cpp
+
+case $_endian in
+ big)
+ add_line_to_config_h '#undef SCUMM_LITTLE_ENDIAN'
+ add_line_to_config_h '#define SCUMM_BIG_ENDIAN'
+ ;;
+ little)
+ add_line_to_config_h '#define SCUMM_LITTLE_ENDIAN'
+ add_line_to_config_h '#undef SCUMM_BIG_ENDIAN'
+ ;;
+ *)
+ exit 1
+ ;;
+esac
#
# Determine a data type with the given length
#
find_type_with_size() {
- for datatype in int short char long 'long long' unknown; do
- cat <<EOF >tmp_find_type_with_size.cpp
+ for datatype in int short char long "long long" unknown; do
+ cat > tmp_find_type_with_size.cpp << EOF
typedef $datatype ac__type_sizeof_;
int main() {
static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) == $1)];
@@ -610,37 +1130,49 @@ int main() {
return 0;
}
EOF
-if $CXX $CXXFLAGS -c -o tmp_find_type_with_size$HOSTEXEEXT tmp_find_type_with_size.cpp 2>/dev/null ; then
- break
-else
- if test "$datatype" = "unknown"; then
- echo "couldn't find data type with $1 bytes"
- exit 1
- fi
- continue
-fi
-done
-rm -f tmp_find_type_with_size$HOSTEXEEXT tmp_find_type_with_size.cpp
-echo $datatype
+ if $CXX $CXXFLAGS -c -o $TMPO.o tmp_find_type_with_size.cpp 2>/dev/null ; then
+ break
+ else
+ if test "$datatype" = "unknown"; then
+ echo "couldn't find data type with $1 bytes"
+ exit 1
+ fi
+ continue
+ fi
+ done
+ cc_check_clean tmp_find_type_with_size.cpp
+ echo $datatype
}
#
-# Determine a size of pointer type
+# Check whether the system is 32-bit
#
-find_pointer_size() {
- cat <<EOF >tmp_find_pointer_size.cpp
+pointer_is_32bit() {
+ cat > tmp_pointer_is_32bit.cpp << EOF
int main() {
- void *p;
- int v = (int)p;
+ static int test_array[1 - 2 * !(sizeof(void *) == 4)];
+ test_array[0] = 0;
return 0;
}
EOF
- $CXX $CXXFLAGS -c -o tmp_find_pointer_size$HOSTEXEEXT tmp_find_pointer_size.cpp 2>/dev/null
+ $CXX $CXXFLAGS -c -o $TMPO.o tmp_pointer_is_32bit.cpp 2>/dev/null
status=$?
- rm -f tmp_find_pointer_size$HOSTEXEEXT tmp_find_pointer_size.cpp
+ cc_check_clean tmp_pointer_is_32bit.cpp
return $status
}
+echo_n "Checking 64-bitness... "
+pointer_is_32bit
+if test $? -eq 0; then
+ type_ptr=int32
+ echo "no"
+ add_line_to_config_h "/* #define SCUMM_64BITS */"
+else
+ type_ptr=int64
+ echo "yes"
+ add_line_to_config_h "#define SCUMM_64BITS"
+fi
+
#
# Determine data type sizes
#
@@ -670,30 +1202,89 @@ if test $TMPR -eq 0; then
_def_64bit_type_signed="typedef signed $type_8_byte int64;"
_def_64bit_type_unsigned="typedef unsigned $type_8_byte uint64;"
fi
+# force cleanup after check for 8 bytes type
+cc_check_clean tmp_find_type_with_size.cpp
-echo_n "Target 64 bits... "
-find_pointer_size
-if test $? -eq 0; then
- echo "no"
- add_line_to_config_h "/* #define TARGET_64BITS */"
-else
- echo "yes"
- add_line_to_config_h "#define TARGET_64BITS"
-fi
+#
+# Check whether memory alignment is required
+#
+# For some CPU types, unaligned memory access is either not supported at
+# all (and so leads to a crash), requires a super-slow emulation via an
+# exception handler, or just results in incorrect results.
+# On the other hand, accessing data in a manner that works regardless of
+# alignment can be a lot slower than regular access, so we don't want
+# to use it if we don't have to.
+#
+# So we do the following: For CPU families where we know whether unaligned
+# access is safe & fast, we enable / disable unaligned access accordingly.
+# Otherwise, we just disable memory alignment.
+#
+# NOTE: In the past, for non-cross compiled builds, we would also run some code
+# which would try to test whether unaligned access worked or not. But this test
+# could not reliably determine whether unaligned access really worked in all
+# situations (and across different implementations of the target CPU arch), nor
+# whether it was fast (as opposed to slowly emulated by fault handlers). Hence,
+# we do not use this approach anymore.
+#
+# NOTE: The only kinds of unaligned access we allow are for 2 byte and 4
+# byte loads / stores. No promises are made for bigger sizes, such as 8
+# or 16 byte loads, for which architectures may behave differently than
+# for the smaller sizes.
+echo_n "Alignment required... "
+case $_host_cpu in
+ i[3-6]86 | x86_64 | ppc*)
+ # Unaligned access should work
+ _need_memalign=no
+ ;;
+ alpha* | arm* | bfin* | hp* | mips* | sh* | sparc* | ia64 | nv1*)
+ # Unaligned access is not supported or extremely slow.
+ _need_memalign=yes
+ ;;
+ *)
+ # Status of unaligned access is unknown, so assume the worst.
+ _need_memalign=yes
+ ;;
+esac
+echo "$_need_memalign"
+
+define_in_config_h_if_yes $_need_memalign 'SCUMM_NEED_ALIGNMENT'
#
-# Check whether we can use x86 asm routines
+# Check the CPU architecture
#
-echo_n "Compiling for x86... "
+echo_n "Checking host CPU architecture... "
case $_host_cpu in
- i386|i486|i586|i686|x86_64)
+ arm*)
+ echo "ARM"
+ define_in_config_if_yes yes 'USE_ARM_SCALER_ASM'
+ define_in_config_if_yes yes 'USE_ARM_SOUND_ASM'
+ define_in_config_if_yes yes 'USE_ARM_SMUSH_ASM'
+ define_in_config_if_yes yes 'USE_ARM_GFX_ASM'
+ define_in_config_if_yes yes 'USE_ARM_COSTUME_ASM'
+
+ DEFINES="$DEFINES -DARM_TARGET"
+ ;;
+ i[3-6]86)
+ echo "x86"
_have_x86=yes
+ define_in_config_h_if_yes $_have_x86 'HAVE_X86'
+ ;;
+ mips*)
+ echo "MIPS"
+ DEFINES="$DEFINES -DMIPS_TARGET"
+ ;;
+ ppc*)
+ echo "PowerPC"
+ DEFINES="$DEFINES -DPPC_TARGET"
+ ;;
+ x86_64)
+ echo "x86_64"
;;
*)
- _have_x86=no
+ echo "unknown ($_host_cpu)"
;;
esac
-echo "$_have_x86"
+
#
# Determine build settings
@@ -701,180 +1292,716 @@ echo "$_have_x86"
echo_n "Checking hosttype... "
echo $_host_os
case $_host_os in
- linux* | uclinux*)
- # When not cross-compiling, enable large file support, but don't
- # care if getconf doesn't exist or doesn't recognize LFS_CFLAGS.
- if test -z "$_host"; then
- CXXFLAGS="$CXXFLAGS $(getconf LFS_CFLAGS 2>/dev/null)"
- fi
- DEFINES="$DEFINES -DUNIX"
+ amigaos*)
+ LDFLAGS="$LDFLAGS -use-dynld"
+ LDFLAGS="$LDFLAGS -L/sdk/local/newlib/lib"
+ # We have to use 'long' for our 4 byte typedef because AmigaOS already typedefs (u)int32
+ # as (unsigned) long, and consequently we'd get a compiler error otherwise.
+ type_4_byte='long'
+ add_line_to_config_mk 'AMIGAOS = 1'
;;
- openbsd* | netbsd* | bsd* | sunos* | hpux*)
- DEFINES="$DEFINES -DUNIX"
-
+ android)
+ case $_host in
+ android)
+ CXXFLAGS="$CXXFLAGS -march=armv5te"
+ CXXFLAGS="$CXXFLAGS -mtune=xscale"
+ CXXFLAGS="$CXXFLAGS -msoft-float"
+ ;;
+ android-v7a)
+ CXXFLAGS="$CXXFLAGS -march=armv7-a"
+ CXXFLAGS="$CXXFLAGS -mfloat-abi=softfp"
+ CXXFLAGS="$CXXFLAGS -mfpu=vfp"
+ LDFLAGS="$LDFLAGS -Wl,--fix-cortex-a8"
+ ;;
+ esac
+ CXXFLAGS="$CXXFLAGS --sysroot=$ANDROID_NDK/platforms/android-4/arch-arm"
+ CXXFLAGS="$CXXFLAGS -fpic"
+ CXXFLAGS="$CXXFLAGS -ffunction-sections"
+ CXXFLAGS="$CXXFLAGS -funwind-tables"
+ if test "$_debug_build" = yes; then
+ CXXFLAGS="$CXXFLAGS -fno-omit-frame-pointer"
+ CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"
+ else
+ CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
+ CXXFLAGS="$CXXFLAGS -fstrict-aliasing"
+ fi
+ CXXFLAGS="$CXXFLAGS -finline-limit=300"
+ _optimization_level=-Os
+ CXXFLAGS="$CXXFLAGS -mthumb-interwork"
+ # FIXME: Why is the following in CXXFLAGS and not in DEFINES? Change or document this.
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5__"
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5T__"
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5E__"
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5TE__"
+ # supress 'mangling of 'va_list' has changed in GCC 4.4'
+ CXXFLAGS="$CXXFLAGS -Wno-psabi"
+ LDFLAGS="$LDFLAGS --sysroot=$ANDROID_NDK/platforms/android-4/arch-arm"
+ LDFLAGS="$LDFLAGS -mthumb-interwork"
+ add_line_to_config_mk "ANDROID_SDK = $ANDROID_SDK"
+ _seq_midi=no
;;
- freebsd*)
- DEFINES="$DEFINES -DUNIX"
- LDFLAGS="$LDFLAGS -L/usr/local/lib"
- CXXFLAGS="$CXXFLAGS -I/usr/local/include"
+ bada)
+ BADA_SDK_ROOT="`cygpath -m ${BADA_SDK}`"
+ add_line_to_config_mk "BADA_SDK = $BADA_SDK"
+ add_line_to_config_mk "BADA_SDK_ROOT = $BADA_SDK_ROOT"
+
+ # assume dependencies have been installed in cygwin's /usr/local
+ CYGWIN_USR_LOCAL="`cygpath -m /usr/local`"
+ LDFLAGS="$LDFLAGS -L${CYGWIN_USR_LOCAL}/lib"
+ CXXFLAGS="$CXXFLAGS -I${CYGWIN_USR_LOCAL}/include"
;;
beos*)
- DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
# Needs -lbind -lsocket for the timidity MIDI driver
LDFLAGS="-L/boot/home/config/lib"
CFLAGS="-I/boot/home/config/include"
CXXFLAGS="$CXXFLAGS -fhuge-objects"
- # FIXME: Please document why 'long' has to be used instead of int
- #type_4_byte='long'
+ LIBS="$LIBS -lbind -lsocket"
+ _seq_midi=no
;;
- solaris*)
- DEFINES="$DEFINES -DUNIX -DSOLARIS -DSYSTEM_NOT_SUPPORTING_D_TYPE"
- # Needs -lbind -lsocket for the timidity MIDI driver
- LIBS="$LIBS -lnsl -lsocket"
+ cygwin*)
+ echo ERROR: Cygwin building is not supported by ScummVM anymore. Consider using MinGW.
+ exit 1
+ ;;
+ darwin*)
+ DEFINES="$DEFINES -DMACOSX"
+ LIBS="$LIBS -framework AudioUnit -framework AudioToolbox -framework Carbon -framework CoreMIDI"
+ add_line_to_config_mk 'MACOSX = 1'
+
+ # Now we may have MacPorts or Fink installed
+ # Which put libraries and headers in non-standard places
+ # Checking them here
+
+ # MacPorts
+ # There is no way to get the prefix, so implementing a hack here
+ macport_version=`port version 2>/dev/null`
+ if test "$?" -eq 0; then
+ macport_version="`echo "${macport_version}" | sed -ne 's/Version: \([0-9]\.[0-9]\.[0-9]\)/\1/gp'`"
+ echo_n "You seem to be running MacPorts version ${macport_version}..."
+
+ macport_prefix=`which port`
+ # strip off /bin/port from /opt/local/bin/port
+ macport_prefix=`dirname ${macport_prefix}`
+ macport_prefix=`dirname ${macport_prefix}`
+
+ echo "adding ${macport_prefix} to paths"
+
+ LDFLAGS="-L${macport_prefix}/lib $LDFLAGS"
+ CXXFLAGS="-I${macport_prefix}/include $CXXFLAGS"
+ fi
+ ;;
+ dreamcast)
+ DEFINES="$DEFINES -D__DC__"
+ DEFINES="$DEFINES -DNONSTANDARD_PORT"
+ ;;
+ ds)
+ DEFINES="$DEFINES -D__DS__"
+ DEFINES="$DEFINES -DNDS"
+ DEFINES="$DEFINES -DARM9"
+ DEFINES="$DEFINES -DARM"
+ DEFINES="$DEFINES -DNONSTANDARD_PORT"
+ CXXFLAGS="$CXXFLAGS -isystem $DEVKITPRO/libnds/include"
+ CXXFLAGS="$CXXFLAGS -isystem $DEVKITPRO/devkitARM/arm-eabi/include"
+ CXXFLAGS="$CXXFLAGS -mcpu=arm9tdmi"
+ CXXFLAGS="$CXXFLAGS -mtune=arm9tdmi"
+ CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
+ CXXFLAGS="$CXXFLAGS -mthumb-interwork"
+ CXXFLAGS="$CXXFLAGS -ffunction-sections"
+ CXXFLAGS="$CXXFLAGS -fdata-sections"
+ CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"
+ CXXFLAGS="$CXXFLAGS -fuse-cxa-atexit"
+ LDFLAGS="$LDFLAGS -specs=ds_arm9.specs"
+ LDFLAGS="$LDFLAGS -mthumb-interwork"
+ LDFLAGS="$LDFLAGS -mno-fpu"
+ LDFLAGS="$LDFLAGS -Wl,-Map,map.txt"
+ if test "$_dynamic_modules" = no ; then
+ LDFLAGS="$LDFLAGS -Wl,--gc-sections"
+ else
+ LDFLAGS="$LDFLAGS -Wl,--no-gc-sections"
+ # TODO automate this required 2 step linking phase
+ # LDFLAGS="$LDFLAGS -Wl,--retain-symbols-file,ds.syms"
+ fi
+ LDFLAGS="$LDFLAGS -L$DEVKITPRO/libnds/lib"
+ LIBS="$LIBS -lnds9"
+ ;;
+ freebsd*)
+ LDFLAGS="$LDFLAGS -L/usr/local/lib"
+ CXXFLAGS="$CXXFLAGS -I/usr/local/include"
+ ;;
+ gamecube)
+ _optimization_level=-Os
+ CXXFLAGS="$CXXFLAGS -mogc"
+ CXXFLAGS="$CXXFLAGS -mcpu=750"
+ CXXFLAGS="$CXXFLAGS -meabi"
+ CXXFLAGS="$CXXFLAGS -mhard-float"
+ CXXFLAGS="$CXXFLAGS -ffunction-sections"
+ CXXFLAGS="$CXXFLAGS -fdata-sections"
+ CXXFLAGS="$CXXFLAGS -fmodulo-sched"
+ CXXFLAGS="$CXXFLAGS -fuse-cxa-atexit"
+ CXXFLAGS="$CXXFLAGS -I$DEVKITPRO/libogc/include"
+ # libogc is required to link the cc tests (includes _start())
+ LDFLAGS="$LDFLAGS -mogc"
+ LDFLAGS="$LDFLAGS -mcpu=750"
+ LDFLAGS="$LDFLAGS -L$DEVKITPRO/libogc/lib/cube"
+ LDFLAGS="$LDFLAGS -logc"
+ if test "$_dynamic_modules" = "yes" ; then
+ # retarded toolchain patch forces --gc-sections, overwrite it
+ LDFLAGS="$LDFLAGS -Wl,--no-gc-sections"
+ fi
+ ;;
+ haiku*)
+ DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ # Needs -lnetwork for the timidity MIDI driver
+ LIBS="$LIBS -lnetwork"
+ _seq_midi=no
;;
irix*)
- DEFINES="$DEFINES -DUNIX -DIRIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ DEFINES="$DEFINES -DIRIX"
+ DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
LIBS="$LIBS -lmd -lfastm -lm"
_ranlib=:
;;
- darwin*)
- DEFINES="$DEFINES -DUNIX -DMACOSX"
- add_line_to_config_mk 'MACOSX = 1'
+ linux* | uclinux*)
+ # When not cross-compiling, enable large file support, but don't
+ # care if getconf doesn't exist or doesn't recognize LFS_CFLAGS.
+ if test -z "$_host"; then
+ CXXFLAGS="$CXXFLAGS $(getconf LFS_CFLAGS 2>/dev/null)"
+ fi
+ ;;
+ maemo)
+ DEFINES="$DEFINES -DMAEMO"
;;
mingw*)
- DEFINES="$DEFINES -DWIN32 -D__USE_MINGW_ANSI_STDIO=0"
+ DEFINES="$DEFINES -DWIN32"
+ DEFINES="$DEFINES -D__USE_MINGW_ANSI_STDIO=0"
LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++"
- LIBS="$LIBS -lmingw32 -lwinmm"
+ LIBS="$LIBS -lmingw32 -lwinmm -lgdi32"
+ OBJS="$OBJS residualvmwinres.o"
+ add_line_to_config_mk 'WIN32 = 1'
;;
- cygwin*)
- echo ERROR: Cygwin building is not supported by ResidualVM anymore. Consider using MinGW.
- exit 1
+ mint*)
+ DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
;;
- os2-emx*)
- DEFINES="$DEFINES -DUNIX"
+ n64)
+ DEFINES="$DEFINES -D__N64__"
+ DEFINES="$DEFINES -DLIMIT_FPS"
+ DEFINES="$DEFINES -DNONSTANDARD_PORT"
+ DEFINES="$DEFINES -DDISABLE_COMMAND_LINE"
+ DEFINES="$DEFINES -DDISABLE_DEFAULT_SAVEFILEMANAGER"
+ DEFINES="$DEFINES -DDISABLE_DOSBOX_OPL"
+ DEFINES="$DEFINES -DDISABLE_FANCY_THEMES"
+ DEFINES="$DEFINES -DDISABLE_NES_APU"
+ DEFINES="$DEFINES -DDISABLE_SID"
+ DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
;;
- mint*)
- DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ ps2)
+ CXXFLAGS="$CXXFLAGS -G2"
+ DEFINES="$DEFINES -D_EE"
+ DEFINES="$DEFINES -D__PLAYSTATION2__"
;;
- amigaos*)
- CXXFLAGS="$CXXFLAGS -mcrt=newlib -mstrict-align -mcpu=750 -mtune=7400"
- LDFLAGS="$LDFLAGS -mcrt=newlib -use-dynld -Lsobjs:"
- # We have to use 'long' for our 4 byte typedef because AmigaOS already typedefs (u)int32
- # as (unsigned) long, and consequently we'd get a compiler error otherwise.
- type_4_byte='long'
+ ps3)
+ # Force use of SDL from the ps3 toolchain
+ _sdlpath="$PS3DEV/portlibs/ppu:$PS3DEV/portlibs/ppu/bin"
+
+ DEFINES="$DEFINES -DPLAYSTATION3"
+ CXXFLAGS="$CXXFLAGS -mcpu=cell -mminimal-toc -I$PS3DEV/psl1ght/ppu/include -I$PS3DEV/portlibs/ppu/include"
+ LDFLAGS="$LDFLAGS -L$PS3DEV/psl1ght/ppu/lib -L$PS3DEV/portlibs/ppu/lib"
+ add_line_to_config_mk 'PLAYSTATION3 = 1'
+ add_line_to_config_h "#define PREFIX \"${prefix}\""
;;
- # given this is a shell script assume some type of unix
- *)
- echo "WARNING: could not establish system type, assuming unix like"
- DEFINES="$DEFINES -DUNIX"
+ psp)
+ if test -d "$PSPDEV/psp/lib"; then
+ LDFLAGS="$LDFLAGS -L$PSPDEV/psp/lib"
+ fi
+ LDFLAGS="$LDFLAGS -L$PSPSDK/lib"
+ LDFLAGS="$LDFLAGS -specs=$_srcdir/backends/platform/psp/psp.spec"
+ _optimization_level=-O3
+ CXXFLAGS="$CXXFLAGS -I$PSPSDK/include"
+ # FIXME: Why is the following in CXXFLAGS and not in DEFINES? Change or document this.
+ CXXFLAGS="$CXXFLAGS -D_PSP_FW_VERSION=150"
+ ;;
+ solaris*)
+ DEFINES="$DEFINES -DSOLARIS"
+ DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
+ # Needs -lbind -lsocket for the timidity MIDI driver
+ LIBS="$LIBS -lnsl -lsocket"
+ ;;
+ webos)
+ CXXFLAGS="$CXXFLAGS --sysroot=$WEBOS_PDK/arm-gcc/sysroot"
+ CXXFLAGS="$CXXFLAGS -I$WEBOS_PDK/include"
+ CXXFLAGS="$CXXFLAGS -I$WEBOS_PDK/include/SDL"
+ CXXFLAGS="$CXXFLAGS -I$WEBOS_PDK/device/usr/include"
+ # These compiler options are needed to support the Palm Pixi
+ CXXFLAGS="$CXXFLAGS -mcpu=arm1136jf-s"
+ CXXFLAGS="$CXXFLAGS -mfpu=vfp "
+ CXXFLAGS="$CXXFLAGS -mfloat-abi=softfp"
+ LDFLAGS="$LDFLAGS -L$WEBOS_PDK/device/lib"
+ LDFLAGS="$LDFLAGS -L$WEBOS_PDK/device/usr/lib"
+ LDFLAGS="$LDFLAGS -Wl,--allow-shlib-undefined"
+ LDFLAGS="$LDFLAGS --sysroot=$WEBOS_PDK/arm-gcc/sysroot"
+ add_line_to_config_mk "WEBOS_SDK = $WEBOS_SDK"
+ _seq_midi=no
+ ;;
+ wii)
+ _optimization_level=-Os
+ CXXFLAGS="$CXXFLAGS -mrvl"
+ CXXFLAGS="$CXXFLAGS -mcpu=750"
+ CXXFLAGS="$CXXFLAGS -meabi"
+ CXXFLAGS="$CXXFLAGS -mhard-float"
+ CXXFLAGS="$CXXFLAGS -ffunction-sections"
+ CXXFLAGS="$CXXFLAGS -fdata-sections"
+ CXXFLAGS="$CXXFLAGS -fmodulo-sched"
+ CXXFLAGS="$CXXFLAGS -fuse-cxa-atexit"
+ CXXFLAGS="$CXXFLAGS -I$DEVKITPRO/libogc/include"
+ # libogc is required to link the cc tests (includes _start())
+ LDFLAGS="$LDFLAGS -mrvl"
+ LDFLAGS="$LDFLAGS -mcpu=750"
+ LDFLAGS="$LDFLAGS -L$DEVKITPRO/libogc/lib/wii"
+ LDFLAGS="$LDFLAGS -logc"
+ if test "$_dynamic_modules" = "yes" ; then
+ # retarded toolchain patch forces --gc-sections, overwrite it
+ LDFLAGS="$LDFLAGS -Wl,--no-gc-sections"
+ fi
+ ;;
+ wince)
+ _optimization_level=-O3
+ CXXFLAGS="$CXXFLAGS -fno-inline-functions"
+ CXXFLAGS="$CXXFLAGS -march=armv4"
+ CXXFLAGS="$CXXFLAGS -mtune=xscale"
+ DEFINES="$DEFINES -D_WIN32_WCE=300"
+ DEFINES="$DEFINES -D__ARM__"
+ DEFINES="$DEFINES -D_ARM_"
+ DEFINES="$DEFINES -DUNICODE"
+ DEFINES="$DEFINES -DFPM_DEFAULT"
+ DEFINES="$DEFINES -DNONSTANDARD_PORT"
+ DEFINES="$DEFINES -DWRAP_MALLOC"
+ DEFINES="$DEFINES -DWIN32"
+ DEFINES="$DEFINES -Dcdecl="
+ DEFINES="$DEFINES -D__cdecl__="
+ add_line_to_config_mk "WRAP_MALLOC = 1"
;;
esac
if test -n "$_host"; then
# Cross-compiling mode - add your target here if needed
- echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes"
+ echo "Cross-compiling to $_host"
case "$_host" in
- arm-linux|arm*-linux-gnueabi|arm-*-linux|*-angstrom-linux)
- DEFINES="$DEFINES -DUNIX"
- _need_memalign=yes
+ android | android-v7a)
+ # we link a .so as default
+ LDFLAGS="$LDFLAGS -shared"
+ LDFLAGS="$LDFLAGS -Wl,-Bsymbolic,--no-undefined"
+ HOSTEXEPRE=lib
+ HOSTEXEEXT=.so
+ _backend="android"
+ _port_mk="backends/platform/android/android.mk"
+ _build_scalers=no
+ _seq_midi=no
+ _mt32emu=no
+ _timidity=no
+ ;;
+ arm-linux|arm*-linux-gnueabi|arm-*-linux)
+ ;;
+ arm-riscos|linupy)
+ DEFINES="$DEFINES -DLINUPY"
+ ;;
+ bada)
+ _unix=yes
+ _backend="bada"
+ _port_mk="backends/platform/bada/bada.mk"
+ if test "$_debug_build" = yes; then
+ _arm_asm=no
+ else
+ _arm_asm=yes
+ fi
+ _taskbar=no
+ _build_scalers=no
+ _seq_midi=no
+ _mt32emu=no
+ _timidity=no
+ _vkeybd=yes
+ ;;
+ bfin*)
+ ;;
+ caanoo)
+ # This uses the GPH backend.
+ DEFINES="$DEFINES -DGPH_DEVICE"
+ DEFINES="$DEFINES -DCAANOO"
+ DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
+ if test "$_debug_build" = yes; then
+ DEFINES="$DEFINES -DGPH_DEBUG"
+ else
+ # Use -O3 on the Caanoo for non-debug builds.
+ _optimization_level=-O3
+ fi
+ CXXFLAGS="$CXXFLAGS -mcpu=arm926ej-s"
+ CXXFLAGS="$CXXFLAGS -mtune=arm926ej-s"
+ ASFLAGS="$ASFLAGS"
+ _backend="gph"
+ _build_hq_scalers=no
+ _savegame_timestamp=no
+ _vkeybd=yes
+ _seq_midi=no
+ _mt32emu=no
+ _timidity=no
+ _port_mk="backends/platform/gph/caanoo-bundle.mk"
;;
*darwin*)
_ranlib=$_host-ranlib
_strip=$_host-strip
;;
- ppc-amigaos)
- _endian=big
- _need_memalign=yes
- # FIXME: Please document why 'long' has to be used instead of int
- #type_4_byte='long'
+ dingux)
+ DEFINES="$DEFINES -DDINGUX"
+ DEFINES="$DEFINES -DDISABLE_DOSBOX_OPL"
+ DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
+ ASFLAGS="$ASFLAGS"
+ CXXFLAGS="$CXXFLAGS -msoft-float"
+ CXXFLAGS="$CXXFLAGS -mips32"
+ _backend="dingux"
+ _mt32emu=no
+ _vkeybd=yes
+ _build_hq_scalers=no
+ _keymapper=no
+ # Force disable vorbis on dingux, it has terrible performance compared to tremor
+ _vorbis=no
+ # Force disable seq on dingux, no way to use it and it would get enabled by default with configure
+ _seq_midi=no
+ _port_mk="backends/platform/dingux/dingux.mk"
+ ;;
+ dreamcast)
+ DEFINES="$DEFINES -DDISABLE_DEFAULT_SAVEFILEMANAGER"
+ DEFINES="$DEFINES -DDISABLE_TEXT_CONSOLE"
+ DEFINES="$DEFINES -DDISABLE_COMMAND_LINE"
+ if test "$_release_build" = yes; then
+ DEFINES="$DEFINES -DNOSERIAL"
+ fi
+ _optimization_level=-O3
+ CXXFLAGS="$CXXFLAGS -funroll-loops"
+ CXXFLAGS="$CXXFLAGS -fschedule-insns2"
+ CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
+ CXXFLAGS="$CXXFLAGS -fdelete-null-pointer-checks"
+ _backend="dc"
+ _build_scalers=no
+ _mad=yes
+ _zlib=yes
+ add_line_to_config_mk 'ronindir = /usr/local/ronin'
+ _port_mk="backends/platform/dc/dreamcast.mk"
+ ;;
+ ds)
+ DEFINES="$DEFINES -DDISABLE_COMMAND_LINE"
+ DEFINES="$DEFINES -DDISABLE_DEFAULT_SAVEFILEMANAGER"
+ DEFINES="$DEFINES -DDISABLE_DOSBOX_OPL"
+ DEFINES="$DEFINES -DDISABLE_FANCY_THEMES"
+ DEFINES="$DEFINES -DDISABLE_SID"
+ DEFINES="$DEFINES -DDISABLE_NES_APU"
+ DEFINES="$DEFINES -DDISABLE_TEXT_CONSOLE"
+ DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
+ DEFINES="$DEFINES -DSTREAM_AUDIO_FROM_DISK"
+ DEFINES="$DEFINES -DVECTOR_RENDERER_FORMAT=1555"
+ _backend="ds"
+ _build_scalers=no
+ _mt32emu=no
+ _port_mk="backends/platform/ds/ds.mk"
+ ;;
+ gamecube)
+ _backend="wii"
+ _build_scalers=no
+ _vkeybd=yes
+ _mt32emu=no
+ _port_mk="backends/platform/wii/wii.mk"
+ add_line_to_config_mk 'GAMECUBE = 1'
+ add_line_to_config_h '#define AUDIO_REVERSE_STEREO'
+ add_line_to_config_h '#define GAMECUBE'
+ add_line_to_config_h "/* #define DEBUG_WII_USBGECKO */"
+ add_line_to_config_h "/* #define DEBUG_WII_MEMSTATS */"
+ add_line_to_config_h "/* #define DEBUG_WII_GDB */"
+ add_line_to_config_h "#define USE_WII_DI"
+ ;;
+ gp2x)
+ # This uses the GPH backend.
+ DEFINES="$DEFINES -DGPH_DEVICE"
+ DEFINES="$DEFINES -DGP2X"
+ DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
+ if test "$_debug_build" = yes; then
+ DEFINES="$DEFINES -DGPH_DEBUG"
+ fi
+ CXXFLAGS="$CXXFLAGS -march=armv4t"
+ ASFLAGS="$ASFLAGS -mfloat-abi=soft"
+ LDFLAGS="$LDFLAGS -static"
+ _backend="gph"
+ _build_hq_scalers=no
+ _savegame_timestamp=no
+ _vkeybd=yes
+ _seq_midi=no
+ _mt32emu=no
+ _timidity=no
+ _port_mk="backends/platform/gph/gp2x-bundle.mk"
+ ;;
+ gp2xwiz)
+ # This uses the GPH backend.
+ DEFINES="$DEFINES -DGPH_DEVICE"
+ DEFINES="$DEFINES -DGP2XWIZ"
+ DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
+ if test "$_debug_build" = yes; then
+ DEFINES="$DEFINES -DGPH_DEBUG"
+ fi
+ CXXFLAGS="$CXXFLAGS -mcpu=arm926ej-s"
+ CXXFLAGS="$CXXFLAGS -mtune=arm926ej-s"
+ ASFLAGS="$ASFLAGS -mfloat-abi=soft"
+ _backend="gph"
+ _build_hq_scalers=no
+ _savegame_timestamp=no
+ _vkeybd=yes
+ _seq_midi=no
+ _mt32emu=no
+ _timidity=no
+ _port_mk="backends/platform/gph/gp2xwiz-bundle.mk"
+ ;;
+ iphone)
+ DEFINES="$DEFINES -DIPHONE"
+ _backend="iphone"
+ _build_hq_scalers=no
+ _seq_midi=no
;;
m68k-atari-mint)
- DEFINES="$DEFINES -DUNIX -DSYSTEM_NOT_SUPPORTING_D_TYPE"
- _endian=big
- _need_memalign=yes
- # FIXME: Please document why 'long' has to be used instead of int
- #type_4_byte='long'
+ DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
_ranlib=m68k-atari-mint-ranlib
_ar="m68k-atari-mint-ar cru"
+ _seq_midi=no
+ ;;
+ maemo)
+ _optimization_level=-Os
+ CXXFLAGS="$CXXFLAGS -mcpu=arm926ej-s"
+ CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
+ INCLUDES="$INCLUDES -I/usr/X11R6/include"
+ LIBS="$LIBS -lX11"
+ LIBS="$LIBS -L/usr/lib"
+
+ _backend="maemo"
+ _vkeybd=yes
+ _keymapper=yes
+ _build_hq_scalers=no
+ _mt32emu=no
+ _alsa=no
+ _mad=yes
+ _tremor=yes
+ _zlib=yes
;;
*mingw32*)
+ _sdlconfig=$_host-sdl-config
_windres=$_host-windres
_ar="$_host-ar cru"
_ranlib=$_host-ranlib
;;
- *)
- echo "WARNING: Unknown target, continuing with auto-detected values"
+ mips-sgi*)
+ LDFLAGS="$LDFLAGS -static-libgcc"
+ LIBS="$LIBS -laudio"
;;
- esac
-
-else
- #
- # Check whether memory alignment is required
- #
- echo_n "Alignment required... "
- case $_host_cpu in
- arm*)
- _need_memalign=yes
+ motoezx)
+ DEFINES="$DEFINES -DMOTOEZX"
+ ASFLAGS="$ASFLAGS -mfpu=vfp"
+ _backend="linuxmoto"
+ _build_hq_scalers=no
+ _mt32emu=no
+ _vkeybd=yes
+ _seq_midi=no
+ _port_mk="backends/platform/linuxmoto/linuxmoto.mk"
+ ;;
+ motomagx)
+ DEFINES="$DEFINES -DMOTOMAGX"
+ ASFLAGS="$ASFLAGS -mfpu=vfp"
+ _backend="linuxmoto"
+ _build_hq_scalers=no
+ _mt32emu=no
+ _vkeybd=yes
+ _seq_midi=no
+ _port_mk="backends/platform/linuxmoto/linuxmoto.mk"
;;
- alpha*)
- # Hardcode alignment requirements for Alpha processsors
- _need_memalign=yes
+ n64)
+ CXXFLAGS="$CXXFLAGS -mno-extern-sdata"
+ CXXFLAGS="$CXXFLAGS --param max-inline-insns-auto=20"
+ CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
+ CXXFLAGS="$CXXFLAGS -march=vr4300"
+ CXXFLAGS="$CXXFLAGS -mtune=vr4300"
+ CXXFLAGS="$CXXFLAGS -mhard-float"
+ LDFLAGS="$LDFLAGS -march=vr4300"
+ LDFLAGS="$LDFLAGS -mtune=vr4300"
+ LDFLAGS="$LDFLAGS -nodefaultlibs"
+ LDFLAGS="$LDFLAGS -nostartfiles"
+ LDFLAGS="$LDFLAGS -mno-crt0"
+ LDFLAGS="$LDFLAGS -L$N64SDK/hkz-libn64"
+ LDFLAGS="$LDFLAGS -L$N64SDK/lib"
+ LDFLAGS="$LDFLAGS -T n64ld_cpp.x -Xlinker -Map -Xlinker residualvm.map"
+ _backend="n64"
+ _mt32emu=no
+ _build_scalers=no
+ _savegame_timestamp=no
+ _translation=no
+ _keymapper=no
+ _text_console=no
+ _vkeybd=yes
+ _dynamic_modules=no
+ _plugins_default=static
+ # Force use of libmad, libtremor and zlib
+ _mad=no
+ _tremor=yes
+ _zlib=yes
+ _port_mk="backends/platform/n64/n64.mk"
+ ;;
+ neuros)
+ DEFINES="$DEFINES -DNEUROS"
+ _backend='null'
+ _build_hq_scalers=no
+ _mt32emu=no
+ ;;
+ openpandora)
+ DEFINES="$DEFINES -DOPENPANDORA"
+ DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
+ if test "$_release_build" = no; then
+ DEFINES="$DEFINES -DOP_DEBUG"
+ else
+ # Use -O3 on the OpenPandora for non-debug builds.
+ _optimization_level=-O3
+ fi
+ CXXFLAGS="$CXXFLAGS -march=armv7-a"
+ CXXFLAGS="$CXXFLAGS -mtune=cortex-a8"
+ CXXFLAGS="$CXXFLAGS -mfpu=neon"
+ ASFLAGS="$ASFLAGS -mfloat-abi=soft"
+ _backend="openpandora"
+ _build_hq_scalers=yes
+ _vkeybd=no
+ _mt32emu=no
+ _seq_midi=no
+ _port_mk="backends/platform/openpandora/op-bundle.mk"
+ ;;
+ ppc-amigaos)
+ ;;
+ ps2)
+ DEFINES="$DEFINES -DDISABLE_TEXT_CONSOLE"
+ DEFINES="$DEFINES -DDISABLE_COMMAND_LINE"
+ DEFINES="$DEFINES -DDISABLE_DOSBOX_OPL"
+ DEFINES="$DEFINES -DDISABLE_SID"
+ DEFINES="$DEFINES -DDISABLE_NES_APU"
+ _backend="ps2"
+ _build_scalers=no
+ _mt32emu=no
+ # HACK to enable mad & zlib (they are not properly detected due to linker issues).
+ # This trick doesn't work for tremor right now, as the PS2 port the resulting library
+ # libtremor, while our code later on expects it to be called libvorbisidec.
+ # TODO: Enable tremor, e.g. by adding -ltremor or by renaming the lib.
+ _mad=yes
+ _zlib=yes
+ # HACK to fix compilation of C source files for now.
+ add_line_to_config_mk 'CC = ee-gcc'
+ # HACK to fix linking for now. It seems ee-g++ does not handle linking correctly.
+ LD=ee-gcc
+
+ if test "$_debug_build" = yes; then
+ # TODO: Setup debug build properly
+ DEFINES="$DEFINES -D__PS2_DEBUG__"
+ #INCLUDES="$INCLUDES -I$(PS2GDB)/ee"
+ #LDFLAGS="$LDFLAGS -L$(PS2GDB)/lib"
+ LDFLAGS="$LDFLAGS -lps2gdbStub"
+ LDFLAGS="$LDFLAGS -lps2ip"
+ LDFLAGS="$LDFLAGS -ldebug"
+ else
+ # If not building for debug mode, strip binaries.
+ CXXFLAGS="$CXXFLAGS -s"
+ fi
;;
- sh*)
- # Hardcode alignment requirements for SH processsors.
- # While these can emulate unaligned memory access, this
- # emulation is rather slow.
- _need_memalign=yes
+ ps3)
+ _mt32emu=no
+ _timidity=no
+ _vkeybd=yes
;;
- mips*)
- # Hardcode alignment requirements for MIPS processsors.
- # While these can emulate unaligned memory access, this
- # emulation is rather slow.
- _need_memalign=yes
+ psp)
+ _backend="psp"
+ _build_scalers=no
+ _mt32emu=no
+ _port_mk="backends/platform/psp/psp.mk"
+ ;;
+ samsungtv)
+ DEFINES="$DEFINES -DSAMSUNGTV"
+ DEFINES="$DEFINES -DDISABLE_COMMAND_LINE"
+ ASFLAGS="$ASFLAGS -mfpu=vfp"
+ HOSTEXEEXT=".so"
+ _backend="samsungtv"
+ _mt32emu=no
+ _vkeybd=yes
+ ;;
+ webos)
+ _backend="webos"
+ _port_mk="backends/platform/webos/webos.mk"
+ _build_scalers=yes
+ _build_hq_scalers=no
+ _timidity=no
+ _mt32emu=no
+ _seq_midi=no
+ _vkeybd=no
+ _keymapper=yes
+ add_line_to_config_mk "HOST_COMPILER = `uname`"
+ ;;
+ wii)
+ _backend="wii"
+ _build_scalers=no
+ _vkeybd=yes
+ _port_mk="backends/platform/wii/wii.mk"
+ add_line_to_config_mk 'GAMECUBE = 0'
+ add_line_to_config_h '#define AUDIO_REVERSE_STEREO'
+ add_line_to_config_h "#define DEBUG_WII_USBGECKO"
+ add_line_to_config_h "/* #define DEBUG_WII_MEMSTATS */"
+ add_line_to_config_h "/* #define DEBUG_WII_GDB */"
+ add_line_to_config_h "#define USE_WII_DI"
+ add_line_to_config_h "#define USE_WII_SMB"
+ add_line_to_config_h "#define USE_WII_KBD"
+ ;;
+ wince)
+ LDFLAGS="$LDFLAGS -Wl,--stack,65536"
+ _tremolo=yes
+ _backend="wince"
+ _detectlang=yes
+ _mt32emu=no
+ _port_mk="backends/platform/wince/wince.mk"
;;
*)
- # Try to auto-detect....
- cat > $TMPC << EOF
-#include <stdlib.h>
-#include <signal.h>
-int main(int argc, char **argv) {
- unsigned char test[8] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 };
- signal(SIGBUS, exit);
- signal(SIGABRT, exit);
- signal(SIGSEGV, exit);
- if (*((unsigned int *)(test + 1)) != 0x55443322 && *((unsigned int *)(test + 1)) != 0x22334455) {
- return 1;
- }
- return 0;
-}
-EOF
- _need_memalign=yes
- cc_check && $TMPO$HOSTEXEEXT && _need_memalign=no
+ echo "WARNING: Unknown target, continuing with auto-detected values"
;;
esac
- echo "$_need_memalign"
fi
#
-# Add the results of the above checks to config.h
+# Determine whether host is POSIX compliant, or at least POSIX
+# compatible enough to support our POSIX code (including dlsym(),
+# mkdir() and some other APIs).
#
-case $_endian in
- big)
- add_line_to_config_h '/* #define SCUMM_LITTLE_ENDIAN */'
- add_line_to_config_h '#define SCUMM_BIG_ENDIAN'
+# TODO: Instead of basing this on the host name, we should really base
+# this on the presence of features (such as the dlsym and mkdir APIs).
+#
+echo_n "Checking if host is POSIX compliant... "
+case $_host_os in
+ amigaos* | cygwin* | dreamcast | ds | gamecube | mingw* | n64 | ps2 | ps3 | psp | wii | wince)
+ _posix=no
;;
- little)
- add_line_to_config_h '#define SCUMM_LITTLE_ENDIAN'
- add_line_to_config_h '/* #define SCUMM_BIG_ENDIAN */'
+ android | beos* | bsd* | darwin* | freebsd* | gph-linux | haiku* | hpux* | iphone | irix* | linux* | maemo | mint* | netbsd* | openbsd* | solaris* | sunos* | uclinux* | webos)
+ _posix=yes
+ ;;
+ os2-emx*)
+ _posix=yes # FIXME: Really???
;;
*)
- exit 1
+ # given this is a shell script, we might assume some type of posix.
+ # However, the host system might be a totally different one, so
+ # we can assume nothing about it.
+ # Indeed, as mentioned further above, we really should test for the
+ # presences of relevant APIs on the host anyway...
+ _posix=no
;;
esac
+echo $_posix
-add_to_config_h_if_yes $_have_x86 '#define HAVE_X86'
-
-add_to_config_h_if_yes $_need_memalign '#define SCUMM_NEED_ALIGNMENT'
+if test "$_posix" = yes ; then
+ DEFINES="$DEFINES -DPOSIX"
+ add_line_to_config_mk 'POSIX = 1'
+fi
#
# Check whether to enable a verbose build
@@ -883,13 +2010,91 @@ echo_n "Checking whether to have a verbose build... "
echo "$_verbose_build"
add_to_config_mk_if_yes "$_verbose_build" 'VERBOSE_BUILD = 1'
+
+#
+# If a specific optimization level was requested, enable optimizations
+#
+if test -n "$_optimization_level" ; then
+ # Ports will specify an optimization level and expect that to be enabled
+ if test "$_optimizations" != no ; then
+ _optimizations=yes
+ fi
+else
+ _optimization_level=$_default_optimization_level
+fi
+
+#
+# Check whether to enable optimizations
+#
+if test "$_optimizations" = yes ; then
+ # Enable optimizations. This also
+ # makes it possible to use -Wuninitialized, so let's do that.
+ CXXFLAGS="$CXXFLAGS $_optimization_level"
+ CXXFLAGS="$CXXFLAGS -Wuninitialized"
+fi
+
+
+#
+# Check whether integrated ELF loader support is requested
+#
+define_in_config_if_yes "$_elf_loader" 'USE_ELF_LOADER'
+
+if test "$_elf_loader" = yes; then
+ _plugin_prefix=""
+ _plugin_suffix=".plg"
+ _mak_plugins='
+PLUGIN_EXTRA_DEPS = $(EXECUTABLE)
+PLUGIN_LDFLAGS = -nostartfiles backends/plugins/elf/version.o -Wl,-q,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(srcdir)/backends/plugins/elf/plugin.syms
+PRE_OBJS_FLAGS := -Wl,--whole-archive
+POST_OBJS_FLAGS := -Wl,--no-whole-archive
+'"$_mak_plugins"
+fi
+
+#
+# Set up some common plugin settings in config.h and config.mk, if enabled
+#
+define_in_config_if_yes "$_dynamic_modules" 'DYNAMIC_MODULES'
+
+if test "$_dynamic_modules" = yes ; then
+ add_line_to_config_h "#define PLUGIN_PREFIX \"$_plugin_prefix\""
+ add_line_to_config_h "#define PLUGIN_SUFFIX \"$_plugin_suffix\""
+ add_line_to_config_mk "PLUGIN_PREFIX := $_plugin_prefix"
+ add_line_to_config_mk "PLUGIN_SUFFIX := $_plugin_suffix"
+fi
+
+
+#
+# Check whether integrated MT-32 emulator support is requested
+#
+define_in_config_if_yes "$_mt32emu" 'USE_MT32EMU'
+
+#
+# Check whether 16bit color support is requested
+#
+define_in_config_if_yes "$_16bit" 'USE_RGB_COLOR'
+
+#
+# Check whether save games use the current time as default description
+#
+define_in_config_if_yes "$_savegame_timestamp" 'USE_SAVEGAME_TIMESTAMP'
+
+#
+# Check whether to enable the (hq) scalers
+#
+if test "$_build_scalers" = no ; then
+ _build_hq_scalers=no
+fi
+define_in_config_if_yes "$_build_scalers" 'USE_SCALERS'
+
+define_in_config_if_yes "$_build_hq_scalers" 'USE_HQ_SCALERS'
+
#
# Check for math lib
#
cat > $TMPC << EOF
int main(void) { return 0; }
EOF
-cc_check $LDFLAGS $CXXFLAGS -lm && LDFLAGS="$LDFLAGS -lm"
+cc_check -lm && LIBS="$LIBS -lm"
#
# Check for Ogg Vorbis
@@ -901,42 +2106,48 @@ if test "$_vorbis" = auto ; then
#include <vorbis/codec.h>
int main(void) { vorbis_packet_blocksize(0,0); return 0; }
EOF
- cc_check $LDFLAGS $CXXFLAGS $OGG_CFLAGS $OGG_LIBS $VORBIS_CFLAGS $VORBIS_LIBS \
+ cc_check $OGG_CFLAGS $OGG_LIBS $VORBIS_CFLAGS $VORBIS_LIBS \
-lvorbisfile -lvorbis -logg && _vorbis=yes
fi
if test "$_vorbis" = yes ; then
- _def_vorbis='#define USE_VORBIS'
LIBS="$LIBS $OGG_LIBS $VORBIS_LIBS -lvorbisfile -lvorbis -logg"
INCLUDES="$INCLUDES $OGG_CFLAGS $VORBIS_CFLAGS"
-else
- _def_vorbis='#undef USE_VORBIS'
fi
-add_to_config_mk_if_yes "$_vorbis" 'USE_VORBIS = 1'
+define_in_config_if_yes "$_vorbis" 'USE_VORBIS'
echo "$_vorbis"
#
# Check for Tremor
#
echocheck "Tremor"
+if test "$_tremolo" = yes ; then
+ _tremor=yes
+fi
+
if test "$_tremor" = auto ; then
_tremor=no
cat > $TMPC << EOF
#include <tremor/ivorbiscodec.h>
int main(void) { vorbis_info_init(0); return 0; }
EOF
- cc_check $LDFLAGS $CXXFLAGS $TREMOR_CFLAGS $TREMOR_LIBS -lvorbisidec && \
+ cc_check $TREMOR_CFLAGS $TREMOR_LIBS -lvorbisidec && \
_tremor=yes
fi
if test "$_tremor" = yes && test "$_vorbis" = no; then
- _def_tremor='#define USE_TREMOR'
- _def_vorbis='#define USE_VORBIS'
- LIBS="$LIBS $TREMOR_LIBS -lvorbisidec"
+ add_line_to_config_h '#define USE_TREMOR'
+ add_line_to_config_h '#define USE_VORBIS'
+ if test "$_tremolo" = yes ; then
+ add_line_to_config_h '#define USE_TREMOLO'
+ LIBS="$LIBS $TREMOR_LIBS -ltremolo"
+ else
+ LIBS="$LIBS $TREMOR_LIBS -lvorbisidec"
+ fi
INCLUDES="$INCLUDES $TREMOR_CFLAGS"
else
if test "$_vorbis" = yes; then
_tremor="no (Ogg Vorbis/Tremor support is mutually exclusive)"
fi
- _def_tremor='#undef USE_TREMOR'
+ add_line_to_config_h '#undef USE_TREMOR'
fi
add_to_config_mk_if_yes "$_tremor" 'USE_TREMOR = 1'
echo "$_tremor"
@@ -952,25 +2163,22 @@ if test "$_flac" = auto ; then
int main(void) { return FLAC__STREAM_SYNC_LEN >> 30; /* guaranteed to be 0 */ }
EOF
if test "$_vorbis" = yes ; then
- cc_check $LDFLAGS $CXXFLAGS $FLAC_CFLAGS $FLAC_LIBS $OGG_CFLAGS $OGG_LIBS \
+ cc_check $FLAC_CFLAGS $FLAC_LIBS $OGG_CFLAGS $OGG_LIBS \
-lFLAC -logg && _flac=yes
else
- cc_check $LDFLAGS $CXXFLAGS $FLAC_CFLAGS $FLAC_LIBS \
+ cc_check $FLAC_CFLAGS $FLAC_LIBS \
-lFLAC && _flac=yes
fi
fi
if test "$_flac" = yes ; then
- _def_flac='#define USE_FLAC'
if test "$_vorbis" = yes ; then
LIBS="$LIBS $FLAC_LIBS $OGG_LIBS -lFLAC -logg"
else
LIBS="$LIBS $FLAC_LIBS -lFLAC"
fi
INCLUDES="$INCLUDES $FLAC_CFLAGS"
-else
- _def_flac='#undef USE_FLAC'
fi
-add_to_config_mk_if_yes "$_flac" 'USE_FLAC = 1'
+define_in_config_if_yes "$_flac" 'USE_FLAC'
echo "$_flac"
#
@@ -983,78 +2191,108 @@ if test "$_mad" = auto ; then
#include <mad.h>
int main(void) { return 0; }
EOF
- cc_check $LDFLAGS $CXXFLAGS $MAD_CFLAGS $MAD_LIBS -lmad && _mad=yes
+ cc_check $MAD_CFLAGS $MAD_LIBS -lmad && _mad=yes
fi
if test "$_mad" = yes ; then
- _def_mad='#define USE_MAD'
LIBS="$LIBS $MAD_LIBS -lmad"
INCLUDES="$INCLUDES $MAD_CFLAGS"
-else
- _def_mad='#undef USE_MAD'
fi
-add_to_config_mk_if_yes "$_mad" 'USE_MAD = 1'
+define_in_config_if_yes "$_mad" 'USE_MAD'
echo "$_mad"
#
# Check for ZLib
#
echocheck "zlib"
-_zlib=no
-
-cat > $TMPC << EOF
+if test "$_zlib" = auto ; then
+ _zlib=no
+ cat > $TMPC << EOF
#include <string.h>
#include <zlib.h>
int main(void) { return strcmp(ZLIB_VERSION, zlibVersion()); }
EOF
-
-cc_check $LDFLAGS $CXXFLAGS $ZLIB_CFLAGS $ZLIB_LIBS -lz && _zlib=yes
-
+ cc_check $ZLIB_CFLAGS $ZLIB_LIBS -lz && _zlib=yes
+fi
if test "$_zlib" = yes ; then
- _def_zlib='#define USE_ZLIB'
LIBS="$LIBS $ZLIB_LIBS -lz"
INCLUDES="$INCLUDES $ZLIB_CFLAGS"
-else
- echo
- echo "zlib library support required"
- exit 1
fi
-add_to_config_mk_if_yes "$_zlib" 'USE_ZLIB = 1'
+define_in_config_if_yes "$_zlib" 'USE_ZLIB'
echo "$_zlib"
#
# Figure out installation directories
#
-test -z "$_bindir" && _bindir="$_prefix/bin"
-test -z "$_mandir" && _mandir="$_prefix/share/man"
-test -z "$_datadir" && _datadir="$_prefix/share"
-test -z "$_libdir" && _libdir="$_prefix/lib"
+test "x$prefix" = xNONE && prefix=/usr/local
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+DEFINES="$DEFINES -DDATA_PATH=\\\"$datadir\\\""
+case $_backend in
+ openpandora)
+ # Add ../plugins as a path so plugins can be found when running from a .PND.
+ DEFINES="$DEFINES -DPLUGIN_DIRECTORY=\\\"../plugins\\\""
+ ;;
+ maemo | webos)
+ # The WebOS and Maemo apps want the plugins in the "lib" directory
+ # without a scummvm sub directory.
+ DEFINES="$DEFINES -DPLUGIN_DIRECTORY=\\\"$libdir\\\""
+ ;;
+ *)
+ DEFINES="$DEFINES -DPLUGIN_DIRECTORY=\\\"$libdir/residualvm\\\""
+ ;;
+esac
#
-# Do CXXFLAGS now that we know the compiler version
+# Set variables for profiling.
+# We need to do it here to prevent mess-ups with the tests e.g. on the PSP
#
-if test "$have_gcc" = yes ; then
- if test "$_cxx_major" -ge "3" ; then
- case $_host_os in
- # newlib-based system include files suppress non-C89 function
- # declarations under __STRICT_ANSI__
- mingw* | dreamcast | wii | gamecube | psp | wince | amigaos*)
- CXXFLAGS="$CXXFLAGS -W -Wno-unused-parameter"
- ;;
- *)
- CXXFLAGS="$CXXFLAGS -ansi -W -Wno-unused-parameter"
- ;;
- esac
- add_line_to_config_mk 'HAVE_GCC3 = 1'
- add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP'
- fi;
+if test "$_enable_prof" = yes ; then
+ CXXFLAGS="$CXXFLAGS -pg"
+ LDFLAGS="$LDFLAGS -pg"
+ DEFINES="$DEFINES -DENABLE_PROFILING"
+fi
+
+
+#
+# Some last-minute backend specific stuff, executed
+# after all of CXXFLAGS, LDFLAGS, LIBS etc. have been setup
+#
+case $_backend in
+ android)
+ # ssp at this point so the cxxtests link
+ if test "$_debug_build" = yes; then
+ CXXFLAGS="$CXXFLAGS -fstack-protector"
+ else
+ CXXFLAGS="$CXXFLAGS -fno-stack-protector"
+ fi
+
+ static_libs=''
+ system_libs=''
+ for lib in $LIBS; do
+ case $lib in
+ -lz|-lm|-ldl)
+ system_libs="$system_libs $lib"
+ ;;
+ *)
+ static_libs="$static_libs $lib"
+ ;;
+ esac
+ done
+
+ # -lgcc is carefully placed here - we want to catch
+ # all toolchain symbols in *our* libraries rather
+ # than pick up anything unhygenic from the Android libs.
+ LIBS="-Wl,-Bstatic $static_libs -Wl,-Bdynamic -lgcc $system_libs -llog -lGLESv1_CM"
+ ;;
+ n64)
+ # Move some libs down here, otherwise some symbols requires by libvorbis aren't found
+ # during linking stage
+ LIBS="$LIBS -lc -lgcc -lnosys"
+ ;;
+esac
+
- if test "$_cxx_major" -ge "4" && test "$_cxx_minor" -ge "3" ; then
- CXXFLAGS="$CXXFLAGS -Wno-empty-body"
- else
- CXXFLAGS="$CXXFLAGS -Wconversion"
- fi;
-fi;
echo
echo "Creating config.h"
@@ -1073,18 +2311,28 @@ typedef unsigned int uint;
typedef unsigned $type_1_byte uint8;
typedef unsigned $type_2_byte uint16;
typedef unsigned $type_4_byte uint32;
-$_def_64bit_type_signed
typedef signed $type_1_byte int8;
typedef signed $type_2_byte int16;
typedef signed $type_4_byte int32;
+EOF
+
+if test -n "$_def_64bit_type_unsigned" ; then
+cat >> config.h << EOF
+
+/* 64-bit stuff */
+$_def_64bit_type_signed
+#if defined(__APPLE__) && !defined(__ppc__)
+#ifndef _UINT64
+#define _UINT64
+$_def_64bit_type_unsigned
+#endif
+#else
$_def_64bit_type_unsigned
+#endif
+EOF
+fi
-/* Libs */
-$_def_vorbis
-$_def_tremor
-$_def_flac
-$_def_mad
-$_def_zlib
+cat >> config.h << EOF
#endif /* CONFIG_H */
EOF
@@ -1104,19 +2352,26 @@ AS := $_as
ASFLAGS := $ASFLAGS
WINDRES := $_windres
WINDRESFLAGS := $WINDRESFLAGS
+STAGINGPATH=$_stagingpath
WIN32PATH=$_win32path
AOS4PATH=$_aos4path
STATICLIBPATH=$_staticlibpath
MODULES += $MODULES
MODULE_DIRS += $MODULE_DIRS
+EXEPRE := $HOSTEXEPRE
EXEEXT := $HOSTEXEEXT
-PREFIX := $_prefix
-BINDIR := $_bindir
-MANDIR := $_mandir
-DATADIR := $_datadir
-LIBDIR := $_libdir
+prefix = $prefix
+exec_prefix = $exec_prefix
+bindir = $bindir
+libdir = $libdir
+datarootdir = $datarootdir
+datadir = $datadir
+mandir = $mandir
+docdir = $docdir
+
+$_config_mk_data
INCLUDES += $INCLUDES
OBJS += $OBJS
diff --git a/rules.mk b/rules.mk
index 6223c323c..5ab375476 100644
--- a/rules.mk
+++ b/rules.mk
@@ -1,5 +1,6 @@
###############################################
# Common build rules, used by the sub modules and their module.mk files
+#
###############################################
@@ -19,18 +20,42 @@ ifdef TOOL_EXECUTABLE
# TODO: Refactor this, so that even our master executable can use this rule?
################################################
TOOL-$(MODULE) := $(MODULE)/$(TOOL_EXECUTABLE)$(EXEEXT)
-$(TOOL-$(MODULE)): $(MODULE_OBJS-$(MODULE))
+$(TOOL-$(MODULE)): $(MODULE_OBJS-$(MODULE)) $(TOOL_DEPS)
$(QUIET_CXX)$(CXX) $(LDFLAGS) $+ -o $@
-# Reset TOOL_EXECUTABLE var
+# Reset TOOL_* vars
TOOL_EXECUTABLE:=
+TOOL_DEPS:=
-# Add to "tools" target
-tools: $(TOOL-$(MODULE))
+# Add to "devtools" target
+devtools: $(TOOL-$(MODULE))
-# Pseudo target for comfort, allows for "make tools/skycpt", etc.
+# Pseudo target for comfort, allows for "make devtools/skycpt", etc.
$(MODULE): $(TOOL-$(MODULE))
-clean-tools: clean-$(MODULE)
+clean-devtools: clean-$(MODULE)
+
+else
+ifdef PLUGIN
+################################################
+# Build rule for dynamic (loadable) plugins
+################################################
+PLUGIN-$(MODULE) := plugins/$(PLUGIN_PREFIX)$(notdir $(MODULE))$(PLUGIN_SUFFIX)
+$(PLUGIN-$(MODULE)): $(MODULE_OBJS-$(MODULE)) $(PLUGIN_EXTRA_DEPS)
+ $(QUIET)$(MKDIR) plugins
+ $(QUIET_PLUGIN)$(CXX) $(filter-out $(PLUGIN_EXTRA_DEPS),$+) $(PLUGIN_LDFLAGS) -o $@
+
+# Reset PLUGIN var
+PLUGIN:=
+
+# Add to "plugins" target
+plugins: $(PLUGIN-$(MODULE))
+
+# Add to the PLUGINS variable
+PLUGINS += $(PLUGIN-$(MODULE))
+
+# Pseudo target for comfort, allows for "make common", "make gui" etc.
+$(MODULE): $(PLUGIN-$(MODULE))
+clean-plugins: clean-$(MODULE)
else
################################################
@@ -50,6 +75,7 @@ $(MODULE_LIB-$(MODULE)): $(MODULE_OBJS-$(MODULE))
# Pseudo target for comfort, allows for "make common", "make gui" etc.
$(MODULE): $(MODULE_LIB-$(MODULE))
+endif # PLUGIN
endif # TOOL_EXECUTABLE
###############################################
@@ -59,6 +85,6 @@ endif # TOOL_EXECUTABLE
###############################################
clean: clean-$(MODULE)
clean-$(MODULE): clean-% :
- -$(RM) $(MODULE_OBJS-$*) $(MODULE_LIB-$*) $(TOOL-$*)
+ -$(RM) $(MODULE_OBJS-$*) $(MODULE_LIB-$*) $(PLUGIN-$*) $(TOOL-$*)
.PHONY: clean-$(MODULE) $(MODULE)
Commit: 0becc6b82757710ac195fc35f75df87bd2c0440e
https://github.com/scummvm/scummvm-tools/commit/0becc6b82757710ac195fc35f75df87bd2c0440e
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-03-18T18:48:35+01:00
Commit Message:
TOOLS: remove not needed defines
Changed paths:
configure
diff --git a/configure b/configure
index 6ab09f78f..c85484919 100755
--- a/configure
+++ b/configure
@@ -2033,61 +2033,6 @@ if test "$_optimizations" = yes ; then
CXXFLAGS="$CXXFLAGS -Wuninitialized"
fi
-
-#
-# Check whether integrated ELF loader support is requested
-#
-define_in_config_if_yes "$_elf_loader" 'USE_ELF_LOADER'
-
-if test "$_elf_loader" = yes; then
- _plugin_prefix=""
- _plugin_suffix=".plg"
- _mak_plugins='
-PLUGIN_EXTRA_DEPS = $(EXECUTABLE)
-PLUGIN_LDFLAGS = -nostartfiles backends/plugins/elf/version.o -Wl,-q,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(srcdir)/backends/plugins/elf/plugin.syms
-PRE_OBJS_FLAGS := -Wl,--whole-archive
-POST_OBJS_FLAGS := -Wl,--no-whole-archive
-'"$_mak_plugins"
-fi
-
-#
-# Set up some common plugin settings in config.h and config.mk, if enabled
-#
-define_in_config_if_yes "$_dynamic_modules" 'DYNAMIC_MODULES'
-
-if test "$_dynamic_modules" = yes ; then
- add_line_to_config_h "#define PLUGIN_PREFIX \"$_plugin_prefix\""
- add_line_to_config_h "#define PLUGIN_SUFFIX \"$_plugin_suffix\""
- add_line_to_config_mk "PLUGIN_PREFIX := $_plugin_prefix"
- add_line_to_config_mk "PLUGIN_SUFFIX := $_plugin_suffix"
-fi
-
-
-#
-# Check whether integrated MT-32 emulator support is requested
-#
-define_in_config_if_yes "$_mt32emu" 'USE_MT32EMU'
-
-#
-# Check whether 16bit color support is requested
-#
-define_in_config_if_yes "$_16bit" 'USE_RGB_COLOR'
-
-#
-# Check whether save games use the current time as default description
-#
-define_in_config_if_yes "$_savegame_timestamp" 'USE_SAVEGAME_TIMESTAMP'
-
-#
-# Check whether to enable the (hq) scalers
-#
-if test "$_build_scalers" = no ; then
- _build_hq_scalers=no
-fi
-define_in_config_if_yes "$_build_scalers" 'USE_SCALERS'
-
-define_in_config_if_yes "$_build_hq_scalers" 'USE_HQ_SCALERS'
-
#
# Check for math lib
#
Commit: b93c6a54a15eab25a367d26a0c33727e753bf68f
https://github.com/scummvm/scummvm-tools/commit/b93c6a54a15eab25a367d26a0c33727e753bf68f
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2012-04-07T13:08:42-07:00
Commit Message:
UNLAB: Add a check to make sure that the input file is long enough to extract the files. This makes it properly report errors when improperly copying the copy protected german version
Changed paths:
tools/unlab.cpp
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index ea3d3baf4..6ef5d8903 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -81,19 +81,24 @@ int main(int argc, char **argv) {
printf("No file specified\n");
exit(1);
}
+ const char *filename = argv[1];
- infile = fopen(argv[1], "rb");
+ infile = fopen(filename, "rb");
if (infile == 0) {
- printf("Can not open source file: %s\n", argv[1]);
+ printf("Can not open source file: %s\n", filename);
exit(1);
}
+ fseek(infile, 0, SEEK_END);
+ int filesize = ftell(infile);
+ fseek(infile, 0, SEEK_SET);
+
fread(&head.magic, 1, 4, infile);
fread(&head.magic2, 1, 4, infile);
uint32_t num, s_size, s_offset;
fread(&num, 1, 4, infile);
fread(&s_size, 1, 4, infile);
-
+
uint32_t typeTest = 0;
fread(&typeTest, 1, 4, infile);
if (typeTest == 0) { // First entry of the table has offset 0 for Grim
@@ -147,14 +152,21 @@ int main(int argc, char **argv) {
}
for (i = 0; i < head.num_entries; i++) {
char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
+
+ offset = READ_LE_UINT32(&entries[i].start);
+ uint32_t size = READ_LE_UINT32(&entries[i].size);
+
+ if (offset + size > filesize) {
+ printf("File \"%s\" past the end of lab \"%s\". Your game files may be corrupt.", fname, filename);
+ break;
+ }
+
createDirectoryStructure(fname);
outfile = fopen(fname, "wb");
if (!outfile) {
printf("Could not open file: %s\n", fname);
continue;
}
- offset = READ_LE_UINT32(&entries[i].start);
- uint32_t size = READ_LE_UINT32(&entries[i].size);
if (bufSize < size) {
bufSize = size;
char *newBuf = (char *)realloc(buf, bufSize);
Commit: 9d02719ed69a61e1f11c2702f5153f8244e78a84
https://github.com/scummvm/scummvm-tools/commit/9d02719ed69a61e1f11c2702f5153f8244e78a84
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-04-14T10:03:56+02:00
Commit Message:
ALL: update credits
Changed paths:
AUTHORS
COPYRIGHT
diff --git a/AUTHORS b/AUTHORS
index 527f0179e..95ae8a64b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -10,7 +10,9 @@ ResidualVM
James Brown - Core developer (retired)
Giulio Camuffo - Core developer
Pawel Kolodziejski - Core developer (suspended)
- Einar Johan T. Somaen - Initial EMI support, various code fixes and
+ Einar Johan T. Somaen - EMI support, various code fixes and
+ improvements
+ Joel Teichroeb - EMI support, various engine fixes and
improvements
Myst 3 Team:
@@ -22,6 +24,7 @@ ResidualVM
list. Contact us and we'll add you.
Grim:
+ Thomas Allen - Various engine code fixes and improvements
Torbjorn Andersson - Various code fixes
Ori Avtalion - Lipsync, LAF support, various code fixes
Robert Biro - Fixes to antiliasing
@@ -47,8 +50,6 @@ ResidualVM
Vincent Pelletier - Various engine improvements and code fixes
Daniel Schepler - Initial engine codebase, LUA support
Yaron Tausky - Fixes to subtitles
- Joel Teichroeb - Initial EMI support, various engine fixes and
- improvements
Julien Templier - create_project tool
Pino Toscano - Debian GNU/Linux package files
Lionel Ulmer - OpenGL optimisations
diff --git a/COPYRIGHT b/COPYRIGHT
index d56434bc3..2a462e13a 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -252,3 +252,4 @@ Xanathar "xanathar"
Grant Yeager "glo_kidd"
Benjamin W. Zale "junior_aepi"
Yotam Barnoy "bluddy"
+Tom Frost "TomFrost"
Commit: 9ae2412a2af670cbf17be28471dfeb349727d45b
https://github.com/scummvm/scummvm-tools/commit/9ae2412a2af670cbf17be28471dfeb349727d45b
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-16T15:11:16+02:00
Commit Message:
ALL: Add some entries in .gitignore
Changed paths:
.gitignore
diff --git a/.gitignore b/.gitignore
index d1b28158e..1f5dd0003 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,7 @@
+*~
+.*.swp
+.*.swo
*.a
*.o
*.exe
@@ -18,8 +21,8 @@ sklb2txt
til2bmp
unlab
vima
-luac
-patchex
+tools/luac/luac
+tools/patchex/patchex
.deps
/config.h
Commit: 9d3d4fc260b5ffcfdc36319b0ed8bac9a27e8ccb
https://github.com/scummvm/scummvm-tools/commit/9d3d4fc260b5ffcfdc36319b0ed8bac9a27e8ccb
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-16T15:11:16+02:00
Commit Message:
LUAC: Fix a bug
Changed paths:
tools/luac/dump.c
diff --git a/tools/luac/dump.c b/tools/luac/dump.c
index 0487fa146..14dd3ca5d 100644
--- a/tools/luac/dump.c
+++ b/tools/luac/dump.c
@@ -27,12 +27,9 @@ static void DumpLong(long i, FILE* D) {
/* LUA_NUMBER */
/* assumes sizeof(long)==4 and sizeof(float)==4 (IEEE) */
static void DumpFloat(float f, FILE* D) {
- byte *fdata = (byte *)(&f);
-
- fputc(fdata[3],D);
- fputc(fdata[2],D);
- fputc(fdata[1],D);
- fputc(fdata[0],D);
+ byte out[4];
+ WRITE_LE_UINT32(out, *(uint32*)(&f));
+ DumpBlock(out, 4, D);
}
static void DumpCode(TProtoFunc* tf, FILE* D) {
Commit: 4b0a47628f4d52adc6a7a1546dbb854abbe1383c
https://github.com/scummvm/scummvm-tools/commit/4b0a47628f4d52adc6a7a1546dbb854abbe1383c
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-16T15:11:17+02:00
Commit Message:
LUAC: Improve undump output format
Changed paths:
tools/luac/print.c
diff --git a/tools/luac/print.c b/tools/luac/print.c
index c1e74b8ab..1fc4870d3 100644
--- a/tools/luac/print.c
+++ b/tools/luac/print.c
@@ -8,7 +8,6 @@
#include <stdlib.h>
#include "luac.h"
-#ifdef DEBUG
void PrintConstant1(TProtoFunc* tf, int i)
{
TObject* o=tf->consts+i;
@@ -19,13 +18,13 @@ void PrintConstant1(TProtoFunc* tf, int i)
switch (ttype(o))
{
case LUA_T_NUMBER:
- printf("N " NUMBER_FMT "\n",nvalue(o)); /* LUA_NUMBER */
+ printf("N\t" NUMBER_FMT "\n", nvalue(o)); /* LUA_NUMBER */
break;
case LUA_T_STRING:
- printf("S %p\t\"%s\"\n",(void*)tsvalue(o),svalue(o));
+ printf("S\t\"%s\"\n", svalue(o));
break;
case LUA_T_PROTO:
- printf("F %p\n",(void*)tfvalue(o));
+ printf("F\n");
break;
default: /* cannot happen */
printf("? %d\n",ttype(o));
@@ -39,7 +38,6 @@ static void PrintConstants(TProtoFunc* tf)
printf("constants (%d):\n",n);
for (i=0; i<n; i++) PrintConstant1(tf,i);
}
-#endif
static void PrintConstant(TProtoFunc* tf, int i)
{
@@ -57,7 +55,7 @@ static void PrintConstant(TProtoFunc* tf, int i)
printf("\"%s\"",svalue(o));
break;
case LUA_T_PROTO:
- printf("function at %p",(void*)tfvalue(o));
+ printf("function");
break;
case LUA_T_NIL:
printf("(nil)");
@@ -185,8 +183,8 @@ static void PrintHeader(TProtoFunc* tf, TProtoFunc* Main, int at)
printf("\nmain of \"%s\" (%d bytes at %p)\n",fileName(tf),size,(void*)tf);
else if (Main)
{
- printf("\nfunction defined at \"%s\":%d (%d bytes at %p); used at ",
- fileName(tf),tf->lineDefined,size,(void*)tf);
+ printf("\nfunction defined at \"%s\":%d (%d bytes); used at ",
+ fileName(tf),tf->lineDefined,size);
if (IsMain(Main))
printf("main");
else
@@ -221,9 +219,7 @@ static void PrintFunction(TProtoFunc* tf, TProtoFunc* Main, int at)
PrintHeader(tf,Main,at);
PrintLocals(tf);
PrintCode(tf);
-#ifdef DEBUG
PrintConstants(tf);
-#endif
PrintFunctions(tf);
}
Commit: f061b8d2fa80677901a4c0d4efdf39e88d735a63
https://github.com/scummvm/scummvm-tools/commit/f061b8d2fa80677901a4c0d4efdf39e88d735a63
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-16T15:11:17+02:00
Commit Message:
DELUA: Remove a source of round errors by setting an higer precision
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 8000b1958..d9c52af2d 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -1251,6 +1251,9 @@ void decompile(std::ostream &os, TProtoFunc *tf, std::string indent_str,
std::ostringstream first_time;
std::multiset<Byte *> loc_vars;
+ //set the maximum precision, in order to avoid round errors with float numbers
+ os.precision(8);
+
// First, do a preliminary pass to see where local variables are defined
Decompiler dc;
dc.os = &first_time;
Commit: 3458d6577d53b24ee1429730004dea85f431a315
https://github.com/scummvm/scummvm-tools/commit/3458d6577d53b24ee1429730004dea85f431a315
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-16T15:11:44+02:00
Commit Message:
LUAC: Introduce rebase function
Changed paths:
A tools/luac/rebase.c
tools/luac/luac.c
tools/module.mk
diff --git a/tools/luac/luac.c b/tools/luac/luac.c
index b904b4868..459abc3a5 100644
--- a/tools/luac/luac.c
+++ b/tools/luac/luac.c
@@ -17,7 +17,9 @@
extern void DumpChunk(TProtoFunc* Main, FILE* D);
extern void PrintChunk(TProtoFunc* Main);
extern void OptChunk(TProtoFunc* Main);
+extern void rebase(TProtoFunc* Main, TProtoFunc* base);
+static void load_base_script(const char* fname);
static FILE* efopen(const char* name, const char* mode);
static void doit(int undump, const char* filename);
@@ -29,11 +31,12 @@ static int optimizing=0; /* optimize? */
static int parsing=0; /* parse only? */
static int verbose=0; /* tell user what is done */
static FILE* D; /* output file */
+static TProtoFunc *bs = NULL;
static void usage(void)
{
fprintf(stderr,"usage: "
- "luac [-c | -u] [-D name] [-d] [-l] [-o output] [-O] [-p] [-q] [-v] [-V] [files]\n"
+ "luac [-c | -u] [-D name] [-d] [-l] [-o output] [-O] [-p] [-q] [-v] [-V] [-b base] [files]\n"
" -c\tcompile (default)\n"
" -u\tundump\n"
" -d\tgenerate debugging information\n"
@@ -45,6 +48,7 @@ static void usage(void)
" -q\tquiet (default for -c)\n"
" -v\tshow version information\n"
" -V\tverbose\n"
+ " -b\tused the specified script as base for compiling (useful for patch, see diffr manual)\n"
" -\tcompile \"stdin\"\n"
);
exit(1);
@@ -55,6 +59,7 @@ static void usage(void)
int main(int argc, char* argv[])
{
const char* d = OUTPUT; /* output file name */
+ const char* base_s = NULL; /* base script file name */
int i;
lua_open();
for (i=1; i<argc; i++)
@@ -78,6 +83,8 @@ int main(int argc, char* argv[])
debugging=1;
else if (IS("-l")) /* list */
listing=1;
+ else if (IS("-b")) /* base script */
+ base_s=argv[++i];
else if (IS("-o")) /* output file */
d=argv[++i];
else if (IS("-O")) /* optimize */
@@ -105,30 +112,44 @@ int main(int argc, char* argv[])
--i; /* fake new argv[0] */
argc-=i;
argv+=i;
- if (dumping || parsing)
- {
- if (argc<2) usage();
- if (dumping)
- {
- for (i=1; i<argc; i++) /* play safe with output file */
- if (IS(d)) luaL_verror("will not overwrite input file \"%s\"",d);
- D=efopen(d,"wb"); /* must open in binary mode */
-#if ID_NUMBER==ID_NATIVE
- if (verbose) fprintf(stderr,"luac: warning: "
- "saving numbers in native format. file may not be portable.\n");
-#endif
- }
- for (i=1; i<argc; i++) doit(0,IS("-")? NULL : argv[i]);
- if (dumping) fclose(D);
- }
- if (undumping)
- {
- if (argc<2)
- doit(1,OUTPUT);
- else
- for (i=1; i<argc; i++) doit(1,IS("-")? NULL : argv[i]);
- }
- return 0;
+
+ if (dumping || parsing) {
+ if (argc < 2)
+ usage();
+
+ if (dumping) {
+ for (i = 1; i < argc; i++) /* play safe with output file */
+ if (IS(d))
+ luaL_verror("will not overwrite input file \"%s\"",d);
+ D = efopen(d,"wb"); /* must open in binary mode */
+ }
+
+ if (dumping && base_s != NULL)
+ load_base_script(base_s);
+
+ for (i = 1; i < argc; i++)
+ doit(0, IS("-")? NULL : argv[i]);
+ if (dumping)
+ fclose(D);
+ }
+
+ if (undumping) {
+ if (argc < 2)
+ doit(1, OUTPUT);
+ else
+ for (i = 1; i < argc; i++)
+ doit(1,IS("-")? NULL : argv[i]);
+ }
+ return 0;
+}
+
+static void load_base_script(const char* fname) {
+ FILE* f;
+ ZIO z;
+ f = efopen(fname, "rb");
+ zFopen(&z,f,fname);
+ bs = luaU_undump1(&z);
+ fclose(f);
}
static void do_compile(ZIO* z)
@@ -137,6 +158,7 @@ static void do_compile(ZIO* z)
if (optimizing) lua_debug=0; /* set debugging before parsing */
if (debugging) lua_debug=1;
Main=luaY_parser(z);
+ if (bs) rebase(Main, bs);
if (optimizing) OptChunk(Main);
if (listing) PrintChunk(Main);
if (dumping) DumpChunk(Main,D);
diff --git a/tools/luac/rebase.c b/tools/luac/rebase.c
new file mode 100644
index 000000000..18bb028e5
--- /dev/null
+++ b/tools/luac/rebase.c
@@ -0,0 +1,228 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "luac.h"
+#include "lmem.h"
+#include "lstring.h"
+
+static const Opcode Info[]= /* ORDER lopcodes.h */
+{
+#include "opcode.h"
+};
+
+int increase_const_list(TProtoFunc* func);
+void uniform_const_list(TProtoFunc* func, TProtoFunc* base);
+void rec_bytecode(TProtoFunc* func, int* inst);
+int num_opcodes(TProtoFunc* tf);
+void fix_op(Opcode *op);
+bool cmp(const TObject *a, const TObject *b);
+
+/*Rebase a function upon another to reduce the differences
+ The main requiment is that the functions order still unchanged
+ Don't delete useless functions and add new functions as last, or in
+ another file*/
+void rebase(TProtoFunc* func, TProtoFunc* base) {
+ //Set the right filename and line number
+ //luaS_free(func->fileName);
+ func->lineDefined = base->lineDefined;
+ func->fileName = base->fileName;
+
+ //Uniformize the const list in order to reduce the differences
+ uniform_const_list(func, base);
+
+ //Recursively rebase nested functions
+ //It assumes that the subfunctions has the same index
+ for (int j = 0; j < func->nconsts; ++j)
+ if (ttype(&func->consts[j]) == LUA_T_PROTO && ttype(&base->consts[j]) == LUA_T_PROTO)
+ rebase(tfvalue(&func->consts[j]), tfvalue(&base->consts[j]));
+}
+
+void uniform_const_list(TProtoFunc* func, TProtoFunc* base) {
+ int i, j, k;
+
+ //Part1: Add back the deleted constant into the new function
+ int max_const = func->nconsts;
+ for (i = 0; i < base->nconsts; ++i) {
+ //Ignore functions
+ if (ttype(&base->consts[i]) == LUA_T_PROTO)
+ continue;
+
+ for (j = 0; j < func->nconsts; ++j)
+ if (cmp(&base->consts[i], &func->consts[j]))
+ break;
+
+ if (j == func->nconsts) { //Const not found, re-add it
+ if (func->nconsts + 1 >= max_const)
+ max_const = increase_const_list(func);
+ ++func->nconsts;
+ ttype(&func->consts[func->nconsts - 1]) = ttype(&base->consts[i]);
+ assert(ttype(&base->consts[i]) == LUA_T_NUMBER || ttype(&base->consts[i]) == LUA_T_STRING);
+ if (ttype(&base->consts[i]) == LUA_T_NUMBER)
+ nvalue(&func->consts[func->nconsts - 1]) = nvalue(&base->consts[i]);
+ else if (ttype(&base->consts[i]) == LUA_T_STRING)
+ tsvalue(&func->consts[func->nconsts - 1]) = tsvalue(&base->consts[i]);
+ }
+ }
+
+ //Part2: Scan the const list and search the right position by comparing the
+ //current element with the const list of base function
+ int *inst;
+ TObject *new_const_list;
+ bool *already_used;
+
+ inst = luaM_newvector(func->nconsts, int);
+ new_const_list = luaM_newvector(func->nconsts, TObject);
+ already_used = luaM_newvector(base->nconsts, bool);
+ for (i = 0; i < base->nconsts; ++i)
+ already_used[i] = false;
+
+ k = func->nconsts;
+ assert(func->nconsts >= base->nconsts);
+ for (j = 0; j < func->nconsts; ++j) {
+ for (i = 0; i < base->nconsts; ++i)
+ if (!already_used[i] && cmp(&base->consts[i], &func->consts[j]))
+ break;
+
+ if (i != base->nconsts) {
+ inst[j] = i;
+ already_used[i] = true;
+ } else
+ inst[j] = --k; //if there is a new element, put it in the end of the list
+
+ assert(inst[j] < func->nconsts);
+ new_const_list[inst[j]] = func->consts[j];
+ }
+ luaM_free(func->consts);
+ luaM_free(already_used);
+ func->consts = new_const_list;
+
+ //Part3: Modify bytecode in order to use new constant list
+ rec_bytecode(func, inst);
+ luaM_free(inst);
+}
+
+void rec_bytecode(TProtoFunc* func, int* inst) {
+ int n_op = num_opcodes(func);
+ int i, newsize;
+ Opcode *opcode_list = luaM_newvector(n_op, Opcode);
+
+ Byte* p = func->code;
+
+ //Change const index
+ i = 0;
+ newsize = 0;
+ while (1) {
+ p += INFO(func, p, &opcode_list[i]);
+ Opcode &op = opcode_list[i];
+
+ //Change const index, if needed
+ if (op.op_class == PUSHCONSTANT ||
+ op.op_class == GETGLOBAL ||
+ op.op_class == SETGLOBAL ||
+ op.op_class == GETDOTTED ||
+ op.op_class == PUSHSELF)
+ if (op.arg != inst[op.arg]) {
+ op.arg = inst[op.arg];
+ fix_op(&op);
+ }
+
+ newsize += op.size;
+ ++i;
+ if (op.op == ENDCODE)
+ break;
+ }
+
+ luaM_free(func->code);
+ Byte *code = (Byte*)luaM_malloc(newsize);
+ func->code = code;
+
+ //Compile bytecode
+ Byte out[4];
+
+ //Out stacksize and arguments number
+ code[0] = (byte)opcode_list[0].arg;
+ if (opcode_list[1].op == VARARGS)
+ code[1] = (byte)opcode_list[1].arg + ZEROVARARG;
+ else
+ code[1] = (byte)opcode_list[1].arg;
+ code += 2;
+
+ for (i = 2; i < n_op; ++i) {
+ Opcode &op = opcode_list[i];
+
+ //Out opcode
+ out[0] = (byte)op.op;
+
+ //Out args
+ if (op.op == SETLIST || op.op == CLOSURE || op.op == CALLFUNC) {
+ out[1] = (byte)op.arg;
+ out[2] = (byte)op.arg2;
+ }
+ else if (op.size == 2)
+ out[1] = (byte)op.arg;
+ else if (op.size >= 3)
+ WRITE_LE_UINT16(out + 1, op.arg);
+ if (op.op == SETLISTW)
+ out[3] = (byte)op.arg2;
+
+ memcpy(code, out, op.size);
+ code += op.size;
+ }
+
+ luaM_free(opcode_list);
+}
+
+//Works only on opcodes that access to constant list
+//Don't use with others opcodes!
+void fix_op(Opcode *op) {
+ //Fix opcode
+ if (op->arg < 8) //built-in paramter
+ op->op = op->op_class + op->arg + 1;
+ else if (op->arg < 256) //byte parameter
+ op->op = op->op_class;
+ else //word parameter
+ op->op = op->op_class + 9;
+
+ //Fix size and name
+ op->size = Info[op->op].size;
+ op->name = Info[op->op].name;
+}
+
+int num_opcodes(TProtoFunc* tf) {
+ Byte* code = tf->code;
+ Byte* p = code;
+ int i = 0;
+ while (1) {
+ Opcode OP;
+ p+=INFO(tf, p, &OP);
+ ++i;
+ if (OP.op == ENDCODE)
+ break;
+ }
+
+ return i;
+}
+
+bool cmp(const TObject *a, const TObject *b) {
+ if (ttype(a) != ttype(b))
+ return false;
+
+ if (ttype(a) == LUA_T_PROTO)
+ return true;
+
+ if (ttype(a) == LUA_T_NUMBER)
+ if (nvalue(a) == nvalue(b))
+ return true;
+
+ if (ttype(a) == LUA_T_STRING)
+ if (strncmp(svalue(a), svalue(b), tsvalue(a)->u.s.len) == 0)
+ return true;
+
+ return false;
+}
+
+//Increase by one the const list count
+int increase_const_list(TProtoFunc* func) {
+ return luaM_growvector(&func->consts, func->nconsts, TObject,
+ constantEM, MAX_WORD);
+}
diff --git a/tools/module.mk b/tools/module.mk
index 0a685615b..15dc7088a 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -62,8 +62,9 @@ tools/luac/luac$(EXEEXT):
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/opcode.o tools/luac/opcode.c
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/opt.o tools/luac/opt.c
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/print.o tools/luac/print.c
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/rebase.o tools/luac/rebase.c
$(MKDIR) tools/luac/$(DEPDIR)
- $(CXX) $(CFLAGS) tools/luac/dump.o tools/luac/luac.o tools/luac/opcode.o tools/luac/opt.o tools/luac/print.o -Wall -L$(srcdir)/tools/lua -llua -o $@ $< $(LDFLAGS)
+ $(CXX) $(CFLAGS) tools/luac/dump.o tools/luac/luac.o tools/luac/opcode.o tools/luac/opt.o tools/luac/print.o tools/luac/rebase.o -Wall -L$(srcdir)/tools/lua -llua -o $@ $< $(LDFLAGS)
tools/mat2ppm$(EXEEXT): $(srcdir)/tools/mat2ppm.cpp
$(MKDIR) tools/$(DEPDIR)
Commit: c2cc139c89c51560cf206700cf4e0e9b63b102e4
https://github.com/scummvm/scummvm-tools/commit/c2cc139c89c51560cf206700cf4e0e9b63b102e4
Author: PaweÅ KoÅodziejski (aquadran at xtr.net.pl)
Date: 2012-04-16T10:22:58-07:00
Commit Message:
Merge pull request #24 from YakBizzarro/luac-diff2
LUAC: Add rebase function
Changed paths:
A tools/luac/rebase.c
.gitignore
tools/delua.cpp
tools/luac/dump.c
tools/luac/luac.c
tools/luac/print.c
tools/module.mk
Commit: d2fee8f0a12e8f75cdcc559925de6a94bb4b5fbe
https://github.com/scummvm/scummvm-tools/commit/d2fee8f0a12e8f75cdcc559925de6a94bb4b5fbe
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2012-04-17T15:30:53+02:00
Commit Message:
ALL: update copyrights
Changed paths:
COPYRIGHT
diff --git a/COPYRIGHT b/COPYRIGHT
index 2a462e13a..7b6997518 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -4,6 +4,7 @@ Copyright (C) 2003-2012 by the following:
If you have contributed to this project then you deserve to be on this
list. Contact us (see: AUTHORS) and we'll add you.
+Thomas Allen
Torbjorn Andersson
Ori Avtalion
Robert Biro
@@ -19,10 +20,12 @@ Matthew Hoops
Erich Hoover
Max Horn
Travis Howell
+Guillem Jover
Filippos Karapetis
Pawel Kolodziejski
Joost Peters
George Macon
+Josh Matthews
Matthieu Milan
Christian Neumair
Vincent Pelletier
Commit: ad0dfc7ed97be0e4455932782ff910e777974dbc
https://github.com/scummvm/scummvm-tools/commit/ad0dfc7ed97be0e4455932782ff910e777974dbc
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-18T09:31:06+02:00
Commit Message:
MKLAB: Lab files has the same version both in Grim and Emi
Changed paths:
tools/mklab.cpp
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index 8d96c2c4d..4fd0b4708 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -220,12 +220,7 @@ int main(int argc, char **argv) {
}
fwrite("LABN", 1, 4, outfile);
- if (g_type == GT_GRIM) {
- fwrite(" ", 1, 4, outfile); //version
- } else {
- //EMI expects this as the version number.
- fwrite("\x00\x00\x01\x00", 1, 4, outfile);
- }
+ fwrite("\x00\x00\x01\x00", 1, 4, outfile); //version
writeUint32(outfile, head.num_entries);
writeUint32(outfile, head.string_table_size);
Commit: edaa41c7ff15680dd7afbd13561cef878350b11d
https://github.com/scummvm/scummvm-tools/commit/edaa41c7ff15680dd7afbd13561cef878350b11d
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-18T10:04:54+02:00
Commit Message:
MKLAB: Fix a segfault
Changed paths:
tools/mklab.cpp
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index 4fd0b4708..b53cd8642 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -141,7 +141,7 @@ static void createEntries(DIR *dir, lab_entry *entries, char *str_table, const c
entry.reserved = 0; //What is this??
char *path = appendPath(dirfile->d_name, dirname);
- char *name = strchr(path, '/') + 1;
+ char *name = strrchr(path, '/') + 1;
strcpy(str_offset, name);
str_offset[strlen(name)] = 0;
name_offset += strlen(name) + 1;
Commit: ed5a2beb727f97577aceeb6cd90adaded87d7ad0
https://github.com/scummvm/scummvm-tools/commit/ed5a2beb727f97577aceeb6cd90adaded87d7ad0
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-04-18T01:15:09-07:00
Commit Message:
Merge pull request #25 from YakBizzarro/mklab-fix
MKLAB: Fix a segfault and set correctly lab version
Changed paths:
tools/mklab.cpp
Commit: 0ded9c95beb864a8d93228919f61fdee4d49a5a0
https://github.com/scummvm/scummvm-tools/commit/0ded9c95beb864a8d93228919f61fdee4d49a5a0
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-05-03T09:28:21+02:00
Commit Message:
LUAC/DELUA: Interpret all unused opcodes as NOP
Changed paths:
tools/delua.cpp
tools/luac/opcode.c
diff --git a/tools/delua.cpp b/tools/delua.cpp
index d9c52af2d..1fc5e6be8 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -37,8 +37,6 @@
#include <list>
#include <set>
-#define NOP 255
-
// Provide debug.cpp functions which don't call SDL_Quit.
void warning(const char *fmt, ...) {
fprintf(stderr, "WARNING: ");
@@ -538,7 +536,7 @@ int instr_lens[] = {
};
int get_instr_len(Byte opc) {
- if (opc == NOP)
+ if (opc > sizeof(instr_lens)/sizeof(int))
return 1;
else
return instr_lens[opc];
@@ -1232,13 +1230,10 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
delete stk->top(); stk->pop();
}
break;
- case NOP:
- break;
+ //Nop
default:
- *os << indent_str << "error: unrecognized opcode "
- << int(opc) << std::endl;
- return;
+ break;
}
}
}
diff --git a/tools/luac/opcode.c b/tools/luac/opcode.c
index aed496786..1476c1320 100644
--- a/tools/luac/opcode.c
+++ b/tools/luac/opcode.c
@@ -43,19 +43,13 @@ int OpcodeInfo(TProtoFunc* tf, Byte* p, Opcode* I, const char* xFILE, int xLINE)
OP.arg=op;
}
}
- else if (op==NOP)
+ else if (op>=NOPCODES)
{
OP.name="NOP";
OP.size=1;
OP.op=NOP;
OP.op_class=NOP;
}
- else if (op>=NOPCODES) /* cannot happen */
- {
- luaL_verror("internal error at %s:%d: bad opcode %d at %d in tf=%p",
- xFILE, xLINE,op,(int)(p-code),tf);
- return 0;
- }
else
{
OP=Info[op];
Commit: 2b60bcf9fa1954182800b76c5093bfeae38e1ce5
https://github.com/scummvm/scummvm-tools/commit/2b60bcf9fa1954182800b76c5093bfeae38e1ce5
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-05-03T10:39:27+02:00
Commit Message:
Add patchr and diffr tools
Changed paths:
A common/getopt.h
A common/md5.cpp
A common/md5.h
A common/zlib.cpp
A common/zlib.h
A doc/ResidualVM-Patch.txt
A tools/diffr.cpp
A tools/patchr.cpp
tools/module.mk
diff --git a/common/getopt.h b/common/getopt.h
new file mode 100644
index 000000000..80ce326da
--- /dev/null
+++ b/common/getopt.h
@@ -0,0 +1,109 @@
+/* ResidualVM - A 3D game interpreter
+*
+* ResidualVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+*/
+
+#ifndef GETOPT_H
+#define GETOPT_H
+
+#ifdef POSIX
+#include <unistd.h>
+#else
+//Fallback getopt
+//Based on XGetopt by Hans Dietrich. Removed non-portable unicode support
+// XGetopt.h Version 1.2
+//
+// Author: Hans Dietrich
+// hdietrich2 at hotmail.com
+//
+// This software is released into the public domain.
+// You are free to use it in any way you like.
+//
+// This software is provided "as is" with no expressed
+// or implied warranty. I accept no liability for any
+// damage or loss of business that this software may cause.
+//
+// http://www.codeproject.com/KB/cpp/xgetopt.aspx
+//
+///////////////////////////////////////////////////////////////////////////////
+
+// BUGS
+// 1) Long options are not supported.
+// 2) The GNU double-colon extension is not supported.
+// 3) The environment variable POSIXLY_CORRECT is not supported.
+// 4) The + syntax is not supported.
+// 5) The automatic permutation of arguments is not supported.
+
+
+char *optarg; // global argument pointer
+int optind = 0; // global argv index
+
+int getopt(int argc, char * const argv[], const char *optstring) {
+ static char *next = NULL;
+ if (optind == 0)
+ next = NULL;
+
+ optarg = NULL;
+
+ if (next == NULL || *next == '\0') {
+ if (optind == 0)
+ optind++;
+
+ if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') {
+ optarg = NULL;
+ if (optind < argc)
+ optarg = argv[optind];
+ return -1;
+ }
+
+ if (strcmp(argv[optind], "--") == 0) {
+ optind++;
+ optarg = NULL;
+ if (optind < argc)
+ optarg = argv[optind];
+ return -1;
+ }
+
+ next = argv[optind];
+ next++; // skip past -
+ optind++;
+ }
+
+ char c = *next++;
+ const char *cp = strchr(optstring, c);
+
+ if (cp == NULL || c == ':')
+ return '?';
+
+ cp++;
+ if (*cp == ':') {
+ if (*next != '\0') {
+ optarg = next;
+ next = NULL;
+ }
+ else if (optind < argc) {
+ optarg = argv[optind];
+ optind++;
+ }
+ else {
+ return '?';
+ }
+ }
+
+ return c;
+}
+
+#endif //POSIX
+#endif //GETOPT_H
diff --git a/common/md5.cpp b/common/md5.cpp
new file mode 100644
index 000000000..220ce84a9
--- /dev/null
+++ b/common/md5.cpp
@@ -0,0 +1,269 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/md5.h"
+#include "common/endian.h"
+
+#include <stdio.h>
+#include <string.h>
+
+namespace Common {
+
+#define GET_UINT32(n, b, i) (n) = READ_LE_UINT32(b + i)
+#define PUT_UINT32(n, b, i) WRITE_LE_UINT32(b + i, n)
+
+void md5_starts(md5_context *ctx) {
+ ctx->total[0] = 0;
+ ctx->total[1] = 0;
+
+ ctx->state[0] = 0x67452301;
+ ctx->state[1] = 0xEFCDAB89;
+ ctx->state[2] = 0x98BADCFE;
+ ctx->state[3] = 0x10325476;
+}
+
+static void md5_process(md5_context *ctx, const uint8 data[64]) {
+ uint32 X[16], A, B, C, D;
+
+ GET_UINT32(X[0], data, 0);
+ GET_UINT32(X[1], data, 4);
+ GET_UINT32(X[2], data, 8);
+ GET_UINT32(X[3], data, 12);
+ GET_UINT32(X[4], data, 16);
+ GET_UINT32(X[5], data, 20);
+ GET_UINT32(X[6], data, 24);
+ GET_UINT32(X[7], data, 28);
+ GET_UINT32(X[8], data, 32);
+ GET_UINT32(X[9], data, 36);
+ GET_UINT32(X[10], data, 40);
+ GET_UINT32(X[11], data, 44);
+ GET_UINT32(X[12], data, 48);
+ GET_UINT32(X[13], data, 52);
+ GET_UINT32(X[14], data, 56);
+ GET_UINT32(X[15], data, 60);
+
+#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
+
+#define P(a, b, c, d, k, s, t) \
+{ \
+ a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
+}
+
+ A = ctx->state[0];
+ B = ctx->state[1];
+ C = ctx->state[2];
+ D = ctx->state[3];
+
+#define F(x, y, z) (z ^ (x & (y ^ z)))
+
+ P(A, B, C, D, 0, 7, 0xD76AA478);
+ P(D, A, B, C, 1, 12, 0xE8C7B756);
+ P(C, D, A, B, 2, 17, 0x242070DB);
+ P(B, C, D, A, 3, 22, 0xC1BDCEEE);
+ P(A, B, C, D, 4, 7, 0xF57C0FAF);
+ P(D, A, B, C, 5, 12, 0x4787C62A);
+ P(C, D, A, B, 6, 17, 0xA8304613);
+ P(B, C, D, A, 7, 22, 0xFD469501);
+ P(A, B, C, D, 8, 7, 0x698098D8);
+ P(D, A, B, C, 9, 12, 0x8B44F7AF);
+ P(C, D, A, B, 10, 17, 0xFFFF5BB1);
+ P(B, C, D, A, 11, 22, 0x895CD7BE);
+ P(A, B, C, D, 12, 7, 0x6B901122);
+ P(D, A, B, C, 13, 12, 0xFD987193);
+ P(C, D, A, B, 14, 17, 0xA679438E);
+ P(B, C, D, A, 15, 22, 0x49B40821);
+
+#undef F
+
+#define F(x, y, z) (y ^ (z & (x ^ y)))
+
+ P(A, B, C, D, 1, 5, 0xF61E2562);
+ P(D, A, B, C, 6, 9, 0xC040B340);
+ P(C, D, A, B, 11, 14, 0x265E5A51);
+ P(B, C, D, A, 0, 20, 0xE9B6C7AA);
+ P(A, B, C, D, 5, 5, 0xD62F105D);
+ P(D, A, B, C, 10, 9, 0x02441453);
+ P(C, D, A, B, 15, 14, 0xD8A1E681);
+ P(B, C, D, A, 4, 20, 0xE7D3FBC8);
+ P(A, B, C, D, 9, 5, 0x21E1CDE6);
+ P(D, A, B, C, 14, 9, 0xC33707D6);
+ P(C, D, A, B, 3, 14, 0xF4D50D87);
+ P(B, C, D, A, 8, 20, 0x455A14ED);
+ P(A, B, C, D, 13, 5, 0xA9E3E905);
+ P(D, A, B, C, 2, 9, 0xFCEFA3F8);
+ P(C, D, A, B, 7, 14, 0x676F02D9);
+ P(B, C, D, A, 12, 20, 0x8D2A4C8A);
+
+#undef F
+
+#define F(x, y, z) (x ^ y ^ z)
+
+ P(A, B, C, D, 5, 4, 0xFFFA3942);
+ P(D, A, B, C, 8, 11, 0x8771F681);
+ P(C, D, A, B, 11, 16, 0x6D9D6122);
+ P(B, C, D, A, 14, 23, 0xFDE5380C);
+ P(A, B, C, D, 1, 4, 0xA4BEEA44);
+ P(D, A, B, C, 4, 11, 0x4BDECFA9);
+ P(C, D, A, B, 7, 16, 0xF6BB4B60);
+ P(B, C, D, A, 10, 23, 0xBEBFBC70);
+ P(A, B, C, D, 13, 4, 0x289B7EC6);
+ P(D, A, B, C, 0, 11, 0xEAA127FA);
+ P(C, D, A, B, 3, 16, 0xD4EF3085);
+ P(B, C, D, A, 6, 23, 0x04881D05);
+ P(A, B, C, D, 9, 4, 0xD9D4D039);
+ P(D, A, B, C, 12, 11, 0xE6DB99E5);
+ P(C, D, A, B, 15, 16, 0x1FA27CF8);
+ P(B, C, D, A, 2, 23, 0xC4AC5665);
+
+#undef F
+
+#define F(x, y, z) (y ^ (x | ~z))
+
+ P(A, B, C, D, 0, 6, 0xF4292244);
+ P(D, A, B, C, 7, 10, 0x432AFF97);
+ P(C, D, A, B, 14, 15, 0xAB9423A7);
+ P(B, C, D, A, 5, 21, 0xFC93A039);
+ P(A, B, C, D, 12, 6, 0x655B59C3);
+ P(D, A, B, C, 3, 10, 0x8F0CCC92);
+ P(C, D, A, B, 10, 15, 0xFFEFF47D);
+ P(B, C, D, A, 1, 21, 0x85845DD1);
+ P(A, B, C, D, 8, 6, 0x6FA87E4F);
+ P(D, A, B, C, 15, 10, 0xFE2CE6E0);
+ P(C, D, A, B, 6, 15, 0xA3014314);
+ P(B, C, D, A, 13, 21, 0x4E0811A1);
+ P(A, B, C, D, 4, 6, 0xF7537E82);
+ P(D, A, B, C, 11, 10, 0xBD3AF235);
+ P(C, D, A, B, 2, 15, 0x2AD7D2BB);
+ P(B, C, D, A, 9, 21, 0xEB86D391);
+
+#undef F
+
+ ctx->state[0] += A;
+ ctx->state[1] += B;
+ ctx->state[2] += C;
+ ctx->state[3] += D;
+}
+
+void md5_update(md5_context *ctx, const uint8 *input, uint32 length) {
+ uint32 left, fill;
+
+ if (!length)
+ return;
+
+ left = ctx->total[0] & 0x3F;
+ fill = 64 - left;
+
+ ctx->total[0] += length;
+ ctx->total[0] &= 0xFFFFFFFF;
+
+ if (ctx->total[0] < length)
+ ctx->total[1]++;
+
+ if (left && length >= fill) {
+ memcpy((void *)(ctx->buffer + left), (const void *)input, fill);
+ md5_process(ctx, ctx->buffer);
+ length -= fill;
+ input += fill;
+ left = 0;
+ }
+
+ while (length >= 64) {
+ md5_process(ctx, input);
+ length -= 64;
+ input += 64;
+ }
+
+ if (length) {
+ memcpy((void *)(ctx->buffer + left), (const void *)input, length);
+ }
+}
+
+static const uint8 md5_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
+};
+
+void md5_finish(md5_context *ctx, uint8 digest[16]) {
+ uint32 last, padn;
+ uint32 high, low;
+ uint8 msglen[8];
+
+ high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
+ low = (ctx->total[0] << 3);
+
+ PUT_UINT32(low, msglen, 0);
+ PUT_UINT32(high, msglen, 4);
+
+ last = ctx->total[0] & 0x3F;
+ padn = (last < 56) ? (56 - last) : (120 - last);
+
+ md5_update(ctx, md5_padding, padn);
+ md5_update(ctx, msglen, 8);
+
+ PUT_UINT32(ctx->state[0], digest, 0);
+ PUT_UINT32(ctx->state[1], digest, 4);
+ PUT_UINT32(ctx->state[2], digest, 8);
+ PUT_UINT32(ctx->state[3], digest, 12);
+}
+
+bool md5_file(const char *name, uint8 digest[16], uint32 length) {
+ FILE *f;
+
+ f = fopen(name, "rb");
+ if (f == NULL) {
+ printf("md5_file couldn't open '%s'", name);
+ return false;
+ }
+
+ md5_context ctx;
+ uint32 i;
+ unsigned char buf[1000];
+ bool restricted = (length != 0);
+ int readlen;
+
+ if (!restricted || sizeof(buf) <= length)
+ readlen = sizeof(buf);
+ else
+ readlen = length;
+
+ md5_starts(&ctx);
+
+
+ while ((i = (uint32)fread(buf, 1, readlen, f)) > 0) {
+ md5_update(&ctx, buf, i);
+
+ length -= i;
+ if (restricted && length == 0)
+ break;
+
+ if (restricted && sizeof(buf) > length)
+ readlen = length;
+ }
+
+ md5_finish(&ctx, digest);
+ fclose(f);
+ return true;
+}
+
+}
diff --git a/common/md5.h b/common/md5.h
new file mode 100644
index 000000000..b8ac9d64e
--- /dev/null
+++ b/common/md5.h
@@ -0,0 +1,44 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMMON_MD5_H
+#define COMMON_MD5_H
+
+#include "common/scummsys.h"
+
+namespace Common {
+
+typedef struct {
+ uint32 total[2];
+ uint32 state[4];
+ uint8 buffer[64];
+} md5_context;
+
+void md5_starts(md5_context *ctx);
+void md5_update(md5_context *ctx, const uint8 *input, uint32 length);
+void md5_finish(md5_context *ctx, uint8 digest[16]);
+
+bool md5_file(const char *name, uint8 digest[16], uint32 length = 0);
+
+} // End of namespace Common
+
+#endif
diff --git a/common/zlib.cpp b/common/zlib.cpp
new file mode 100644
index 000000000..56ec96d1f
--- /dev/null
+++ b/common/zlib.cpp
@@ -0,0 +1,248 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <iostream>
+#include <fstream>
+
+#include "common/scummsys.h"
+#include "common/endian.h"
+#include "common/zlib.h"
+
+#define MIN(x,y) (((x)<(y)) ? (x) : (y))
+
+#if defined(USE_ZLIB)
+
+GZipReadStream::GZipReadStream(std::ifstream *w, uint32 start, uint32 size_p) : _wrapped(w), _stream(), _start(start), _size(size_p) {
+ char buf[4];
+ assert(w != 0);
+
+ // Verify file header is correct
+ w->seekg(_start, std::ios::beg);
+ w->read(buf, 2);
+ uint16 header = READ_BE_UINT16(buf);
+ assert(header == 0x1F8B ||
+ ((header & 0x0F00) == 0x0800 && header % 31 == 0));
+
+ if (header == 0x1F8B && _size > 0) {
+ // Retrieve the original file size
+ w->seekg(_start + _size - 4, std::ios::beg);
+ w->read(buf, 4);
+ _origSize = READ_LE_UINT32(buf);
+ } else {
+ // Original size not available in zlib format
+ _origSize = 0;
+ }
+ _pos = 0;
+ w->seekg(_start, std::ios::beg);
+ _eos = false;
+
+ // Adding 32 to windowBits indicates to zlib that it is supposed to
+ // automatically detect whether gzip or zlib headers are used for
+ // the compressed file. This feature was added in zlib 1.2.0.4,
+ // released 10 August 2003.
+ // Note: This is *crucial* for savegame compatibility, do *not* remove!
+ _zlibErr = inflateInit2(&_stream, MAX_WBITS + 32);
+ if (_zlibErr != Z_OK)
+ return;
+
+ // Setup input buffer
+ _stream.next_in = _buf;
+ _stream.avail_in = 0;
+}
+
+GZipReadStream::~GZipReadStream() {
+ inflateEnd(&_stream);
+}
+
+bool GZipReadStream::err() const { return (_zlibErr != Z_OK) && (_zlibErr != Z_STREAM_END); }
+void GZipReadStream::clearErr() {
+ // only reset _eos; I/O errors are not recoverable
+ _eos = false;
+}
+
+uint32 GZipReadStream::read(void *dataPtr, uint32 dataSize) {
+ _stream.next_out = (byte *)dataPtr;
+ _stream.avail_out = dataSize;
+
+ // Keep going while we get no error
+ while (_zlibErr == Z_OK && _stream.avail_out) {
+ if (_stream.avail_in == 0 && !_wrapped->eof()) {
+ // If we are out of input data: Read more data, if available.
+ _wrapped->read((char*)_buf, BUFSIZE);
+ _stream.next_in = _buf;
+ _stream.avail_in = _wrapped->gcount();
+ }
+ _zlibErr = inflate(&_stream, Z_NO_FLUSH);
+ }
+
+ // Update the position counter
+ _pos += dataSize - _stream.avail_out;
+
+ if (_zlibErr == Z_STREAM_END && _stream.avail_out > 0)
+ _eos = true;
+
+ return dataSize - _stream.avail_out;
+}
+
+bool GZipReadStream::eos() const {
+ return _eos;
+}
+
+int32 GZipReadStream::pos() const {
+ return _pos;
+}
+
+int32 GZipReadStream::size() const {
+ return _origSize;
+}
+
+bool GZipReadStream::seek(int32 offset, std::ios::seekdir whence) {
+ int32 newPos = 0;
+ assert(whence != std::ios::end); // std::ios::end not supported
+ switch (whence) {
+ case std::ios::beg:
+ newPos = offset;
+ break;
+ case std::ios::cur:
+ newPos = _pos + offset;
+ default:
+ assert(false);
+ }
+
+ assert(newPos >= 0);
+
+ if ((uint32)newPos < _pos) {
+ // To search backward, we have to restart the whole decompression
+ // from the start of the file. A rather wasteful operation, best
+ // to avoid it. :/
+#if DEBUG
+ warning("Backward seeking in GZipReadStream detected");
+#endif
+ _pos = 0;
+ _wrapped->seekg(_start, std::ios_base::beg);
+ _zlibErr = inflateReset(&_stream);
+ if (_zlibErr != Z_OK)
+ return false; // FIXME: STREAM REWRITE
+ _stream.next_in = _buf;
+ _stream.avail_in = 0;
+ }
+
+ offset = newPos - _pos;
+
+ // Skip the given amount of data (very inefficient if one tries to skip
+ // huge amounts of data, but usually client code will only skip a few
+ // bytes, so this should be fine.
+ byte tmpBuf[1024];
+ while (!err() && offset > 0) {
+ offset -= read(tmpBuf, MIN((int32)sizeof(tmpBuf), offset));
+ }
+
+ _eos = false;
+ return true; // FIXME: STREAM REWRITE
+}
+
+void GZipWriteStream::processData(int flushType) {
+ // This function is called by both write() and finalize().
+ while (_zlibErr == Z_OK && (_stream.avail_in || flushType == Z_FINISH)) {
+ if (_stream.avail_out == 0) {
+ _wrapped->write((char*)_buf, BUFSIZE);
+ if (_wrapped->bad()) {
+ _zlibErr = Z_ERRNO;
+ break;
+ }
+
+ _stream.next_out = _buf;
+ _stream.avail_out = BUFSIZE;
+ }
+ _zlibErr = deflate(&_stream, flushType);
+ }
+}
+
+GZipWriteStream::GZipWriteStream(std::ofstream *w) : _wrapped(w), _stream() {
+ assert(w != 0);
+
+ // Adding 16 to windowBits indicates to zlib that it is supposed to
+ // write gzip headers. This feature was added in zlib 1.2.0.4,
+ // released 10 August 2003.
+ // Note: This is *crucial* for savegame compatibility, do *not* remove!
+ _zlibErr = deflateInit2(&_stream,
+ Z_DEFAULT_COMPRESSION,
+ Z_DEFLATED,
+ MAX_WBITS + 16,
+ 8,
+ Z_DEFAULT_STRATEGY);
+ assert(_zlibErr == Z_OK);
+
+ _stream.next_out = _buf;
+ _stream.avail_out = BUFSIZE;
+ _stream.avail_in = 0;
+ _stream.next_in = 0;
+}
+
+GZipWriteStream::~GZipWriteStream() {
+ finalize();
+ deflateEnd(&_stream);
+}
+
+bool GZipWriteStream::err() const {
+ // CHECKME: does Z_STREAM_END make sense here?
+ return (_zlibErr != Z_OK && _zlibErr != Z_STREAM_END) || _wrapped->bad();
+}
+
+void GZipWriteStream::finalize() {
+ if (_zlibErr != Z_OK)
+ return;
+
+ // Process whatever remaining data there is.
+ processData(Z_FINISH);
+
+ // Since processData only writes out blocks of size BUFSIZE,
+ // we may have to flush some stragglers.
+ uint remainder = BUFSIZE - _stream.avail_out;
+ if (remainder > 0) {
+ _wrapped->write((char*)_buf, remainder);
+ if (_wrapped->bad())
+ _zlibErr = Z_ERRNO;
+ }
+
+ // Finalize the wrapped savefile, too
+ _wrapped->flush();
+}
+
+uint32 GZipWriteStream::write(const void *dataPtr, uint32 dataSize) {
+ if (err())
+ return 0;
+
+ // Hook in the new data ...
+ // Note: We need to make a const_cast here, as zlib is not aware
+ // of the const keyword.
+ _stream.next_in = const_cast<byte *>((const byte *)dataPtr);
+ _stream.avail_in = dataSize;
+
+ // ... and flush it to disk
+ processData(Z_NO_FLUSH);
+
+ return dataSize - _stream.avail_in;
+}
+
+#endif
diff --git a/common/zlib.h b/common/zlib.h
new file mode 100644
index 000000000..503d47fe8
--- /dev/null
+++ b/common/zlib.h
@@ -0,0 +1,103 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+
+#ifndef COMMON_ZLIB_H
+#define COMMON_ZLIB_H
+
+#if defined(USE_ZLIB)
+ #ifdef __SYMBIAN32__
+ #include <zlib\zlib.h>
+ #else
+ #include <zlib.h>
+ #endif
+
+ #if ZLIB_VERNUM < 0x1204
+ #error Version 1.2.0.4 or newer of zlib is required for this code
+ #endif
+
+/**
+ * A simple wrapper class which can be used to wrap around an arbitrary
+ * other std::ifstream and will then provide on-the-fly decompression support.
+ * Assumes the compressed data to be in gzip format.
+ */
+class GZipReadStream {
+protected:
+ enum {
+ BUFSIZE = 16384 // 1 << MAX_WBITS
+ };
+
+ byte _buf[BUFSIZE];
+
+ std::ifstream *_wrapped;
+ z_stream _stream;
+ int _zlibErr;
+ uint32 _pos;
+ uint32 _origSize;
+ bool _eos;
+ uint32 _start, _size;
+
+public:
+ GZipReadStream(std::ifstream *w, uint32 start, uint32 size = 0);
+ ~GZipReadStream();
+ bool err() const;
+ void clearErr();
+
+ uint32 read(void *dataPtr, uint32 dataSize);
+
+ bool eos() const;
+ int32 pos() const;
+ int32 size() const;
+ bool seek(int32 offset, std::ios::seekdir whence = std::ios::beg);
+};
+
+/**
+ * A simple wrapper class which can be used to wrap around an arbitrary
+ * other std::ofstream and will then provide on-the-fly compression support.
+ * The compressed data is written in the gzip format.
+ */
+class GZipWriteStream {
+protected:
+ enum {
+ BUFSIZE = 16384 // 1 << MAX_WBITS
+ };
+
+ byte _buf[BUFSIZE];
+ std::ofstream *_wrapped;
+ z_stream _stream;
+ int _zlibErr;
+
+ void processData(int flushType);
+
+public:
+ GZipWriteStream(std::ofstream *w);
+ ~GZipWriteStream();
+
+ bool err() const;
+ void finalize();
+
+ uint32 write(const void *dataPtr, uint32 dataSize);
+};
+
+#endif
+
+#endif
diff --git a/doc/ResidualVM-Patch.txt b/doc/ResidualVM-Patch.txt
new file mode 100644
index 000000000..8ee0d3bed
--- /dev/null
+++ b/doc/ResidualVM-Patch.txt
@@ -0,0 +1,72 @@
+PatchR - Usage and File Format specifications
+
+The ResidualVM Patch (patchr) is a binary patch engine, useful for changes in games files.
+Its mainly used to fix bugs in scripts of games, when the distribution of patched script is
+forbidden due to copyright. The patching is all done in ram, at every read() call, so it could
+patch even big files.
+
+A patch come in form of a binary file, with .patchr extension, generated by the diffr tool.
+In order to make these patches available to ResidualVM, these files should be enclosed in a
+lab file, usually residualvm-grim-patch.lab (for game fixes) or datausr.lab (for user contents).
+These files can be generated with mklab tool.
+
+Tools usage:
+DIFFR:
+Synatx: diffr [-m][-n] oldfile newfile patchfile
+
+Diffr compares (oldfile) to (newfile) and writes to (patchfile) a binary patch suitable for
+use by patchr or ResidualVM (if enclosed in a lab file, see above).
+-m Mix diff and extra stream (see File format section).
+-n Doesn't compress ctrl stream (see File format section).
+Both these options increase slightly the size of
+patchfile, but they reduce the patching memory usage (about 44kB less each).
+
+If you wants to use the resulting patchfile with ResidualVM, the filename of patchfile must be
+oldfile.patchr (with the original file extension, for example sg.lua.patchr)
+If you have multiple versions of a file with the same filename (for example from differents versions
+of the game), you could provide patches for all of them by calling the others patchfiles
+oldfile_1.patchr, oldfile_2.patchr and so on. ResidualVM recognize the correct patch by checking the
+md5 sum of the oldfile (see file format section).
+
+Note that diffr uses a lot of memory, according to bsdiff manual.
+
+PATCHR:
+Syntax: patchr [-a] oldfile newfile patchfile
+Patchr generates (newfile) from (oldfile) and (patchfile) where (patchfile) is a binary patch built by diffr.
+-a Show the contents of the the patch file
+
+PatchR - File format:
+It's modeled on bsdiff format (http://www.daemonology.net/bsdiff/), but:
+- it has a different signature
+- it uses gzip insted of bzip2 in order to avoid to add new dependences to ResidualVM and to
+ reduce decompression time and memory usage (at the cost of bigger patches)
+- it checks the md5sum of the first 5000 bytes and the size of the file to be patched
+- it uses 32 bit offsets instead of 64 bit offsets
+- the patching process isn't performed in one step, but at every read() call, with a big save of
+ memory if the resulting file is large
+- instead of an arithmetic difference between the original data and the diff block, it uses a xor
+- the bytes are xored in groups of 4 or 8 bytes (respectively on 32 or 64 bit machines) to improve performances
+- optionally (-m flag in diffr) it mixs diff and extra stream in only one stream in order to
+ reduce decompression memory usage (about 44kB less, according to http://zlib.net/zlib_tech.html, Memory footprint section)
+- the ctrl block could be uncompressed (-n flags in diffr). Useful for small patches, same advanages as above
+
+All values, except the signature, are encoded in little endian
+
+Header (size = 48)
+Offset Size Var
+0 4 Signature = 'PATR'
+4 2 VersionMajor = 2
+6 2 VersionMinor <= 0
+8 4 flags
+12 16 md5sum of old file
+28 4 lenght of old file
+32 4 lenght of new file
+36 4 length of gzipped ctrl block (x)
+40 4 length of gzipped diff block (y)
+44 4 length of gzipped extra block (z) (if zero the extra block is missing or mixed with diff block)
+
+File
+0 48 Header
+48 x Gzipped or uncompressed ctrl block
+48+x y Gzipped diff block
+48+x+y z Gzipped extra block (it could be missing)
diff --git a/tools/diffr.cpp b/tools/diffr.cpp
new file mode 100644
index 000000000..6b68d6c97
--- /dev/null
+++ b/tools/diffr.cpp
@@ -0,0 +1,556 @@
+/* ResidualVM - A 3D game interpreter
+*
+* ResidualVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+*/
+
+//Large parts of this program have been taken from bsdiff written by Colin Percival:
+/*-
+ * Copyright 2003-2005 Colin Percival
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted providing 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <iostream>
+#include <fstream>
+#include "common/endian.h"
+#include "common/zlib.h"
+#include "common/md5.h"
+#include "common/getopt.h"
+
+#define MIN(x,y) (((x)<(y)) ? (x) : (y))
+
+static void split(int32 *I, int32 *V, int32 start, int32 len, int32 h) {
+ int32 i, j, k, x, tmp, jj, kk;
+
+ if (len < 16) {
+ for (k = start; k < start + len; k += j) {
+ j = 1;
+ x = V[I[k] + h];
+ for (i = 1; k + i < start + len; i++) {
+ if (V[I[k + i] + h] < x) {
+ x = V[I[k + i] + h];
+ j = 0;
+ };
+ if (V[I[k + i] + h] == x) {
+ tmp = I[k + j];
+ I[k + j] = I[k + i];
+ I[k + i] = tmp;
+ j++;
+ };
+ };
+ for (i = 0; i < j; i++) V[I[k + i]] = k + j - 1;
+ if (j == 1) I[k] = -1;
+ };
+ return;
+ };
+
+ x = V[I[start + len/2] + h];
+ jj = 0;
+ kk = 0;
+ for (i = start; i < start + len; i++) {
+ if (V[I[i] + h] < x) jj++;
+ if (V[I[i] + h] == x) kk++;
+ };
+ jj += start;
+ kk += jj;
+
+ i = start;
+ j = 0;
+ k = 0;
+ while (i < jj) {
+ if (V[I[i] + h] < x) {
+ i++;
+ } else if (V[I[i] + h] == x) {
+ tmp = I[i];
+ I[i] = I[jj + j];
+ I[jj + j] = tmp;
+ j++;
+ } else {
+ tmp = I[i];
+ I[i] = I[kk + k];
+ I[kk + k] = tmp;
+ k++;
+ };
+ };
+
+ while (jj + j < kk) {
+ if (V[I[jj + j] + h] == x) {
+ j++;
+ } else {
+ tmp = I[jj + j];
+ I[jj + j] = I[kk + k];
+ I[kk + k] = tmp;
+ k++;
+ };
+ };
+
+ if (jj > start) split(I, V, start, jj - start, h);
+
+ for (i = 0; i < kk - jj; i++) V[I[jj + i]] = kk - 1;
+ if (jj == kk - 1) I[jj] = -1;
+
+ if (start + len > kk) split(I, V, kk, start + len - kk, h);
+}
+
+static void qsufsort(int32 *I, int32 *V, byte *old, int32 oldsize) {
+ int32 buckets[256];
+ int32 i, h, len;
+
+ for (i = 0; i < 256; i++) buckets[i] = 0;
+ for (i = 0; i < oldsize; i++) buckets[old[i]]++;
+ for (i = 1; i < 256; i++) buckets[i] += buckets[i-1];
+ for (i = 255; i > 0; i--) buckets[i] = buckets[i-1];
+ buckets[0] = 0;
+
+ for (i = 0; i < oldsize; i++) I[++buckets[old[i]]] = i;
+ I[0] = oldsize;
+ for (i = 0; i < oldsize; i++) V[i] = buckets[old[i]];
+ V[oldsize] = 0;
+ for (i = 1; i < 256; i++) if (buckets[i] == buckets[i-1] + 1) I[buckets[i]] = -1;
+ I[0] = -1;
+
+ for (h = 1; I[0] != -(oldsize + 1); h += h) {
+ len = 0;
+ for (i = 0; i < oldsize + 1;) {
+ if (I[i] < 0) {
+ len -= I[i];
+ i -= I[i];
+ } else {
+ if (len) I[i-len] = -len;
+ len = V[I[i]] + 1 - i;
+ split(I, V, i, len, h);
+ i += len;
+ len = 0;
+ };
+ };
+ if (len) I[i-len] = -len;
+ };
+
+ for (i = 0; i < oldsize + 1; i++)
+ I[V[i]] = i;
+}
+
+static int32 matchlen(byte *old, int32 oldsize, byte *new_block, int32 new_size) {
+ int32 i;
+
+ for (i = 0; (i < oldsize) && (i < new_size); i++)
+ if (old[i] != new_block[i])
+ break;
+
+ return i;
+}
+
+static int32 search(int32 *I, byte *old, int32 oldsize,
+ byte *new_block, int32 newsize, int32 st, int32 en, int32 *pos) {
+ int32 x, y;
+
+ if (en - st < 2) {
+ x = matchlen(old + I[st], oldsize - I[st], new_block, newsize);
+ y = matchlen(old + I[en], oldsize - I[en], new_block, newsize);
+
+ if (x > y) {
+ *pos = I[st];
+ return x;
+ } else {
+ *pos = I[en];
+ return y;
+ }
+ };
+
+ x = st + (en - st) / 2;
+ if (memcmp(old + I[x], new_block, MIN(oldsize - I[x], newsize)) < 0) {
+ return search(I, old, oldsize, new_block, newsize, x, en, pos);
+ } else {
+ return search(I, old, oldsize, new_block, newsize, st, x, pos);
+ };
+}
+
+typedef struct {
+ char *oldfile;
+ char *newfile;
+ char *patchfile;
+ bool mix;
+ bool comp_ctrl;
+} arguments;
+
+void show_usage(char *name) {
+ printf("usage: %s [-m][-n] oldfile newfile patchfile\n", name);
+}
+
+arguments parse_args(int argc, char *argv[]) {
+ arguments arg;
+ arg.comp_ctrl = true;
+ arg.mix = false;
+
+ int c;
+ while ((c = getopt (argc, argv, "nm")) != -1)
+ switch (c) {
+ case 'n':
+ arg.comp_ctrl = false;
+ break;
+ case 'm':
+ arg.mix = true;
+ break;
+ case '?':
+ show_usage(argv[0]);
+ exit(0);
+ default:
+ fprintf (stderr, "Internal error\n");
+ exit(1);
+ }
+
+ if (argc - optind < 3) {
+ show_usage(argv[0]);
+ exit(0);
+ }
+
+ arg.oldfile = argv[optind++];
+ arg.newfile = argv[optind++];
+ arg.patchfile = argv[optind++];
+
+ return arg;
+}
+
+int main(int argc, char *argv[]) {
+ byte *old, *new_block;
+ int32 oldsize, newsize, newsize2;
+ int32 *I, *V;
+ int32 scan, pos, len;
+ int32 lastscan, lastpos, lastoffset;
+ int32 oldscore, scsc;
+ int32 s, Sf, lenf, Sb, lenb;
+ int32 overlap, Ss, lens;
+ int32 i;
+ int32 dblen, eblen;
+ uint32 flags = 0;
+ byte *db, *eb;
+ byte buf[4];
+ byte header[48];
+ std::ofstream patch;
+ std::ifstream in;
+ arguments args;
+
+ args = parse_args(argc, argv);
+
+ //Set flags
+ if (args.mix)
+ flags |= 1 << 0;
+ if (args.comp_ctrl)
+ flags |= 1 << 1;
+
+ /* Allocate oldsize+1 bytes instead of oldsize bytes to ensure
+ that we never try to alloc zero elements and get a NULL pointer */
+
+ //Read old file
+ in.open(args.oldfile, std::ios::in | std::ios::binary);
+ if (in.fail()) {
+ std::cerr << "Unable to open " << args.oldfile << std::endl;
+ return 1;
+ }
+ in.seekg(0, std::ios::end);
+ oldsize = in.tellg();
+ in.seekg(0);
+ if ((old = new byte[oldsize + 1]) == NULL) {
+ std::cerr << "Unable to allocate memory" << std::endl;
+ return 1;
+ }
+ in.read((char*)old, oldsize);
+ if (in.fail()) {
+ std::cerr << "Unable to read from " << args.oldfile << std::endl;
+ return 1;
+ }
+ in.close();
+
+ I = new int32[oldsize + 1];
+ V = new int32[oldsize + 1];
+ if (I == NULL || V == NULL) {
+ std::cerr << "Unable to allocate memory" << std::endl;
+ return 1;
+ }
+ qsufsort(I, V, old, oldsize);
+
+ delete[] V;
+
+ //Read new file
+ in.open(args.newfile, std::ios::in | std::ios::binary);
+ if (in.fail()) {
+ std::cerr << "Unable to open " << args.newfile << std::endl;
+ return 1;
+ }
+ in.seekg(0, std::ios::end);
+ newsize = in.tellg();
+ in.seekg(0);
+ if ((new_block = new byte[newsize + 1]) == NULL) {
+ std::cerr << "Unable to allocate memory" << std::endl;
+ return 1;
+ }
+ in.read((char*)new_block, newsize);
+ if (in.fail()) {
+ std::cerr << "Unable to read from " << args.newfile << std::endl;
+ return 1;
+ }
+ in.close();
+
+
+ db = new byte[newsize + 1];
+ if (db == NULL) {
+ std::cerr << "Unable to allocate memory" << std::endl;
+ return 1;
+ }
+ if (!args.mix) {
+ eb = new byte[newsize + 1];
+ if (eb == NULL) {
+ std::cerr << "Unable to allocate memory" << std::endl;
+ return 1;
+ }
+ }
+ dblen = 0;
+ eblen = 0;
+
+ /* Create the patch file */
+ patch.open(args.patchfile, std::ios::out | std::ios::binary);
+ if (patch.fail()) {
+ std::cerr << "Unable to open " << args.patchfile << std::endl;
+ return 1;
+ }
+
+ memcpy(header, "PATR", 4); //Signature
+ WRITE_LE_UINT16(header + 4, 2); //Version major
+ WRITE_LE_UINT16(header + 6, 0); //Version minor
+ WRITE_LE_UINT32(header + 8, flags); //flags
+ Common::md5_file(args.oldfile, header + 12, 5000); //Md5sum
+ WRITE_LE_UINT32(header + 28, oldsize); //oldsize
+ WRITE_LE_UINT32(header + 32, newsize); //newsize
+ //WRITE_LE_UINT32(header + 36, 0); //ctrl compressed size
+ //WRITE_LE_UINT32(header + 40, 0); //diff compressed size
+ //WRITE_LE_UINT32(header + 44, 0); //extra compressed size
+ patch.write((char *)header, 48);
+ if (patch.bad()) {
+ std::cerr << "Write error on " << args.patchfile << std::endl;
+ return 1;
+ }
+
+ /* Compute the differences, writing ctrl as we go */
+ GZipWriteStream *ctrlBlock;
+ if (args.comp_ctrl)
+ ctrlBlock = new GZipWriteStream(&patch);
+
+ scan = 0;
+ len = 0;
+ lastscan = 0;
+ lastpos = 0;
+ lastoffset = 0;
+ while (scan < newsize) {
+ oldscore = 0;
+
+ for (scsc = scan += len; scan < newsize; scan++) {
+ len = search(I, old, oldsize, new_block + scan, newsize - scan,
+ 0, oldsize, &pos);
+
+ for (; scsc < scan + len; scsc++)
+ if ((scsc + lastoffset < oldsize) &&
+ (old[scsc + lastoffset] == new_block[scsc]))
+ oldscore++;
+
+ if (((len == oldscore) && (len != 0)) ||
+ (len > oldscore + 8)) break;
+
+ if ((scan + lastoffset < oldsize) &&
+ (old[scan + lastoffset] == new_block[scan]))
+ oldscore--;
+ };
+
+ if ((len != oldscore) || (scan == newsize)) {
+ s = 0;
+ Sf = 0;
+ lenf = 0;
+ for (i = 0; (lastscan + i < scan) && (lastpos + i < oldsize);) {
+ if (old[lastpos + i] == new_block[lastscan + i]) s++;
+ i++;
+ if (s * 2 - i > Sf * 2 - lenf) {
+ Sf = s;
+ lenf = i;
+ };
+ };
+
+ lenb = 0;
+ if (scan < newsize) {
+ s = 0;
+ Sb = 0;
+ for (i = 1; (scan >= lastscan + i) && (pos >= i); i++) {
+ if (old[pos - i] == new_block[scan - i]) s++;
+ if (s * 2 - i > Sb * 2 - lenb) {
+ Sb = s;
+ lenb = i;
+ };
+ };
+ };
+
+ if (lastscan + lenf > scan - lenb) {
+ overlap = (lastscan + lenf) - (scan - lenb);
+ s = 0;
+ Ss = 0;
+ lens = 0;
+ for (i = 0; i < overlap; i++) {
+ if (new_block[lastscan + lenf - overlap + i] ==
+ old[lastpos + lenf - overlap + i]) s++;
+ if (new_block[scan - lenb + i] ==
+ old[pos - lenb + i]) s--;
+ if (s > Ss) {
+ Ss = s;
+ lens = i + 1;
+ };
+ };
+
+ lenf += lens - overlap;
+ lenb -= lens;
+ };
+
+ for (i = 0; i < lenf; i++)
+ db[dblen + i] = new_block[lastscan + i] ^ old[lastpos + i];
+ dblen += lenf;
+
+ if (!args.mix) {
+ for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++)
+ eb[eblen + i] = new_block[lastscan + lenf + i];
+ eblen += (scan - lenb) - (lastscan + lenf);
+ } else {
+ for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++)
+ db[dblen + i] = new_block[lastscan + lenf + i];
+ dblen += (scan - lenb) - (lastscan + lenf);
+ }
+
+ WRITE_LE_UINT32(buf, lenf);
+ if (args.comp_ctrl) {
+ ctrlBlock->write(buf, 4);
+ if (ctrlBlock->err()) {
+ std::cerr << "Write error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ } else
+ patch.write((char*)buf, 4);
+
+
+ WRITE_LE_UINT32(buf, (scan - lenb) - (lastscan + lenf));
+ if (args.comp_ctrl) {
+ ctrlBlock->write(buf, 4);
+ if (ctrlBlock->err()) {
+ std::cerr << "Write error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ } else
+ patch.write((char*)buf, 4);
+
+ WRITE_LE_UINT32(buf, int32((pos - lenb) - (lastpos + lenf)));
+ if (args.comp_ctrl) {
+ ctrlBlock->write(buf, 4);
+ if (ctrlBlock->err()) {
+ std::cerr << "Write error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ } else
+ patch.write((char*)buf, 4);
+
+ lastscan = scan - lenb;
+ lastpos = pos - lenb;
+ lastoffset = pos - scan;
+ };
+ };
+ if (args.comp_ctrl)
+ delete ctrlBlock;
+
+ /* Compute size of ctrl data (compressed or not)*/
+ if ((len = patch.tellp()) == -1) {
+ std::cerr << "Read error on " << args.patchfile << std::endl;
+ return 1;
+ }
+
+ WRITE_LE_UINT32(header + 36, len - 48);
+
+ /* Write compressed diff data */
+ GZipWriteStream *diffBlock = new GZipWriteStream(&patch);
+ diffBlock->write(db, dblen);
+ if (diffBlock->err()) {
+ std::cerr << "Write error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ delete diffBlock;
+
+ /* Compute size of compressed diff data */
+ if ((newsize = patch.tellp()) == -1) {
+ std::cerr << "Read error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ WRITE_LE_UINT32(header + 40, newsize - len);
+
+ /* Write compressed extra data */
+ if (!args.mix) {
+ GZipWriteStream *extraBlock = new GZipWriteStream(&patch);
+ extraBlock->write(eb, eblen);
+ if (extraBlock->err()) {
+ std::cerr << "Write error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ delete extraBlock;
+
+ /* Compute size of compressed extra data */
+ if ((newsize2 = patch.tellp()) == -1) {
+ std::cerr << "Read error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ WRITE_LE_UINT32(header + 44, newsize2 - newsize);
+
+ delete[] eb;
+ }
+ else
+ WRITE_LE_UINT32(header + 44, 0);
+
+ /* Seek to the beginning, write the header, and close the file */
+ patch.seekp(0, std::ios::beg);
+ patch.write((char *)header, 48);
+ if (patch.bad()) {
+ std::cerr << "Write error on " << args.patchfile << std::endl;
+ return 1;
+ }
+ patch.close();
+
+ /* Free the memory we used */
+ delete[] db;
+ delete[] I;
+ delete[] old;
+ delete[] new_block;
+
+ return 0;
+}
diff --git a/tools/module.mk b/tools/module.mk
index 15dc7088a..9a80aa331 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -24,7 +24,9 @@ TOOLS := \
tools/vima$(EXEEXT) \
tools/labcopy$(EXEEXT) \
tools/luac/luac$(EXEEXT) \
- tools/patchex/patchex$(EXEEXT)
+ tools/patchex/patchex$(EXEEXT) \
+ tools/diffr$(EXEEXT) \
+ tools/patchr$(EXEEXT)
# below not added as it depends for ppm, bpm library
# tools/mat2ppm$(EXEEXT)
@@ -49,6 +51,16 @@ clean-tools:
# Build rules for the tools
#
+tools/diffr$(EXEEXT): $(srcdir)/tools/diffr.cpp $(srcdir)/common/md5.o $(srcdir)/common/zlib.o
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common $(srcdir)/common/md5.o $(srcdir)/common/zlib.o -lz -o $@ $< $(LDFLAGS)
+
+tools/patchr$(EXEEXT): $(srcdir)/tools/patchr.cpp $(srcdir)/common/md5.o $(srcdir)/common/zlib.o
+ $(MKDIR) tools/$(DEPDIR)
+ $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
+ -L$(srcdir)/common $(srcdir)/common/md5.o $(srcdir)/common/zlib.o -lz -o $@ $< $(LDFLAGS)
+
tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
$(MKDIR) tools/$(DEPDIR)
$(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
diff --git a/tools/patchr.cpp b/tools/patchr.cpp
new file mode 100644
index 000000000..83dcad665
--- /dev/null
+++ b/tools/patchr.cpp
@@ -0,0 +1,353 @@
+/* ResidualVM - A 3D game interpreter
+*
+* ResidualVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+*/
+
+//Large parts of this program have been taken from bsdiff written by Colin Percival:
+/*-
+ * Copyright 2003-2005 Colin Percival
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted providing 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <iostream>
+#include <fstream>
+#include <cstdlib>
+#include "common/endian.h"
+#include "common/zlib.h"
+#include "common/md5.h"
+#include "common/getopt.h"
+
+uint8 *old_block, *new_block;
+GZipReadStream *ctrlDec, *diffDec, *extraDec;
+
+void free_memory() {
+ if (old_block)
+ delete[] old_block;
+ if (new_block)
+ delete[] new_block;
+
+ if (ctrlDec)
+ delete ctrlDec;
+ if (diffDec)
+ delete diffDec;
+ if (extraDec && extraDec != diffDec)
+ delete extraDec;
+}
+
+void show_header_info(uint8 *header) {
+ printf("PatchR v%d.%d\n", READ_LE_UINT16(header + 4), READ_LE_UINT16(header + 6));
+ printf("Md5: ");
+ for (int i = 0; i < 16; ++i)
+ printf("%x", *(header + 12 + i));
+ printf("\n");
+
+ uint32 flags = READ_LE_UINT32(header + 8);
+ printf("MIX_DIFF_EXTRA %s\n", (flags & 1 << 0) ? "YES" : "NO");
+ printf("COMPRESS_CTRL %s\n", (flags & 1 << 1) ? "YES" : "NO");
+ printf("\n");
+
+ printf("OLD FILE SIZE %d\n", READ_LE_UINT32(header + 28));
+ printf("NEW FILE SIZE %d\n", READ_LE_UINT32(header + 32));
+ printf("\n");
+ printf("CTRL STREAM SIZE %d\n", READ_LE_UINT32(header + 36));
+ printf("DIFF STREAM SIZE %d\n", READ_LE_UINT32(header + 40));
+ printf("EXTRA STREAM SIZE %d\n", READ_LE_UINT32(header + 44));
+ printf("\n");
+}
+
+typedef struct {
+ char *oldfile;
+ char *newfile;
+ char *patchfile;
+ bool show_info;
+} arguments;
+
+void show_usage(char *name) {
+ printf("usage: %s [-a] oldfile newfile patchfile\n", name);
+}
+
+arguments parse_args(int argc, char *argv[]) {
+ arguments arg;
+ arg.show_info = false;
+
+ int c;
+ while ((c = getopt (argc, argv, "a")) != -1)
+ switch (c) {
+ case 'a':
+ arg.show_info = true;
+ break;
+ case '?':
+ show_usage(argv[0]);
+ exit(0);
+ default:
+ fprintf (stderr, "Internal error\n");
+ exit(1);
+ }
+
+ if (argc - optind < 3) {
+ show_usage(argv[0]);
+ exit(0);
+ }
+
+ arg.oldfile = argv[optind++];
+ arg.newfile = argv[optind++];
+ arg.patchfile = argv[optind++];
+
+ return arg;
+}
+
+int main(int argc,char * argv[]) {
+ uint32 oldsize, newsize;
+ uint32 zctrllen, zdatalen, zextralen;
+ uint8 header[48], buf[4];
+ uint32 oldpos, newpos;
+ uint32 ctrl[3];
+ uint32 lenread;
+ uint32 flags;
+ uint8 md5[16];
+ std::ifstream oldfile, patch, ctrlStream, diffStream, extraStream;
+ std::ofstream newfile;
+ bool comp_ctrl, mix;
+ arguments args;
+
+ old_block = 0;
+ new_block = 0;
+ atexit(free_memory);
+
+ args = parse_args(argc, argv);
+
+ /* Opens the old file */
+ oldfile.open(args.oldfile, std::ios::in | std::ios::binary);
+ if (oldfile.fail()) {
+ std::cerr << "Unable to open" << args.oldfile << std::endl;
+ return 1;
+ }
+
+ //Get the file size
+ oldfile.seekg(0, std::ios::end);
+ oldsize = oldfile.tellg();
+
+ /* Open patch file */
+ patch.open(args.patchfile, std::ios::in | std::ios::binary);
+ ctrlStream.open(args.patchfile, std::ios::in | std::ios::binary);
+ diffStream.open(args.patchfile, std::ios::in | std::ios::binary);
+ extraStream.open(args.patchfile, std::ios::in | std::ios::binary);
+
+ if (patch.fail() || ctrlStream.fail() || diffStream.fail() || extraStream.fail()) {
+ std::cerr << "Unable to open " << args.patchfile << std::endl;
+ return 1;
+ }
+
+ /* Read header */
+ patch.read((char*)header, 48);
+ if (patch.eof() || patch.bad() || patch.fail()) {
+ std::cerr << "Corrupt patch\n";
+ return 1;
+ }
+
+ /* Check for appropriate signature */
+ if (READ_BE_UINT32(header) != MKTAG('P','A','T','R')) {
+ std::cerr << "Corrupt patch\n";
+ return 1;
+ }
+
+ /* Check the version */
+ if (READ_LE_UINT16(header + 4) != 2 || READ_LE_UINT16(header + 6) > 0) {
+ std::cerr << "Wrong version number\n";
+ return 1;
+ }
+
+ //Set flags
+ flags = READ_LE_UINT32(header + 8);
+ mix = (flags & 1 << 0) ? true : false;
+ comp_ctrl = (flags & 1 << 1) ? true : false;
+
+ /* Check if the file to patch match */
+ Common::md5_file(args.oldfile, md5, 5000);
+ if (memcmp(md5, header + 12, 16) != 0 || oldsize != READ_LE_UINT32(header + 28)) {
+ std::cerr << args.patchfile << " targets a different file\n";
+ return 1;
+ }
+
+ /* Read lengths from header */
+ newsize = READ_LE_UINT32(header + 32);
+ zctrllen = READ_LE_UINT32(header + 36);
+ zdatalen = READ_LE_UINT32(header + 40);
+ zextralen = READ_LE_UINT32(header + 44);
+
+ patch.close();
+ if (args.show_info)
+ show_header_info(header);
+
+ // Open the compressed sub-streams
+ //Check if the ctrl is compressed
+ ctrlStream.seekg(48, std::ios::beg);
+ if (comp_ctrl)
+ ctrlDec = new GZipReadStream(&ctrlStream, 48, zctrllen);
+
+ diffDec = new GZipReadStream(&diffStream, 48 + zctrllen, zdatalen);
+ if (mix)
+ extraDec = diffDec;
+ else
+ extraDec = new GZipReadStream(&extraStream, 48 + zctrllen + zdatalen, zextralen);
+
+ old_block = new uint8[oldsize];
+ new_block = new byte[newsize];
+ if (old_block == NULL || new_block == NULL) {
+ std::cerr << "Not enough memory\n";
+ return 1;
+ }
+
+ //Read the oldfile
+ oldfile.seekg(0, std::ios::beg);
+ oldfile.read((char*)old_block, oldsize);
+ oldfile.close();
+ if (oldfile.bad() || oldfile.fail()) {
+ std::cerr << "Input error\n";
+ return 1;
+ }
+
+ oldpos=0;
+ newpos=0;
+ while(newpos < newsize) {
+ /* Read control data */
+ for (uint i = 0; i < 3; i++) {
+ if (comp_ctrl)
+ lenread = ctrlDec->read(buf, 4);
+ else {
+ ctrlStream.read((char*)buf, 4);
+ lenread = ctrlStream.gcount();
+ }
+ if (lenread < 4) {
+ std::cerr << "Corrupt patch\n";
+ return 1;
+ }
+ ctrl[i] = READ_LE_UINT32(buf);
+ };
+
+ /* Sanity-check */
+ if (newpos + ctrl[0] > newsize) {
+ std::cerr << "Corrupt patch\n";
+ return 1;
+ }
+
+ /* Read diff string */
+ lenread = diffDec->read(new_block + newpos, ctrl[0]);
+ if ((lenread < ctrl[0]) || diffDec->err()) {
+ std::cerr << "Corrupt patch\n";
+ return 1;
+ }
+
+ //Show info
+ if (args.show_info && ctrl[0] > 0) {
+ uint i = 0;
+ while (i < ctrl[0]) {
+ if (*(new_block + newpos + i) != 0) {
+ printf("XOR");
+ do {
+ printf(" %02x", *(new_block + newpos + i));
+ ++i;
+ } while (i < ctrl[0] && *(new_block + newpos + i) != 0);
+ printf("\n");
+ } else {
+ uint pos = i;
+ while (i < ctrl[0] && *(new_block + newpos + i) == 0)
+ ++i;
+ printf("COPY %d\n", i - pos);
+ }
+ }
+ }
+
+ /* Add old data to diff string */
+ for (uint i = 0; i < ctrl[0]; i++)
+ if ((oldpos + i >= 0) && (oldpos + i < oldsize))
+ new_block[newpos + i] ^= old_block[oldpos + i];
+
+ /* Adjust pointers */
+ newpos += ctrl[0];
+ oldpos += ctrl[0];
+
+ /* Sanity-check */
+ if (newpos + ctrl[1] > newsize) {
+ std::cerr << "Corrupt patch\n";
+ return 1;
+ }
+
+ /* Read extra string */
+ lenread = extraDec->read(new_block + newpos, ctrl[1]);
+ if ((lenread < ctrl[1]) || extraDec->err()) {
+ std::cerr << "Corrupt patch\n";
+ return 1;
+ }
+
+ //Show info
+ if (args.show_info) {
+ if (ctrl[1] > 0) {
+ printf("INSERT");
+ for (uint i = 0; i < ctrl[1]; i++)
+ printf(" %02x", *(new_block + newpos + i));
+ printf("\n");
+ }
+
+ if (ctrl[2] != 0)
+ printf("JUMP %d\n", ctrl[2]);
+ }
+
+ /* Adjust pointers */
+ newpos += ctrl[1];
+ oldpos += int32(ctrl[2]);
+ };
+
+ /* Clean up the bzip2 reads */
+ ctrlStream.close();
+ diffStream.close();
+ extraStream.close();
+
+ /* Write the new file */
+ newfile.open(args.newfile, std::ios::out | std::ios::binary);
+ if (newfile.fail()) {
+ std::cerr << "Unable to open" << args.newfile << std::endl;
+ return 1;
+ }
+
+ newfile.write((char*)new_block, newsize);
+ if (patch.bad()) {
+ std::cerr << "Output error.\n";
+ return 1;
+ }
+
+ return 0;
+}
Commit: e9c54e46ba8e10220f509c1120b921d7ef13635e
https://github.com/scummvm/scummvm-tools/commit/e9c54e46ba8e10220f509c1120b921d7ef13635e
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-07-12T15:51:10-07:00
Commit Message:
Merge pull request #26 from YakBizzarro/patchr2
Add patchr and diffr tools
Changed paths:
A common/getopt.h
A common/md5.cpp
A common/md5.h
A common/zlib.cpp
A common/zlib.h
A doc/ResidualVM-Patch.txt
A tools/diffr.cpp
A tools/patchr.cpp
tools/module.mk
Commit: aa854ae9e0ce476d95d7ff0ffd53665b4316c622
https://github.com/scummvm/scummvm-tools/commit/aa854ae9e0ce476d95d7ff0ffd53665b4316c622
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-10T13:04:09+02:00
Commit Message:
DELUA: Fix validIdentifier function
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 1fc5e6be8..7684567fb 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -121,7 +121,7 @@ public:
return false;
for (int i = 0; i < text->u.s.len; i++) {
char c = text->str[i];
- if ((! isalnum(text->str[0])) && c != '_')
+ if ((! isalnum(c)) && c != '_')
return false;
}
return true;
Commit: 33332bd6bd82f06607c4f6798f6ceace8383c3ac
https://github.com/scummvm/scummvm-tools/commit/33332bd6bd82f06607c4f6798f6ceace8383c3ac
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-22T11:08:54+02:00
Commit Message:
DELUA: Fix some memory leaks
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 7684567fb..b46b5a303 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -228,7 +228,7 @@ public:
~FuncCallExpr() {
for (int i = 0; i < num_args; i++)
delete args[i];
- delete args;
+ delete[] args;
delete func;
}
};
@@ -623,6 +623,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
if (v == NULL || v->name != "nil")
*os << " = " << *def;
*os << std::endl;
+ delete def;
}
if (rev_iffupjmp_map.find(start) != rev_iffupjmp_map.end()) {
Commit: ea5b7ac38e4000111702c57e31835a5ee20bae2f
https://github.com/scummvm/scummvm-tools/commit/ea5b7ac38e4000111702c57e31835a5ee20bae2f
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-22T21:36:31+02:00
Commit Message:
DELUA: Don't search a POP after a SETTABLE0
This partially fixs the decompilation of _system.lua from MI4 retail.
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index b46b5a303..4d0331de1 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -388,11 +388,12 @@ void Decompiler::do_multi_assign(Byte *&start) {
case SETTABLE:
start++; // assume offset is correct
- case SETTABLE0:
- results.push(new IndexExpr(start, NULL, NULL));
num_tables++;
// this needs stuff from farther up the stack, wait until
// it's available
+
+ case SETTABLE0:
+ results.push(new IndexExpr(start, NULL, NULL));
break;
default:
Commit: 92d9f2d4b9b35492330455f2d9260db3cc77239c
https://github.com/scummvm/scummvm-tools/commit/92d9f2d4b9b35492330455f2d9260db3cc77239c
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-22T23:41:37+02:00
Commit Message:
DELUA: Decompile correctly access to the table fields
It now distinguishes correctly
simpleexp '[' exp1 ']'
from
simpleexp '.' name
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 4d0331de1..9bd047953 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -182,7 +182,7 @@ public:
IndexExpr(Byte *p, Expression *tbl, Expression *i)
: Expression(p), table(tbl), index(i) { }
Expression *table, *index;
- void print(std::ostream &os) const {
+ virtual void print(std::ostream &os) const {
table->print(os);
StringExpr *field = dynamic_cast<StringExpr *>(index);
if (field != NULL && field->validIdentifier())
@@ -190,16 +190,36 @@ public:
else
os << "[" << *index << "]";
}
+
~IndexExpr() {
delete table;
delete index;
}
};
+class DotIndexExpr : public IndexExpr {
+public:
+ DotIndexExpr(Byte *p, Expression *tbl, Expression *i) : IndexExpr(p, tbl, i) { }
+ virtual void print(std::ostream &os) const {
+ table->print(os);
+ StringExpr *field = dynamic_cast<StringExpr *>(index);
+ os << "." << field->text->str;
+ }
+};
+
+class BracketsIndexExpr : public IndexExpr {
+public:
+ BracketsIndexExpr(Byte *p, Expression *tbl, Expression *i) : IndexExpr(p, tbl, i) { }
+ virtual void print(std::ostream &os) const {
+ table->print(os);
+ os << "[" << *index << "]";
+ }
+};
+
class SelfExpr : public IndexExpr {
public:
SelfExpr(Byte *p, Expression *tbl, StringExpr *i) : IndexExpr(p, tbl, i) { }
- void print(std::ostream &os) const {
+ virtual void print(std::ostream &os) const {
StringExpr *field = static_cast<StringExpr *>(index);
os << *table << ":" << field->text->str;
}
@@ -778,7 +798,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
Expression *index = stk->top(); stk->pop();
Expression *table = stk->top(); stk->pop();
- stk->push(new IndexExpr(start, table, index));
+ stk->push(new BracketsIndexExpr(start, table, index));
}
break;
@@ -803,7 +823,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
getdotted:
{
Expression *tbl = stk->top(); stk->pop();
- stk->push(new IndexExpr(start, tbl, new StringExpr
+ stk->push(new DotIndexExpr(start, tbl, new StringExpr
(start, tsvalue(tf->consts + aux))));
}
break;
Commit: 11cf6bed6ce90fa0d00fa6c4e4aa4848308b854a
https://github.com/scummvm/scummvm-tools/commit/11cf6bed6ce90fa0d00fa6c4e4aa4848308b854a
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-22T23:41:37+02:00
Commit Message:
DELUA: Lua expects escape sequences for special characters with decimal digits
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 9bd047953..5240b3868 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -141,7 +141,7 @@ public:
os << special_text[i];
}
else if (! isprint(c))
- os << "\\" << int(c >> 6) << int((c >> 3) & 7) << int(c & 7);
+ os << "\\" << std::dec << (unsigned int)(c);
else
os << c;
}
Commit: 4d6c46b1d719480f2b909d7f84b29b0befa31f77
https://github.com/scummvm/scummvm-tools/commit/4d6c46b1d719480f2b909d7f84b29b0befa31f77
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-24T15:22:58+02:00
Commit Message:
DELUA: In validIdentifier checks if the string isn't a reserved word
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 5240b3868..e86925784 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -113,6 +113,9 @@ public:
StringExpr(Byte *p, TaggedString *txt) : Expression(p), text(txt) { }
TaggedString *text;
bool validIdentifier() const {
+ static const char *reserved [] = {"and", "do", "else", "elseif", "end", "function",
+ "if", "local", "nil", "not", "or", "repeat", "return", "then",
+ "until", "while"}; //Taken from llex.cpp
if (text->u.s.len == 0)
return false;
if (isdigit(text->str[0]))
@@ -124,6 +127,9 @@ public:
if ((! isalnum(c)) && c != '_')
return false;
}
+ for (unsigned int i = 0; i < (sizeof(reserved) / sizeof(reserved[0])); i++)
+ if (strncmp(text->str, reserved[i], text->u.s.len) == 0)
+ return false;
return true;
}
void print(std::ostream &os) const {
Commit: 9428d0a2ef67ddeedc9c6c212938925d01a416f1
https://github.com/scummvm/scummvm-tools/commit/9428d0a2ef67ddeedc9c6c212938925d01a416f1
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-24T15:23:03+02:00
Commit Message:
DELUA: Add a sanity-check on the input file
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index e86925784..12613216a 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -1331,6 +1331,11 @@ int main(int argc, char *argv[]) {
TProtoFunc *tf = luaU_undump1(&z);
fclose(f);
+ if (tf == NULL) {
+ fprintf(stderr, "%s isn't a valid lua script\n", filename);
+ exit(1);
+ }
+
decompile(std::cout, tf, "", NULL, 0);
lua_close();
Commit: 82f1aaaf2f0cafe4be86b57718ba678635140051
https://github.com/scummvm/scummvm-tools/commit/82f1aaaf2f0cafe4be86b57718ba678635140051
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-24T15:23:03+02:00
Commit Message:
DELUA: Avoid multiple definitions of local variables
This fix a bug which happens if a local is defined before
a repeat/until loop
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 12613216a..001ff08d7 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -651,6 +651,8 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
*os << " = " << *def;
*os << std::endl;
delete def;
+
+ local_var_defs->erase(start);
}
if (rev_iffupjmp_map.find(start) != rev_iffupjmp_map.end()) {
Commit: 6c0e2cff7f653a068a7a36ee302f4ed0d3e77052
https://github.com/scummvm/scummvm-tools/commit/6c0e2cff7f653a068a7a36ee302f4ed0d3e77052
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-24T15:23:03+02:00
Commit Message:
DELUA: Add a space before and after the concatenation operator
This fix the decompilation of lav.lua from MI4 Windows retail
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 001ff08d7..163479ae8 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -1000,7 +1000,7 @@ void Decompiler::decompileRange(Byte *start, Byte *end) {
break;
case CONCOP:
- do_binary_op(start, 2, false, "..");
+ do_binary_op(start, 2, false, " .. ");
break;
case MINUSOP:
Commit: 5eb746192a0c72078ef8151913b58ecead9b67b0
https://github.com/scummvm/scummvm-tools/commit/5eb746192a0c72078ef8151913b58ecead9b67b0
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-24T22:02:31+02:00
Commit Message:
LUAC: Implement a better floating point comparison
Changed paths:
tools/luac/rebase.c
diff --git a/tools/luac/rebase.c b/tools/luac/rebase.c
index 18bb028e5..d9cd7ae4c 100644
--- a/tools/luac/rebase.c
+++ b/tools/luac/rebase.c
@@ -48,8 +48,13 @@ void uniform_const_list(TProtoFunc* func, TProtoFunc* base) {
continue;
for (j = 0; j < func->nconsts; ++j)
- if (cmp(&base->consts[i], &func->consts[j]))
+ if (cmp(&base->consts[i], &func->consts[j])) {
+ //Set the value of numbers to the value of base functions
+ //since they could be sligthly differents (rounding errors)
+ if (ttype(&base->consts[i]) == LUA_T_NUMBER)
+ nvalue(&func->consts[j]) = nvalue(&base->consts[i]);
break;
+ }
if (j == func->nconsts) { //Const not found, re-add it
if (func->nconsts + 1 >= max_const)
@@ -210,9 +215,20 @@ bool cmp(const TObject *a, const TObject *b) {
if (ttype(a) == LUA_T_PROTO)
return true;
- if (ttype(a) == LUA_T_NUMBER)
- if (nvalue(a) == nvalue(b))
+ if (ttype(a) == LUA_T_NUMBER) {
+ //A simple fp comparision
+ double diff, fa, fb, largest;
+
+ diff = fabs(nvalue(a) - nvalue(b));
+ fa = fabs(nvalue(a));
+ fb = fabs(nvalue(b));
+ largest = (fb > fa) ? fb : fa;
+
+ if (diff <= largest * 1e-5) //Ten parts in a million should be enough
return true;
+ else
+ return false;
+ }
if (ttype(a) == LUA_T_STRING)
if (strncmp(svalue(a), svalue(b), tsvalue(a)->u.s.len) == 0)
Commit: f9ec24268f57f8450398cba8e35aa1f19d64b4ac
https://github.com/scummvm/scummvm-tools/commit/f9ec24268f57f8450398cba8e35aa1f19d64b4ac
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-08-24T22:02:31+02:00
Commit Message:
LUAC: Improve a little the performances of rebase function
Changed paths:
tools/luac/rebase.c
diff --git a/tools/luac/rebase.c b/tools/luac/rebase.c
index d9cd7ae4c..f563801ac 100644
--- a/tools/luac/rebase.c
+++ b/tools/luac/rebase.c
@@ -38,7 +38,8 @@ void rebase(TProtoFunc* func, TProtoFunc* base) {
}
void uniform_const_list(TProtoFunc* func, TProtoFunc* base) {
- int i, j, k;
+ int i, j, k, j0;
+ j0 = 0;
//Part1: Add back the deleted constant into the new function
int max_const = func->nconsts;
@@ -47,8 +48,10 @@ void uniform_const_list(TProtoFunc* func, TProtoFunc* base) {
if (ttype(&base->consts[i]) == LUA_T_PROTO)
continue;
- for (j = 0; j < func->nconsts; ++j)
+ for (j = j0; j < func->nconsts; ++j)
if (cmp(&base->consts[i], &func->consts[j])) {
+ j0 = j + 1;
+
//Set the value of numbers to the value of base functions
//since they could be sligthly differents (rounding errors)
if (ttype(&base->consts[i]) == LUA_T_NUMBER)
Commit: 4c9059728a19bf5bea51f2da860c8a1ed41f23b9
https://github.com/scummvm/scummvm-tools/commit/4c9059728a19bf5bea51f2da860c8a1ed41f23b9
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2012-12-17T12:22:50+01:00
Commit Message:
COMMON: Refactor the build system.
Changed paths:
A common/module.mk
A tools/luac/dump.cpp
A tools/luac/luac.cpp
A tools/luac/module.mk
A tools/luac/opcode.cpp
A tools/luac/opt.cpp
A tools/luac/print.cpp
A tools/luac/rebase.cpp
R tools/luac/dump.c
R tools/luac/luac.c
R tools/luac/opcode.c
R tools/luac/opt.c
R tools/luac/print.c
R tools/luac/rebase.c
Makefile.common
rules.mk
tools/lua/module.mk
tools/luac/luac.h
tools/module.mk
diff --git a/Makefile.common b/Makefile.common
index 9d6f2318d..1354b528b 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -13,11 +13,7 @@ all: build
# Module settings
######################################################################
-MODULES := tools/lua tools $(MODULES)
-
-# After the game specific modules follow the shared modules
-MODULES +=
-# common
+MODULES := common tools/lua tools/luac tools $(MODULES)
######################################################################
# The build rules follow - normally you should have no need to
@@ -26,6 +22,7 @@ MODULES +=
# Concat DEFINES and INCLUDES to form the CPPFLAGS
CPPFLAGS := $(DEFINES) $(INCLUDES)
+LDFLAGS += $(addprefix "-L", $(MODULES))
# Include the build instructions for all modules
-include $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES)))
@@ -60,6 +57,9 @@ endif
endif
endif
+dirs:
+ $(QUIET)$(MKDIR) $(MODULE_DIRS)
+
build: dirs $(OBJS) $(MODULES)
distclean: clean
diff --git a/common/module.mk b/common/module.mk
new file mode 100644
index 000000000..52c231917
--- /dev/null
+++ b/common/module.mk
@@ -0,0 +1,8 @@
+MODULE := common
+
+MODULE_OBJS := \
+ md5.o \
+ zlib.o
+
+# Include common rules
+include $(srcdir)/rules.mk
diff --git a/rules.mk b/rules.mk
index 5ab375476..eefc57e3b 100644
--- a/rules.mk
+++ b/rules.mk
@@ -3,38 +3,54 @@
#
###############################################
+ifdef TOOL
# Copy the list of objects to a new variable. The name of the new variable
# contains the module name, a trick we use so we can keep multiple different
# module object lists, one for each module.
-MODULE_OBJS-$(MODULE) := $(addprefix $(MODULE)/, $(MODULE_OBJS))
+TOOL_OBJS-$(TOOL) := $(addprefix $(MODULE)/, $(TOOL_OBJS))
# Add all involved directories to the MODULE_DIRS list
-MODULE_DIRS += $(sort $(dir $(MODULE_OBJS-$(MODULE))))
+MODULE_DIRS += $(sort $(dir $(TOOL_OBJS-$(TOOL))))
+LDFLAGS_$(TOOL)$(EXEEXT) := $(TOOL_LDFLAGS)
+$(MODULE)/$(TOOL)$(EXEEXT): $(TOOL_OBJS-$(TOOL))
+ $(QUIET_CXX)$(CXX) $(LDFLAGS) $+ $(LDFLAGS_$(@F)) -o $(@F)
-ifdef TOOL_EXECUTABLE
-################################################
-# Build rule for (tool) executables.
-# TODO: Refactor this, so that even our master executable can use this rule?
-################################################
-TOOL-$(MODULE) := $(MODULE)/$(TOOL_EXECUTABLE)$(EXEEXT)
-$(TOOL-$(MODULE)): $(MODULE_OBJS-$(MODULE)) $(TOOL_DEPS)
- $(QUIET_CXX)$(CXX) $(LDFLAGS) $+ -o $@
+$(TOOL): $(TOOL_DEPS) $(MODULE)/$(TOOL)$(EXEEXT)
+
+tools: $(MAKE)
+
+clean: clean-$(TOOL)
+clean-$(TOOL): clean-% :
+ -$(RM) $(TOOL_OBJS-$*) $(TOOL-$*) $(TOOL)$(EXEEXT)
+
+dist-clean: dist-clean/$(TOOL)
+dist-clean/$(TOOL): dist-clean/% : clean-%
+ -$(RM) $(@F)$(EXEEXT)
+
+.PHONY: clean-$(TOOL) $(TOOL)
# Reset TOOL_* vars
-TOOL_EXECUTABLE:=
+TOOL:=
TOOL_DEPS:=
+TOOL_LDFLAGS:=
-# Add to "devtools" target
-devtools: $(TOOL-$(MODULE))
+else
+
+#############################################################
+
+
+# Copy the list of objects to a new variable. The name of the new variable
+# contains the module name, a trick we use so we can keep multiple different
+# module object lists, one for each module.
+MODULE_OBJS-$(MODULE) := $(addprefix $(MODULE)/, $(MODULE_OBJS))
+
+# Add all involved directories to the MODULE_DIRS list
+MODULE_DIRS += $(sort $(dir $(MODULE_OBJS-$(MODULE))))
-# Pseudo target for comfort, allows for "make devtools/skycpt", etc.
-$(MODULE): $(TOOL-$(MODULE))
-clean-devtools: clean-$(MODULE)
-else
ifdef PLUGIN
################################################
# Build rule for dynamic (loadable) plugins
@@ -76,7 +92,6 @@ $(MODULE_LIB-$(MODULE)): $(MODULE_OBJS-$(MODULE))
$(MODULE): $(MODULE_LIB-$(MODULE))
endif # PLUGIN
-endif # TOOL_EXECUTABLE
###############################################
# Clean target, removes all object files. This looks a bit hackish, as we have to
@@ -88,3 +103,5 @@ clean-$(MODULE): clean-% :
-$(RM) $(MODULE_OBJS-$*) $(MODULE_LIB-$*) $(PLUGIN-$*) $(TOOL-$*)
.PHONY: clean-$(MODULE) $(MODULE)
+
+endif # TOOL
diff --git a/tools/lua/module.mk b/tools/lua/module.mk
index 4b46be619..4e80862c4 100644
--- a/tools/lua/module.mk
+++ b/tools/lua/module.mk
@@ -26,7 +26,3 @@ MODULE_OBJS := \
# Include common rules
include $(srcdir)/rules.mk
-
-dirs:
- $(QUIET)$(MKDIR) tools/lua
- $(QUIET)$(MKDIR) tools/patchex
diff --git a/tools/luac/dump.c b/tools/luac/dump.cpp
similarity index 100%
rename from tools/luac/dump.c
rename to tools/luac/dump.cpp
diff --git a/tools/luac/luac.c b/tools/luac/luac.cpp
similarity index 98%
rename from tools/luac/luac.c
rename to tools/luac/luac.cpp
index 459abc3a5..6afb9a23d 100644
--- a/tools/luac/luac.c
+++ b/tools/luac/luac.cpp
@@ -8,9 +8,9 @@
#include <stdlib.h>
#include <string.h>
#include "luac.h"
-#include "lparser.h"
-#include "lzio.h"
-#include "luadebug.h"
+#include "tools/lua/lparser.h"
+#include "tools/lua/lzio.h"
+#include "tools/lua/luadebug.h"
#define OUTPUT "luac.out" /* default output file */
diff --git a/tools/luac/luac.h b/tools/luac/luac.h
index 3e7e8d9eb..77f3eb11f 100644
--- a/tools/luac/luac.h
+++ b/tools/luac/luac.h
@@ -4,12 +4,12 @@
** See Copyright Notice in lua.h
*/
-#include "lauxlib.h"
-#include "lfunc.h"
-#include "lobject.h"
-#include "lopcodes.h"
-#include "lstring.h"
-#include "lundump.h"
+#include "tools/lua/lauxlib.h"
+#include "tools/lua/lfunc.h"
+#include "tools/lua/lobject.h"
+#include "tools/lua/lopcodes.h"
+#include "tools/lua/lstring.h"
+#include "tools/lua/lundump.h"
#include "common/endian.h"
typedef struct
diff --git a/tools/luac/module.mk b/tools/luac/module.mk
new file mode 100644
index 000000000..18ab5004d
--- /dev/null
+++ b/tools/luac/module.mk
@@ -0,0 +1,19 @@
+MODULE := tools/luac
+
+TOOL_OBJS := \
+ dump.o \
+ luac.o \
+ opcode.o \
+ opt.o \
+ print.o \
+ rebase.o \
+
+TOOL := luac
+TOOL_DEPS := tools/lua
+TOOL_LDFLAGS := -Ltools/lua -llua
+
+MAKE := luac
+
+# Include common rules
+include $(srcdir)/rules.mk
+
diff --git a/tools/luac/opcode.c b/tools/luac/opcode.cpp
similarity index 100%
rename from tools/luac/opcode.c
rename to tools/luac/opcode.cpp
diff --git a/tools/luac/opt.c b/tools/luac/opt.cpp
similarity index 99%
rename from tools/luac/opt.c
rename to tools/luac/opt.cpp
index 8fc0e8f6a..c0e13e48c 100644
--- a/tools/luac/opt.c
+++ b/tools/luac/opt.cpp
@@ -7,7 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "luac.h"
-#include "lmem.h"
+#include "tools/lua/lmem.h"
static void FixConstants(TProtoFunc* tf, int* C)
{
diff --git a/tools/luac/print.c b/tools/luac/print.cpp
similarity index 100%
rename from tools/luac/print.c
rename to tools/luac/print.cpp
diff --git a/tools/luac/rebase.c b/tools/luac/rebase.cpp
similarity index 99%
rename from tools/luac/rebase.c
rename to tools/luac/rebase.cpp
index f563801ac..d67a2bb65 100644
--- a/tools/luac/rebase.c
+++ b/tools/luac/rebase.cpp
@@ -2,8 +2,8 @@
#include <stdlib.h>
#include <string.h>
#include "luac.h"
-#include "lmem.h"
-#include "lstring.h"
+#include "tools/lua/lmem.h"
+#include "tools/lua/lstring.h"
static const Opcode Info[]= /* ORDER lopcodes.h */
{
diff --git a/tools/module.mk b/tools/module.mk
index 9a80aa331..2bd2f630b 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -1,152 +1,119 @@
MODULE := tools
-MODULE_DIRS += \
- tools/
-
#######################################################################
# Tools directory
#######################################################################
-TOOLS := \
- tools/delua$(EXEEXT) \
- tools/imc2wav$(EXEEXT) \
- tools/int2flt$(EXEEXT) \
- tools/cosb2cos$(EXEEXT) \
- tools/meshb2obj$(EXEEXT) \
- tools/sklb2txt$(EXEEXT) \
- tools/animb2txt$(EXEEXT) \
- tools/setb2set$(EXEEXT) \
- tools/set2fig$(EXEEXT) \
- tools/til2bmp$(EXEEXT) \
- tools/unlab$(EXEEXT) \
- tools/mklab$(EXEEXT) \
- tools/vima$(EXEEXT) \
- tools/labcopy$(EXEEXT) \
- tools/luac/luac$(EXEEXT) \
- tools/patchex/patchex$(EXEEXT) \
- tools/diffr$(EXEEXT) \
- tools/patchr$(EXEEXT)
-
-# below not added as it depends for ppm, bpm library
-# tools/mat2ppm$(EXEEXT)
-# tools/bm2ppm$(EXEEXT)
-
-# Make sure the 'all' / 'clean' targets build/clean the tools, too
-#all:
-clean: clean-tools
-
-# Main target
-tools: $(TOOLS)
-
-clean-tools:
- -$(RM) $(TOOLS)
- -$(RM) tools/emi/*.o
- -$(RM) tools/patchex/*.o
- -$(RM) -r tools/patchex/.deps
- -$(RM) -r tools/luac/*.o
- -$(RM) -r tools/luac/.deps
+MAKE := \
+ delua \
+ imc2wav \
+ int2flt \
+ cosb2cos \
+ meshb2obj \
+ sklb2txt \
+ animb2txt \
+ setb2set \
+ set2fig \
+ til2bmp \
+ unlab \
+ mklab \
+ vima \
+ labcopy \
+ luac \
+ patchex \
+ diffr \
+ patchr
+
+# these below are not added because they depend on the ppm and bpm libraries
+# mat2ppm
+# bm2ppm
+
#
# Build rules for the tools
#
-tools/diffr$(EXEEXT): $(srcdir)/tools/diffr.cpp $(srcdir)/common/md5.o $(srcdir)/common/zlib.o
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common $(srcdir)/common/md5.o $(srcdir)/common/zlib.o -lz -o $@ $< $(LDFLAGS)
-
-tools/patchr$(EXEEXT): $(srcdir)/tools/patchr.cpp $(srcdir)/common/md5.o $(srcdir)/common/zlib.o
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common $(srcdir)/common/md5.o $(srcdir)/common/zlib.o -lz -o $@ $< $(LDFLAGS)
-
-tools/delua$(EXEEXT): $(srcdir)/tools/delua.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -Ltools/lua -o $@ $< $(LDFLAGS) -llua
-
-#g++ -DHAVE_CONFIG_H -DUNIX -I. -I./tools/luac -I ./tools/lua -c -o tools/luac/print.o tools/luac/print.c
-
-tools/luac/luac$(EXEEXT):
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/dump.o tools/luac/dump.c
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/luac.o tools/luac/luac.c
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/opcode.o tools/luac/opcode.c
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/opt.o tools/luac/opt.c
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/print.o tools/luac/print.c
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I$(srcdir)/tools/lua -c -o tools/luac/rebase.o tools/luac/rebase.c
- $(MKDIR) tools/luac/$(DEPDIR)
- $(CXX) $(CFLAGS) tools/luac/dump.o tools/luac/luac.o tools/luac/opcode.o tools/luac/opt.o tools/luac/print.o tools/luac/rebase.o -Wall -L$(srcdir)/tools/lua -llua -o $@ $< $(LDFLAGS)
-
-tools/mat2ppm$(EXEEXT): $(srcdir)/tools/mat2ppm.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -lppm -o $@ $< $(LDFLAGS)
-
-tools/bmtoppm$(EXEEXT): $(srcdir)/tools/bmtoppm.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -lppm -lpbm -o $@ $< $(LDFLAGS)
-
-tools/imc2wav$(EXEEXT): $(srcdir)/tools/imc2wav.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
-
-tools/int2flt$(EXEEXT): $(srcdir)/tools/int2flt.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
-
-tools/cosb2cos$(EXEEXT): $(srcdir)/tools/emi/cosb2cos.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common -o $@ $< $(LDFLAGS)
-
-tools/meshb2obj$(EXEEXT): $(srcdir)/tools/emi/meshb2obj.o $(srcdir)/tools/emi/lab.o
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
-
-tools/animb2txt$(EXEEXT): $(srcdir)/tools/emi/animb2txt.cpp $(srcdir)/tools/emi/lab.o
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
-
-tools/setb2set$(EXEEXT): $(srcdir)/tools/emi/setb2set.cpp $(srcdir)/tools/emi/lab.o
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
-
-tools/sklb2txt$(EXEEXT): $(srcdir)/tools/emi/sklb2txt.cpp $(srcdir)/tools/emi/lab.o
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS)
-
-tools/set2fig$(EXEEXT): $(srcdir)/tools/set2fig.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
-
-tools/til2bmp$(EXEEXT): $(srcdir)/tools/emi/til2bmp.cpp $(srcdir)/tools/emi/lab.o
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -I. -Wall \
- -L$(srcdir)/common tools/emi/lab.o -o $@ $< $(LDFLAGS) -lz
-
-tools/unlab$(EXEEXT): $(srcdir)/tools/unlab.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
-
-tools/mklab$(EXEEXT): $(srcdir)/tools/mklab.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
-
-tools/vima$(EXEEXT): $(srcdir)/tools/vima.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) -Wall -o $@ $< $(LDFLAGS)
-
-tools/labcopy$(EXEEXT): $(srcdir)/tools/labcopy.cpp
- $(MKDIR) tools/$(DEPDIR)
- $(CXX) $(CFLAGS) $(DEFINES) -DHAVE_CONFIG_H -I$(srcdir) -Wall \
- -L$(srcdir)/common -o $@ $< $(LDFLAGS)
-
-tools/patchex/patchex$(EXEEXT): tools/patchex/patchex.o tools/patchex/mszipd.o tools/patchex/cabd.o
- $(MKDIR) tools/patchex/$(DEPDIR)
- $(CXX) $(CFLAGS) tools/patchex/mszipd.o tools/patchex/cabd.o -Wall -o $@ $< $(LDFLAGS)
+TOOL := diffr
+TOOL_OBJS := diffr.o
+TOOL_LDFLAGS := -lz -lcommon
+include $(srcdir)/rules.mk
+
+TOOL := patchr
+TOOL_OBJS := patchr.o
+TOOL_LDFLAGS := -lz -lcommon
+include $(srcdir)/rules.mk
+
+TOOL := delua
+TOOL_OBJS := delua.o
+TOOL_LDFLAGS := -Ltools/lua -llua
+include $(srcdir)/rules.mk
+
+TOOL := mat2ppm
+TOOL_OBJS := mat2ppm.o
+TOOL_LDFLAGS := -lppm -lpbm
+include $(srcdir)/rules.mk
+
+TOOL := bmtoppm
+TOOL_OBJS := bmtoppm.o
+TOOL_LDFLAGS := -lppm -lpbm
+include $(srcdir)/rules.mk
+
+TOOL := imc2wav
+TOOL_OBJS := imc2wav.o
+include $(srcdir)/rules.mk
+
+TOOL := int2flt
+TOOL_OBJS := int2flt.o
+include $(srcdir)/rules.mk
+
+TOOL := cosb2cos
+TOOL_OBJS := emi/cosb2cos.o
+include $(srcdir)/rules.mk
+
+TOOL := meshb2obj
+TOOL_OBJS := emi/meshb2obj.o emi/lab.o
+include $(srcdir)/rules.mk
+
+TOOL := animb2txt
+TOOL_OBJS := emi/animb2txt.o emi/lab.o
+include $(srcdir)/rules.mk
+
+TOOL := setb2set
+TOOL_OBJS := emi/setb2set.o emi/lab.o
+include $(srcdir)/rules.mk
+
+TOOL := sklb2txt
+TOOL_OBJS := emi/sklb2txt.o emi/lab.o
+include $(srcdir)/rules.mk
+
+TOOL := set2fig
+TOOL_OBJS := set2fig.o
+include $(srcdir)/rules.mk
+
+TOOL := til2bmp
+TOOL_OBJS := emi/til2bmp.o emi/lab.o
+TOOL_LDFLAGS := -lz
+include $(srcdir)/rules.mk
+
+TOOL := unlab
+TOOL_OBJS := unlab.o
+include $(srcdir)/rules.mk
+
+TOOL := mklab
+TOOL_OBJS := mklab.o
+include $(srcdir)/rules.mk
+
+TOOL := vima
+TOOL_OBJS := vima.o
+include $(srcdir)/rules.mk
+
+TOOL := labcopy
+TOOL_OBJS := labcopy.o
+include $(srcdir)/rules.mk
+
+TOOL := patchex
+TOOL_OBJS := patchex/patchex.o patchex/mszipd.o patchex/cabd.o
+include $(srcdir)/rules.mk
.PHONY: clean-tools tools
Commit: 30009e868f25cc53055781a87e320446ec06d218
https://github.com/scummvm/scummvm-tools/commit/30009e868f25cc53055781a87e320446ec06d218
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2012-12-20T09:34:34-08:00
Commit Message:
Merge pull request #27 from giucam/buildsystem
Refactor the build system.
Changed paths:
A common/module.mk
A tools/luac/dump.cpp
A tools/luac/luac.cpp
A tools/luac/module.mk
A tools/luac/opcode.cpp
A tools/luac/opt.cpp
A tools/luac/print.cpp
A tools/luac/rebase.cpp
R tools/luac/dump.c
R tools/luac/luac.c
R tools/luac/opcode.c
R tools/luac/opt.c
R tools/luac/print.c
R tools/luac/rebase.c
Makefile.common
rules.mk
tools/lua/module.mk
tools/luac/luac.h
tools/module.mk
Commit: 78cd2ba2a3fbc29608cb284b6fc6cef6bdbd56b7
https://github.com/scummvm/scummvm-tools/commit/78cd2ba2a3fbc29608cb284b6fc6cef6bdbd56b7
Author: Dries Harnie (dries at harnie.be)
Date: 2012-12-23T22:33:23+01:00
Commit Message:
COMMON: Fix compilation order.
Swap the order of -lz and -lcommon around, fixes #28.
Changed paths:
tools/module.mk
diff --git a/tools/module.mk b/tools/module.mk
index 2bd2f630b..ca8aa515c 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -36,12 +36,12 @@ MAKE := \
TOOL := diffr
TOOL_OBJS := diffr.o
-TOOL_LDFLAGS := -lz -lcommon
+TOOL_LDFLAGS := -lcommon -lz
include $(srcdir)/rules.mk
TOOL := patchr
TOOL_OBJS := patchr.o
-TOOL_LDFLAGS := -lz -lcommon
+TOOL_LDFLAGS := -lcommon -lz
include $(srcdir)/rules.mk
TOOL := delua
Commit: ba0cd00e2c2d3709fdcb1bad2ebbf5f2932c8654
https://github.com/scummvm/scummvm-tools/commit/ba0cd00e2c2d3709fdcb1bad2ebbf5f2932c8654
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2012-12-23T23:29:34+01:00
Commit Message:
TOOLS: Fix a bunch of warnings
Changed paths:
tools/emi/animb2txt.cpp
tools/emi/meshb2obj.cpp
tools/emi/setb2set.cpp
tools/emi/til2bmp.cpp
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index aa5284de2..32b32acdf 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -64,14 +64,14 @@ int main(int argc, char **argv) {
" Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
if (operation == 3) { // Translation
- for(int i = 0; i < numKeyframes; i++) {
+ for(int j = 0; i < numKeyframes; i++) {
time = readFloat(*file);
vec3d = readVector3d(*file);
std::cout << "Time : " << time << " Vector: " << vec3d->toString() << std::endl;
delete vec3d;
}
} else if (operation == 4) { // Rotation
- for(int i = 0; i < numKeyframes; i++) {
+ for(int j = 0; i < numKeyframes; i++) {
time = readFloat(*file);
vec4d = readVector4d(*file);
std::cout << "Time : " << time << " Vector: " << vec4d->toString() << std::endl;
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index 32852e7ca..cfcaff1b8 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -131,13 +131,13 @@ int main(int argc, char **argv) {
faceLength = readInt(*file);
std::cout << "#Face-header: flags: " << flags << " hasTexture: " << hasTexture
<< " texId: " << texID << " faceLength: " << faceLength << std::endl;
- short x = 0, y = 0, z = 0;
+ short xCoord = 0, yCoord = 0, zCoord = 0;
std::cout << "g " << j << std::endl;
for (int i = 0; i < faceLength; i += 3) {
- x = readShort(*file) + 1;
- y = readShort(*file) + 1;
- z = readShort(*file) + 1;
- std::cout << "f " << x << "//" << x << " " << y << "//" << y << " " << z << "//" << z << std::endl;
+ xCoord = readShort(*file) + 1;
+ yCoord = readShort(*file) + 1;
+ zCoord = readShort(*file) + 1;
+ std::cout << "f " << xCoord << "//" << xCoord << " " << yCoord << "//" << yCoord << " " << zCoord << "//" << zCoord << std::endl;
}
}
int hasBones = readInt(*file);
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index e9048fb27..036e1d9dc 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -92,6 +92,7 @@ void Data::Skip(int val)
struct Section {
public:
Section(Data *data);
+ virtual ~Section() {};
//virtual uint32 load() = 0;
virtual string ToString() = 0;
protected:
diff --git a/tools/emi/til2bmp.cpp b/tools/emi/til2bmp.cpp
index 07fa6a5ff..2f4951dfa 100644
--- a/tools/emi/til2bmp.cpp
+++ b/tools/emi/til2bmp.cpp
@@ -277,13 +277,13 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
width = FROM_LE_32(width);
til.read((char *)&height, 4);
height = FROM_LE_32(height);
- uint32_t size = width*height*bpp;
- char *data = new char[size];
+ uint32_t dataSize = width*height*bpp;
+ char *imageData = new char[dataSize];
char *outnamet = new char[64];
sprintf(outnamet,"%d.bmp",i);
- til.read(data, size);
+ til.read(imageData, dataSize);
- allTheData[i] = new LucasBitMap(data, width, height,bpp,false);
+ allTheData[i] = new LucasBitMap(imageData, width, height,bpp,false);
}
LucasBitMap* bit = MakeFullPicture(allTheData);
bit->WriteBMP(name.c_str());
Commit: ed562c55cdff2b39caa2aee99f4945568d932dee
https://github.com/scummvm/scummvm-tools/commit/ed562c55cdff2b39caa2aee99f4945568d932dee
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2012-12-23T23:32:55+01:00
Commit Message:
TOOLS: Correct loop-mistake in last commit
Changed paths:
tools/emi/animb2txt.cpp
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 32b32acdf..40d820218 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -64,14 +64,14 @@ int main(int argc, char **argv) {
" Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
if (operation == 3) { // Translation
- for(int j = 0; i < numKeyframes; i++) {
+ for(int j = 0; j < numKeyframes; j++) {
time = readFloat(*file);
vec3d = readVector3d(*file);
std::cout << "Time : " << time << " Vector: " << vec3d->toString() << std::endl;
delete vec3d;
}
} else if (operation == 4) { // Rotation
- for(int j = 0; i < numKeyframes; i++) {
+ for(int j = 0; j < numKeyframes; j++) {
time = readFloat(*file);
vec4d = readVector4d(*file);
std::cout << "Time : " << time << " Vector: " << vec4d->toString() << std::endl;
Commit: 76e2321d2c668d4594ab403c36041a4c8e62bb57
https://github.com/scummvm/scummvm-tools/commit/76e2321d2c668d4594ab403c36041a4c8e62bb57
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2012-12-30T14:58:52+01:00
Commit Message:
LUAC: Fix the jumps when rebasing a function
Changed paths:
tools/luac/rebase.cpp
diff --git a/tools/luac/rebase.cpp b/tools/luac/rebase.cpp
index d67a2bb65..0b9121e50 100644
--- a/tools/luac/rebase.cpp
+++ b/tools/luac/rebase.cpp
@@ -116,11 +116,57 @@ void rec_bytecode(TProtoFunc* func, int* inst) {
Byte* p = func->code;
- //Change const index
+ //Load opcodes in a more descriptive structure
i = 0;
- newsize = 0;
- while (1) {
+ do
p += INFO(func, p, &opcode_list[i]);
+ while (opcode_list[i++].op != ENDCODE);
+ luaM_free(func->code);
+ func->code = NULL;
+
+ //For jump instructions, calculate the number of
+ //instructions to skip/rewind, from the number of
+ //bytes to skip/rewind. The result is improperly
+ //stored in op.arg2, since it's a unused field.
+ for (i = 0; opcode_list[i].op != ENDCODE; ++i) {
+ Opcode &op = opcode_list[i];
+ int bytesToSkip, instToSkip, bytesToRewind, instToRewind, j;
+
+ switch (op.op_class) {
+ //Forward jump
+ case ONTJMP:
+ case ONFJMP:
+ case JMP:
+ case IFFJMP:
+ bytesToSkip = op.arg;
+ instToSkip = 0;
+ j = i;
+ while (bytesToSkip > 0) {
+ instToSkip++;
+ bytesToSkip -= opcode_list[++j].size;
+ }
+ assert(bytesToSkip == 0);
+ op.arg2 = instToSkip;
+ break;
+
+ //Backwards jump
+ case IFTUPJMP:
+ case IFFUPJMP:
+ bytesToRewind = op.arg;
+ instToRewind = 0;
+ j = i;
+ while (bytesToRewind > 0) {
+ bytesToRewind -= opcode_list[j--].size;
+ instToRewind++;
+ }
+ assert(bytesToRewind == 0);
+ op.arg2 = instToRewind;
+ break;
+ }
+ }
+
+ //Change const index
+ for (i = 0; opcode_list[i].op != ENDCODE; ++i) {
Opcode &op = opcode_list[i];
//Change const index, if needed
@@ -133,14 +179,73 @@ void rec_bytecode(TProtoFunc* func, int* inst) {
op.arg = inst[op.arg];
fix_op(&op);
}
-
- newsize += op.size;
- ++i;
- if (op.op == ENDCODE)
- break;
}
- luaM_free(func->code);
+ //Recalculate the number of bytes to jump
+ bool expJmp;
+ do {
+ expJmp = false;
+
+ for (i = 0; opcode_list[i].op != ENDCODE; ++i) {
+ Opcode &op = opcode_list[i];
+ int bytesToSkip, instToSkip, bytesToRewind, instToRewind, j;
+
+
+ switch (op.op_class) {
+ //Forward jump
+ case ONTJMP:
+ case ONFJMP:
+ case JMP:
+ case IFFJMP:
+ bytesToSkip = 0;
+ instToSkip = op.arg2;
+ j = i;
+ while (instToSkip > 0) {
+ instToSkip--;
+ bytesToSkip += opcode_list[++j].size;
+ }
+ assert(instToSkip == 0);
+ op.arg = bytesToSkip;
+ break;
+
+ //Backwards jump
+ case IFTUPJMP:
+ case IFFUPJMP:
+ bytesToRewind = 0;
+ instToRewind = op.arg2;
+ j = i;
+ while (instToRewind > 0) {
+ bytesToRewind += opcode_list[j--].size;
+ instToRewind--;
+ }
+ assert(instToRewind == 0);
+ op.arg = bytesToRewind;
+ break;
+
+ default:
+ continue;
+ }
+
+ //Expand JMPs to JMPWs, if needed.
+ //It set also the expJmp flag, in order
+ //to make another cycle, since this
+ //action changed again the code size
+ if (op.size == 2 && op.arg > 255) {
+ op.op++;
+ op.size++;
+ expJmp = true;
+ }
+ }
+ } while (expJmp);
+
+ //Calculate the size of new bytecode and
+ //alloc the space for it
+ i = 0;
+ newsize = 0;
+ do
+ newsize += opcode_list[i].size;
+ while (opcode_list[i++].op != ENDCODE);
+
Byte *code = (Byte*)luaM_malloc(newsize);
func->code = code;
Commit: 0c07c27bd2a1a681ef259a53b35ca0129f896e97
https://github.com/scummvm/scummvm-tools/commit/0c07c27bd2a1a681ef259a53b35ca0129f896e97
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2012-12-30T16:00:47+01:00
Commit Message:
TOOLS: Make lab.{h,cpp} detect if it is a Grim or EMI lab and move them in tools/.
Changed paths:
A tools/lab.cpp
A tools/lab.h
R tools/emi/lab.cpp
R tools/emi/lab.h
tools/emi/animb2txt.cpp
tools/emi/meshb2obj.cpp
tools/emi/setb2set.cpp
tools/emi/sklb2txt.cpp
tools/emi/til2bmp.cpp
tools/module.mk
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 40d820218..2184a20e3 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -21,7 +21,7 @@
#include <string>
#include <iostream>
#include "filetools.h"
-#include "lab.h"
+#include "tools/lab.h"
using namespace std;
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index cfcaff1b8..d8abad9f9 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -19,7 +19,7 @@
#include <string>
#include <iostream>
#include "filetools.h"
-#include "lab.h"
+#include "tools/lab.h"
int main(int argc, char **argv) {
if (argc < 2) {
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index 036e1d9dc..8f49fc3c7 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -11,7 +11,7 @@
#include <fstream>
#include <vector>
#include <sstream>
-#include "lab.h"
+#include "tools/lab.h"
using namespace std;
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
index 3fa95e156..c114f0113 100644
--- a/tools/emi/sklb2txt.cpp
+++ b/tools/emi/sklb2txt.cpp
@@ -2,7 +2,7 @@
#include <string>
#include <iostream>
#include "filetools.h"
-#include "lab.h"
+#include "tools/lab.h"
// Based on Benjamin Haischs work on sklb-files.
using namespace std;
diff --git a/tools/emi/til2bmp.cpp b/tools/emi/til2bmp.cpp
index 2f4951dfa..4e270ecb9 100644
--- a/tools/emi/til2bmp.cpp
+++ b/tools/emi/til2bmp.cpp
@@ -26,7 +26,7 @@
#include <cstdio>
#include <cstring>
#include "common/endian.h"
-#include "lab.h"
+#include "tools/lab.h"
/*
This tool converts EMI-TILEs into BMP-files, and supports both the format used in the Windows
diff --git a/tools/emi/lab.cpp b/tools/lab.cpp
similarity index 94%
rename from tools/emi/lab.cpp
rename to tools/lab.cpp
index 5eca05834..4af7f4651 100644
--- a/tools/emi/lab.cpp
+++ b/tools/lab.cpp
@@ -36,8 +36,6 @@ uint32 READ_LE_UINT32(const void *ptr) {
}
void Lab::Load(std::string filename) {
- g_type = GT_EMI; // FIXME, detect game-type properly.
-
infile = fopen(filename.c_str(), "rb");
if (infile == 0) {
std::cout << "Can not open source file: " << filename << std::endl;
@@ -49,8 +47,17 @@ void Lab::Load(std::string filename) {
uint32 num, s_size, s_offset;
fread(&num, 1, 4, infile);
fread(&s_size, 1, 4, infile);
- if(g_type == GT_EMI)
- fread(&s_offset,1,4,infile);
+
+ uint32 typeTest = 0;
+ fread(&typeTest, 1, 4, infile);
+ if (typeTest == 0) { // First entry of the table has offset 0 for Grim
+ g_type = GT_GRIM;
+ fseek(infile, -4, SEEK_CUR);
+ } else { // EMI has an offset instead.
+ s_offset = typeTest;
+ g_type = GT_EMI;
+ }
+
head.num_entries = READ_LE_UINT32(&num);
head.string_table_size = READ_LE_UINT32(&s_size);
if (0 != memcmp(&head.magic, "LABN", 4)) {
diff --git a/tools/emi/lab.h b/tools/lab.h
similarity index 100%
rename from tools/emi/lab.h
rename to tools/lab.h
diff --git a/tools/module.mk b/tools/module.mk
index ca8aa515c..6ed7f6382 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -72,19 +72,19 @@ TOOL_OBJS := emi/cosb2cos.o
include $(srcdir)/rules.mk
TOOL := meshb2obj
-TOOL_OBJS := emi/meshb2obj.o emi/lab.o
+TOOL_OBJS := emi/meshb2obj.o lab.o
include $(srcdir)/rules.mk
TOOL := animb2txt
-TOOL_OBJS := emi/animb2txt.o emi/lab.o
+TOOL_OBJS := emi/animb2txt.o lab.o
include $(srcdir)/rules.mk
TOOL := setb2set
-TOOL_OBJS := emi/setb2set.o emi/lab.o
+TOOL_OBJS := emi/setb2set.o lab.o
include $(srcdir)/rules.mk
TOOL := sklb2txt
-TOOL_OBJS := emi/sklb2txt.o emi/lab.o
+TOOL_OBJS := emi/sklb2txt.o lab.o
include $(srcdir)/rules.mk
TOOL := set2fig
@@ -92,7 +92,7 @@ TOOL_OBJS := set2fig.o
include $(srcdir)/rules.mk
TOOL := til2bmp
-TOOL_OBJS := emi/til2bmp.o emi/lab.o
+TOOL_OBJS := emi/til2bmp.o lab.o
TOOL_LDFLAGS := -lz
include $(srcdir)/rules.mk
Commit: 81ad269f3a0a3f9546775ab2e1cf970be7f807b8
https://github.com/scummvm/scummvm-tools/commit/81ad269f3a0a3f9546775ab2e1cf970be7f807b8
Author: Giulio Camuffo (giuliocamuffo at gmail.com)
Date: 2012-12-30T16:11:25+01:00
Commit Message:
TOOL: Add a tool to convert Grim's bm images to bmp bitmaps.
Changed paths:
A tools/bm2bmp.cpp
tools/module.mk
diff --git a/tools/bm2bmp.cpp b/tools/bm2bmp.cpp
new file mode 100644
index 000000000..2be560fe5
--- /dev/null
+++ b/tools/bm2bmp.cpp
@@ -0,0 +1,311 @@
+/* Residual - A 3D game interpreter
+*
+* Residual is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the AUTHORS
+* file distributed with this source distribution.
+
+* 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
+*
+*/
+
+/**
+ * A tool that converts Grim's bm images to bmp bitmaps.
+ */
+
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <zlib.h>
+#include <cassert>
+#include <sys/types.h>
+#include <sstream>
+#include <stdint.h>
+#include <cstdio>
+#include <cstring>
+#include "common/endian.h"
+#include "lab.h"
+
+struct BMPHeader {
+ uint32_t size;
+ uint32_t reserved;
+ uint32_t offset;
+ uint32_t headerSize;
+ int32_t width;
+ int32_t height;
+ uint32_t nplanesbpp;
+ uint32_t compress_type;
+ uint32_t bmp_bytesz;
+ int32_t hres;
+ int32_t vres;
+ uint32_t ncolors;
+ uint32_t nimpcolors;
+};
+
+class Bitmap {
+public:
+ ~Bitmap();
+
+ inline uint32_t size() const { return _height * _width * _bpp / 8; }
+
+ static Bitmap *load(const char *data, int len);
+
+ void toBMP(const std::string &fname);
+
+private:
+ Bitmap() { }
+
+ int _numImages;
+ char **_data;
+ int _bpp;
+ int _width;
+ int _height;
+};
+
+Bitmap::~Bitmap() {
+ for (int i = 0; i < _numImages; ++i) {
+ delete[] _data[i];
+ }
+ delete[] _data;
+}
+
+void Bitmap::toBMP(const std::string &fname) {
+ for (int img = 0; img < _numImages; ++img) {
+ std::stringstream name;
+ name << fname << '.' << img << ".bmp";
+ printf("Saving image %d to file %s\n", img, name.str().c_str());
+
+ std::fstream file(name.str().c_str(), std::fstream::out | std::fstream::binary);
+ BMPHeader header;
+ unsigned short bm = TO_LE_16(19778);
+ file.write((char*)&bm, 2);
+ header.size = TO_LE_32(size() + 54);
+ header.reserved = TO_LE_32(0);
+ header.width = TO_LE_32(_width);
+ header.height = TO_LE_32(_height);
+ header.offset = TO_LE_32(54);
+ header.headerSize = TO_LE_32(40);
+ if(_bpp == 32)
+ header.nplanesbpp = TO_LE_32(2097153);
+ else if(_bpp == 16)
+ header.nplanesbpp = TO_LE_32(1048577);
+ header.compress_type = TO_LE_32(0);
+ header.bmp_bytesz = TO_LE_32(0);
+ header.hres = TO_LE_32(2835);
+ header.vres = TO_LE_32(2835);
+ header.ncolors = TO_LE_32(0);
+ header.nimpcolors = TO_LE_32(0);
+ file.write((char *)&header, sizeof(BMPHeader));
+ for (int i = _height - 1; i >= 0; --i) {
+ char *d = _data[0] + (_width * i * _bpp / 8);
+ file.write(d, _width * _bpp / 8);
+ }
+ file.close();
+ }
+}
+
+#define GET_BIT do { bit = bitstr_value & 1; \
+bitstr_len--; \
+bitstr_value >>= 1; \
+if (bitstr_len == 0) { \
+ bitstr_value = READ_LE_UINT16(compressed); \
+ bitstr_len = 16; \
+ compressed += 2; \
+ } \
+} while (0)
+
+static bool decompress_codec3(const char *compressed, char *result, int maxBytes) {
+ int bitstr_value = READ_LE_UINT16(compressed);
+ int bitstr_len = 16;
+ compressed += 2;
+ bool bit;
+
+ int byteIndex = 0;
+ for (;;) {
+ GET_BIT;
+ if (bit == 1) {
+ if (byteIndex >= maxBytes) {
+ printf("Buffer overflow when decoding image: decompress_codec3 walked past the input buffer!\n");
+ return false;
+ }
+ else
+ *result++ = *compressed++;
+ ++byteIndex;
+ }
+ else {
+ GET_BIT;
+ int copy_len, copy_offset;
+ if (bit == 0) {
+ GET_BIT;
+ copy_len = 2 * bit;
+ GET_BIT;
+ copy_len += bit + 3;
+ copy_offset = *(uint8 *)(compressed++) - 0x100;
+ } else {
+ copy_offset = (*(uint8 *)(compressed) | (*(uint8 *)(compressed + 1) & 0xf0) << 4) - 0x1000;
+ copy_len = (*(uint8 *)(compressed + 1) & 0xf) + 3;
+ compressed += 2;
+ if (copy_len == 3) {
+ copy_len = *(uint8 *)(compressed++) + 1;
+ if (copy_len == 1)
+ return true;
+ }
+ }
+ while (copy_len > 0) {
+ if (byteIndex >= maxBytes) {
+ printf("Buffer overflow when decoding image: decompress_codec3 walked past the input buffer!\n");
+ return false;
+ }
+ else {
+ assert(byteIndex + copy_offset >= 0);
+ assert(byteIndex + copy_offset < maxBytes);
+ *result = result[copy_offset];
+ result++;
+ }
+ ++byteIndex;
+ copy_len--;
+ }
+ }
+ }
+ return true;
+}
+
+Bitmap *Bitmap::load(const char *data, int len) {
+ if (len < 8 || memcmp(data, "BM F\0\0\0", 8) != 0) {
+ printf("Invalid magic loading bitmap.\n");
+ return NULL;
+ }
+
+ Bitmap *b = new Bitmap();
+
+ int codec = READ_LE_UINT32(data + 8);
+// _paletteIncluded = READ_LE_UINT32(data + 12);
+ b->_numImages = READ_LE_UINT32(data + 16);
+// int x = READ_LE_UINT32(data + 20);
+// int y = READ_LE_UINT32(data + 24);
+// _transparentColor = READ_LE_UINT32(data + 28);
+ int format = READ_LE_UINT32(data + 32);
+
+ if (format != 1) {
+ printf("ZBuffer images are not supported.\n");
+ return NULL;
+ }
+
+ b->_bpp = READ_LE_UINT32(data + 36);
+// _blueBits = READ_LE_UINT32(data + 40);
+// _greenBits = READ_LE_UINT32(data + 44);
+// _redBits = READ_LE_UINT32(data + 48);
+// _blueShift = READ_LE_UINT32(data + 52);
+// _greenShift = READ_LE_UINT32(data + 56);
+// _redShift = READ_LE_UINT32(data + 60);
+ b->_width = READ_LE_UINT32(data + 128);
+ b->_height = READ_LE_UINT32(data + 132);
+
+ b->_data = new char *[b->_numImages];
+ int pos = 0x88;
+ for (int i = 0; i < b->_numImages; i++) {
+ b->_data[i] = new char[b->_bpp / 8 * b->_width * b->_height];
+ if (codec == 0) {
+ memcpy(b->_data[i], data + pos, b->_bpp / 8 * b->_width * b->_height);
+ pos += b->_bpp / 8 * b->_width * b->_height + 8;
+ } else if (codec == 3) {
+ int compressed_len = READ_LE_UINT32(data + pos);
+ bool success = decompress_codec3(data + pos + 4, b->_data[i], b->_bpp / 8 * b->_width * b->_height);
+ if (!success)
+ printf(".. when loading image\n");
+ char *temp = new char[b->_bpp / 8 * b->_width * b->_height];
+ memcpy(temp, b->_data[i], b->_bpp / 8 * b->_width * b->_height);
+ delete[] b->_data[i];
+ b->_data[i] = temp;
+ pos += compressed_len + 12;
+ } else {
+ printf("Unknown image codec in BitmapData ctor!\n");
+ return NULL;
+ }
+
+#ifdef SCUMM_BIG_ENDIAN
+ for (int j = 0; j < b->_width * b->_height; ++j) {
+ ((uint16 *)b->_data[i])[j] = SWAP_BYTES_16(((uint16 *)b->_data[i])[j]);
+ }
+#endif
+ }
+
+ for (int img = 0; img < b->_numImages; img++) {
+ char *texData = new char[4 * b->_width * b->_height];
+ // Convert data to 32-bit RGBA format
+ char *texDataPtr = texData;
+ uint16 *bitmapData = reinterpret_cast<uint16 *>(b->_data[img]);
+ for (int i = 0; i < b->_width * b->_height; i++, texDataPtr += 4, bitmapData++) {
+ uint16 pixel = *bitmapData;
+ int r = pixel >> 11;
+ int g = (pixel >> 5) & 0x3f;
+ int bb = pixel & 0x1f;
+ texDataPtr[2] = (r << 3) | (r >> 2);
+ texDataPtr[1] = (g << 2) | (g >> 4);
+ texDataPtr[0] = (bb << 3) | (bb >> 2);
+ }
+ delete[] b->_data[img];
+ b->_data[img] = texData;
+ b->_bpp = 32;
+ }
+
+ return b;
+}
+
+void usage() {
+ std::cout << "Usage: bm2bmp [labfilename] <filename>" << std::endl;
+}
+
+int main(int argc, char **argv) {
+ if (argc < 2) {
+ std::cout << "No Argument" << std::endl;
+ usage();
+ return 0;
+ }
+ if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
+ usage();
+ return 0;
+ }
+
+ Lab *lab = NULL;
+ std::string filename;
+ int length = 0;
+
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab, length);
+
+ if (!file) {
+ std::cout << "Could not open file" << std::endl;
+ return 1;
+ }
+
+ int p = filename.rfind('/');
+ std::string outname = filename.substr(p + 1);
+
+ char *data = new char[length];
+ file->read(data, length);
+ delete file;
+ Bitmap *b = Bitmap::load(data, length);
+ if (b) {
+ b->toBMP(filename.substr(p + 1));
+ delete b;
+ } else {
+ printf("Could not load file %s.\n", filename.c_str());
+ return 1;
+ }
+
+ delete[] data;
+ return 0;
+}
diff --git a/tools/module.mk b/tools/module.mk
index 6ed7f6382..906848818 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -23,7 +23,8 @@ MAKE := \
luac \
patchex \
diffr \
- patchr
+ patchr \
+ bm2bmp
# these below are not added because they depend on the ppm and bpm libraries
# mat2ppm
@@ -116,4 +117,8 @@ TOOL := patchex
TOOL_OBJS := patchex/patchex.o patchex/mszipd.o patchex/cabd.o
include $(srcdir)/rules.mk
+TOOL := bm2bmp
+TOOL_OBJS := bm2bmp.o lab.o
+include $(srcdir)/rules.mk
+
.PHONY: clean-tools tools
Commit: 7e597d5c6c1710904fdbbdd89a0422ca2513fbce
https://github.com/scummvm/scummvm-tools/commit/7e597d5c6c1710904fdbbdd89a0422ca2513fbce
Author: PaweÅ KoÅodziejski (aquadran at xtr.net.pl)
Date: 2013-01-13T15:14:29+01:00
Commit Message:
TOOLS: LGPL -> GPL headers
Changed paths:
AUTHORS
COPYING.LGPL
COPYRIGHT
common/getopt.h
configure
tools/bm2bmp.cpp
tools/bmtoppm.cpp
tools/delua.cpp
tools/diffr.cpp
tools/emi/cosb2cos.cpp
tools/emi/filetools.h
tools/emi/meshb2obj.cpp
tools/emi/model.h
tools/emi/renderModel.cpp
tools/emi/setb2set.cpp
tools/emi/sklb2txt.cpp
tools/emi/til2bmp.cpp
tools/imc2wav.cpp
tools/int2flt.cpp
tools/lab.cpp
tools/lab.h
tools/labcopy.cpp
tools/mat2ppm.cpp
tools/mklab.cpp
tools/patchex/cab.h
tools/patchex/cabd.cpp
tools/patchex/mspack.h
tools/patchex/mszip.h
tools/patchex/mszipd.cpp
tools/patchex/patchex.cpp
tools/patchr.cpp
tools/set2fig.cpp
tools/unlab.cpp
tools/vima.cpp
diff --git a/AUTHORS b/AUTHORS
index 95ae8a64b..db14b69be 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,14 +1,17 @@
ResidualVM
**********
- Project Leader
- --------------
+ Project Leaders
+ ---------------
Pawel Kolodziejski
+ Einar Johan T. Somaen
Teams
-----
Grim Team:
James Brown - Core developer (retired)
Giulio Camuffo - Core developer
+ Dries Harnie - EMI support, various code fixes and
+ improvements
Pawel Kolodziejski - Core developer (suspended)
Einar Johan T. Somaen - EMI support, various code fixes and
improvements
@@ -27,11 +30,13 @@ ResidualVM
Thomas Allen - Various engine code fixes and improvements
Torbjorn Andersson - Various code fixes
Ori Avtalion - Lipsync, LAF support, various code fixes
- Robert Biro - Fixes to antiliasing
+ Robert Biro - Antialiasing support
Bastien Bouclet - Various fixes to engine
Marcus Comstedt - Initial Dreamcast port
Andrea Corna - Patcher module, various engine improvements
Jonathan Gray - Various code fixes
+ Tobias Gunkel - Initial Android port, few engines fixes
+ Azamat H. Hackimov - Configure fix
Vincent Hamm - Various engine code fixes and improvements
Sven Hesse - Various compilation fixes
Matthew Hoops - Some engine improvements, some work on EMI
@@ -43,7 +48,7 @@ ResidualVM
Guillem Jover - Few code improvements
Filippos Karapetis - Compilation fixes
Joost Peters - Various code fixes
- George Macon - Compilation fixes
+ George Macon - Few fixes
Josh Matthews - Few fixes to engine
Matthieu Milan - Various engine improvements
Christian Neumair - Various optimisation patches
@@ -53,7 +58,7 @@ ResidualVM
Julien Templier - create_project tool
Pino Toscano - Debian GNU/Linux package files
Lionel Ulmer - OpenGL optimisations
- Joni Vahamaki - A lot engine improvements and fixes
+ Joni Vahamaki - A lot of engine improvements and fixes
JenniBee - Compilation fixes
Myst 3:
@@ -61,7 +66,7 @@ ResidualVM
ScummVM code
************
- ResidualVM use a lot of ScummVM code. For a list of authors look into
+ ResidualVM uses a lot of ScummVM code. For a list of authors look into
COPYRIGHT file.
Website code
diff --git a/COPYING.LGPL b/COPYING.LGPL
index b485d85f0..d0ff92e99 100644
--- a/COPYING.LGPL
+++ b/COPYING.LGPL
@@ -506,5 +506,3 @@ necessary. Here is a sample; alter the names:
Ty Coon, President of Vice
That's all there is to it!
-
-
diff --git a/COPYRIGHT b/COPYRIGHT
index 7b6997518..0b33308b6 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1,5 +1,8 @@
ResidualVM
-Copyright (C) 2003-2012 by the following:
+Copyright (C) 2003-2013 by the following:
+
+Some of the code in this project was originally LGPL v2.1 (or later)
+but is used as GPL v2 (or later) starting from 19 Dec 2012.
If you have contributed to this project then you deserve to be on this
list. Contact us (see: AUTHORS) and we'll add you.
@@ -14,7 +17,10 @@ Giulio Camuffo
Marcus Comstedt
Andrea Corna
Jonathan Gray
+Tobias Gunkel
+Azamat H. Hackimov
Vincent Hamm
+Dries Harnie
Sven Hesse
Matthew Hoops
Erich Hoover
@@ -39,9 +45,8 @@ Lionel Ulmer
Joni Vahamaki
JenniBee
-
ScummVM
-Copyright (C) 2001-2012 by the following:
+Copyright (C) 2001-2013 by the following:
If you have contributed to this project then you deserve to be on this
list. Contact us (see: AUTHORS) and we'll add you.
diff --git a/common/getopt.h b/common/getopt.h
index 80ce326da..f442c7c2a 100644
--- a/common/getopt.h
+++ b/common/getopt.h
@@ -1,19 +1,24 @@
/* ResidualVM - A 3D game interpreter
-*
-* ResidualVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
#ifndef GETOPT_H
#define GETOPT_H
diff --git a/configure b/configure
index c85484919..2918daf18 100755
--- a/configure
+++ b/configure
@@ -1,8 +1,8 @@
#!/bin/sh
#
-# configure -- custom configure script for ScummVM.
+# configure -- custom configure script for ResidualVM.
#
-# ScummVM is the legal property of its developers, whose names
+# ResidualVM is the legal property of its developers, whose names
# are too numerous to list here. Please refer to the COPYRIGHT
# file distributed with this source distribution.
#
diff --git a/tools/bm2bmp.cpp b/tools/bm2bmp.cpp
index 2be560fe5..948140c16 100644
--- a/tools/bm2bmp.cpp
+++ b/tools/bm2bmp.cpp
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
/**
* A tool that converts Grim's bm images to bmp bitmaps.
diff --git a/tools/bmtoppm.cpp b/tools/bmtoppm.cpp
index 45025fe3a..d23d21a05 100644
--- a/tools/bmtoppm.cpp
+++ b/tools/bmtoppm.cpp
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <stdio.h>
#include <stdlib.h>
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 163479ae8..e8e151a8a 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -1,22 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
- * 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 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/diffr.cpp b/tools/diffr.cpp
index 6b68d6c97..5b9711959 100644
--- a/tools/diffr.cpp
+++ b/tools/diffr.cpp
@@ -1,19 +1,24 @@
/* ResidualVM - A 3D game interpreter
-*
-* ResidualVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
//Large parts of this program have been taken from bsdiff written by Colin Percival:
/*-
diff --git a/tools/emi/cosb2cos.cpp b/tools/emi/cosb2cos.cpp
index ad5bdf130..dd20adc05 100644
--- a/tools/emi/cosb2cos.cpp
+++ b/tools/emi/cosb2cos.cpp
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 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.
+ * 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 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
-*
-*/
+ * 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 <fstream>
#include <string>
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index 89576e7e7..8486b9b3a 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
#ifndef FILETOOLS_H
#define FILETOOLS_H
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index d8abad9f9..ce5506523 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 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.
+ * 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 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
-*
-*/
+ * 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 <fstream>
#include <string>
diff --git a/tools/emi/model.h b/tools/emi/model.h
index 82502f104..f436c603a 100644
--- a/tools/emi/model.h
+++ b/tools/emi/model.h
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
#ifndef MODEL_H
#define MODEL_H
diff --git a/tools/emi/renderModel.cpp b/tools/emi/renderModel.cpp
index 7fa13fef3..d3ab1384d 100644
--- a/tools/emi/renderModel.cpp
+++ b/tools/emi/renderModel.cpp
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <iostream>
#include <string>
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index 8f49fc3c7..c5ef5572d 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -1,8 +1,24 @@
-/*
-* TODO: Put GPL-license here
-* Thanks to klusark, for his work.
-* This version written by Einar Johan T. SÃmÃen
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <cassert>
#include <cstdio>
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
index c114f0113..4b75a6a9a 100644
--- a/tools/emi/sklb2txt.cpp
+++ b/tools/emi/sklb2txt.cpp
@@ -1,9 +1,32 @@
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+// Based on Benjamin Haischs work on sklb-files.
+
#include <fstream>
#include <string>
#include <iostream>
#include "filetools.h"
#include "tools/lab.h"
-// Based on Benjamin Haischs work on sklb-files.
using namespace std;
diff --git a/tools/emi/til2bmp.cpp b/tools/emi/til2bmp.cpp
index 4e270ecb9..a1e99f819 100644
--- a/tools/emi/til2bmp.cpp
+++ b/tools/emi/til2bmp.cpp
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <fstream>
#include <iostream>
diff --git a/tools/imc2wav.cpp b/tools/imc2wav.cpp
index f3e6348d1..34505377f 100644
--- a/tools/imc2wav.cpp
+++ b/tools/imc2wav.cpp
@@ -1,22 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
- * 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 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/int2flt.cpp b/tools/int2flt.cpp
index 220ba85b1..e196bc0ca 100644
--- a/tools/int2flt.cpp
+++ b/tools/int2flt.cpp
@@ -1,22 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
- * 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 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/lab.cpp b/tools/lab.cpp
index 4af7f4651..147df3122 100644
--- a/tools/lab.cpp
+++ b/tools/lab.cpp
@@ -1,17 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
-
- * This library is distributed in the hope that it will be useful,
+ *
+ * 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
- * 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
+ * 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.
*
*/
diff --git a/tools/lab.h b/tools/lab.h
index 4bbc4cc98..d99f94a19 100644
--- a/tools/lab.h
+++ b/tools/lab.h
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 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.
+ * 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 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
-*
-*/
+ * 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.
+ *
+ */
#ifndef LAB_H
#define LAB_H
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
index 03da5a7aa..edce77c39 100644
--- a/tools/labcopy.cpp
+++ b/tools/labcopy.cpp
@@ -1,27 +1,30 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-* $URL:
-* $Id:
-*
-*/
-/*labcopy.cpp
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+/*
quick & dirty LAB file copier based on residual code.
Adapted from code posted on residual forum by Joost Peters
- http://residual.scummvm.org/viewtopic.php?t=91
+ http://forums.residualvm.org/viewtopic.php?t=91
*/
diff --git a/tools/mat2ppm.cpp b/tools/mat2ppm.cpp
index 037b8fea2..291633085 100644
--- a/tools/mat2ppm.cpp
+++ b/tools/mat2ppm.cpp
@@ -1,24 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-*
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <stdio.h>
#include <stdlib.h>
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index b53cd8642..61cc76ee4 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -1,22 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
- * 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,
+ * 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
- * 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
+ * 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.
*
*/
diff --git a/tools/patchex/cab.h b/tools/patchex/cab.h
index 7924a8d98..4f4810a98 100644
--- a/tools/patchex/cab.h
+++ b/tools/patchex/cab.h
@@ -1,17 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
+ *
+ * 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/patchex/cabd.cpp b/tools/patchex/cabd.cpp
index 7fe8d2c16..a24f1bc1f 100644
--- a/tools/patchex/cabd.cpp
+++ b/tools/patchex/cabd.cpp
@@ -1,17 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
+ *
+ * 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/patchex/mspack.h b/tools/patchex/mspack.h
index 21d35a865..916d03fa4 100644
--- a/tools/patchex/mspack.h
+++ b/tools/patchex/mspack.h
@@ -1,17 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
+ *
+ * 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/patchex/mszip.h b/tools/patchex/mszip.h
index a78536199..bcd941f04 100644
--- a/tools/patchex/mszip.h
+++ b/tools/patchex/mszip.h
@@ -1,17 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
+ *
+ * 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/patchex/mszipd.cpp b/tools/patchex/mszipd.cpp
index 307605e09..e6ff38c92 100644
--- a/tools/patchex/mszipd.cpp
+++ b/tools/patchex/mszipd.cpp
@@ -1,17 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
+ *
+ * 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index 1dbb72dbb..5064fdd20 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -1,17 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
+ *
+ * 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/patchr.cpp b/tools/patchr.cpp
index 83dcad665..072461d93 100644
--- a/tools/patchr.cpp
+++ b/tools/patchr.cpp
@@ -1,19 +1,24 @@
/* ResidualVM - A 3D game interpreter
-*
-* ResidualVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
//Large parts of this program have been taken from bsdiff written by Colin Percival:
/*-
diff --git a/tools/set2fig.cpp b/tools/set2fig.cpp
index 29cfd46bc..163e01e85 100644
--- a/tools/set2fig.cpp
+++ b/tools/set2fig.cpp
@@ -1,24 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-*
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
// Utility to dump drawing of the sectors in a set file to an xfig file
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 6ef5d8903..9e653f892 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -1,22 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
- * 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 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
diff --git a/tools/vima.cpp b/tools/vima.cpp
index eedba5ddc..1120c6943 100644
--- a/tools/vima.cpp
+++ b/tools/vima.cpp
@@ -1,22 +1,22 @@
-/* Residual - A 3D game interpreter
+/* ResidualVM - A 3D game interpreter
*
- * Residual is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the AUTHORS
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
- * 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 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 library is distributed in the hope that it will be useful,
+ * 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
- * Lesser General Public License for more details.
+ * 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 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
+ * 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.
*
*/
Commit: a49967ddf9a30303f3ccd36ba5f80bd8b5bb4390
https://github.com/scummvm/scummvm-tools/commit/a49967ddf9a30303f3ccd36ba5f80bd8b5bb4390
Author: Dries Harnie (dries at harnie.be)
Date: 2013-05-05T15:49:42+02:00
Commit Message:
EMI: Read time correctly in .animb files
Changed paths:
tools/emi/animb2txt.cpp
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 2184a20e3..55d3f0636 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -65,15 +65,15 @@ int main(int argc, char **argv) {
if (operation == 3) { // Translation
for(int j = 0; j < numKeyframes; j++) {
- time = readFloat(*file);
vec3d = readVector3d(*file);
+ time = readFloat(*file);
std::cout << "Time : " << time << " Vector: " << vec3d->toString() << std::endl;
delete vec3d;
}
} else if (operation == 4) { // Rotation
for(int j = 0; j < numKeyframes; j++) {
- time = readFloat(*file);
vec4d = readVector4d(*file);
+ time = readFloat(*file);
std::cout << "Time : " << time << " Vector: " << vec4d->toString() << std::endl;
delete vec4d;
}
Commit: 6cdcec7f421e3bcc369ba20cc10c69fb25f3c4e5
https://github.com/scummvm/scummvm-tools/commit/6cdcec7f421e3bcc369ba20cc10c69fb25f3c4e5
Author: Dries Harnie (dries at harnie.be)
Date: 2013-05-05T15:49:42+02:00
Commit Message:
EMI: Display a single chore in a .cosb
Changed paths:
tools/emi/cosb2cos.cpp
diff --git a/tools/emi/cosb2cos.cpp b/tools/emi/cosb2cos.cpp
index dd20adc05..66ef36309 100644
--- a/tools/emi/cosb2cos.cpp
+++ b/tools/emi/cosb2cos.cpp
@@ -23,6 +23,7 @@
#include <fstream>
#include <string>
#include <iostream>
+#include <iomanip>
#include <vector>
#include "filetools.h"
@@ -160,6 +161,36 @@ struct Costume {
std::cout << "\tnumkeys: x\n";
// TODO
}
+
+ void printChore(const char *choreName) {
+ for (int i = 0; i < _numChores; i++) {
+ if (_chores[i]._choreName == choreName) {
+ std::cout << "Chore " << choreName << " (" << _chores[i]._numTracks << " tracks) ";
+ if (_chores[i]._length == 1000)
+ std::cout << "(instant)";
+ else
+ std::cout << 1000.0 * _chores[i]._length << " ms";
+
+ std::cout << std::endl;
+ for (int t = 0; t < _chores[i]._numTracks; t++) {
+ ChoreTrack &track = _chores[i]._tracks[t];
+ std::string &tag = track._tag;
+ std::string &data = track._trackName;
+ std::cout << "Track " << t << ": tag " << tag << ", data [" << data << "]" << std::endl;
+
+ for (int k = 0; k < track._numKeys; k++) {
+ TrackKey &tk = track._keys[k];
+ std::cout << "\t";
+ std::cout << std::right << std::setw(5);
+ std::cout << (1000.0 * tk._time) << " ms";
+ std::cout << "\t" << tk._value << std::endl;
+ }
+ }
+ return;
+ }
+ }
+ std::cout << "Error: chore " << choreName << " not found!" << std::endl;
+ }
};
int main(int argc, char **argv) {
@@ -178,6 +209,10 @@ int main(int argc, char **argv) {
Costume c;
c.readFromFile(file);
- c.print();
+ if (argc == 2) {
+ c.print();
+ } else {
+ c.printChore(argv[2]);
+ }
}
Commit: 56f36d1ef56e40da909db2579393fc8ea1f51d9b
https://github.com/scummvm/scummvm-tools/commit/56f36d1ef56e40da909db2579393fc8ea1f51d9b
Author: Dries Harnie (dries at harnie.be)
Date: 2013-05-05T15:51:48+02:00
Commit Message:
EMI: Show normals in setb2set
Changed paths:
tools/emi/setb2set.cpp
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index c5ef5572d..445488988 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -21,6 +21,7 @@
*/
#include <cassert>
+#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
@@ -133,6 +134,7 @@ private:
float height;
int numVertices; // byte;
float* vertices; // 3 * numVertices.
+ float normal[3];
bool visible;
};
@@ -155,6 +157,29 @@ Sector::Sector(Data *data) : Section(data)
int skip = data->GetInt();
data->Skip(skip*4);
height = data->GetFloat();
+
+ float cross1[3], cross2[3];
+ cross1[0] = vertices[3] - vertices[0];
+ cross1[1] = vertices[4] - vertices[1];
+ cross1[2] = vertices[5] - vertices[2];
+
+ int x = 3 * (numVertices - 1);
+ cross2[0] = vertices[x+0] - vertices[0];
+ cross2[1] = vertices[x+1] - vertices[1];
+ cross2[2] = vertices[x+2] - vertices[2];
+
+ float &nx = normal[0];
+ float &ny = normal[1];
+ float &nz = normal[2];
+ nx = cross1[1] * cross2[2] - cross2[1] * cross1[2];
+ ny = cross1[0] * cross2[2] - cross2[0] * cross1[2];
+ nz = cross1[0] * cross2[1] - cross2[0] * cross1[1];
+
+ float norm = nx * nx + ny * ny + nz * nz;
+ norm = ::sqrt(norm);
+ nx /= norm;
+ ny /= norm;
+ nz /= norm;
}
string Sector::ToString()
@@ -191,6 +216,7 @@ string Sector::ToString()
ss << endl;
ss << "\theight\t" << height << endl;
ss << "\tnumvertices\t" << numVertices << endl;
+ ss << "\tnormal\t\t\t" << normal[0] << "\t" << normal[1] << "\t" << normal[2] << endl;
ss << "\tvertices:\t\t";
for (int i = 0; i < numVertices*3; i+=3) {
if (i != 0)
Commit: 1780f35cb1325f05121e4b3ccd9d2af905cc3b07
https://github.com/scummvm/scummvm-tools/commit/1780f35cb1325f05121e4b3ccd9d2af905cc3b07
Author: Dries Harnie (dries at harnie.be)
Date: 2013-05-05T15:57:37+02:00
Commit Message:
ALL: Update .gitignore
Changed paths:
.gitignore
diff --git a/.gitignore b/.gitignore
index 1f5dd0003..247f451a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,14 +7,19 @@
*.exe
animb2txt
+bm2bmp
bmtoppm
cosb2cos
delua
+diffr
imc2wav
int2flt
labcopy
+luac
meshb2obj
mklab
+patchex
+patchr
set2fig
setb2set
sklb2txt
Commit: 7136479e0797e5ece9913a02e57cc3144d564e18
https://github.com/scummvm/scummvm-tools/commit/7136479e0797e5ece9913a02e57cc3144d564e18
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2013-07-09T19:16:20+02:00
Commit Message:
TOOLS: Add a small stream workalike to tools.
Changed paths:
tools/emi/filetools.h
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index 8486b9b3a..59cb570c8 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -144,5 +144,52 @@ Vector4d *readVector4d(std::istream& file) {
vec4d->w = readFloat(file);
return vec4d;
}
+//TODO: Endianness
+class SeekableReadStream {
+public:
+ virtual uint32 readUint32() = 0;
+ virtual void read(void *target, uint32 length) = 0;
+ virtual void seek(int offset, int whence = SEEK_SET) = 0;
+};
+
+class MemoryReadStream : public SeekableReadStream {
+ byte *_data;
+ uint32 _pos;
+ uint32 _length;
+public:
+ MemoryReadStream(byte *data, uint32 length) : _data(data), _length(length), _pos(0) {}
+ ~MemoryReadStream() {
+ delete[] _data;
+ }
+
+ uint32 readUint32() {
+ if (_pos + 4 > _length) {
+ std::cout << "ERROR: Crossed end of stream" << std::endl;
+ return 0;
+ }
+ uint32 result = 0;
+ uint32 *temp = (uint32 *)(_data + _pos);
+ result = *temp;
+ _pos += 4;
+ return result;
+ }
+ void read(void *target, uint32 length) {
+ memcpy(target, _data + _pos, length);
+ _pos += length;
+ }
+ void seek(int offset, int whence = SEEK_SET) {
+ switch (whence) {
+ case SEEK_SET:
+ _pos = offset;
+ break;
+ case SEEK_CUR:
+ _pos += offset;
+ break;
+ case SEEK_END:
+ std::cout << "ERROR: SEEK_END not implemented yet" << std::endl;
+ break;
+ }
+ }
+};
#endif
Commit: 768180347732da1fa4ae519752f0ce6f6ab26a59
https://github.com/scummvm/scummvm-tools/commit/768180347732da1fa4ae519752f0ce6f6ab26a59
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2013-07-09T19:16:38+02:00
Commit Message:
TOOLS: Reformat filetools.h
Changed paths:
tools/emi/filetools.h
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index 59cb570c8..113db1ff2 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -73,34 +73,34 @@ struct Vector4d {
}
};
-float readFloat(std::istream& file) {
+float readFloat(std::istream &file) {
float retVal = 0.0f;
- file.read((char*)&retVal, 4);
+ file.read((char *)&retVal, 4);
retVal = get_float((char *) &retVal);
return retVal;
}
-int readInt(std::istream& file) {
+int readInt(std::istream &file) {
int retVal = 0;
- file.read((char*)&retVal, 4);
+ file.read((char *)&retVal, 4);
return FROM_LE_32(retVal);
}
-short readShort(std::istream& file) {
+short readShort(std::istream &file) {
short retVal = 0;
- file.read((char*)&retVal, 2);
+ file.read((char *)&retVal, 2);
return FROM_LE_16(retVal);
}
-int readByte(std::istream& file) {
+int readByte(std::istream &file) {
char retVal = 0;
- file.read((char*)&retVal, 1);
+ file.read((char *)&retVal, 1);
return retVal;
}
-std::string readString(std::istream& file) {
+std::string readString(std::istream &file) {
int strLength = readInt(file);
- char* readString = new char[strLength];
+ char *readString = new char[strLength];
file.read(readString, strLength);
std::string retVal(readString);
@@ -117,7 +117,7 @@ std::string readCString(std::istream &file, int len) {
return retVal;
}
-Vector2d *readVector2d(std::istream& file, int count = 1) {
+Vector2d *readVector2d(std::istream &file, int count = 1) {
Vector2d *vec2d = new Vector2d[count];
for (int i = 0; i < count; i++) {
vec2d[i].x = readFloat(file);
@@ -126,7 +126,7 @@ Vector2d *readVector2d(std::istream& file, int count = 1) {
return vec2d;
}
-Vector3d *readVector3d(std::istream& file, int count = 1) {
+Vector3d *readVector3d(std::istream &file, int count = 1) {
Vector3d *vec3d = new Vector3d[count];
for (int i = 0; i < count; i++) {
vec3d[i].x = readFloat(file);
@@ -136,7 +136,7 @@ Vector3d *readVector3d(std::istream& file, int count = 1) {
return vec3d;
}
-Vector4d *readVector4d(std::istream& file) {
+Vector4d *readVector4d(std::istream &file) {
Vector4d *vec4d = new Vector4d();
vec4d->x = readFloat(file);
vec4d->y = readFloat(file);
Commit: 8199181ffb528e41182631c9a78fd1a60acaefb7
https://github.com/scummvm/scummvm-tools/commit/8199181ffb528e41182631c9a78fd1a60acaefb7
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2013-07-09T19:17:42+02:00
Commit Message:
EMI: Add a tool for rendering TIL-files. (With selective layer-support)
Changed paths:
A tools/emi/renderTil.cpp
diff --git a/tools/emi/renderTil.cpp b/tools/emi/renderTil.cpp
new file mode 100644
index 000000000..8b46bd78a
--- /dev/null
+++ b/tools/emi/renderTil.cpp
@@ -0,0 +1,448 @@
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <fstream>
+#include <iostream>
+#include <string>
+#include <zlib.h>
+#include <cassert>
+#include <sys/types.h>
+#include <sstream>
+#include <stdint.h>
+#include <cstdio>
+#include <cstring>
+#include "common/endian.h"
+#include "tools/lab.h"
+#include "tools/emi/filetools.h"
+#include <GLFW/glfw3.h>
+
+/*
+This tool renders EMI-TILEs, optionally allowing the user to enable/disable layers in the TIL.
+
+I'm rather sure this only works on LE-systems for now, and it REQUIRES GLFW 3 and zlib to work.
+
+Usage:
+renderTil [labName] <filename>
+
+To enable or disable layers, simply press the matching key.
+
+somaen.
+*/
+
+// Credits: The TILE-loading and texture-generation/drawing code was lifted directly from ResidualVM
+// The rendering setup was lifted directly from the GLFW-intro tutorial.
+
+#define BITMAP_TEXTURE_SIZE 256
+
+/**
+ * The Color-formats used for bitmaps in Grim Fandango/Escape From Monkey Island
+ */
+enum colorFormat {
+ BM_RGB565 = 1, // Grim Fandango
+ BM_RGB1555 = 2, // EMI-PS2
+ BM_RGBA = 3, // EMI-PC (Also internal Material-format for Grim)
+ BM_BGR888 = 4, // EMI-TGA-materials (888)
+ BM_BGRA = 5 // EMI-TGA-materials with alpha
+};
+
+class Tile {
+ float *_texc;
+ struct Vert {
+ uint32 _texid;
+ uint32 _pos;
+ uint32 _verts;
+ };
+ struct Layer {
+ uint32 _offset;
+ uint32 _numImages;
+ };
+ Vert *_verts;
+ Layer *_layers;
+ uint32 _numCoords;
+ uint32 _numVerts;
+ uint32 _numLayers;
+ int _numSubImages;
+ char **_data;
+ int _width, _height;
+ int _bpp;
+ int _colorFormat;
+ // Rendering:
+ int _numTex;
+ void *_texIds;
+ bool *_enabledLayers;
+public:
+ Tile() : _data(NULL), _layers(NULL), _verts(NULL), _numSubImages(0), _numVerts(0), _numLayers(0), _numCoords(0), _width(0), _height(0), _texc(0), _bpp(0), _colorFormat(0), _numTex(0), _texIds(NULL), _enabledLayers(NULL) {}
+ ~Tile() {
+ for (int i = 0; i < _numSubImages; i++) {
+ delete _data[i];
+ }
+ delete[] _enabledLayers;
+ delete[] _data;
+ delete[] _verts;
+ delete[] _layers;
+ }
+ bool loadTile(SeekableReadStream *stream);
+ void createBitmap();
+ void drawBitmap(int dx, int dy, uint32 layer);
+ void drawAllLayers() {
+ for (int layer = _numLayers - 1; layer >= 0; layer--) {
+ if (_enabledLayers[layer]) {
+ drawBitmap(0, 0, layer);
+ }
+ }
+ }
+ void toggleLayer(int layer) {
+ if (layer < _numLayers) {
+ _enabledLayers[layer] = !_enabledLayers[layer];
+ std::cout << "Layer " << layer << (_enabledLayers[layer] ? " enabled" : " disabled") << std::endl;
+ }
+ }
+};
+
+bool Tile::loadTile(SeekableReadStream *stream) {
+ uint32 id = FROM_BE_32(stream->readUint32());
+ char *test = (char *)&id;
+ // Should check that we actually HAVE a TIL
+ uint32 bmoffset = stream->readUint32();
+ _numCoords = stream->readUint32();
+ _numLayers = stream->readUint32();
+ _numVerts = stream->readUint32();
+
+ // skip some 0
+ stream->seek(16, SEEK_CUR);
+ _texc = new float[_numCoords * 4];
+ std::cout << "Num Coords: " << _numCoords << std::endl;
+ for (uint32 i = 0; i < _numCoords * 4; ++i) {
+ char f[4];
+ stream->read(f, 4);
+ _texc[i] = get_float(f);
+ }
+
+ _layers = new Layer[_numLayers];
+ std::cout << "Num Layers: " << _numLayers << std::endl;
+ for (uint32 i = 0; i < _numLayers; ++i) {
+ _layers[i]._offset = stream->readUint32();
+ _layers[i]._numImages = stream->readUint32();
+ }
+
+ _verts = new Vert[_numVerts];
+ std::cout << "Num Vertices:" << _numVerts << std::endl;
+ for (uint32 i = 0; i < _numVerts; ++i) {
+ _verts[i]._texid = stream->readUint32();
+ _verts[i]._pos = stream->readUint32();
+ _verts[i]._verts = stream->readUint32();
+ }
+
+ stream->seek(16, SEEK_CUR);
+ _numSubImages = stream->readUint32();
+ std::cout << "Num Sub-images: " << _numSubImages << std::endl;
+ if (_numSubImages < 5) {
+ std::cout << "Can not handle a tile with less than 5 sub images, this has " << _numSubImages << std::endl;
+ exit(0);
+ }
+
+ _data = new char *[_numSubImages];
+
+ stream->seek(16, SEEK_CUR);
+ _bpp = stream->readUint32();
+
+ stream->seek(bmoffset + 128);
+
+ _width = stream->readUint32();
+ _height = stream->readUint32();
+ std::cout << "Width: " << _width << std::endl << "Height: " << _height << std::endl;
+ stream->seek(-8, SEEK_CUR);
+
+ int size = _bpp / 8 * _width * _height;
+ for (int i = 0; i < _numSubImages; ++i) {
+ _data[i] = new char[size];
+ stream->seek(8, SEEK_CUR);
+ stream->read(_data[i], size);
+ }
+ //Graphics::PixelFormat pixelFormat;
+ if (_bpp == 16) {
+ // _colorFormat = BM_RGB1555;
+ // pixelFormat = Graphics::createPixelFormat<1555>();
+ //convertToColorFormat(0, BM_RGBA);
+ } else {
+ // pixelFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
+ // _colorFormat = BM_RGBA;
+ }
+
+ _width = 256;
+ _height = 256;
+
+ _enabledLayers = new bool[_numLayers];
+ for (int i = 0; i < _numLayers; i++) {
+ _enabledLayers[i] = true;
+ }
+
+ return true;
+}
+
+void Tile::createBitmap() {
+// bitmap->_hasTransparency = false;
+ _numTex = ((_width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
+ ((_height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
+ _texIds = new GLuint[_numTex * _numSubImages];
+ GLuint *textures = (GLuint *)_texIds;
+ glGenTextures(_numTex * _numSubImages, textures);
+
+ byte *texData = 0;
+ byte *texOut = 0;
+
+ GLint format = GL_RGBA;
+ GLint type = GL_UNSIGNED_BYTE;
+ int bytes = 4;
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, bytes);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, _width);
+
+ for (int pic = 0; pic < _numSubImages; pic++) {
+ if (_bpp == 16 && _colorFormat != BM_RGB1555) {
+ if (texData == 0) {
+ texData = new byte[4 * _width * _height];
+ }
+ // Convert data to 32-bit RGBA format
+ byte *texDataPtr = texData;
+ uint16 *bitmapData = reinterpret_cast<uint16 *>(_data[pic]);
+ for (int i = 0; i < _width * _height; i++, texDataPtr += 4, bitmapData++) {
+ uint16 pixel = *bitmapData;
+ int r = pixel >> 11;
+ texDataPtr[0] = (r << 3) | (r >> 2);
+ int g = (pixel >> 5) & 0x3f;
+ texDataPtr[1] = (g << 2) | (g >> 4);
+ int b = pixel & 0x1f;
+ texDataPtr[2] = (b << 3) | (b >> 2);
+ if (pixel == 0xf81f) { // transparent
+ texDataPtr[3] = 0;
+ //bitmap->_hasTransparency = true;
+ } else {
+ texDataPtr[3] = 255;
+ }
+ }
+ texOut = texData;
+ } else if (_colorFormat == BM_RGB1555) {
+ std::cout << "TODO: BM_RGB1555 Support" << std::endl;
+// bitmap->convertToColorFormat(pic, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
+// texOut = (byte *)bitmap->getImageData(pic).getRawBuffer();
+ } else {
+ texOut = (byte *)_data[pic];
+ }
+
+ for (int i = 0; i < _numTex; i++) {
+ glBindTexture(GL_TEXTURE_2D, textures[_numTex * pic + i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexImage2D(GL_TEXTURE_2D, 0, format, BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0, format, type, NULL);
+ }
+
+ int cur_tex_idx = _numTex * pic;
+
+ for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) {
+ for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) {
+ int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE;
+ int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE;
+ glBindTexture(GL_TEXTURE_2D, textures[cur_tex_idx]);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type,
+ texOut + (y * bytes * _width) + (bytes * x));
+ cur_tex_idx++;
+ }
+ }
+ }
+
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+}
+
+void Tile::drawBitmap(int dx, int dy, uint32 layer) {
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(-1, 1, -1, 1, 0, 1);
+
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_LIGHTING);
+ glEnable(GL_TEXTURE_2D);
+ glColor3f(1, 1, 1);
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+
+ GLuint *textures = (GLuint *)_texIds;
+ float *texc = _texc;
+
+ uint32 offset = _layers[layer]._offset;
+ for (uint32 i = offset; i < offset + _layers[layer]._numImages; ++i) {
+ glBindTexture(GL_TEXTURE_2D, textures[_verts[i]._texid]);
+ glBegin(GL_QUADS);
+ uint32 ntex = _verts[i]._pos * 4;
+ for (uint32 x = 0; x < _verts[i]._verts; ++x) {
+ glTexCoord2f(texc[ntex + 2], texc[ntex + 3]);
+ glVertex2f(texc[ntex + 0], texc[ntex + 1]);
+ ntex += 4;
+ }
+ glEnd();
+ }
+
+ glDisable(GL_TEXTURE_2D);
+ glDepthMask(GL_TRUE);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ return;
+}
+
+void renderInit() {
+ glClearColor(0.2f, 0.2f, 0.2f, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+}
+
+// HACK, to enable and disable layers
+static int keyForLayer = -1;
+void renderLoop(GLFWwindow *window, Tile &t) {
+ float rot = 0.5f;
+ while (!glfwWindowShouldClose(window) && keyForLayer != -2) {
+ renderInit();
+
+ t.drawAllLayers();
+ if (keyForLayer != -1) {
+ t.toggleLayer(keyForLayer);
+ keyForLayer = -1;
+ }
+ glFlush();
+ glfwSwapBuffers(window);
+ glfwPollEvents();
+ usleep(5000);
+ }
+ glfwTerminate();
+}
+
+void keycallback(GLFWwindow *window, int key, int scancode, int action, int mods) {
+ if (action == GLFW_PRESS) {
+ if (key >= GLFW_KEY_0 && key <= GLFW_KEY_9) {
+ keyForLayer = key - GLFW_KEY_0;
+ } else if (key == GLFW_KEY_ESCAPE) {
+ keyForLayer = -2;
+ }
+ }
+}
+
+Bytef *decompress(Bytef *in, int size, uint32_t &outsize) {
+ const uint32_t block = 8 * 1024 * 1024;
+ Bytef *dest = new Bytef[block]; // 8 MiB ought to be enough.
+
+ int success = 0;
+ z_stream_s zStream;
+
+ zStream.next_in = Z_NULL;
+ zStream.avail_in = 0;
+ zStream.zalloc = Z_NULL;
+ zStream.zfree = Z_NULL;
+ zStream.opaque = Z_NULL;
+
+ success = inflateInit2(&zStream, 16 + MAX_WBITS);
+ if (success != Z_OK) {
+ std::cout << "ZLIB failed to initialize\n";
+ return 0;
+ }
+ zStream.avail_in = size;
+ zStream.next_in = in;
+ zStream.avail_out = block;
+ zStream.next_out = dest;
+
+ success = inflate(&zStream, Z_NO_FLUSH);
+
+ outsize = zStream.total_out;
+
+ if (success != Z_STREAM_END) {
+ std::cout << "ERROR: decompressed size bigger than 8 MiB\n";
+ return 0;
+ }
+ return dest;
+}
+
+
+int main(int argc, char **argv) {
+ if (argc < 2) {
+ std::cout << "No Argument" << std::endl;
+ std::cout << "Usage: renderTil [labfilename] <filename>" << std::endl;
+ return 0;
+ }
+
+ Lab *lab = NULL;
+ std::string filename;
+ int length = 0;
+
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab, length);
+
+ if (!file) {
+ std::cout << "ERROR: Could not open file" << std::endl;
+ return 0;
+ }
+
+ Bytef *compressedData = new Bytef[length];
+ file->read((char *)compressedData, length);
+ uint32_t outsize;
+ Bytef *data = decompress((Bytef *)compressedData, length, outsize);
+ delete[] compressedData;
+ if (!data) {
+ return -1;
+ }
+
+ MemoryReadStream *stream = new MemoryReadStream(data, outsize);
+
+ // Initialization and render-loop more or less copied directly from
+ // http://www.glfw.org/documentation.html
+ glfwInit();
+ GLFWwindow *window = glfwCreateWindow(640, 480, filename.c_str(), NULL, NULL);
+ glfwMakeContextCurrent(window);
+ glfwSetKeyCallback(window, keycallback);
+ Tile t;
+ if (t.loadTile(stream)) {
+ t.createBitmap();
+ std::cout << "Loading of " << filename << " succeeded" << std::endl;
+ std::cout << "Use keys 0 - 9 to enable or disable layers, close window to exit, or press ESC" << std::endl;
+ renderLoop(window, t);
+ } else {
+ std::cout << "Load error for " << filename << std::endl;
+ }
+ delete stream;
+ return 0;
+}
Commit: cd3d83844a7b99613fcf1ceb4e99912f4d2430f1
https://github.com/scummvm/scummvm-tools/commit/cd3d83844a7b99613fcf1ceb4e99912f4d2430f1
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2013-07-09T19:42:44+02:00
Commit Message:
JANITORIAL: Reformat most files, to be closer to code-style of ResidualVM
Changed paths:
tools/bm2bmp.cpp
tools/bmtoppm.cpp
tools/diffr.cpp
tools/emi/animb2txt.cpp
tools/emi/cosb2cos.cpp
tools/emi/meshb2obj.cpp
tools/emi/model.h
tools/emi/renderModel.cpp
tools/emi/setb2set.cpp
tools/emi/sklb2txt.cpp
tools/emi/til2bmp.cpp
tools/imc2wav.cpp
tools/int2flt.cpp
tools/lab.cpp
tools/lab.h
tools/labcopy.cpp
tools/mat2ppm.cpp
tools/mklab.cpp
tools/patchr.cpp
tools/set2fig.cpp
tools/unlab.cpp
tools/vima.cpp
diff --git a/tools/bm2bmp.cpp b/tools/bm2bmp.cpp
index 948140c16..1585d297b 100644
--- a/tools/bm2bmp.cpp
+++ b/tools/bm2bmp.cpp
@@ -89,17 +89,18 @@ void Bitmap::toBMP(const std::string &fname) {
std::fstream file(name.str().c_str(), std::fstream::out | std::fstream::binary);
BMPHeader header;
unsigned short bm = TO_LE_16(19778);
- file.write((char*)&bm, 2);
+ file.write((char *)&bm, 2);
header.size = TO_LE_32(size() + 54);
header.reserved = TO_LE_32(0);
header.width = TO_LE_32(_width);
header.height = TO_LE_32(_height);
header.offset = TO_LE_32(54);
header.headerSize = TO_LE_32(40);
- if(_bpp == 32)
+ if (_bpp == 32) {
header.nplanesbpp = TO_LE_32(2097153);
- else if(_bpp == 16)
+ } else if (_bpp == 16) {
header.nplanesbpp = TO_LE_32(1048577);
+ }
header.compress_type = TO_LE_32(0);
header.bmp_bytesz = TO_LE_32(0);
header.hres = TO_LE_32(2835);
@@ -116,21 +117,21 @@ void Bitmap::toBMP(const std::string &fname) {
}
#define GET_BIT do { bit = bitstr_value & 1; \
-bitstr_len--; \
-bitstr_value >>= 1; \
-if (bitstr_len == 0) { \
- bitstr_value = READ_LE_UINT16(compressed); \
- bitstr_len = 16; \
- compressed += 2; \
- } \
-} while (0)
+ bitstr_len--; \
+ bitstr_value >>= 1; \
+ if (bitstr_len == 0) { \
+ bitstr_value = READ_LE_UINT16(compressed); \
+ bitstr_len = 16; \
+ compressed += 2; \
+ } \
+ } while (0)
static bool decompress_codec3(const char *compressed, char *result, int maxBytes) {
int bitstr_value = READ_LE_UINT16(compressed);
int bitstr_len = 16;
compressed += 2;
bool bit;
-
+
int byteIndex = 0;
for (;;) {
GET_BIT;
@@ -138,12 +139,11 @@ static bool decompress_codec3(const char *compressed, char *result, int maxBytes
if (byteIndex >= maxBytes) {
printf("Buffer overflow when decoding image: decompress_codec3 walked past the input buffer!\n");
return false;
- }
- else
+ } else {
*result++ = *compressed++;
+ }
++byteIndex;
- }
- else {
+ } else {
GET_BIT;
int copy_len, copy_offset;
if (bit == 0) {
@@ -158,16 +158,16 @@ static bool decompress_codec3(const char *compressed, char *result, int maxBytes
compressed += 2;
if (copy_len == 3) {
copy_len = *(uint8 *)(compressed++) + 1;
- if (copy_len == 1)
+ if (copy_len == 1) {
return true;
+ }
}
}
while (copy_len > 0) {
if (byteIndex >= maxBytes) {
printf("Buffer overflow when decoding image: decompress_codec3 walked past the input buffer!\n");
return false;
- }
- else {
+ } else {
assert(byteIndex + copy_offset >= 0);
assert(byteIndex + copy_offset < maxBytes);
*result = result[copy_offset];
@@ -222,8 +222,9 @@ Bitmap *Bitmap::load(const char *data, int len) {
} else if (codec == 3) {
int compressed_len = READ_LE_UINT32(data + pos);
bool success = decompress_codec3(data + pos + 4, b->_data[i], b->_bpp / 8 * b->_width * b->_height);
- if (!success)
+ if (!success) {
printf(".. when loading image\n");
+ }
char *temp = new char[b->_bpp / 8 * b->_width * b->_height];
memcpy(temp, b->_data[i], b->_bpp / 8 * b->_width * b->_height);
delete[] b->_data[i];
@@ -233,7 +234,7 @@ Bitmap *Bitmap::load(const char *data, int len) {
printf("Unknown image codec in BitmapData ctor!\n");
return NULL;
}
-
+
#ifdef SCUMM_BIG_ENDIAN
for (int j = 0; j < b->_width * b->_height; ++j) {
((uint16 *)b->_data[i])[j] = SWAP_BYTES_16(((uint16 *)b->_data[i])[j]);
diff --git a/tools/bmtoppm.cpp b/tools/bmtoppm.cpp
index d23d21a05..f4011b5a3 100644
--- a/tools/bmtoppm.cpp
+++ b/tools/bmtoppm.cpp
@@ -47,8 +47,8 @@ void read_header(FILE *in, int *codec, int *num_images, int *format) {
read_LEint32(in);
*num_images = read_LEint32(in);
- read_LEint32(in); /* ignore x offset */
- read_LEint32(in); /* ignore y offset */
+ read_LEint32(in); /* ignore x offset */
+ read_LEint32(in); /* ignore y offset */
read_LEint32(in);
*format = read_LEint32(in);
fseek(in, 128, SEEK_SET);
@@ -84,9 +84,9 @@ void read_data_codec3(FILE *in, int size, unsigned char *result) {
})
for (;;) {
- if (GET_BIT == 1)
+ if (GET_BIT == 1) {
*result++ = *data_ptr++;
- else {
+ } else {
if (GET_BIT == 0) {
len = GET_BIT * 2;
len += GET_BIT;
@@ -122,14 +122,15 @@ void write_img(pixel **img, const char *fname, int img_num, int width, int heigh
FILE *out;
basename = strrchr(fname, '/');
- if (basename != NULL)
+ if (basename != NULL) {
basename++;
- else
+ } else {
basename = fname;
+ }
strcpy(newname, basename);
- if (strlen(newname) > 3 && strcasecmp(newname + strlen(newname) - 3, ".bm") == 0)
+ if (strlen(newname) > 3 && strcasecmp(newname + strlen(newname) - 3, ".bm") == 0) {
newname[strlen(newname) - 3] = '\0';
- else if (strlen(newname) > 4 && strcasecmp(newname + strlen(newname) - 4, ".zbm") == 0) {
+ } else if (strlen(newname) > 4 && strcasecmp(newname + strlen(newname) - 4, ".zbm") == 0) {
newname[strlen(newname) - 4] = '\0';
strcat(newname, "_z");
}
@@ -162,7 +163,7 @@ pixel **toimg_fmt1(const unsigned char *data, int width, int height) {
PPM_ASSIGN(result[y][x], r, g, b);
data += 2;
}
- return result;
+ return result;
}
pixel **toimg_fmt5(const unsigned char *data, int width, int height) {
@@ -178,7 +179,7 @@ pixel **toimg_fmt5(const unsigned char *data, int width, int height) {
PPM_ASSIGN(result[y][x], gray, gray, gray);
data += 2;
}
- return result;
+ return result;
}
void process_file(const char *fname) {
@@ -201,9 +202,9 @@ void process_file(const char *fname) {
height = read_LEint32(in);
data = malloc(width * height * 2);
- if (codec == 0)
+ if (codec == 0) {
read_data_codec0(in, width, height, data);
- else if (codec == 3) {
+ } else if (codec == 3) {
size = read_LEint32(in);
read_data_codec3(in, size, data);
} else {
@@ -233,7 +234,8 @@ int main(int argc, char **argv) {
int i;
ppm_init(&argc, argv);
- for (i = 1; i < argc; i++)
+ for (i = 1; i < argc; i++) {
process_file(argv[i]);
+ }
return 0;
}
diff --git a/tools/diffr.cpp b/tools/diffr.cpp
index 5b9711959..2561e03ec 100644
--- a/tools/diffr.cpp
+++ b/tools/diffr.cpp
@@ -75,18 +75,26 @@ static void split(int32 *I, int32 *V, int32 start, int32 len, int32 h) {
j++;
};
};
- for (i = 0; i < j; i++) V[I[k + i]] = k + j - 1;
- if (j == 1) I[k] = -1;
+ for (i = 0; i < j; i++) {
+ V[I[k + i]] = k + j - 1;
+ }
+ if (j == 1) {
+ I[k] = -1;
+ }
};
return;
};
- x = V[I[start + len/2] + h];
+ x = V[I[start + len / 2] + h];
jj = 0;
kk = 0;
for (i = start; i < start + len; i++) {
- if (V[I[i] + h] < x) jj++;
- if (V[I[i] + h] == x) kk++;
+ if (V[I[i] + h] < x) {
+ jj++;
+ }
+ if (V[I[i] + h] == x) {
+ kk++;
+ }
};
jj += start;
kk += jj;
@@ -121,29 +129,51 @@ static void split(int32 *I, int32 *V, int32 start, int32 len, int32 h) {
};
};
- if (jj > start) split(I, V, start, jj - start, h);
+ if (jj > start) {
+ split(I, V, start, jj - start, h);
+ }
- for (i = 0; i < kk - jj; i++) V[I[jj + i]] = kk - 1;
- if (jj == kk - 1) I[jj] = -1;
+ for (i = 0; i < kk - jj; i++) {
+ V[I[jj + i]] = kk - 1;
+ }
+ if (jj == kk - 1) {
+ I[jj] = -1;
+ }
- if (start + len > kk) split(I, V, kk, start + len - kk, h);
+ if (start + len > kk) {
+ split(I, V, kk, start + len - kk, h);
+ }
}
static void qsufsort(int32 *I, int32 *V, byte *old, int32 oldsize) {
int32 buckets[256];
int32 i, h, len;
- for (i = 0; i < 256; i++) buckets[i] = 0;
- for (i = 0; i < oldsize; i++) buckets[old[i]]++;
- for (i = 1; i < 256; i++) buckets[i] += buckets[i-1];
- for (i = 255; i > 0; i--) buckets[i] = buckets[i-1];
+ for (i = 0; i < 256; i++) {
+ buckets[i] = 0;
+ }
+ for (i = 0; i < oldsize; i++) {
+ buckets[old[i]]++;
+ }
+ for (i = 1; i < 256; i++) {
+ buckets[i] += buckets[i - 1];
+ }
+ for (i = 255; i > 0; i--) {
+ buckets[i] = buckets[i - 1];
+ }
buckets[0] = 0;
- for (i = 0; i < oldsize; i++) I[++buckets[old[i]]] = i;
+ for (i = 0; i < oldsize; i++) {
+ I[++buckets[old[i]]] = i;
+ }
I[0] = oldsize;
- for (i = 0; i < oldsize; i++) V[i] = buckets[old[i]];
+ for (i = 0; i < oldsize; i++) {
+ V[i] = buckets[old[i]];
+ }
V[oldsize] = 0;
- for (i = 1; i < 256; i++) if (buckets[i] == buckets[i-1] + 1) I[buckets[i]] = -1;
+ for (i = 1; i < 256; i++) if (buckets[i] == buckets[i - 1] + 1) {
+ I[buckets[i]] = -1;
+ }
I[0] = -1;
for (h = 1; I[0] != -(oldsize + 1); h += h) {
@@ -153,32 +183,38 @@ static void qsufsort(int32 *I, int32 *V, byte *old, int32 oldsize) {
len -= I[i];
i -= I[i];
} else {
- if (len) I[i-len] = -len;
+ if (len) {
+ I[i - len] = -len;
+ }
len = V[I[i]] + 1 - i;
split(I, V, i, len, h);
i += len;
len = 0;
};
};
- if (len) I[i-len] = -len;
+ if (len) {
+ I[i - len] = -len;
+ }
};
- for (i = 0; i < oldsize + 1; i++)
+ for (i = 0; i < oldsize + 1; i++) {
I[V[i]] = i;
+ }
}
static int32 matchlen(byte *old, int32 oldsize, byte *new_block, int32 new_size) {
int32 i;
for (i = 0; (i < oldsize) && (i < new_size); i++)
- if (old[i] != new_block[i])
+ if (old[i] != new_block[i]) {
break;
+ }
return i;
}
static int32 search(int32 *I, byte *old, int32 oldsize,
- byte *new_block, int32 newsize, int32 st, int32 en, int32 *pos) {
+ byte *new_block, int32 newsize, int32 st, int32 en, int32 *pos) {
int32 x, y;
if (en - st < 2) {
@@ -220,7 +256,7 @@ arguments parse_args(int argc, char *argv[]) {
arg.mix = false;
int c;
- while ((c = getopt (argc, argv, "nm")) != -1)
+ while ((c = getopt(argc, argv, "nm")) != -1)
switch (c) {
case 'n':
arg.comp_ctrl = false;
@@ -232,7 +268,7 @@ arguments parse_args(int argc, char *argv[]) {
show_usage(argv[0]);
exit(0);
default:
- fprintf (stderr, "Internal error\n");
+ fprintf(stderr, "Internal error\n");
exit(1);
}
@@ -270,10 +306,12 @@ int main(int argc, char *argv[]) {
args = parse_args(argc, argv);
//Set flags
- if (args.mix)
+ if (args.mix) {
flags |= 1 << 0;
- if (args.comp_ctrl)
+ }
+ if (args.comp_ctrl) {
flags |= 1 << 1;
+ }
/* Allocate oldsize+1 bytes instead of oldsize bytes to ensure
that we never try to alloc zero elements and get a NULL pointer */
@@ -291,7 +329,7 @@ int main(int argc, char *argv[]) {
std::cerr << "Unable to allocate memory" << std::endl;
return 1;
}
- in.read((char*)old, oldsize);
+ in.read((char *)old, oldsize);
if (in.fail()) {
std::cerr << "Unable to read from " << args.oldfile << std::endl;
return 1;
@@ -321,7 +359,7 @@ int main(int argc, char *argv[]) {
std::cerr << "Unable to allocate memory" << std::endl;
return 1;
}
- in.read((char*)new_block, newsize);
+ in.read((char *)new_block, newsize);
if (in.fail()) {
std::cerr << "Unable to read from " << args.newfile << std::endl;
return 1;
@@ -351,16 +389,16 @@ int main(int argc, char *argv[]) {
return 1;
}
- memcpy(header, "PATR", 4); //Signature
- WRITE_LE_UINT16(header + 4, 2); //Version major
- WRITE_LE_UINT16(header + 6, 0); //Version minor
- WRITE_LE_UINT32(header + 8, flags); //flags
- Common::md5_file(args.oldfile, header + 12, 5000); //Md5sum
- WRITE_LE_UINT32(header + 28, oldsize); //oldsize
- WRITE_LE_UINT32(header + 32, newsize); //newsize
- //WRITE_LE_UINT32(header + 36, 0); //ctrl compressed size
- //WRITE_LE_UINT32(header + 40, 0); //diff compressed size
- //WRITE_LE_UINT32(header + 44, 0); //extra compressed size
+ memcpy(header, "PATR", 4); //Signature
+ WRITE_LE_UINT16(header + 4, 2); //Version major
+ WRITE_LE_UINT16(header + 6, 0); //Version minor
+ WRITE_LE_UINT32(header + 8, flags); //flags
+ Common::md5_file(args.oldfile, header + 12, 5000); //Md5sum
+ WRITE_LE_UINT32(header + 28, oldsize); //oldsize
+ WRITE_LE_UINT32(header + 32, newsize); //newsize
+ //WRITE_LE_UINT32(header + 36, 0); //ctrl compressed size
+ //WRITE_LE_UINT32(header + 40, 0); //diff compressed size
+ //WRITE_LE_UINT32(header + 44, 0); //extra compressed size
patch.write((char *)header, 48);
if (patch.bad()) {
std::cerr << "Write error on " << args.patchfile << std::endl;
@@ -369,8 +407,9 @@ int main(int argc, char *argv[]) {
/* Compute the differences, writing ctrl as we go */
GZipWriteStream *ctrlBlock;
- if (args.comp_ctrl)
+ if (args.comp_ctrl) {
ctrlBlock = new GZipWriteStream(&patch);
+ }
scan = 0;
len = 0;
@@ -382,19 +421,23 @@ int main(int argc, char *argv[]) {
for (scsc = scan += len; scan < newsize; scan++) {
len = search(I, old, oldsize, new_block + scan, newsize - scan,
- 0, oldsize, &pos);
+ 0, oldsize, &pos);
for (; scsc < scan + len; scsc++)
if ((scsc + lastoffset < oldsize) &&
- (old[scsc + lastoffset] == new_block[scsc]))
+ (old[scsc + lastoffset] == new_block[scsc])) {
oldscore++;
+ }
if (((len == oldscore) && (len != 0)) ||
- (len > oldscore + 8)) break;
+ (len > oldscore + 8)) {
+ break;
+ }
if ((scan + lastoffset < oldsize) &&
- (old[scan + lastoffset] == new_block[scan]))
+ (old[scan + lastoffset] == new_block[scan])) {
oldscore--;
+ }
};
if ((len != oldscore) || (scan == newsize)) {
@@ -402,7 +445,9 @@ int main(int argc, char *argv[]) {
Sf = 0;
lenf = 0;
for (i = 0; (lastscan + i < scan) && (lastpos + i < oldsize);) {
- if (old[lastpos + i] == new_block[lastscan + i]) s++;
+ if (old[lastpos + i] == new_block[lastscan + i]) {
+ s++;
+ }
i++;
if (s * 2 - i > Sf * 2 - lenf) {
Sf = s;
@@ -415,7 +460,9 @@ int main(int argc, char *argv[]) {
s = 0;
Sb = 0;
for (i = 1; (scan >= lastscan + i) && (pos >= i); i++) {
- if (old[pos - i] == new_block[scan - i]) s++;
+ if (old[pos - i] == new_block[scan - i]) {
+ s++;
+ }
if (s * 2 - i > Sb * 2 - lenb) {
Sb = s;
lenb = i;
@@ -430,9 +477,13 @@ int main(int argc, char *argv[]) {
lens = 0;
for (i = 0; i < overlap; i++) {
if (new_block[lastscan + lenf - overlap + i] ==
- old[lastpos + lenf - overlap + i]) s++;
+ old[lastpos + lenf - overlap + i]) {
+ s++;
+ }
if (new_block[scan - lenb + i] ==
- old[pos - lenb + i]) s--;
+ old[pos - lenb + i]) {
+ s--;
+ }
if (s > Ss) {
Ss = s;
lens = i + 1;
@@ -443,17 +494,20 @@ int main(int argc, char *argv[]) {
lenb -= lens;
};
- for (i = 0; i < lenf; i++)
+ for (i = 0; i < lenf; i++) {
db[dblen + i] = new_block[lastscan + i] ^ old[lastpos + i];
+ }
dblen += lenf;
if (!args.mix) {
- for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++)
+ for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++) {
eb[eblen + i] = new_block[lastscan + lenf + i];
+ }
eblen += (scan - lenb) - (lastscan + lenf);
} else {
- for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++)
+ for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++) {
db[dblen + i] = new_block[lastscan + lenf + i];
+ }
dblen += (scan - lenb) - (lastscan + lenf);
}
@@ -464,8 +518,9 @@ int main(int argc, char *argv[]) {
std::cerr << "Write error on " << args.patchfile << std::endl;
return 1;
}
- } else
- patch.write((char*)buf, 4);
+ } else {
+ patch.write((char *)buf, 4);
+ }
WRITE_LE_UINT32(buf, (scan - lenb) - (lastscan + lenf));
@@ -475,8 +530,9 @@ int main(int argc, char *argv[]) {
std::cerr << "Write error on " << args.patchfile << std::endl;
return 1;
}
- } else
- patch.write((char*)buf, 4);
+ } else {
+ patch.write((char *)buf, 4);
+ }
WRITE_LE_UINT32(buf, int32((pos - lenb) - (lastpos + lenf)));
if (args.comp_ctrl) {
@@ -485,16 +541,18 @@ int main(int argc, char *argv[]) {
std::cerr << "Write error on " << args.patchfile << std::endl;
return 1;
}
- } else
- patch.write((char*)buf, 4);
+ } else {
+ patch.write((char *)buf, 4);
+ }
lastscan = scan - lenb;
lastpos = pos - lenb;
lastoffset = pos - scan;
};
};
- if (args.comp_ctrl)
+ if (args.comp_ctrl) {
delete ctrlBlock;
+ }
/* Compute size of ctrl data (compressed or not)*/
if ((len = patch.tellp()) == -1) {
@@ -538,9 +596,9 @@ int main(int argc, char *argv[]) {
WRITE_LE_UINT32(header + 44, newsize2 - newsize);
delete[] eb;
- }
- else
+ } else {
WRITE_LE_UINT32(header + 44, 0);
+ }
/* Seek to the beginning, write the header, and close the file */
patch.seekp(0, std::ios::beg);
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index 55d3f0636..c5c976159 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -30,19 +30,19 @@ int main(int argc, char **argv) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
-
+
Lab *lab = NULL;
std::string filename;
-
+
if (argc > 2) {
lab = new Lab(argv[1]);
filename = argv[2];
} else {
filename = argv[1];
}
-
+
std::istream *file = getFile(filename, lab);
-
+
if (!file) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
@@ -61,22 +61,22 @@ int main(int argc, char **argv) {
int unknown2 = readInt(*file);
int numKeyframes = readInt(*file);
std::cout << "Bone: " << boneName << " Operation: " << operation << " Unknown1: " << unknown1 <<
- " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
+ " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
if (operation == 3) { // Translation
- for(int j = 0; j < numKeyframes; j++) {
+ for (int j = 0; j < numKeyframes; j++) {
vec3d = readVector3d(*file);
time = readFloat(*file);
std::cout << "Time : " << time << " Vector: " << vec3d->toString() << std::endl;
delete vec3d;
}
} else if (operation == 4) { // Rotation
- for(int j = 0; j < numKeyframes; j++) {
+ for (int j = 0; j < numKeyframes; j++) {
vec4d = readVector4d(*file);
time = readFloat(*file);
std::cout << "Time : " << time << " Vector: " << vec4d->toString() << std::endl;
delete vec4d;
- }
+ }
}
}
diff --git a/tools/emi/cosb2cos.cpp b/tools/emi/cosb2cos.cpp
index 66ef36309..3479a3756 100644
--- a/tools/emi/cosb2cos.cpp
+++ b/tools/emi/cosb2cos.cpp
@@ -30,9 +30,10 @@
std::vector<std::string> g_tag;
std::string getTag(std::string str) {
- if (str.at(0) != '!')
+ if (str.at(0) != '!') {
std::cout << "Erroneous Tag\n";
- std::string tag = str.substr(1,4);
+ }
+ std::string tag = str.substr(1, 4);
return tag;
}
@@ -43,8 +44,9 @@ std::string getCompName(std::string str) {
void pushtag(std::string tag) {
std::vector<std::string>::iterator it;
for (it = g_tag.begin(); it != g_tag.end(); it++) {
- if (*it == tag)
+ if (*it == tag) {
return;
+ }
}
g_tag.push_back(tag);
}
@@ -66,7 +68,7 @@ struct ChoreTrack {
int _parentID;
int _numKeys;
TrackKey *_keys;
-
+
void readFromFile(std::istream &file) {
// Split this into tag & name later.
_trackName = readString(file);
@@ -75,16 +77,16 @@ struct ChoreTrack {
_hash = readInt(file);
_parentID = readInt(file);
_numKeys = readInt(file);
-
+
pushtag(_tag);
-
+
_keys = new TrackKey[_numKeys];
for (int k = 0; k < _numKeys; k++) {
_keys[k].readFromFile(file);
}
}
void printComponent(int &count) {
- std::cout << count << "\t" << _tag << "\t" << _hash << "\t" <<_parentID << "\t" << _trackName << std::endl;
+ std::cout << count << "\t" << _tag << "\t" << _hash << "\t" << _parentID << "\t" << _trackName << std::endl;
}
};
@@ -93,25 +95,25 @@ struct Chore {
float _length;
int _numTracks;
ChoreTrack *_tracks;
-
+
void readFromFile(std::istream &file) {
_choreName = readString(file);
- _length = readFloat(file);
+ _length = readFloat(file);
_numTracks = readInt(file);
_tracks = new ChoreTrack[_numTracks];
-
+
for (int j = 0; j < _numTracks; j++) {
_tracks[j].readFromFile(file);
}
}
-
+
void printComponents(int &count) {
for (int i = 0; i < _numTracks; i++) {
_tracks[i].printComponent(count);
count++;
}
}
-
+
void print(int count) {
std::cout << count << "\t" << _length << "\t" << _numTracks << "\t" << _choreName << std::endl;
}
@@ -120,12 +122,12 @@ struct Chore {
struct Costume {
int _numChores;
Chore *_chores;
-
+
void readFromFile(std::istream &file) {
_numChores = readInt(file);
-
+
_chores = new Chore[_numChores];
-
+
for (int i = 0; i < _numChores; i++) {
_chores[i].readFromFile(file);
}
@@ -137,13 +139,13 @@ struct Costume {
std::cout << "\tnumtags " << g_tag.size() << std::endl;
int i = 0;
std::vector<std::string>::iterator it = g_tag.begin();
- for(; it != g_tag.end(); it++) {
+ for (; it != g_tag.end(); it++) {
std::cout << i++ << "\t" << *it << std::endl;
}
std::cout << std::endl;
std::cout << "section: components\n";
std::cout << "\tnumcomponents: x\n";
-
+
int count = 0;
for (int i = 0; i < _numChores; i++) {
_chores[i].printComponents(count);
@@ -166,10 +168,11 @@ struct Costume {
for (int i = 0; i < _numChores; i++) {
if (_chores[i]._choreName == choreName) {
std::cout << "Chore " << choreName << " (" << _chores[i]._numTracks << " tracks) ";
- if (_chores[i]._length == 1000)
+ if (_chores[i]._length == 1000) {
std::cout << "(instant)";
- else
+ } else {
std::cout << 1000.0 * _chores[i]._length << " ms";
+ }
std::cout << std::endl;
for (int t = 0; t < _chores[i]._numTracks; t++) {
@@ -194,19 +197,19 @@ struct Costume {
};
int main(int argc, char **argv) {
- if(argc < 2){
+ if (argc < 2) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
std::string filename = argv[1];
-
+
std::fstream file(filename.c_str(), std::ios::in | std::ios::binary);
-
+
if (!file.is_open()) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
-
+
Costume c;
c.readFromFile(file);
if (argc == 2) {
@@ -214,5 +217,5 @@ int main(int argc, char **argv) {
} else {
c.printChore(argv[2]);
}
-
+
}
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index ce5506523..c3d19081f 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -31,10 +31,10 @@ int main(int argc, char **argv) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
-
+
Lab *lab = NULL;
std::string filename;
-
+
if (argc > 2) {
lab = new Lab(argv[1]);
filename = argv[2];
@@ -43,18 +43,18 @@ int main(int argc, char **argv) {
}
std::istream *file = getFile(filename, lab);
-
+
if (!file) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
int strLength = 0;
-
+
std::string nameString = readString(*file);
-
+
Vector4d *vec4d;
Vector3d *vec3d;
-
+
vec4d = readVector4d(*file);
std::cout << "# Spheredata: " << vec4d->toString() << std::endl;
delete vec4d;
@@ -69,28 +69,28 @@ int main(int argc, char **argv) {
int setType = readInt(*file);
std::cout << "# NumTexSets: " << numTexSets << " setType: " << setType << std::endl;
int numTextures = readInt(*file);
-
+
std::string *texNames = new std::string[numTextures];
- for(int i = 0;i < numTextures; i++) {
+ for (int i = 0; i < numTextures; i++) {
texNames[i] = readString(*file);
// Every texname seems to be followed by 4 0-bytes (Ref mk1.mesh,
// this is intentional)
readInt(*file);
}
- for(int i = 0;i < numTextures;i++){
+ for (int i = 0; i < numTextures; i++) {
std::cout << "# TexName " << texNames[i] << std::endl;
}
// 4 unknown bytes - usually with value 19
readInt(*file);
-
+
// Should create an empty mtl
std::cout << "mtllib quit.mtl" << std::endl << "o Arrow" << std::endl;
int numVertices = readInt(*file);
std::cout << "#File has " << numVertices << " Vertices" << std::endl;
-
+
float x = 0, y = 0;
- int r = 0, g = 0, b = 0, a = 0;
+ int r = 0, g = 0, b = 0, a = 0;
// Vertices
for (int i = 0; i < numVertices; ++i) {
vec3d = readVector3d(*file);
@@ -117,9 +117,9 @@ int main(int argc, char **argv) {
y = readFloat(*file);
std::cout << "vt " << x << " " << y << std::endl;
}
-
- std::cout << "usemtl (null)"<< std::endl;
-
+
+ std::cout << "usemtl (null)" << std::endl;
+
// Faces
// The head of this section needs quite a bit of rechecking
int numFaces = 0;
@@ -128,14 +128,15 @@ int main(int argc, char **argv) {
int flags = 0;
numFaces = readInt(*file);
int faceLength = 0;
- for(int j = 0; j < numFaces; j++){
+ for (int j = 0; j < numFaces; j++) {
flags = readInt(*file);
hasTexture = readInt(*file);
- if(hasTexture)
+ if (hasTexture) {
texID = readInt(*file);
+ }
faceLength = readInt(*file);
std::cout << "#Face-header: flags: " << flags << " hasTexture: " << hasTexture
- << " texId: " << texID << " faceLength: " << faceLength << std::endl;
+ << " texId: " << texID << " faceLength: " << faceLength << std::endl;
short xCoord = 0, yCoord = 0, zCoord = 0;
std::cout << "g " << j << std::endl;
for (int i = 0; i < faceLength; i += 3) {
@@ -146,30 +147,31 @@ int main(int argc, char **argv) {
}
}
int hasBones = readInt(*file);
-
+
if (hasBones == 1) {
int numBones = readInt(*file);
char **boneNames = new char*[numBones];
- for(int i = 0;i < numBones; i++) {
+ for (int i = 0; i < numBones; i++) {
strLength = readInt(*file);
boneNames[i] = new char[strLength];
file->read(boneNames[i], strLength);
std::cout << "# BoneName " << boneNames[i] << std::endl;
}
-
+
int numBoneData = readInt(*file);
int unknownVal = 0;
int boneDatanum;
float boneDataWgt;
int vertex = 0;
- for(int i = 0;i < numBoneData; i++) {
+ for (int i = 0; i < numBoneData; i++) {
unknownVal = readInt(*file);
boneDatanum = readInt(*file);
boneDataWgt = readFloat(*file);
- if(unknownVal)
+ if (unknownVal) {
vertex++;
+ }
std::cout << "# BoneData: Vertex: " << vertex << " boneNum: "
- << boneDatanum << " weight: " << boneDataWgt << std::endl;
+ << boneDatanum << " weight: " << boneDataWgt << std::endl;
}
}
}
diff --git a/tools/emi/model.h b/tools/emi/model.h
index f436c603a..b3cc46c34 100644
--- a/tools/emi/model.h
+++ b/tools/emi/model.h
@@ -115,7 +115,7 @@ public:
float _timelen;
int _numBones;
int _numKeyFrames;
- std::vector<Bone*> _bones;
+ std::vector<Bone *> _bones;
};
class Mesh {
@@ -133,7 +133,7 @@ class Mesh {
Bone *_bones;
int _numBones;
- std::map<std::string, Bone*> _boneMap;
+ std::map<std::string, Bone *> _boneMap;
Animation *_anim;
diff --git a/tools/emi/renderModel.cpp b/tools/emi/renderModel.cpp
index d3ab1384d..80f75d084 100644
--- a/tools/emi/renderModel.cpp
+++ b/tools/emi/renderModel.cpp
@@ -47,21 +47,25 @@ using namespace std;
*/
bool Bone::hasChild(Bone *node) {
- if (!_child)
+ if (!_child) {
return false;
- if (_child == node)
+ }
+ if (_child == node) {
return true;
- else
+ } else {
return _child->hasSibling(node);
+ }
}
bool Bone::hasSibling(Bone *node) {
- if (!_sibling)
+ if (!_sibling) {
return false;
- if (_sibling == node)
+ }
+ if (_sibling == node) {
return true;
- else
+ } else {
return _sibling->hasSibling(node);
+ }
}
void Bone::addChild(Bone *node) {
@@ -97,11 +101,12 @@ void Material::bindTexture(int index) {
}
void Material::loadTexture(string filename) {
- string s = filename.substr(filename.length()-3);
- if (s == "sur")
+ string s = filename.substr(filename.length() - 3);
+ if (s == "sur") {
loadSURTexture(filename);
- else
+ } else {
loadTGATexture(filename);
+ }
}
void Material::loadSURTexture(string filename) {
@@ -127,7 +132,7 @@ void Material::loadSURTexture(string filename) {
void Material::loadTGATexture(string filename) {
std::istream *file = getFile(filename, _lab);
- if (!((fstream*)file)->is_open()) {
+ if (!((fstream *)file)->is_open()) {
std::cout << "Unable to open file " << filename << std::endl;
return;
}
@@ -148,14 +153,15 @@ void Material::loadTGATexture(string filename) {
height = readShort(*file);
bpp = readByte(*file);
file->seekg(1, std::ios::cur);
- if(bpp!=24)
- cout << bpp <<" BPP " << endl;
- int len = width * height * bpp/8;
+ if (bpp != 24) {
+ cout << bpp << " BPP " << endl;
+ }
+ int len = width * height * bpp / 8;
char *newData = new char[len];
- char *target = newData + len - width * bpp/8;
+ char *target = newData + len - width * bpp / 8;
for (int i = 0; i < height; i++) {
- file->read(target, width*(bpp/8));
- target -= width * (bpp/8);
+ file->read(target, width * (bpp / 8));
+ target -= width * (bpp / 8);
}
glBindTexture(GL_TEXTURE_2D, _texIDs[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -169,11 +175,12 @@ void Material::loadTGATexture(string filename) {
void MeshFace::loadFace(std::istream *file) {
_flags = readInt(*file);
_hasTexture = readInt(*file);
- if(_hasTexture > 1) {
+ if (_hasTexture > 1) {
cout << "We have this many textures: " << _hasTexture << endl;
}
- if(_hasTexture)
+ if (_hasTexture) {
_texID = readInt(*file);
+ }
_faceLength = readInt(*file);
short x = 0, y = 0, z = 0;
_indexes = new Vector3<int>[_faceLength];
@@ -182,12 +189,12 @@ void MeshFace::loadFace(std::istream *file) {
file->read((char *)&x, 2);
file->read((char *)&y, 2);
file->read((char *)&z, 2);
- _indexes[i].setVal(x,y,z);
+ _indexes[i].setVal(x, y, z);
}
}
void MeshFace::render() {
- if(_hasTexture) {
+ if (_hasTexture) {
_parent->setTex(_texID);
}
glDrawElements(GL_TRIANGLES, _faceLength * 3, GL_UNSIGNED_INT, _indexes);
@@ -206,7 +213,7 @@ void Mesh::loadMesh(string filename) {
_boxData = readVector3d(*file);
_boxData2 = readVector3d(*file);
std::cout << "# Boxdata: " << _boxData->toString()
- << _boxData2->toString() << std::endl;
+ << _boxData2->toString() << std::endl;
_numTexSets = readInt(*file);
_setType = readInt(*file);
@@ -215,7 +222,7 @@ void Mesh::loadMesh(string filename) {
_texNames = new string[_numTextures];
- for(int i = 0;i < _numTextures; i++) {
+ for (int i = 0; i < _numTextures; i++) {
_texNames[i] = readString(*file);
// Every texname seems to be followed by 4 0-bytes (Ref mk1.mesh,
// this is intentional)
@@ -247,18 +254,18 @@ void Mesh::loadMesh(string filename) {
file->read((char *) &_numFaces, 4);
_faces = new MeshFace[_numFaces];
int faceLength = 0;
- for(int j = 0;j < _numFaces; j++) {
+ for (int j = 0; j < _numFaces; j++) {
_faces[j].setParent(this);
_faces[j].loadFace(file);
}
int hasBones = 0;
- file->read((char*)&hasBones, 4);
+ file->read((char *)&hasBones, 4);
if (hasBones == 1) {
_numBones = readInt(*file);
_bones = new Bone[_numBones];
- for(int i = 0;i < _numBones; i++) {
+ for (int i = 0; i < _numBones; i++) {
_bones[i].setName(readString(*file));
_boneMap[_bones[i].getName()] = _bones + i;
}
@@ -268,12 +275,13 @@ void Mesh::loadMesh(string filename) {
int boneDatanum;
float boneDataWgt;
int vertex = 0;
- for(int i = 0;i < numBoneData; i++) {
+ for (int i = 0; i < numBoneData; i++) {
unknownVal = readInt(*file);
boneDatanum = readInt(*file);
boneDataWgt = readFloat(*file);
- if(unknownVal)
+ if (unknownVal) {
vertex++;
+ }
_bones[boneDatanum].addVertex(vertex, boneDataWgt);
}
}
@@ -292,33 +300,34 @@ void Mesh::loadSkeleton(std::string filename) {
float angle = 0.0f;
// Bones are listed in the same order as in the meshb.
Vector3d *vec = 0;
- for(int i = 0;i < numBones; i++) {
- boneName = readCString(*file,32);
- parentName = readCString(*file,32);
+ for (int i = 0; i < numBones; i++) {
+ boneName = readCString(*file, 32);
+ parentName = readCString(*file, 32);
bone = _boneMap[boneName];
- /* for (int j = 0; j < _numBones; j++) {
- if (_bones[j].getName() == boneName) {
- bone = _bones + j;
- break;
- }
- }*/
+ /* for (int j = 0; j < _numBones; j++) {
+ if (_bones[j].getName() == boneName) {
+ bone = _bones + j;
+ break;
+ }
+ }*/
if (parentName != "no_parent") {
- /* for (int j = 0; j < _numBones; j++) {
- if (_bones[j].getName() == parentName) {
- parent = _bones + j;
- break;
- }
- }*/
+ /* for (int j = 0; j < _numBones; j++) {
+ if (_bones[j].getName() == parentName) {
+ parent = _bones + j;
+ break;
+ }
+ }*/
parent = _boneMap[parentName];
assert(parent != 0);
assert(bone != 0);
- if (!parent->hasChild(bone))
+ if (!parent->hasChild(bone)) {
parent->addChild(bone);
+ }
}
bone->setPos(readVector3d(*file));
bone->setRot(readVector3d(*file));
@@ -353,16 +362,16 @@ void Mesh::loadAnimation(std::string filename) {
keyList = new KeyframeList(numKeyframes, operation);
std::cout << "Bone: " << boneName << " Operation: " << operation << " Unknown1: " << unknown1 <<
- " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
+ " Unknown2: " << unknown2 << " numKeyframes: " << numKeyframes << std::endl;
if (operation == 3) { // Translation
- for(int i = 0; i < numKeyframes; i++) {
+ for (int i = 0; i < numKeyframes; i++) {
key = keyList->_frames + i;
key->_time = readFloat(*file);
key->_vec3d = readVector3d(*file);
}
} else if (operation == 4) { // Rotation
- for(int i = 0; i < numKeyframes; i++) {
+ for (int i = 0; i < numKeyframes; i++) {
key = keyList->_frames + i;
key->_time = readFloat(*file);
key->_vec4d = readVector4d(*file);
@@ -391,7 +400,7 @@ void Mesh::render() {
glNormalPointer(GL_FLOAT, 0, _normals);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, _colorMap);
- for(int i = 0; i < _numFaces; i++) {
+ for (int i = 0; i < _numFaces; i++) {
_faces[i].render();
}
@@ -402,7 +411,7 @@ void Mesh::render() {
}
void renderInit() {
- glClearColor(0.2f,0.2f,0.2f,0.0);
+ glClearColor(0.2f, 0.2f, 0.2f, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
}
@@ -411,11 +420,11 @@ Mesh m;
void renderLoop() {
float rot = 0.5f;
- while(true) {
+ while (true) {
renderInit();
- glTranslatef(0.0,-0.9f, 0.0f);
- glRotatef(rot,0.0f,0.1f,0.0f);
- rot+=0.1f;
+ glTranslatef(0.0, -0.9f, 0.0f);
+ glRotatef(rot, 0.0f, 0.1f, 0.0f);
+ rot += 0.1f;
m.render();
glFlush();
glfwSwapBuffers();
@@ -431,9 +440,11 @@ int main(int argc, char **argv) {
m.loadMesh(argv[2]);
} else {
m.loadMesh(argv[1]);
- } if (argc > 3) {
+ }
+ if (argc > 3) {
m.loadSkeleton(argv[3]);
- } if (argc > 4) {
+ }
+ if (argc > 4) {
m.loadAnimation(argv[4]);
}
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index 445488988..7a2b7315b 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -42,7 +42,7 @@ enum SectorType {
};
-enum LightType{
+enum LightType {
omni,
direct
};
@@ -60,49 +60,42 @@ private:
const char *buf;
};
-Data::Data(const char *data)
-{
+Data::Data(const char *data) {
buf = data;
}
-float Data::GetFloat()
-{
+float Data::GetFloat() {
float retVal = *(float *) buf;
buf += 4;
return retVal;
}
-int Data::GetInt()
-{
+int Data::GetInt() {
int retVal = *(int *) buf;
buf += 4;
return retVal;
}
-bool Data::GetBool()
-{
+bool Data::GetBool() {
bool retVal = *(bool *) buf;
buf += 1;
return retVal;
}
-string Data::GetString(int length)
-{
+string Data::GetString(int length) {
//kind of a hack
string s = string(buf);
buf += length;
return s;
}
-string Data::GetNullTerminatedString()
-{
+string Data::GetNullTerminatedString() {
string s = string(buf);
- buf += s.length()+1;
+ buf += s.length() + 1;
return s;
}
-void Data::Skip(int val)
-{
+void Data::Skip(int val) {
buf += val;
}
@@ -116,13 +109,11 @@ protected:
Data *data;
};
-Section::Section(Data *data)
-{
+Section::Section(Data *data) {
this->data = data;
}
-class Sector : public Section
-{
+class Sector : public Section {
public:
Sector(Data *data);
@@ -133,20 +124,18 @@ private:
SectorType type;
float height;
int numVertices; // byte;
- float* vertices; // 3 * numVertices.
+ float *vertices; // 3 * numVertices.
float normal[3];
bool visible;
};
-Sector::Sector(Data *data) : Section(data)
-{
+Sector::Sector(Data *data) : Section(data) {
numVertices = data->GetInt();
- vertices = new float[3*numVertices];
- for(int i=0; i < numVertices; i++)
- {
- vertices[0+3*i] = data->GetFloat();
- vertices[1+3*i] = data->GetFloat();
- vertices[2+3*i] = data->GetFloat();
+ vertices = new float[3 * numVertices];
+ for (int i = 0; i < numVertices; i++) {
+ vertices[0 + 3 * i] = data->GetFloat();
+ vertices[1 + 3 * i] = data->GetFloat();
+ vertices[2 + 3 * i] = data->GetFloat();
}
int nameLength = data->GetInt();
@@ -155,7 +144,7 @@ Sector::Sector(Data *data) : Section(data)
visible = data->GetBool();
type = (SectorType)data->GetInt();
int skip = data->GetInt();
- data->Skip(skip*4);
+ data->Skip(skip * 4);
height = data->GetFloat();
float cross1[3], cross2[3];
@@ -164,9 +153,9 @@ Sector::Sector(Data *data) : Section(data)
cross1[2] = vertices[5] - vertices[2];
int x = 3 * (numVertices - 1);
- cross2[0] = vertices[x+0] - vertices[0];
- cross2[1] = vertices[x+1] - vertices[1];
- cross2[2] = vertices[x+2] - vertices[2];
+ cross2[0] = vertices[x + 0] - vertices[0];
+ cross2[1] = vertices[x + 1] - vertices[1];
+ cross2[2] = vertices[x + 2] - vertices[2];
float &nx = normal[0];
float &ny = normal[1];
@@ -182,11 +171,10 @@ Sector::Sector(Data *data) : Section(data)
nz /= norm;
}
-string Sector::ToString()
-{
+string Sector::ToString() {
stringstream ss;
ss.precision(6);
- ss.setf(ios::fixed,ios::floatfield);
+ ss.setf(ios::fixed, ios::floatfield);
ss << "\tsector\t" << name << endl;
ss << "\tID\t" << ID << endl;
ss << "\ttype\t";
@@ -209,26 +197,27 @@ string Sector::ToString()
};
ss << endl;
ss << "\tdefault visibility\t";
- if (visible)
+ if (visible) {
ss << "visible";
- else
+ } else {
ss << "invisible";
+ }
ss << endl;
ss << "\theight\t" << height << endl;
ss << "\tnumvertices\t" << numVertices << endl;
ss << "\tnormal\t\t\t" << normal[0] << "\t" << normal[1] << "\t" << normal[2] << endl;
ss << "\tvertices:\t\t";
- for (int i = 0; i < numVertices*3; i+=3) {
- if (i != 0)
+ for (int i = 0; i < numVertices * 3; i += 3) {
+ if (i != 0) {
ss << "\t\t\t\t";
- ss << vertices[i] << "\t" << vertices[i+1] << "\t" << vertices[i+2] << endl;
+ }
+ ss << vertices[i] << "\t" << vertices[i + 1] << "\t" << vertices[i + 2] << endl;
}
return ss.str();
}
-class Setup : public Section
-{
+class Setup : public Section {
public:
Setup(Data *data);
@@ -238,16 +227,15 @@ private:
string tile;
string background;
string zbuffer;
- float* position;
- float* interest;
+ float *position;
+ float *interest;
float roll;
float fov;
float nclip;
float fclip;
};
-Setup::Setup(Data *data) : Section(data)
-{
+Setup::Setup(Data *data) : Section(data) {
name = data->GetString(128); // Parse a string really
// Skip an unknown number
@@ -274,11 +262,10 @@ Setup::Setup(Data *data) : Section(data)
fclip = data->GetFloat();
}
-string Setup::ToString()
-{
+string Setup::ToString() {
stringstream ss;
ss.precision(6);
- ss.setf(ios::fixed,ios::floatfield);
+ ss.setf(ios::fixed, ios::floatfield);
ss << "\tname\t" << name << endl;
// background
// zbuffer
@@ -292,8 +279,7 @@ string Setup::ToString()
return ss.str();
}
-class Light : public Section
-{
+class Light : public Section {
public:
Light(Data *data);
virtual string ToString();
@@ -301,22 +287,20 @@ public:
private:
string name;
LightType type;
- float* position;
- float* direction;
+ float *position;
+ float *direction;
float intensity;
float umbraangla;
float penumbraangle;
- int* color; // Byte
+ int *color; // Byte
};
-Light::Light(Data *data) : Section(data)
-{
+Light::Light(Data *data) : Section(data) {
data->Skip(100);
}
-string Light::ToString()
-{
+string Light::ToString() {
return "";
}
@@ -336,79 +320,78 @@ private:
vector<Section *> sectors;
};
-Set::Set(Data *data)
-{
+Set::Set(Data *data) {
numSetups = data->GetInt();
setups.reserve(numSetups);
- for(uint32 i = 0; i < numSetups; i++) {
+ for (uint32 i = 0; i < numSetups; i++) {
setups.push_back(new Setup(data));
}
numLights = data->GetInt();
lights.reserve(numLights);
- for(uint32 i = 0; i < numLights; i++) {
+ for (uint32 i = 0; i < numLights; i++) {
lights.push_back(new Light(data));
}
numSectors = data->GetInt();
sectors.reserve(numSectors);
- for(uint32 i = 0; i < numSectors; i++) {
+ for (uint32 i = 0; i < numSectors; i++) {
sectors.push_back(new Sector(data));
}
}
-string Set::ToString()
-{
+string Set::ToString() {
stringstream ss;
// colormaps
ss << "section: colormaps" << endl; // we don't have any.
// setups
ss << "section: setups" << endl;
- vector<Section*>::iterator it;
+ vector<Section *>::iterator it;
ss << "\tnumsetups " << setups.size() << endl;
- for(it = setups.begin(); it != setups.end(); ++it) {
+ for (it = setups.begin(); it != setups.end(); ++it) {
ss << (*it)->ToString() << endl << endl;
}
// lights
ss << "section: lights" << endl;
ss << "\tnumlights 0" << endl;
- for(it = lights.begin();it!=lights.end();it++) {
+ for (it = lights.begin(); it != lights.end(); it++) {
ss << (*it)->ToString() << endl << endl;
}
// sectors
ss << "section: sectors\n";
- for(it = sectors.begin(); it != sectors.end();it++) {
+ for (it = sectors.begin(); it != sectors.end(); it++) {
ss << (*it)->ToString() << endl << endl;
}
return ss.str();
}
-int main(int argc, char** argv){
- if (argc < 2)
+int main(int argc, char **argv) {
+ if (argc < 2) {
return 0;
+ }
Lab *lab = NULL;
std::string filename;
int length = 0;
-
+
if (argc > 2) {
lab = new Lab(argv[1]);
filename = argv[2];
} else {
filename = argv[1];
}
-
+
std::istream *file = getFile(filename, lab, length);
-
+
if (!file) {
std::cout << "Could not open file" << std::endl;
return 0;
}
-
+
char *buf = new char[length];
file->read(buf, length);
delete file;
-
+
Data *data = new Data(buf);
- Set* ourSet = new Set(data);
+ Set *ourSet = new Set(data);
delete data;
delete buf;
cout << ourSet->ToString();
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
index 4b75a6a9a..29b95600d 100644
--- a/tools/emi/sklb2txt.cpp
+++ b/tools/emi/sklb2txt.cpp
@@ -35,36 +35,36 @@ int main(int argc, char **argv) {
std::cout << "Error: filename not specified" << std::endl;
return 0;
}
-
+
Lab *lab = NULL;
std::string filename;
-
+
if (argc > 2) {
lab = new Lab(argv[1]);
filename = argv[2];
} else {
filename = argv[1];
}
-
+
std::istream *file = getFile(filename, lab);
-
+
if (!file) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
int numBones = readInt(*file);
-
+
char boneString[32];
char parentString[32];
float angle = 0;
// Bones are listed in the same order as in the meshb.
Vector3d *vec = 0;
- for(int i=0;i<numBones;i++) {
- file->read((char*)&boneString,32);
- file->read((char*)&parentString,32);
-
- std::cout << "# BoneName " << boneString << "\twith parent: " << parentString << "\t";
+ for (int i = 0; i < numBones; i++) {
+ file->read((char *)&boneString, 32);
+ file->read((char *)&parentString, 32);
+
+ std::cout << "# BoneName " << boneString << "\twith parent: " << parentString << "\t";
std::cout << " position: ";
vec = readVector3d(*file);
std::cout << vec->toString();
diff --git a/tools/emi/til2bmp.cpp b/tools/emi/til2bmp.cpp
index a1e99f819..5d660ae3d 100644
--- a/tools/emi/til2bmp.cpp
+++ b/tools/emi/til2bmp.cpp
@@ -46,13 +46,13 @@ The current implementation also has a few limitation w.r.t. if there should be T
Also, I _THINK_ that it should work on Big-Endian-systems now, but I haven't gotten around to testing that yet.
Usage:
-til2bmp <filename>
+til2bmp <filename>
somaen.
*/
-struct BMPHeader{
+struct BMPHeader {
uint32_t size;
uint32_t reserved;
uint32_t offset;
@@ -70,51 +70,55 @@ struct BMPHeader{
Bytef *decompress(Bytef *in, int size, uint32_t &outsize);
-class LucasBitMap{
+class LucasBitMap {
public:
char *_data;
- inline uint32_t size(){ return _height*_width*_bpp; }
+ inline uint32_t size() {
+ return _height * _width * _bpp;
+ }
uint32_t _width, _height, _bpp;
- ~LucasBitMap(){ delete[] _data; }
- LucasBitMap() : _data(0), _width(0), _height(0), _bpp(4){}
- LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp=4, bool copy=true);
- void MakeNewData(){
- printf("Size: %d Bpp: %d Width: %d Height: %d\n",size(),_bpp,_width,_height);
- _data = new char[size()];
-
+ ~LucasBitMap() {
+ delete[] _data;
+ }
+ LucasBitMap() : _data(0), _width(0), _height(0), _bpp(4) {}
+ LucasBitMap(char *data, uint32_t width, uint32_t height, uint32_t bpp = 4, bool copy = true);
+ void MakeNewData() {
+ printf("Size: %d Bpp: %d Width: %d Height: %d\n", size(), _bpp, _width, _height);
+ _data = new char[size()];
+
}
void BGR2RGB();
void MoreBits();
void LessBits();
- void WriteBMP(const char* name);
+ void WriteBMP(const char *name);
};
-void LucasBitMap::LessBits(){
+void LucasBitMap::LessBits() {
printf("Not implemented\n");
}
-void LucasBitMap::MoreBits(){
- if(_bpp==2){
- char* newData = new char[_width*_height*4];
- char* to = newData;
- char red=0,green=0,blue=0;
- for(unsigned int i=0;i<_height;i++){
- for(unsigned int j=0;j<_width;j++){
- char byte2 = _data[i*_width*_bpp+j*2];
- char byte1 = _data[i*_width*_bpp+j*2+1];
- // Probably Alpha, then 555.
- // Red
+void LucasBitMap::MoreBits() {
+ if (_bpp == 2) {
+ char *newData = new char[_width * _height * 4];
+ char *to = newData;
+ char red = 0, green = 0, blue = 0;
+ for (unsigned int i = 0; i < _height; i++) {
+ for (unsigned int j = 0; j < _width; j++) {
+ char byte2 = _data[i * _width * _bpp + j * 2];
+ char byte1 = _data[i * _width * _bpp + j * 2 + 1];
+ // Probably Alpha, then 555.
+ // Red
red = (byte1 >> 2) & 31;
red = red << 3 | red >> 2;
- // Green
+ // Green
char green1 = (byte1 & 3);
char green2 = (((byte2) >> 5) & 7);
char green3 = green1 << 3 | green2;
green = green3 << 3 | green3 >> 2 ;
- // Blue
+ // Blue
blue = (byte2) & 31;
blue = blue << 3 | blue >> 2;
- // Some more magic to stretch the values
+ // Some more magic to stretch the values
*to = red;
to++;
*to = green;
@@ -131,30 +135,31 @@ void LucasBitMap::MoreBits(){
}
}
-LucasBitMap::LucasBitMap(char* data, uint32_t width, uint32_t height,uint32_t bpp, bool copy) : _data(data), _width(width), _height(height), _bpp(bpp){
- if(data == 0)
+LucasBitMap::LucasBitMap(char *data, uint32_t width, uint32_t height, uint32_t bpp, bool copy) : _data(data), _width(width), _height(height), _bpp(bpp) {
+ if (data == 0) {
MakeNewData();
- else if(copy){
+ } else if (copy) {
MakeNewData();
memcpy(_data, data, size());
}
}
-void LucasBitMap::WriteBMP(const char* name){
+void LucasBitMap::WriteBMP(const char *name) {
std::fstream file(name, std::fstream::out | std::fstream::binary);
BMPHeader header;
unsigned short bm = TO_LE_16(19778);
- file.write((char*)&bm, 2);
+ file.write((char *)&bm, 2);
header.size = TO_LE_32(size() + 54);
header.reserved = TO_LE_32(0);
header.width = TO_LE_32(_width);
header.height = TO_LE_32(_height);
header.offset = TO_LE_32(54);
header.headerSize = TO_LE_32(40);
-if(_bpp == 4)
- header.nplanesbpp = TO_LE_32(2097153);
-else if(_bpp == 2)
- header.nplanesbpp = TO_LE_32(1048577);
+ if (_bpp == 4) {
+ header.nplanesbpp = TO_LE_32(2097153);
+ } else if (_bpp == 2) {
+ header.nplanesbpp = TO_LE_32(1048577);
+ }
header.compress_type = TO_LE_32(0);
header.bmp_bytesz = TO_LE_32(0);
header.hres = TO_LE_32(2835);
@@ -166,80 +171,81 @@ else if(_bpp == 2)
file.close();
}
-void LucasBitMap::BGR2RGB(){
- if(_bpp == 4){
+void LucasBitMap::BGR2RGB() {
+ if (_bpp == 4) {
uint32_t end = size();
- for(uint32_t i = 0; i < end; i += 4){
+ for (uint32_t i = 0; i < end; i += 4) {
char temp = _data[i + 2];
_data[i + 2] = _data[i];
_data[i] = temp;
}
- }else if(_bpp==2){
- MoreBits();
+ } else if (_bpp == 2) {
+ MoreBits();
}
}
-char* GetLine(int lineNum, LucasBitMap* bit){
+char *GetLine(int lineNum, LucasBitMap *bit) {
int bpp = bit->_bpp;
- return bit->_data + (lineNum*(bit->_width * bpp));
+ return bit->_data + (lineNum * (bit->_width * bpp));
}
-char* GetLine(int lineNum, char* data, unsigned int width,int bpp){
+char *GetLine(int lineNum, char *data, unsigned int width, int bpp) {
return data + (lineNum * (width * bpp));
}
// Expects 5 LucasBitmaps, and returns a LucasBitmap untiled.
-LucasBitMap* MakeFullPicture(LucasBitMap** bits){
- LucasBitMap* fullImage = new LucasBitMap(0, 640, 480, bits[0]->_bpp);
-
+LucasBitMap *MakeFullPicture(LucasBitMap **bits) {
+ LucasBitMap *fullImage = new LucasBitMap(0, 640, 480, bits[0]->_bpp);
+
const int tWidth = 256 * bits[0]->_bpp; // All of them should have the same bpp. (32)
int bpp = bits[0]->_bpp;
-
- char* target = fullImage->_data;
- for(int i = 0;i < 256;i++){
+
+ char *target = fullImage->_data;
+ for (int i = 0; i < 256; i++) {
/* This can be modified to actually use the last 32 lines.
- * We simply put the lower half on line 223 and down to line 32,
+ * We simply put the lower half on line 223 and down to line 32,
* then skip the last 32.
* While the upper half is put on line 479 and down to line 224.
*/
- if(i < 224){ // Skip blank space
- target = GetLine(223 - i,fullImage);
-
+ if (i < 224) { // Skip blank space
+ target = GetLine(223 - i, fullImage);
+
memcpy(target, GetLine(i, bits[3]), tWidth);
target += bits[3]->_width * bpp;
-
+
memcpy(target, GetLine(i, bits[4]), tWidth);
target += bits[4]->_width * bpp;
-
- memcpy(target,GetLine(i,bits[2])+128*bpp,128*bpp);
+
+ memcpy(target, GetLine(i, bits[2]) + 128 * bpp, 128 * bpp);
target += bpp * bits[2]->_width / 2;
}
-
+
// Top half of course
-
- target = GetLine(479-i, fullImage);
-
+
+ target = GetLine(479 - i, fullImage);
+
memcpy(target, GetLine(i, bits[0]), tWidth);
target += bits[0]->_width * bpp;
-
+
memcpy(target, GetLine(i, bits[1]), tWidth);
target += bits[1]->_width * bpp;
-
- memcpy(target,GetLine(i, bits[2]), 128 * bpp);
+
+ memcpy(target, GetLine(i, bits[2]), 128 * bpp);
target += bpp * bits[2]->_width / 2;
-
+
}
fullImage->BGR2RGB();
-
+
return fullImage;
}
-void ProcessFile(const char *_data, uint32_t size, std::string name){
+void ProcessFile(const char *_data, uint32_t size, std::string name) {
std::stringstream til;
uint32_t outsize = 0, bpp = 4;
Bytef *data = decompress((Bytef *)_data, size, outsize);
- if(!data)
+ if (!data) {
return;
+ }
til.write((const char *)data, outsize);
delete[] data;
uint32_t id, bmoffset, rects, b, c, numImages;
@@ -256,43 +262,43 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
c = FROM_LE_32(c);
// We want to actually read numImages and bpp
- til.seekg(bmoffset + 16,std::ios::beg);
- til.read((char*)&numImages, 4);
+ til.seekg(bmoffset + 16, std::ios::beg);
+ til.read((char *)&numImages, 4);
numImages = FROM_LE_32(numImages);
- if(numImages < 5){
+ if (numImages < 5) {
printf("This tile has less than 5 tiles, I don't know how to parse it\n");
}
- til.seekg(16,std::ios::cur);
- til.read((char*) &bpp, 4);
+ til.seekg(16, std::ios::cur);
+ til.read((char *) &bpp, 4);
bpp = FROM_LE_32(bpp);
bpp = bpp / 8;
- printf("Detected %d bpp\n",bpp*8);
+ printf("Detected %d bpp\n", bpp * 8);
til.seekg(bmoffset + 128, std::ios::beg);
uint32_t width = 0, height = 0;
-
+
LucasBitMap **allTheData = new LucasBitMap*[5];
-
+
for (uint32_t i = 0; i < 5; ++i) {
til.read((char *)&width, 4);
width = FROM_LE_32(width);
til.read((char *)&height, 4);
height = FROM_LE_32(height);
- uint32_t dataSize = width*height*bpp;
+ uint32_t dataSize = width * height * bpp;
char *imageData = new char[dataSize];
char *outnamet = new char[64];
- sprintf(outnamet,"%d.bmp",i);
+ sprintf(outnamet, "%d.bmp", i);
til.read(imageData, dataSize);
-
- allTheData[i] = new LucasBitMap(imageData, width, height,bpp,false);
+
+ allTheData[i] = new LucasBitMap(imageData, width, height, bpp, false);
}
- LucasBitMap* bit = MakeFullPicture(allTheData);
+ LucasBitMap *bit = MakeFullPicture(allTheData);
bit->WriteBMP(name.c_str());
-
+
for (uint32_t i = 0; i < 5; ++i) {
delete allTheData[i];
}
@@ -302,21 +308,21 @@ void ProcessFile(const char *_data, uint32_t size, std::string name){
}
-Bytef *decompress(Bytef *in, int size, uint32_t &outsize){
+Bytef *decompress(Bytef *in, int size, uint32_t &outsize) {
const uint32_t block = 8 * 1024 * 1024;
Bytef *dest = new Bytef[block]; // 8 MiB ought to be enough.
-
+
int success = 0;
z_stream_s zStream;
-
+
zStream.next_in = Z_NULL;
zStream.avail_in = 0;
zStream.zalloc = Z_NULL;
zStream.zfree = Z_NULL;
zStream.opaque = Z_NULL;
-
- success = inflateInit2(&zStream, 16+MAX_WBITS);
- if(success != Z_OK){
+
+ success = inflateInit2(&zStream, 16 + MAX_WBITS);
+ if (success != Z_OK) {
std::cout << "ZLIB failed to initialize\n";
return 0;
}
@@ -324,50 +330,50 @@ Bytef *decompress(Bytef *in, int size, uint32_t &outsize){
zStream.next_in = in;
zStream.avail_out = block;
zStream.next_out = dest;
-
+
success = inflate(&zStream, Z_NO_FLUSH);
-
+
outsize = zStream.total_out;
-
- if(success != Z_STREAM_END) {
+
+ if (success != Z_STREAM_END) {
std::cout << "ERROR: decompressed size bigger than 8 MiB\n";
return 0;
}
return dest;
}
-int main(int argc, char **argv){
+int main(int argc, char **argv) {
if (argc < 2) {
std::cout << "No Argument" << std::endl;
std::cout << "Usage: til2bmp [labfilename] <filename>" << std::endl;
return 0;
}
-
+
Lab *lab = NULL;
std::string filename;
int length = 0;
-
+
if (argc > 2) {
lab = new Lab(argv[1]);
filename = argv[2];
} else {
filename = argv[1];
}
-
+
std::istream *file = getFile(filename, lab, length);
-
+
if (!file) {
std::cout << "Could not open file" << std::endl;
return 0;
}
-
+
std::string outname = filename;
outname += ".bmp";
-
+
char *data = new char[length];
file->read(data, length);
delete file;
ProcessFile(data, length, outname);
-
+
delete[] data;
}
diff --git a/tools/imc2wav.cpp b/tools/imc2wav.cpp
index 34505377f..bfa04c9f4 100644
--- a/tools/imc2wav.cpp
+++ b/tools/imc2wav.cpp
@@ -42,11 +42,11 @@ void write_le_uint16(unsigned short val) {
int main() {
char block[1024];
- fread(block, 8, 1, stdin); // skip iMUS header
- fread(block, 8, 1, stdin); // read MAP header
+ fread(block, 8, 1, stdin); // skip iMUS header
+ fread(block, 8, 1, stdin); // read MAP header
int mapSize = get_be_uint32(block + 4);
int numBits = 16, rate = 22050, channels = 2;
- for (int mapPos = 0; mapPos < mapSize; ) {
+ for (int mapPos = 0; mapPos < mapSize;) {
fread(block, 8, 1, stdin);
int blockSize = get_be_uint32(block + 4);
if (memcmp(block, "FRMT", 4) == 0) {
@@ -54,8 +54,9 @@ int main() {
numBits = get_be_uint32(block + 8);
rate = get_be_uint32(block + 12);
channels = get_be_uint32(block + 16);
- } else
+ } else {
fread(block, blockSize, 1, stdin);
+ }
mapPos += (blockSize + 8);
}
fread(block, 8, 1, stdin);
diff --git a/tools/int2flt.cpp b/tools/int2flt.cpp
index e196bc0ca..12bcc9bad 100644
--- a/tools/int2flt.cpp
+++ b/tools/int2flt.cpp
@@ -24,8 +24,8 @@
#include <stdlib.h>
int main(int argc, char *argv[]) {
- unsigned i = atoi(argv[1]);
- float *f = (float *)&i;
- printf("%g\n", *f);
- return 0;
+ unsigned i = atoi(argv[1]);
+ float *f = (float *)&i;
+ printf("%g\n", *f);
+ return 0;
}
diff --git a/tools/lab.cpp b/tools/lab.cpp
index 147df3122..cb7886e5c 100644
--- a/tools/lab.cpp
+++ b/tools/lab.cpp
@@ -46,7 +46,7 @@ void Lab::Load(std::string filename) {
std::cout << "Can not open source file: " << filename << std::endl;
exit(1);
}
-
+
fread(&head.magic, 1, 4, infile);
fread(&head.magic2, 1, 4, infile);
uint32 num, s_size, s_offset;
@@ -69,7 +69,7 @@ void Lab::Load(std::string filename) {
std::cout << "There is no LABN header in source lab-file\n";
exit(1);
}
-
+
entries = new lab_entry[head.num_entries];
str_table = new char[head.string_table_size];
if (!str_table || !entries) {
@@ -77,12 +77,12 @@ void Lab::Load(std::string filename) {
exit(1);
}
// Grim-stuff
- if(g_type == GT_GRIM) {
+ if (g_type == GT_GRIM) {
fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
-
+
fread(str_table, 1, head.string_table_size, infile);
-
- } else if(g_type == GT_EMI) { // EMI-stuff
+
+ } else if (g_type == GT_EMI) { // EMI-stuff
// EMI has a string-table-offset
head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
// Find the string-table
@@ -90,12 +90,13 @@ void Lab::Load(std::string filename) {
// Read the entire string table into str-table
fread(str_table, 1, head.string_table_size, infile);
fseek(infile, 20, SEEK_SET);
-
+
// Decrypt the string table
uint32 j;
for (j = 0; j < head.string_table_size; j++)
- if (str_table[j] != 0)
+ if (str_table[j] != 0) {
str_table[j] ^= 0x96;
+ }
fread(entries, 1, head.num_entries * sizeof(lab_entry), infile);
}
}
@@ -104,17 +105,16 @@ int Lab::getIndex(std::string filename) {
for (i = 0; i < head.num_entries; i++) {
const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
std::string test = std::string(fname);
- if (test != filename)
+ if (test != filename) {
continue;
- else
- {
+ } else {
return i;
}
}
return -1;
}
-std::istream* Lab::getFile(std::string filename) {
+std::istream *Lab::getFile(std::string filename) {
if (!buf) {
printf("Could not allocate memory\n");
exit(1);
@@ -140,25 +140,26 @@ std::istream* Lab::getFile(std::string filename) {
stream->seekg(offset, std::ios::beg);
return stream;
}
-
+
return NULL;
}
int Lab::getLength(std::string filename) {
int index = getIndex(filename);
- if (index == -1)
+ if (index == -1) {
return 0;
+ }
return entries[i].size;
}
-std::istream *getFile(std::string filename, Lab* lab) {
+std::istream *getFile(std::string filename, Lab *lab) {
std::istream *stream;
if (lab) {
return lab->getFile(filename);
} else {
stream = new std::fstream(filename.c_str(), std::ios::in | std::ios::binary);
-
- if (!((std::fstream*)stream)->is_open()) {
+
+ if (!((std::fstream *)stream)->is_open()) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
@@ -166,15 +167,15 @@ std::istream *getFile(std::string filename, Lab* lab) {
}
}
-std::istream *getFile(std::string filename, Lab* lab, int& length) {
+std::istream *getFile(std::string filename, Lab *lab, int &length) {
std::istream *stream;
if (lab) {
length = lab->getLength(filename);
return lab->getFile(filename);
} else {
stream = new std::fstream(filename.c_str(), std::ios::in | std::ios::binary);
-
- if (!((std::fstream*)stream)->is_open()) {
+
+ if (!((std::fstream *)stream)->is_open()) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
diff --git a/tools/lab.h b/tools/lab.h
index d99f94a19..6b343ca5c 100644
--- a/tools/lab.h
+++ b/tools/lab.h
@@ -60,7 +60,7 @@ class Lab {
public:
Lab(std::string filename) : _filename(filename) {
// allocate a 1mb buffer to start with
- bufSize = 1024*1024;
+ bufSize = 1024 * 1024;
buf = (char *)malloc(bufSize);
Load(filename);
}
@@ -75,7 +75,7 @@ public:
int getLength(std::string filename);
};
-std::istream *getFile(std::string filename, Lab* lab);
-std::istream *getFile(std::string filename, Lab* lab, int& length);
+std::istream *getFile(std::string filename, Lab *lab);
+std::istream *getFile(std::string filename, Lab *lab, int &length);
#endif
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
index edce77c39..7dc49b751 100644
--- a/tools/labcopy.cpp
+++ b/tools/labcopy.cpp
@@ -33,7 +33,7 @@
#include <cstring>
#include "common/endian.h"
-#define BUFFER_SIZE 0x100000
+#define BUFFER_SIZE 0x100000
FILE *inLab = NULL, *outLab = NULL;
void *buffer = NULL;
@@ -57,8 +57,9 @@ bool copyFile(uint32 offset, uint32 lenght) {
count = (uint32)fread(buffer, 1, bytesToRead, inLab);
fwrite(buffer, count, 1, outLab);
copied_bytes += count;
- if(ferror(inLab) != 0 || ferror(outLab) != 0)
+ if (ferror(inLab) != 0 || ferror(outLab) != 0) {
return false;
+ }
}
return true;
@@ -84,7 +85,7 @@ bool copyLab() {
//Read files entries
lab_entries = (lab_entry *)calloc(sizeof(lab_entry), num_entries);
fread(lab_entries, 1, num_entries * sizeof(struct lab_entry), inLab);
-
+
//Read string table
string_table = (char *)malloc(string_table_size);
fread(string_table, 1, string_table_size, inLab);
@@ -95,7 +96,7 @@ bool copyLab() {
fwrite(string_table, string_table_size, 1, outLab);
//Check for errors
- if(ferror(inLab) != 0 || ferror(outLab) != 0) {
+ if (ferror(inLab) != 0 || ferror(outLab) != 0) {
free(lab_entries);
free(string_table);
return false;
@@ -103,7 +104,7 @@ bool copyLab() {
//Copy the files, except cp_0_intha.bm
for (uint32 i = 0; i < num_entries; i++)
- if(strcmp(string_table + READ_LE_UINT32(&lab_entries[i].fname_offset), "cp_0_intha.bm") != 0)
+ if (strcmp(string_table + READ_LE_UINT32(&lab_entries[i].fname_offset), "cp_0_intha.bm") != 0)
if (!copyFile(lab_entries[i].start, lab_entries[i].size)) {
free(lab_entries);
free(string_table);
@@ -116,26 +117,29 @@ bool copyLab() {
}
void cleanup() {
- if (inLab)
+ if (inLab) {
fclose(inLab);
+ }
- if (outLab)
+ if (outLab) {
fclose(outLab);
+ }
- if (buffer)
+ if (buffer) {
free(buffer);
+ }
}
int main(int argc, char *argv[]) {
atexit(cleanup);
-
+
//Argument checks and usage display
if (argc != 3) {
printf("Usage: labcopy original.lab destination.lab\n");
printf("Copy original.lab from Grimfandango cd with illegal-toc protection.\n");
return 1;
}
-
+
//Files opening
inLab = fopen(argv[1], "rb");
if (!inLab) {
diff --git a/tools/mat2ppm.cpp b/tools/mat2ppm.cpp
index 291633085..094986ff3 100644
--- a/tools/mat2ppm.cpp
+++ b/tools/mat2ppm.cpp
@@ -49,7 +49,9 @@ void read_cmp(const char *fname) {
}
fseek(cmp, 48, SEEK_SET);
for (i = 0; i < 256; i++) {
- col[0] = getc(cmp); col[1] = getc(cmp); col[2] = getc(cmp);
+ col[0] = getc(cmp);
+ col[1] = getc(cmp);
+ col[2] = getc(cmp);
PPM_ASSIGN(cmap[i], col[0], col[1], col[2]);
}
fclose(cmp);
@@ -75,26 +77,28 @@ void write_img(FILE *f, const char *fname, int n, int num_img) {
img[y][x] = cmap[p];
}
- basename = strrchr(fname, '/');
- if (basename != NULL)
- basename++;
- else
- basename = fname;
- strcpy(newname, basename);
- if (strlen(newname) > 4 &&
- strcasecmp(newname + strlen(newname) - 4, ".mat") == 0)
- newname[strlen(newname) - 4] = '\0';
- sprintf(newname + strlen(newname), "_%d.ppm", n);
-
- out = fopen(newname, "wb");
- if (out == NULL) {
- perror(newname);
- exit(1);
- }
+ basename = strrchr(fname, '/');
+ if (basename != NULL) {
+ basename++;
+ } else {
+ basename = fname;
+ }
+ strcpy(newname, basename);
+ if (strlen(newname) > 4 &&
+ strcasecmp(newname + strlen(newname) - 4, ".mat") == 0) {
+ newname[strlen(newname) - 4] = '\0';
+ }
+ sprintf(newname + strlen(newname), "_%d.ppm", n);
+
+ out = fopen(newname, "wb");
+ if (out == NULL) {
+ perror(newname);
+ exit(1);
+ }
- ppm_writeppm(out, img, width, height, 255, 0);
- ppm_freearray(img, height);
- fclose(out);
+ ppm_writeppm(out, img, width, height, 255, 0);
+ ppm_freearray(img, height);
+ fclose(out);
}
void process_file(const char *fname) {
@@ -109,8 +113,9 @@ void process_file(const char *fname) {
}
fseek(in, 12, SEEK_SET);
num_img = read_LEint32(in);
- for (i = 0; i < num_img; i++)
+ for (i = 0; i < num_img; i++) {
write_img(in, fname, i, num_img);
+ }
fclose(in);
}
@@ -118,16 +123,18 @@ int main(int argc, char **argv) {
int i;
ppm_init(&argc, argv);
- for (i = 0; i < 256; i++)
+ for (i = 0; i < 256; i++) {
PPM_ASSIGN(cmap[i], i, i, i);
+ }
i = 1;
if (argc >= 3 && strncmp(argv[1], "-c", 2) == 0) {
read_cmp(argv[2]);
i = 3;
}
- for (; i < argc; i++)
+ for (; i < argc; i++) {
process_file(argv[i]);
+ }
return 0;
}
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index 61cc76ee4..b772fec90 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -102,8 +102,9 @@ static char *appendPath(const char *name, const char *dir) {
static void countFiles(lab_header *head, DIR *dir, const char *dirname, int additionalLen) {
struct dirent *dirfile;
while ((dirfile = readdir(dir))) {
- if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
+ if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, "..")) {
continue;
+ }
if (dirfile->d_type == S_IFDIR) {
char *d = appendPath(dirfile->d_name, dirname);
@@ -124,8 +125,9 @@ static void createEntries(DIR *dir, lab_entry *entries, char *str_table, const c
static char *str_offset = str_table;
struct dirent *dirfile;
while ((dirfile = readdir(dir))) {
- if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, ".."))
+ if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, "..")) {
continue;
+ }
if (dirfile->d_type == S_IFDIR) {
char *d = appendPath(dirfile->d_name, dirname);
@@ -150,7 +152,7 @@ static void createEntries(DIR *dir, lab_entry *entries, char *str_table, const c
struct stat st;
stat(path, &st);
- // printf("entry of file %s, at offset %d and of size %d\n", path, offset, st.st_size);
+ // printf("entry of file %s, at offset %d and of size %d\n", path, offset, st.st_size);
free(path);
offset += st.st_size;
@@ -196,7 +198,7 @@ int main(int argc, char **argv) {
countFiles(&head, dir, dirname, 0);
-// printf("%d files, string table of size %d\n", head.num_entries, head.string_table_size);
+// printf("%d files, string table of size %d\n", head.num_entries, head.string_table_size);
lab_entry *entries = (lab_entry *)malloc(head.num_entries * sizeof(lab_entry));
char *str_table = (char *)malloc(head.string_table_size);
@@ -239,14 +241,15 @@ int main(int argc, char **argv) {
char *s = (char *)malloc(head.string_table_size);
memset(s, 0, head.string_table_size);
for (uint32_t j = 0; j < head.string_table_size; j++) {
- if (str_table[j] != 0)
+ if (str_table[j] != 0) {
s[j] = str_table[j] ^ 0x96;
+ }
}
fwrite(s, 1, head.string_table_size, outfile);
free(s);
}
- uint32_t bufsize = 1024*1024;
+ uint32_t bufsize = 1024 * 1024;
char *buf = (char *)malloc(bufsize);
for (uint32_t i = 0; i < head.num_entries; ++i) {
@@ -272,7 +275,7 @@ int main(int argc, char **argv) {
buf = newbuf;
}
-// printf("writing file %s, at offset %d and of size %d\n", fname, offset, size);
+// printf("writing file %s, at offset %d and of size %d\n", fname, offset, size);
fread(buf, 1, size, file);
fseek(outfile, offset, SEEK_SET);
diff --git a/tools/patchr.cpp b/tools/patchr.cpp
index 072461d93..b9486bb81 100644
--- a/tools/patchr.cpp
+++ b/tools/patchr.cpp
@@ -26,7 +26,7 @@
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted providing that the following conditions
+ * modification, are permitted providing 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.
@@ -75,8 +75,9 @@ void free_memory() {
void show_header_info(uint8 *header) {
printf("PatchR v%d.%d\n", READ_LE_UINT16(header + 4), READ_LE_UINT16(header + 6));
printf("Md5: ");
- for (int i = 0; i < 16; ++i)
+ for (int i = 0; i < 16; ++i) {
printf("%x", *(header + 12 + i));
+ }
printf("\n");
uint32 flags = READ_LE_UINT32(header + 8);
@@ -109,7 +110,7 @@ arguments parse_args(int argc, char *argv[]) {
arg.show_info = false;
int c;
- while ((c = getopt (argc, argv, "a")) != -1)
+ while ((c = getopt(argc, argv, "a")) != -1)
switch (c) {
case 'a':
arg.show_info = true;
@@ -118,7 +119,7 @@ arguments parse_args(int argc, char *argv[]) {
show_usage(argv[0]);
exit(0);
default:
- fprintf (stderr, "Internal error\n");
+ fprintf(stderr, "Internal error\n");
exit(1);
}
@@ -134,7 +135,7 @@ arguments parse_args(int argc, char *argv[]) {
return arg;
}
-int main(int argc,char * argv[]) {
+int main(int argc, char *argv[]) {
uint32 oldsize, newsize;
uint32 zctrllen, zdatalen, zextralen;
uint8 header[48], buf[4];
@@ -177,14 +178,14 @@ int main(int argc,char * argv[]) {
}
/* Read header */
- patch.read((char*)header, 48);
+ patch.read((char *)header, 48);
if (patch.eof() || patch.bad() || patch.fail()) {
std::cerr << "Corrupt patch\n";
return 1;
}
/* Check for appropriate signature */
- if (READ_BE_UINT32(header) != MKTAG('P','A','T','R')) {
+ if (READ_BE_UINT32(header) != MKTAG('P', 'A', 'T', 'R')) {
std::cerr << "Corrupt patch\n";
return 1;
}
@@ -214,20 +215,23 @@ int main(int argc,char * argv[]) {
zextralen = READ_LE_UINT32(header + 44);
patch.close();
- if (args.show_info)
+ if (args.show_info) {
show_header_info(header);
+ }
// Open the compressed sub-streams
//Check if the ctrl is compressed
ctrlStream.seekg(48, std::ios::beg);
- if (comp_ctrl)
+ if (comp_ctrl) {
ctrlDec = new GZipReadStream(&ctrlStream, 48, zctrllen);
+ }
diffDec = new GZipReadStream(&diffStream, 48 + zctrllen, zdatalen);
- if (mix)
+ if (mix) {
extraDec = diffDec;
- else
+ } else {
extraDec = new GZipReadStream(&extraStream, 48 + zctrllen + zdatalen, zextralen);
+ }
old_block = new uint8[oldsize];
new_block = new byte[newsize];
@@ -235,25 +239,25 @@ int main(int argc,char * argv[]) {
std::cerr << "Not enough memory\n";
return 1;
}
-
+
//Read the oldfile
oldfile.seekg(0, std::ios::beg);
- oldfile.read((char*)old_block, oldsize);
+ oldfile.read((char *)old_block, oldsize);
oldfile.close();
if (oldfile.bad() || oldfile.fail()) {
std::cerr << "Input error\n";
return 1;
}
- oldpos=0;
- newpos=0;
- while(newpos < newsize) {
+ oldpos = 0;
+ newpos = 0;
+ while (newpos < newsize) {
/* Read control data */
for (uint i = 0; i < 3; i++) {
- if (comp_ctrl)
+ if (comp_ctrl) {
lenread = ctrlDec->read(buf, 4);
- else {
- ctrlStream.read((char*)buf, 4);
+ } else {
+ ctrlStream.read((char *)buf, 4);
lenread = ctrlStream.gcount();
}
if (lenread < 4) {
@@ -289,8 +293,9 @@ int main(int argc,char * argv[]) {
printf("\n");
} else {
uint pos = i;
- while (i < ctrl[0] && *(new_block + newpos + i) == 0)
+ while (i < ctrl[0] && *(new_block + newpos + i) == 0) {
++i;
+ }
printf("COPY %d\n", i - pos);
}
}
@@ -298,8 +303,9 @@ int main(int argc,char * argv[]) {
/* Add old data to diff string */
for (uint i = 0; i < ctrl[0]; i++)
- if ((oldpos + i >= 0) && (oldpos + i < oldsize))
+ if ((oldpos + i >= 0) && (oldpos + i < oldsize)) {
new_block[newpos + i] ^= old_block[oldpos + i];
+ }
/* Adjust pointers */
newpos += ctrl[0];
@@ -322,13 +328,15 @@ int main(int argc,char * argv[]) {
if (args.show_info) {
if (ctrl[1] > 0) {
printf("INSERT");
- for (uint i = 0; i < ctrl[1]; i++)
+ for (uint i = 0; i < ctrl[1]; i++) {
printf(" %02x", *(new_block + newpos + i));
+ }
printf("\n");
}
- if (ctrl[2] != 0)
+ if (ctrl[2] != 0) {
printf("JUMP %d\n", ctrl[2]);
+ }
}
/* Adjust pointers */
@@ -348,7 +356,7 @@ int main(int argc,char * argv[]) {
return 1;
}
- newfile.write((char*)new_block, newsize);
+ newfile.write((char *)new_block, newsize);
if (patch.bad()) {
std::cerr << "Output error.\n";
return 1;
diff --git a/tools/set2fig.cpp b/tools/set2fig.cpp
index 163e01e85..21c6a4dcd 100644
--- a/tools/set2fig.cpp
+++ b/tools/set2fig.cpp
@@ -33,14 +33,14 @@ int main(int argc, char *argv[]) {
exit(1);
}
printf("#FIG 3.2\n"
- "Landscape\n"
- "Center\n"
- "Metric\n"
- "A4\n"
- "100.00\n"
- "Single\n"
- "-2\n"
- "1200 2\n");
+ "Landscape\n"
+ "Center\n"
+ "Metric\n"
+ "A4\n"
+ "100.00\n"
+ "Single\n"
+ "-2\n"
+ "1200 2\n");
FILE *in = fopen(argv[1], "r");
if (in == NULL) {
@@ -60,29 +60,32 @@ int main(int argc, char *argv[]) {
int id;
fscanf(in, " ID %d", &id);
- if (numSectors < 0)
+ if (numSectors < 0) {
numSectors = id + 1;
+ }
char buf[256];
int color = 0;
fscanf(in, " type %256s", buf);
- if (strcmp(buf, "walk") == 0)
+ if (strcmp(buf, "walk") == 0) {
color = 0;
- else if (strcmp(buf, "funnel") == 0)
+ } else if (strcmp(buf, "funnel") == 0) {
color = 0;
- else if (strcmp(buf, "camera") == 0)
+ } else if (strcmp(buf, "camera") == 0) {
color = 1;
- else if (strcmp(buf, "special") == 0)
+ } else if (strcmp(buf, "special") == 0) {
color = 5;
- else if (strcmp(buf, "chernobyl") == 0)
+ } else if (strcmp(buf, "chernobyl") == 0) {
color = 4;
+ }
int linetype = 0;
fscanf(in, " default visibility %256s", buf);
- if (strcmp(buf, "visible") == 0)
+ if (strcmp(buf, "visible") == 0) {
linetype = 0;
- else if (strcmp(buf, "invisible") == 0)
+ } else if (strcmp(buf, "invisible") == 0) {
linetype = 1;
+ }
float dummy;
fscanf(in, " height %f", &dummy);
@@ -95,7 +98,7 @@ int main(int argc, char *argv[]) {
float vertices[300];
fscanf(in, " vertices:");
for (int i = 0; i < numVertices; i++) {
- fscanf(in, " %f %f %f", vertices + 3*i, vertices + (3 * i + 1), vertices + (3 * i + 2));
+ fscanf(in, " %f %f %f", vertices + 3 * i, vertices + (3 * i + 1), vertices + (3 * i + 2));
printf(" %d %d", (int) round(vertices[3 * i] * 1000), -(int)round(vertices[3 * i + 1] * 1000));
}
printf(" %d %d\n", (int) round(vertices[0] * 1000), -(int)round(vertices[1] * 1000));
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 9e653f892..17fb91cd9 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -122,11 +122,11 @@ int main(int argc, char **argv) {
exit(1);
}
// Grim-stuff
- if(g_type == GT_GRIM) {
+ if (g_type == GT_GRIM) {
fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
fread(str_table, 1, head.string_table_size, infile);
- } else if(g_type == GT_EMI) { // EMI-stuff
+ } else if (g_type == GT_EMI) { // EMI-stuff
// EMI has a string-table-offset
head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
// Find the string-table
@@ -138,13 +138,14 @@ int main(int argc, char **argv) {
// Decrypt the string table
uint32_t j;
for (j = 0; j < head.string_table_size; j++)
- if (str_table[j] != 0)
+ if (str_table[j] != 0) {
str_table[j] ^= 0x96;
+ }
fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
}
// allocate a 1mb buffer to start with
- uint32_t bufSize = 1024*1024;
+ uint32_t bufSize = 1024 * 1024;
char *buf = (char *)malloc(bufSize);
if (!buf) {
printf("Could not allocate memory\n");
diff --git a/tools/vima.cpp b/tools/vima.cpp
index 1120c6943..117963635 100644
--- a/tools/vima.cpp
+++ b/tools/vima.cpp
@@ -172,10 +172,11 @@ void decompressVima(byte *src, int16 *dest, int destLen, uint16 *destTable) {
bitPtr -= 8;
}
- if (val & highBit)
+ if (val & highBit) {
val ^= highBit;
- else
+ } else {
highBit = 0;
+ }
if (val == lowBits) {
outputWord = ((int16)(bits << bitPtr) & 0xffffff00);
@@ -186,16 +187,19 @@ void decompressVima(byte *src, int16 *dest, int destLen, uint16 *destTable) {
int index = (val << (7 - numBits)) | (currTablePos << 6);
int delta = destTable[index];
- if (val)
+ if (val) {
delta += (imcTable1[currTablePos] >> (numBits - 1));
- if (highBit)
+ }
+ if (highBit) {
delta = -delta;
+ }
outputWord += delta;
- if (outputWord < -0x8000)
+ if (outputWord < -0x8000) {
outputWord = -0x8000;
- else if (outputWord > 0x7fff)
+ } else if (outputWord > 0x7fff) {
outputWord = 0x7fff;
+ }
}
byte *b = (byte *)destPos;
@@ -205,10 +209,11 @@ void decompressVima(byte *src, int16 *dest, int destLen, uint16 *destTable) {
currTablePos += offsets[numBits - 2][val];
- if (currTablePos < 0)
+ if (currTablePos < 0) {
currTablePos = 0;
- else if (currTablePos > 88)
+ } else if (currTablePos > 88) {
currTablePos = 88;
+ }
}
}
}
@@ -247,9 +252,9 @@ int main(int /* argc */, char *argv[]) {
sourceBuffer = new byte[compSize];
fread(sourceBuffer, 1, compSize, f);
- if (strcmp(codecs + 5 * codec, "NULL") == 0)
+ if (strcmp(codecs + 5 * codec, "NULL") == 0) {
fwrite(sourceBuffer, 1, uncompSize, stdout);
- else if (strcmp(codecs + 5 * codec, "VIMA") == 0) {
+ } else if (strcmp(codecs + 5 * codec, "VIMA") == 0) {
char *buffer = new char[uncompSize];
decompressVima(sourceBuffer, (int16 *)buffer, uncompSize, destTable);
fwrite(buffer, 1, uncompSize, stdout);
Commit: 110ac1b796fd30007b2ddd3c0cadf90bd3a25a80
https://github.com/scummvm/scummvm-tools/commit/110ac1b796fd30007b2ddd3c0cadf90bd3a25a80
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2013-07-09T19:43:50+02:00
Commit Message:
TOOLS: Add destructor to SeekableReadStream.
Changed paths:
tools/emi/filetools.h
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index 113db1ff2..f51a7bcfa 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -147,6 +147,7 @@ Vector4d *readVector4d(std::istream &file) {
//TODO: Endianness
class SeekableReadStream {
public:
+ virtual ~SeekableReadStream() {}
virtual uint32 readUint32() = 0;
virtual void read(void *target, uint32 length) = 0;
virtual void seek(int offset, int whence = SEEK_SET) = 0;
@@ -158,7 +159,7 @@ class MemoryReadStream : public SeekableReadStream {
uint32 _length;
public:
MemoryReadStream(byte *data, uint32 length) : _data(data), _length(length), _pos(0) {}
- ~MemoryReadStream() {
+ virtual ~MemoryReadStream() {
delete[] _data;
}
Commit: a04e0753d028361ebbf91c43e913cd712aab6fc2
https://github.com/scummvm/scummvm-tools/commit/a04e0753d028361ebbf91c43e913cd712aab6fc2
Author: Einar Johan Trøan SømaÌen (einarjohants at gmail.com)
Date: 2013-07-09T19:50:00+02:00
Commit Message:
TOOLS: Fix warnings in cosb2cos
Changed paths:
tools/emi/cosb2cos.cpp
diff --git a/tools/emi/cosb2cos.cpp b/tools/emi/cosb2cos.cpp
index 3479a3756..09db31645 100644
--- a/tools/emi/cosb2cos.cpp
+++ b/tools/emi/cosb2cos.cpp
@@ -27,7 +27,7 @@
#include <vector>
#include "filetools.h"
-std::vector<std::string> g_tag;
+std::vector<std::string> *g_tag = 0;
std::string getTag(std::string str) {
if (str.at(0) != '!') {
@@ -43,12 +43,12 @@ std::string getCompName(std::string str) {
void pushtag(std::string tag) {
std::vector<std::string>::iterator it;
- for (it = g_tag.begin(); it != g_tag.end(); it++) {
+ for (it = g_tag->begin(); it != g_tag->end(); it++) {
if (*it == tag) {
return;
}
}
- g_tag.push_back(tag);
+ g_tag->push_back(tag);
}
struct TrackKey {
@@ -136,10 +136,10 @@ struct Costume {
void print() {
std::cout << "section: tags\n";
- std::cout << "\tnumtags " << g_tag.size() << std::endl;
- int i = 0;
- std::vector<std::string>::iterator it = g_tag.begin();
- for (; it != g_tag.end(); it++) {
+ std::cout << "\tnumtags " << g_tag->size() << std::endl;
+
+ std::vector<std::string>::iterator it = g_tag->begin();
+ for (int i = 0; it != g_tag->end(); it++) {
std::cout << i++ << "\t" << *it << std::endl;
}
std::cout << std::endl;
@@ -209,7 +209,7 @@ int main(int argc, char **argv) {
std::cout << "Unable to open file " << filename << std::endl;
return 0;
}
-
+ g_tag = new std::vector<std::string>;
Costume c;
c.readFromFile(file);
if (argc == 2) {
@@ -217,5 +217,5 @@ int main(int argc, char **argv) {
} else {
c.printChore(argv[2]);
}
-
+ delete g_tag;
}
Commit: e525a54509a2bb566b5725b1da5e57cd7a48efe1
https://github.com/scummvm/scummvm-tools/commit/e525a54509a2bb566b5725b1da5e57cd7a48efe1
Author: Dries Harnie (dries at harnie.be)
Date: 2013-07-09T22:20:02+02:00
Commit Message:
EMI: Show sortplanes for sectors (setb2set)
Changed paths:
tools/emi/setb2set.cpp
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index 7a2b7315b..dae5569bb 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -127,6 +127,8 @@ private:
float *vertices; // 3 * numVertices.
float normal[3];
bool visible;
+ int numSortPlanes;
+ int *sortPlanes;
};
Sector::Sector(Data *data) : Section(data) {
@@ -143,8 +145,10 @@ Sector::Sector(Data *data) : Section(data) {
ID = data->GetInt();
visible = data->GetBool();
type = (SectorType)data->GetInt();
- int skip = data->GetInt();
- data->Skip(skip * 4);
+ numSortPlanes = data->GetInt();
+ sortPlanes = new int[numSortPlanes];
+ for (int i = 0; i < numSortPlanes; ++i)
+ sortPlanes[i] = data->GetInt();
height = data->GetFloat();
float cross1[3], cross2[3];
@@ -205,6 +209,13 @@ string Sector::ToString() {
ss << endl;
ss << "\theight\t" << height << endl;
ss << "\tnumvertices\t" << numVertices << endl;
+ ss << "\tsortplanes\t" << numSortPlanes << "\t";
+ for (int i = 0; i < numSortPlanes; ++i) {
+ if (i != 0)
+ ss << ",";
+ ss << sortPlanes[i];
+ }
+ ss << endl;
ss << "\tnormal\t\t\t" << normal[0] << "\t" << normal[1] << "\t" << normal[2] << endl;
ss << "\tvertices:\t\t";
for (int i = 0; i < numVertices * 3; i += 3) {
Commit: b2a2f1531e793736280a635e5bee508ad206ebc9
https://github.com/scummvm/scummvm-tools/commit/b2a2f1531e793736280a635e5bee508ad206ebc9
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2013-07-11T21:17:39-07:00
Commit Message:
TOOLS: Use endian for lab
Changed paths:
tools/lab.cpp
tools/lab.h
diff --git a/tools/lab.cpp b/tools/lab.cpp
index cb7886e5c..f5b17e0a2 100644
--- a/tools/lab.cpp
+++ b/tools/lab.cpp
@@ -28,17 +28,7 @@
#include <fstream>
#include <string>
#include "lab.h"
-
-// TODO: Use common/endian for this
-uint16 READ_LE_UINT16(const void *ptr) {
- const uint8 *b = (const uint8 *)ptr;
- return (b[1] << 8) + b[0];
-}
-
-uint32 READ_LE_UINT32(const void *ptr) {
- const uint8 *b = (const uint8 *)ptr;
- return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
-}
+#include "common/endian.h"
void Lab::Load(std::string filename) {
infile = fopen(filename.c_str(), "rb");
diff --git a/tools/lab.h b/tools/lab.h
index 6b343ca5c..ea5c3fe48 100644
--- a/tools/lab.h
+++ b/tools/lab.h
@@ -23,7 +23,7 @@
#ifndef LAB_H
#define LAB_H
-#include "config.h"
+#include "common/endian.h"
#include <string>
#include <iostream>
Commit: e2d29b077a23fc3be2e6dac323e3e811094ee18e
https://github.com/scummvm/scummvm-tools/commit/e2d29b077a23fc3be2e6dac323e3e811094ee18e
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2013-07-12T22:26:54-07:00
Commit Message:
TOOLS: Make unlab use lab.cpp and improve the lab.cpp code
Changed paths:
tools/lab.cpp
tools/lab.h
tools/unlab.cpp
diff --git a/tools/lab.cpp b/tools/lab.cpp
index f5b17e0a2..5aeeb5b50 100644
--- a/tools/lab.cpp
+++ b/tools/lab.cpp
@@ -27,9 +27,22 @@
#include <iostream>
#include <fstream>
#include <string>
+#include <sstream>
#include "lab.h"
#include "common/endian.h"
+Lab::Lab(std::string filename) : _filename(filename) {
+ // allocate a 1mb buffer to start with
+ bufSize = 1024 * 1024;
+ buf = (char *)malloc(bufSize);
+ Load(filename);
+}
+Lab::~Lab() {
+ free(buf);
+ delete[] str_table;
+ delete[] entries;
+}
+
void Lab::Load(std::string filename) {
infile = fopen(filename.c_str(), "rb");
if (infile == 0) {
@@ -92,7 +105,7 @@ void Lab::Load(std::string filename) {
}
int Lab::getIndex(std::string filename) {
- for (i = 0; i < head.num_entries; i++) {
+ for (uint32 i = 0; i < head.num_entries; i++) {
const char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
std::string test = std::string(fname);
if (test != filename) {
@@ -104,6 +117,10 @@ int Lab::getIndex(std::string filename) {
return -1;
}
+std::string Lab::getFileName(int index) {
+ return str_table + READ_LE_UINT32(&entries[index].fname_offset);
+}
+
std::istream *Lab::getFile(std::string filename) {
if (!buf) {
printf("Could not allocate memory\n");
@@ -113,8 +130,8 @@ std::istream *Lab::getFile(std::string filename) {
if (index == -1) {
return NULL;
} else {
- offset = READ_LE_UINT32(&entries[i].start);
- uint32 size = READ_LE_UINT32(&entries[i].size);
+ offset = READ_LE_UINT32(&entries[index].start);
+ uint32 size = READ_LE_UINT32(&entries[index].size);
if (bufSize < size) {
bufSize = size;
char *newBuf = (char *)realloc(buf, bufSize);
@@ -125,10 +142,11 @@ std::istream *Lab::getFile(std::string filename) {
buf = newBuf;
}
}
- std::fstream *stream;
- stream = new std::fstream(_filename.c_str(), std::ios::in | std::ios::binary);
- stream->seekg(offset, std::ios::beg);
- return stream;
+ std::fstream stream(_filename.c_str(), std::ios::in | std::ios::binary);
+ stream.seekg(offset, std::ios::beg);
+ stream.read(buf, size);
+ std::istringstream *iss = new std::istringstream(std::string(buf, buf + size));
+ return iss;
}
return NULL;
@@ -139,7 +157,7 @@ int Lab::getLength(std::string filename) {
if (index == -1) {
return 0;
}
- return entries[i].size;
+ return entries[index].size;
}
std::istream *getFile(std::string filename, Lab *lab) {
diff --git a/tools/lab.h b/tools/lab.h
index ea5c3fe48..52599ae33 100644
--- a/tools/lab.h
+++ b/tools/lab.h
@@ -48,7 +48,6 @@ struct lab_entry {
class Lab {
std::string _filename;
uint8 g_type;
- uint32 i;
uint32 offset;
uint32 bufSize;
lab_header head;
@@ -58,18 +57,12 @@ class Lab {
FILE *infile;
void Load(std::string filename);
public:
- Lab(std::string filename) : _filename(filename) {
- // allocate a 1mb buffer to start with
- bufSize = 1024 * 1024;
- buf = (char *)malloc(bufSize);
- Load(filename);
- }
- ~Lab() {
- free(buf);
- delete[] str_table;
- delete[] entries;
- }
+ Lab(std::string filename);
+ ~Lab();
+ int getNumEntries() { return head.num_entries; }
+
+ std::string getFileName(int index);
std::istream *getFile(std::string filename);
int getIndex(std::string filename);
int getLength(std::string filename);
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 17fb91cd9..7253b5ade 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -24,6 +24,8 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
+#include <fstream>
+#include "lab.h"
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
@@ -33,162 +35,58 @@
#define GT_GRIM 1
#define GT_EMI 2
-struct lab_header {
- uint32_t magic;
- uint32_t magic2;
- uint32_t num_entries;
- uint32_t string_table_size;
- uint32_t string_table_offset;
-};
-
-struct lab_entry {
- uint32_t fname_offset;
- uint32_t start;
- uint32_t size;
- uint32_t reserved;
-};
-
-uint16_t READ_LE_UINT16(const void *ptr) {
- const uint8_t *b = (const uint8_t *)ptr;
- return (b[1] << 8) + b[0];
-}
-uint32_t READ_LE_UINT32(const void *ptr) {
- const uint8_t *b = (const uint8_t *)ptr;
- return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
-}
-
-static void createDirectoryStructure(char *name) {
+static void createDirectoryStructure(std::string name) {
#ifdef WIN32
- char *dir = strrchr(name, '\\');
- if (dir) {
- dir[0] = 0;
- CreateDirectory(name, NULL);
- dir[0] = '\\';
+ int pos = name.find_last_of("\\");
+ if (pos != name.npos) {
+ name.erase(pos);
+ createDirectoryStructure(name);
+ CreateDirectory(name.c_str(), NULL);
}
#endif
}
-int main(int argc, char **argv) {
- FILE *infile, *outfile;
- struct lab_header head;
- struct lab_entry *entries;
- char *str_table;
- uint32_t i;
- uint32_t offset;
- uint8_t g_type;
-
- if (argc < 2) {
- printf("No file specified\n");
- exit(1);
- }
- const char *filename = argv[1];
-
- infile = fopen(filename, "rb");
- if (infile == 0) {
- printf("Can not open source file: %s\n", filename);
- exit(1);
- }
+std::string fixFilename(std::string filename) {
+ int len = filename.size();
+ for (int i = 0; i < len; i++) {
+ if (filename[i] == '\\') {
+ filename[i] = '/';
+ }
+ filename[i] = tolower(filename[i]);
- fseek(infile, 0, SEEK_END);
- int filesize = ftell(infile);
- fseek(infile, 0, SEEK_SET);
-
- fread(&head.magic, 1, 4, infile);
- fread(&head.magic2, 1, 4, infile);
- uint32_t num, s_size, s_offset;
- fread(&num, 1, 4, infile);
- fread(&s_size, 1, 4, infile);
-
- uint32_t typeTest = 0;
- fread(&typeTest, 1, 4, infile);
- if (typeTest == 0) { // First entry of the table has offset 0 for Grim
- g_type = GT_GRIM;
- fseek(infile, -4, SEEK_CUR);
- } else { // EMI has an offset instead.
- s_offset = typeTest;
- g_type = GT_EMI;
- }
- head.num_entries = READ_LE_UINT32(&num);
- head.string_table_size = READ_LE_UINT32(&s_size);
- if (0 != memcmp(&head.magic, "LABN", 4)) {
- printf("There is no LABN header in source file\n");
- exit(1);
}
- entries = (struct lab_entry *)malloc(head.num_entries * sizeof(struct lab_entry));
- str_table = (char *)malloc(head.string_table_size);
- if (!str_table || !entries) {
- printf("Could not allocate memory\n");
- exit(1);
- }
- // Grim-stuff
- if (g_type == GT_GRIM) {
- fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
-
- fread(str_table, 1, head.string_table_size, infile);
- } else if (g_type == GT_EMI) { // EMI-stuff
- // EMI has a string-table-offset
- head.string_table_offset = READ_LE_UINT32(&s_offset) - 0x13d0f;
- // Find the string-table
- fseek(infile, head.string_table_offset, SEEK_SET);
- // Read the entire string table into str-table
- fread(str_table, 1, head.string_table_size, infile);
- fseek(infile, 20, SEEK_SET);
-
- // Decrypt the string table
- uint32_t j;
- for (j = 0; j < head.string_table_size; j++)
- if (str_table[j] != 0) {
- str_table[j] ^= 0x96;
- }
- fread(entries, 1, head.num_entries * sizeof(struct lab_entry), infile);
+ return filename;
+}
- }
- // allocate a 1mb buffer to start with
- uint32_t bufSize = 1024 * 1024;
- char *buf = (char *)malloc(bufSize);
- if (!buf) {
- printf("Could not allocate memory\n");
+int main(int argc, char **argv) {
+ if (argc < 2) {
+ printf("No file specified\n");
exit(1);
}
- for (i = 0; i < head.num_entries; i++) {
- char *fname = str_table + READ_LE_UINT32(&entries[i].fname_offset);
-
- offset = READ_LE_UINT32(&entries[i].start);
- uint32_t size = READ_LE_UINT32(&entries[i].size);
-
- if (offset + size > filesize) {
- printf("File \"%s\" past the end of lab \"%s\". Your game files may be corrupt.", fname, filename);
- break;
- }
+ const char *filename = argv[1];
- createDirectoryStructure(fname);
- outfile = fopen(fname, "wb");
- if (!outfile) {
- printf("Could not open file: %s\n", fname);
+ Lab lab(filename);
+
+ for (int i = 0; i < lab.getNumEntries(); i++) {
+ std::string filename = lab.getFileName(i);
+ std::istream *infile = lab.getFile(filename);
+ filename = fixFilename(filename);
+ createDirectoryStructure(filename.c_str());
+ std::fstream outfile(filename.c_str(), std::ios::out | std::ios::binary);
+ if (!outfile.is_open()) {
+ printf("Could not open %s for writing\n", filename.c_str());
+ createDirectoryStructure(filename.c_str());
continue;
}
- if (bufSize < size) {
- bufSize = size;
- char *newBuf = (char *)realloc(buf, bufSize);
- if (!newBuf) {
- printf("Could not reallocate memory\n");
- exit(1);
- } else {
- buf = newBuf;
- }
- }
- fseek(infile, offset, SEEK_SET);
- fread(buf, 1, READ_LE_UINT32(&entries[i].size), infile);
- fwrite(buf, 1, READ_LE_UINT32(&entries[i].size), outfile);
- fclose(outfile);
+ printf("Extracting file %s\n", filename.c_str());
+
+ outfile << infile->rdbuf();
+
+ delete infile;
}
- free(buf);
- free(entries);
- free(str_table);
- fclose(infile);
return 0;
}
Commit: d7c4b835c93b9b6450b86fe9585896ca48446ebf
https://github.com/scummvm/scummvm-tools/commit/d7c4b835c93b9b6450b86fe9585896ca48446ebf
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2013-07-12T22:32:18-07:00
Commit Message:
TOOLS: Update module.mk to add lab.o to the unlab linking
Changed paths:
tools/module.mk
diff --git a/tools/module.mk b/tools/module.mk
index 906848818..d5e555a42 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -98,7 +98,7 @@ TOOL_LDFLAGS := -lz
include $(srcdir)/rules.mk
TOOL := unlab
-TOOL_OBJS := unlab.o
+TOOL_OBJS := unlab.o lab.o
include $(srcdir)/rules.mk
TOOL := mklab
Commit: 9a4f6fe880c8c2d9804f7d1211b3a15abc9fbf2f
https://github.com/scummvm/scummvm-tools/commit/9a4f6fe880c8c2d9804f7d1211b3a15abc9fbf2f
Author: Dries Harnie (dries at harnie.be)
Date: 2013-08-03T16:30:06+02:00
Commit Message:
TOOLS: Pass liblua.a to linker for delua
Solves #29.
Changed paths:
tools/module.mk
diff --git a/tools/module.mk b/tools/module.mk
index d5e555a42..5408fe419 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -46,8 +46,7 @@ TOOL_LDFLAGS := -lcommon -lz
include $(srcdir)/rules.mk
TOOL := delua
-TOOL_OBJS := delua.o
-TOOL_LDFLAGS := -Ltools/lua -llua
+TOOL_OBJS := delua.o lua/liblua.a
include $(srcdir)/rules.mk
TOOL := mat2ppm
Commit: 9b69f4bed9db312afc8072ff54cc613288c37862
https://github.com/scummvm/scummvm-tools/commit/9b69f4bed9db312afc8072ff54cc613288c37862
Author: Dries Harnie (dries at harnie.be)
Date: 2013-08-04T03:19:37+02:00
Commit Message:
TOOLS: Also link liblua.a statically for luac
Changed paths:
tools/luac/module.mk
diff --git a/tools/luac/module.mk b/tools/luac/module.mk
index 18ab5004d..5c08e5ab7 100644
--- a/tools/luac/module.mk
+++ b/tools/luac/module.mk
@@ -7,10 +7,10 @@ TOOL_OBJS := \
opt.o \
print.o \
rebase.o \
+ ../lua/liblua.a
TOOL := luac
TOOL_DEPS := tools/lua
-TOOL_LDFLAGS := -Ltools/lua -llua
MAKE := luac
Commit: f7ad1ec5539ecbf2d925c2c55635a256ff513151
https://github.com/scummvm/scummvm-tools/commit/f7ad1ec5539ecbf2d925c2c55635a256ff513151
Author: Ingo van Lil (inguin at gmx.de)
Date: 2014-02-02T01:25:21+01:00
Commit Message:
TOOLS: Implement recursive directory creation for UNIX-like systems.
Changed paths:
tools/unlab.cpp
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 7253b5ade..9fc4a6843 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -30,6 +30,8 @@
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#else
+#include <sys/stat.h>
#endif
#define GT_GRIM 1
@@ -43,6 +45,13 @@ static void createDirectoryStructure(std::string name) {
createDirectoryStructure(name);
CreateDirectory(name.c_str(), NULL);
}
+#else
+ int pos = name.find_last_of("/");
+ if (pos != name.npos) {
+ name.erase(pos);
+ createDirectoryStructure(name);
+ mkdir(name.c_str(), 0755);
+ }
#endif
}
Commit: 53ca44d3d9b0c11083696dc52ea30ce699b4d82e
https://github.com/scummvm/scummvm-tools/commit/53ca44d3d9b0c11083696dc52ea30ce699b4d82e
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2014-03-26T22:03:44-07:00
Commit Message:
MKLAB: Fix creating labs with subdirectoires and generally cleanup the code
Changed paths:
tools/emi/renderTil.cpp
tools/mklab.cpp
diff --git a/tools/emi/renderTil.cpp b/tools/emi/renderTil.cpp
index 8b46bd78a..106921aa5 100644
--- a/tools/emi/renderTil.cpp
+++ b/tools/emi/renderTil.cpp
@@ -342,7 +342,7 @@ void renderLoop(GLFWwindow *window, Tile &t) {
glFlush();
glfwSwapBuffers(window);
glfwPollEvents();
- usleep(5000);
+ //usleep(5000);
}
glfwTerminate();
}
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index b772fec90..e03904ab2 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -26,43 +26,30 @@
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
+#include "common/endian.h"
+
+#include <vector>
+#include <string>
#define GT_GRIM 1
#define GT_EMI 2
-typedef struct {
+struct lab_header {
uint32_t magic;
uint32_t magic2;
uint32_t num_entries;
uint32_t string_table_size;
uint32_t string_table_offset;
-} lab_header;
+};
-typedef struct {
+struct lab_entry {
uint32_t fname_offset;
uint32_t start;
uint32_t size;
uint32_t reserved;
-} lab_entry;
-
-uint32_t READ_LE_UINT32(const void *ptr) {
- const uint8_t *b = (const uint8_t *)ptr;
- return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
-}
+};
-void WRITE_LE_UINT16(void *ptr, uint16_t value) {
- uint8_t *b = (uint8_t *)ptr;
- b[0] = (uint8_t)(value >> 0);
- b[1] = (uint8_t)(value >> 8);
-}
-void WRITE_LE_UINT32(void *ptr, uint32_t value) {
- uint8_t *b = (uint8_t *)ptr;
- b[0] = (uint8_t)(value >> 0);
- b[1] = (uint8_t)(value >> 8);
- b[2] = (uint8_t)(value >> 16);
- b[3] = (uint8_t)(value >> 24);
-}
void writeUint16(FILE *file, uint16_t value) {
char v[2];
@@ -89,17 +76,8 @@ void help() {
exit(0);
}
-static char *appendPath(const char *name, const char *dir) {
- int namelen = strlen(name);
- int dirlen = strlen(dir);
- char *path = (char *)malloc(namelen + dirlen + 2);
- strcpy(path, dir);
- path[dirlen] = '/';
- strcpy(path + dirlen + 1, name);
- return path;
-}
-static void countFiles(lab_header *head, DIR *dir, const char *dirname, int additionalLen) {
+static void countFiles(std::vector<std::string> &files, lab_header *head, DIR *dir, const std::string &d, std::string subdirn = "") {
struct dirent *dirfile;
while ((dirfile = readdir(dir))) {
if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, "..")) {
@@ -107,57 +85,50 @@ static void countFiles(lab_header *head, DIR *dir, const char *dirname, int addi
}
if (dirfile->d_type == S_IFDIR) {
- char *d = appendPath(dirfile->d_name, dirname);
- DIR *subdir = opendir(d);
- countFiles(head, subdir, d, additionalLen + strlen(dirfile->d_name) + 1);
- free(d);
+ std::string nextsub = subdirn;
+ nextsub += dirfile->d_name;
+ nextsub += "/";
+ std::string subdirname = d + "/" + dirfile->d_name;
+ DIR *subdir = opendir(subdirname.c_str());
+ countFiles(files, head, subdir, subdirname, nextsub);
closedir(subdir);
} else {
- ++head->num_entries;
- head->string_table_size += strlen(dirfile->d_name) + 1 + additionalLen;
+ std::string fname = subdirn + dirfile->d_name;
+ files.push_back(fname);
+ head->string_table_size += fname.length() + 1;
+ head->num_entries++;
}
}
}
-static void createEntries(DIR *dir, lab_entry *entries, char *str_table, const char *dirname, uint32_t &offset) {
- static uint32_t num_entry = 0;
- static uint32_t name_offset = 0;
- static char *str_offset = str_table;
- struct dirent *dirfile;
- while ((dirfile = readdir(dir))) {
- if (!strcmp(dirfile->d_name, ".") || !strcmp(dirfile->d_name, "..")) {
- continue;
- }
- if (dirfile->d_type == S_IFDIR) {
- char *d = appendPath(dirfile->d_name, dirname);
- DIR *subdir = opendir(d);
- createEntries(subdir, entries, str_table, d, offset);
- free(d);
- closedir(subdir);
- } else {
- lab_entry &entry = entries[num_entry++];
- WRITE_LE_UINT32(&entry.fname_offset, name_offset);
- WRITE_LE_UINT32(&entry.start, offset);
- entry.reserved = 0; //What is this??
+static void createEntries(const std::vector<std::string> &files, lab_entry *entries, char *str_table, uint32_t offset, const std::string &dirname) {
+ uint32_t name_offset = 0;
+ char *str_offset = str_table;
- char *path = appendPath(dirfile->d_name, dirname);
- char *name = strrchr(path, '/') + 1;
- strcpy(str_offset, name);
- str_offset[strlen(name)] = 0;
- name_offset += strlen(name) + 1;
- str_offset = str_table + name_offset;
+ uint size = files.size();
+ for (uint i = 0; i < size; ++i) {
+ lab_entry &entry = entries[i];
- struct stat st;
- stat(path, &st);
+ WRITE_LE_UINT32(&entry.fname_offset, name_offset);
+ WRITE_LE_UINT32(&entry.start, offset);
+ entry.reserved = 0; //What is this??
- // printf("entry of file %s, at offset %d and of size %d\n", path, offset, st.st_size);
- free(path);
+ const std::string &name = files[i];
- offset += st.st_size;
- WRITE_LE_UINT32(&entry.size, st.st_size);
- }
+ strcpy(str_offset, name.c_str());
+ str_offset[name.length()] = 0;
+ name_offset += name.length() + 1;
+ str_offset = str_table + name_offset;
+
+ std::string fullname = dirname + "/" + name;
+
+ struct stat st;
+ stat(fullname.c_str(), &st);
+
+ offset += st.st_size;
+ WRITE_LE_UINT32(&entry.size, st.st_size);
}
}
@@ -196,22 +167,21 @@ int main(int argc, char **argv) {
head.num_entries = 0;
head.string_table_size = 0;
- countFiles(&head, dir, dirname, 0);
+ std::vector<std::string> files;
+ countFiles(files, &head, dir, dirname);
+ closedir(dir);
-// printf("%d files, string table of size %d\n", head.num_entries, head.string_table_size);
- lab_entry *entries = (lab_entry *)malloc(head.num_entries * sizeof(lab_entry));
- char *str_table = (char *)malloc(head.string_table_size);
+ lab_entry *entries = new lab_entry[head.num_entries];
+ char *str_table = new char[head.string_table_size];
if (!str_table || !entries) {
printf("Could not allocate memory\n");
exit(3);
}
- rewinddir(dir);
uint32_t offset = 16 + head.num_entries * sizeof(lab_entry) + head.string_table_size + 16;
- createEntries(dir, entries, str_table, dirname, offset);
+ createEntries(files, entries, str_table, offset, dirname);
- closedir(dir);
// Open the output file after we've finished with the dir, so that we're sure
// we don't include the lab into itself if it was asked to be created into the same dir.
@@ -252,14 +222,14 @@ int main(int argc, char **argv) {
uint32_t bufsize = 1024 * 1024;
char *buf = (char *)malloc(bufsize);
- for (uint32_t i = 0; i < head.num_entries; ++i) {
+ for (uint i = 0; i < files.size(); ++i) {
lab_entry &entry = entries[i];
- const char *fname = str_table + READ_LE_UINT32(&entry.fname_offset);
+ std::string fname = files[i];
- char *path = appendPath(fname, dirname);
+ std::string path = dirname;
+ path += "/" + fname;
- FILE *file = fopen(path, "rb");
- free(path);
+ FILE *file = fopen(path.c_str(), "rb");
uint32_t offset = READ_LE_UINT32(&entry.start);
uint32_t size = READ_LE_UINT32(&entry.size);
@@ -275,7 +245,6 @@ int main(int argc, char **argv) {
buf = newbuf;
}
-// printf("writing file %s, at offset %d and of size %d\n", fname, offset, size);
fread(buf, 1, size, file);
fseek(outfile, offset, SEEK_SET);
@@ -286,8 +255,8 @@ int main(int argc, char **argv) {
fclose(outfile);
free(buf);
- free(entries);
- free(str_table);
+ delete[] entries;
+ delete[] str_table;
return 0;
}
Commit: f2f166f13e50a325875e5f11f202c47133ad2224
https://github.com/scummvm/scummvm-tools/commit/f2f166f13e50a325875e5f11f202c47133ad2224
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2014-03-26T22:06:59-07:00
Commit Message:
TOOLS: Remove accedental comment
Changed paths:
tools/emi/renderTil.cpp
diff --git a/tools/emi/renderTil.cpp b/tools/emi/renderTil.cpp
index 106921aa5..8b46bd78a 100644
--- a/tools/emi/renderTil.cpp
+++ b/tools/emi/renderTil.cpp
@@ -342,7 +342,7 @@ void renderLoop(GLFWwindow *window, Tile &t) {
glFlush();
glfwSwapBuffers(window);
glfwPollEvents();
- //usleep(5000);
+ usleep(5000);
}
glfwTerminate();
}
Commit: 259ab2ec8b26b64b62b8fdd9191a2bb99edaaf6e
https://github.com/scummvm/scummvm-tools/commit/259ab2ec8b26b64b62b8fdd9191a2bb99edaaf6e
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2014-03-26T22:12:17-07:00
Commit Message:
MKLAB: Fix a few warnings and use the correct d_type
Changed paths:
tools/mklab.cpp
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index e03904ab2..2c69cae4c 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -84,7 +84,7 @@ static void countFiles(std::vector<std::string> &files, lab_header *head, DIR *d
continue;
}
- if (dirfile->d_type == S_IFDIR) {
+ if (dirfile->d_type == DT_DIR) {
std::string nextsub = subdirn;
nextsub += dirfile->d_name;
nextsub += "/";
@@ -231,7 +231,7 @@ int main(int argc, char **argv) {
FILE *file = fopen(path.c_str(), "rb");
- uint32_t offset = READ_LE_UINT32(&entry.start);
+ uint32_t file_offset = READ_LE_UINT32(&entry.start);
uint32_t size = READ_LE_UINT32(&entry.size);
if (size > bufsize) {
@@ -247,7 +247,7 @@ int main(int argc, char **argv) {
fread(buf, 1, size, file);
- fseek(outfile, offset, SEEK_SET);
+ fseek(outfile, file_offset, SEEK_SET);
fwrite(buf, 1, size, outfile);
fclose(file);
Commit: 307730f950980631ba8b99ad4b1d7cfe60e30950
https://github.com/scummvm/scummvm-tools/commit/307730f950980631ba8b99ad4b1d7cfe60e30950
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2014-03-30T13:48:41+02:00
Commit Message:
DELUA: Increase number precision to 9 digits for all streams
Changed paths:
tools/delua.cpp
diff --git a/tools/delua.cpp b/tools/delua.cpp
index e8e151a8a..29cf71f9b 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -1277,7 +1277,8 @@ void decompile(std::ostream &os, TProtoFunc *tf, std::string indent_str,
std::multiset<Byte *> loc_vars;
//set the maximum precision, in order to avoid round errors with float numbers
- os.precision(8);
+ os.precision(9);
+ first_time.precision(9);
// First, do a preliminary pass to see where local variables are defined
Decompiler dc;
Commit: 70192f53629dba899f249d0b035e965e95829203
https://github.com/scummvm/scummvm-tools/commit/70192f53629dba899f249d0b035e965e95829203
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2014-03-30T13:58:34+02:00
Commit Message:
LUAC: Remove weird number comparison, since delua doesn't make anymore rounding errors
Changed paths:
tools/luac/rebase.cpp
diff --git a/tools/luac/rebase.cpp b/tools/luac/rebase.cpp
index 0b9121e50..5ed939b34 100644
--- a/tools/luac/rebase.cpp
+++ b/tools/luac/rebase.cpp
@@ -51,11 +51,6 @@ void uniform_const_list(TProtoFunc* func, TProtoFunc* base) {
for (j = j0; j < func->nconsts; ++j)
if (cmp(&base->consts[i], &func->consts[j])) {
j0 = j + 1;
-
- //Set the value of numbers to the value of base functions
- //since they could be sligthly differents (rounding errors)
- if (ttype(&base->consts[i]) == LUA_T_NUMBER)
- nvalue(&func->consts[j]) = nvalue(&base->consts[i]);
break;
}
@@ -323,24 +318,11 @@ bool cmp(const TObject *a, const TObject *b) {
if (ttype(a) == LUA_T_PROTO)
return true;
- if (ttype(a) == LUA_T_NUMBER) {
- //A simple fp comparision
- double diff, fa, fb, largest;
-
- diff = fabs(nvalue(a) - nvalue(b));
- fa = fabs(nvalue(a));
- fb = fabs(nvalue(b));
- largest = (fb > fa) ? fb : fa;
-
- if (diff <= largest * 1e-5) //Ten parts in a million should be enough
- return true;
- else
- return false;
- }
+ if (ttype(a) == LUA_T_NUMBER)
+ return (nvalue(a) == nvalue(b));
if (ttype(a) == LUA_T_STRING)
- if (strncmp(svalue(a), svalue(b), tsvalue(a)->u.s.len) == 0)
- return true;
+ return (strncmp(svalue(a), svalue(b), tsvalue(a)->u.s.len) == 0);
return false;
}
Commit: caf15cf0319f9d04205862189c150edc3d392f33
https://github.com/scummvm/scummvm-tools/commit/caf15cf0319f9d04205862189c150edc3d392f33
Author: Andrea Corna (yak.bizzarro+github at corna.info)
Date: 2014-03-30T14:00:02+02:00
Commit Message:
LUAC: Improve checks on constants in rebase function
Changed paths:
tools/luac/rebase.cpp
diff --git a/tools/luac/rebase.cpp b/tools/luac/rebase.cpp
index 5ed939b34..71cc730c4 100644
--- a/tools/luac/rebase.cpp
+++ b/tools/luac/rebase.cpp
@@ -38,8 +38,7 @@ void rebase(TProtoFunc* func, TProtoFunc* base) {
}
void uniform_const_list(TProtoFunc* func, TProtoFunc* base) {
- int i, j, k, j0;
- j0 = 0;
+ int i, j, k;
//Part1: Add back the deleted constant into the new function
int max_const = func->nconsts;
@@ -48,11 +47,9 @@ void uniform_const_list(TProtoFunc* func, TProtoFunc* base) {
if (ttype(&base->consts[i]) == LUA_T_PROTO)
continue;
- for (j = j0; j < func->nconsts; ++j)
- if (cmp(&base->consts[i], &func->consts[j])) {
- j0 = j + 1;
+ for (j = 0; j < func->nconsts; ++j)
+ if (cmp(&base->consts[i], &func->consts[j]))
break;
- }
if (j == func->nconsts) { //Const not found, re-add it
if (func->nconsts + 1 >= max_const)
Commit: 5c3e4a67ecced1d65901512cb1f27511df10d038
https://github.com/scummvm/scummvm-tools/commit/5c3e4a67ecced1d65901512cb1f27511df10d038
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2014-04-06T08:29:00+02:00
Commit Message:
TOOLS: synced with scummvm/(tools) and updates
Changed paths:
A COPYING.LUA
A common/algorithm.h
A common/array.h
A common/c++11-compat.h
A common/debug-channels.h
A common/debug.cpp
A common/debug.h
A common/file.cpp
A common/file.h
A common/func.h
A common/hash-str.h
A common/hashmap.cpp
A common/hashmap.h
A common/list.h
A common/list_intern.h
A common/memory.h
A common/memorypool.cpp
A common/memorypool.h
A common/noncopyable.h
A common/pack-end.h
A common/pack-start.h
A common/singleton.h
A common/str.cpp
A common/str.h
A common/textconsole.cpp
A common/textconsole.h
A common/tool_exception.h
A common/util.cpp
A common/util.h
A tools/lua/Changelog
R tools/lua/README.residualvm
AUTHORS
COPYRIGHT
Makefile
Makefile.common
common/endian.h
common/getopt.h
common/md5.cpp
common/md5.h
common/module.mk
common/scummsys.h
common/zlib.cpp
common/zlib.h
configure
tools/bm2bmp.cpp
tools/bmtoppm.cpp
tools/delua.cpp
tools/diffr.cpp
tools/emi/animb2txt.cpp
tools/emi/cosb2cos.cpp
tools/emi/filetools.h
tools/emi/meshb2obj.cpp
tools/emi/model.h
tools/emi/renderModel.cpp
tools/emi/renderTil.cpp
tools/emi/setb2set.cpp
tools/emi/sklb2txt.cpp
tools/emi/til2bmp.cpp
tools/imc2wav.cpp
tools/int2flt.cpp
tools/lab.cpp
tools/lab.h
tools/labcopy.cpp
tools/lua/lua.h
tools/mat2ppm.cpp
tools/mklab.cpp
tools/patchex/cab.h
tools/patchex/cabd.cpp
tools/patchex/mspack.h
tools/patchex/mszip.h
tools/patchex/mszipd.cpp
tools/patchex/patchex.cpp
tools/patchr.cpp
tools/set2fig.cpp
tools/unlab.cpp
tools/vima.cpp
diff --git a/AUTHORS b/AUTHORS
index db14b69be..2d1ff9f03 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -8,18 +8,20 @@ ResidualVM
Teams
-----
Grim Team:
- James Brown - Core developer (retired)
- Giulio Camuffo - Core developer
- Dries Harnie - EMI support, various code fixes and
- improvements
- Pawel Kolodziejski - Core developer (suspended)
- Einar Johan T. Somaen - EMI support, various code fixes and
- improvements
- Joel Teichroeb - EMI support, various engine fixes and
- improvements
+ James Brown - Core developer (retired)
+ Giulio Camuffo - Core developer
+ Dries Harnie - EMI support, various code fixes and
+ improvements
+ Pawel Kolodziejski - Core developer (suspended)
+ Christian Krause - EMI support, Various engine fixes and
+ improvements
+ Einar Johan T. Somaen - EMI support, various code fixes and
+ improvements
+ Joel Teichroeb - EMI support, various engine fixes and
+ improvements
Myst 3 Team:
- Bastien Bouclet - Core developer
+ Bastien Bouclet - Core developer
Contributors
------------
@@ -27,42 +29,51 @@ ResidualVM
list. Contact us and we'll add you.
Grim:
- Thomas Allen - Various engine code fixes and improvements
- Torbjorn Andersson - Various code fixes
- Ori Avtalion - Lipsync, LAF support, various code fixes
- Robert Biro - Antialiasing support
- Bastien Bouclet - Various fixes to engine
- Marcus Comstedt - Initial Dreamcast port
- Andrea Corna - Patcher module, various engine improvements
- Jonathan Gray - Various code fixes
- Tobias Gunkel - Initial Android port, few engines fixes
- Azamat H. Hackimov - Configure fix
- Vincent Hamm - Various engine code fixes and improvements
- Sven Hesse - Various compilation fixes
- Matthew Hoops - Some engine improvements, some work on EMI
- support
- Erich Hoover - x86-64 fixes, various code fixes and
- improvements
- Max Horn - Minor code fixes
- Travis Howell - Various code fixes, Windows port
- Guillem Jover - Few code improvements
- Filippos Karapetis - Compilation fixes
- Joost Peters - Various code fixes
- George Macon - Few fixes
- Josh Matthews - Few fixes to engine
- Matthieu Milan - Various engine improvements
- Christian Neumair - Various optimisation patches
- Vincent Pelletier - Various engine improvements and code fixes
- Daniel Schepler - Initial engine codebase, LUA support
- Yaron Tausky - Fixes to subtitles
- Julien Templier - create_project tool
- Pino Toscano - Debian GNU/Linux package files
- Lionel Ulmer - OpenGL optimisations
- Joni Vahamaki - A lot of engine improvements and fixes
- JenniBee - Compilation fixes
+ Thomas Allen - Various engine code fixes and
+ improvements
+ Torbjorn Andersson - Various code fixes
+ Ori Avtalion - Lipsync, LAF support, various code
+ fixes
+ Robert Biro - Antialiasing support
+ Bastien Bouclet - Various fixes to engine
+ Marcus Comstedt - Initial Dreamcast port
+ Andrea Corna - Patcher module, various engine
+ improvements
+ Jonathan Gray - Various code fixes
+ Tobias Gunkel - Initial Android port, few engines fixes
+ Azamat H. Hackimov - Configure fix
+ Vincent Hamm - Various engine code fixes and
+ improvements
+ Sven Hesse - Various compilation fixes
+ Matthew Hoops - Some engine improvements, some work on
+ EMI support
+ Erich Hoover - x86-64 fixes, various code fixes and
+ improvements
+ Max Horn - Minor code fixes
+ Travis Howell - Various code fixes, Windows port
+ Guillem Jover - Few code improvements
+ Filippos Karapetis - Compilation fixes
+ Ingo van Lil - Various fixes and improvements for EMI
+ Joost Peters - Various code fixes
+ George Macon - Few fixes
+ Josh Matthews - Few fixes to engine
+ Matthieu Milan - Various engine improvements
+ Christian Neumair - Various optimisation patches
+ Vincent Pelletier - Various engine improvements and code
+ fixes
+ Daniel Schepler - Initial engine codebase, LUA support
+ Dmitry Smirnov - Minor spelling corrections
+ Yaron Tausky - Fixes to subtitles
+ Julien Templier - create_project tool
+ Pino Toscano - Debian GNU/Linux package files
+ Lionel Ulmer - OpenGL optimisations
+ Joni Vahamaki - A lot of engine improvements and fixes
+ JenniBee - Compilation fixes
+ karjonas - Various engine code fixes
Myst 3:
- Matthew Hoops - Various engine improvements and code fixes
+ Matthew Hoops - Various engine improvements and code
+ fixes
ScummVM code
************
diff --git a/COPYING.LUA b/COPYING.LUA
new file mode 100644
index 000000000..0f84f6042
--- /dev/null
+++ b/COPYING.LUA
@@ -0,0 +1,38 @@
+NOTE: ResidualVM uses code from Lua, which is covered by the following license.
+This implementation of Lua contains additional code and modifications added
+only for ResidualVM project.
+Look into the source code file "tools/lua/Changelog" for more info.
+
+/******************************************************************************
+* Copyright (c) 1994-1998 TeCGraf, PUC-Rio. All rights reserved.
+*
+* Permission is hereby granted, without written agreement and without license
+* or royalty fees, to use, copy, modify, and distribute this software and its
+* documentation for any purpose, including commercial applications, subject to
+* the following conditions:
+*
+* - The above copyright notice and this permission notice shall appear in all
+* copies or substantial portions of this software.
+*
+* - 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 greatly
+* appreciated (but it is not required).
+*
+* - Altered source versions must be plainly marked as such, and must not be
+* misrepresented as being the original software.
+*
+* The authors specifically disclaim any warranties, including, but not limited
+* to, the implied warranties of merchantability and fitness for a particular
+* purpose. The software provided hereunder is on an "as is" basis, and the
+* authors have no obligation to provide maintenance, support, updates,
+* enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
+* authors be held liable to any party for direct, indirect, special,
+* incidental, or consequential damages arising out of the use of this software
+* and its documentation.
+*
+* The Lua language and this implementation have been entirely designed and
+* written by Waldemar Celes Filho, Roberto Ierusalimschy and
+* Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
+*
+******************************************************************************/
diff --git a/COPYRIGHT b/COPYRIGHT
index 0b33308b6..96f8e87d3 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1,5 +1,5 @@
ResidualVM
-Copyright (C) 2003-2013 by the following:
+Copyright (C) 2003-2014 by the following:
Some of the code in this project was originally LGPL v2.1 (or later)
but is used as GPL v2 (or later) starting from 19 Dec 2012.
@@ -46,7 +46,7 @@ Joni Vahamaki
JenniBee
ScummVM
-Copyright (C) 2001-2013 by the following:
+Copyright (C) 2001-2014 by the following:
If you have contributed to this project then you deserve to be on this
list. Contact us (see: AUTHORS) and we'll add you.
diff --git a/Makefile b/Makefile
index b84a55c47..b9cfb05ff 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ srcdir ?= .
DEFINES := -DHAVE_CONFIG_H
LDFLAGS :=
-INCLUDES := -I. -I$(srcdir) -I$(srcdir)/engines
+INCLUDES := -I. -I$(srcdir)
LIBS :=
OBJS :=
DEPDIR := .deps
@@ -32,9 +32,6 @@ ifeq "$(HAVE_GCC)" "1"
# being helpful.
#CXXFLAGS+= -Wmissing-format-attribute
- # Disable exceptions, ResidualVM use RTTI:
- CXXFLAGS+= -fno-exceptions
-
ifneq "$(HAVE_CLANG)" "1"
# enable checking of pointers returned by "new", but only when we do not
# build with clang
@@ -44,6 +41,11 @@ endif
ifeq "$(HAVE_CLANG)" "1"
CXXFLAGS+= -Wno-conversion -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-four-char-constants
+ # We use a anonymous nested type declaration in an anonymous union in
+ # common/str.h. This is no standard construct and clang warns about it.
+ # It works for all our target systems though, thus we simply disable that
+ # warning.
+ CXXFLAGS+= -Wno-nested-anon-types
endif
ifeq "$(HAVE_ICC)" "1"
diff --git a/Makefile.common b/Makefile.common
index 1354b528b..819daa6f2 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -137,7 +137,8 @@ endif
# Get the current version information
######################################################################
-VERSION = $(shell grep SCUMMVM_VERSION "${srcdir}/base/internal_version.h" | cut -d\" -f2)
+# AmigaOS4's grep has a problem with "./" in pathnames, so use cat piped into grep.
+VERSION = $(shell cat "${srcdir}/base/internal_version.h" | grep SCUMMVM_VERSION | cut -d\" -f2)
VER_MAJOR = $(shell echo $(VERSION) | cut -d. -f 1)
VER_MINOR = $(shell echo $(VERSION) | cut -d. -f 2)
VER_PATCH = $(shell echo $(VERSION) | cut -d. -f 3 | cut -c1)
@@ -155,7 +156,7 @@ ifeq ($(origin VER_REV), undefined)
VER_DIRTY := $(shell cd $(srcdir); git update-index --refresh --unmerged 1>/dev/null 2>&1; git diff-index --quiet HEAD || echo "-dirty")
# Get the working copy base revision
#ResidualVM: --always
-VER_REV := $(shell cd $(srcdir); git describe --always --match desc/\* | cut -d '-' -f 2-)$(VER_DIRTY)
+VER_REV := $(shell cd $(srcdir); git describe --always --long --match desc/\* | cut -d '-' -f 2-)$(VER_DIRTY)
endif
else
GITROOT := git://github.com/residualvm/residualvm-tools.git
diff --git a/common/algorithm.h b/common/algorithm.h
new file mode 100644
index 000000000..6453073ae
--- /dev/null
+++ b/common/algorithm.h
@@ -0,0 +1,272 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_ALGORITHM_H
+#define COMMON_ALGORITHM_H
+
+#include "common/scummsys.h"
+#include "common/func.h"
+#include "common/util.h"
+
+namespace Common {
+
+/**
+ * Copies data from the range [first, last) to [dst, dst + (last - first)).
+ * It requires the range [dst, dst + (last - first)) to be valid.
+ * It also requires dst not to be in the range [first, last).
+ */
+template<class In, class Out>
+Out copy(In first, In last, Out dst) {
+ while (first != last)
+ *dst++ = *first++;
+ return dst;
+}
+
+/**
+ * Copies data from the range [first, last) to [dst - (last - first), dst).
+ * It requires the range [dst - (last - first), dst) to be valid.
+ * It also requires dst not to be in the range [first, last).
+ *
+ * Unlike copy copy_backward copies the data from the end to the beginning.
+ */
+template<class In, class Out>
+Out copy_backward(In first, In last, Out dst) {
+ while (first != last)
+ *--dst = *--last;
+ return dst;
+}
+
+/**
+ * Copies data from the range [first, last) to [dst, dst + (last - first)).
+ * It requires the range [dst, dst + (last - first)) to be valid.
+ * It also requires dst not to be in the range [first, last).
+ *
+ * Unlike copy or copy_backward it does not copy all data. It only copies
+ * a data element when operator() of the op parameter returns true for the
+ * passed data element.
+ */
+template<class In, class Out, class Op>
+Out copy_if(In first, In last, Out dst, Op op) {
+ while (first != last) {
+ if (op(*first))
+ *dst++ = *first;
+ ++first;
+ }
+ return dst;
+}
+
+// Our 'specialized' 'fill' template for char, signed char and unsigned char arrays.
+// Since C++ doesn't support partial specialized template functions (currently) we
+// are going this way...
+// With this we assure the usage of memset for those, which should be
+// faster than a simple loop like for the generic 'fill'.
+template<class Value>
+signed char *fill(signed char *first, signed char *last, Value val) {
+ memset(first, (val & 0xFF), last - first);
+ return last;
+}
+
+template<class Value>
+unsigned char *fill(unsigned char *first, unsigned char *last, Value val) {
+ memset(first, (val & 0xFF), last - first);
+ return last;
+}
+
+template<class Value>
+char *fill(char *first, char *last, Value val) {
+ memset(first, (val & 0xFF), last - first);
+ return last;
+}
+
+/**
+ * Sets all elements in the range [first, last) to val.
+ */
+template<class In, class Value>
+In fill(In first, In last, const Value &val) {
+ while (first != last)
+ *first++ = val;
+ return first;
+}
+
+/**
+ * Finds the first data value in the range [first, last) matching v.
+ * For data comperance it uses operator == of the data elements.
+ */
+template<class In, class T>
+In find(In first, In last, const T &v) {
+ while (first != last) {
+ if (*first == v)
+ return first;
+ ++first;
+ }
+ return last;
+}
+
+/**
+ * Finds the first data value in the range [first, last) for which
+ * the specified predicate p returns true.
+ */
+template<class In, class Pred>
+In find_if(In first, In last, Pred p) {
+ while (first != last) {
+ if (p(*first))
+ return first;
+ ++first;
+ }
+ return last;
+}
+
+/**
+ * Applies the function f on all elements of the range [first, last).
+ * The processing order is from beginning to end.
+ */
+template<class In, class Op>
+Op for_each(In first, In last, Op f) {
+ while (first != last) f(*first++);
+ return f;
+}
+
+template<typename T>
+unsigned int distance(T *first, T *last) {
+ return last - first;
+}
+
+template<typename T>
+unsigned int distance(T first, T last) {
+ unsigned int n = 0;
+ while (first != last) {
+ ++n;
+ ++first;
+ }
+ return n;
+}
+
+template<typename T>
+T *sortChoosePivot(T *first, T *last) {
+ return first + distance(first, last) / 2;
+}
+
+template<typename T>
+T sortChoosePivot(T first, T last) {
+ unsigned int n = distance(first, last);
+ n /= 2;
+ while (n--)
+ ++first;
+ return first;
+}
+
+template<typename T, class StrictWeakOrdering>
+T sortPartition(T first, T last, T pivot, StrictWeakOrdering &comp) {
+ --last;
+ SWAP(*pivot, *last);
+
+ T sorted;
+ for (sorted = first; first != last; ++first) {
+ if (!comp(*last, *first)) {
+ if (first != sorted)
+ SWAP(*first, *sorted);
+ ++sorted;
+ }
+ }
+
+ SWAP(*last, *sorted);
+ return sorted;
+}
+
+/**
+ * Simple sort function, modeled after std::sort.
+ * It compares data with the given comparator object comp.
+ *
+ * Like std::sort this is not guaranteed to be stable.
+ *
+ * Two small quotes from wikipedia about stability:
+ *
+ * Stable sorting algorithms maintain the relative order of records with
+ * equal keys.
+ *
+ * Unstable sorting algorithms may change the relative order of records with
+ * equal keys, but stable sorting algorithms never do so.
+ *
+ * For more information on that topic check out:
+ * http://en.wikipedia.org/wiki/Sorting_algorithm#Stability
+ *
+ * NOTE: Actually as the time of writing our implementation is unstable.
+ */
+template<typename T, class StrictWeakOrdering>
+void sort(T first, T last, StrictWeakOrdering comp) {
+ if (first == last)
+ return;
+
+ T pivot = sortChoosePivot(first, last);
+ pivot = sortPartition(first, last, pivot, comp);
+ sort<T, StrictWeakOrdering>(first, pivot, comp);
+ sort<T, StrictWeakOrdering>(++pivot, last, comp);
+}
+
+/**
+ * Simple sort function, modeled after std::sort.
+ */
+template<typename T>
+void sort(T *first, T *last) {
+ sort(first, last, Less<T>());
+}
+
+template<class T>
+void sort(T first, T last) {
+ sort(first, last, Less<typename T::ValueType>());
+}
+
+// MSVC is complaining about the minus operator being applied to an unsigned type
+// We disable this warning for the affected section of code
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable: 4146)
+#endif
+
+/**
+ * Euclid's algorithm to compute the greatest common divisor.
+ */
+template<class T>
+T gcd(T a, T b) {
+ // Note: We check for <= instead of < to avoid spurious compiler
+ // warnings if T is an unsigned type, i.e. warnings like "comparison
+ // of unsigned expression < 0 is always false".
+ if (a <= 0)
+ a = -a;
+ if (b <= 0)
+ b = -b;
+
+ while (a > 0) {
+ T tmp = a;
+ a = b % a;
+ b = tmp;
+ }
+
+ return b;
+}
+
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+
+} // End of namespace Common
+#endif
diff --git a/common/array.h b/common/array.h
new file mode 100644
index 000000000..f240a9c2f
--- /dev/null
+++ b/common/array.h
@@ -0,0 +1,352 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_ARRAY_H
+#define COMMON_ARRAY_H
+
+#include "common/scummsys.h"
+#include "common/algorithm.h"
+#include "common/textconsole.h" // For error()
+#include "common/memory.h"
+
+namespace Common {
+
+/**
+ * This class implements a dynamically sized container, which
+ * can be accessed similar to a regular C++ array. Accessing
+ * elements is performed in constant time (like with plain arrays).
+ * In addition, one can append, insert and remove entries (this
+ * is the 'dynamic' part). Doing that in general takes time
+ * proportional to the number of elements in the array.
+ *
+ * The container class closest to this in the C++ standard library is
+ * std::vector. However, there are some differences.
+ */
+template<class T>
+class Array {
+public:
+ typedef T *iterator;
+ typedef const T *const_iterator;
+
+ typedef T value_type;
+
+ typedef uint size_type;
+
+protected:
+ size_type _capacity;
+ size_type _size;
+ T *_storage;
+
+public:
+ Array() : _capacity(0), _size(0), _storage(0) {}
+
+ Array(const Array<T> &array) : _capacity(array._size), _size(array._size), _storage(0) {
+ if (array._storage) {
+ allocCapacity(_size);
+ uninitialized_copy(array._storage, array._storage + _size, _storage);
+ }
+ }
+
+ /**
+ * Construct an array by copying data from a regular array.
+ */
+ template<class T2>
+ Array(const T2 *data, size_type n) {
+ _size = n;
+ allocCapacity(n);
+ uninitialized_copy(data, data + _size, _storage);
+ }
+
+ ~Array() {
+ freeStorage(_storage, _size);
+ _storage = 0;
+ _capacity = _size = 0;
+ }
+
+ /** Appends element to the end of the array. */
+ void push_back(const T &element) {
+ if (_size + 1 <= _capacity)
+ new ((void *)&_storage[_size++]) T(element);
+ else
+ insert_aux(end(), &element, &element + 1);
+ }
+
+ void push_back(const Array<T> &array) {
+ if (_size + array.size() <= _capacity) {
+ uninitialized_copy(array.begin(), array.end(), end());
+ _size += array.size();
+ } else
+ insert_aux(end(), array.begin(), array.end());
+ }
+
+ /** Removes the last element of the array. */
+ void pop_back() {
+ assert(_size > 0);
+ _size--;
+ // We also need to destroy the last object properly here.
+ _storage[_size].~T();
+ }
+
+ /** Returns a reference to the first element of the array. */
+ T &front() {
+ assert(_size > 0);
+ return _storage[0];
+ }
+
+ /** Returns a reference to the first element of the array. */
+ const T &front() const {
+ assert(_size > 0);
+ return _storage[0];
+ }
+
+ /** Returns a reference to the last element of the array. */
+ T &back() {
+ assert(_size > 0);
+ return _storage[_size-1];
+ }
+
+ /** Returns a reference to the last element of the array. */
+ const T &back() const {
+ assert(_size > 0);
+ return _storage[_size-1];
+ }
+
+
+ void insert_at(size_type idx, const T &element) {
+ assert(idx <= _size);
+ insert_aux(_storage + idx, &element, &element + 1);
+ }
+
+ void insert_at(size_type idx, const Array<T> &array) {
+ assert(idx <= _size);
+ insert_aux(_storage + idx, array.begin(), array.end());
+ }
+
+
+ T remove_at(size_type idx) {
+ assert(idx < _size);
+ T tmp = _storage[idx];
+ copy(_storage + idx + 1, _storage + _size, _storage + idx);
+ _size--;
+ // We also need to destroy the last object properly here.
+ _storage[_size].~T();
+ return tmp;
+ }
+
+ // TODO: insert, remove, ...
+
+ T &operator[](size_type idx) {
+ assert(idx < _size);
+ return _storage[idx];
+ }
+
+ const T &operator[](size_type idx) const {
+ assert(idx < _size);
+ return _storage[idx];
+ }
+
+ Array<T> &operator=(const Array<T> &array) {
+ if (this == &array)
+ return *this;
+
+ freeStorage(_storage, _size);
+ _size = array._size;
+ allocCapacity(_size);
+ uninitialized_copy(array._storage, array._storage + _size, _storage);
+
+ return *this;
+ }
+
+ size_type size() const {
+ return _size;
+ }
+
+ void clear() {
+ freeStorage(_storage, _size);
+ _storage = 0;
+ _size = 0;
+ _capacity = 0;
+ }
+
+ bool empty() const {
+ return (_size == 0);
+ }
+
+ bool operator==(const Array<T> &other) const {
+ if (this == &other)
+ return true;
+ if (_size != other._size)
+ return false;
+ for (size_type i = 0; i < _size; ++i) {
+ if (_storage[i] != other._storage[i])
+ return false;
+ }
+ return true;
+ }
+
+ bool operator!=(const Array<T> &other) const {
+ return !(*this == other);
+ }
+
+ iterator begin() {
+ return _storage;
+ }
+
+ iterator end() {
+ return _storage + _size;
+ }
+
+ const_iterator begin() const {
+ return _storage;
+ }
+
+ const_iterator end() const {
+ return _storage + _size;
+ }
+
+ void reserve(size_type newCapacity) {
+ if (newCapacity <= _capacity)
+ return;
+
+ T *oldStorage = _storage;
+ allocCapacity(newCapacity);
+
+ if (oldStorage) {
+ // Copy old data
+ uninitialized_copy(oldStorage, oldStorage + _size, _storage);
+ freeStorage(oldStorage, _size);
+ }
+ }
+
+ void resize(size_type newSize) {
+ reserve(newSize);
+ for (size_type i = _size; i < newSize; ++i)
+ new ((void *)&_storage[i]) T();
+ _size = newSize;
+ }
+
+ void assign(const_iterator first, const_iterator last) {
+ resize(distance(first, last)); // FIXME: ineffective?
+ T *dst = _storage;
+ while (first != last)
+ *dst++ = *first++;
+ }
+
+protected:
+ static size_type roundUpCapacity(size_type capacity) {
+ // Round up capacity to the next power of 2;
+ // we use a minimal capacity of 8.
+ size_type capa = 8;
+ while (capa < capacity)
+ capa <<= 1;
+ return capa;
+ }
+
+ void allocCapacity(size_type capacity) {
+ _capacity = capacity;
+ if (capacity) {
+ _storage = (T *)malloc(sizeof(T) * capacity);
+ if (!_storage)
+ ::error("Common::Array: failure to allocate %u bytes", capacity * (size_type)sizeof(T));
+ } else {
+ _storage = 0;
+ }
+ }
+
+ void freeStorage(T *storage, const size_type elements) {
+ for (size_type i = 0; i < elements; ++i)
+ storage[i].~T();
+ free(storage);
+ }
+
+ /**
+ * Insert a range of elements coming from this or another array.
+ * Unlike std::vector::insert, this method does not accept
+ * arbitrary iterators, mainly because our iterator system is
+ * seriously limited and does not distinguish between input iterators,
+ * output iterators, forward iterators or random access iterators.
+ *
+ * So, we simply restrict to Array iterators. Extending this to arbitrary
+ * random access iterators would be trivial.
+ *
+ * Moreover, this method does not handle all cases of inserting a subrange
+ * of an array into itself; this is why it is private for now.
+ */
+ iterator insert_aux(iterator pos, const_iterator first, const_iterator last) {
+ assert(_storage <= pos && pos <= _storage + _size);
+ assert(first <= last);
+ const size_type n = last - first;
+ if (n) {
+ const size_type idx = pos - _storage;
+ if (_size + n > _capacity || (_storage <= first && first <= _storage + _size)) {
+ T *const oldStorage = _storage;
+
+ // If there is not enough space, allocate more.
+ // Likewise, if this is a self-insert, we allocate new
+ // storage to avoid conflicts.
+ allocCapacity(roundUpCapacity(_size + n));
+
+ // Copy the data from the old storage till the position where
+ // we insert new data
+ uninitialized_copy(oldStorage, oldStorage + idx, _storage);
+ // Copy the data we insert
+ uninitialized_copy(first, last, _storage + idx);
+ // Afterwards copy the old data from the position where we
+ // insert.
+ uninitialized_copy(oldStorage + idx, oldStorage + _size, _storage + idx + n);
+
+ freeStorage(oldStorage, _size);
+ } else if (idx + n <= _size) {
+ // Make room for the new elements by shifting back
+ // existing ones.
+ // 1. Move a part of the data to the uninitialized area
+ uninitialized_copy(_storage + _size - n, _storage + _size, _storage + _size);
+ // 2. Move a part of the data to the initialized area
+ copy_backward(pos, _storage + _size - n, _storage + _size);
+
+ // Insert the new elements.
+ copy(first, last, pos);
+ } else {
+ // Copy the old data from the position till the end to the new
+ // place.
+ uninitialized_copy(pos, _storage + _size, _storage + idx + n);
+
+ // Copy a part of the new data to the position inside the
+ // initialized space.
+ copy(first, first + (_size - idx), pos);
+
+ // Copy a part of the new data to the position inside the
+ // uninitialized space.
+ uninitialized_copy(first + (_size - idx), last, _storage + _size);
+ }
+
+ // Finally, update the internal state
+ _size += n;
+ }
+ return pos;
+ }
+
+};
+
+} // End of namespace Common
+
+#endif
diff --git a/common/c++11-compat.h b/common/c++11-compat.h
new file mode 100644
index 000000000..14e064282
--- /dev/null
+++ b/common/c++11-compat.h
@@ -0,0 +1,44 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_CPP11_COMPAT_H
+#define COMMON_CPP11_COMPAT_H
+
+#if __cplusplus >= 201103L
+#error "c++11-compat.h included when C++11 is available"
+#endif
+
+//
+// Custom nullptr replacement. This is not type safe as the real C++11 nullptr
+// though.
+//
+#if !defined(nullptr) // XCode 5.0.1 has __cplusplus=199711 but defines this
+#define nullptr 0
+#endif
+
+//
+// Replacement for the override keyword. This allows compilation of code
+// which uses it, but does not feature any semantic.
+//
+#define override
+
+#endif
diff --git a/common/debug-channels.h b/common/debug-channels.h
new file mode 100644
index 000000000..83f416a3b
--- /dev/null
+++ b/common/debug-channels.h
@@ -0,0 +1,130 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_DEBUG_CHANNELS_H
+#define COMMON_DEBUG_CHANNELS_H
+
+#include "common/scummsys.h"
+
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+#include "common/list.h"
+#include "common/singleton.h"
+#include "common/str.h"
+
+
+namespace Common {
+
+// TODO: Find a better name for this
+class DebugManager : public Singleton<DebugManager> {
+public:
+
+ struct DebugChannel {
+ DebugChannel() : channel(0), enabled(false) {}
+ DebugChannel(uint32 c, const String &n, const String &d)
+ : name(n), description(d), channel(c), enabled(false) {}
+
+ String name;
+ String description;
+
+ uint32 channel;
+ bool enabled;
+ };
+
+ /**
+ * Adds a debug channel.
+ *
+ * A debug channel is considered roughly similar to what our debug levels described by
+ * gDebugLevel try to achieve:
+ *
+ * Debug channels should only affect the display of additional debug output, based on
+ * their state. That is if they are enabled, channel specific debug messages should
+ * be shown. If they are disabled on the other hand, those messages will be hidden.
+ *
+ * @see gDebugLevel.
+ *
+ * Note that we have debug* functions which depend both on the debug level set and
+ * specific debug channels. Those functions will only show output, when *both* criteria
+ * are satisfied.
+ *
+ * @param channel the channel flag (should be OR-able i.e. first one should be 1 then 2, 4, etc.)
+ * @param name the option name which is used in the debugger/on the command line to enable
+ * this special debug level (case will be ignored)
+ * @param description the description which shows up in the debugger
+ * @return true on success false on failure
+ */
+ bool addDebugChannel(uint32 channel, const String &name, const String &description);
+
+ /**
+ * Resets all engine specific debug channels.
+ */
+ void clearAllDebugChannels();
+
+ /**
+ * Enables an debug channel.
+ *
+ * @param name the name of the debug channel to enable
+ * @return true on success, false on failure
+ */
+ bool enableDebugChannel(const String &name);
+
+ /**
+ * Disables an debug channel.
+ *
+ * @param name the name of the debug channel to disable
+ * @return true on success, false on failure
+ */
+ bool disableDebugChannel(const String &name);
+
+
+
+ typedef List<DebugChannel> DebugChannelList;
+
+ /**
+ * Lists all engine specific debug channels.
+ *
+ * @return returns an array with all debug channels
+ */
+ DebugChannelList listDebugChannels();
+
+
+ /**
+ * Test whether the given debug channel is enabled.
+ */
+ bool isDebugChannelEnabled(uint32 channel);
+
+private:
+ typedef HashMap<String, DebugChannel, IgnoreCase_Hash, IgnoreCase_EqualTo> DebugChannelMap;
+
+ DebugChannelMap gDebugChannels;
+ uint32 gDebugChannelsEnabled;
+
+ friend class Singleton<SingletonBaseType>;
+ DebugManager() : gDebugChannelsEnabled(0) {}
+};
+
+/** Shortcut for accessing the debug manager. */
+#define DebugMan Common::DebugManager::instance()
+
+} // End of namespace Common
+
+#endif
diff --git a/common/debug.cpp b/common/debug.cpp
new file mode 100644
index 000000000..c208613ce
--- /dev/null
+++ b/common/debug.cpp
@@ -0,0 +1,210 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/textconsole.h"
+#include "common/algorithm.h"
+
+#include <stdarg.h> // For va_list etc.
+
+// TODO: Move gDebugLevel into namespace Common.
+int gDebugLevel = -1;
+
+namespace Common {
+
+DECLARE_SINGLETON(DebugManager);
+
+namespace {
+
+struct DebugLevelComperator {
+ bool operator()(const DebugManager::DebugChannel &l, const DebugManager::DebugChannel &r) {
+ return (l.name.compareToIgnoreCase(r.name) < 0);
+ }
+};
+
+} // end of anonymous namespace
+
+bool DebugManager::addDebugChannel(uint32 channel, const String &name, const String &description) {
+ if (gDebugChannels.contains(name))
+ warning("Duplicate declaration of engine debug channel '%s'", name.c_str());
+
+ gDebugChannels[name] = DebugChannel(channel, name, description);
+
+ return true;
+}
+
+void DebugManager::clearAllDebugChannels() {
+ gDebugChannelsEnabled = 0;
+ gDebugChannels.clear();
+}
+
+bool DebugManager::enableDebugChannel(const String &name) {
+ DebugChannelMap::iterator i = gDebugChannels.find(name);
+
+ if (i != gDebugChannels.end()) {
+ gDebugChannelsEnabled |= i->_value.channel;
+ i->_value.enabled = true;
+
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool DebugManager::disableDebugChannel(const String &name) {
+ DebugChannelMap::iterator i = gDebugChannels.find(name);
+
+ if (i != gDebugChannels.end()) {
+ gDebugChannelsEnabled &= ~i->_value.channel;
+ i->_value.enabled = false;
+
+ return true;
+ } else {
+ return false;
+ }
+}
+
+
+DebugManager::DebugChannelList DebugManager::listDebugChannels() {
+ DebugChannelList tmp;
+ for (DebugChannelMap::iterator i = gDebugChannels.begin(); i != gDebugChannels.end(); ++i)
+ tmp.push_back(i->_value);
+ sort(tmp.begin(), tmp.end(), DebugLevelComperator());
+
+ return tmp;
+}
+
+bool DebugManager::isDebugChannelEnabled(uint32 channel) {
+ // Debug level 11 turns on all special debug level messages
+ if (gDebugLevel == 11)
+ return true;
+ else
+ return (gDebugChannelsEnabled & channel) != 0;
+}
+
+} // End of namespace Common
+
+
+#ifndef DISABLE_TEXT_CONSOLE
+
+static void debugHelper(const char *s, va_list va, bool caret = true) {
+ Common::String buf = Common::String::vformat(s, va);
+
+ if (caret)
+ buf += '\n';
+
+ printf(buf.c_str());
+}
+
+void debug(const char *s, ...) {
+ va_list va;
+
+ va_start(va, s);
+ debugHelper(s, va);
+ va_end(va);
+}
+
+void debug(int level, const char *s, ...) {
+ va_list va;
+
+ if (level > gDebugLevel)
+ return;
+
+ va_start(va, s);
+ debugHelper(s, va);
+ va_end(va);
+
+}
+
+void debugN(const char *s, ...) {
+ va_list va;
+
+ va_start(va, s);
+ debugHelper(s, va, false);
+ va_end(va);
+}
+
+void debugN(int level, const char *s, ...) {
+ va_list va;
+
+ if (level > gDebugLevel)
+ return;
+
+ va_start(va, s);
+ debugHelper(s, va, false);
+ va_end(va);
+}
+
+void debugC(int level, uint32 debugChannels, const char *s, ...) {
+ va_list va;
+
+ // Debug level 11 turns on all special debug level messages
+ if (gDebugLevel != 11)
+ if (level > gDebugLevel || !(DebugMan.isDebugChannelEnabled(debugChannels)))
+ return;
+
+ va_start(va, s);
+ debugHelper(s, va);
+ va_end(va);
+}
+
+void debugCN(int level, uint32 debugChannels, const char *s, ...) {
+ va_list va;
+
+ // Debug level 11 turns on all special debug level messages
+ if (gDebugLevel != 11)
+ if (level > gDebugLevel || !(DebugMan.isDebugChannelEnabled(debugChannels)))
+ return;
+
+ va_start(va, s);
+ debugHelper(s, va, false);
+ va_end(va);
+}
+
+void debugC(uint32 debugChannels, const char *s, ...) {
+ va_list va;
+
+ // Debug level 11 turns on all special debug level messages
+ if (gDebugLevel != 11)
+ if (!(DebugMan.isDebugChannelEnabled(debugChannels)))
+ return;
+
+ va_start(va, s);
+ debugHelper(s, va);
+ va_end(va);
+}
+
+void debugCN(uint32 debugChannels, const char *s, ...) {
+ va_list va;
+
+ // Debug level 11 turns on all special debug level messages
+ if (gDebugLevel != 11)
+ if (!(DebugMan.isDebugChannelEnabled(debugChannels)))
+ return;
+
+ va_start(va, s);
+ debugHelper(s, va, false);
+ va_end(va);
+}
+
+#endif
diff --git a/common/debug.h b/common/debug.h
new file mode 100644
index 000000000..b6e0679a1
--- /dev/null
+++ b/common/debug.h
@@ -0,0 +1,126 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_DEBUG_H
+#define COMMON_DEBUG_H
+
+#include "common/scummsys.h"
+
+#ifdef DISABLE_TEXT_CONSOLE
+
+inline void debug(const char *s, ...) {}
+inline void debug(int level, const char *s, ...) {}
+inline void debugN(const char *s, ...) {}
+inline void debugN(int level, const char *s, ...) {}
+inline void debugC(int level, uint32 engineChannel, const char *s, ...) {}
+inline void debugC(uint32 engineChannel, const char *s, ...) {}
+inline void debugCN(int level, uint32 engineChannel, const char *s, ...) {}
+inline void debugCN(uint32 engineChannel, const char *s, ...) {}
+
+
+#else
+
+
+/**
+ * Print a debug message to the text console (stdout).
+ * Automatically appends a newline.
+ */
+void debug(const char *s, ...) GCC_PRINTF(1, 2);
+
+/**
+ * Print a debug message to the text console (stdout), but only if
+ * the gDebugLevel equals at least the specified level.
+ * As a rule of thumb, the more important the message, the lower the level.
+ * Automatically appends a newline.
+ */
+void debug(int level, const char *s, ...) GCC_PRINTF(2, 3);
+
+/**
+ * Print a debug message to the text console (stdout).
+ * Does not append a newline.
+ */
+void debugN(const char *s, ...) GCC_PRINTF(1, 2);
+
+/**
+ * Print a debug message to the text console (stdout), but only if
+ * the gDebugLevel equals at least the specified level.
+ * As a rule of thumb, the more important the message, the lower the level.
+ * Does not append a newline.
+ */
+void debugN(int level, const char *s, ...) GCC_PRINTF(2, 3);
+
+/**
+ * Print a debug message to the text console (stdout), but only if
+ * the gDebugLevel equals at least the specified level AND
+ * if the specified special debug level is active.
+ * As a rule of thumb, the more important the message, the lower the level.
+ * Automatically appends a newline.
+ *
+ * @see enableDebugChannel
+ */
+void debugC(int level, uint32 debugChannels, const char *s, ...) GCC_PRINTF(3, 4);
+
+/**
+ * Print a debug message to the text console (stdout), but only if
+ * the gDebugLevel equals at least the specified level AND
+ * if the specified special debug level is active.
+ * As a rule of thumb, the more important the message, the lower the level.
+ * Does not append a newline automatically.
+ *
+ * @see enableDebugChannel
+ */
+void debugCN(int level, uint32 debugChannels, const char *s, ...) GCC_PRINTF(3, 4);
+
+/**
+ * Print a debug message to the text console (stdout), but only if
+ * the specified special debug level is active.
+ * Automatically appends a newline.
+ *
+ * @see enableDebugChannel
+ */
+void debugC(uint32 debugChannels, const char *s, ...) GCC_PRINTF(2, 3);
+
+/**
+ * Print a debug message to the text console (stdout), but only if
+ * the specified special debug level is active.
+ * Does not append a newline automatically.
+ *
+ * @see enableDebugChannel
+ */
+void debugCN(uint32 debugChannels, const char *s, ...) GCC_PRINTF(2, 3);
+
+#endif
+
+/**
+ * The debug level. Initially set to -1, indicating that no debug output
+ * should be shown. Positive values usually imply an increasing number of
+ * debug output shall be generated, the higher the value, the more verbose the
+ * information (although the exact semantics are up to the engines).
+ */
+extern int gDebugLevel;
+
+//Global constant for EventRecorder debug channel
+enum GlobalDebugLevels {
+ kDebugLevelEventRec = 1 << 30
+};
+
+#endif
diff --git a/common/endian.h b/common/endian.h
index 5fc54e97b..c8b27fbd6 100644
--- a/common/endian.h
+++ b/common/endian.h
@@ -8,12 +8,12 @@
* 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.
@@ -86,7 +86,7 @@
}
// Test for GCC >= 4.3.0 as this version added the bswap builtin
-#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+#elif GCC_ATLEAST(4, 3)
FORCEINLINE uint32 SWAP_BYTES_32(uint32 a) {
return __builtin_bswap32(a);
@@ -146,6 +146,12 @@
*/
#define MKTAG(a0,a1,a2,a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
+/**
+ * A wrapper macro used around two character constants, like 'wb', to
+ * ensure portability. Typical usage: MKTAG16('w','b').
+ */
+#define MKTAG16(a0,a1) ((uint16)((a1) | ((a0) << 8)))
+
// Functions for reading/writing native integers.
// They also transparently handle the need for alignment.
@@ -156,7 +162,7 @@
//
// Moreover, we activate this code for GCC >= 3.3 but *only* if unaligned access
// is allowed.
-#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 && !defined(SCUMM_NEED_ALIGNMENT)))
+#if GCC_ATLEAST(4, 0) || (GCC_ATLEAST(3, 3) && !defined(SCUMM_NEED_ALIGNMENT))
FORCEINLINE uint16 READ_UINT16(const void *ptr) {
struct Unaligned16 { uint16 val; } __attribute__ ((__packed__, __may_alias__));
@@ -396,6 +402,12 @@ inline uint32 READ_BE_UINT24(const void *ptr) {
return (b[0] << 16) | (b[1] << 8) | (b[2]);
}
+#ifdef SCUMM_LITTLE_ENDIAN
+#define READ_UINT24(a) READ_LE_UINT24(a)
+#else
+#define READ_UINT24(a) READ_BE_UINT24(a)
+#endif
+
// ResidualVM specific:
#if defined(SCUMM_BIG_ENDIAN)
diff --git a/common/file.cpp b/common/file.cpp
new file mode 100644
index 000000000..051ccff6c
--- /dev/null
+++ b/common/file.cpp
@@ -0,0 +1,602 @@
+/* ScummVM Tools
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
+ *
+ * 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 "file.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <assert.h>
+#include <deque>
+#include <algorithm>
+#include <sys/stat.h> // for stat()
+#include <sys/types.h>
+#ifndef _MSC_VER
+#include <unistd.h> // for unlink()
+#else
+
+// Add a definition for S_IFDIR for MSVC
+#ifndef S_ISDIR
+#ifndef S_IFDIR
+#ifndef _S_IFDIR
+#define S_IFDIR (-1)
+#else
+#define S_IFDIR _S_IFDIR
+#endif
+#endif
+#define S_ISDIR(m) (((m)&S_IFDIR)==S_IFDIR)
+#endif
+
+#endif
+
+namespace Common {
+
+// Filenname implementation
+Filename::Filename() {
+}
+Filename::Filename(const char *path) : _path(path) {
+ // If this is a directory append '/' at the end if needed.
+ if (!_path.empty() && _path[_path.size() - 1] != '/' && _path[_path.size() - 1] != '\\' && isDirectory(_path.c_str()))
+ _path += '/';
+}
+Filename::Filename(std::string path) : _path(path) {
+ // If this is a directory append '/' at the end if needed.
+ if (!_path.empty() && _path[_path.size() - 1] != '/' && _path[_path.size() - 1] != '\\' && isDirectory(_path.c_str()))
+ _path += '/';
+}
+
+Filename::Filename(const Filename& filename) : _path(filename._path) {
+}
+
+Filename& Filename::operator=(const Filename& filename) {
+ _path = filename._path;
+ return *this;
+}
+
+void Filename::setFullPath(const std::string &path) {
+ _path = path;
+ // If this is a directory append '/' at the end if needed.
+ if (!_path.empty() && _path[_path.size() - 1] != '/' && _path[_path.size() - 1] != '\\' && isDirectory(_path.c_str()))
+ _path += '/';
+}
+
+void Filename::setFullName(const std::string &newname) {
+ _path = getPath() + newname;
+}
+
+void Filename::addExtension(const std::string &ext) {
+ _path += ext;
+}
+
+void Filename::setExtension(const std::string &ext) {
+ // FIXME: quick and dirty hack. But then so is this whole class...
+ std::string path = getPath();
+ std::string name = getName();
+ _path = path + name + ext;
+}
+
+bool Filename::equals(const Filename &other) const {
+#ifdef _WIN32
+ // On Windows paths are case-insensitive
+ return scumm_stricmp(_path.c_str(), other._path.c_str()) == 0;
+#else
+ return _path == other._path;
+#endif
+}
+
+bool Filename::empty() const {
+ return _path.empty();
+}
+
+bool Filename::directory() const {
+ return getFullName().size() == 0;
+}
+
+bool Filename::exists() const {
+ // This fails if we don't have permission to read the file
+ // but in most cases, that's the same thing for us.
+ FILE *f = fopen(_path.c_str(), "r");
+ if (!f) {
+ std::string fixedPath = fixPathCase(_path);
+ f = fopen(_path.c_str(), "r");
+ }
+ if (f) {
+ fclose(f);
+ return true;
+ }
+ return false;
+}
+
+bool Filename::hasExtension(std::string ext) const {
+ size_t dot = _path.rfind('.');
+ if (dot == std::string::npos)
+ return false;
+
+ // Check that dot position is less than /, since some
+ // directories contain ., like /home/.data/file
+ size_t slash = _path.rfind('/');
+ if (slash != std::string::npos)
+ if (slash > dot)
+ return false;
+
+ slash = _path.rfind('\\');
+ if (slash != std::string::npos)
+ if (slash > dot)
+ return false;
+
+ // We compare extensions, skip any dots
+ if (_path[dot] == '.')
+ dot++;
+ if (ext[0] == '.')
+ ext = ext.substr(1);
+
+ std::string tmp = _path.substr(dot);
+ // On Windows paths are case-insensitive
+ return scumm_stricmp(tmp.c_str(), ext.c_str()) == 0;
+}
+
+std::string Filename::getFullPath() const {
+ return _path;
+}
+
+std::string Filename::getFullName() const {
+ size_t slash = _path.rfind('/');
+ if (slash == std::string::npos)
+ slash = _path.rfind('\\');
+
+ if (slash == std::string::npos)
+ return _path;
+
+ return _path.substr(slash + 1);
+}
+
+std::string Filename::getName() const {
+ size_t slash = _path.rfind('/');
+ size_t dot = _path.rfind('.');
+ if (slash == std::string::npos)
+ slash = _path.rfind('\\');
+
+ if (dot == std::string::npos)
+ dot = _path.size();
+
+ if (slash == std::string::npos)
+ return _path.substr(0, dot);
+
+ if (dot < slash)
+ dot = _path.size();
+
+ return _path.substr(slash + 1, dot - slash - 1);
+}
+
+std::string Filename::getExtension() const {
+ size_t slash = _path.rfind('/');
+ size_t dot = _path.rfind('.');
+ if (slash == std::string::npos)
+ slash = _path.rfind('\\');
+
+ if (slash == std::string::npos)
+ slash = 0;
+
+ if (dot == std::string::npos)
+ return "";
+
+ if (dot < slash)
+ return "";
+
+ return _path.substr(dot + 1);
+}
+
+std::string Filename::getPath() const {
+ size_t slash = _path.rfind('/');
+ if (slash == std::string::npos)
+ slash = _path.rfind('\\');
+
+ if (slash == std::string::npos)
+ return "";
+
+ return _path.substr(0, slash + 1);
+}
+
+// File interface
+// While this does massive duplication of the code above, it's required to make sure that
+// unconverted tools are backwards-compatible
+
+File::File() {
+ _file = NULL;
+ _mode = FILEMODE_READ;
+ _xormode = 0;
+}
+
+File::File(const Filename &filepath, const char *mode) {
+ _file = NULL;
+ _mode = FILEMODE_READ;
+ _xormode = 0;
+
+ open(filepath, mode);
+}
+
+File::~File() {
+ close();
+}
+
+void File::open(const Filename &filepath, const char *mode) {
+
+ // Clean up previously opened file
+ close();
+
+ _file = fopen(filepath.getFullPath().c_str(), mode);
+ if (!_file) {
+ std::string fixedPath = fixPathCase(filepath.getFullPath());
+ _file = fopen(fixedPath.c_str(), mode);
+ }
+
+ FileMode m = FILEMODE_READ;
+ do {
+ switch(*mode) {
+ case 'w': m = FILEMODE_WRITE; break;
+ case 'r': m = FILEMODE_READ; break;
+ case 'b': m = FileMode(m | FILEMODE_BINARY); break;
+ case '+': m = FileMode(m | FILEMODE_READ | FILEMODE_WRITE); break;
+ default: throw FileException(std::string("Unsupported FileMode ") + mode);
+ }
+ } while (*++mode);
+ _mode = m;
+
+ _name = filepath;
+ _xormode = 0;
+
+ if (!_file)
+ throw FileException("Could not open file " + filepath.getFullPath());
+}
+
+void File::close() {
+ if (_file)
+ fclose(_file);
+ _file = NULL;
+}
+
+void File::setXorMode(uint8 xormode) {
+ _xormode = xormode;
+}
+
+int File::readChar() {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_READ) == 0)
+ throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+ int u8 = fgetc(_file);
+ if (u8 == EOF)
+ throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
+ u8 ^= _xormode;
+ return u8;
+}
+
+uint8 File::readByte() {
+ int u8 = readChar();
+ return (uint8)u8;
+}
+
+uint16 File::readUint16BE() {
+ uint16 ret = 0;
+ ret |= uint16(readByte() << 8ul);
+ ret |= uint16(readByte());
+ return ret;
+}
+
+uint16 File::readUint16LE() {
+ uint16 ret = 0;
+ ret |= uint16(readByte());
+ ret |= uint16(readByte() << 8ul);
+ return ret;
+}
+
+uint32 File::readUint32BE() {
+ uint32 ret = 0;
+ ret |= uint32(readByte() << 24);
+ ret |= uint32(readByte() << 16);
+ ret |= uint32(readByte() << 8);
+ ret |= uint32(readByte());
+ return ret;
+}
+
+uint32 File::readUint32LE() {
+ uint32 ret = 0;
+ ret |= uint32(readByte());
+ ret |= uint32(readByte() << 8);
+ ret |= uint32(readByte() << 16);
+ ret |= uint32(readByte() << 24);
+ return ret;
+}
+
+int16 File::readSint16BE() {
+ int16 ret = 0;
+ ret |= int16(readByte() << 8ul);
+ ret |= int16(readByte());
+ return ret;
+}
+
+int16 File::readSint16LE() {
+ int16 ret = 0;
+ ret |= int16(readByte());
+ ret |= int16(readByte() << 8ul);
+ return ret;
+}
+
+int32 File::readSint32BE() {
+ int32 ret = 0;
+ ret |= int32(readByte() << 24);
+ ret |= int32(readByte() << 16);
+ ret |= int32(readByte() << 8);
+ ret |= int32(readByte());
+ return ret;
+}
+
+int32 File::readSint32LE() {
+ int32 ret = 0;
+ ret |= int32(readByte());
+ ret |= int32(readByte() << 8);
+ ret |= int32(readByte() << 16);
+ ret |= int32(readByte() << 24);
+ return ret;
+}
+
+void File::read_throwsOnError(void *dataPtr, size_t dataSize) {
+ size_t data_read = read_noThrow(dataPtr, dataSize);
+ if (data_read != dataSize)
+ throw FileException("Read beyond the end of file (" + _name.getFullPath() + ")");
+}
+
+size_t File::read_noThrow(void *dataPtr, size_t dataSize) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_READ) == 0)
+ throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+ return fread(dataPtr, 1, dataSize, _file);
+}
+
+std::string File::readString() {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_READ) == 0)
+ throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+ std::string s;
+ try {
+ char c;
+ while ((c = readByte())) {
+ s += c;
+ }
+ } catch (FileException &) {
+ // pass, we reached EOF
+ }
+
+ return s;
+}
+
+std::string File::readString(size_t len) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_READ) == 0)
+ throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
+
+ std::string s('\0', len);
+ std::string::iterator is = s.begin();
+
+ char c;
+ while ((c = readByte())) {
+ *is = c;
+ }
+
+ return s;
+}
+
+void File::scanString(char *result) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_READ) == 0)
+ throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
+
+ fscanf(_file, "%s", result);
+}
+
+void File::writeChar(char i) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_WRITE) == 0)
+ throw FileException("Tried to write to a file opened in read mode (" + _name.getFullPath() + ")");
+
+ i ^= _xormode;
+
+ if (fwrite(&i, 1, 1, _file) != 1)
+ throw FileException("Could not write to file (" + _name.getFullPath() + ")");
+}
+
+void File::writeByte(uint8 b) {
+ writeChar(b);
+}
+
+void File::writeUint16BE(uint16 value) {
+ writeByte((uint8)(value >> 8));
+ writeByte((uint8)(value));
+}
+
+void File::writeUint16LE(uint16 value) {
+ writeByte((uint8)(value));
+ writeByte((uint8)(value >> 8));
+}
+
+void File::writeUint32BE(uint32 value) {
+ writeByte((uint8)(value >> 24));
+ writeByte((uint8)(value >> 16));
+ writeByte((uint8)(value >> 8));
+ writeByte((uint8)(value));
+}
+
+void File::writeUint32LE(uint32 value) {
+ writeByte((uint8)(value));
+ writeByte((uint8)(value >> 8));
+ writeByte((uint8)(value >> 16));
+ writeByte((uint8)(value >> 24));
+}
+
+size_t File::write(const void *dataPtr, size_t dataSize) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_WRITE) == 0)
+ throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
+
+ assert(_xormode == 0); // FIXME: This method does not work in XOR mode (and probably shouldn't)
+
+ size_t data_read = fwrite(dataPtr, 1, dataSize, _file);
+ if (data_read != dataSize)
+ throw FileException("Could not write to file (" + _name.getFullPath() + ")");
+
+ return data_read;
+}
+
+void File::print(const char *format, ...) {
+ if (!_file)
+ throw FileException("File is not open");
+ if ((_mode & FILEMODE_WRITE) == 0)
+ throw FileException("Tried to write to file opened in read mode (" + _name.getFullPath() + ")");
+
+
+ va_list va;
+
+ va_start(va, format);
+ vfprintf(_file, format, va);
+ va_end(va);
+}
+
+void File::seek(long offset, int origin) {
+ if (!_file)
+ throw FileException("File is not open");
+
+ if (fseek(_file, offset, origin) != 0)
+ throw FileException("Could not seek in file (" + _name.getFullPath() + ")");
+}
+
+void File::rewind() {
+ return ::rewind(_file);
+}
+
+int File::pos() const {
+ return ftell(_file);
+}
+
+int File::err() const {
+ return ferror(_file);
+}
+
+void File::clearErr() {
+ clearerr(_file);
+}
+
+bool File::eos() const {
+ return feof(_file) != 0;
+}
+
+uint32 File::size() const {
+ uint32 sz;
+ uint32 p = ftell(_file);
+ fseek(_file, 0, SEEK_END);
+ sz = ftell(_file);
+ fseek(_file, p, SEEK_SET);
+ return sz;
+}
+
+int removeFile(const char *path) {
+ return unlink(path);
+}
+
+bool isDirectory(const char *path) {
+ struct stat st;
+ if (stat(path, &st) == 0) {
+ return S_ISDIR(st.st_mode);
+ }
+ // Try to fix the case
+ std::string fixedPath = fixPathCase(path);
+ return stat(fixedPath.c_str(), &st) == 0 && S_ISDIR(st.st_mode);
+}
+
+std::string fixPathCase(const std::string& originalPath) {
+ std::string result = originalPath;
+ std::deque<std::string> parts;
+ struct stat st;
+
+ // Remove the last part of the path until we get to a path that exists
+ while (stat(result.c_str(), &st) != 0) {
+ size_t slash = result.rfind('/', result.size() - 2);
+ if (slash == std::string::npos)
+ slash = result.rfind('\\', result.size() - 2);
+ if (slash == std::string::npos) {
+ parts.push_back(result);
+ result.clear();
+ break;
+ } else {
+ parts.push_back(result.substr(slash + 1));
+ result.erase(slash + 1);
+ if (slash == 0)
+ break;
+ }
+ }
+
+ // Reconstruct the path by changing the case
+ while (!parts.empty()) {
+ std::string directory = parts.back();
+ // Try first original case, then all lower case and finally all upper case
+ std::string path = result + directory;
+ if (stat(path.c_str(), &st) == 0) {
+ result = path;
+ } else {
+ std::transform(directory.begin(), directory.end(), directory.begin(), ::tolower);
+ path = result + directory;
+ if (stat(path.c_str(), &st) == 0) {
+ result = path;
+ } else {
+ std::transform(directory.begin(), directory.end(), directory.begin(), ::toupper);
+ path = result + directory;
+ if (stat(path.c_str(), &st) == 0) {
+ result = path;
+ } else {
+ // Does not exists whatever the case used.
+ // Add back all the remaining parts and return.
+ while (!parts.empty()) {
+ result += parts.back();
+ parts.pop_back();
+ }
+ return result;
+ }
+ }
+ }
+ parts.pop_back();
+ }
+
+ return result;
+}
+
+} // End of namespace Common
+
diff --git a/common/file.h b/common/file.h
new file mode 100644
index 000000000..69f436317
--- /dev/null
+++ b/common/file.h
@@ -0,0 +1,425 @@
+/* ScummVM Tools
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
+ *
+ * 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.
+ */
+
+#ifndef COMMON_FILE_H
+#define COMMON_FILE_H
+
+#include "common/scummsys.h"
+#include "common/noncopyable.h"
+#include "common/str.h"
+
+#include "common/tool_exception.h"
+
+
+namespace Common {
+
+/**
+ * Something unexpected happened while reading / writing to a file.
+ * Usually premature end, or that it could not be opened (write / read protected).
+ */
+class FileException : public ToolException {
+public:
+ FileException(std::string error, int retcode = -1) : ToolException(error, retcode) {}
+};
+
+/**
+ * A file path, can be queried for different parts
+ * and the parts can be modified separately.
+ */
+class Filename {
+public:
+ std::string _path;
+
+ Filename();
+ Filename(std::string path);
+ Filename(const char *path);
+ Filename(const Filename &path);
+ Filename& operator=(const Filename &fn);
+
+ inline bool operator==(const Filename &fn){
+ return equals(fn);
+ }
+
+ /**
+ * Change the entire path including directory, volume and actual filname.
+ *
+ * @param path The new path.
+ */
+ void setFullPath(const std::string &path);
+
+ /**
+ * Sets the name of the file referred to, does not change the directory referred to.
+ *
+ * @param name New filename.
+ */
+ void setFullName(const std::string &name);
+
+ /**
+ * Adds an extension to the filename (does not replace any current extension).
+ *
+ * @param ext Extension to add.
+ */
+ void addExtension(const std::string &ext);
+
+ /**
+ * Sets the extension of the filename, replacing any current one, or adding one if there isn't any.
+ *
+ * @param ext The new extension of the filename.
+ */
+ void setExtension(const std::string &ext);
+
+ /**
+ * Returns true if the file has that extension.
+ *
+ * @param ext Extension to check for, only last extension is checked.
+ * @return True if the filename has that extension.
+ */
+ bool hasExtension(std::string ext) const;
+
+ /**
+ * Has the filename been set to anything.
+ */
+ bool empty() const;
+
+ /**
+ * Returns true if the file exists, does NOT work for directories.
+ */
+ bool exists() const;
+
+ /**
+ * Returns true if the file is a directory, which is if the path ends with '/'.
+ *
+ * @return true if the path looks like a directory.
+ */
+ bool directory() const;
+
+ /**
+ * True if the filenames are different (relative and absolute paths will NOT compare equally).
+ *
+ * @param other The filename to compare to.
+ * @return True if they are equal.
+ */
+ bool equals(const Filename &other) const;
+
+
+ /**
+ * Returns the entire path.
+ */
+ std::string getFullPath() const;
+
+ /**
+ * Returns the filename (ie. strips all directories from the path).
+ */
+ std::string getFullName() const;
+
+ /**
+ * Returns the name of the file, excluding extension and directories.
+ * Note that in the case of multiple extensions, only the last extension is stripped.
+ */
+ std::string getName() const;
+
+ /**
+ * Get the extension of the filename, only the last extension in case of many.
+ */
+ std::string getExtension() const;
+
+ /**
+ * Returns the path of the filename, the name and extension of the file is stripped.
+ */
+ std::string getPath() const;
+};
+
+/**
+ * Possible modes for opening files
+ */
+enum FileMode {
+ FILEMODE_READ = 1,
+ FILEMODE_WRITE = 2,
+ FILEMODE_BINARY = 4
+};
+
+/**
+ * A basic wrapper around the FILE class.
+ * Offers functionality to write words easily, and deallocates the FILE
+ * automatically on destruction.
+ */
+class File : public NonCopyable {
+public:
+ /**
+ * Opens the given file path as an in/out stream, depending on the
+ * second argument.
+ *
+ * @param filename file to open
+ * @param mode mode to open the file in
+ */
+ File(const Filename &filename, const char *mode);
+
+ /**
+ * Create an empty file, used for two-step construction.
+ */
+ File();
+ ~File();
+
+ /**
+ * Opens the given file path as an in/out stream, depending on the
+ * second argument.
+ *
+ * @param filename file to open
+ * @param mode mode to open the file in
+ */
+ void open(const Filename &filename, const char *mode);
+
+ /**
+ * Closes the file, if it's open.
+ */
+ void close();
+
+ /**
+ * Check whether the file is open.
+ */
+ bool isOpen() const { return _file != 0; }
+
+ /**
+ * Sets the xor mode of the file, bytes written / read to the file
+ * will be XORed with this value. This value is *not* reset when
+ * opening a new file.
+ * Only works for write* and read* operation, not for the array
+ * "read" and "write" methods
+ */
+ void setXorMode(uint8 xormode);
+
+ /**
+ * Reads a single character (equivalent of fgetc).
+ */
+ int readChar();
+ /**
+ * Read a single unsigned byte.
+ * @throws FileException if file is not open / if read failed.
+ */
+ uint8 readByte();
+ /**
+ * Read a single 16-bit word, big endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ uint16 readUint16BE();
+ /**
+ * Read a single 16-bit word, little endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ uint16 readUint16LE();
+ /**
+ * Read a single 32-bit word, big endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ uint32 readUint32BE();
+ /**
+ * Read a single 32-bit word, little endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ uint32 readUint32LE();
+
+ /**
+ * Read a single 16-bit word, big endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ int16 readSint16BE();
+ /**
+ * Read a single 16-bit word, little endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ int16 readSint16LE();
+ /**
+ * Read a single 32-bit word, big endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ int32 readSint32BE();
+ /**
+ * Read a single 32-bit word, little endian.
+ * @throws FileException if file is not open / if read failed.
+ */
+ int32 readSint32LE();
+
+
+ /**
+ * Works the same way as fread, but throws on error or if it could
+ * not read all elements.
+ *
+ * @param dataPtr pointer to a buffer into which the data is read
+ * @param dataSize number of bytes to be read
+ */
+ void read_throwsOnError(void *dataPtr, size_t dataSize);
+
+ /**
+ * Works the same way as fread, does NOT throw if it could not read all elements
+ * still throws if file is not open.
+ *
+ * @param dataPtr pointer to a buffer into which the data is read
+ * @param dataSize number of bytes to be read
+ * @return the number of bytes which were actually read.
+ */
+ size_t read_noThrow(void *dataPtr, size_t dataSize);
+
+ /**
+ * Reads a full string, until NULL or EOF.
+ * @throws FileException if file is not open / if read failed.
+ */
+ std::string readString();
+
+ /**
+ * Reads the queried amount of bytes and returns it as a string.
+ * @throws FileException if file is not open / if read failed.
+ *
+ * @param len How many bytes to read
+ * @return the data read
+ */
+ std::string readString(size_t len);
+
+ /**
+ * Reads a string, using until NULL or EOF or CR/LF.
+ * @throws FileException if file is not open / if read failed.
+ */
+ void scanString(char *result);
+
+ /**
+ * Writes a single character (equivalent of fputc).
+ */
+ void writeChar(char c);
+ /**
+ * Writes a single byte to the file.
+ * @throws FileException if file is not open / if write failed.
+ */
+ void writeByte(uint8 b);
+ /**
+ * Writes a single 16-bit word to the file, big endian.
+ * @throws FileException if file is not open / if write failed.
+ */
+ void writeUint16BE(uint16 value);
+ /**
+ * Writes a single 16-bit word to the file, little endian.
+ * @throws FileException if file is not open / if write failed.
+ */
+ void writeUint16LE(uint16 value);
+ /**
+ * Writes a single 32-bit word to the file, big endian.
+ * @throws FileException if file is not open / if write failed.
+ */
+ void writeUint32BE(uint32 value);
+ /**
+ * Writes a single 32-bit word to the file, little endian.
+ * @throws FileException if file is not open / if write failed.
+ */
+ void writeUint32LE(uint32 value);
+
+ /**
+ * Works the same way as fwrite, but throws on error or if
+ * it could not write all data.
+ *
+ * @param dataPtr pointer to the data to be written
+ * @param dataSize number of bytes to be written
+ * @return the number of bytes which were actually written.
+ */
+ size_t write(const void *dataPtr, size_t dataSize);
+
+ /**
+ * Works the same as fprintf.
+ */
+ void print(const char *format, ...);
+
+ /**
+ * Seek to the specified position in the stream.
+ *
+ * @param offset how many bytes to jump
+ * @param origin SEEK_SET, SEEK_CUR or SEEK_END
+ */
+ void seek(long offset, int origin);
+
+ /**
+ * Resets the file pointer to the start of the file, in essence the same as re-opening it.
+ */
+ void rewind();
+
+ /**
+ * Returns current position of the file cursor.
+ */
+ int pos() const;
+
+ /**
+ * Check whether an error occurred.
+ */
+ int err() const;
+
+ void clearErr();
+
+ /**
+ * True if there is nothing more to read from this file.
+ */
+ bool eos() const;
+
+ /**
+ * Returns the length of the file, in bytes, does not move the cursor.
+ */
+ uint32 size() const;
+
+ // FIXME: Remove this method eventually
+ FILE *getFileHandle() { return _file; }
+
+protected:
+ /** The mode the file was opened in. */
+ FileMode _mode;
+ /** Internal reference to the file. */
+ FILE *_file;
+ /** The name of the file, used for better error messages. */
+ Filename _name;
+ /** xor with this value while reading/writing (default 0), does not work for "read"/"write", only for byte operations. */
+ uint8 _xormode;
+};
+
+
+/**
+ * Remove the specified file.
+ * Currently this simply call unlink() internally,
+ * but by using this wrapper we have an easier time
+ * staying compatible with Windows.
+ */
+int removeFile(const char *path);
+
+/**
+ * Test if the specified path is a directory.
+ * This is just a wrapper around stat/S_ISDIR.
+ */
+bool isDirectory(const char *path);
+
+/**
+ * Transform the given path into an existing path if possible
+ * by changing the case of each path element to either the
+ * original case, all lower case or all upper case.
+ */
+std::string fixPathCase(const std::string& originalPath);
+
+} // End of namespace Common
+
+
+#endif
diff --git a/common/func.h b/common/func.h
new file mode 100644
index 000000000..4d7c48fbd
--- /dev/null
+++ b/common/func.h
@@ -0,0 +1,546 @@
+/* ScummVM Tools
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
+ *
+ * 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.
+ */
+
+#ifndef COMMON_FUNC_H
+#define COMMON_FUNC_H
+
+#include "common/scummsys.h"
+
+namespace Common {
+
+/**
+ * Generic unary function.
+ */
+template<class Arg, class Result>
+struct UnaryFunction {
+ typedef Arg ArgumenType;
+ typedef Result ResultType;
+};
+
+/**
+ * Generic binary function.
+ */
+template<class Arg1, class Arg2, class Result>
+struct BinaryFunction {
+ typedef Arg1 FirstArgumentType;
+ typedef Arg2 SecondArgumentType;
+ typedef Result ResultType;
+};
+
+/**
+ * Predicate to check for equallity of two data elements.
+ */
+template<class T>
+struct EqualTo : public BinaryFunction<T, T, bool> {
+ bool operator()(const T &x, const T &y) const { return x == y; }
+};
+
+/**
+ * Predicate to check for x being less than y.
+ */
+template<class T>
+struct Less : public BinaryFunction<T, T, bool> {
+ bool operator()(const T &x, const T &y) const { return x < y; }
+};
+
+/**
+ * Predicate to check for x being greater than y.
+ */
+template<class T>
+struct Greater : public BinaryFunction<T, T, bool> {
+ bool operator()(const T &x, const T &y) const { return x > y; }
+};
+
+template<class Op>
+class Binder1st : public UnaryFunction<typename Op::SecondArgumentType, typename Op::ResultType> {
+private:
+ Op _op;
+ typename Op::FirstArgumentType _arg1;
+public:
+ Binder1st(const Op &op, typename Op::FirstArgumentType arg1) : _op(op), _arg1(arg1) {}
+
+ typename Op::ResultType operator()(typename Op::SecondArgumentType v) const {
+ return _op(_arg1, v);
+ }
+};
+
+/**
+ * Transforms a binary function object into an unary function object.
+ * To achieve that the first parameter is bound to the passed value t.
+ */
+template<class Op>
+inline Binder1st<Op> bind1st(const Op &op, typename Op::FirstArgumentType t) {
+ return Binder1st<Op>(op, t);
+}
+
+template<class Op>
+class Binder2nd : public UnaryFunction<typename Op::FirstArgumentType, typename Op::ResultType> {
+private:
+ Op _op;
+ typename Op::SecondArgumentType _arg2;
+public:
+ Binder2nd(const Op &op, typename Op::SecondArgumentType arg2) : _op(op), _arg2(arg2) {}
+
+ typename Op::ResultType operator()(typename Op::FirstArgumentType v) const {
+ return _op(v, _arg2);
+ }
+};
+
+/**
+ * Transforms a binary function object into an unary function object.
+ * To achieve that the first parameter is bound to the passed value t.
+ */
+template<class Op>
+inline Binder2nd<Op> bind2nd(const Op &op, typename Op::SecondArgumentType t) {
+ return Binder2nd<Op>(op, t);
+}
+
+template<class Arg, class Result>
+class PointerToUnaryFunc : public UnaryFunction<Arg, Result> {
+private:
+ Result (*_func)(Arg);
+public:
+ typedef Result (*FuncType)(Arg);
+
+ PointerToUnaryFunc(const FuncType &func) : _func(func) {}
+ Result operator()(Arg v) const {
+ return _func(v);
+ }
+};
+
+template<class Arg1, class Arg2, class Result>
+class PointerToBinaryFunc : public BinaryFunction<Arg1, Arg2, Result> {
+private:
+ Result (*_func)(Arg1, Arg2);
+public:
+ typedef Result (*FuncType)(Arg1, Arg2);
+
+ PointerToBinaryFunc(const FuncType &func) : _func(func) {}
+ Result operator()(Arg1 v1, Arg2 v2) const {
+ return _func(v1, v2);
+ }
+};
+
+/**
+ * Creates an unary function object from a function pointer.
+ */
+template<class Arg, class Result>
+inline PointerToUnaryFunc<Arg, Result> ptr_fun(Result (*func)(Arg)) {
+ return PointerToUnaryFunc<Arg, Result>(func);
+}
+
+/**
+ * Creates an binary function object from a function pointer.
+ */
+template<class Arg1, class Arg2, class Result>
+inline PointerToBinaryFunc<Arg1, Arg2, Result> ptr_fun(Result (*func)(Arg1, Arg2)) {
+ return PointerToBinaryFunc<Arg1, Arg2, Result>(func);
+}
+
+template<class Result, class T>
+class MemFunc0 : public UnaryFunction<T *, Result> {
+private:
+ Result (T::*_func)();
+public:
+ typedef Result (T::*FuncType)();
+
+ MemFunc0(const FuncType &func) : _func(func) {}
+ Result operator()(T *v) const {
+ return (v->*_func)();
+ }
+};
+
+template<class Result, class T>
+class ConstMemFunc0 : public UnaryFunction<T *, Result> {
+private:
+ Result (T::*_func)() const;
+public:
+ typedef Result (T::*FuncType)() const;
+
+ ConstMemFunc0(const FuncType &func) : _func(func) {}
+ Result operator()(const T *v) const {
+ return (v->*_func)();
+ }
+};
+
+template<class Result, class Arg, class T>
+class MemFunc1 : public BinaryFunction<T *, Arg, Result> {
+private:
+ Result (T::*_func)(Arg);
+public:
+ typedef Result (T::*FuncType)(Arg);
+
+ MemFunc1(const FuncType &func) : _func(func) {}
+ Result operator()(T *v1, Arg v2) const {
+ return (v1->*_func)(v2);
+ }
+};
+
+template<class Result, class Arg, class T>
+class ConstMemFunc1 : public BinaryFunction<T *, Arg, Result> {
+private:
+ Result (T::*_func)(Arg) const;
+public:
+ typedef Result (T::*FuncType)(Arg) const;
+
+ ConstMemFunc1(const FuncType &func) : _func(func) {}
+ Result operator()(const T *v1, Arg v2) const {
+ return (v1->*_func)(v2);
+ }
+};
+
+/**
+ * Creates a unary function object from a class member function pointer.
+ * The parameter passed to the function object is the 'this' pointer to
+ * be used for the function call.
+ */
+template<class Result, class T>
+inline MemFunc0<Result, T> mem_fun(Result (T::*f)()) {
+ return MemFunc0<Result, T>(f);
+}
+
+/**
+ * Creates a unary function object from a class member function pointer.
+ * The parameter passed to the function object is the 'this' pointer to
+ * be used for the function call.
+ */
+template<class Result, class T>
+inline ConstMemFunc0<Result, T> mem_fun(Result (T::*f)() const) {
+ return ConstMemFunc0<Result, T>(f);
+}
+
+/**
+ * Creates a binary function object from a class member function pointer.
+ * The first parameter passed to the function object is the 'this' pointer to
+ * be used for the function call.
+ * The second one is the parameter passed to the member function.
+ */
+template<class Result, class Arg, class T>
+inline MemFunc1<Result, Arg, T> mem_fun(Result (T::*f)(Arg)) {
+ return MemFunc1<Result, Arg, T>(f);
+}
+
+/**
+ * Creates a binary function object from a class member function pointer.
+ * The first parameter passed to the function object is the 'this' pointer to
+ * be used for the function call.
+ * The second one is the parameter passed to the member function.
+ */
+template<class Result, class Arg, class T>
+inline ConstMemFunc1<Result, Arg, T> mem_fun(Result (T::*f)(Arg) const) {
+ return ConstMemFunc1<Result, Arg, T>(f);
+}
+
+template<class Result, class T>
+class MemFuncRef0 : public UnaryFunction<T &, Result> {
+private:
+ Result (T::*_func)();
+public:
+ typedef Result (T::*FuncType)();
+
+ MemFuncRef0(const FuncType &func) : _func(func) {}
+ Result operator()(T &v) const {
+ return (v.*_func)();
+ }
+};
+
+template<class Result, class T>
+class ConstMemFuncRef0 : public UnaryFunction<T &, Result> {
+private:
+ Result (T::*_func)() const;
+public:
+ typedef Result (T::*FuncType)() const;
+
+ ConstMemFuncRef0(const FuncType &func) : _func(func) {}
+ Result operator()(const T &v) const {
+ return (v.*_func)();
+ }
+};
+
+template<class Result, class Arg, class T>
+class MemFuncRef1 : public BinaryFunction<T &, Arg, Result> {
+private:
+ Result (T::*_func)(Arg);
+public:
+ typedef Result (T::*FuncType)(Arg);
+
+ MemFuncRef1(const FuncType &func) : _func(func) {}
+ Result operator()(T &v1, Arg v2) const {
+ return (v1.*_func)(v2);
+ }
+};
+
+template<class Result, class Arg, class T>
+class ConstMemFuncRef1 : public BinaryFunction<T &, Arg, Result> {
+private:
+ Result (T::*_func)(Arg) const;
+public:
+ typedef Result (T::*FuncType)(Arg) const;
+
+ ConstMemFuncRef1(const FuncType &func) : _func(func) {}
+ Result operator()(const T &v1, Arg v2) const {
+ return (v1.*_func)(v2);
+ }
+};
+
+/**
+ * Creates a unary function object from a class member function pointer.
+ * The parameter passed to the function object is the object instance to
+ * be used for the function call. Note unlike mem_fun, it takes a reference
+ * as parameter. Note unlike mem_fun, it takes a reference
+ * as parameter.
+ */
+template<class Result, class T>
+inline MemFuncRef0<Result, T> mem_fun_ref(Result (T::*f)()) {
+ return MemFuncRef0<Result, T>(f);
+}
+
+/**
+ * Creates a unary function object from a class member function pointer.
+ * The parameter passed to the function object is the object instance to
+ * be used for the function call. Note unlike mem_fun, it takes a reference
+ * as parameter.
+ */
+template<class Result, class T>
+inline ConstMemFuncRef0<Result, T> mem_fun_Ref(Result (T::*f)() const) {
+ return ConstMemFuncRef0<Result, T>(f);
+}
+
+/**
+ * Creates a binary function object from a class member function pointer.
+ * The first parameter passed to the function object is the object instance to
+ * be used for the function call. Note unlike mem_fun, it takes a reference
+ * as parameter.
+ * The second one is the parameter passed to the member function.
+ */
+template<class Result, class Arg, class T>
+inline MemFuncRef1<Result, Arg, T> mem_fun_ref(Result (T::*f)(Arg)) {
+ return MemFuncRef1<Result, Arg, T>(f);
+}
+
+/**
+ * Creates a binary function object from a class member function pointer.
+ * The first parameter passed to the function object is the object instance to
+ * be used for the function call. Note unlike mem_fun, it takes a reference
+ * as parameter.
+ * The second one is the parameter passed to the member function.
+ */
+template<class Result, class Arg, class T>
+inline ConstMemFuncRef1<Result, Arg, T> mem_fun_ref(Result (T::*f)(Arg) const) {
+ return ConstMemFuncRef1<Result, Arg, T>(f);
+}
+
+// functor code
+
+/**
+ * Generic functor object for function objects without parameters.
+ *
+ * @see Functor1
+ */
+template<class Res>
+struct Functor0 {
+ virtual ~Functor0() {}
+
+ virtual bool isValid() const = 0;
+ virtual Res operator()() const = 0;
+};
+
+/**
+ * Functor object for a class member function without parameter.
+ *
+ * Example creation:
+ *
+ * Foo bar;
+ * Functor0Mem<void, Foo> myFunctor(&bar, &Foo::myFunc);
+ *
+ * Example usage:
+ *
+ * myFunctor();
+ */
+template<class Res, class T>
+class Functor0Mem : public Functor0<Res> {
+public:
+ typedef Res (T::*FuncType)();
+
+ Functor0Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
+
+ bool isValid() const { return _func != 0 && _t != 0; }
+ Res operator()() const {
+ return (_t->*_func)();
+ }
+private:
+ mutable T *_t;
+ const FuncType _func;
+};
+
+/**
+ * Generic functor object for unary function objects.
+ *
+ * A typical usage for an unary function object is for executing opcodes
+ * in a script interpreter. To achieve that one can create an Common::Array
+ * object with 'Functor1<Arg, Res> *' as type. Now after the right engine version
+ * has been determined and the opcode table to use is found one could easily
+ * add the opcode implementations like this:
+ *
+ * Common::Array<Functor1<ScriptState, void> *> opcodeTable;
+ * opcodeTable[0] = new Functor1Mem<ScriptState, void, MyEngine_v1>(&myEngine, &MyEngine_v1::o1_foo);
+ * opcodeTable[1] = new Functor1Mem<ScriptState, void, MyEngine_v2>(&myEngine, &MyEngine_v2::o2_foo);
+ * // unimplemented/unused opcode
+ * opcodeTable[2] = 0;
+ * etc.
+ *
+ * This makes it easy to add member functions of different classes as
+ * opcode functions to the function table. Since with the generic
+ * Functor1<ScriptState, void> object the only requirement for an
+ * function to be used is 'ScriptState' as argument and 'void' as return
+ * value.
+ *
+ * Now for calling the opcodes one has simple to do:
+ * if (opcodeTable[opcodeNum] && opcodeTable[opcodeNum]->isValid())
+ * (*opcodeTable[opcodeNum])(scriptState);
+ * else
+ * warning("Unimplemented opcode %d", opcodeNum);
+ *
+ * If you want to see an real world example check the kyra engine.
+ * Files: engines/kyra/script.cpp and .h and engines/kyra/script_*.cpp
+ * are interesting for that matter.
+ */
+template<class Arg, class Res>
+struct Functor1 : public Common::UnaryFunction<Arg, Res> {
+ virtual ~Functor1() {}
+
+ virtual bool isValid() const = 0;
+ virtual Res operator()(Arg) const = 0;
+};
+
+/**
+ * Functor object for an unary class member function.
+ * Usage is like with Functor0Mem. The resulting functor object
+ * will take one parameter though.
+ *
+ * @see Functor0Mem
+ */
+template<class Arg, class Res, class T>
+class Functor1Mem : public Functor1<Arg, Res> {
+public:
+ typedef Res (T::*FuncType)(Arg);
+
+ Functor1Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
+
+ bool isValid() const { return _func != 0 && _t != 0; }
+ Res operator()(Arg v1) const {
+ return (_t->*_func)(v1);
+ }
+private:
+ mutable T *_t;
+ const FuncType _func;
+};
+
+/**
+ * Generic functor object for binary function objects.
+ *
+ * @see Functor1
+ */
+template<class Arg1, class Arg2, class Res>
+struct Functor2 : public Common::BinaryFunction<Arg1, Arg2, Res> {
+ virtual ~Functor2() {}
+
+ virtual bool isValid() const = 0;
+ virtual Res operator()(Arg1, Arg2) const = 0;
+};
+
+/**
+ * Functor object for a binary function.
+ *
+ * @see Functor2Mem
+ */
+template<class Arg1, class Arg2, class Res>
+class Functor2Fun : public Functor2<Arg1, Arg2, Res> {
+public:
+ typedef Res (*FuncType)(Arg1, Arg2);
+
+ Functor2Fun(const FuncType func) : _func(func) {}
+
+ bool isValid() const { return _func != 0; }
+ Res operator()(Arg1 v1, Arg2 v2) const {
+ return (*_func)(v1, v2);
+ }
+private:
+ const FuncType _func;
+};
+
+/**
+ * Functor object for a binary class member function.
+ * Usage is like with Functor0Mem. The resulting functor object
+ * will take two parameter though.
+ *
+ * @see Functor0Mem
+ */
+template<class Arg1, class Arg2, class Res, class T>
+class Functor2Mem : public Functor2<Arg1, Arg2, Res> {
+public:
+ typedef Res (T::*FuncType)(Arg1, Arg2);
+
+ Functor2Mem(T *t, const FuncType &func) : _t(t), _func(func) {}
+
+ bool isValid() const { return _func != 0 && _t != 0; }
+ Res operator()(Arg1 v1, Arg2 v2) const {
+ return (_t->*_func)(v1, v2);
+ }
+private:
+ mutable T *_t;
+ const FuncType _func;
+};
+
+/**
+ * Base template for hash functor objects, used by HashMap.
+ * This needs to be specialized for every type that you need to hash.
+ */
+template<typename T> struct Hash;
+
+
+#define GENERATE_TRIVIAL_HASH_FUNCTOR(T) \
+ template<> struct Hash<T> : public UnaryFunction<T, uint> { \
+ uint operator()(T val) const { return (uint)val; } \
+ }
+
+GENERATE_TRIVIAL_HASH_FUNCTOR(bool);
+GENERATE_TRIVIAL_HASH_FUNCTOR(char);
+GENERATE_TRIVIAL_HASH_FUNCTOR(signed char);
+GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned char);
+GENERATE_TRIVIAL_HASH_FUNCTOR(short);
+GENERATE_TRIVIAL_HASH_FUNCTOR(int);
+GENERATE_TRIVIAL_HASH_FUNCTOR(long);
+GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned short);
+GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned int);
+GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long);
+
+#undef GENERATE_TRIVIAL_HASH_FUNCTOR
+
+} // End of namespace Common
+
+#endif
+
diff --git a/common/getopt.h b/common/getopt.h
index f442c7c2a..58937328a 100644
--- a/common/getopt.h
+++ b/common/getopt.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/common/hash-str.h b/common/hash-str.h
new file mode 100644
index 000000000..82af6cca9
--- /dev/null
+++ b/common/hash-str.h
@@ -0,0 +1,86 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_HASH_STR_H
+#define COMMON_HASH_STR_H
+
+#include "common/hashmap.h"
+#include "common/str.h"
+
+namespace Common {
+
+uint hashit(const char *str);
+uint hashit_lower(const char *str); // Generate a hash based on the lowercase version of the string
+inline uint hashit(const String &str) { return hashit(str.c_str()); }
+inline uint hashit_lower(const String &str) { return hashit_lower(str.c_str()); }
+
+
+// FIXME: The following functors obviously are not consistently named
+
+struct CaseSensitiveString_EqualTo {
+ bool operator()(const String& x, const String& y) const { return x.equals(y); }
+};
+
+struct CaseSensitiveString_Hash {
+ uint operator()(const String& x) const { return hashit(x.c_str()); }
+};
+
+
+struct IgnoreCase_EqualTo {
+ bool operator()(const String& x, const String& y) const { return x.equalsIgnoreCase(y); }
+};
+
+struct IgnoreCase_Hash {
+ uint operator()(const String& x) const { return hashit_lower(x.c_str()); }
+};
+
+
+
+// Specalization of the Hash functor for String objects.
+// We do case sensitve hashing here, because that is what
+// the default EqualTo is compatible with. If one wants to use
+// case insensitve hashing, then only because one wants to use
+// IgnoreCase_EqualTo, and then one has to specify a custom
+// hash anyway.
+template<>
+struct Hash<String> {
+ uint operator()(const String& s) const {
+ return hashit(s.c_str());
+ }
+};
+
+template<>
+struct Hash<const char *> {
+ uint operator()(const char *s) const {
+ return hashit(s);
+ }
+};
+
+// String map -- by default case insensitive
+typedef HashMap<String, String, IgnoreCase_Hash, IgnoreCase_EqualTo> StringMap;
+
+
+
+} // End of namespace Common
+
+
+#endif
diff --git a/common/hashmap.cpp b/common/hashmap.cpp
new file mode 100644
index 000000000..99840993c
--- /dev/null
+++ b/common/hashmap.cpp
@@ -0,0 +1,109 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+// The hash map (associative array) implementation in this file is
+// based on the PyDict implementation of CPython. The erase() method
+// is based on example code in the Wikipedia article on Hash tables.
+
+#include "common/hashmap.h"
+
+namespace Common {
+
+// Hash function for strings, taken from CPython.
+uint hashit(const char *p) {
+ uint hash = *p << 7;
+ byte c;
+ int size = 0;
+ while ((c = *p++)) {
+ hash = (1000003 * hash) ^ c;
+ size++;
+ }
+ return hash ^ size;
+}
+
+// Like hashit, but converts every char to lowercase before hashing.
+uint hashit_lower(const char *p) {
+ uint hash = tolower(*p) << 7;
+ byte c;
+ int size = 0;
+ while ((c = *p++)) {
+ hash = (1000003 * hash) ^ tolower(c);
+ size++;
+ }
+ return hash ^ size;
+}
+
+#ifdef DEBUG_HASH_COLLISIONS
+static double
+ g_collisions = 0,
+ g_dummyHits = 0,
+ g_lookups = 0,
+ g_collPerLook = 0,
+ g_capacity = 0,
+ g_size = 0;
+static int g_max_capacity = 0, g_max_size = 0;
+static int g_totalHashmaps = 0;
+static int g_stats[4] = {0,0,0,0};
+
+void updateHashCollisionStats(int collisions, int dummyHits, int lookups, int arrsize, int nele) {
+ g_collisions += collisions;
+ g_lookups += lookups;
+ g_dummyHits += dummyHits;
+ if (lookups)
+ g_collPerLook += (double)collisions / (double)lookups;
+ g_capacity += arrsize;
+ g_size += nele;
+ g_totalHashmaps++;
+
+ if (3*nele <= 2*8)
+ g_stats[0]++;
+ if (3*nele <= 2*16)
+ g_stats[1]++;
+ if (3*nele <= 2*32)
+ g_stats[2]++;
+ if (3*nele <= 2*64)
+ g_stats[3]++;
+
+ g_max_capacity = MAX(g_max_capacity, arrsize);
+ g_max_size = MAX(g_max_size, nele);
+
+ debug("%d hashmaps: colls %.1f; dummies hit %.1f, lookups %.1f; ratio %.3f%%; size %f (max: %d); capacity %f (max: %d)",
+ g_totalHashmaps,
+ g_collisions / g_totalHashmaps,
+ g_dummyHits / g_totalHashmaps,
+ g_lookups / g_totalHashmaps,
+ 100 * g_collPerLook / g_totalHashmaps,
+ g_size / g_totalHashmaps, g_max_size,
+ g_capacity / g_totalHashmaps, g_max_capacity);
+ debug(" %d less than %d; %d less than %d; %d less than %d; %d less than %d",
+ g_stats[0], 2*8/3,
+ g_stats[1],2*16/3,
+ g_stats[2],2*32/3,
+ g_stats[3],2*64/3);
+
+ // TODO:
+ // * Should record the maximal size of the map during its lifetime, not that at its death
+ // * Should do some statistics: how many maps are less than 2/3*8, 2/3*16, 2/3*32, ...
+}
+#endif
+
+} // End of namespace Common
diff --git a/common/hashmap.h b/common/hashmap.h
new file mode 100644
index 000000000..d7ba10057
--- /dev/null
+++ b/common/hashmap.h
@@ -0,0 +1,637 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+// The hash map (associative array) implementation in this file is
+// based on the PyDict implementation of CPython.
+
+#ifndef COMMON_HASHMAP_H
+#define COMMON_HASHMAP_H
+
+/**
+ * @def DEBUG_HASH_COLLISIONS
+ * Enable the following #define if you want to check how many collisions the
+ * code produces (many collisions indicate either a bad hash function, or a
+ * hash table that is too small).
+ */
+//#define DEBUG_HASH_COLLISIONS
+
+/**
+ * @def USE_HASHMAP_MEMORY_POOL
+ * Enable the following define to let HashMaps use a memory pool for the
+ nodes they contain. * This increases memory usage, but also can improve
+ speed quite a bit.
+ */
+#define USE_HASHMAP_MEMORY_POOL
+
+
+#include "common/func.h"
+
+#ifdef DEBUG_HASH_COLLISIONS
+#include "common/debug.h"
+#endif
+
+#ifdef USE_HASHMAP_MEMORY_POOL
+#include "common/memorypool.h"
+#endif
+
+
+
+namespace Common {
+
+// The sgi IRIX MIPSpro Compiler has difficulties with nested templates.
+// This and the other __sgi conditionals below work around these problems.
+// The Intel C++ Compiler suffers from the same problems.
+#if (defined(__sgi) && !defined(__GNUC__)) || defined(__INTEL_COMPILER)
+template<class T> class IteratorImpl;
+#endif
+
+
+/**
+ * HashMap<Key,Val> maps objects of type Key to objects of type Val.
+ * For each used Key type, we need an "size_type hashit(Key,size_type)" function
+ * that computes a hash for the given Key object and returns it as an
+ * an integer from 0 to hashsize-1, and also an "equality functor".
+ * that returns true if if its two arguments are to be considered
+ * equal. Also, we assume that "=" works on Val objects for assignment.
+ *
+ * If aa is an HashMap<Key,Val>, then space is allocated each time aa[key] is
+ * referenced, for a new key. If the object is const, then an assertion is
+ * triggered instead. Hence if you are not sure whether a key is contained in
+ * the map, use contains() first to check for its presence.
+ */
+template<class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key> >
+class HashMap {
+public:
+ typedef uint size_type;
+
+private:
+
+ typedef HashMap<Key, Val, HashFunc, EqualFunc> HM_t;
+
+ struct Node {
+ const Key _key;
+ Val _value;
+ explicit Node(const Key &key) : _key(key), _value() {}
+ Node() : _key(), _value() {}
+ };
+
+ enum {
+ HASHMAP_PERTURB_SHIFT = 5,
+ HASHMAP_MIN_CAPACITY = 16,
+
+ // The quotient of the next two constants controls how much the
+ // internal storage of the hashmap may fill up before being
+ // increased automatically.
+ // Note: the quotient of these two must be between and different
+ // from 0 and 1.
+ HASHMAP_LOADFACTOR_NUMERATOR = 2,
+ HASHMAP_LOADFACTOR_DENOMINATOR = 3,
+
+ HASHMAP_MEMORYPOOL_SIZE = HASHMAP_MIN_CAPACITY * HASHMAP_LOADFACTOR_NUMERATOR / HASHMAP_LOADFACTOR_DENOMINATOR
+ };
+
+#ifdef USE_HASHMAP_MEMORY_POOL
+ ObjectPool<Node, HASHMAP_MEMORYPOOL_SIZE> _nodePool;
+#endif
+
+ Node **_storage; ///< hashtable of size arrsize.
+ size_type _mask; ///< Capacity of the HashMap minus one; must be a power of two of minus one
+ size_type _size;
+ size_type _deleted; ///< Number of deleted elements (_dummyNodes)
+
+ HashFunc _hash;
+ EqualFunc _equal;
+
+ /** Default value, returned by the const getVal. */
+ const Val _defaultVal;
+
+ /** Dummy node, used as marker for erased objects. */
+ #define HASHMAP_DUMMY_NODE ((Node *)1)
+
+#ifdef DEBUG_HASH_COLLISIONS
+ mutable int _collisions, _lookups, _dummyHits;
+#endif
+
+ Node *allocNode(const Key &key) {
+#ifdef USE_HASHMAP_MEMORY_POOL
+ return new (_nodePool) Node(key);
+#else
+ return new Node(key);
+#endif
+ }
+
+ void freeNode(Node *node) {
+ if (node && node != HASHMAP_DUMMY_NODE)
+#ifdef USE_HASHMAP_MEMORY_POOL
+ _nodePool.deleteChunk(node);
+#else
+ delete node;
+#endif
+ }
+
+ void assign(const HM_t &map);
+ size_type lookup(const Key &key) const;
+ size_type lookupAndCreateIfMissing(const Key &key);
+ void expandStorage(size_type newCapacity);
+
+#if !defined(__sgi) || defined(__GNUC__)
+ template<class T> friend class IteratorImpl;
+#endif
+
+ /**
+ * Simple HashMap iterator implementation.
+ */
+ template<class NodeType>
+ class IteratorImpl {
+ friend class HashMap;
+#if (defined(__sgi) && !defined(__GNUC__)) || defined(__INTEL_COMPILER)
+ template<class T> friend class Common::IteratorImpl;
+#else
+ template<class T> friend class IteratorImpl;
+#endif
+ protected:
+ typedef const HashMap hashmap_t;
+
+ size_type _idx;
+ hashmap_t *_hashmap;
+
+ protected:
+ IteratorImpl(size_type idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {}
+
+ NodeType *deref() const {
+ assert(_hashmap != 0);
+ assert(_idx <= _hashmap->_mask);
+ Node *node = _hashmap->_storage[_idx];
+ assert(node != 0);
+ assert(node != HASHMAP_DUMMY_NODE);
+ return node;
+ }
+
+ public:
+ IteratorImpl() : _idx(0), _hashmap(0) {}
+ template<class T>
+ IteratorImpl(const IteratorImpl<T> &c) : _idx(c._idx), _hashmap(c._hashmap) {}
+
+ NodeType &operator*() const { return *deref(); }
+ NodeType *operator->() const { return deref(); }
+
+ bool operator==(const IteratorImpl &iter) const { return _idx == iter._idx && _hashmap == iter._hashmap; }
+ bool operator!=(const IteratorImpl &iter) const { return !(*this == iter); }
+
+ IteratorImpl &operator++() {
+ assert(_hashmap);
+ do {
+ _idx++;
+ } while (_idx <= _hashmap->_mask && (_hashmap->_storage[_idx] == 0 || _hashmap->_storage[_idx] == HASHMAP_DUMMY_NODE));
+ if (_idx > _hashmap->_mask)
+ _idx = (size_type)-1;
+
+ return *this;
+ }
+
+ IteratorImpl operator++(int) {
+ IteratorImpl old = *this;
+ operator ++();
+ return old;
+ }
+ };
+
+public:
+ typedef IteratorImpl<Node> iterator;
+ typedef IteratorImpl<const Node> const_iterator;
+
+ HashMap();
+ HashMap(const HM_t &map);
+ ~HashMap();
+
+ HM_t &operator=(const HM_t &map) {
+ if (this == &map)
+ return *this;
+
+ // Remove the previous content and ...
+ clear();
+ delete[] _storage;
+ // ... copy the new stuff.
+ assign(map);
+ return *this;
+ }
+
+ bool contains(const Key &key) const;
+
+ Val &operator[](const Key &key);
+ const Val &operator[](const Key &key) const;
+
+ Val &getVal(const Key &key);
+ const Val &getVal(const Key &key) const;
+ const Val &getVal(const Key &key, const Val &defaultVal) const;
+ void setVal(const Key &key, const Val &val);
+
+ void clear(bool shrinkArray = 0);
+
+ void erase(iterator entry);
+ void erase(const Key &key);
+
+ size_type size() const { return _size; }
+
+ iterator begin() {
+ // Find and return the first non-empty entry
+ for (size_type ctr = 0; ctr <= _mask; ++ctr) {
+ if (_storage[ctr] && _storage[ctr] != HASHMAP_DUMMY_NODE)
+ return iterator(ctr, this);
+ }
+ return end();
+ }
+ iterator end() {
+ return iterator((size_type)-1, this);
+ }
+
+ const_iterator begin() const {
+ // Find and return the first non-empty entry
+ for (size_type ctr = 0; ctr <= _mask; ++ctr) {
+ if (_storage[ctr] && _storage[ctr] != HASHMAP_DUMMY_NODE)
+ return const_iterator(ctr, this);
+ }
+ return end();
+ }
+ const_iterator end() const {
+ return const_iterator((size_type)-1, this);
+ }
+
+ iterator find(const Key &key) {
+ size_type ctr = lookup(key);
+ if (_storage[ctr])
+ return iterator(ctr, this);
+ return end();
+ }
+
+ const_iterator find(const Key &key) const {
+ size_type ctr = lookup(key);
+ if (_storage[ctr])
+ return const_iterator(ctr, this);
+ return end();
+ }
+
+ // TODO: insert() method?
+
+ bool empty() const {
+ return (_size == 0);
+ }
+};
+
+//-------------------------------------------------------
+// HashMap functions
+
+/**
+ * Base constructor, creates an empty hashmap.
+ */
+template<class Key, class Val, class HashFunc, class EqualFunc>
+HashMap<Key, Val, HashFunc, EqualFunc>::HashMap()
+//
+// We have to skip _defaultVal() on PS2 to avoid gcc 3.2.2 ICE
+//
+#ifdef __PLAYSTATION2__
+ {
+#else
+ : _defaultVal() {
+#endif
+ _mask = HASHMAP_MIN_CAPACITY - 1;
+ _storage = new Node *[HASHMAP_MIN_CAPACITY];
+ assert(_storage != NULL);
+ memset(_storage, 0, HASHMAP_MIN_CAPACITY * sizeof(Node *));
+
+ _size = 0;
+ _deleted = 0;
+
+#ifdef DEBUG_HASH_COLLISIONS
+ _collisions = 0;
+ _lookups = 0;
+ _dummyHits = 0;
+#endif
+}
+
+/**
+ * Copy constructor, creates a full copy of the given hashmap.
+ * We must provide a custom copy constructor as we use pointers
+ * to heap buffers for the internal storage.
+ */
+template<class Key, class Val, class HashFunc, class EqualFunc>
+HashMap<Key, Val, HashFunc, EqualFunc>::HashMap(const HM_t &map) :
+ _defaultVal() {
+#ifdef DEBUG_HASH_COLLISIONS
+ _collisions = 0;
+ _lookups = 0;
+ _dummyHits = 0;
+#endif
+ assign(map);
+}
+
+/**
+ * Destructor, frees all used memory.
+ */
+template<class Key, class Val, class HashFunc, class EqualFunc>
+HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() {
+ for (size_type ctr = 0; ctr <= _mask; ++ctr)
+ freeNode(_storage[ctr]);
+
+ delete[] _storage;
+#ifdef DEBUG_HASH_COLLISIONS
+ extern void updateHashCollisionStats(int, int, int, int, int);
+ updateHashCollisionStats(_collisions, _dummyHits, _lookups, _mask+1, _size);
+#endif
+}
+
+/**
+ * Internal method for assigning the content of another HashMap
+ * to this one.
+ *
+ * @note We do *not* deallocate the previous storage here -- the caller is
+ * responsible for doing that!
+ */
+template<class Key, class Val, class HashFunc, class EqualFunc>
+void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t &map) {
+ _mask = map._mask;
+ _storage = new Node *[_mask+1];
+ assert(_storage != NULL);
+ memset(_storage, 0, (_mask+1) * sizeof(Node *));
+
+ // Simply clone the map given to us, one by one.
+ _size = 0;
+ _deleted = 0;
+ for (size_type ctr = 0; ctr <= _mask; ++ctr) {
+ if (map._storage[ctr] == HASHMAP_DUMMY_NODE) {
+ _storage[ctr] = HASHMAP_DUMMY_NODE;
+ _deleted++;
+ } else if (map._storage[ctr] != NULL) {
+ _storage[ctr] = allocNode(map._storage[ctr]->_key);
+ _storage[ctr]->_value = map._storage[ctr]->_value;
+ _size++;
+ }
+ }
+ // Perform a sanity check (to help track down hashmap corruption)
+ assert(_size == map._size);
+ assert(_deleted == map._deleted);
+}
+
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) {
+ for (size_type ctr = 0; ctr <= _mask; ++ctr) {
+ freeNode(_storage[ctr]);
+ _storage[ctr] = NULL;
+ }
+
+#ifdef USE_HASHMAP_MEMORY_POOL
+ _nodePool.freeUnusedPages();
+#endif
+
+ if (shrinkArray && _mask >= HASHMAP_MIN_CAPACITY) {
+ delete[] _storage;
+
+ _mask = HASHMAP_MIN_CAPACITY;
+ _storage = new Node *[HASHMAP_MIN_CAPACITY];
+ assert(_storage != NULL);
+ memset(_storage, 0, HASHMAP_MIN_CAPACITY * sizeof(Node *));
+ }
+
+ _size = 0;
+ _deleted = 0;
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(size_type newCapacity) {
+ assert(newCapacity > _mask+1);
+
+#ifndef NDEBUG
+ const size_type old_size = _size;
+#endif
+ const size_type old_mask = _mask;
+ Node **old_storage = _storage;
+
+ // allocate a new array
+ _size = 0;
+ _deleted = 0;
+ _mask = newCapacity - 1;
+ _storage = new Node *[newCapacity];
+ assert(_storage != NULL);
+ memset(_storage, 0, newCapacity * sizeof(Node *));
+
+ // rehash all the old elements
+ for (size_type ctr = 0; ctr <= old_mask; ++ctr) {
+ if (old_storage[ctr] == NULL || old_storage[ctr] == HASHMAP_DUMMY_NODE)
+ continue;
+
+ // Insert the element from the old table into the new table.
+ // Since we know that no key exists twice in the old table, we
+ // can do this slightly better than by calling lookup, since we
+ // don't have to call _equal().
+ const size_type hash = _hash(old_storage[ctr]->_key);
+ size_type idx = hash & _mask;
+ for (size_type perturb = hash; _storage[idx] != NULL && _storage[idx] != HASHMAP_DUMMY_NODE; perturb >>= HASHMAP_PERTURB_SHIFT) {
+ idx = (5 * idx + perturb + 1) & _mask;
+ }
+
+ _storage[idx] = old_storage[ctr];
+ _size++;
+ }
+
+ // Perform a sanity check: Old number of elements should match the new one!
+ // This check will fail if some previous operation corrupted this hashmap.
+ assert(_size == old_size);
+
+ delete[] old_storage;
+
+ return;
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const {
+ const size_type hash = _hash(key);
+ size_type ctr = hash & _mask;
+ for (size_type perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) {
+ if (_storage[ctr] == NULL)
+ break;
+ if (_storage[ctr] == HASHMAP_DUMMY_NODE) {
+#ifdef DEBUG_HASH_COLLISIONS
+ _dummyHits++;
+#endif
+ } else if (_equal(_storage[ctr]->_key, key))
+ break;
+
+ ctr = (5 * ctr + perturb + 1) & _mask;
+
+#ifdef DEBUG_HASH_COLLISIONS
+ _collisions++;
+#endif
+ }
+
+#ifdef DEBUG_HASH_COLLISIONS
+ _lookups++;
+ debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d",
+ _collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups),
+ (const void *)this, _mask+1, _size);
+#endif
+
+ return ctr;
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &key) {
+ const size_type hash = _hash(key);
+ size_type ctr = hash & _mask;
+ const size_type NONE_FOUND = _mask + 1;
+ size_type first_free = NONE_FOUND;
+ bool found = false;
+ for (size_type perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) {
+ if (_storage[ctr] == NULL)
+ break;
+ if (_storage[ctr] == HASHMAP_DUMMY_NODE) {
+#ifdef DEBUG_HASH_COLLISIONS
+ _dummyHits++;
+#endif
+ if (first_free != _mask + 1)
+ first_free = ctr;
+ } else if (_equal(_storage[ctr]->_key, key)) {
+ found = true;
+ break;
+ }
+
+ ctr = (5 * ctr + perturb + 1) & _mask;
+
+#ifdef DEBUG_HASH_COLLISIONS
+ _collisions++;
+#endif
+ }
+
+#ifdef DEBUG_HASH_COLLISIONS
+ _lookups++;
+ debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d",
+ _collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups),
+ (const void *)this, _mask+1, _size);
+#endif
+
+ if (!found && first_free != _mask + 1)
+ ctr = first_free;
+
+ if (!found) {
+ if (_storage[ctr])
+ _deleted--;
+ _storage[ctr] = allocNode(key);
+ assert(_storage[ctr] != NULL);
+ _size++;
+
+ // Keep the load factor below a certain threshold.
+ // Deleted nodes are also counted
+ size_type capacity = _mask + 1;
+ if ((_size + _deleted) * HASHMAP_LOADFACTOR_DENOMINATOR >
+ capacity * HASHMAP_LOADFACTOR_NUMERATOR) {
+ capacity = capacity < 500 ? (capacity * 4) : (capacity * 2);
+ expandStorage(capacity);
+ ctr = lookup(key);
+ assert(_storage[ctr] != NULL);
+ }
+ }
+
+ return ctr;
+}
+
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+bool HashMap<Key, Val, HashFunc, EqualFunc>::contains(const Key &key) const {
+ size_type ctr = lookup(key);
+ return (_storage[ctr] != NULL);
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) {
+ return getVal(key);
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+const Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) const {
+ return getVal(key);
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
+ size_type ctr = lookupAndCreateIfMissing(key);
+ assert(_storage[ctr] != NULL);
+ return _storage[ctr]->_value;
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const {
+ return getVal(key, _defaultVal);
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key, const Val &defaultVal) const {
+ size_type ctr = lookup(key);
+ if (_storage[ctr] != NULL)
+ return _storage[ctr]->_value;
+ else
+ return defaultVal;
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &val) {
+ size_type ctr = lookupAndCreateIfMissing(key);
+ assert(_storage[ctr] != NULL);
+ _storage[ctr]->_value = val;
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+void HashMap<Key, Val, HashFunc, EqualFunc>::erase(iterator entry) {
+ // Check whether we have a valid iterator
+ assert(entry._hashmap == this);
+ const size_type ctr = entry._idx;
+ assert(ctr <= _mask);
+ Node * const node = _storage[ctr];
+ assert(node != NULL);
+ assert(node != HASHMAP_DUMMY_NODE);
+
+ // If we remove a key, we replace it with a dummy node.
+ freeNode(node);
+ _storage[ctr] = HASHMAP_DUMMY_NODE;
+ _size--;
+ _deleted++;
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) {
+
+ size_type ctr = lookup(key);
+ if (_storage[ctr] == NULL)
+ return;
+
+ // If we remove a key, we replace it with a dummy node.
+ freeNode(_storage[ctr]);
+ _storage[ctr] = HASHMAP_DUMMY_NODE;
+ _size--;
+ _deleted++;
+ return;
+}
+
+#undef HASHMAP_DUMMY_NODE
+
+} // End of namespace Common
+
+#endif
diff --git a/common/list.h b/common/list.h
new file mode 100644
index 000000000..1bb4a2a5d
--- /dev/null
+++ b/common/list.h
@@ -0,0 +1,260 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_LIST_H
+#define COMMON_LIST_H
+
+#include "common/list_intern.h"
+
+namespace Common {
+
+/**
+ * Simple double linked list, modeled after the list template of the standard
+ * C++ library.
+ */
+template<typename t_T>
+class List {
+protected:
+ typedef ListInternal::NodeBase NodeBase;
+ typedef ListInternal::Node<t_T> Node;
+
+ NodeBase _anchor;
+
+public:
+ typedef ListInternal::Iterator<t_T> iterator;
+ typedef ListInternal::ConstIterator<t_T> const_iterator;
+
+ typedef t_T value_type;
+ typedef uint size_type;
+
+public:
+ List() {
+ _anchor._prev = &_anchor;
+ _anchor._next = &_anchor;
+ }
+ List(const List<t_T> &list) {
+ _anchor._prev = &_anchor;
+ _anchor._next = &_anchor;
+
+ insert(begin(), list.begin(), list.end());
+ }
+
+ ~List() {
+ clear();
+ }
+
+ /**
+ * Inserts element before pos.
+ */
+ void insert(iterator pos, const t_T &element) {
+ insert(pos._node, element);
+ }
+
+ /**
+ * Inserts the elements from first to last before pos.
+ */
+ template<typename iterator2>
+ void insert(iterator pos, iterator2 first, iterator2 last) {
+ for (; first != last; ++first)
+ insert(pos, *first);
+ }
+
+ /**
+ * Deletes the element at location pos and returns an iterator pointing
+ * to the element after the one which was deleted.
+ */
+ iterator erase(iterator pos) {
+ assert(pos != end());
+ return iterator(erase(pos._node)._next);
+ }
+
+ /**
+ * Deletes the element at location pos and returns an iterator pointing
+ * to the element before the one which was deleted.
+ */
+ iterator reverse_erase(iterator pos) {
+ assert(pos != end());
+ return iterator(erase(pos._node)._prev);
+ }
+
+ /**
+ * Deletes the elements between first and last (including first but not
+ * last) and returns an iterator pointing to the element after the one
+ * which was deleted (i.e., last).
+ */
+ iterator erase(iterator first, iterator last) {
+ NodeBase *f = first._node;
+ NodeBase *l = last._node;
+ while (f != l)
+ f = erase(f)._next;
+ return last;
+ }
+
+ /**
+ * Removes all elements that are equal to val from the list.
+ */
+ void remove(const t_T &val) {
+ NodeBase *i = _anchor._next;
+ while (i != &_anchor)
+ if (val == static_cast<Node *>(i)->_data)
+ i = erase(i)._next;
+ else
+ i = i->_next;
+ }
+
+ /** Inserts element at the start of the list. */
+ void push_front(const t_T &element) {
+ insert(_anchor._next, element);
+ }
+
+ /** Appends element to the end of the list. */
+ void push_back(const t_T &element) {
+ insert(&_anchor, element);
+ }
+
+ /** Removes the first element of the list. */
+ void pop_front() {
+ assert(!empty());
+ erase(_anchor._next);
+ }
+
+ /** Removes the last element of the list. */
+ void pop_back() {
+ assert(!empty());
+ erase(_anchor._prev);
+ }
+
+ /** Returns a reference to the first element of the list. */
+ t_T &front() {
+ return static_cast<Node *>(_anchor._next)->_data;
+ }
+
+ /** Returns a reference to the first element of the list. */
+ const t_T &front() const {
+ return static_cast<Node *>(_anchor._next)->_data;
+ }
+
+ /** Returns a reference to the last element of the list. */
+ t_T &back() {
+ return static_cast<Node *>(_anchor._prev)->_data;
+ }
+
+ /** Returns a reference to the last element of the list. */
+ const t_T &back() const {
+ return static_cast<Node *>(_anchor._prev)->_data;
+ }
+
+ List<t_T> &operator=(const List<t_T> &list) {
+ if (this != &list) {
+ iterator i;
+ const iterator e = end();
+ const_iterator i2;
+ const_iterator e2 = list.end();
+
+ for (i = begin(), i2 = list.begin(); (i != e) && (i2 != e2) ; ++i, ++i2) {
+ static_cast<Node *>(i._node)->_data = static_cast<const Node *>(i2._node)->_data;
+ }
+
+ if (i == e)
+ insert(i, i2, e2);
+ else
+ erase(i, e);
+ }
+
+ return *this;
+ }
+
+ size_type size() const {
+ size_type n = 0;
+ for (const NodeBase *cur = _anchor._next; cur != &_anchor; cur = cur->_next)
+ ++n;
+ return n;
+ }
+
+ void clear() {
+ NodeBase *pos = _anchor._next;
+ while (pos != &_anchor) {
+ Node *node = static_cast<Node *>(pos);
+ pos = pos->_next;
+ delete node;
+ }
+
+ _anchor._prev = &_anchor;
+ _anchor._next = &_anchor;
+ }
+
+ bool empty() const {
+ return (&_anchor == _anchor._next);
+ }
+
+
+ iterator begin() {
+ return iterator(_anchor._next);
+ }
+
+ iterator reverse_begin() {
+ return iterator(_anchor._prev);
+ }
+
+ iterator end() {
+ return iterator(&_anchor);
+ }
+
+ const_iterator begin() const {
+ return const_iterator(_anchor._next);
+ }
+
+ const_iterator reverse_begin() const {
+ return const_iterator(_anchor._prev);
+ }
+
+ const_iterator end() const {
+ return const_iterator(const_cast<NodeBase *>(&_anchor));
+ }
+
+protected:
+ NodeBase erase(NodeBase *pos) {
+ NodeBase n = *pos;
+ Node *node = static_cast<Node *>(pos);
+ n._prev->_next = n._next;
+ n._next->_prev = n._prev;
+ delete node;
+ return n;
+ }
+
+ /**
+ * Inserts element before pos.
+ */
+ void insert(NodeBase *pos, const t_T &element) {
+ ListInternal::NodeBase *newNode = new Node(element);
+ assert(newNode);
+
+ newNode->_next = pos;
+ newNode->_prev = pos->_prev;
+ newNode->_prev->_next = newNode;
+ newNode->_next->_prev = newNode;
+ }
+};
+
+} // End of namespace Common
+
+#endif
diff --git a/common/list_intern.h b/common/list_intern.h
new file mode 100644
index 000000000..b4f347561
--- /dev/null
+++ b/common/list_intern.h
@@ -0,0 +1,171 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_LIST_INTERN_H
+#define COMMON_LIST_INTERN_H
+
+#include "common/scummsys.h"
+
+namespace Common {
+
+template<typename T> class List;
+
+
+namespace ListInternal {
+ struct NodeBase {
+ NodeBase *_prev;
+ NodeBase *_next;
+ };
+
+ template<typename T>
+ struct Node : public NodeBase {
+ T _data;
+
+ Node(const T &x) : _data(x) {}
+ };
+
+ template<typename T> struct ConstIterator;
+
+ template<typename T>
+ struct Iterator {
+ typedef Iterator<T> Self;
+ typedef Node<T> * NodePtr;
+ typedef T & ValueRef;
+ typedef T * ValuePtr;
+ typedef T ValueType;
+
+ NodeBase *_node;
+
+ Iterator() : _node(0) {}
+ explicit Iterator(NodeBase *node) : _node(node) {}
+
+ // Prefix inc
+ Self &operator++() {
+ if (_node)
+ _node = _node->_next;
+ return *this;
+ }
+ // Postfix inc
+ Self operator++(int) {
+ Self tmp(_node);
+ ++(*this);
+ return tmp;
+ }
+ // Prefix dec
+ Self &operator--() {
+ if (_node)
+ _node = _node->_prev;
+ return *this;
+ }
+ // Postfix dec
+ Self operator--(int) {
+ Self tmp(_node);
+ --(*this);
+ return tmp;
+ }
+ ValueRef operator*() const {
+ assert(_node);
+ return static_cast<NodePtr>(_node)->_data;
+ }
+ ValuePtr operator->() const {
+ return &(operator*());
+ }
+
+ bool operator==(const Self &x) const {
+ return _node == x._node;
+ }
+
+ bool operator!=(const Self &x) const {
+ return _node != x._node;
+ }
+ };
+
+ template<typename T>
+ struct ConstIterator {
+ typedef ConstIterator<T> Self;
+ typedef const Node<T> * NodePtr;
+ typedef const T & ValueRef;
+ typedef const T * ValuePtr;
+
+ const NodeBase *_node;
+
+ ConstIterator() : _node(0) {}
+ explicit ConstIterator(const NodeBase *node) : _node(node) {}
+ ConstIterator(const Iterator<T> &x) : _node(x._node) {}
+
+ // Prefix inc
+ Self &operator++() {
+ if (_node)
+ _node = _node->_next;
+ return *this;
+ }
+ // Postfix inc
+ Self operator++(int) {
+ Self tmp(_node);
+ ++(*this);
+ return tmp;
+ }
+ // Prefix dec
+ Self &operator--() {
+ if (_node)
+ _node = _node->_prev;
+ return *this;
+ }
+ // Postfix dec
+ Self operator--(int) {
+ Self tmp(_node);
+ --(*this);
+ return tmp;
+ }
+ ValueRef operator*() const {
+ assert(_node);
+ return static_cast<NodePtr>(_node)->_data;
+ }
+ ValuePtr operator->() const {
+ return &(operator*());
+ }
+
+ bool operator==(const Self &x) const {
+ return _node == x._node;
+ }
+
+ bool operator!=(const Self &x) const {
+ return _node != x._node;
+ }
+ };
+
+
+ template<typename T>
+ bool operator==(const Iterator<T>& a, const ConstIterator<T>& b) {
+ return a._node == b._node;
+ }
+
+ template<typename T>
+ bool operator!=(const Iterator<T>& a, const ConstIterator<T>& b) {
+ return a._node != b._node;
+ }
+}
+
+
+} // End of namespace Common
+
+#endif
diff --git a/common/md5.cpp b/common/md5.cpp
index 220ce84a9..40f174f94 100644
--- a/common/md5.cpp
+++ b/common/md5.cpp
@@ -1,23 +1,27 @@
/* ScummVM Tools
- * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
*
* 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.
- *
- * $URL$
- * $Id$
- *
*/
#include "common/md5.h"
diff --git a/common/md5.h b/common/md5.h
index b8ac9d64e..a78b7b80b 100644
--- a/common/md5.h
+++ b/common/md5.h
@@ -1,23 +1,27 @@
/* ScummVM Tools
- * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * Additionally this file is based on the ScummVM source code.
+ * Copyright information for the ScummVM source code is
+ * available in the COPYRIGHT file of the ScummVM source
+ * distribution.
*
* 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.
- *
- * $URL$
- * $Id$
- *
*/
#ifndef COMMON_MD5_H
diff --git a/common/memory.h b/common/memory.h
new file mode 100644
index 000000000..c32af42ba
--- /dev/null
+++ b/common/memory.h
@@ -0,0 +1,66 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_MEMORY_H
+#define COMMON_MEMORY_H
+
+#include "common/scummsys.h"
+
+namespace Common {
+
+/**
+ * Copies data from the range [first, last) to [dst, dst + (last - first)).
+ * It requires the range [dst, dst + (last - first)) to be valid and
+ * uninitialized.
+ */
+template<class In, class Type>
+Type *uninitialized_copy(In first, In last, Type *dst) {
+ while (first != last)
+ new ((void *)dst++) Type(*first++);
+ return dst;
+}
+
+/**
+ * Initializes the memory [first, first + (last - first)) with the value x.
+ * It requires the range [first, first + (last - first)) to be valid and
+ * uninitialized.
+ */
+/*template<class Type, class Value>
+void uninitialized_fill(Type *first, Type *last, const Value &x) {
+ while (first != last)
+ new ((void *)first++) Type(x);
+}*/
+
+/**
+ * Initializes the memory [dst, dst + n) with the value x.
+ * It requires the range [dst, dst + n) to be valid and
+ * uninitialized.
+ */
+/*template<class Type, class Value>
+void uninitialized_fill_n(Type *dst, size_t n, const Value &x) {
+ while (n--)
+ new ((void *)dst++) Type(x);
+}*/
+
+} // End of namespace Common
+
+#endif
diff --git a/common/memorypool.cpp b/common/memorypool.cpp
new file mode 100644
index 000000000..1a9bfe2e2
--- /dev/null
+++ b/common/memorypool.cpp
@@ -0,0 +1,182 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 "common/memorypool.h"
+#include "common/util.h"
+
+namespace Common {
+
+enum {
+ INITIAL_CHUNKS_PER_PAGE = 8
+};
+
+static size_t adjustChunkSize(size_t chunkSize) {
+ // You must at least fit the pointer in the node (technically unneeded considering the next rounding statement)
+ chunkSize = MAX(chunkSize, sizeof(void *));
+ // There might be an alignment problem on some platforms when trying to load a void* on a non natural boundary
+ // so we round to the next sizeof(void *)
+ chunkSize = (chunkSize + sizeof(void *) - 1) & (~(sizeof(void *) - 1));
+
+ return chunkSize;
+}
+
+
+MemoryPool::MemoryPool(size_t chunkSize)
+ : _chunkSize(adjustChunkSize(chunkSize)) {
+
+ _next = NULL;
+
+ _chunksPerPage = INITIAL_CHUNKS_PER_PAGE;
+}
+
+MemoryPool::~MemoryPool() {
+#if 0
+ freeUnusedPages();
+ if (!_pages.empty())
+ warning("Memory leak found in pool");
+#endif
+
+ for (size_t i = 0; i < _pages.size(); ++i)
+ ::free(_pages[i].start);
+}
+
+void MemoryPool::allocPage() {
+ Page page;
+
+ // Allocate a new page
+ page.numChunks = _chunksPerPage;
+ assert(page.numChunks * _chunkSize < 16*1024*1024); // Refuse to allocate pages bigger than 16 MB
+
+ page.start = ::malloc(page.numChunks * _chunkSize);
+ assert(page.start);
+ _pages.push_back(page);
+
+
+ // Next time, we'll allocate a page twice as big as this one.
+ _chunksPerPage *= 2;
+
+ // Add the page to the pool of free chunk
+ addPageToPool(page);
+}
+
+void MemoryPool::addPageToPool(const Page &page) {
+ // Add all chunks of the new page to the linked list (pool) of free chunks
+ void *current = page.start;
+ for (size_t i = 1; i < page.numChunks; ++i) {
+ void *next = (byte *)current + _chunkSize;
+ *(void **)current = next;
+
+ current = next;
+ }
+
+ // Last chunk points to the old _next
+ *(void **)current = _next;
+
+ // From now on, the first free chunk is the first chunk of the new page
+ _next = page.start;
+}
+
+void *MemoryPool::allocChunk() {
+ // No free chunks left? Allocate a new page
+ if (!_next)
+ allocPage();
+
+ assert(_next);
+ void *result = _next;
+ _next = *(void **)result;
+ return result;
+}
+
+void MemoryPool::freeChunk(void *ptr) {
+ // Add the chunk back to (the start of) the list of free chunks
+ *(void **)ptr = _next;
+ _next = ptr;
+}
+
+// Technically not compliant C++ to compare unrelated pointers. In practice...
+bool MemoryPool::isPointerInPage(void *ptr, const Page &page) {
+ return (ptr >= page.start) && (ptr < (char *)page.start + page.numChunks * _chunkSize);
+}
+
+void MemoryPool::freeUnusedPages() {
+ //std::sort(_pages.begin(), _pages.end());
+ Array<size_t> numberOfFreeChunksPerPage;
+ numberOfFreeChunksPerPage.resize(_pages.size());
+ for (size_t i = 0; i < numberOfFreeChunksPerPage.size(); ++i) {
+ numberOfFreeChunksPerPage[i] = 0;
+ }
+
+ // Compute for each page how many chunks in it are still in use.
+ void *iterator = _next;
+ while (iterator) {
+ // TODO: This should be a binary search (requiring us to keep _pages sorted)
+ for (size_t i = 0; i < _pages.size(); ++i) {
+ if (isPointerInPage(iterator, _pages[i])) {
+ ++numberOfFreeChunksPerPage[i];
+ break;
+ }
+ }
+
+ iterator = *(void **)iterator;
+ }
+
+ // Free all pages which are not in use.
+ size_t freedPagesCount = 0;
+ for (size_t i = 0; i < _pages.size(); ++i) {
+ if (numberOfFreeChunksPerPage[i] == _pages[i].numChunks) {
+ // Remove all chunks of this page from the list of free chunks
+ void **iter2 = &_next;
+ while (*iter2) {
+ if (isPointerInPage(*iter2, _pages[i]))
+ *iter2 = **(void ***)iter2;
+ else
+ iter2 = *(void ***)iter2;
+ }
+
+ ::free(_pages[i].start);
+ ++freedPagesCount;
+ _pages[i].start = NULL;
+ }
+ }
+
+// debug("freed %d pages out of %d", (int)freedPagesCount, (int)_pages.size());
+
+ // Remove all now unused pages
+ size_t newSize = 0;
+ for (size_t i = 0; i < _pages.size(); ++i) {
+ if (_pages[i].start != NULL) {
+ if (newSize != i)
+ _pages[newSize] = _pages[i];
+ ++newSize;
+ }
+ }
+ _pages.resize(newSize);
+
+ // Reset _chunksPerPage
+ _chunksPerPage = INITIAL_CHUNKS_PER_PAGE;
+ for (size_t i = 0; i < _pages.size(); ++i) {
+ if (_chunksPerPage < _pages[i].numChunks)
+ _chunksPerPage = _pages[i].numChunks;
+ }
+}
+
+} // End of namespace Common
diff --git a/common/memorypool.h b/common/memorypool.h
new file mode 100644
index 000000000..b84012232
--- /dev/null
+++ b/common/memorypool.h
@@ -0,0 +1,163 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_MEMORYPOOL_H
+#define COMMON_MEMORYPOOL_H
+
+#include "common/scummsys.h"
+#include "common/array.h"
+
+
+namespace Common {
+
+/**
+ * This class provides a pool of memory 'chunks' of identical size.
+ * The size of a chunk is determined when creating the memory pool.
+ *
+ * Using a memory pool may yield better performance and memory usage
+ * when allocating and deallocating many memory blocks of equal size.
+ * E.g. the Common::String class uses a memory pool for the refCount
+ * variables (each the size of an int) it allocates for each string
+ * instance.
+ */
+class MemoryPool {
+protected:
+ MemoryPool(const MemoryPool&);
+ MemoryPool& operator=(const MemoryPool&);
+
+ struct Page {
+ void *start;
+ size_t numChunks;
+ };
+
+ const size_t _chunkSize;
+ Array<Page> _pages;
+ void *_next;
+ size_t _chunksPerPage;
+
+ void allocPage();
+ void addPageToPool(const Page &page);
+ bool isPointerInPage(void *ptr, const Page &page);
+
+public:
+ /**
+ * Constructor for a memory pool with the given chunk size.
+ * @param chunkSize the chunk size of this memory pool
+ */
+ explicit MemoryPool(size_t chunkSize);
+ ~MemoryPool();
+
+ /**
+ * Allocate a new chunk from the memory pool.
+ */
+ void *allocChunk();
+ /**
+ * Return a chunk to the memory pool. The given pointer must have
+ * been obtained from calling the allocChunk() method of the very
+ * same MemoryPool instance. Passing any other pointer (e.g. to
+ * a chunk from another MemoryPool, or a malloc'ed memory block)
+ * will lead to undefined behavior and may result in a crash (if
+ * you are lucky) or in silent data corruption.
+ */
+ void freeChunk(void *ptr);
+
+ /**
+ * Perform garbage collection. The memory pool stores all the
+ * chunks it manages in memory 'pages' obtained via the classic
+ * memory allocation APIs (i.e. malloc/free). Ordinarily, once
+ * a page has been allocated, it won't be released again during
+ * the life time of the memory pool. The exception is when this
+ * method is called.
+ */
+ void freeUnusedPages();
+
+ /**
+ * Return the chunk size used by this memory pool.
+ */
+ size_t getChunkSize() const { return _chunkSize; }
+};
+
+/**
+ * This is a memory pool which already contains in itself some storage
+ * space for a fixed number of chunks. Thus if the memory pool is only
+ * lightly used, no malloc() calls have to be made at all.
+ */
+template<size_t CHUNK_SIZE, size_t NUM_INTERNAL_CHUNKS = 32>
+class FixedSizeMemoryPool : public MemoryPool {
+private:
+ enum {
+ REAL_CHUNK_SIZE = (CHUNK_SIZE + sizeof(void *) - 1) & (~(sizeof(void *) - 1))
+ };
+
+ byte _storage[NUM_INTERNAL_CHUNKS * REAL_CHUNK_SIZE];
+public:
+ FixedSizeMemoryPool() : MemoryPool(CHUNK_SIZE) {
+ assert(REAL_CHUNK_SIZE == _chunkSize);
+ // Insert some static storage
+ Page internalPage = { _storage, NUM_INTERNAL_CHUNKS };
+ addPageToPool(internalPage);
+ }
+};
+
+// Ensure NUM_INTERNAL_CHUNKS == 0 results in a compile error
+template<size_t CHUNK_SIZE>
+class FixedSizeMemoryPool<CHUNK_SIZE,0> : public MemoryPool {
+public:
+ FixedSizeMemoryPool() : MemoryPool(CHUNK_SIZE) {}
+};
+
+/**
+ * A memory pool for C++ objects.
+ */
+template<class T, size_t NUM_INTERNAL_CHUNKS = 32>
+class ObjectPool : public FixedSizeMemoryPool<sizeof(T), NUM_INTERNAL_CHUNKS> {
+public:
+ /**
+ * Return the memory chunk used as storage for the given object back
+ * to the pool, after calling its destructor.
+ */
+ void deleteChunk(T *ptr) {
+ ptr->~T();
+ this->freeChunk(ptr);
+ }
+};
+
+} // End of namespace Common
+
+/**
+ * A custom placement new operator, using an arbitrary MemoryPool.
+ *
+ * This *should* work with all C++ implementations, but may not.
+ *
+ * For details on using placement new for custom allocators, see e.g.
+ * <http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.14>
+ */
+inline void *operator new(size_t nbytes, Common::MemoryPool &pool) {
+ assert(nbytes <= pool.getChunkSize());
+ return pool.allocChunk();
+}
+
+inline void operator delete(void *p, Common::MemoryPool &pool) {
+ pool.freeChunk(p);
+}
+
+#endif
diff --git a/common/module.mk b/common/module.mk
index 52c231917..d36d65509 100644
--- a/common/module.mk
+++ b/common/module.mk
@@ -1,7 +1,14 @@
MODULE := common
MODULE_OBJS := \
+ debug.o \
+ file.o \
+ hashmap.o \
md5.o \
+ memorypool.o \
+ str.o \
+ textconsole.o \
+ util.o \
zlib.o
# Include common rules
diff --git a/common/noncopyable.h b/common/noncopyable.h
new file mode 100644
index 000000000..24021f42a
--- /dev/null
+++ b/common/noncopyable.h
@@ -0,0 +1,43 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_NONCOPYABLE_H
+#define COMMON_NONCOPYABLE_H
+
+namespace Common {
+
+/**
+ * Subclass of NonCopyable can not be copied due to the fact that
+ * we made the copy constructor and assigment operator private.
+ */
+class NonCopyable {
+public:
+ NonCopyable() {}
+private:
+ // Prevent copying instances by accident
+ NonCopyable(const NonCopyable&);
+ NonCopyable& operator=(const NonCopyable&);
+};
+
+} // End of namespace Common
+
+#endif
diff --git a/common/pack-end.h b/common/pack-end.h
new file mode 100644
index 000000000..5fed5e577
--- /dev/null
+++ b/common/pack-end.h
@@ -0,0 +1,25 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#if defined(SCUMMVM_USE_PRAGMA_PACK)
+ #pragma pack()
+#endif
diff --git a/common/pack-start.h b/common/pack-start.h
new file mode 100644
index 000000000..cfb8968a5
--- /dev/null
+++ b/common/pack-start.h
@@ -0,0 +1,25 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#if defined(SCUMMVM_USE_PRAGMA_PACK)
+ #pragma pack(1)
+#endif
diff --git a/common/scummsys.h b/common/scummsys.h
index 39650ce1f..0971425dd 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -8,12 +8,12 @@
* 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.
@@ -23,6 +23,13 @@
#ifndef COMMON_SCUMMSYS_H
#define COMMON_SCUMMSYS_H
+#ifndef __has_feature // Optional of course.
+ #define __has_feature(x) 0 // Compatibility with non-clang compilers.
+#endif
+
+// This is a convenience macro to test whether the compiler used is a GCC
+// version, which is at least major.minor.
+#define GCC_ATLEAST(major, minor) (defined(__GNUC__) && (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))))
#if defined(_WIN32_WCE) && _WIN32_WCE < 300
#define NONSTANDARD_PORT
@@ -48,7 +55,7 @@
#include <stdio.h>
#include <stdarg.h>
- // MSVC's vsnprintf is either non-existant (2003) or bugged since it
+ // MSVC's vsnprintf is either non-existent (2003) or bugged since it
// does not always include a terminating NULL (2005+). To work around
// that we fix up the _vsnprintf included. Note that the return value
// will still not match C99's specs!
@@ -141,7 +148,67 @@
#endif
#endif
+// The following math constants are usually defined by the system math.h header, but
+// they are not part of the ANSI C++ standards and so can NOT be relied upon to be
+// present i.e. when -std=c++11 is passed to GCC, enabling strict ANSI compliance.
+// As we rely on these being present, we define them if they are not set.
+
+#ifndef M_E
+ #define M_E 2.7182818284590452354 /* e */
+#endif
+#ifndef M_LOG2E
+ #define M_LOG2E 1.4426950408889634074 /* log_2 e */
+#endif
+
+#ifndef M_LOG10E
+ #define M_LOG10E 0.43429448190325182765 /* log_10 e */
+#endif
+
+#ifndef M_LN2
+ #define M_LN2 0.69314718055994530942 /* log_e 2 */
+#endif
+
+#ifndef M_LN10
+ #define M_LN10 2.30258509299404568402 /* log_e 10 */
+#endif
+
+#ifndef M_PI
+ #define M_PI 3.14159265358979323846 /* pi */
+#endif
+
+#ifndef M_PI_2
+ #define M_PI_2 1.57079632679489661923 /* pi/2 */
+#endif
+
+#ifndef M_PI_4
+ #define M_PI_4 0.78539816339744830962 /* pi/4 */
+#endif
+
+#ifndef M_1_PI
+ #define M_1_PI 0.31830988618379067154 /* 1/pi */
+#endif
+
+#ifndef M_2_PI
+ #define M_2_PI 0.63661977236758134308 /* 2/pi */
+#endif
+
+#ifndef M_2_SQRTPI
+ #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
+#endif
+
+#ifndef M_SQRT2
+ #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
+#endif
+
+#ifndef M_SQRT1_2
+ #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
+#endif
+
+// Include our C++11 compatability header for pre-C++11 compilers.
+#if __cplusplus < 201103L
+#include "common/c++11-compat.h"
+#endif
// Use config.h, generated by configure
#if defined(HAVE_CONFIG_H)
@@ -268,7 +335,7 @@
#ifndef FORCEINLINE
#if defined(_MSC_VER)
#define FORCEINLINE __forceinline
- #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+ #elif GCC_ATLEAST(3, 1)
#define FORCEINLINE inline __attribute__((__always_inline__))
#else
#define FORCEINLINE inline
@@ -307,6 +374,7 @@
#endif
#endif
+// ResidualVM specific:
#ifndef LOCAL_PI
#define LOCAL_PI 3.14159265358979323846
#endif
@@ -320,7 +388,7 @@
#define scumm_va_copy va_copy
#elif defined(__va_copy)
#define scumm_va_copy __va_copy
- #elif defined(_MSC_VER) || defined (__SYMBIAN32__)
+ #elif defined(_MSC_VER) || defined(__SYMBIAN32__)
#define scumm_va_copy(dst, src) ((dst) = (src))
#else
#error scumm_va_copy undefined for this port
@@ -342,6 +410,8 @@
typedef unsigned int uint32;
typedef signed int int32;
typedef unsigned int uint;
+ typedef signed long long int64;
+ typedef unsigned long long uint64;
#endif
diff --git a/common/singleton.h b/common/singleton.h
new file mode 100644
index 000000000..13bdb0c3a
--- /dev/null
+++ b/common/singleton.h
@@ -0,0 +1,102 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_SINGLETON_H
+#define COMMON_SINGLETON_H
+
+#include "common/noncopyable.h"
+
+namespace Common {
+
+/**
+ * Generic template base class for implementing the singleton design pattern.
+ */
+template<class T>
+class Singleton : NonCopyable {
+private:
+ Singleton<T>(const Singleton<T> &);
+ Singleton<T> &operator=(const Singleton<T> &);
+
+ /**
+ * The default object factory used by the template class Singleton.
+ * By specialising this template function, one can make a singleton use a
+ * custom object factory. For example, to support encapsulation, your
+ * singleton class might be pure virtual (or "abstract" in Java terminology),
+ * and you specialise makeInstance to return an instance of a subclass.
+ */
+ //template<class T>
+#if defined(_WIN32_WCE) || defined(_MSC_VER) || defined(__WINS__)
+//FIXME evc4 and msvc7 doesn't like it as private member
+public:
+#endif
+ static T *makeInstance() {
+ return new T();
+ }
+
+ static void destroyInstance() {
+ delete _singleton;
+ _singleton = 0;
+ }
+
+
+public:
+ static T& instance() {
+ // TODO: We aren't thread safe. For now we ignore it since the
+ // only thing using this singleton template is the config manager,
+ // and that is first instantiated long before any threads.
+ // TODO: We don't leak, but the destruction order is nevertheless
+ // semi-random. If we use multiple singletons, the destruction
+ // order might become an issue. There are various approaches
+ // to solve that problem, but for now this is sufficient
+ if (!_singleton)
+ _singleton = T::makeInstance();
+ return *_singleton;
+ }
+
+ static void destroy() {
+ T::destroyInstance();
+ }
+protected:
+ Singleton<T>() { }
+#ifdef __SYMBIAN32__
+ virtual ~Singleton() { }
+#else
+ virtual ~Singleton<T>() { }
+#endif
+
+ typedef T SingletonBaseType;
+
+ static T *_singleton;
+};
+
+/**
+ * Note that you need to use this macro from the Common namespace.
+ *
+ * This is because C++ requires initial explicit specialization
+ * to be placed in the same namespace as the template.
+ */
+#define DECLARE_SINGLETON(T) \
+ template<> T *Singleton<T>::_singleton = 0
+
+} // End of namespace Common
+
+#endif
diff --git a/common/str.cpp b/common/str.cpp
new file mode 100644
index 000000000..faf84d722
--- /dev/null
+++ b/common/str.cpp
@@ -0,0 +1,906 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 "common/hash-str.h"
+#include "common/list.h"
+#include "common/memorypool.h"
+#include "common/str.h"
+#include "common/util.h"
+
+namespace Common {
+
+MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now
+
+static uint32 computeCapacity(uint32 len) {
+ // By default, for the capacity we use the next multiple of 32
+ return ((len + 32 - 1) & ~0x1F);
+}
+
+String::String(const char *str) : _size(0), _str(_storage) {
+ if (str == 0) {
+ _storage[0] = 0;
+ _size = 0;
+ } else
+ initWithCStr(str, strlen(str));
+}
+
+String::String(const char *str, uint32 len) : _size(0), _str(_storage) {
+ initWithCStr(str, len);
+}
+
+String::String(const char *beginP, const char *endP) : _size(0), _str(_storage) {
+ assert(endP >= beginP);
+ initWithCStr(beginP, endP - beginP);
+}
+
+void String::initWithCStr(const char *str, uint32 len) {
+ assert(str);
+
+ // Init _storage member explicitly (ie. without calling its constructor)
+ // for GCC 2.95.x compatibility (see also tracker item #1602879).
+ _storage[0] = 0;
+
+ _size = len;
+
+ if (len >= _builtinCapacity) {
+ // Not enough internal storage, so allocate more
+ _extern._capacity = computeCapacity(len+1);
+ _extern._refCount = 0;
+ _str = new char[_extern._capacity];
+ assert(_str != 0);
+ }
+
+ // Copy the string into the storage area
+ memmove(_str, str, len);
+ _str[len] = 0;
+}
+
+String::String(const String &str)
+ : _size(str._size) {
+ if (str.isStorageIntern()) {
+ // String in internal storage: just copy it
+ memcpy(_storage, str._storage, _builtinCapacity);
+ _str = _storage;
+ } else {
+ // String in external storage: use refcount mechanism
+ str.incRefCount();
+ _extern._refCount = str._extern._refCount;
+ _extern._capacity = str._extern._capacity;
+ _str = str._str;
+ }
+ assert(_str != 0);
+}
+
+String::String(char c)
+ : _size(0), _str(_storage) {
+
+ _storage[0] = c;
+ _storage[1] = 0;
+
+ _size = (c == 0) ? 0 : 1;
+}
+
+String::~String() {
+ decRefCount(_extern._refCount);
+}
+
+void String::makeUnique() {
+ ensureCapacity(_size, true);
+}
+
+/**
+ * Ensure that enough storage is available to store at least new_size
+ * characters plus a null byte. In addition, if we currently share
+ * the storage with another string, unshare it, so that we can safely
+ * write to the storage.
+ */
+void String::ensureCapacity(uint32 new_size, bool keep_old) {
+ bool isShared;
+ uint32 curCapacity, newCapacity;
+ char *newStorage;
+ int *oldRefCount = _extern._refCount;
+
+ if (isStorageIntern()) {
+ isShared = false;
+ curCapacity = _builtinCapacity;
+ } else {
+ isShared = (oldRefCount && *oldRefCount > 1);
+ curCapacity = _extern._capacity;
+ }
+
+ // Special case: If there is enough space, and we do not share
+ // the storage, then there is nothing to do.
+ if (!isShared && new_size < curCapacity)
+ return;
+
+ if (isShared && new_size < _builtinCapacity) {
+ // We share the storage, but there is enough internal storage: Use that.
+ newStorage = _storage;
+ newCapacity = _builtinCapacity;
+ } else {
+ // We need to allocate storage on the heap!
+
+ // Compute a suitable new capacity limit
+ // If the current capacity is sufficient we use the same capacity
+ if (new_size < curCapacity)
+ newCapacity = curCapacity;
+ else
+ newCapacity = MAX(curCapacity * 2, computeCapacity(new_size+1));
+
+ // Allocate new storage
+ newStorage = new char[newCapacity];
+ assert(newStorage);
+ }
+
+ // Copy old data if needed, elsewise reset the new storage.
+ if (keep_old) {
+ assert(_size < newCapacity);
+ memcpy(newStorage, _str, _size + 1);
+ } else {
+ _size = 0;
+ newStorage[0] = 0;
+ }
+
+ // Release hold on the old storage ...
+ decRefCount(oldRefCount);
+
+ // ... in favor of the new storage
+ _str = newStorage;
+
+ if (!isStorageIntern()) {
+ // Set the ref count & capacity if we use an external storage.
+ // It is important to do this *after* copying any old content,
+ // else we would override data that has not yet been copied!
+ _extern._refCount = 0;
+ _extern._capacity = newCapacity;
+ }
+}
+
+void String::incRefCount() const {
+ assert(!isStorageIntern());
+ if (_extern._refCount == 0) {
+ if (g_refCountPool == 0) {
+ g_refCountPool = new MemoryPool(sizeof(int));
+ assert(g_refCountPool);
+ }
+
+ _extern._refCount = (int *)g_refCountPool->allocChunk();
+ *_extern._refCount = 2;
+ } else {
+ ++(*_extern._refCount);
+ }
+}
+
+void String::decRefCount(int *oldRefCount) {
+ if (isStorageIntern())
+ return;
+
+ if (oldRefCount) {
+ --(*oldRefCount);
+ }
+ if (!oldRefCount || *oldRefCount <= 0) {
+ // The ref count reached zero, so we free the string storage
+ // and the ref count storage.
+ if (oldRefCount) {
+ assert(g_refCountPool);
+ g_refCountPool->freeChunk(oldRefCount);
+ }
+ delete[] _str;
+
+ // Even though _str points to a freed memory block now,
+ // we do not change its value, because any code that calls
+ // decRefCount will have to do this afterwards anyway.
+ }
+}
+
+String &String::operator=(const char *str) {
+ uint32 len = strlen(str);
+ ensureCapacity(len, false);
+ _size = len;
+ memmove(_str, str, len + 1);
+ return *this;
+}
+
+String &String::operator=(const String &str) {
+ if (&str == this)
+ return *this;
+
+ if (str.isStorageIntern()) {
+ decRefCount(_extern._refCount);
+ _size = str._size;
+ _str = _storage;
+ memcpy(_str, str._str, _size + 1);
+ } else {
+ str.incRefCount();
+ decRefCount(_extern._refCount);
+
+ _extern._refCount = str._extern._refCount;
+ _extern._capacity = str._extern._capacity;
+ _size = str._size;
+ _str = str._str;
+ }
+
+ return *this;
+}
+
+String &String::operator=(char c) {
+ decRefCount(_extern._refCount);
+ _str = _storage;
+
+ _str[0] = c;
+ _str[1] = 0;
+
+ _size = (c == 0) ? 0 : 1;
+ return *this;
+}
+
+String &String::operator+=(const char *str) {
+ if (_str <= str && str <= _str + _size)
+ return operator+=(String(str));
+
+ int len = strlen(str);
+ if (len > 0) {
+ ensureCapacity(_size + len, true);
+
+ memcpy(_str + _size, str, len + 1);
+ _size += len;
+ }
+ return *this;
+}
+
+String &String::operator+=(const String &str) {
+ if (&str == this)
+ return operator+=(String(str));
+
+ int len = str._size;
+ if (len > 0) {
+ ensureCapacity(_size + len, true);
+
+ memcpy(_str + _size, str._str, len + 1);
+ _size += len;
+ }
+ return *this;
+}
+
+String &String::operator+=(char c) {
+ ensureCapacity(_size + 1, true);
+
+ _str[_size++] = c;
+ _str[_size] = 0;
+
+ return *this;
+}
+
+bool String::hasPrefix(const String &x) const {
+ return hasPrefix(x.c_str());
+}
+
+bool String::hasPrefix(const char *x) const {
+ assert(x != 0);
+ // Compare x with the start of _str.
+ const char *y = c_str();
+ while (*x && *x == *y) {
+ ++x;
+ ++y;
+ }
+ // It's a prefix, if and only if all letters in x are 'used up' before
+ // _str ends.
+ return *x == 0;
+}
+
+bool String::hasSuffix(const String &x) const {
+ return hasSuffix(x.c_str());
+}
+
+bool String::hasSuffix(const char *x) const {
+ assert(x != 0);
+ // Compare x with the end of _str.
+ const uint32 x_size = strlen(x);
+ if (x_size > _size)
+ return false;
+ const char *y = c_str() + _size - x_size;
+ while (*x && *x == *y) {
+ ++x;
+ ++y;
+ }
+ // It's a suffix, if and only if all letters in x are 'used up' before
+ // _str ends.
+ return *x == 0;
+}
+
+bool String::contains(const String &x) const {
+ return strstr(c_str(), x.c_str()) != NULL;
+}
+
+bool String::contains(const char *x) const {
+ assert(x != 0);
+ return strstr(c_str(), x) != NULL;
+}
+
+bool String::contains(char x) const {
+ return strchr(c_str(), x) != NULL;
+}
+
+bool String::matchString(const char *pat, bool ignoreCase, bool pathMode) const {
+ return Common::matchString(c_str(), pat, ignoreCase, pathMode);
+}
+
+bool String::matchString(const String &pat, bool ignoreCase, bool pathMode) const {
+ return Common::matchString(c_str(), pat.c_str(), ignoreCase, pathMode);
+}
+
+void String::deleteLastChar() {
+ if (_size > 0)
+ deleteChar(_size - 1);
+}
+
+void String::deleteChar(uint32 p) {
+ assert(p < _size);
+
+ makeUnique();
+ while (p++ < _size)
+ _str[p - 1] = _str[p];
+ _size--;
+}
+
+void String::erase(uint32 p, uint32 len) {
+ assert(p < _size);
+
+ makeUnique();
+ // If len == npos or p + len is over the end, remove all the way to the end
+ if (len == npos || p + len >= _size) {
+ // Delete char at p as well. So _size = (p - 1) + 1
+ _size = p;
+ // Null terminate
+ _str[_size] = 0;
+ return;
+ }
+
+ for ( ; p + len <= _size; p++) {
+ _str[p] = _str[p + len];
+ }
+ _size -= len;
+}
+
+void String::clear() {
+ decRefCount(_extern._refCount);
+
+ _size = 0;
+ _str = _storage;
+ _storage[0] = 0;
+}
+
+void String::setChar(char c, uint32 p) {
+ assert(p < _size);
+
+ makeUnique();
+ _str[p] = c;
+}
+
+void String::insertChar(char c, uint32 p) {
+ assert(p <= _size);
+
+ ensureCapacity(_size + 1, true);
+ _size++;
+ for (uint32 i = _size; i > p; --i)
+ _str[i] = _str[i - 1];
+ _str[p] = c;
+}
+
+void String::toLowercase() {
+ makeUnique();
+ for (uint32 i = 0; i < _size; ++i)
+ _str[i] = tolower(_str[i]);
+}
+
+void String::toUppercase() {
+ makeUnique();
+ for (uint32 i = 0; i < _size; ++i)
+ _str[i] = toupper(_str[i]);
+}
+
+void String::trim() {
+ if (_size == 0)
+ return;
+
+ makeUnique();
+
+ // Trim trailing whitespace
+ while (_size >= 1 && isSpace(_str[_size - 1]))
+ --_size;
+ _str[_size] = 0;
+
+ // Trim leading whitespace
+ char *t = _str;
+ while (isSpace(*t))
+ t++;
+
+ if (t != _str) {
+ _size -= t - _str;
+ memmove(_str, t, _size + 1);
+ }
+}
+
+uint String::hash() const {
+ return hashit(c_str());
+}
+
+// static
+String String::format(const char *fmt, ...) {
+ String output;
+
+ va_list va;
+ va_start(va, fmt);
+ output = String::vformat(fmt, va);
+ va_end(va);
+
+ return output;
+}
+
+// static
+String String::vformat(const char *fmt, va_list args) {
+ String output;
+ assert(output.isStorageIntern());
+
+ va_list va;
+ scumm_va_copy(va, args);
+ int len = vsnprintf(output._str, _builtinCapacity, fmt, va);
+ va_end(va);
+
+ if (len == -1 || len == _builtinCapacity - 1) {
+ // MSVC and IRIX don't return the size the full string would take up.
+ // MSVC returns -1, IRIX returns the number of characters actually written,
+ // which is at the most the size of the buffer minus one, as the string is
+ // truncated to fit.
+
+ // We assume MSVC failed to output the correct, null-terminated string
+ // if the return value is either -1 or size.
+ // For IRIX, because we lack a better mechanism, we assume failure
+ // if the return value equals size - 1.
+ // The downside to this is that whenever we try to format a string where the
+ // size is 1 below the built-in capacity, the size is needlessly increased.
+
+ // Try increasing the size of the string until it fits.
+ int size = _builtinCapacity;
+ do {
+ size *= 2;
+ output.ensureCapacity(size - 1, false);
+ assert(!output.isStorageIntern());
+ size = output._extern._capacity;
+
+ scumm_va_copy(va, args);
+ len = vsnprintf(output._str, size, fmt, va);
+ va_end(va);
+ } while (len == -1 || len >= size - 1);
+ output._size = len;
+ } else if (len < (int)_builtinCapacity) {
+ // vsnprintf succeeded
+ output._size = len;
+ } else {
+ // vsnprintf didn't have enough space, so grow buffer
+ output.ensureCapacity(len, false);
+ scumm_va_copy(va, args);
+ int len2 = vsnprintf(output._str, len+1, fmt, va);
+ va_end(va);
+ assert(len == len2);
+ output._size = len2;
+ }
+
+ return output;
+}
+
+
+#pragma mark -
+
+bool String::operator==(const String &x) const {
+ return equals(x);
+}
+
+bool String::operator==(const char *x) const {
+ assert(x != 0);
+ return equals(x);
+}
+
+bool String::operator!=(const String &x) const {
+ return !equals(x);
+}
+
+bool String::operator !=(const char *x) const {
+ assert(x != 0);
+ return !equals(x);
+}
+
+bool String::operator<(const String &x) const {
+ return compareTo(x) < 0;
+}
+
+bool String::operator<=(const String &x) const {
+ return compareTo(x) <= 0;
+}
+
+bool String::operator>(const String &x) const {
+ return compareTo(x) > 0;
+}
+
+bool String::operator>=(const String &x) const {
+ return compareTo(x) >= 0;
+}
+
+#pragma mark -
+
+bool operator==(const char* y, const String &x) {
+ return (x == y);
+}
+
+bool operator!=(const char* y, const String &x) {
+ return x != y;
+}
+
+#pragma mark -
+
+bool String::equals(const String &x) const {
+ return (0 == compareTo(x));
+}
+
+bool String::equals(const char *x) const {
+ assert(x != 0);
+ return (0 == compareTo(x));
+}
+
+bool String::equalsIgnoreCase(const String &x) const {
+ return (0 == compareToIgnoreCase(x));
+}
+
+bool String::equalsIgnoreCase(const char *x) const {
+ assert(x != 0);
+ return (0 == compareToIgnoreCase(x));
+}
+
+int String::compareTo(const String &x) const {
+ return compareTo(x.c_str());
+}
+
+int String::compareTo(const char *x) const {
+ assert(x != 0);
+ return strcmp(c_str(), x);
+}
+
+int String::compareToIgnoreCase(const String &x) const {
+ return compareToIgnoreCase(x.c_str());
+}
+
+int String::compareToIgnoreCase(const char *x) const {
+ assert(x != 0);
+ return scumm_stricmp(c_str(), x);
+}
+
+#pragma mark -
+
+String operator+(const String &x, const String &y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator+(const char *x, const String &y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator+(const String &x, const char *y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator+(char x, const String &y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator+(const String &x, char y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+char *ltrim(char *t) {
+ while (isSpace(*t))
+ t++;
+ return t;
+}
+
+char *rtrim(char *t) {
+ int l = strlen(t) - 1;
+ while (l >= 0 && isSpace(t[l]))
+ t[l--] = 0;
+ return t;
+}
+
+char *trim(char *t) {
+ return rtrim(ltrim(t));
+}
+
+String lastPathComponent(const String &path, const char sep) {
+ const char *str = path.c_str();
+ const char *last = str + path.size();
+
+ // Skip over trailing slashes
+ while (last > str && *(last-1) == sep)
+ --last;
+
+ // Path consisted of only slashes -> return empty string
+ if (last == str)
+ return String();
+
+ // Now scan the whole component
+ const char *first = last - 1;
+ while (first > str && *first != sep)
+ --first;
+
+ if (*first == sep)
+ first++;
+
+ return String(first, last);
+}
+
+String normalizePath(const String &path, const char sep) {
+ if (path.empty())
+ return path;
+
+ const char *cur = path.c_str();
+ String result;
+
+ // If there is a leading slash, preserve that:
+ if (*cur == sep) {
+ result += sep;
+ // Skip over multiple leading slashes, so "//" equals "/"
+ while (*cur == sep)
+ ++cur;
+ }
+
+ // Scan for path components till the end of the String
+ List<String> comps;
+ while (*cur != 0) {
+ const char *start = cur;
+
+ // Scan till the next path separator resp. the end of the string
+ while (*cur != sep && *cur != 0)
+ cur++;
+
+ const String component(start, cur);
+
+ if (component.empty() || component == ".") {
+ // Skip empty components and dot components
+ } else if (!comps.empty() && component == ".." && comps.back() != "..") {
+ // If stack is non-empty and top is not "..", remove top
+ comps.pop_back();
+ } else {
+ // Add the component to the stack
+ comps.push_back(component);
+ }
+
+ // Skip over separator chars
+ while (*cur == sep)
+ cur++;
+ }
+
+ // Finally, assemble all components back into a path
+ while (!comps.empty()) {
+ result += comps.front();
+ comps.pop_front();
+ if (!comps.empty())
+ result += sep;
+ }
+
+ return result;
+}
+
+bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMode) {
+ assert(str);
+ assert(pat);
+
+ const char *p = 0;
+ const char *q = 0;
+
+ for (;;) {
+ if (pathMode && *str == '/') {
+ p = 0;
+ q = 0;
+ if (*pat == '?')
+ return false;
+ }
+
+ switch (*pat) {
+ case '*':
+ if (*str) {
+ // Record pattern / string position for backtracking
+ p = ++pat;
+ q = str;
+ } else {
+ // If we've reached the end of str, we can't backtrack further
+ // NB: We can't simply check if pat also ended here, because
+ // the pattern might end with any number of *s.
+ ++pat;
+ p = 0;
+ q = 0;
+ }
+ // If pattern ended with * -> match
+ if (!*pat)
+ return true;
+ break;
+
+ default:
+ if ((!ignoreCase && *pat != *str) ||
+ (ignoreCase && tolower(*pat) != tolower(*str))) {
+ if (p) {
+ // No match, oops -> try to backtrack
+ pat = p;
+ str = ++q;
+ if (!*str)
+ return !*pat;
+ break;
+ }
+ else
+ return false;
+ }
+ // fallthrough
+ case '?':
+ if (!*str)
+ return !*pat;
+ pat++;
+ str++;
+ }
+ }
+}
+
+String tag2string(uint32 tag) {
+ char str[5];
+ str[0] = (char)(tag >> 24);
+ str[1] = (char)(tag >> 16);
+ str[2] = (char)(tag >> 8);
+ str[3] = (char)tag;
+ str[4] = '\0';
+ // Replace non-printable chars by dot
+ for (int i = 0; i < 4; ++i) {
+ if (!Common::isPrint(str[i]))
+ str[i] = '.';
+ }
+ return String(str);
+}
+
+size_t strlcpy(char *dst, const char *src, size_t size) {
+ // Our backup of the source's start, we need this
+ // to calculate the source's length.
+ const char * const srcStart = src;
+
+ // In case a non-empty size was specified we
+ // copy over (size - 1) bytes at max.
+ if (size != 0) {
+ // Copy over (size - 1) bytes at max.
+ while (--size != 0) {
+ if ((*dst++ = *src) == 0)
+ break;
+ ++src;
+ }
+
+ // In case the source string was longer than the
+ // destination, we need to add a terminating
+ // zero.
+ if (size == 0)
+ *dst = 0;
+ }
+
+ // Move to the terminating zero of the source
+ // string, we need this to determine the length
+ // of the source string.
+ while (*src)
+ ++src;
+
+ // Return the source string's length.
+ return src - srcStart;
+}
+
+size_t strlcat(char *dst, const char *src, size_t size) {
+ // In case the destination buffer does not contain
+ // space for at least 1 character, we will just
+ // return the source string's length.
+ if (size == 0)
+ return strlen(src);
+
+ // Our backup of the source's start, we need this
+ // to calculate the source's length.
+ const char * const srcStart = src;
+
+ // Our backup of the destination's start, we need
+ // this to calculate the destination's length.
+ const char * const dstStart = dst;
+
+ // Search the end of the destination, but do not
+ // move past the terminating zero.
+ while (size-- != 0 && *dst != 0)
+ ++dst;
+
+ // Calculate the destination's length;
+ const size_t dstLength = dst - dstStart;
+
+ // In case we reached the end of the destination
+ // buffer before we had a chance to append any
+ // characters we will just return the destination
+ // length plus the source string's length.
+ if (size == 0)
+ return dstLength + strlen(srcStart);
+
+ // Copy over all of the source that fits
+ // the destination buffer. We also need
+ // to take the terminating zero we will
+ // add into consideration.
+ while (size-- != 0 && *src != 0)
+ *dst++ = *src++;
+ *dst = 0;
+
+ // Move to the terminating zero of the source
+ // string, we need this to determine the length
+ // of the source string.
+ while (*src)
+ ++src;
+
+ // Return the total length of the result string
+ return dstLength + (src - srcStart);
+}
+
+} // End of namespace Common
+
+// Portable implementation of stricmp / strcasecmp / strcmpi.
+// TODO: Rename this to Common::strcasecmp
+int scumm_stricmp(const char *s1, const char *s2) {
+ byte l1, l2;
+ do {
+ // Don't use ++ inside tolower, in case the macro uses its
+ // arguments more than once.
+ l1 = (byte)*s1++;
+ l1 = tolower(l1);
+ l2 = (byte)*s2++;
+ l2 = tolower(l2);
+ } while (l1 == l2 && l1 != 0);
+ return l1 - l2;
+}
+
+// Portable implementation of strnicmp / strncasecmp / strncmpi.
+// TODO: Rename this to Common::strncasecmp
+int scumm_strnicmp(const char *s1, const char *s2, uint n) {
+ byte l1, l2;
+ do {
+ if (n-- == 0)
+ return 0; // no difference found so far -> signal equality
+
+ // Don't use ++ inside tolower, in case the macro uses its
+ // arguments more than once.
+ l1 = (byte)*s1++;
+ l1 = tolower(l1);
+ l2 = (byte)*s2++;
+ l2 = tolower(l2);
+ } while (l1 == l2 && l1 != 0);
+ return l1 - l2;
+}
diff --git a/common/str.h b/common/str.h
new file mode 100644
index 000000000..a2451f2f6
--- /dev/null
+++ b/common/str.h
@@ -0,0 +1,408 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_STRING_H
+#define COMMON_STRING_H
+
+#include "common/scummsys.h"
+
+#include <stdarg.h>
+
+namespace Common {
+
+/**
+ * Simple string class for ScummVM. Provides automatic storage managment,
+ * and overloads several operators in a 'natural' fashion, mimicking
+ * the std::string class. Even provides simple iterators.
+ *
+ * This class tries to avoid allocating lots of small blocks on the heap,
+ * since that is inefficient on several platforms supported by ScummVM.
+ * Instead, small strings are stored 'inside' the string object (i.e. on
+ * the stack, for stack allocated objects), and only for strings exceeding
+ * a certain length do we allocate a buffer on the heap.
+ *
+ * The presence of \0 characters in the string will cause undefined
+ * behavior in some operations.
+ */
+class String {
+public:
+ static const uint32 npos = 0xFFFFFFFF;
+protected:
+ /**
+ * The size of the internal storage. Increasing this means less heap
+ * allocations are needed, at the cost of more stack memory usage,
+ * and of course lots of wasted memory. Empirically, 90% or more of
+ * all String instances are less than 32 chars long. If a platform
+ * is very short on stack space, it would be possible to lower this.
+ * A value of 24 still seems acceptable, though considerably worse,
+ * while 16 seems to be the lowest you want to go... Anything lower
+ * than 8 makes no sense, since that's the size of member _extern
+ * (on 32 bit machines; 12 bytes on systems with 64bit pointers).
+ */
+ static const uint32 _builtinCapacity = 32 - sizeof(uint32) - sizeof(char *);
+
+ /**
+ * Length of the string. Stored to avoid having to call strlen
+ * a lot. Yes, we limit ourselves to strings shorter than 4GB --
+ * on purpose :-).
+ */
+ uint32 _size;
+
+ /**
+ * Pointer to the actual string storage. Either points to _storage,
+ * or to a block allocated on the heap via malloc.
+ */
+ char *_str;
+
+
+ union {
+ /**
+ * Internal string storage.
+ */
+ char _storage[_builtinCapacity];
+ /**
+ * External string storage data -- the refcounter, and the
+ * capacity of the string _str points to.
+ */
+ struct {
+ mutable int *_refCount;
+ uint32 _capacity;
+ } _extern;
+ };
+
+ inline bool isStorageIntern() const {
+ return _str == _storage;
+ }
+
+public:
+ /** Construct a new empty string. */
+ String() : _size(0), _str(_storage) { _storage[0] = 0; }
+
+ /** Construct a new string from the given NULL-terminated C string. */
+ String(const char *str);
+
+ /** Construct a new string containing exactly len characters read from address str. */
+ String(const char *str, uint32 len);
+
+ /** Construct a new string containing the characters between beginP (including) and endP (excluding). */
+ String(const char *beginP, const char *endP);
+
+ /** Construct a copy of the given string. */
+ String(const String &str);
+
+ /** Construct a string consisting of the given character. */
+ explicit String(char c);
+
+ ~String();
+
+ String &operator=(const char *str);
+ String &operator=(const String &str);
+ String &operator=(char c);
+ String &operator+=(const char *str);
+ String &operator+=(const String &str);
+ String &operator+=(char c);
+
+ bool operator==(const String &x) const;
+ bool operator==(const char *x) const;
+ bool operator!=(const String &x) const;
+ bool operator!=(const char *x) const;
+
+ bool operator<(const String &x) const;
+ bool operator<=(const String &x) const;
+ bool operator>(const String &x) const;
+ bool operator>=(const String &x) const;
+
+ bool equals(const String &x) const;
+ bool equalsIgnoreCase(const String &x) const;
+ int compareTo(const String &x) const; // strcmp clone
+ int compareToIgnoreCase(const String &x) const; // stricmp clone
+
+ bool equals(const char *x) const;
+ bool equalsIgnoreCase(const char *x) const;
+ int compareTo(const char *x) const; // strcmp clone
+ int compareToIgnoreCase(const char *x) const; // stricmp clone
+
+ bool hasSuffix(const String &x) const;
+ bool hasSuffix(const char *x) const;
+
+ bool hasPrefix(const String &x) const;
+ bool hasPrefix(const char *x) const;
+
+ bool contains(const String &x) const;
+ bool contains(const char *x) const;
+ bool contains(char x) const;
+
+ /**
+ * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
+ * Taken from exult/files/listfiles.cc
+ *
+ * Token meaning:
+ * "*": any character, any amount of times.
+ * "?": any character, only once.
+ *
+ * Example strings/patterns:
+ * String: monkey.s01 Pattern: monkey.s?? => true
+ * String: monkey.s101 Pattern: monkey.s?? => false
+ * String: monkey.s99 Pattern: monkey.s?1 => false
+ * String: monkey.s101 Pattern: monkey.s* => true
+ * String: monkey.s99 Pattern: monkey.s*1 => false
+ *
+ * @param str Text to be matched against the given pattern.
+ * @param pat Glob pattern.
+ * @param ignoreCase Whether to ignore the case when doing pattern match
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
+ *
+ * @return true if str matches the pattern, false otherwise.
+ */
+ bool matchString(const char *pat, bool ignoreCase = false, bool pathMode = false) const;
+ bool matchString(const String &pat, bool ignoreCase = false, bool pathMode = false) const;
+
+
+ inline const char *c_str() const { return _str; }
+ inline uint size() const { return _size; }
+
+ inline bool empty() const { return (_size == 0); }
+ char lastChar() const { return (_size > 0) ? _str[_size - 1] : 0; }
+
+ char operator[](int idx) const {
+ assert(_str && idx >= 0 && idx < (int)_size);
+ return _str[idx];
+ }
+
+ /** Remove the last character from the string. */
+ void deleteLastChar();
+
+ /** Remove the character at position p from the string. */
+ void deleteChar(uint32 p);
+
+ /** Remove all characters from position p to the p + len. If len = String::npos, removes all characters to the end */
+ void erase(uint32 p, uint32 len = npos);
+
+ /** Set character c at position p, replacing the previous character there. */
+ void setChar(char c, uint32 p);
+
+ /** Insert character c before position p. */
+ void insertChar(char c, uint32 p);
+
+ /** Clears the string, making it empty. */
+ void clear();
+
+ /** Convert all characters in the string to lowercase. */
+ void toLowercase();
+
+ /** Convert all characters in the string to uppercase. */
+ void toUppercase();
+
+ /**
+ * Removes trailing and leading whitespaces. Uses isspace() to decide
+ * what is whitespace and what not.
+ */
+ void trim();
+
+ uint hash() const;
+
+ /**
+ * Print formatted data into a String object. Similar to sprintf,
+ * except that it stores the result in (variably sized) String
+ * instead of a fixed size buffer.
+ */
+ static String format(const char *fmt, ...) GCC_PRINTF(1,2);
+
+ /**
+ * Print formatted data into a String object. Similar to vsprintf,
+ * except that it stores the result in (variably sized) String
+ * instead of a fixed size buffer.
+ */
+ static String vformat(const char *fmt, va_list args);
+
+public:
+ typedef char value_type;
+ /**
+ * Unsigned version of the underlying type. This can be used to cast
+ * individual string characters to bigger integer types without sign
+ * extension happening.
+ */
+ typedef unsigned char unsigned_type;
+ typedef char * iterator;
+ typedef const char * const_iterator;
+
+ iterator begin() {
+ // Since the user could potentially
+ // change the string via the returned
+ // iterator we have to assure we are
+ // pointing to a unique storage.
+ makeUnique();
+
+ return _str;
+ }
+
+ iterator end() {
+ return begin() + size();
+ }
+
+ const_iterator begin() const {
+ return _str;
+ }
+
+ const_iterator end() const {
+ return begin() + size();
+ }
+
+protected:
+ void makeUnique();
+ void ensureCapacity(uint32 new_size, bool keep_old);
+ void incRefCount() const;
+ void decRefCount(int *oldRefCount);
+ void initWithCStr(const char *str, uint32 len);
+};
+
+// Append two strings to form a new (temp) string
+String operator+(const String &x, const String &y);
+
+String operator+(const char *x, const String &y);
+String operator+(const String &x, const char *y);
+
+String operator+(const String &x, char y);
+String operator+(char x, const String &y);
+
+// Some useful additional comparison operators for Strings
+bool operator==(const char *x, const String &y);
+bool operator!=(const char *x, const String &y);
+
+// Utility functions to remove leading and trailing whitespaces
+extern char *ltrim(char *t);
+extern char *rtrim(char *t);
+extern char *trim(char *t);
+
+
+/**
+ * Returns the last component of a given path.
+ *
+ * Examples:
+ * /foo/bar.txt would return 'bar.txt'
+ * /foo/bar/ would return 'bar'
+ * /foo/./bar// would return 'bar'
+ *
+ * @param path the path of which we want to know the last component
+ * @param sep character used to separate path components
+ * @return The last component of the path.
+ */
+String lastPathComponent(const String &path, const char sep);
+
+/**
+ * Normalize a given path to a canonical form. In particular:
+ * - trailing separators are removed: /foo/bar/ -> /foo/bar
+ * - double separators (= empty components) are removed: /foo//bar -> /foo/bar
+ * - dot components are removed: /foo/./bar -> /foo/bar
+ *
+ * @todo remove double dot components: /foo/baz/../bar -> /foo/bar
+ *
+ * @param path the path to normalize
+ * @param sep the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff)
+ * @return the normalized path
+ */
+String normalizePath(const String &path, const char sep);
+
+
+/**
+ * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
+ * Taken from exult/files/listfiles.cc
+ *
+ * Token meaning:
+ * "*": any character, any amount of times.
+ * "?": any character, only once.
+ *
+ * Example strings/patterns:
+ * String: monkey.s01 Pattern: monkey.s?? => true
+ * String: monkey.s101 Pattern: monkey.s?? => false
+ * String: monkey.s99 Pattern: monkey.s?1 => false
+ * String: monkey.s101 Pattern: monkey.s* => true
+ * String: monkey.s99 Pattern: monkey.s*1 => false
+ *
+ * @param str Text to be matched against the given pattern.
+ * @param pat Glob pattern.
+ * @param ignoreCase Whether to ignore the case when doing pattern match
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
+ *
+ * @return true if str matches the pattern, false otherwise.
+ */
+bool matchString(const char *str, const char *pat, bool ignoreCase = false, bool pathMode = false);
+
+
+/**
+ * Take a 32 bit value and turn it into a four character string, where each of
+ * the four bytes is turned into one character. Most significant byte is printed
+ * first.
+ */
+String tag2string(uint32 tag);
+
+/**
+ * Copy up to size - 1 characters from src to dst and also zero terminate the
+ * result. Note that src must be a zero terminated string.
+ *
+ * In case size is zero this function just returns the length of the source
+ * string.
+ *
+ * @note This is modeled after OpenBSD's strlcpy. See the manpage here:
+ * http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy
+ *
+ * @param dst The destination buffer.
+ * @param src The source string.
+ * @param size The size of the destination buffer.
+ * @return The length of the (non-truncated) result, i.e. strlen(src).
+ */
+size_t strlcpy(char *dst, const char *src, size_t size);
+
+/**
+ * Append the string src to the string dst. Note that both src and dst must be
+ * zero terminated. The result will be zero terminated. At most
+ * "size - strlen(dst) - 1" bytes will be appended.
+ *
+ * In case the dst string does not contain a zero within the first "size" bytes
+ * the dst string will not be changed and size + strlen(src) is returned.
+ *
+ * @note This is modeled after OpenBSD's strlcat. See the manpage here:
+ * http://www.openbsd.org/cgi-bin/man.cgi?query=strlcat
+ *
+ * @param dst The string the source string should be appended to.
+ * @param src The source string.
+ * @param size The (total) size of the destination buffer.
+ * @return The length of the (non-truncated) result. That is
+ * strlen(dst) + strlen(src). In case strlen(dst) > size
+ * size + strlen(src) is returned.
+ */
+size_t strlcat(char *dst, const char *src, size_t size);
+
+/**
+ * Convenience wrapper for tag2string which "returns" a C string.
+ * Note: It is *NOT* safe to do anything with the return value other than directly
+ * copying or printing it.
+ */
+#define tag2str(x) Common::tag2string(x).c_str()
+
+
+} // End of namespace Common
+
+extern int scumm_stricmp(const char *s1, const char *s2);
+extern int scumm_strnicmp(const char *s1, const char *s2, uint n);
+
+#endif
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
new file mode 100644
index 000000000..152b00d93
--- /dev/null
+++ b/common/textconsole.cpp
@@ -0,0 +1,96 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#define FORBIDDEN_SYMBOL_EXCEPTION_exit
+
+#include "common/textconsole.h"
+#include "common/str.h"
+
+namespace Common {
+
+static OutputFormatter s_errorOutputFormatter = 0;
+
+void setErrorOutputFormatter(OutputFormatter f) {
+ s_errorOutputFormatter = f;
+}
+
+static ErrorHandler s_errorHandler = 0;
+
+void setErrorHandler(ErrorHandler handler) {
+ s_errorHandler = handler;
+}
+
+
+} // End of namespace Common
+
+
+#ifndef DISABLE_TEXT_CONSOLE
+
+void warning(const char *s, ...) {
+ Common::String output;
+ va_list va;
+
+ va_start(va, s);
+ output = Common::String::vformat(s, va);
+ va_end(va);
+
+ output = "WARNING: " + output + "!\n";
+
+ printf(output.c_str());
+}
+
+#endif
+
+void NORETURN_PRE error(const char *s, ...) {
+ // We don't use String::vformat here, as that require
+ // using the heap, and that might be impossible at this
+ // point, e.g. if the error was an "out-of-memory" error.
+ char buf_input[STRINGBUFLEN];
+ char buf_output[STRINGBUFLEN];
+ va_list va;
+
+ // Generate the full error message
+ va_start(va, s);
+ vsnprintf(buf_input, STRINGBUFLEN, s, va);
+ va_end(va);
+
+
+ // Next, give the active engine (if any) a chance to augment the message
+ if (Common::s_errorOutputFormatter) {
+ (*Common::s_errorOutputFormatter)(buf_output, buf_input, STRINGBUFLEN);
+ } else {
+ strncpy(buf_output, buf_input, STRINGBUFLEN);
+ }
+
+ buf_output[STRINGBUFLEN - 3] = '\0';
+ buf_output[STRINGBUFLEN - 2] = '\0';
+ buf_output[STRINGBUFLEN - 1] = '\0';
+ strcat(buf_output, "!\n");
+
+ printf(buf_output);
+
+ // If there is an error handler, invoke it now
+ if (Common::s_errorHandler)
+ (*Common::s_errorHandler)(buf_output);
+
+ exit(1);
+}
diff --git a/common/textconsole.h b/common/textconsole.h
new file mode 100644
index 000000000..e7654dd7e
--- /dev/null
+++ b/common/textconsole.h
@@ -0,0 +1,81 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_CONSOLE_H
+#define COMMON_CONSOLE_H
+
+#include "common/scummsys.h"
+
+namespace Common {
+
+/**
+ * An output formatter takes a source string and 'decorates' it with
+ * extra information, storing the result in a destination buffer.
+ * A typical use is to (optionally) enhance the output given by
+ * the error() and debug() functions with extra information on
+ * the state of the active engine.
+ */
+typedef void (*OutputFormatter)(char *dst, const char *src, size_t dstSize);
+
+/**
+ * Set the output formatter used by error().
+ */
+void setErrorOutputFormatter(OutputFormatter f);
+
+
+/**
+ * A callback which is invoked by error() just before aborting.
+ * A typical example would be a function which shows a debug
+ * console and displays the given message in it.
+ */
+typedef void (*ErrorHandler)(const char *msg);
+
+/**
+ * Set a callback that is invoked by error() after the error
+ * message has been printed, but before the application is
+ * terminated.
+ * This can be used to e.g. show a debugger console.
+ */
+void setErrorHandler(ErrorHandler handler);
+
+} // End of namespace Common
+
+
+void NORETURN_PRE error(const char *s, ...) GCC_PRINTF(1, 2) NORETURN_POST;
+
+#ifdef DISABLE_TEXT_CONSOLE
+
+inline void warning(const char *s, ...) {}
+
+#else
+
+/**
+ * Print a warning message to the text console (stderr).
+ * Automatically prepends the text "WARNING: " and appends
+ * an exclamation mark and a newline.
+ */
+void warning(const char *s, ...) GCC_PRINTF(1, 2);
+
+#endif
+
+
+#endif
diff --git a/common/tool_exception.h b/common/tool_exception.h
new file mode 100644
index 000000000..fc900b61c
--- /dev/null
+++ b/common/tool_exception.h
@@ -0,0 +1,56 @@
+/* ScummVM Tools
+ *
+ * ScummVM Tools is the legal property of its developers, whose
+ * names are too numerous to list here. Please refer to the
+ * COPYRIGHT file distributed with this source distribution.
+ *
+ * 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.
+ */
+
+#ifndef TOOL_EXCEPTION_H
+#define TOOL_EXCEPTION_H
+
+#include <string>
+#include <stdexcept>
+
+/**
+ * Throw an exception of this type (or subtype of it), if the tool fails fatally.
+ * This type is intended for general errors
+ */
+class ToolException : public std::runtime_error {
+public:
+ /**
+ * Construct an exception, with an appropriate error message
+ * A return value for the tool should be supplied if none is appropriate
+ * @todo If the tools are even more C++ized, the tool should decide retcode itself, not by exception
+ *
+ * @param error The error message
+ * @param retcode The return value of the process
+ */
+ ToolException(std::string error, int retcode = -1) : std::runtime_error(error), _retcode(retcode) {}
+
+ int _retcode;
+};
+
+/**
+ * Something unexpected happened while reading / writing to a file
+ * Usually premature end, or that it could not be opened (write / read protected)
+ */
+class AbortException : public ToolException {
+public:
+ AbortException() : ToolException("Operation was aborted", -2) {}
+};
+
+#endif
diff --git a/common/util.cpp b/common/util.cpp
new file mode 100644
index 000000000..8e0a2fd61
--- /dev/null
+++ b/common/util.cpp
@@ -0,0 +1,153 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#define FORBIDDEN_SYMBOL_EXCEPTION_isalnum
+#define FORBIDDEN_SYMBOL_EXCEPTION_isalpha
+#define FORBIDDEN_SYMBOL_EXCEPTION_isdigit
+#define FORBIDDEN_SYMBOL_EXCEPTION_isnumber
+#define FORBIDDEN_SYMBOL_EXCEPTION_islower
+#define FORBIDDEN_SYMBOL_EXCEPTION_isspace
+#define FORBIDDEN_SYMBOL_EXCEPTION_isupper
+#define FORBIDDEN_SYMBOL_EXCEPTION_isprint
+
+
+#include "common/util.h"
+#include "common/debug.h"
+
+namespace Common {
+
+//
+// Print hexdump of the data passed in
+//
+void hexdump(const byte *data, int len, int bytesPerLine, int startOffset) {
+ assert(1 <= bytesPerLine && bytesPerLine <= 32);
+ int i;
+ byte c;
+ int offset = startOffset;
+ while (len >= bytesPerLine) {
+ debugN("%06x: ", offset);
+ for (i = 0; i < bytesPerLine; i++) {
+ debugN("%02x ", data[i]);
+ if (i % 4 == 3)
+ debugN(" ");
+ }
+ debugN(" |");
+ for (i = 0; i < bytesPerLine; i++) {
+ c = data[i];
+ if (c < 32 || c >= 127)
+ c = '.';
+ debugN("%c", c);
+ }
+ debugN("|\n");
+ data += bytesPerLine;
+ len -= bytesPerLine;
+ offset += bytesPerLine;
+ }
+
+ if (len <= 0)
+ return;
+
+ debugN("%06x: ", offset);
+ for (i = 0; i < bytesPerLine; i++) {
+ if (i < len)
+ debugN("%02x ", data[i]);
+ else
+ debugN(" ");
+ if (i % 4 == 3)
+ debugN(" ");
+ }
+ debugN(" |");
+ for (i = 0; i < len; i++) {
+ c = data[i];
+ if (c < 32 || c >= 127)
+ c = '.';
+ debugN("%c", c);
+ }
+ for (; i < bytesPerLine; i++)
+ debugN(" ");
+ debugN("|\n");
+}
+
+
+#pragma mark -
+
+
+bool parseBool(const String &val, bool &valAsBool) {
+ if (val.equalsIgnoreCase("true") ||
+ val.equalsIgnoreCase("yes") ||
+ val.equals("1")) {
+ valAsBool = true;
+ return true;
+ }
+ if (val.equalsIgnoreCase("false") ||
+ val.equalsIgnoreCase("no") ||
+ val.equals("0")) {
+ valAsBool = false;
+ return true;
+ }
+
+ return false;
+}
+
+
+#pragma mark -
+
+
+#define ENSURE_ASCII_CHAR(c) \
+ if (c < 0 || c > 127) \
+ return false
+
+bool isAlnum(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return isalnum((byte)c);
+}
+
+bool isAlpha(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return isalpha((byte)c);
+}
+
+bool isDigit(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return isdigit((byte)c);
+}
+
+bool isLower(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return islower((byte)c);
+}
+
+bool isSpace(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return isspace((byte)c);
+}
+
+bool isUpper(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return isupper((byte)c);
+}
+
+bool isPrint(int c) {
+ ENSURE_ASCII_CHAR(c);
+ return isprint((byte)c);
+}
+} // End of namespace Common
diff --git a/common/util.h b/common/util.h
new file mode 100644
index 000000000..1c0e45662
--- /dev/null
+++ b/common/util.h
@@ -0,0 +1,182 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+#ifndef COMMON_UTIL_H
+#define COMMON_UTIL_H
+
+#include "common/scummsys.h"
+#include "common/str.h"
+
+/**
+ * Check whether a given pointer is aligned correctly.
+ * Note that 'alignment' must be a power of two!
+ */
+#define IS_ALIGNED(value, alignment) \
+ ((((size_t)value) & ((alignment) - 1)) == 0)
+
+
+#ifdef MIN
+#undef MIN
+#endif
+
+#ifdef MAX
+#undef MAX
+#endif
+
+template<typename T> inline T ABS(T x) { return (x >= 0) ? x : -x; }
+template<typename T> inline T MIN(T a, T b) { return (a < b) ? a : b; }
+template<typename T> inline T MAX(T a, T b) { return (a > b) ? a : b; }
+template<typename T> inline T CLIP(T v, T amin, T amax)
+ { if (v < amin) return amin; else if (v > amax) return amax; else return v; }
+
+/**
+ * Template method which swaps the vaulues of its two parameters.
+ */
+template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
+
+/**
+ * Macro which determines the number of entries in a fixed size array.
+ */
+#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
+
+/**
+ * Compute a pointer to one past the last element of an array.
+ */
+#define ARRAYEND(x) ((x) + ARRAYSIZE((x)))
+
+
+/**
+ * @def SCUMMVM_CURRENT_FUNCTION
+ * This macro evaluates to the current function's name on compilers supporting this.
+ */
+#if defined(__GNUC__)
+# define SCUMMVM_CURRENT_FUNCTION __PRETTY_FUNCTION__
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
+# define SCUMMVM_CURRENT_FUNCTION __func__
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
+# define SCUMMVM_CURRENT_FUNCTION __FUNCTION__
+#else
+# define SCUMMVM_CURRENT_FUNCTION "<unknown>"
+#endif
+
+namespace Common {
+
+/**
+ * Print a hexdump of the data passed in. The number of bytes per line is
+ * customizable.
+ * @param data the data to be dumped
+ * @param len the length of that data
+ * @param bytesPerLine number of bytes to print per line (default: 16)
+ * @param startOffset shift the shown offsets by the starting offset (default: 0)
+ */
+extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int startOffset = 0);
+
+
+/**
+ * Parse a string for a boolean value.
+ * The strings "true", "yes", and "1" are interpreted as true.
+ * The strings "false", "no", and "0" are interpreted as false.
+ * This function ignores case.
+ *
+ * @param[in] val the string to parse
+ * @param[out] valAsBool the parsing result
+ * @return true if the string parsed correctly, false if an error occurred.
+ */
+bool parseBool(const String &val, bool &valAsBool);
+
+
+/**
+ * Test whether the given character is alphanumeric (a-z, A-Z, 0-9).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is alphanumeric, false otherwise.
+ */
+bool isAlnum(int c);
+
+/**
+ * Test whether the given character is an alphabetic letter (a-z, A-Z).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is TODO, false otherwise.
+ */
+bool isAlpha(int c);
+
+/**
+ * Test whether the given character is a decimal-digit (0-9).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is a decimal-digit, false otherwise.
+ */
+bool isDigit(int c);
+
+/**
+ * Test whether the given character is a lower-case letter (a-z).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is a lower-case letter, false otherwise.
+ */
+bool isLower(int c);
+
+/**
+ * Test whether the given character is a white-space.
+ * White-space characters are ' ', '\t', '\r', '\n', '\v', '\f'.
+ *
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is a white-space, false otherwise.
+ */
+bool isSpace(int c);
+
+/**
+ * Test whether the given character is an upper-case letter (A-Z).
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is an upper-case letter, false otherwise.
+ */
+bool isUpper(int c);
+
+/**
+ * Test whether the given character is printable. This includes the space
+ * character (' ').
+ *
+ * If the parameter is outside the range of a signed or unsigned char, then
+ * false is returned.
+ *
+ * @param c the character to test
+ * @return true if the character is printable, false otherwise.
+ */
+bool isPrint(int c);
+} // End of namespace Common
+
+#endif
diff --git a/common/zlib.cpp b/common/zlib.cpp
index 56ec96d1f..8019b054b 100644
--- a/common/zlib.cpp
+++ b/common/zlib.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/common/zlib.h b/common/zlib.h
index 503d47fe8..64a0adb3a 100644
--- a/common/zlib.h
+++ b/common/zlib.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/configure b/configure
index 2918daf18..4fb63da9e 100755
--- a/configure
+++ b/configure
@@ -21,6 +21,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
# Save the current environment variables for next runs
SAVED_CONFIGFLAGS=$@
SAVED_LDFLAGS=$LDFLAGS
@@ -62,50 +68,67 @@ get_var() {
eval echo \$${1}
}
+# Add a feature: id name settings-list
+add_feature() {
+ set_var _feature_${1}_name "${2}"
+ # This is a list of settings, where one must be "yes" for the feature to
+ # be enabled
+ set_var _feature_${1}_settings "${3}"
+}
+
+_srcdir=`dirname $0`
#
# Default settings
#
-#ResidualVM defaults: mpeg2=auto, faad=no, opengles=no
-#mt32emu=no, translation=no
+#ResidualVM defaults: faad=no, opengles=no, tremor=no mt32emu=no, translation=no,
+# flac=no, seq_midi=no, snd_io=no, timidity=no fluidsynth=no, opengles2=no
+# eventrec=no, build_scalers=no, build_hq_scalers=no
#
# Default lib behaviour yes/no/auto
_vorbis=auto
-_tremor=auto
+_tremor=no
_tremolo=no
-_flac=auto
+_flac=no
_mad=auto
_alsa=auto
-_seq_midi=auto
-_timidity=auto
+_seq_midi=no
+_sndio=no
+_timidity=no
_zlib=auto
-_sparkle=auto
-_png=no
_mpeg2=auto
+_sparkle=auto
+_jpeg=auto
+_png=auto
_theoradec=auto
_faad=no
-_fluidsynth=auto
+_fluidsynth=no
_opengl=auto
_opengles=no
+_opengles2=no
+_opengl_shaders=no
_readline=auto
_freetype2=auto
-_taskbar=yes
+_taskbar=auto
_updates=no
_libunity=auto
-# Default option behaviour yes/no
+# Default option behavior yes/no
_debug_build=auto
_release_build=auto
_optimizations=auto
+_use_cxx11=no
_verbose_build=no
_text_console=no
_mt32emu=no
-_build_scalers=yes
-_build_hq_scalers=yes
+_build_scalers=no
+_build_hq_scalers=no
_enable_prof=no
_global_constructors=no
_bink=yes
-# Default vkeybd/keymapper options
+_safedisc=no
+# Default vkeybd/keymapper/eventrec options
_vkeybd=no
_keymapper=no
+_eventrec=no
# GUI translation options
_translation=no
# Default platform settings
@@ -126,10 +149,10 @@ _strip=strip
_ar="ar cru"
_as="as"
_windres=windres
+_stagingpath="staging"
_win32path="C:/residualvm-tools"
_aos4path="Games:ResidualVM-tools"
-_stagingpath="staging"
-_staticlibpath=/sw
+_staticlibpath=
_sdlconfig=sdl-config
_freetypeconfig=freetype-config
_sdlpath="$PATH"
@@ -145,6 +168,14 @@ _endian=unknown
_need_memalign=yes
_have_x86=no
+# Add (virtual) features
+add_feature mad "MAD" "_mad"
+add_feature jpeg "JPEG" "_jpeg"
+add_feature png "PNG" "_png"
+add_feature theoradec "libtheoradec" "_theoradec"
+add_feature vorbis "Vorbis file support" "_vorbis _tremor"
+add_feature zlib "zlib" "_zlib"
+
# Directories for installing ScummVM.
@@ -171,7 +202,6 @@ _host_vendor=""
_host_os=""
_host_alias=""
-_srcdir=`dirname $0`
_port_mk="ports.mk"
# Use temp files in the build directory
@@ -185,7 +215,11 @@ cc_check_no_clean() {
echo >> "$TMPLOG"
echo "$CXX $LDFLAGS $CXXFLAGS $TMPC -o $TMPO$HOSTEXEEXT $@" >> "$TMPLOG"
rm -f "$TMPO$HOSTEXEEXT"
- ( $CXX $LDFLAGS $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
+ if test "-c" = "$*" ; then
+ ( $CXX $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
+ else
+ ( $CXX $LDFLAGS $CXXFLAGS "$TMPC" -o "$TMPO$HOSTEXEEXT" "$@" ) >> "$TMPLOG" 2>&1
+ fi
TMPR="$?"
echo "return code: $TMPR" >> "$TMPLOG"
echo >> "$TMPLOG"
@@ -338,10 +372,29 @@ Try \`$0 --help' for more information." >&2
exit 1
}
+#
+# Feature handling functions
+#
+
+# Get the name of the feature
+get_feature_name() {
+ get_var _feature_$1_name
+}
+
+# Check whether the feature is enabled
+get_feature_state() {
+ for i in `get_var _feature_$1_settings`; do
+ if test `get_var $i` = "yes"; then
+ echo "yes"
+ return
+ fi
+ done
+ echo "no"
+}
#
# Greet user
#
-echo "Running Tools configure..."
+echo "Running ResidualVM Tools configure..."
echo "Configure run on" `date` > $TMPLOG
#
@@ -367,7 +420,6 @@ Usage: $0 [OPTIONS]...
Configuration:
-h, --help display this help and exit
- --backend=BACKEND backend to build (sdl, null) [sdl]
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
@@ -395,6 +447,7 @@ Special configuration feature:
--host=HOST cross-compile to target HOST (arm-linux, ...)
Optional Features:
+ --enable-c++11 build as C++11 if the compiler allows that
--disable-debug disable building with debugging symbols
--enable-Werror treat warnings as errors
--enable-release enable building in release mode (this activates
@@ -422,7 +475,17 @@ Optional Libraries:
--with-zlib-prefix=DIR Prefix where zlib is installed (optional)
--disable-zlib disable zlib (compression) support [autodetect]
+ --with-mpeg2-prefix=DIR Prefix where libmpeg2 is installed (optional)
+ --enable-mpeg2 enable mpeg2 codec for cutscenes [autodetect]
+
+ --with-jpeg-prefix=DIR Prefix where libjpeg is installed (optional)
+ --disable-jpeg disable JPEG decoder [autodetect]
+
+ --with-png-prefix=DIR Prefix where libpng is installed (optional)
+ --disable-png disable PNG decoder [autodetect]
+ --with-theoradec-prefix=DIR Prefix where libtheoradec is installed (optional)
+ --disable-theoradec disable Theora decoder [autodetect]
Some influential environment variables:
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
@@ -449,6 +512,11 @@ for ac_option in $@; do
--enable-mad) _mad=yes ;;
--disable-mad) _mad=no ;;
--enable-verbose-build) _verbose_build=yes ;;
+ --with-mpeg2-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ MPEG2_CFLAGS="-I$arg/include"
+ MPEG2_LIBS="-L$arg/lib"
+ ;;
--with-ogg-prefix=*)
arg=`echo $ac_option | cut -d '=' -f 2`
OGG_CFLAGS="-I$arg/include"
@@ -474,11 +542,32 @@ for ac_option in $@; do
MAD_CFLAGS="-I$arg/include"
MAD_LIBS="-L$arg/lib"
;;
+ --with-jpeg-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ JPEG_CFLAGS="-I$arg/include"
+ JPEG_LIBS="-L$arg/lib"
+ ;;
+ --with-png-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ PNG_CFLAGS="-I$arg/include"
+ PNG_LIBS="-L$arg/lib"
+ ;;
+ --with-theoradec-prefix=*)
+ arg=`echo $ac_option | cut -d '=' -f 2`
+ THEORADEC_CFLAGS="-I$arg/include"
+ THEORADEC_LIBS="-L$arg/lib"
+ ;;
--with-zlib-prefix=*)
arg=`echo $ac_option | cut -d '=' -f 2`
ZLIB_CFLAGS="-I$arg/include"
ZLIB_LIBS="-L$arg/lib"
;;
+ --enable-c++11)
+ _use_cxx11=yes
+ ;;
+ --disable-c++11)
+ _use_cxx11=no
+ ;;
--enable-debug)
_debug_build=yes
;;
@@ -552,25 +641,25 @@ get_system_exe_extension $guessed_host
NATIVEEXEEXT=$_exeext
case $_host in
-android | android-v7a)
+android | android-arm | android-v7a | android-arm-v7a | ouya)
_host_os=android
_host_cpu=arm
_host_alias=arm-linux-androideabi
;;
+android-mips)
+ _host_os=android
+ _host_cpu=mipsel
+ _host_alias=mipsel-linux-android
+ ;;
+android-x86)
+ _host_os=android
+ _host_cpu=i686
+ _host_alias=i686-linux-android
+ ;;
arm-riscos)
_host_os=riscos
_host_cpu=arm
;;
-bada)
- _host_os=bada
- if test "$_debug_build" = yes; then
- _host_cpu=i686
- _host_alias=i686-mingw32
- else
- _host_cpu=arm
- _host_alias=arm-samsung-nucleuseabi
- fi
- ;;
caanoo)
_host_os=gph-linux
_host_cpu=arm
@@ -596,7 +685,7 @@ ds)
gamecube)
_host_os=gamecube
_host_cpu=ppc
- _host_alias=powerpc-gekko
+ _host_alias=powerpc-eabi
;;
gp2x)
_host_os=gph-linux
@@ -696,6 +785,11 @@ samsungtv)
_host_cpu=arm
_host_alias=arm-linux-gnueabi
;;
+tizen)
+ _host_os=tizen
+ _host_cpu=arm
+ _host_alias=arm-linux-gnueabi
+ ;;
webos)
_host_os=webos
_host_cpu=arm
@@ -714,7 +808,7 @@ webos)
wii)
_host_os=wii
_host_cpu=ppc
- _host_alias=powerpc-gekko
+ _host_alias=powerpc-eabi
;;
wince)
_host_os=wince
@@ -749,15 +843,10 @@ fi
case $_host in
caanoo | gp2x | gp2xwiz | openpandora | ps2)
if test "$_debug_build" = auto; then
- # If you want to debug one of these platforms, use '--disable-release --enable-debug'
+ # If you want to debug one of these platforms, use '--disable-optimizations --enable-debug'
_debug_build=no
fi
- if test "$_release_build" = auto; then
- # Enable release build by default.
- _release_build=yes
- fi
-
if test "$_optimizations" = auto; then
# Enable optimizations by default.
_optimizations=yes
@@ -766,8 +855,16 @@ caanoo | gp2x | gp2xwiz | openpandora | ps2)
esac
if test "$_debug_build" != no; then
- # debug mode not explicitly disabled -> compile with -g
- CXXFLAGS="$CXXFLAGS -g"
+ # debug mode not explicitly disabled -> compile with debug information
+ case $_host_os in
+ amigaos*)
+ # AmigaOS debugger uses plain stabs, with no gdb extensions.
+ CXXFLAGS="$CXXFLAGS -gstabs"
+ ;;
+ *)
+ # Use the system default format for debug info.
+ CXXFLAGS="$CXXFLAGS -g"
+ esac
fi
if test "$_release_build" = yes; then
@@ -810,12 +907,6 @@ android)
exit 1
fi
;;
-bada)
- if test -z "$BADA_SDK"; then
- echo "Please set BADA_SDK in your environment. export BADA_SDK=<path to Bada SDK>"
- exit 1
- fi
- ;;
ds | gamecube | wii)
if test -z "$DEVKITPRO"; then
echo "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to devkitPRO>"
@@ -839,6 +930,10 @@ ps3)
echo "Please set PS3DEV in your environment. export PS3DEV=<path to ps3 toolchain>"
exit 1
fi
+ if test -z "$PSL1GHT"; then
+ echo "Please set PSL1GHT in your environment. export PSL1GHT=<path to psl1ght>"
+ exit 1
+ fi
;;
psp)
if test -z "$PSPDEV"; then
@@ -853,6 +948,12 @@ psp)
exit 1
fi
;;
+tizen)
+ if test -z "$TIZEN_ROOTSTRAP"; then
+ echo "Please set TIZEN_ROOTSTRAP in your environment. export TIZEN_ROOTSTRAP=<path to Tizen SDK device profile>"
+ exit 1
+ fi
+ ;;
webos)
if test -z "$WEBOS_SDK"; then
echo "Please set WEBOS_SDK in your environment. export WEBOS_SDK=<path to WebOS SDK>"
@@ -885,7 +986,7 @@ EOF
if test -n "$_host"; then
# In cross-compiling mode, we cannot run the result
- eval "$1 $CXXFLAGS $LDFLAGS -o $TMPO.o -c tmp_cxx_compiler.cpp" 2> /dev/null && cc_check_clean tmp_cxx_compiler.cpp
+ eval "$1 $CXXFLAGS -o $TMPO.o -c tmp_cxx_compiler.cpp" 2> /dev/null && cc_check_clean tmp_cxx_compiler.cpp
else
eval "$1 $CXXFLAGS $LDFLAGS -o $TMPO$HOSTEXEEXT tmp_cxx_compiler.cpp" 2> /dev/null && eval "$TMPO$HOSTEXEEXT 2> /dev/null" && cc_check_clean tmp_cxx_compiler.cpp
fi
@@ -1022,6 +1123,18 @@ if test "$cxx_verc_fail" = yes ; then
exit 1
fi
+#
+# Check whether the compiler supports C++11
+#
+have_cxx11=no
+cat > $TMPC << EOF
+int main(int argc, char *argv[]) { if (argv == nullptr) return -1; else return 0; }
+EOF
+cc_check -std=c++11 && have_cxx11=yes
+if test "$_use_cxx11" = "yes" ; then
+ _use_cxx11=$have_cxx11
+fi
+
#
# Setup compiler specific CXXFLAGS now that we know the compiler version.
# Foremost, this means enabling various warnings.
@@ -1029,15 +1142,18 @@ fi
#
if test "$have_gcc" = yes ; then
if test "$_cxx_major" -ge "3" ; then
- case $_host_os in
- # newlib-based system include files suppress non-C89 function
- # declarations under __STRICT_ANSI__
- amigaos* | android | bada | dreamcast | ds | gamecube | mingw* | n64 | psp | ps2 | ps3 | wii | wince )
- ;;
- *)
- CXXFLAGS="$CXXFLAGS -ansi"
- ;;
- esac
+ # Try to use ANSI mode when C++11 is disabled.
+ if test "$_use_cxx11" = "no" ; then
+ case $_host_os in
+ # newlib-based system include files suppress non-C89 function
+ # declarations under __STRICT_ANSI__
+ amigaos* | android | dreamcast | ds | gamecube | mingw* | n64 | psp | ps2 | ps3 | tizen | wii | wince )
+ ;;
+ *)
+ CXXFLAGS="$CXXFLAGS -ansi"
+ ;;
+ esac
+ fi
CXXFLAGS="$CXXFLAGS -W -Wno-unused-parameter"
add_line_to_config_mk 'HAVE_GCC3 = 1'
add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
@@ -1053,17 +1169,27 @@ elif test "$have_icc" = yes ; then
add_line_to_config_mk 'CXX_UPDATE_DEP_FLAG = -MMD -MF "$(*D)/$(DEPDIR)/$(*F).d" -MQ "$@" -MP'
fi;
+#
+# Update status about C++11 mode
+#
+echo_n "Building as C++11... "
+if test "$_use_cxx11" = "yes" ; then
+ CXXFLAGS="$CXXFLAGS -std=c++11"
+fi
+echo $_use_cxx11
+
# By default, we add -pedantic to the CXXFLAGS to catch some potentially
# non-portable constructs, like use of GNU extensions.
# However, some platforms use GNU extensions in system header files, so
# for these we must not use -pedantic.
case $_host_os in
-android | gamecube | psp | wii | webos)
+android | gamecube | psp | tizen | wii | webos)
;;
*)
# ICC does not support pedantic, while GCC and clang do.
if test "$have_icc" = no ; then
- CXXFLAGS="$CXXFLAGS -pedantic"
+ # We *do* want the 'long long' extension.
+ CXXFLAGS="$CXXFLAGS -pedantic -Wno-long-long"
fi
;;
esac
@@ -1121,7 +1247,7 @@ esac
# Determine a data type with the given length
#
find_type_with_size() {
- for datatype in int short char long "long long" unknown; do
+ for datatype in int short char long "long long" __int64 "long long int" unknown; do
cat > tmp_find_type_with_size.cpp << EOF
typedef $datatype ac__type_sizeof_;
int main() {
@@ -1232,7 +1358,7 @@ cc_check_clean tmp_find_type_with_size.cpp
# for the smaller sizes.
echo_n "Alignment required... "
case $_host_cpu in
- i[3-6]86 | x86_64 | ppc*)
+ i[3-6]86 | amd64 | x86_64 | ppc*)
# Unaligned access should work
_need_memalign=no
;;
@@ -1260,7 +1386,9 @@ case $_host_cpu in
define_in_config_if_yes yes 'USE_ARM_SOUND_ASM'
define_in_config_if_yes yes 'USE_ARM_SMUSH_ASM'
define_in_config_if_yes yes 'USE_ARM_GFX_ASM'
- define_in_config_if_yes yes 'USE_ARM_COSTUME_ASM'
+ # FIXME: The following feature exhibits a bug during the intro scene of Indy 4
+ # (on Pandora and iPhone at least)
+ #define_in_config_if_yes yes 'USE_ARM_COSTUME_ASM'
DEFINES="$DEFINES -DARM_TARGET"
;;
@@ -1277,7 +1405,7 @@ case $_host_cpu in
echo "PowerPC"
DEFINES="$DEFINES -DPPC_TARGET"
;;
- x86_64)
+ amd64 | x86_64)
echo "x86_64"
;;
*)
@@ -1293,28 +1421,65 @@ echo_n "Checking hosttype... "
echo $_host_os
case $_host_os in
amigaos*)
- LDFLAGS="$LDFLAGS -use-dynld"
+ LDFLAGS="$LDFLAGS -use-dynld -Wl,--export-dynamic"
LDFLAGS="$LDFLAGS -L/sdk/local/newlib/lib"
# We have to use 'long' for our 4 byte typedef because AmigaOS already typedefs (u)int32
# as (unsigned) long, and consequently we'd get a compiler error otherwise.
type_4_byte='long'
+ # Supress format warnings as the long 4 byte causes noisy warnings.
+ CXXFLAGS="$CXXFLAGS -Wno-format"
add_line_to_config_mk 'AMIGAOS = 1'
;;
android)
case $_host in
- android)
+ android | android-arm)
CXXFLAGS="$CXXFLAGS -march=armv5te"
CXXFLAGS="$CXXFLAGS -mtune=xscale"
CXXFLAGS="$CXXFLAGS -msoft-float"
+ ABI="armeabi"
+ # Platform version 9 is used by ResidualVM
+ ANDROID_PLATFORM=9
+ ANDROID_PLATFORM_ARCH="arm"
;;
- android-v7a)
+ android-v7a | android-arm-v7a)
CXXFLAGS="$CXXFLAGS -march=armv7-a"
CXXFLAGS="$CXXFLAGS -mfloat-abi=softfp"
CXXFLAGS="$CXXFLAGS -mfpu=vfp"
LDFLAGS="$LDFLAGS -Wl,--fix-cortex-a8"
+ ABI="armeabi-v7a"
+ # Platform version 9 is used by ResidualVM
+ ANDROID_PLATFORM=9
+ ANDROID_PLATFORM_ARCH="arm"
+ ;;
+ android-mips)
+ CXXFLAGS="$CXXFLAGS -march=mips32"
+ CXXFLAGS="$CXXFLAGS -mtune=mips32"
+ ABI="mips"
+ # Platform version 9 is needed as earlier versions of platform do not support this arch.
+ ANDROID_PLATFORM=9
+ ANDROID_PLATFORM_ARCH="mips"
+ ;;
+ android-x86)
+ CXXFLAGS="$CXXFLAGS -march=i686"
+ CXXFLAGS="$CXXFLAGS -mtune=i686"
+ ABI="x86"
+ # Platform version 9 is needed as earlier versions of platform do not support this arch.
+ ANDROID_PLATFORM=9
+ ANDROID_PLATFORM_ARCH="x86"
+ ;;
+ ouya)
+ CXXFLAGS="$CXXFLAGS -march=armv7-a"
+ CXXFLAGS="$CXXFLAGS -mtune=cortex-a9"
+ CXXFLAGS="$CXXFLAGS -mfloat-abi=softfp"
+ CXXFLAGS="$CXXFLAGS -mfpu=neon"
+ ABI="armeabi-v7a"
;;
esac
- CXXFLAGS="$CXXFLAGS --sysroot=$ANDROID_NDK/platforms/android-4/arch-arm"
+
+ # Setup platform version and arch
+ CXXFLAGS="$CXXFLAGS --sysroot=$ANDROID_NDK/platforms/android-$ANDROID_PLATFORM/arch-$ANDROID_PLATFORM_ARCH"
+ LDFLAGS="$LDFLAGS --sysroot=$ANDROID_NDK/platforms/android-$ANDROID_PLATFORM/arch-$ANDROID_PLATFORM_ARCH"
+
CXXFLAGS="$CXXFLAGS -fpic"
CXXFLAGS="$CXXFLAGS -ffunction-sections"
CXXFLAGS="$CXXFLAGS -funwind-tables"
@@ -1327,29 +1492,28 @@ case $_host_os in
fi
CXXFLAGS="$CXXFLAGS -finline-limit=300"
_optimization_level=-Os
- CXXFLAGS="$CXXFLAGS -mthumb-interwork"
- # FIXME: Why is the following in CXXFLAGS and not in DEFINES? Change or document this.
- CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5__"
- CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5T__"
- CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5E__"
- CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5TE__"
- # supress 'mangling of 'va_list' has changed in GCC 4.4'
+
+ if test "$_host" = android -o "$_host" = android-arm; then
+ CXXFLAGS="$CXXFLAGS -mthumb-interwork"
+ # FIXME: Why is the following in CXXFLAGS and not in DEFINES? Change or document this.
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5__"
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5T__"
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5E__"
+ CXXFLAGS="$CXXFLAGS -D__ARM_ARCH_5TE__"
+ fi
+
+ # surpress 'mangling of 'va_list' has changed in GCC 4.4' warning
CXXFLAGS="$CXXFLAGS -Wno-psabi"
- LDFLAGS="$LDFLAGS --sysroot=$ANDROID_NDK/platforms/android-4/arch-arm"
- LDFLAGS="$LDFLAGS -mthumb-interwork"
+
+ if test "$_host" = android -o "$_host" = android-arm; then
+ LDFLAGS="$LDFLAGS -mthumb-interwork"
+ fi
+
+ LDFLAGS="$LDFLAGS -L$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/`$CXX -dumpversion`/libs/$ABI/"
+ LIBS="$LIBS -lsupc++"
add_line_to_config_mk "ANDROID_SDK = $ANDROID_SDK"
_seq_midi=no
;;
- bada)
- BADA_SDK_ROOT="`cygpath -m ${BADA_SDK}`"
- add_line_to_config_mk "BADA_SDK = $BADA_SDK"
- add_line_to_config_mk "BADA_SDK_ROOT = $BADA_SDK_ROOT"
-
- # assume dependencies have been installed in cygwin's /usr/local
- CYGWIN_USR_LOCAL="`cygpath -m /usr/local`"
- LDFLAGS="$LDFLAGS -L${CYGWIN_USR_LOCAL}/lib"
- CXXFLAGS="$CXXFLAGS -I${CYGWIN_USR_LOCAL}/include"
- ;;
beos*)
DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
# Needs -lbind -lsocket for the timidity MIDI driver
@@ -1388,6 +1552,24 @@ case $_host_os in
LDFLAGS="-L${macport_prefix}/lib $LDFLAGS"
CXXFLAGS="-I${macport_prefix}/include $CXXFLAGS"
+
+ if test -z "$_staticlibpath"; then
+ _staticlibpath=${macport_prefix}
+ echo "Set staticlib-prefix to ${_staticlibpath}"
+ fi
+ fi
+ # If _staticlibpath is not set yet try first /sw (fink) then /usr/local
+ # (the macports case is handled above).
+ if test -z "$_staticlibpath"; then
+ if test -d "/sw"; then
+ _staticlibpath=/sw
+ echo "Set staticlib-prefix to ${_staticlibpath}"
+ elif test -d "/usr/local"; then
+ _staticlibpath=/usr/local
+ echo "Set staticlib-prefix to ${_staticlibpath}"
+ else
+ echo "Could not determine prefix for static libraries"
+ fi
fi
;;
dreamcast)
@@ -1465,7 +1647,7 @@ case $_host_os in
# When not cross-compiling, enable large file support, but don't
# care if getconf doesn't exist or doesn't recognize LFS_CFLAGS.
if test -z "$_host"; then
- CXXFLAGS="$CXXFLAGS $(getconf LFS_CFLAGS 2>/dev/null)"
+ CXXFLAGS="$CXXFLAGS `getconf LFS_CFLAGS 2>/dev/null`"
fi
;;
maemo)
@@ -1500,12 +1682,13 @@ case $_host_os in
DEFINES="$DEFINES -D__PLAYSTATION2__"
;;
ps3)
- # Force use of SDL from the ps3 toolchain
+ # Force use of SDL and freetype from the ps3 toolchain
_sdlpath="$PS3DEV/portlibs/ppu:$PS3DEV/portlibs/ppu/bin"
+ _freetypepath="$PS3DEV/portlibs/ppu:$PS3DEV/portlibs/ppu/bin"
DEFINES="$DEFINES -DPLAYSTATION3"
- CXXFLAGS="$CXXFLAGS -mcpu=cell -mminimal-toc -I$PS3DEV/psl1ght/ppu/include -I$PS3DEV/portlibs/ppu/include"
- LDFLAGS="$LDFLAGS -L$PS3DEV/psl1ght/ppu/lib -L$PS3DEV/portlibs/ppu/lib"
+ CXXFLAGS="$CXXFLAGS -mcpu=cell -mminimal-toc -I$PSL1GHT/ppu/include -I$PS3DEV/portlibs/ppu/include"
+ LDFLAGS="$LDFLAGS -L$PSL1GHT/ppu/lib -L$PS3DEV/portlibs/ppu/lib"
add_line_to_config_mk 'PLAYSTATION3 = 1'
add_line_to_config_h "#define PREFIX \"${prefix}\""
;;
@@ -1526,6 +1709,12 @@ case $_host_os in
# Needs -lbind -lsocket for the timidity MIDI driver
LIBS="$LIBS -lnsl -lsocket"
;;
+ tizen)
+ add_line_to_config_mk "TIZEN_ROOTSTRAP = $TIZEN_ROOTSTRAP"
+ LDFLAGS="$LDFLAGS --sysroot=${TIZEN_ROOTSTRAP}"
+ LDFLAGS="$LDFLAGS -L${TIZEN_LIBS}/lib"
+ CXXFLAGS="$CXXFLAGS -I${TIZEN_LIBS}/include"
+ ;;
webos)
CXXFLAGS="$CXXFLAGS --sysroot=$WEBOS_PDK/arm-gcc/sysroot"
CXXFLAGS="$CXXFLAGS -I$WEBOS_PDK/include"
@@ -1586,7 +1775,7 @@ if test -n "$_host"; then
# Cross-compiling mode - add your target here if needed
echo "Cross-compiling to $_host"
case "$_host" in
- android | android-v7a)
+ android | android-arm | android-v7a | android-arm-v7a | android-mips | android-x86 | ouya)
# we link a .so as default
LDFLAGS="$LDFLAGS -shared"
LDFLAGS="$LDFLAGS -Wl,-Bsymbolic,--no-undefined"
@@ -1604,32 +1793,11 @@ if test -n "$_host"; then
arm-riscos|linupy)
DEFINES="$DEFINES -DLINUPY"
;;
- bada)
- _unix=yes
- _backend="bada"
- _port_mk="backends/platform/bada/bada.mk"
- if test "$_debug_build" = yes; then
- _arm_asm=no
- else
- _arm_asm=yes
- fi
- _taskbar=no
- _build_scalers=no
- _seq_midi=no
- _mt32emu=no
- _timidity=no
- _vkeybd=yes
- ;;
bfin*)
;;
caanoo)
- # This uses the GPH backend.
- DEFINES="$DEFINES -DGPH_DEVICE"
DEFINES="$DEFINES -DCAANOO"
- DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
- if test "$_debug_build" = yes; then
- DEFINES="$DEFINES -DGPH_DEBUG"
- else
+ if test "$_debug_build" = no; then
# Use -O3 on the Caanoo for non-debug builds.
_optimization_level=-O3
fi
@@ -1658,6 +1826,9 @@ if test -n "$_host"; then
CXXFLAGS="$CXXFLAGS -mips32"
_backend="dingux"
_mt32emu=no
+ _optimization_level=-O3
+ # Disable alsa midi to get the port build on OpenDingux toolchain
+ _alsa=no
_vkeybd=yes
_build_hq_scalers=no
_keymapper=no
@@ -1671,7 +1842,8 @@ if test -n "$_host"; then
DEFINES="$DEFINES -DDISABLE_DEFAULT_SAVEFILEMANAGER"
DEFINES="$DEFINES -DDISABLE_TEXT_CONSOLE"
DEFINES="$DEFINES -DDISABLE_COMMAND_LINE"
- if test "$_release_build" = yes; then
+ # Enable serial debugging output only when --enable-debug is passed
+ if test "$_release_build" = yes -o "$_debug_build" != yes; then
DEFINES="$DEFINES -DNOSERIAL"
fi
_optimization_level=-O3
@@ -1679,6 +1851,8 @@ if test -n "$_host"; then
CXXFLAGS="$CXXFLAGS -fschedule-insns2"
CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
CXXFLAGS="$CXXFLAGS -fdelete-null-pointer-checks"
+ # no-delayed-branch is a workaround for GCC bug #42841 - "SH: Assembler complains pcrel too far."
+ CXXFLAGS="$CXXFLAGS -fno-delayed-branch"
_backend="dc"
_build_scalers=no
_mad=yes
@@ -1717,13 +1891,7 @@ if test -n "$_host"; then
add_line_to_config_h "#define USE_WII_DI"
;;
gp2x)
- # This uses the GPH backend.
- DEFINES="$DEFINES -DGPH_DEVICE"
DEFINES="$DEFINES -DGP2X"
- DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
- if test "$_debug_build" = yes; then
- DEFINES="$DEFINES -DGPH_DEBUG"
- fi
CXXFLAGS="$CXXFLAGS -march=armv4t"
ASFLAGS="$ASFLAGS -mfloat-abi=soft"
LDFLAGS="$LDFLAGS -static"
@@ -1737,13 +1905,7 @@ if test -n "$_host"; then
_port_mk="backends/platform/gph/gp2x-bundle.mk"
;;
gp2xwiz)
- # This uses the GPH backend.
- DEFINES="$DEFINES -DGPH_DEVICE"
DEFINES="$DEFINES -DGP2XWIZ"
- DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
- if test "$_debug_build" = yes; then
- DEFINES="$DEFINES -DGPH_DEBUG"
- fi
CXXFLAGS="$CXXFLAGS -mcpu=arm926ej-s"
CXXFLAGS="$CXXFLAGS -mtune=arm926ej-s"
ASFLAGS="$ASFLAGS -mfloat-abi=soft"
@@ -1758,9 +1920,12 @@ if test -n "$_host"; then
;;
iphone)
DEFINES="$DEFINES -DIPHONE"
+ ASFLAGS="$ASFLAGS -arch armv6"
_backend="iphone"
- _build_hq_scalers=no
+ _build_scalers=no
+ _mt32emu=no
_seq_midi=no
+ _timidity=no
;;
m68k-atari-mint)
DEFINES="$DEFINES -DSYSTEM_NOT_SUPPORTING_D_TYPE"
@@ -1858,14 +2023,20 @@ if test -n "$_host"; then
DEFINES="$DEFINES -DREDUCE_MEMORY_USAGE"
if test "$_release_build" = no; then
DEFINES="$DEFINES -DOP_DEBUG"
- else
- # Use -O3 on the OpenPandora for non-debug builds.
+ fi
+
+ # Use -O3 on the OpenPandora for optimized builds.
+ if test "$_optimizations" = yes; then
_optimization_level=-O3
fi
+
+ define_in_config_if_yes yes 'USE_ARM_NEON_ASPECT_CORRECTOR'
CXXFLAGS="$CXXFLAGS -march=armv7-a"
CXXFLAGS="$CXXFLAGS -mtune=cortex-a8"
+ CXXFLAGS="$CXXFLAGS -mfloat-abi=softfp"
CXXFLAGS="$CXXFLAGS -mfpu=neon"
- ASFLAGS="$ASFLAGS -mfloat-abi=soft"
+ CXXFLAGS="$CXXFLAGS -fsingle-precision-constant"
+ ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
_backend="openpandora"
_build_hq_scalers=yes
_vkeybd=no
@@ -1874,6 +2045,16 @@ if test -n "$_host"; then
_port_mk="backends/platform/openpandora/op-bundle.mk"
;;
ppc-amigaos)
+ # Only static builds link successfully on buildbot
+ LDFLAGS=`echo $LDFLAGS | sed 's/-use-dynld//'`
+ LDFLAGS="$LDFLAGS -static"
+
+ # toolchain binaries prefixed by host
+ _ranlib=$_host-ranlib
+ _strip=$_host-strip
+ _ar="$_host-ar cru"
+ _as="$_host-as"
+ _windres=$_host-windres
;;
ps2)
DEFINES="$DEFINES -DDISABLE_TEXT_CONSOLE"
@@ -1928,6 +2109,17 @@ if test -n "$_host"; then
_mt32emu=no
_vkeybd=yes
;;
+ tizen)
+ _unix=yes
+ _backend="tizen"
+ _port_mk="backends/platform/tizen/tizen.mk"
+ _arm_asm=yes
+ _build_scalers=no
+ _seq_midi=no
+ _mt32emu=no
+ _timidity=no
+ _vkeybd=yes
+ ;;
webos)
_backend="webos"
_port_mk="backends/platform/webos/webos.mk"
@@ -1981,7 +2173,7 @@ case $_host_os in
amigaos* | cygwin* | dreamcast | ds | gamecube | mingw* | n64 | ps2 | ps3 | psp | wii | wince)
_posix=no
;;
- android | beos* | bsd* | darwin* | freebsd* | gph-linux | haiku* | hpux* | iphone | irix* | linux* | maemo | mint* | netbsd* | openbsd* | solaris* | sunos* | uclinux* | webos)
+ android | beos* | bsd* | darwin* | freebsd* | gnu* | gph-linux | haiku* | hpux* | iphone | irix*| k*bsd*-gnu* | linux* | maemo | mint* | netbsd* | openbsd* | solaris* | sunos* | uclinux* | webos)
_posix=yes
;;
os2-emx*)
@@ -2146,6 +2338,83 @@ define_in_config_if_yes "$_mad" 'USE_MAD'
echo "$_mad"
#
+#
+# Check for libjpeg
+#
+echocheck "libjpeg >= v6b"
+if test "$_jpeg" = auto ; then
+ _jpeg=no
+ cat > $TMPC << EOF
+#include <stdio.h>
+#include <jpeglib.h>
+int main(void) {
+#if JPEG_LIB_VERSION >= 62
+#else
+ syntax error
+#endif
+ return 0;
+}
+EOF
+ cc_check $JPEG_CFLAGS $JPEG_LIBS -ljpeg && _jpeg=yes
+fi
+if test "$_jpeg" = yes ; then
+ LIBS="$LIBS $JPEG_LIBS -ljpeg"
+ INCLUDES="$INCLUDES $JPEG_CFLAGS"
+fi
+define_in_config_if_yes "$_jpeg" 'USE_JPEG'
+echo "$_jpeg"
+
+#
+# Check for PNG
+#
+echocheck "PNG >= 1.2.8"
+if test "$_png" = auto ; then
+ _png=no
+ cat > $TMPC << EOF
+#include <png.h>
+int main(void) {
+#if PNG_LIBPNG_VER >= 10208
+#else
+ syntax error
+#endif
+ return 0;
+}
+EOF
+ cc_check $PNG_CFLAGS $PNG_LIBS -lpng -lz && _png=yes
+fi
+if test "$_png" = yes ; then
+ LIBS="$LIBS $PNG_LIBS -lpng -lz"
+ INCLUDES="$INCLUDES $PNG_CFLAGS"
+fi
+define_in_config_if_yes "$_png" 'USE_PNG'
+echo "$_png"
+
+#
+# Check for Theora Decoder
+#
+echocheck "libtheoradec >= 1.0"
+if test "$_vorbis" = no ; then
+ echo "skipping. no vorbis"
+ _theoradec=notsupported
+fi
+if test "$_theoradec" = auto ; then
+ _theoradec=no
+ cat > $TMPC << EOF
+#include <theora/theoradec.h>
+#include <vorbis/codec.h>
+int main(void) { th_ycbcr_buffer yuv; th_decode_ycbcr_out(NULL, yuv); }
+EOF
+ cc_check $THEORADEC_CFLAGS $THEORADEC_LIBS -ltheoradec && _theoradec=yes
+fi
+if test "$_theoradec" = yes ; then
+ LIBS="$LIBS $THEORADEC_LIBS -ltheoradec"
+ INCLUDES="$INCLUDES $THEORADEC_CFLAGS"
+fi
+define_in_config_if_yes "$_theoradec" 'USE_THEORADEC'
+if test ! "$_theoradec" = notsupported ; then
+ echo "$_theoradec"
+fi
+
# Check for ZLib
#
echocheck "zlib"
@@ -2166,12 +2435,64 @@ define_in_config_if_yes "$_zlib" 'USE_ZLIB'
echo "$_zlib"
#
+# Check for LibMPEG2
+#
+echocheck "libmpeg2 >= 0.4.0"
+if test "$_mpeg2" = auto ; then
+ _mpeg2=no
+ cat > $TMPC << EOF
+typedef signed $type_1_byte int8_t;
+typedef signed $type_2_byte int16_t;
+typedef signed $type_4_byte int32_t;
+
+typedef unsigned $type_1_byte uint8_t;
+typedef unsigned $type_2_byte uint16_t;
+typedef unsigned $type_4_byte uint32_t;
+
+extern "C" {
+#include <mpeg2dec/mpeg2.h>
+}
+
+int main(void) {
+ #if MPEG2_RELEASE < MPEG2_VERSION(0, 4, 0)
+ #error libmpeg2 version too low
+ #endif
+
+ /* mpeg2_state_t first appears in 0.4.0 */
+ mpeg2_state_t state;
+
+ return 0;
+}
+EOF
+
+ if test -n "$_host"; then
+ # don't execute while cross compiling
+ cc_check $MPEG2_CFLAGS $MPEG2_LIBS -lmpeg2 && _mpeg2=yes
+ else
+ cc_check_no_clean $MPEG2_CFLAGS $MPEG2_LIBS -lmpeg2 && $TMPO$HOSTEXEEXT && _mpeg2=yes
+ cc_check_clean
+ fi
+fi
+if test "$_mpeg2" = yes ; then
+ INCLUDES="$INCLUDES $MPEG2_CFLAGS"
+ LIBS="$LIBS $MPEG2_LIBS -lmpeg2"
+fi
+define_in_config_if_yes "$_mpeg2" 'USE_MPEG2'
+echo "$_mpeg2"
+
# Figure out installation directories
#
test "x$prefix" = xNONE && prefix=/usr/local
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
-DEFINES="$DEFINES -DDATA_PATH=\\\"$datadir\\\""
+case $_host_os in
+ mingw*)
+ # Windows stores all the external data files in executable file.
+ ;;
+ *)
+ DEFINES="$DEFINES -DDATA_PATH=\\\"$datadir\\\""
+ ;;
+esac
case $_backend in
openpandora)
@@ -2216,7 +2537,7 @@ case $_backend in
system_libs=''
for lib in $LIBS; do
case $lib in
- -lz|-lm|-ldl)
+ -lz|-lm|-ldl|-landroid|-lGLESv1_CM|-lGLESv2) # ResidualVM specific
system_libs="$system_libs $lib"
;;
*)
@@ -2228,7 +2549,7 @@ case $_backend in
# -lgcc is carefully placed here - we want to catch
# all toolchain symbols in *our* libraries rather
# than pick up anything unhygenic from the Android libs.
- LIBS="-Wl,-Bstatic $static_libs -Wl,-Bdynamic -lgcc $system_libs -llog -lGLESv1_CM"
+ LIBS="-Wl,-Bstatic $static_libs -Wl,-Bdynamic -lgcc $system_libs -llog -landroid" # ResidualVM removed: -lGLESv1_CM
;;
n64)
# Move some libs down here, otherwise some symbols requires by libvorbis aren't found
diff --git a/tools/bm2bmp.cpp b/tools/bm2bmp.cpp
index 1585d297b..e033fedc4 100644
--- a/tools/bm2bmp.cpp
+++ b/tools/bm2bmp.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/bmtoppm.cpp b/tools/bmtoppm.cpp
index f4011b5a3..0c7b2cac8 100644
--- a/tools/bmtoppm.cpp
+++ b/tools/bmtoppm.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 29cf71f9b..718af4873 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/diffr.cpp b/tools/diffr.cpp
index 2561e03ec..d22f6b221 100644
--- a/tools/diffr.cpp
+++ b/tools/diffr.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/animb2txt.cpp b/tools/emi/animb2txt.cpp
index c5c976159..67c387a27 100644
--- a/tools/emi/animb2txt.cpp
+++ b/tools/emi/animb2txt.cpp
@@ -1,19 +1,24 @@
-/* Residual - A 3D game interpreter
-*
-* Residual is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the AUTHORS
-* file distributed with this source distribution.
-
-* 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
-*
-*/
+/* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
// Based on Benjamin Haischs filetype-information.
diff --git a/tools/emi/cosb2cos.cpp b/tools/emi/cosb2cos.cpp
index 09db31645..0562e2a44 100644
--- a/tools/emi/cosb2cos.cpp
+++ b/tools/emi/cosb2cos.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/filetools.h b/tools/emi/filetools.h
index f51a7bcfa..8deaa841f 100644
--- a/tools/emi/filetools.h
+++ b/tools/emi/filetools.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/meshb2obj.cpp b/tools/emi/meshb2obj.cpp
index c3d19081f..0bce143f9 100644
--- a/tools/emi/meshb2obj.cpp
+++ b/tools/emi/meshb2obj.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/model.h b/tools/emi/model.h
index b3cc46c34..e5f9a5b83 100644
--- a/tools/emi/model.h
+++ b/tools/emi/model.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/renderModel.cpp b/tools/emi/renderModel.cpp
index 80f75d084..ee372ed16 100644
--- a/tools/emi/renderModel.cpp
+++ b/tools/emi/renderModel.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/renderTil.cpp b/tools/emi/renderTil.cpp
index 8b46bd78a..3813142bd 100644
--- a/tools/emi/renderTil.cpp
+++ b/tools/emi/renderTil.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index dae5569bb..82d9768ea 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/sklb2txt.cpp b/tools/emi/sklb2txt.cpp
index 29b95600d..bd20f559b 100644
--- a/tools/emi/sklb2txt.cpp
+++ b/tools/emi/sklb2txt.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/emi/til2bmp.cpp b/tools/emi/til2bmp.cpp
index 5d660ae3d..797cd9c82 100644
--- a/tools/emi/til2bmp.cpp
+++ b/tools/emi/til2bmp.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/imc2wav.cpp b/tools/imc2wav.cpp
index bfa04c9f4..d01d4abf5 100644
--- a/tools/imc2wav.cpp
+++ b/tools/imc2wav.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/int2flt.cpp b/tools/int2flt.cpp
index 12bcc9bad..75d61097f 100644
--- a/tools/int2flt.cpp
+++ b/tools/int2flt.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/lab.cpp b/tools/lab.cpp
index 5aeeb5b50..a591135b3 100644
--- a/tools/lab.cpp
+++ b/tools/lab.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/lab.h b/tools/lab.h
index 52599ae33..c85769fb6 100644
--- a/tools/lab.h
+++ b/tools/lab.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
index 7dc49b751..de807b9df 100644
--- a/tools/labcopy.cpp
+++ b/tools/labcopy.cpp
@@ -8,12 +8,12 @@
* 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.
@@ -21,9 +21,9 @@
*/
/*
- quick & dirty LAB file copier based on residual code.
+ quick & dirty LAB file copier based on ResidualVM code.
- Adapted from code posted on residual forum by Joost Peters
+ Adapted from code posted on ResidualVM forum by Joost Peters
http://forums.residualvm.org/viewtopic.php?t=91
*/
diff --git a/tools/lua/Changelog b/tools/lua/Changelog
new file mode 100644
index 000000000..55322a88c
--- /dev/null
+++ b/tools/lua/Changelog
@@ -0,0 +1,14 @@
+This is a modified version of Lua 3.1 intended for use with ResidualVM.
+The major changes made from the original version of Lua 3.1 are:
+
+* Applied differences from RCS labeled 3.1-alpha from lua.org.
+* Changed the binary file loader to allow read GrimE lua files.
+* Revamped the way function calls and returns are handled in order to
+ facilitate implementing GrimE's cooperative multithreading model.
+* Added several internal functions which implement this multithreading.
+* Added save/restore Lua state in the files: lsave.cpp and lrestore.cpp.
+* Unified types like int -> int32 and similiars.
+* Removed few library functions not used by game engine.
+* Formatting code.
+* Replace FILE usage code with File class code.
+* Remove union from TaggedString, that simplify things.
diff --git a/tools/lua/README.residualvm b/tools/lua/README.residualvm
deleted file mode 100644
index 3e4362910..000000000
--- a/tools/lua/README.residualvm
+++ /dev/null
@@ -1,11 +0,0 @@
-This is a modified version of Lua 3.1 intended for use with ResidualVM.
-The major changes made from the original version of Lua 3.1 are:
-
-* Changed the binary file loader to read the file format from Lua 3.1alpha2.
-* Revamped the way function calls and returns are handled in order to
- facilitate implementing Residual/GrimE's cooperative multithreading model.
-* Added several internal functions which implement this multithreading.
-* Unified types like int -> int32 and similiars
-* Removed few unused library funcs by games
-* formatting code
-* replace FILE usage code with File class code
diff --git a/tools/lua/lua.h b/tools/lua/lua.h
index aeb5233be..e7d509bc9 100644
--- a/tools/lua/lua.h
+++ b/tools/lua/lua.h
@@ -220,5 +220,8 @@ lua_Object lua_setfallback (char *event, lua_CFunction fallback);
* The Lua language and this implementation have been entirely designed and
* written by Waldemar Celes Filho, Roberto Ierusalimschy and
* Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
-* This implementation contains no third-party code.
+*
+* NOTE: This implementation of Lua contains additional code and
+* modifications added only for ResidualVM project.
+* Look into the source code file "Changelog" for more info.
******************************************************************************/
diff --git a/tools/mat2ppm.cpp b/tools/mat2ppm.cpp
index 094986ff3..fa62aa342 100644
--- a/tools/mat2ppm.cpp
+++ b/tools/mat2ppm.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/mklab.cpp b/tools/mklab.cpp
index 2c69cae4c..8109b53d3 100644
--- a/tools/mklab.cpp
+++ b/tools/mklab.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/patchex/cab.h b/tools/patchex/cab.h
index 4f4810a98..8f5c57130 100644
--- a/tools/patchex/cab.h
+++ b/tools/patchex/cab.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/patchex/cabd.cpp b/tools/patchex/cabd.cpp
index a24f1bc1f..484d98237 100644
--- a/tools/patchex/cabd.cpp
+++ b/tools/patchex/cabd.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/patchex/mspack.h b/tools/patchex/mspack.h
index 916d03fa4..b6dc1903f 100644
--- a/tools/patchex/mspack.h
+++ b/tools/patchex/mspack.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/patchex/mszip.h b/tools/patchex/mszip.h
index bcd941f04..5c5321ebf 100644
--- a/tools/patchex/mszip.h
+++ b/tools/patchex/mszip.h
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/patchex/mszipd.cpp b/tools/patchex/mszipd.cpp
index e6ff38c92..b9515e4d2 100644
--- a/tools/patchex/mszipd.cpp
+++ b/tools/patchex/mszipd.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index 5064fdd20..b80b1d49e 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/patchr.cpp b/tools/patchr.cpp
index b9486bb81..b0cf0d0cf 100644
--- a/tools/patchr.cpp
+++ b/tools/patchr.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/set2fig.cpp b/tools/set2fig.cpp
index 21c6a4dcd..9a47e597d 100644
--- a/tools/set2fig.cpp
+++ b/tools/set2fig.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 9fc4a6843..0cc4d1522 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -8,12 +8,12 @@
* 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.
diff --git a/tools/vima.cpp b/tools/vima.cpp
index 117963635..71f3bdd23 100644
--- a/tools/vima.cpp
+++ b/tools/vima.cpp
@@ -8,12 +8,12 @@
* 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.
Commit: 45c69fb9d91f0fc45c5ae71126aad02ae7baebeb
https://github.com/scummvm/scummvm-tools/commit/45c69fb9d91f0fc45c5ae71126aad02ae7baebeb
Author: Joseph Jezak josejx at gentoo.org (josejx at gentoo.org)
Date: 2014-05-31T13:02:49-04:00
Commit Message:
TOOLS: Add lighting decoding.
Changed paths:
tools/emi/setb2set.cpp
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index dae5569bb..2b349d8da 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -43,8 +43,10 @@ enum SectorType {
enum LightType {
- omni,
- direct
+ OmniType = 1,
+ SpotType = 2,
+ DirectType = 3,
+ AmbientType = 4
};
class Data {
@@ -106,11 +108,11 @@ public:
//virtual uint32 load() = 0;
virtual string ToString() = 0;
protected:
- Data *data;
+ Data *section_data;
};
Section::Section(Data *data) {
- this->data = data;
+ this->section_data = data;
}
class Sector : public Section {
@@ -198,6 +200,9 @@ string Sector::ToString() {
case HotType:
ss << "hot";
break;
+ case NoneType:
+ ss << "unknown";
+ break;
};
ss << endl;
ss << "\tdefault visibility\t";
@@ -252,7 +257,6 @@ Setup::Setup(Data *data) : Section(data) {
// Skip an unknown number
int unknown = data->GetInt();
-
tile = data->GetNullTerminatedString();
position = new float[3];
@@ -301,18 +305,82 @@ private:
float *position;
float *direction;
float intensity;
- float umbraangla;
- float penumbraangle;
int *color; // Byte
+ float umbraangle;
+ float penumbraangle;
+ float focusdistance;
+ float spreaddistance;
};
Light::Light(Data *data) : Section(data) {
- data->Skip(100);
+ name = data->GetString(32); // 0x00
+
+ position = new float[3]; // 0x20
+ position[0] = data->GetFloat(); // X
+ position[1] = data->GetFloat(); // Y
+ position[2] = data->GetFloat(); // Z
+
+ direction = new float[3]; // 0x2C
+ direction[0] = data->GetFloat(); // X
+ direction[1] = data->GetFloat(); // Y
+ direction[2] = data->GetFloat(); // Z
+
+ intensity = data->GetFloat(); // 0x38
+
+ // Need to check the light type
+ type = (LightType)data->GetInt(); // 0x3C
+
+ float i = data->GetFloat(); // 0x40 // Unknown, definitely float
+ int j = data->GetInt(); // 0x44
+ if (j != 0) {
+ cout << "Warning j != 0!" << endl;
+ }
+
+ // Light color
+ color = new int[3];
+ color[0] = data->GetInt(); // R // 0x48
+ color[1] = data->GetInt(); // G // 0x4C
+ color[2] = data->GetInt(); // B // 0x50
+
+ // Not 100% on these names
+ focusdistance = data->GetFloat(); // 0x54
+ spreaddistance = data->GetFloat(); // 0x58
+ umbraangle = data->GetFloat(); // 0x5C // In radians
+ penumbraangle = data->GetFloat(); // 0x60 // In radians
}
string Light::ToString() {
- return "";
+ stringstream ss;
+ ss.precision(6);
+ ss.setf(ios::fixed, ios::floatfield);
+ ss << "\tlight\t" << name << endl;
+ ss << "\ttype\t";
+ switch (type) {
+ case OmniType:
+ ss << "omni";
+ break;
+ case SpotType:
+ ss << "spot";
+ break;
+ case DirectType:
+ ss << "direct";
+ break;
+ case AmbientType:
+ ss << "ambient";
+ break;
+ default:
+ ss << "unknown: " << type;
+ break;
+ }
+ ss << endl;
+ ss << "\tposition\t" << position[0] << "\t" << position[1] << "\t" << position[2] << endl;
+ ss << "\tdirection\t" << direction[0] << "\t" << direction[1] << "\t" << direction[2] << endl;
+ ss << "\tintensity\t" << intensity << endl;
+ ss << "\tcolor\t" << color[0] << " " << color[1] << " " << color[2] << endl;
+ ss << "\tumbraangle\t" << umbraangle << endl;
+ ss << "\tpenumbraangle\t" << penumbraangle << endl;
+ return ss.str();
}
class Set {
@@ -356,25 +424,25 @@ string Set::ToString() {
ss << "section: colormaps" << endl; // we don't have any.
// setups
ss << "section: setups" << endl;
- vector<Section *>::iterator it;
ss << "\tnumsetups " << setups.size() << endl;
- for (it = setups.begin(); it != setups.end(); ++it) {
+ for (vector<Section *>::iterator it = setups.begin(); it != setups.end(); ++it) {
ss << (*it)->ToString() << endl << endl;
}
-
// lights
ss << "section: lights" << endl;
- ss << "\tnumlights 0" << endl;
- for (it = lights.begin(); it != lights.end(); it++) {
+ ss << "\tnumlights " << lights.size() << endl;
+ for (vector<Section *>::iterator it = lights.begin(); it != lights.end(); it++) {
ss << (*it)->ToString() << endl << endl;
}
// sectors
ss << "section: sectors\n";
- for (it = sectors.begin(); it != sectors.end(); it++) {
+ ss << "\tnumsectors " << sectors.size() << endl;
+ for (vector<Section *>::iterator it = sectors.begin(); it != sectors.end(); it++) {
ss << (*it)->ToString() << endl << endl;
}
return ss.str();
}
+
int main(int argc, char **argv) {
if (argc < 2) {
return 0;
Commit: 5a2e20fe69b0ee7758e2cc7a73d60deb2edc5273
https://github.com/scummvm/scummvm-tools/commit/5a2e20fe69b0ee7758e2cc7a73d60deb2edc5273
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2014-05-31T10:06:33-07:00
Commit Message:
Merge pull request #32 from JoseJX/FixSetb
TOOLS: Add lighting decoding.
Changed paths:
tools/emi/setb2set.cpp
Commit: d5072dcaa6907802bb4d1261142752c50ac2c7bb
https://github.com/scummvm/scummvm-tools/commit/d5072dcaa6907802bb4d1261142752c50ac2c7bb
Author: Dries Harnie (dries at harnie.be)
Date: 2014-06-05T10:06:09+02:00
Commit Message:
BUILD: Move liblua.a to TOOL_LDFLAGS. Fixes #33.
Changed paths:
tools/luac/module.mk
diff --git a/tools/luac/module.mk b/tools/luac/module.mk
index 5c08e5ab7..02d38e83b 100644
--- a/tools/luac/module.mk
+++ b/tools/luac/module.mk
@@ -6,8 +6,9 @@ TOOL_OBJS := \
opcode.o \
opt.o \
print.o \
- rebase.o \
- ../lua/liblua.a
+ rebase.o
+
+TOOL_LDFLAGS := tools/lua/liblua.a
TOOL := luac
TOOL_DEPS := tools/lua
Commit: 6f32e52d6517d0f1269aed873d1a1a9055682157
https://github.com/scummvm/scummvm-tools/commit/6f32e52d6517d0f1269aed873d1a1a9055682157
Author: Joseph Jezak (josejx at gentoo.org)
Date: 2014-07-21T12:31:24-04:00
Commit Message:
TOOLS: The interest and roll are actually a rotation Quaternion.
Changed paths:
tools/emi/setb2set.cpp
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index 80cdcb95f..c0725f41a 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -244,8 +244,7 @@ private:
string background;
string zbuffer;
float *position;
- float *interest;
- float roll;
+ float *rotationQuat;
float fov;
float nclip;
float fclip;
@@ -265,13 +264,13 @@ Setup::Setup(Data *data) : Section(data) {
position[1] = data->GetFloat();
position[2] = data->GetFloat();
- interest = new float[3];
+ rotationQuat = new float[4];
- interest[0] = data->GetFloat();
- interest[1] = data->GetFloat();
- interest[2] = data->GetFloat();
+ rotationQuat[0] = data->GetFloat();
+ rotationQuat[1] = data->GetFloat();
+ rotationQuat[2] = data->GetFloat();
+ rotationQuat[3] = data->GetFloat();
- roll = data->GetFloat();
fov = data->GetFloat();
nclip = data->GetFloat();
fclip = data->GetFloat();
@@ -285,8 +284,7 @@ string Setup::ToString() {
// background
// zbuffer
ss << "\tposition\t" << position[0] << "\t" << position[1] << "\t" << position[2] << endl;
- ss << "\tinterest\t" << interest[0] << "\t" << interest[1] << "\t" << interest[2] << endl;
- ss << "\troll\t" << roll << endl;
+ ss << "\trotationQuat\tX: " << rotationQuat[0] << "\tY: " << rotationQuat[1] << "\tZ: " << rotationQuat[2] << "\tW: " << rotationQuat[3] << "\t" << endl;
ss << "\tfov\t" << fov << endl;
ss << "\tnclip\t" << nclip << endl;
ss << "\tfclip\t" << fclip << endl;
Commit: f215c8b33e9aca66fc8c22fd937750fab75b5ff3
https://github.com/scummvm/scummvm-tools/commit/f215c8b33e9aca66fc8c22fd937750fab75b5ff3
Author: Dries Harnie (dries+github at harnie.be)
Date: 2014-07-22T13:21:32+02:00
Commit Message:
Merge pull request #34 from JoseJX/ReallyAQuat
TOOLS: The interest and roll are actually a rotation Quaternion.
Changed paths:
tools/emi/setb2set.cpp
Commit: 013e0a3a83215995061d50194a811446e41cba6f
https://github.com/scummvm/scummvm-tools/commit/013e0a3a83215995061d50194a811446e41cba6f
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2015-02-08T08:06:30+01:00
Commit Message:
TOOLS: remove not used code from tools
Changed paths:
R tools/labcopy.cpp
tools/module.mk
diff --git a/tools/labcopy.cpp b/tools/labcopy.cpp
deleted file mode 100644
index de807b9df..000000000
--- a/tools/labcopy.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/* ResidualVM - A 3D game interpreter
- *
- * ResidualVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * 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.
- *
- */
-
-/*
- quick & dirty LAB file copier based on ResidualVM code.
-
- Adapted from code posted on ResidualVM forum by Joost Peters
- http://forums.residualvm.org/viewtopic.php?t=91
-*/
-
-
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include "common/endian.h"
-
-#define BUFFER_SIZE 0x100000
-FILE *inLab = NULL, *outLab = NULL;
-void *buffer = NULL;
-
-struct lab_entry {
- uint32 fname_offset;
- uint32 start;
- uint32 size;
- uint32 reserved;
-};
-
-
-bool copyFile(uint32 offset, uint32 lenght) {
- uint32 copied_bytes, count, bytesToRead;
-
- copied_bytes = 0;
- fseek(inLab, offset, SEEK_SET);
- fseek(outLab, offset, SEEK_SET);
-
- while (copied_bytes < lenght) {
- bytesToRead = (lenght - copied_bytes < BUFFER_SIZE) ? lenght - copied_bytes : BUFFER_SIZE;
- count = (uint32)fread(buffer, 1, bytesToRead, inLab);
- fwrite(buffer, count, 1, outLab);
- copied_bytes += count;
- if (ferror(inLab) != 0 || ferror(outLab) != 0) {
- return false;
- }
- }
-
- return true;
-}
-
-bool copyLab() {
- char header[16];
- uint32 num_entries, string_table_size;
- char *string_table;
- lab_entry *lab_entries;
-
- //Read and parse header
- fseek(inLab, 0, SEEK_SET);
- fread(header, 16, 1, inLab);
- if (READ_BE_UINT32(header) != MKTAG('L','A','B','N')) {
- printf("This isn't a valid .lab file!\n");
- exit(1);
- }
-
- num_entries = READ_LE_UINT32(header + 8);
- string_table_size = READ_LE_UINT32(header + 12);
-
- //Read files entries
- lab_entries = (lab_entry *)calloc(sizeof(lab_entry), num_entries);
- fread(lab_entries, 1, num_entries * sizeof(struct lab_entry), inLab);
-
- //Read string table
- string_table = (char *)malloc(string_table_size);
- fread(string_table, 1, string_table_size, inLab);
-
- //Write out new lab
- fwrite(header, 16, 1, outLab);
- fwrite(lab_entries, sizeof(struct lab_entry), num_entries, outLab);
- fwrite(string_table, string_table_size, 1, outLab);
-
- //Check for errors
- if (ferror(inLab) != 0 || ferror(outLab) != 0) {
- free(lab_entries);
- free(string_table);
- return false;
- }
-
- //Copy the files, except cp_0_intha.bm
- for (uint32 i = 0; i < num_entries; i++)
- if (strcmp(string_table + READ_LE_UINT32(&lab_entries[i].fname_offset), "cp_0_intha.bm") != 0)
- if (!copyFile(lab_entries[i].start, lab_entries[i].size)) {
- free(lab_entries);
- free(string_table);
- return false;
- }
-
- free(lab_entries);
- free(string_table);
- return true;
-}
-
-void cleanup() {
- if (inLab) {
- fclose(inLab);
- }
-
- if (outLab) {
- fclose(outLab);
- }
-
- if (buffer) {
- free(buffer);
- }
-}
-
-int main(int argc, char *argv[]) {
- atexit(cleanup);
-
- //Argument checks and usage display
- if (argc != 3) {
- printf("Usage: labcopy original.lab destination.lab\n");
- printf("Copy original.lab from Grimfandango cd with illegal-toc protection.\n");
- return 1;
- }
-
- //Files opening
- inLab = fopen(argv[1], "rb");
- if (!inLab) {
- printf("Couldn't open %s!\n", argv[1]);
- return 1;
- }
-
- outLab = fopen(argv[2], "wb");
- if (!outLab) {
- printf("Couldn't write to %s!\n", argv[2]);
- return 1;
- }
-
- buffer = malloc(BUFFER_SIZE);
- if (!buffer) {
- printf("Unable to allocate memory!\n");
- return 1;
- }
-
- if (!copyLab()) {
- printf("I/O error!\n");
- return 1;
- }
-
- printf("%s successfully copied to %s.\n", argv[1], argv[2]);
- return 0;
-}
diff --git a/tools/module.mk b/tools/module.mk
index 5408fe419..4bedd516e 100644
--- a/tools/module.mk
+++ b/tools/module.mk
@@ -19,7 +19,6 @@ MAKE := \
unlab \
mklab \
vima \
- labcopy \
luac \
patchex \
diffr \
Commit: 85f6d59612836564d4527cc285a8ec60716999d3
https://github.com/scummvm/scummvm-tools/commit/85f6d59612836564d4527cc285a8ec60716999d3
Author: Pawel Kolodziejski (aquadran at users.sourceforge.net)
Date: 2015-02-08T08:29:32+01:00
Commit Message:
TOOLS: fixed compiler warnings
Changed paths:
common/debug.cpp
common/textconsole.cpp
tools/delua.cpp
tools/emi/setb2set.cpp
tools/patchex/mszipd.cpp
tools/patchex/patchex.cpp
tools/patchr.cpp
tools/unlab.cpp
tools/vima.cpp
diff --git a/common/debug.cpp b/common/debug.cpp
index c208613ce..cfa311fad 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -113,7 +113,7 @@ static void debugHelper(const char *s, va_list va, bool caret = true) {
if (caret)
buf += '\n';
- printf(buf.c_str());
+ printf("%s", buf.c_str());
}
void debug(const char *s, ...) {
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index 152b00d93..b08cac68f 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -55,7 +55,7 @@ void warning(const char *s, ...) {
output = "WARNING: " + output + "!\n";
- printf(output.c_str());
+ printf("%s", output.c_str());
}
#endif
@@ -86,7 +86,7 @@ void NORETURN_PRE error(const char *s, ...) {
buf_output[STRINGBUFLEN - 1] = '\0';
strcat(buf_output, "!\n");
- printf(buf_output);
+ printf("%s", buf_output);
// If there is an error handler, invoke it now
if (Common::s_errorHandler)
diff --git a/tools/delua.cpp b/tools/delua.cpp
index 718af4873..bcdf03e62 100644
--- a/tools/delua.cpp
+++ b/tools/delua.cpp
@@ -143,8 +143,8 @@ public:
for (std::string::iterator i = str.begin(); i != str.end(); i++) {
unsigned char c = *i;
if (strchr(specials, c)) {
- int i = strchr(specials, c) - specials;
- os << special_text[i];
+ int index = strchr(specials, c) - specials;
+ os << special_text[index];
}
else if (! isprint(c))
os << "\\" << std::dec << (unsigned int)(c);
diff --git a/tools/emi/setb2set.cpp b/tools/emi/setb2set.cpp
index c0725f41a..b5043b5bf 100644
--- a/tools/emi/setb2set.cpp
+++ b/tools/emi/setb2set.cpp
@@ -254,7 +254,7 @@ Setup::Setup(Data *data) : Section(data) {
name = data->GetString(128); // Parse a string really
// Skip an unknown number
- int unknown = data->GetInt();
+ data->GetInt();
tile = data->GetNullTerminatedString();
@@ -329,7 +329,7 @@ Light::Light(Data *data) : Section(data) {
// Need to check the light type
type = (LightType)data->GetInt(); // 0x3C
- float i = data->GetFloat(); // 0x40 // Unknown, definitely float
+ data->GetFloat(); // 0x40 // Unknown, definitely float
int j = data->GetInt(); // 0x44
if (j != 0) {
cout << "Warning j != 0!" << endl;
@@ -385,10 +385,10 @@ class Set {
public:
virtual string ToString();
Set(Data *data);
+ virtual ~Set() {}
private:
string setName;
uint32 numSetups;
- uint32 numColormaps;
uint32 numLights;
uint32 numSectors;
vector<Section *> setups;
diff --git a/tools/patchex/mszipd.cpp b/tools/patchex/mszipd.cpp
index b9515e4d2..ef8661d9a 100644
--- a/tools/patchex/mszipd.cpp
+++ b/tools/patchex/mszipd.cpp
@@ -135,7 +135,7 @@ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
register unsigned char bit_num;
unsigned int pos = 0;
unsigned int table_mask = 1 << nbits;
- unsigned int bit_mask = table_mask >> 1;
+ unsigned int bmask = table_mask >> 1;
for (bit_num = 1; bit_num <= nbits; bit_num++) {
for (sym = 0; sym < nsyms; sym++) {
@@ -144,12 +144,12 @@ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
fill = length[sym]; reverse = pos >> (nbits - fill); leaf = 0;
do {leaf <<= 1; leaf |= reverse & 1; reverse >>= 1;} while (--fill);
- if((pos += bit_mask) > table_mask) return 1;
+ if((pos += bmask) > table_mask) return 1;
- fill = bit_mask; next_sym = 1 << bit_num;
+ fill = bmask; next_sym = 1 << bit_num;
do { table[leaf] = sym; leaf += next_sym; } while (--fill);
}
- bit_mask >>= 1;
+ bmask >>= 1;
}
if (pos == table_mask) return 0;
@@ -164,7 +164,7 @@ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
pos <<= 16;
table_mask <<= 16;
- bit_mask = 1 << 15;
+ bmask = 1 << 15;
for (bit_num = nbits+1; bit_num <= MSZIP_MAX_HUFFBITS; bit_num++) {
for (sym = 0; sym < nsyms; sym++) {
@@ -183,9 +183,9 @@ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
}
table[leaf] = sym;
- if ((pos += bit_mask) > table_mask) return 1;
+ if ((pos += bmask) > table_mask) return 1;
}
- bit_mask >>= 1;
+ bmask >>= 1;
}
return (pos != table_mask) ? 1 : 0;
diff --git a/tools/patchex/patchex.cpp b/tools/patchex/patchex.cpp
index b80b1d49e..0edd17111 100644
--- a/tools/patchex/patchex.cpp
+++ b/tools/patchex/patchex.cpp
@@ -295,14 +295,14 @@ char *file_filter(const struct mscabd_file *file) {
return NULL;
}
-void extract_files(struct mscab_decompressor *cabd, struct mscabd_cabinet *cab) {
+void extract_files(struct mscab_decompressor *cabdec, struct mscabd_cabinet *cabinet) {
unsigned int files_extracted = 0;
struct mscabd_file *file;
char *filename;
- for (file = cab->files; file; file = file->next) {
+ for (file = cabinet->files; file; file = file->next) {
if ((filename = file_filter(file))) {
- if (cabd->extract(cabd, file, filename) != MSPACK_ERR_OK) {
+ if (cabdec->extract(cabdec, file, filename) != MSPACK_ERR_OK) {
printf("Extract error on %s!\n", file->filename);
free(filename);
continue;
diff --git a/tools/patchr.cpp b/tools/patchr.cpp
index b0cf0d0cf..41850423c 100644
--- a/tools/patchr.cpp
+++ b/tools/patchr.cpp
@@ -303,7 +303,7 @@ int main(int argc, char *argv[]) {
/* Add old data to diff string */
for (uint i = 0; i < ctrl[0]; i++)
- if ((oldpos + i >= 0) && (oldpos + i < oldsize)) {
+ if (oldpos + i < oldsize) {
new_block[newpos + i] ^= old_block[oldpos + i];
}
diff --git a/tools/unlab.cpp b/tools/unlab.cpp
index 0cc4d1522..ba82bdc52 100644
--- a/tools/unlab.cpp
+++ b/tools/unlab.cpp
@@ -78,18 +78,18 @@ int main(int argc, char **argv) {
Lab lab(filename);
for (int i = 0; i < lab.getNumEntries(); i++) {
- std::string filename = lab.getFileName(i);
- std::istream *infile = lab.getFile(filename);
- filename = fixFilename(filename);
- createDirectoryStructure(filename.c_str());
- std::fstream outfile(filename.c_str(), std::ios::out | std::ios::binary);
+ std::string fname = lab.getFileName(i);
+ std::istream *infile = lab.getFile(fname);
+ fname = fixFilename(fname);
+ createDirectoryStructure(fname.c_str());
+ std::fstream outfile(fname.c_str(), std::ios::out | std::ios::binary);
if (!outfile.is_open()) {
- printf("Could not open %s for writing\n", filename.c_str());
- createDirectoryStructure(filename.c_str());
+ printf("Could not open %s for writing\n", fname.c_str());
+ createDirectoryStructure(fname.c_str());
continue;
}
- printf("Extracting file %s\n", filename.c_str());
+ printf("Extracting file %s\n", fname.c_str());
outfile << infile->rdbuf();
diff --git a/tools/vima.cpp b/tools/vima.cpp
index 71f3bdd23..110337abc 100644
--- a/tools/vima.cpp
+++ b/tools/vima.cpp
@@ -114,7 +114,7 @@ static int8 *offsets[] = {
static uint16 destTable[5786];
byte *sourceBuffer;
-void vimaInit(uint16 *destTable) {
+void vimaInit() {
int destTableStartPos, incer;
for (destTableStartPos = 0, incer = 0; destTableStartPos < 64; destTableStartPos++, incer++) {
@@ -132,7 +132,7 @@ void vimaInit(uint16 *destTable) {
}
}
-void decompressVima(byte *src, int16 *dest, int destLen, uint16 *destTable) {
+void decompressVima(byte *src, int16 *dest, int destLen) {
int numChannels = 1;
byte sBytes[2];
int16 sWords[2];
@@ -219,7 +219,7 @@ void decompressVima(byte *src, int16 *dest, int destLen, uint16 *destTable) {
}
int main(int /* argc */, char *argv[]) {
- vimaInit(destTable);
+ vimaInit();
FILE *f = fopen(argv[1], "rb");
if (f == NULL) {
@@ -256,7 +256,7 @@ int main(int /* argc */, char *argv[]) {
fwrite(sourceBuffer, 1, uncompSize, stdout);
} else if (strcmp(codecs + 5 * codec, "VIMA") == 0) {
char *buffer = new char[uncompSize];
- decompressVima(sourceBuffer, (int16 *)buffer, uncompSize, destTable);
+ decompressVima(sourceBuffer, (int16 *)buffer, uncompSize);
fwrite(buffer, 1, uncompSize, stdout);
delete[] buffer;
} else {
Commit: 60d7a24f592be8d141cb6731a901e3f4c13f5d6d
https://github.com/scummvm/scummvm-tools/commit/60d7a24f592be8d141cb6731a901e3f4c13f5d6d
Author: PaweÅ KoÅodziejski (aquadran at users.sourceforge.net)
Date: 2020-10-14T12:09:04+02:00
Commit Message:
ALL: Merge ResidualVM tools
Changed paths:
A COPYING.LGPL
A COPYING.LUA
A engines/grim/bm2bmp.cpp
A engines/grim/bmtoppm.cpp
A engines/grim/delua.cpp
A engines/grim/diffr.cpp
A engines/grim/docs/ResidualVM-Patch.txt
A engines/grim/docs/setb.txt
A engines/grim/emi/animb2txt.cpp
A engines/grim/emi/cosb2cos.cpp
A engines/grim/emi/filetools.h
A engines/grim/emi/meshb2obj.cpp
A engines/grim/emi/model.h
A engines/grim/emi/renderModel.cpp
A engines/grim/emi/renderTil.cpp
A engines/grim/emi/setb2set.cpp
A engines/grim/emi/sklb2txt.cpp
A engines/grim/emi/til2bmp.cpp
A engines/grim/imc2wav.cpp
A engines/grim/int2flt.cpp
A engines/grim/lab.cpp
A engines/grim/lab.h
A engines/grim/lua/Changelog
A engines/grim/lua/lapi.cpp
A engines/grim/lua/lapi.h
A engines/grim/lua/lauxlib.cpp
A engines/grim/lua/lauxlib.h
A engines/grim/lua/lbuffer.cpp
A engines/grim/lua/lbuiltin.cpp
A engines/grim/lua/lbuiltin.h
A engines/grim/lua/ldo.cpp
A engines/grim/lua/ldo.h
A engines/grim/lua/lfunc.cpp
A engines/grim/lua/lfunc.h
A engines/grim/lua/lgc.cpp
A engines/grim/lua/lgc.h
A engines/grim/lua/liolib.cpp
A engines/grim/lua/llex.cpp
A engines/grim/lua/llex.h
A engines/grim/lua/lmathlib.cpp
A engines/grim/lua/lmem.cpp
A engines/grim/lua/lmem.h
A engines/grim/lua/lobject.cpp
A engines/grim/lua/lobject.h
A engines/grim/lua/lopcodes.h
A engines/grim/lua/lparser.cpp
A engines/grim/lua/lparser.h
A engines/grim/lua/lstate.cpp
A engines/grim/lua/lstate.h
A engines/grim/lua/lstring.cpp
A engines/grim/lua/lstring.h
A engines/grim/lua/lstrlib.cpp
A engines/grim/lua/ltable.cpp
A engines/grim/lua/ltable.h
A engines/grim/lua/ltask.cpp
A engines/grim/lua/ltask.h
A engines/grim/lua/ltm.cpp
A engines/grim/lua/ltm.h
A engines/grim/lua/lua.h
A engines/grim/lua/luadebug.h
A engines/grim/lua/lualib.h
A engines/grim/lua/lundump.cpp
A engines/grim/lua/lundump.h
A engines/grim/lua/lvm.cpp
A engines/grim/lua/lvm.h
A engines/grim/lua/lzio.cpp
A engines/grim/lua/lzio.h
A engines/grim/lua/module.mk
A engines/grim/luac/dump.cpp
A engines/grim/luac/luac.cpp
A engines/grim/luac/luac.h
A engines/grim/luac/module.mk
A engines/grim/luac/opcode.cpp
A engines/grim/luac/opcode.h
A engines/grim/luac/opt.cpp
A engines/grim/luac/print.cpp
A engines/grim/luac/rebase.cpp
A engines/grim/mat2ppm.cpp
A engines/grim/mklab.cpp
A engines/grim/module.mk
A engines/grim/patchex/cab.h
A engines/grim/patchex/cabd.cpp
A engines/grim/patchex/mspack.h
A engines/grim/patchex/mszip.h
A engines/grim/patchex/mszipd.cpp
A engines/grim/patchex/patchex.cpp
A engines/grim/patchr.cpp
A engines/grim/set2fig.cpp
A engines/grim/unlab.cpp
A engines/grim/vima.cpp
COPYRIGHT
diff --cc COPYING.LGPL
index 000000000,d0ff92e99..8dda7c500
mode 000000,100644..100644
--- a/COPYING.LGPL
+++ b/COPYING.LGPL
@@@ -1,0 -1,508 +1,508 @@@
-NOTE: Only certain parts of the ResidualVM project are under the GNU LGPL.
++NOTE: Only certain parts of the ScummVM project are under the GNU LGPL.
+ The majority of the files are under the GNU GPL. See the headers of the
+ individual files to find out the exact license.
+
+
+
+ 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.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Also add information on how to contact you by electronic and paper mail.
+
+ You should also get your employer (if you work as a programmer) or your
+ school, if any, to sign a "copyright disclaimer" for the library, if
+ necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+ That's all there is to it!
diff --cc COPYING.LUA
index 000000000,0f84f6042..b52b41fd8
mode 000000,100644..100644
--- a/COPYING.LUA
+++ b/COPYING.LUA
@@@ -1,0 -1,38 +1,38 @@@
-NOTE: ResidualVM uses code from Lua, which is covered by the following license.
++NOTE: ScummVM uses code from Lua, which is covered by the following license.
+ This implementation of Lua contains additional code and modifications added
-only for ResidualVM project.
-Look into the source code file "tools/lua/Changelog" for more info.
++only for ScummVM project.
++Look into the source code file "engines/grim/lua/Changelog" for more info.
+
+ /******************************************************************************
+ * Copyright (c) 1994-1998 TeCGraf, PUC-Rio. All rights reserved.
+ *
+ * Permission is hereby granted, without written agreement and without license
+ * or royalty fees, to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, including commercial applications, subject to
+ * the following conditions:
+ *
+ * - The above copyright notice and this permission notice shall appear in all
+ * copies or substantial portions of this software.
+ *
+ * - 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 greatly
+ * appreciated (but it is not required).
+ *
+ * - Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ *
+ * The authors specifically disclaim any warranties, including, but not limited
+ * to, the implied warranties of merchantability and fitness for a particular
+ * purpose. The software provided hereunder is on an "as is" basis, and the
+ * authors have no obligation to provide maintenance, support, updates,
+ * enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
+ * authors be held liable to any party for direct, indirect, special,
+ * incidental, or consequential damages arising out of the use of this software
+ * and its documentation.
+ *
+ * The Lua language and this implementation have been entirely designed and
+ * written by Waldemar Celes Filho, Roberto Ierusalimschy and
+ * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
+ *
+ ******************************************************************************/
diff --cc COPYRIGHT
index 83e93a4c2,96f8e87d3..3fa5f4121
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@@ -1,57 -1,263 +1,77 @@@
-ResidualVM
-Copyright (C) 2003-2014 by the following:
-
-Some of the code in this project was originally LGPL v2.1 (or later)
-but is used as GPL v2 (or later) starting from 19 Dec 2012.
-
-If you have contributed to this project then you deserve to be on this
-list. Contact us (see: AUTHORS) and we'll add you.
-
-Thomas Allen
-Torbjorn Andersson
-Ori Avtalion
-Robert Biro
-Bastien Bouclet
-James Brown
-Giulio Camuffo
-Marcus Comstedt
-Andrea Corna
-Jonathan Gray
-Tobias Gunkel
-Azamat H. Hackimov
-Vincent Hamm
-Dries Harnie
-Sven Hesse
-Matthew Hoops
-Erich Hoover
-Max Horn
-Travis Howell
-Guillem Jover
-Filippos Karapetis
-Pawel Kolodziejski
-Joost Peters
-George Macon
-Josh Matthews
-Matthieu Milan
-Christian Neumair
-Vincent Pelletier
-Daniel Schepler
-Einar Johan Soemaaen
-Yaron Tausky
-Joel Teichroeb
-Julien Templier
-Pino Toscano
-Lionel Ulmer
-Joni Vahamaki
-JenniBee
-
-ScummVM
-Copyright (C) 2001-2014 by the following:
+ScummVM Tools
+Copyright (C) 2001-2020 by the following:
If you have contributed to this project then you deserve to be on this
-list. Contact us (see: AUTHORS) and we'll add you.
+list. Contact us and we'll add you.
-Tore Anderson
Torbjorn Andersson
-Chris Apers
Ori Avtalion
-Nicolas Bacca
Fabio Battaglia
-Bastien Bouclet
-Arnaud Boutonne
-Jurgen Braam
-Ralph Brorsen
James Brown
-Stuart Caie
-Jamieson Christian
-Marcus Comstedt
-Paolo Costabel
+Arnaud Boutonne
+Henry Bush
Thierry Crozat
-Ivan Dubrov
-Frantisek Dufka
-Oystein Eftevaag
-Kovacs Endre Janos
-David Eriksson
-Jerome Fisher
-Stuart George
-Paul Gilbert
-Robert Goeffringmann
-Jonathan Gray
+Adam Forsyth
Benjamin Haisch
-Vincent Hamm
-Sven Hesse
-Jochen Hoenicke
-Matthew Hoops
+Marcoen Hirschberg
Max Horn
+Matthew Hoops
Travis Howell
-Janne Huttunen
-Felix Jakschitsch
-Jeroen Janssen
+Casey Hutchinson
Florian Kagerer
Filippos Karapetis
-Andreas Karlsson
-Ismail Khatib
-Oliver Kiehl
Martin Kiewitz
Pawel Kolodziejski
-Mutwin Kraus
-Andrew Kurushin
-Angus Lees
-Claudio Matsuoka
-Thomas Mayer
+Paul Gilbert
+Sven Hesse
+Michael Madsen
Alyssa Milburn
-Neil Millstone
Gregory Montoir
-Kostas Nakos
-Mikesch Nepomuk
-Nicolas Noble
Willem Jan Palenstijn
-Lars Persson
Joost Peters
-Tim Phillips
-Edward Rudd
Eugene Sandulenko
Johannes Schickel
-Won Star
Ludvig Strigeus
-Keith Scroggins
-David Symonds
-Jordi Vilalta
-Robin Watts
-John Willis
-Jezar
-n0p
+Julien Templier
+David Turner
+Jordi Vilalta Prat
peres
+
+Patches contributed by:
+
+agf
+Alban Bedel
+Yak Bizzarro
+Laurent Blume
+Ben "irrelevant"
+canavan
+Florob
+Nicolas Joly
+KeithS
+Norbert Lange
+Langa Lucian
+LunaVorax
+Sean Murray
+remere
Quietust
+Andrea Suatoni
+
+
-Patches contributed by:
++ResidualVM Tools
++Copyright (C) 2003-2020 by the following:
++
++Some of the code in this project was originally LGPL v2.1 (or later)
++but is used as GPL v2 (or later) starting from 19 Dec 2012.
++
++If you have contributed to this project then you deserve to be on this
++list. Contact us (see: AUTHORS) and we'll add you.
+
-Laura Abbott "sageofminerva"
-Vikram Aggarwal "youngelf"
-the rara avis "theraraavis"
-Dieter Baron "dillo"
-Alban Bedel "albeu"
-Bodo Bellut "bellut"
-Bramvandijk "bramvandijk"
-Andreas Bierfert "awjb"
-Elio Blanca "eblanca76"
-David Breakey "dbreakey"
-Robert Buchholz "prendi"
-Rainer Canavan "canavan"
-Mathieu Carot "yokna"
-Stefano Ceccherini "jackburton"
-Travis S Coady "theealien"
-Josh Coalson "jcoalson"
-Thomas Combeleran "hibernatus"
-Kees Cook "keescook"
-Carlos Corbacho "cathectic"
-Roberto Costa "fiix76"
-dc france "erwan2004"
-dewt "mncl"
-Martin Doucha "next_ghost"
-Michael Drueing "doc_wagon"
-Michael du Breuil "WickedShell"
-dubsdj
-Matthew Duggan "stauff1"
-Olivier Duverne "richiefs"
-Andrei Dziahel "develop7"
-John Eckerdal "johneck"
-Thomas Fach-Pedersen "madm00se"
-Florent "flobo"
-Florob "florob"
-Mike Frysinger "vapier"
-Chris Gelatt "kreeblah"
-Jens Georg "phako"
-Nicolas George "cigaes"
-Jonathan Gevaryahu "lord_nightmare"
-Tobias Gruetzmacher "tobig"
-Damien Guard "damienguard"
-Tobias Gunkel "tobigun"
-Matti Hamalainen "ccrtnsp"
-Matt Hargett "matt_hargett"
-Stefan Haubenthal "polluks"
-Alexander Holler "holler"
-Falk Hueffner "mellum"
-Casey Hutchinson "nnooiissee"
-j0tt
-Gregor Jasny "gjasny"
-Jellby "jellby"
-Joerg "macdrega"
-Matt Johnson "mattjon"
-Nicolas Joly "njoly"
-KeithS "keithscr"
-Sam Kenny "sam_k"
-Koen Kooi "koenkooi"
-Zygmunt Krynicki "zygoon"
-Janne Kujanpaa "jukuja"
-Jay Lanagan "r0ni"
-Norbert Lange "nolange"
-Manuel Lauss "mlau2"
-Rolf Leggewie "leggewie"
-Duncan Lock "dflock"
-Mark Lodato "itsr0y"
-Fridvin Logi "phillip_j_fry"
-Lostech "lostech"
-Georg Lukas "ge0rg"
-Michael Madsen "pidgeot"
-Dmitry Marakasov "amdmi3"
-Alejandro Marzini "vgvgf"
-Connor McLeod "mcleod2032"
-Mickey McMurray "metafox"
-Vladimir Menshakov "megath"
-Adam Metcalf "gamblore"
-Frank Meyering "frank_m24"
-Gael Le Migno "kilobug"
-Andy Molloy "maloi"
-Sean Murrau "lightcast"
-Armin Mueller "arm_in"
-Andrea Musuruane "musuruan"
-KO Myung-Hun "lvzuufx"
-Markus Napp "meist3r"
-Peter Naulls "pnaulls"
-Christian Neumair "mannythegnome"
-Nicos "anarxia"
-Juha Niemimaki "capehill"
-Markus Niemisto "niemisto"
-ole
-Chris Paras "paras_rasmatazz"
-Aubin Paul "outlyer"
-Vincent Pelletier "subdino"
-phi1
-Pix2 "pix2"
-Carsten Pohl "carstenpohl"
-Markus Pyykko "mankeli"
-Richard "trinity78"
-Felix Riemann "kirschsaft"
-Thomas Richter "thorfdbg"
-Timo Roehling "t1m0"
-Andreas Roever "roever"
-Jonathan Rogers "jonner"
-Marek Roth "logicdeluxe"
-Uwe Ryssel "uweryssel"
-Simon Sawatzki "simsaw"
-Scarlatti "escarlate"
-Daniel Schepler "dschepler"
-Florian Schmitt "fatpenguin"
-Mark Schreiber "mark7"
-Ben Shadwick "benshadwick"
-Jean-Yves Simon "lethalwp"
-Andrej Sinicyn "andrej4000"
-Andre Souza "luke_br"
-spookypeanut "spookypeanut"
-Steve Stavropoulos "isnothere"
-Daniel Steinberger "amorphousshape"
-Sven Strothoff "dataslayer"
-Andrea Suatoni "mrhandler"
-tbcarey
-Tim "tipabu"
-Luigi Toscano "ltosky"
-Xavier Trochu "xtrochu"
-Michal Tulacek "tutchek"
-Michael Udaltsov "cccp99"
-Kristof Vansant "lupusbe"
-Tim Walters "realmz"
-David Weinehall "weine"
-Eric A. Welsh "eweish42"
-Yudhi Widyatama "yudhi97"
-Robert Wohlrab "moshroum"
-Xanathar "xanathar"
-Grant Yeager "glo_kidd"
-Benjamin W. Zale "junior_aepi"
-Yotam Barnoy "bluddy"
-Tom Frost "TomFrost"
++Giulio Camuffo
++Dries Harnie
++Joseph Jezak
++Pawel Kolodziejski
++Ingo van Lil
++Vincent Pelletier
++David A. Russo
++Einar Johan T. Somaaen
++Joel Teichroeb
diff --cc engines/grim/bm2bmp.cpp
index 000000000,e033fedc4..e033fedc4
mode 000000,100644..100644
--- a/engines/grim/bm2bmp.cpp
+++ b/engines/grim/bm2bmp.cpp
diff --cc engines/grim/bmtoppm.cpp
index 000000000,0c7b2cac8..0c7b2cac8
mode 000000,100644..100644
--- a/engines/grim/bmtoppm.cpp
+++ b/engines/grim/bmtoppm.cpp
diff --cc engines/grim/delua.cpp
index 000000000,bcdf03e62..bcdf03e62
mode 000000,100644..100644
--- a/engines/grim/delua.cpp
+++ b/engines/grim/delua.cpp
diff --cc engines/grim/diffr.cpp
index 000000000,d22f6b221..d22f6b221
mode 000000,100644..100644
--- a/engines/grim/diffr.cpp
+++ b/engines/grim/diffr.cpp
diff --cc engines/grim/docs/ResidualVM-Patch.txt
index 000000000,8ee0d3bed..8ee0d3bed
mode 000000,100644..100644
--- a/engines/grim/docs/ResidualVM-Patch.txt
+++ b/engines/grim/docs/ResidualVM-Patch.txt
diff --cc engines/grim/docs/setb.txt
index 000000000,e8e91c063..e8e91c063
mode 000000,100644..100644
--- a/engines/grim/docs/setb.txt
+++ b/engines/grim/docs/setb.txt
diff --cc engines/grim/emi/animb2txt.cpp
index 000000000,67c387a27..67c387a27
mode 000000,100644..100644
--- a/engines/grim/emi/animb2txt.cpp
+++ b/engines/grim/emi/animb2txt.cpp
diff --cc engines/grim/emi/cosb2cos.cpp
index 000000000,0562e2a44..0562e2a44
mode 000000,100644..100644
--- a/engines/grim/emi/cosb2cos.cpp
+++ b/engines/grim/emi/cosb2cos.cpp
diff --cc engines/grim/emi/filetools.h
index 000000000,8deaa841f..8deaa841f
mode 000000,100644..100644
--- a/engines/grim/emi/filetools.h
+++ b/engines/grim/emi/filetools.h
diff --cc engines/grim/emi/meshb2obj.cpp
index 000000000,0bce143f9..0bce143f9
mode 000000,100644..100644
--- a/engines/grim/emi/meshb2obj.cpp
+++ b/engines/grim/emi/meshb2obj.cpp
diff --cc engines/grim/emi/model.h
index 000000000,e5f9a5b83..e5f9a5b83
mode 000000,100644..100644
--- a/engines/grim/emi/model.h
+++ b/engines/grim/emi/model.h
diff --cc engines/grim/emi/renderModel.cpp
index 000000000,ee372ed16..ee372ed16
mode 000000,100644..100644
--- a/engines/grim/emi/renderModel.cpp
+++ b/engines/grim/emi/renderModel.cpp
diff --cc engines/grim/emi/renderTil.cpp
index 000000000,3813142bd..235bddbe5
mode 000000,100644..100644
--- a/engines/grim/emi/renderTil.cpp
+++ b/engines/grim/emi/renderTil.cpp
@@@ -1,0 -1,448 +1,448 @@@
+ /* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 <fstream>
+ #include <iostream>
+ #include <string>
+ #include <zlib.h>
+ #include <cassert>
+ #include <sys/types.h>
+ #include <sstream>
+ #include <stdint.h>
+ #include <cstdio>
+ #include <cstring>
+ #include "common/endian.h"
+ #include "tools/lab.h"
+ #include "tools/emi/filetools.h"
+ #include <GLFW/glfw3.h>
+
+ /*
+ This tool renders EMI-TILEs, optionally allowing the user to enable/disable layers in the TIL.
+
+ I'm rather sure this only works on LE-systems for now, and it REQUIRES GLFW 3 and zlib to work.
+
+ Usage:
+ renderTil [labName] <filename>
+
+ To enable or disable layers, simply press the matching key.
+
+ somaen.
+ */
+
-// Credits: The TILE-loading and texture-generation/drawing code was lifted directly from ResidualVM
++// Credits: The TILE-loading and texture-generation/drawing code was lifted directly from ScummVM
+ // The rendering setup was lifted directly from the GLFW-intro tutorial.
+
+ #define BITMAP_TEXTURE_SIZE 256
+
+ /**
+ * The Color-formats used for bitmaps in Grim Fandango/Escape From Monkey Island
+ */
+ enum colorFormat {
+ BM_RGB565 = 1, // Grim Fandango
+ BM_RGB1555 = 2, // EMI-PS2
+ BM_RGBA = 3, // EMI-PC (Also internal Material-format for Grim)
+ BM_BGR888 = 4, // EMI-TGA-materials (888)
+ BM_BGRA = 5 // EMI-TGA-materials with alpha
+ };
+
+ class Tile {
+ float *_texc;
+ struct Vert {
+ uint32 _texid;
+ uint32 _pos;
+ uint32 _verts;
+ };
+ struct Layer {
+ uint32 _offset;
+ uint32 _numImages;
+ };
+ Vert *_verts;
+ Layer *_layers;
+ uint32 _numCoords;
+ uint32 _numVerts;
+ uint32 _numLayers;
+ int _numSubImages;
+ char **_data;
+ int _width, _height;
+ int _bpp;
+ int _colorFormat;
+ // Rendering:
+ int _numTex;
+ void *_texIds;
+ bool *_enabledLayers;
+ public:
+ Tile() : _data(NULL), _layers(NULL), _verts(NULL), _numSubImages(0), _numVerts(0), _numLayers(0), _numCoords(0), _width(0), _height(0), _texc(0), _bpp(0), _colorFormat(0), _numTex(0), _texIds(NULL), _enabledLayers(NULL) {}
+ ~Tile() {
+ for (int i = 0; i < _numSubImages; i++) {
+ delete _data[i];
+ }
+ delete[] _enabledLayers;
+ delete[] _data;
+ delete[] _verts;
+ delete[] _layers;
+ }
+ bool loadTile(SeekableReadStream *stream);
+ void createBitmap();
+ void drawBitmap(int dx, int dy, uint32 layer);
+ void drawAllLayers() {
+ for (int layer = _numLayers - 1; layer >= 0; layer--) {
+ if (_enabledLayers[layer]) {
+ drawBitmap(0, 0, layer);
+ }
+ }
+ }
+ void toggleLayer(int layer) {
+ if (layer < _numLayers) {
+ _enabledLayers[layer] = !_enabledLayers[layer];
+ std::cout << "Layer " << layer << (_enabledLayers[layer] ? " enabled" : " disabled") << std::endl;
+ }
+ }
+ };
+
+ bool Tile::loadTile(SeekableReadStream *stream) {
+ uint32 id = FROM_BE_32(stream->readUint32());
+ char *test = (char *)&id;
+ // Should check that we actually HAVE a TIL
+ uint32 bmoffset = stream->readUint32();
+ _numCoords = stream->readUint32();
+ _numLayers = stream->readUint32();
+ _numVerts = stream->readUint32();
+
+ // skip some 0
+ stream->seek(16, SEEK_CUR);
+ _texc = new float[_numCoords * 4];
+ std::cout << "Num Coords: " << _numCoords << std::endl;
+ for (uint32 i = 0; i < _numCoords * 4; ++i) {
+ char f[4];
+ stream->read(f, 4);
+ _texc[i] = get_float(f);
+ }
+
+ _layers = new Layer[_numLayers];
+ std::cout << "Num Layers: " << _numLayers << std::endl;
+ for (uint32 i = 0; i < _numLayers; ++i) {
+ _layers[i]._offset = stream->readUint32();
+ _layers[i]._numImages = stream->readUint32();
+ }
+
+ _verts = new Vert[_numVerts];
+ std::cout << "Num Vertices:" << _numVerts << std::endl;
+ for (uint32 i = 0; i < _numVerts; ++i) {
+ _verts[i]._texid = stream->readUint32();
+ _verts[i]._pos = stream->readUint32();
+ _verts[i]._verts = stream->readUint32();
+ }
+
+ stream->seek(16, SEEK_CUR);
+ _numSubImages = stream->readUint32();
+ std::cout << "Num Sub-images: " << _numSubImages << std::endl;
+ if (_numSubImages < 5) {
+ std::cout << "Can not handle a tile with less than 5 sub images, this has " << _numSubImages << std::endl;
+ exit(0);
+ }
+
+ _data = new char *[_numSubImages];
+
+ stream->seek(16, SEEK_CUR);
+ _bpp = stream->readUint32();
+
+ stream->seek(bmoffset + 128);
+
+ _width = stream->readUint32();
+ _height = stream->readUint32();
+ std::cout << "Width: " << _width << std::endl << "Height: " << _height << std::endl;
+ stream->seek(-8, SEEK_CUR);
+
+ int size = _bpp / 8 * _width * _height;
+ for (int i = 0; i < _numSubImages; ++i) {
+ _data[i] = new char[size];
+ stream->seek(8, SEEK_CUR);
+ stream->read(_data[i], size);
+ }
+ //Graphics::PixelFormat pixelFormat;
+ if (_bpp == 16) {
+ // _colorFormat = BM_RGB1555;
+ // pixelFormat = Graphics::createPixelFormat<1555>();
+ //convertToColorFormat(0, BM_RGBA);
+ } else {
+ // pixelFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
+ // _colorFormat = BM_RGBA;
+ }
+
+ _width = 256;
+ _height = 256;
+
+ _enabledLayers = new bool[_numLayers];
+ for (int i = 0; i < _numLayers; i++) {
+ _enabledLayers[i] = true;
+ }
+
+ return true;
+ }
+
+ void Tile::createBitmap() {
+ // bitmap->_hasTransparency = false;
+ _numTex = ((_width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
+ ((_height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
+ _texIds = new GLuint[_numTex * _numSubImages];
+ GLuint *textures = (GLuint *)_texIds;
+ glGenTextures(_numTex * _numSubImages, textures);
+
+ byte *texData = 0;
+ byte *texOut = 0;
+
+ GLint format = GL_RGBA;
+ GLint type = GL_UNSIGNED_BYTE;
+ int bytes = 4;
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, bytes);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, _width);
+
+ for (int pic = 0; pic < _numSubImages; pic++) {
+ if (_bpp == 16 && _colorFormat != BM_RGB1555) {
+ if (texData == 0) {
+ texData = new byte[4 * _width * _height];
+ }
+ // Convert data to 32-bit RGBA format
+ byte *texDataPtr = texData;
+ uint16 *bitmapData = reinterpret_cast<uint16 *>(_data[pic]);
+ for (int i = 0; i < _width * _height; i++, texDataPtr += 4, bitmapData++) {
+ uint16 pixel = *bitmapData;
+ int r = pixel >> 11;
+ texDataPtr[0] = (r << 3) | (r >> 2);
+ int g = (pixel >> 5) & 0x3f;
+ texDataPtr[1] = (g << 2) | (g >> 4);
+ int b = pixel & 0x1f;
+ texDataPtr[2] = (b << 3) | (b >> 2);
+ if (pixel == 0xf81f) { // transparent
+ texDataPtr[3] = 0;
+ //bitmap->_hasTransparency = true;
+ } else {
+ texDataPtr[3] = 255;
+ }
+ }
+ texOut = texData;
+ } else if (_colorFormat == BM_RGB1555) {
+ std::cout << "TODO: BM_RGB1555 Support" << std::endl;
+ // bitmap->convertToColorFormat(pic, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
+ // texOut = (byte *)bitmap->getImageData(pic).getRawBuffer();
+ } else {
+ texOut = (byte *)_data[pic];
+ }
+
+ for (int i = 0; i < _numTex; i++) {
+ glBindTexture(GL_TEXTURE_2D, textures[_numTex * pic + i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexImage2D(GL_TEXTURE_2D, 0, format, BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0, format, type, NULL);
+ }
+
+ int cur_tex_idx = _numTex * pic;
+
+ for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) {
+ for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) {
+ int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE;
+ int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE;
+ glBindTexture(GL_TEXTURE_2D, textures[cur_tex_idx]);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type,
+ texOut + (y * bytes * _width) + (bytes * x));
+ cur_tex_idx++;
+ }
+ }
+ }
+
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ }
+
+ void Tile::drawBitmap(int dx, int dy, uint32 layer) {
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(-1, 1, -1, 1, 0, 1);
+
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_LIGHTING);
+ glEnable(GL_TEXTURE_2D);
+ glColor3f(1, 1, 1);
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+
+ GLuint *textures = (GLuint *)_texIds;
+ float *texc = _texc;
+
+ uint32 offset = _layers[layer]._offset;
+ for (uint32 i = offset; i < offset + _layers[layer]._numImages; ++i) {
+ glBindTexture(GL_TEXTURE_2D, textures[_verts[i]._texid]);
+ glBegin(GL_QUADS);
+ uint32 ntex = _verts[i]._pos * 4;
+ for (uint32 x = 0; x < _verts[i]._verts; ++x) {
+ glTexCoord2f(texc[ntex + 2], texc[ntex + 3]);
+ glVertex2f(texc[ntex + 0], texc[ntex + 1]);
+ ntex += 4;
+ }
+ glEnd();
+ }
+
+ glDisable(GL_TEXTURE_2D);
+ glDepthMask(GL_TRUE);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ return;
+ }
+
+ void renderInit() {
+ glClearColor(0.2f, 0.2f, 0.2f, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ }
+
+ // HACK, to enable and disable layers
+ static int keyForLayer = -1;
+ void renderLoop(GLFWwindow *window, Tile &t) {
+ float rot = 0.5f;
+ while (!glfwWindowShouldClose(window) && keyForLayer != -2) {
+ renderInit();
+
+ t.drawAllLayers();
+ if (keyForLayer != -1) {
+ t.toggleLayer(keyForLayer);
+ keyForLayer = -1;
+ }
+ glFlush();
+ glfwSwapBuffers(window);
+ glfwPollEvents();
+ usleep(5000);
+ }
+ glfwTerminate();
+ }
+
+ void keycallback(GLFWwindow *window, int key, int scancode, int action, int mods) {
+ if (action == GLFW_PRESS) {
+ if (key >= GLFW_KEY_0 && key <= GLFW_KEY_9) {
+ keyForLayer = key - GLFW_KEY_0;
+ } else if (key == GLFW_KEY_ESCAPE) {
+ keyForLayer = -2;
+ }
+ }
+ }
+
+ Bytef *decompress(Bytef *in, int size, uint32_t &outsize) {
+ const uint32_t block = 8 * 1024 * 1024;
+ Bytef *dest = new Bytef[block]; // 8 MiB ought to be enough.
+
+ int success = 0;
+ z_stream_s zStream;
+
+ zStream.next_in = Z_NULL;
+ zStream.avail_in = 0;
+ zStream.zalloc = Z_NULL;
+ zStream.zfree = Z_NULL;
+ zStream.opaque = Z_NULL;
+
+ success = inflateInit2(&zStream, 16 + MAX_WBITS);
+ if (success != Z_OK) {
+ std::cout << "ZLIB failed to initialize\n";
+ return 0;
+ }
+ zStream.avail_in = size;
+ zStream.next_in = in;
+ zStream.avail_out = block;
+ zStream.next_out = dest;
+
+ success = inflate(&zStream, Z_NO_FLUSH);
+
+ outsize = zStream.total_out;
+
+ if (success != Z_STREAM_END) {
+ std::cout << "ERROR: decompressed size bigger than 8 MiB\n";
+ return 0;
+ }
+ return dest;
+ }
+
+
+ int main(int argc, char **argv) {
+ if (argc < 2) {
+ std::cout << "No Argument" << std::endl;
+ std::cout << "Usage: renderTil [labfilename] <filename>" << std::endl;
+ return 0;
+ }
+
+ Lab *lab = NULL;
+ std::string filename;
+ int length = 0;
+
+ if (argc > 2) {
+ lab = new Lab(argv[1]);
+ filename = argv[2];
+ } else {
+ filename = argv[1];
+ }
+
+ std::istream *file = getFile(filename, lab, length);
+
+ if (!file) {
+ std::cout << "ERROR: Could not open file" << std::endl;
+ return 0;
+ }
+
+ Bytef *compressedData = new Bytef[length];
+ file->read((char *)compressedData, length);
+ uint32_t outsize;
+ Bytef *data = decompress((Bytef *)compressedData, length, outsize);
+ delete[] compressedData;
+ if (!data) {
+ return -1;
+ }
+
+ MemoryReadStream *stream = new MemoryReadStream(data, outsize);
+
+ // Initialization and render-loop more or less copied directly from
+ // http://www.glfw.org/documentation.html
+ glfwInit();
+ GLFWwindow *window = glfwCreateWindow(640, 480, filename.c_str(), NULL, NULL);
+ glfwMakeContextCurrent(window);
+ glfwSetKeyCallback(window, keycallback);
+ Tile t;
+ if (t.loadTile(stream)) {
+ t.createBitmap();
+ std::cout << "Loading of " << filename << " succeeded" << std::endl;
+ std::cout << "Use keys 0 - 9 to enable or disable layers, close window to exit, or press ESC" << std::endl;
+ renderLoop(window, t);
+ } else {
+ std::cout << "Load error for " << filename << std::endl;
+ }
+ delete stream;
+ return 0;
+ }
diff --cc engines/grim/emi/setb2set.cpp
index 000000000,b5043b5bf..b5043b5bf
mode 000000,100644..100644
--- a/engines/grim/emi/setb2set.cpp
+++ b/engines/grim/emi/setb2set.cpp
diff --cc engines/grim/emi/sklb2txt.cpp
index 000000000,bd20f559b..bd20f559b
mode 000000,100644..100644
--- a/engines/grim/emi/sklb2txt.cpp
+++ b/engines/grim/emi/sklb2txt.cpp
diff --cc engines/grim/emi/til2bmp.cpp
index 000000000,797cd9c82..797cd9c82
mode 000000,100644..100644
--- a/engines/grim/emi/til2bmp.cpp
+++ b/engines/grim/emi/til2bmp.cpp
diff --cc engines/grim/imc2wav.cpp
index 000000000,d01d4abf5..d01d4abf5
mode 000000,100644..100644
--- a/engines/grim/imc2wav.cpp
+++ b/engines/grim/imc2wav.cpp
diff --cc engines/grim/int2flt.cpp
index 000000000,75d61097f..75d61097f
mode 000000,100644..100644
--- a/engines/grim/int2flt.cpp
+++ b/engines/grim/int2flt.cpp
diff --cc engines/grim/lab.cpp
index 000000000,a591135b3..a591135b3
mode 000000,100644..100644
--- a/engines/grim/lab.cpp
+++ b/engines/grim/lab.cpp
diff --cc engines/grim/lab.h
index 000000000,c85769fb6..c85769fb6
mode 000000,100644..100644
--- a/engines/grim/lab.h
+++ b/engines/grim/lab.h
diff --cc engines/grim/lua/Changelog
index 000000000,55322a88c..1da343570
mode 000000,100644..100644
--- a/engines/grim/lua/Changelog
+++ b/engines/grim/lua/Changelog
@@@ -1,0 -1,14 +1,14 @@@
-This is a modified version of Lua 3.1 intended for use with ResidualVM.
++This is a modified version of Lua 3.1 intended for use with ScummVM.
+ The major changes made from the original version of Lua 3.1 are:
+
+ * Applied differences from RCS labeled 3.1-alpha from lua.org.
+ * Changed the binary file loader to allow read GrimE lua files.
+ * Revamped the way function calls and returns are handled in order to
+ facilitate implementing GrimE's cooperative multithreading model.
+ * Added several internal functions which implement this multithreading.
+ * Added save/restore Lua state in the files: lsave.cpp and lrestore.cpp.
+ * Unified types like int -> int32 and similiars.
+ * Removed few library functions not used by game engine.
+ * Formatting code.
+ * Replace FILE usage code with File class code.
+ * Remove union from TaggedString, that simplify things.
diff --cc engines/grim/lua/lapi.cpp
index 000000000,128515f84..128515f84
mode 000000,100644..100644
--- a/engines/grim/lua/lapi.cpp
+++ b/engines/grim/lua/lapi.cpp
diff --cc engines/grim/lua/lapi.h
index 000000000,11950cbb2..11950cbb2
mode 000000,100644..100644
--- a/engines/grim/lua/lapi.h
+++ b/engines/grim/lua/lapi.h
diff --cc engines/grim/lua/lauxlib.cpp
index 000000000,a59882d8c..a59882d8c
mode 000000,100644..100644
--- a/engines/grim/lua/lauxlib.cpp
+++ b/engines/grim/lua/lauxlib.cpp
diff --cc engines/grim/lua/lauxlib.h
index 000000000,f6645474f..f6645474f
mode 000000,100644..100644
--- a/engines/grim/lua/lauxlib.h
+++ b/engines/grim/lua/lauxlib.h
diff --cc engines/grim/lua/lbuffer.cpp
index 000000000,45a363623..45a363623
mode 000000,100644..100644
--- a/engines/grim/lua/lbuffer.cpp
+++ b/engines/grim/lua/lbuffer.cpp
diff --cc engines/grim/lua/lbuiltin.cpp
index 000000000,c63e5ed6a..c63e5ed6a
mode 000000,100644..100644
--- a/engines/grim/lua/lbuiltin.cpp
+++ b/engines/grim/lua/lbuiltin.cpp
diff --cc engines/grim/lua/lbuiltin.h
index 000000000,a76db6dfa..a76db6dfa
mode 000000,100644..100644
--- a/engines/grim/lua/lbuiltin.h
+++ b/engines/grim/lua/lbuiltin.h
diff --cc engines/grim/lua/ldo.cpp
index 000000000,faaab66b6..faaab66b6
mode 000000,100644..100644
--- a/engines/grim/lua/ldo.cpp
+++ b/engines/grim/lua/ldo.cpp
diff --cc engines/grim/lua/ldo.h
index 000000000,9e236430a..9e236430a
mode 000000,100644..100644
--- a/engines/grim/lua/ldo.h
+++ b/engines/grim/lua/ldo.h
diff --cc engines/grim/lua/lfunc.cpp
index 000000000,61ab888a0..61ab888a0
mode 000000,100644..100644
--- a/engines/grim/lua/lfunc.cpp
+++ b/engines/grim/lua/lfunc.cpp
diff --cc engines/grim/lua/lfunc.h
index 000000000,28272465c..28272465c
mode 000000,100644..100644
--- a/engines/grim/lua/lfunc.h
+++ b/engines/grim/lua/lfunc.h
diff --cc engines/grim/lua/lgc.cpp
index 000000000,7c978f2cb..7c978f2cb
mode 000000,100644..100644
--- a/engines/grim/lua/lgc.cpp
+++ b/engines/grim/lua/lgc.cpp
diff --cc engines/grim/lua/lgc.h
index 000000000,43e2fb4f1..43e2fb4f1
mode 000000,100644..100644
--- a/engines/grim/lua/lgc.h
+++ b/engines/grim/lua/lgc.h
diff --cc engines/grim/lua/liolib.cpp
index 000000000,ffef2d551..ffef2d551
mode 000000,100644..100644
--- a/engines/grim/lua/liolib.cpp
+++ b/engines/grim/lua/liolib.cpp
diff --cc engines/grim/lua/llex.cpp
index 000000000,98eade1f5..98eade1f5
mode 000000,100644..100644
--- a/engines/grim/lua/llex.cpp
+++ b/engines/grim/lua/llex.cpp
diff --cc engines/grim/lua/llex.h
index 000000000,93e8ec8e9..93e8ec8e9
mode 000000,100644..100644
--- a/engines/grim/lua/llex.h
+++ b/engines/grim/lua/llex.h
diff --cc engines/grim/lua/lmathlib.cpp
index 000000000,cb22df4d1..cb22df4d1
mode 000000,100644..100644
--- a/engines/grim/lua/lmathlib.cpp
+++ b/engines/grim/lua/lmathlib.cpp
diff --cc engines/grim/lua/lmem.cpp
index 000000000,9d03263cc..9d03263cc
mode 000000,100644..100644
--- a/engines/grim/lua/lmem.cpp
+++ b/engines/grim/lua/lmem.cpp
diff --cc engines/grim/lua/lmem.h
index 000000000,12671acd8..12671acd8
mode 000000,100644..100644
--- a/engines/grim/lua/lmem.h
+++ b/engines/grim/lua/lmem.h
diff --cc engines/grim/lua/lobject.cpp
index 000000000,57c0d99f7..57c0d99f7
mode 000000,100644..100644
--- a/engines/grim/lua/lobject.cpp
+++ b/engines/grim/lua/lobject.cpp
diff --cc engines/grim/lua/lobject.h
index 000000000,dfa6bc53c..dfa6bc53c
mode 000000,100644..100644
--- a/engines/grim/lua/lobject.h
+++ b/engines/grim/lua/lobject.h
diff --cc engines/grim/lua/lopcodes.h
index 000000000,a39284f1f..a39284f1f
mode 000000,100644..100644
--- a/engines/grim/lua/lopcodes.h
+++ b/engines/grim/lua/lopcodes.h
diff --cc engines/grim/lua/lparser.cpp
index 000000000,60d4adc1f..60d4adc1f
mode 000000,100644..100644
--- a/engines/grim/lua/lparser.cpp
+++ b/engines/grim/lua/lparser.cpp
diff --cc engines/grim/lua/lparser.h
index 000000000,2559a23d3..2559a23d3
mode 000000,100644..100644
--- a/engines/grim/lua/lparser.h
+++ b/engines/grim/lua/lparser.h
diff --cc engines/grim/lua/lstate.cpp
index 000000000,2c6bd4d08..2c6bd4d08
mode 000000,100644..100644
--- a/engines/grim/lua/lstate.cpp
+++ b/engines/grim/lua/lstate.cpp
diff --cc engines/grim/lua/lstate.h
index 000000000,2b7b1a0f4..2b7b1a0f4
mode 000000,100644..100644
--- a/engines/grim/lua/lstate.h
+++ b/engines/grim/lua/lstate.h
diff --cc engines/grim/lua/lstring.cpp
index 000000000,a9d74e809..a9d74e809
mode 000000,100644..100644
--- a/engines/grim/lua/lstring.cpp
+++ b/engines/grim/lua/lstring.cpp
diff --cc engines/grim/lua/lstring.h
index 000000000,d5eb23da6..d5eb23da6
mode 000000,100644..100644
--- a/engines/grim/lua/lstring.h
+++ b/engines/grim/lua/lstring.h
diff --cc engines/grim/lua/lstrlib.cpp
index 000000000,e8e11a6cd..e8e11a6cd
mode 000000,100644..100644
--- a/engines/grim/lua/lstrlib.cpp
+++ b/engines/grim/lua/lstrlib.cpp
diff --cc engines/grim/lua/ltable.cpp
index 000000000,6e6847f73..6e6847f73
mode 000000,100644..100644
--- a/engines/grim/lua/ltable.cpp
+++ b/engines/grim/lua/ltable.cpp
diff --cc engines/grim/lua/ltable.h
index 000000000,02b4b54c7..02b4b54c7
mode 000000,100644..100644
--- a/engines/grim/lua/ltable.h
+++ b/engines/grim/lua/ltable.h
diff --cc engines/grim/lua/ltask.cpp
index 000000000,2757dd006..2757dd006
mode 000000,100644..100644
--- a/engines/grim/lua/ltask.cpp
+++ b/engines/grim/lua/ltask.cpp
diff --cc engines/grim/lua/ltask.h
index 000000000,730343f6f..730343f6f
mode 000000,100644..100644
--- a/engines/grim/lua/ltask.h
+++ b/engines/grim/lua/ltask.h
diff --cc engines/grim/lua/ltm.cpp
index 000000000,bbb5bab1a..bbb5bab1a
mode 000000,100644..100644
--- a/engines/grim/lua/ltm.cpp
+++ b/engines/grim/lua/ltm.cpp
diff --cc engines/grim/lua/ltm.h
index 000000000,bbecfd1ec..bbecfd1ec
mode 000000,100644..100644
--- a/engines/grim/lua/ltm.h
+++ b/engines/grim/lua/ltm.h
diff --cc engines/grim/lua/lua.h
index 000000000,e7d509bc9..b0ea6a3d2
mode 000000,100644..100644
--- a/engines/grim/lua/lua.h
+++ b/engines/grim/lua/lua.h
@@@ -1,0 -1,227 +1,227 @@@
+ /*
+ ** $Id: lua.h 922 2008-07-25 22:21:04Z aquadran $
+ ** Lua - An Extensible Extension Language
+ ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
+ ** e-mail: lua at tecgraf.puc-rio.br
+ ** www: http://www.tecgraf.puc-rio.br/lua/
+ ** See Copyright Notice at the end of this file
+ */
+
+ #include "common/scummsys.h"
+
+ #ifndef lua_h
+ #define lua_h
+
+ #define LUA_VERSION "Lua 3.1"
+ #define LUA_COPYRIGHT "Copyright (C) 1994-1998 TeCGraf, PUC-Rio"
+ #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
+
+ #define LUA_NOOBJECT 0
+
+ #define LUA_ANYTAG (-1)
+
+ typedef void (*lua_CFunction)(void);
+ typedef uint32 lua_Object;
+
+ typedef struct lua_State lua_State;
+ extern lua_State *lua_state;
+
+ struct PointerId {
+ uint32 low;
+ uint32 hi;
+ };
+
+ PointerId makeIdFromPointer(void *ptr);
+ void *makePointerFromId(PointerId ptr);
+
+ typedef void (*SaveStream)(void *, int32);
+ typedef void (*SaveSint32)(int32);
+ typedef void (*SaveUint32)(uint32);
+ typedef void (*RestoreStream)(void *, int32);
+ typedef int32 (*RestoreSint32)();
+ typedef uint32 (*RestoreUint32)();
+ typedef PointerId (*SaveCallback)(int32, PointerId, SaveSint32);
+ typedef PointerId (*RestoreCallback)(int32, PointerId, RestoreSint32);
+
+ extern SaveCallback saveCallbackPtr;
+ extern RestoreCallback restoreCallbackPtr;
+
+ void lua_Save(SaveStream, SaveSint32, SaveUint32);
+ void lua_Restore(RestoreStream, RestoreSint32, RestoreUint32);
+
+ void lua_removelibslists(void);
+
+ void lua_open (void);
+ void lua_close (void);
+ lua_State *lua_setstate (lua_State *st);
+
+ lua_Object lua_settagmethod (int32 tag, const char *event); /* In: new method */
+ lua_Object lua_gettagmethod (int32 tag, const char *event);
+ lua_Object lua_seterrormethod (void); /* In: new method */
+
+ int32 lua_newtag (void);
+ int32 lua_copytagmethods (int32 tagto, int32 tagfrom);
+ void lua_settag (int32 tag); /* In: object */
+
+ void lua_error (const char *s);
+ int32 lua_dofile (const char *filename); /* Out: returns */
+ int32 lua_dostring (const char *string); /* Out: returns */
+ int32 lua_dobuffer (const char *buff, int32 size, const char *name);
+ /* Out: returns */
+ int32 lua_callfunction (lua_Object f);
+ /* In: parameters; Out: returns */
+
+ void lua_beginblock (void);
+ void lua_endblock (void);
+
+ lua_Object lua_lua2C (int32 number);
+ #define lua_getparam(_) lua_lua2C(_)
+ #define lua_getresult(_) lua_lua2C(_)
+
+ int32 lua_isnil (lua_Object object);
+ int32 lua_istable (lua_Object object);
+ int32 lua_isuserdata (lua_Object object);
+ int32 lua_iscfunction (lua_Object object);
+ int32 lua_isnumber (lua_Object object);
+ int32 lua_isstring (lua_Object object);
+ int32 lua_isfunction (lua_Object object);
+
+ double lua_getnumber (lua_Object object);
+ const char *lua_getstring (lua_Object object);
+ int32 lua_strlen (lua_Object object);
+ lua_CFunction lua_getcfunction (lua_Object object);
+ void *lua_getuserdata (lua_Object object);
+
+
+ void lua_pushnil (void);
+ void lua_pushnumber (double n);
+ void lua_pushlstring (const char *s, int32 len);
+ void lua_pushstring (const char *s);
+ void lua_pushcclosure (lua_CFunction fn, int32 n);
+ void lua_pushusertag (void *u, int32 tag);
+ void lua_pushobject (lua_Object object);
+
+ lua_Object lua_pop (void);
+
+ lua_Object lua_getglobal (const char *name);
+ lua_Object lua_rawgetglobal (const char *name);
+ void lua_setglobal (const char *name); /* In: value */
+ void lua_rawsetglobal (const char *name); /* In: value */
+
+ void lua_settable (void); /* In: table, index, value */
+ void lua_rawsettable (void); /* In: table, index, value */
+ lua_Object lua_gettable (void); /* In: table, index */
+ lua_Object lua_rawgettable (void); /* In: table, index */
+
+ int32 lua_tag (lua_Object object);
+
+
+ int32 lua_ref (int32 lock); /* In: value */
+ lua_Object lua_getref (int32 ref);
+ void lua_unref (int32 ref);
+
+ lua_Object lua_createtable (void);
+
+ int32 lua_collectgarbage (int32 limit);
+
+ void lua_runtasks (void);
+
+ void current_script (void);
+
+ /* =============================================================== */
+ /* some useful macros/derived functions */
+
+ int32 (lua_call) (char *name);
+ #define lua_call(name) lua_callfunction(lua_getglobal(name))
+
+ void (lua_pushref) (int32 ref);
+ #define lua_pushref(ref) lua_pushobject(lua_getref(ref))
+
+ int32 (lua_refobject) (lua_Object o, int32 l);
+ #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
+
+ void (lua_register) (char *n, lua_CFunction f);
+ #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n))
+
+ void (lua_pushuserdata) (void *u);
+ #define lua_pushuserdata(u) lua_pushusertag(u, 0)
+
+ void (lua_pushcfunction) (lua_CFunction f);
+ #define lua_pushcfunction(f) lua_pushcclosure(f, 0)
+
+ int32 (lua_clonetag) (int32 t);
+ #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
+
+
+ /* ==========================================================================
+ ** for compatibility with old versions. Avoid using these macros/functions
+ ** If your program does need any of these, define LUA_COMPAT2_5
+ */
+ //#define LUA_COMPAT2_5
+
+ #ifdef LUA_COMPAT2_5
+
+
+ lua_Object lua_setfallback (char *event, lua_CFunction fallback);
+
+ #define lua_storeglobal lua_setglobal
+ #define lua_type lua_tag
+
+ #define lua_lockobject(o) lua_refobject(o,1)
+ #define lua_lock() lua_ref(1)
+ #define lua_getlocked lua_getref
+ #define lua_pushlocked lua_pushref
+ #define lua_unlock lua_unref
+
+ #define lua_pushliteral(o) lua_pushstring(o)
+
+ #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable())
+ #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_gettable())
+
+ #define lua_copystring(o) (strdup(lua_getstring(o)))
+
+ #define lua_getsubscript lua_gettable
+ #define lua_storesubscript lua_settable
+
+ #endif
+
+ #endif
+
+
+
+ /******************************************************************************
+ * Copyright (c) 1994-1998 TeCGraf, PUC-Rio. All rights reserved.
+ *
+ * Permission is hereby granted, without written agreement and without license
+ * or royalty fees, to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, including commercial applications, subject to
+ * the following conditions:
+ *
+ * - The above copyright notice and this permission notice shall appear in all
+ * copies or substantial portions of this software.
+ *
+ * - 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 greatly
+ * appreciated (but it is not required).
+ *
+ * - Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ *
+ * The authors specifically disclaim any warranties, including, but not limited
+ * to, the implied warranties of merchantability and fitness for a particular
+ * purpose. The software provided hereunder is on an "as is" basis, and the
+ * authors have no obligation to provide maintenance, support, updates,
+ * enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the
+ * authors be held liable to any party for direct, indirect, special,
+ * incidental, or consequential damages arising out of the use of this software
+ * and its documentation.
+ *
+ * The Lua language and this implementation have been entirely designed and
+ * written by Waldemar Celes Filho, Roberto Ierusalimschy and
+ * Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio.
+ *
+ * NOTE: This implementation of Lua contains additional code and
-* modifications added only for ResidualVM project.
++* modifications added only for ScummVM project.
+ * Look into the source code file "Changelog" for more info.
+ ******************************************************************************/
diff --cc engines/grim/lua/luadebug.h
index 000000000,54cac1b58..54cac1b58
mode 000000,100644..100644
--- a/engines/grim/lua/luadebug.h
+++ b/engines/grim/lua/luadebug.h
diff --cc engines/grim/lua/lualib.h
index 000000000,62ab6fa90..62ab6fa90
mode 000000,100644..100644
--- a/engines/grim/lua/lualib.h
+++ b/engines/grim/lua/lualib.h
diff --cc engines/grim/lua/lundump.cpp
index 000000000,b2cad6e83..b2cad6e83
mode 000000,100644..100644
--- a/engines/grim/lua/lundump.cpp
+++ b/engines/grim/lua/lundump.cpp
diff --cc engines/grim/lua/lundump.h
index 000000000,54b18c5f8..54b18c5f8
mode 000000,100644..100644
--- a/engines/grim/lua/lundump.h
+++ b/engines/grim/lua/lundump.h
diff --cc engines/grim/lua/lvm.cpp
index 000000000,cc89b5d4b..cc89b5d4b
mode 000000,100644..100644
--- a/engines/grim/lua/lvm.cpp
+++ b/engines/grim/lua/lvm.cpp
diff --cc engines/grim/lua/lvm.h
index 000000000,306527012..306527012
mode 000000,100644..100644
--- a/engines/grim/lua/lvm.h
+++ b/engines/grim/lua/lvm.h
diff --cc engines/grim/lua/lzio.cpp
index 000000000,be49d6c8d..be49d6c8d
mode 000000,100644..100644
--- a/engines/grim/lua/lzio.cpp
+++ b/engines/grim/lua/lzio.cpp
diff --cc engines/grim/lua/lzio.h
index 000000000,6b1ecccd9..6b1ecccd9
mode 000000,100644..100644
--- a/engines/grim/lua/lzio.h
+++ b/engines/grim/lua/lzio.h
diff --cc engines/grim/lua/module.mk
index 000000000,4e80862c4..4e80862c4
mode 000000,100644..100644
--- a/engines/grim/lua/module.mk
+++ b/engines/grim/lua/module.mk
diff --cc engines/grim/luac/dump.cpp
index 000000000,14dd3ca5d..14dd3ca5d
mode 000000,100644..100644
--- a/engines/grim/luac/dump.cpp
+++ b/engines/grim/luac/dump.cpp
diff --cc engines/grim/luac/luac.cpp
index 000000000,6afb9a23d..6afb9a23d
mode 000000,100644..100644
--- a/engines/grim/luac/luac.cpp
+++ b/engines/grim/luac/luac.cpp
diff --cc engines/grim/luac/luac.h
index 000000000,77f3eb11f..77f3eb11f
mode 000000,100644..100644
--- a/engines/grim/luac/luac.h
+++ b/engines/grim/luac/luac.h
diff --cc engines/grim/luac/module.mk
index 000000000,02d38e83b..02d38e83b
mode 000000,100644..100644
--- a/engines/grim/luac/module.mk
+++ b/engines/grim/luac/module.mk
diff --cc engines/grim/luac/opcode.cpp
index 000000000,1476c1320..1476c1320
mode 000000,100644..100644
--- a/engines/grim/luac/opcode.cpp
+++ b/engines/grim/luac/opcode.cpp
diff --cc engines/grim/luac/opcode.h
index 000000000,6bc608669..6bc608669
mode 000000,100644..100644
--- a/engines/grim/luac/opcode.h
+++ b/engines/grim/luac/opcode.h
diff --cc engines/grim/luac/opt.cpp
index 000000000,c0e13e48c..c0e13e48c
mode 000000,100644..100644
--- a/engines/grim/luac/opt.cpp
+++ b/engines/grim/luac/opt.cpp
diff --cc engines/grim/luac/print.cpp
index 000000000,1fc4870d3..1fc4870d3
mode 000000,100644..100644
--- a/engines/grim/luac/print.cpp
+++ b/engines/grim/luac/print.cpp
diff --cc engines/grim/luac/rebase.cpp
index 000000000,71cc730c4..71cc730c4
mode 000000,100644..100644
--- a/engines/grim/luac/rebase.cpp
+++ b/engines/grim/luac/rebase.cpp
diff --cc engines/grim/mat2ppm.cpp
index 000000000,fa62aa342..fa62aa342
mode 000000,100644..100644
--- a/engines/grim/mat2ppm.cpp
+++ b/engines/grim/mat2ppm.cpp
diff --cc engines/grim/mklab.cpp
index 000000000,8109b53d3..8109b53d3
mode 000000,100644..100644
--- a/engines/grim/mklab.cpp
+++ b/engines/grim/mklab.cpp
diff --cc engines/grim/module.mk
index 000000000,4bedd516e..4bedd516e
mode 000000,100644..100644
--- a/engines/grim/module.mk
+++ b/engines/grim/module.mk
diff --cc engines/grim/patchex/cab.h
index 000000000,8f5c57130..e54829920
mode 000000,100644..100644
--- a/engines/grim/patchex/cab.h
+++ b/engines/grim/patchex/cab.h
@@@ -1,0 -1,126 +1,126 @@@
+ /* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+ /* This file is part of libmspack.
+ * (C) 2003-2004 Stuart Caie.
+ *
- * This source code is adopted and striped for Residual project.
++ * This source code is adopted and striped for ScummVM project.
+ *
+ * libmspack is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License (LGPL) version 2.1
+ *
+ * For further details, see the file COPYING.LIB distributed with libmspack
+ */
+
+ #ifndef MSPACK_CAB_H
+ #define MSPACK_CAB_H
+
+ #include "tools/patchex/mszip.h"
+
+ #define cfhead_Signature (0x00)
+ #define cfhead_CabinetSize (0x08)
+ #define cfhead_FileOffset (0x10)
+ #define cfhead_MinorVersion (0x18)
+ #define cfhead_MajorVersion (0x19)
+ #define cfhead_NumFolders (0x1A)
+ #define cfhead_NumFiles (0x1C)
+ #define cfhead_Flags (0x1E)
+ #define cfhead_SetID (0x20)
+ #define cfhead_CabinetIndex (0x22)
+ #define cfhead_SIZEOF (0x24)
+ #define cfheadext_HeaderReserved (0x00)
+ #define cfheadext_FolderReserved (0x02)
+ #define cfheadext_DataReserved (0x03)
+ #define cfheadext_SIZEOF (0x04)
+ #define cffold_DataOffset (0x00)
+ #define cffold_NumBlocks (0x04)
+ #define cffold_CompType (0x06)
+ #define cffold_SIZEOF (0x08)
+ #define cffile_UncompressedSize (0x00)
+ #define cffile_FolderOffset (0x04)
+ #define cffile_FolderIndex (0x08)
+ #define cffile_Date (0x0A)
+ #define cffile_Time (0x0C)
+ #define cffile_Attribs (0x0E)
+ #define cffile_SIZEOF (0x10)
+ #define cfdata_CheckSum (0x00)
+ #define cfdata_CompressedSize (0x04)
+ #define cfdata_UncompressedSize (0x06)
+ #define cfdata_SIZEOF (0x08)
+
+ #define cffoldCOMPTYPE_MASK (0x000f)
+ #define cffoldCOMPTYPE_NONE (0x0000)
+ #define cffoldCOMPTYPE_MSZIP (0x0001)
+ #define cfheadPREV_CABINET (0x0001)
+ #define cfheadNEXT_CABINET (0x0002)
+ #define cfheadRESERVE_PRESENT (0x0004)
+ #define cffileCONTINUED_FROM_PREV (0xFFFD)
+ #define cffileCONTINUED_TO_NEXT (0xFFFE)
+ #define cffileCONTINUED_PREV_AND_NEXT (0xFFFF)
+
+ #define CAB_BLOCKMAX (32768)
+ #define CAB_INPUTMAX (CAB_BLOCKMAX+6144)
+
+ struct mscabd_decompress_state {
+ struct mscabd_folder_p *folder;
+ struct mscabd_folder_data *data;
+ unsigned int offset;
+ unsigned int block;
+ struct mspack_system sys;
+ int comp_type;
+ int (*decompress)(void *, off_t);
+ void *state;
+ struct mscabd_cabinet_p *incab;
+ struct mspack_file *infh;
+ struct mspack_file *outfh;
+ unsigned char *i_ptr, *i_end;
+ unsigned char input[CAB_INPUTMAX];
+ };
+
+ struct mscab_decompressor_p {
+ struct mscab_decompressor base;
+ struct mscabd_decompress_state *d;
+ struct mspack_system *system;
+ int param[3];
+ int error;
+ };
+
+ struct mscabd_cabinet_p {
+ struct mscabd_cabinet base;
+ off_t blocks_off;
+ int block_resv;
+ };
+
+ struct mscabd_folder_data {
+ struct mscabd_folder_data *next;
+ struct mscabd_cabinet_p *cab;
+ off_t offset;
+ };
+
+ struct mscabd_folder_p {
+ struct mscabd_folder base;
+ struct mscabd_folder_data data;
+ struct mscabd_file *merge_prev;
+ struct mscabd_file *merge_next;
+ };
+
+ #endif
diff --cc engines/grim/patchex/cabd.cpp
index 000000000,484d98237..65ce046c8
mode 000000,100644..100644
--- a/engines/grim/patchex/cabd.cpp
+++ b/engines/grim/patchex/cabd.cpp
@@@ -1,0 -1,688 +1,688 @@@
+ /* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+ /* This file is part of libmspack.
+ * (C) 2003-2004 Stuart Caie.
+ *
- * This source code is adopted and striped for Residual project.
++ * This source code is adopted and striped for ScummVM project.
+ *
+ * libmspack is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License (LGPL) version 2.1
+ *
+ * For further details, see the file COPYING.LIB distributed with libmspack
+ */
+
+ #include "tools/patchex/cab.h"
+
+ static struct mscabd_cabinet * cabd_open(
+ struct mscab_decompressor *base, char *filename);
+ static void cabd_close(
+ struct mscab_decompressor *base, struct mscabd_cabinet *origcab);
+ static int cabd_read_headers(
+ struct mspack_system *sys, struct mspack_file *fh,
+ struct mscabd_cabinet_p *cab, off_t offset, int quiet);
+ static char *cabd_read_string(
+ struct mspack_system *sys, struct mspack_file *fh,
+ struct mscabd_cabinet_p *cab, int *error);
+
+ static int cabd_extract(
+ struct mscab_decompressor *base, struct mscabd_file *file, char *filename);
+ static int cabd_init_decomp(
+ struct mscab_decompressor_p *handle, unsigned int ct);
+ static void cabd_free_decomp(
+ struct mscab_decompressor_p *handle);
+ static int cabd_sys_read(
+ struct mspack_file *file, void *buffer, int bytes);
+ static int cabd_sys_write(
+ struct mspack_file *file, void *buffer, int bytes);
+ static int cabd_sys_read_block(
+ struct mspack_system *sys, struct mscabd_decompress_state *d, int *out,
+ int ignore_cksum);
+ static unsigned int cabd_checksum(
+ unsigned char *data, unsigned int bytes, unsigned int cksum);
+
+ static int cabd_error(
+ struct mscab_decompressor *base);
+
+ #define __egi32(a,n) ( ((((unsigned char *) a)[n+3]) << 24) | \
+ ((((unsigned char *) a)[n+2]) << 16) | \
+ ((((unsigned char *) a)[n+1]) << 8) | \
+ ((((unsigned char *) a)[n+0])))
+
+ #define EndGetI32(a) __egi32(a,0)
+ #define EndGetI16(a) ((((a)[1])<<8)|((a)[0]))
+
+ struct mscab_decompressor *
+ mspack_create_cab_decompressor(struct mspack_system *sys)
+ {
+ struct mscab_decompressor_p *handle = NULL;
+
+ if ((handle = (mscab_decompressor_p *)malloc(sizeof(struct mscab_decompressor_p)))) {
+ handle->base.open = &cabd_open;
+ handle->base.close = &cabd_close;
+ handle->base.extract = &cabd_extract;
+ handle->base.last_error = &cabd_error;
+ handle->system = sys;
+ handle->d = NULL;
+ handle->error = MSPACK_ERR_OK;
+
+ handle->param[MSCABD_PARAM_SEARCHBUF] = 32768;
+ handle->param[MSCABD_PARAM_FIXMSZIP] = 0;
+ handle->param[MSCABD_PARAM_DECOMPBUF] = 4096;
+ }
+ return (struct mscab_decompressor *) handle;
+ }
+
+ void mspack_destroy_cab_decompressor(struct mscab_decompressor *base) {
+ struct mscab_decompressor_p *handle = (struct mscab_decompressor_p *) base;
+ if (handle) {
+ struct mspack_system *sys = handle->system;
+ cabd_free_decomp(handle);
+ if (handle->d) {
+ if (handle->d->infh) sys->close(handle->d->infh);
+ free(handle->d);
+ }
+ free(handle);
+ }
+ }
+
+ static struct mscabd_cabinet *cabd_open(struct mscab_decompressor *base,
+ char *filename)
+ {
+ struct mscab_decompressor_p *handle = (struct mscab_decompressor_p *) base;
+ struct mscabd_cabinet_p *cab = NULL;
+ struct mspack_system *sys;
+ struct mspack_file *fh;
+ int error;
+
+ if (!base) return NULL;
+ sys = handle->system;
+
+ if ((fh = sys->open(sys, filename, MSPACK_SYS_OPEN_READ))) {
+ if ((cab = (mscabd_cabinet_p *)malloc(sizeof(struct mscabd_cabinet_p)))) {
+ cab->base.filename = filename;
+ error = cabd_read_headers(sys, fh, cab, (off_t) 0, 0);
+ if (error) {
+ cabd_close(base, (struct mscabd_cabinet *) cab);
+ cab = NULL;
+ }
+ handle->error = error;
+ }
+ else {
+ handle->error = MSPACK_ERR_NOMEMORY;
+ }
+ sys->close(fh);
+ }
+ else {
+ handle->error = MSPACK_ERR_OPEN;
+ }
+ return (struct mscabd_cabinet *) cab;
+ }
+
+ static void cabd_close(struct mscab_decompressor *base,
+ struct mscabd_cabinet *origcab)
+ {
+ struct mscab_decompressor_p *handle = (struct mscab_decompressor_p *) base;
+ struct mscabd_folder_data *dat, *ndat;
+ struct mscabd_cabinet *cab, *ncab;
+ struct mscabd_folder *fol, *nfol;
+ struct mscabd_file *fi, *nfi;
+ struct mspack_system *sys;
+
+ if (!base) return;
+ sys = handle->system;
+
+ handle->error = MSPACK_ERR_OK;
+
+ while (origcab) {
+ /* free files */
+ for (fi = origcab->files; fi; fi = nfi) {
+ nfi = fi->next;
+ free(fi->filename);
+ free(fi);
+ }
+
+ for (fol = origcab->folders; fol; fol = nfol) {
+ nfol = fol->next;
+
+ if (handle->d && (handle->d->folder == (struct mscabd_folder_p *) fol)) {
+ if (handle->d->infh) sys->close(handle->d->infh);
+ cabd_free_decomp(handle);
+ free(handle->d);
+ handle->d = NULL;
+ }
+
+ for (dat = ((struct mscabd_folder_p *)fol)->data.next; dat; dat = ndat) {
+ ndat = dat->next;
+ free(dat);
+ }
+ free(fol);
+ }
+
+ for (cab = origcab; cab; cab = ncab) {
+ ncab = cab->prevcab;
+ free(cab->prevname);
+ free(cab->nextname);
+ free(cab->previnfo);
+ free(cab->nextinfo);
+ if (cab != origcab) free(cab);
+ }
+
+ for (cab = origcab->nextcab; cab; cab = ncab) {
+ ncab = cab->nextcab;
+ free(cab->prevname);
+ free(cab->nextname);
+ free(cab->previnfo);
+ free(cab->nextinfo);
+ free(cab);
+ }
+
+ cab = origcab->next;
+ free(origcab);
+
+ origcab = cab;
+ }
+ }
+
+ static int cabd_read_headers(struct mspack_system *sys,
+ struct mspack_file *fh,
+ struct mscabd_cabinet_p *cab,
+ off_t offset, int quiet)
+ {
+ int num_folders, num_files, folder_resv, i, x;
+ struct mscabd_folder_p *fol, *linkfol = NULL;
+ struct mscabd_file *file, *linkfile = NULL;
+ unsigned char buf[64];
+
+ cab->base.next = NULL;
+ cab->base.files = NULL;
+ cab->base.folders = NULL;
+ cab->base.prevcab = cab->base.nextcab = NULL;
+ cab->base.prevname = cab->base.nextname = NULL;
+ cab->base.previnfo = cab->base.nextinfo = NULL;
+
+ cab->base.base_offset = offset;
+
+ if (sys->seek(fh, offset, MSPACK_SYS_SEEK_START)) {
+ return MSPACK_ERR_SEEK;
+ }
+
+ if (sys->read(fh, &buf[0], cfhead_SIZEOF) != cfhead_SIZEOF) {
+ return MSPACK_ERR_READ;
+ }
+
+ if (EndGetI32(&buf[cfhead_Signature]) != 0x4643534D) {
+ return MSPACK_ERR_SIGNATURE;
+ }
+
+ cab->base.length = EndGetI32(&buf[cfhead_CabinetSize]);
+ cab->base.set_id = EndGetI16(&buf[cfhead_SetID]);
+ cab->base.set_index = EndGetI16(&buf[cfhead_CabinetIndex]);
+
+ num_folders = EndGetI16(&buf[cfhead_NumFolders]);
+ if (num_folders == 0) {
+ if (!quiet) fprintf(stderr, "no folders in cabinet.");
+ return MSPACK_ERR_DATAFORMAT;
+ }
+
+ num_files = EndGetI16(&buf[cfhead_NumFiles]);
+ if (num_files == 0) {
+ if (!quiet) fprintf(stderr, "no files in cabinet.");
+ return MSPACK_ERR_DATAFORMAT;
+ }
+
+ if ((buf[cfhead_MajorVersion] != 1) && (buf[cfhead_MinorVersion] != 3)) {
+ if (!quiet) fprintf(stderr, "WARNING; cabinet version is not 1.3");
+ }
+
+ cab->base.flags = EndGetI16(&buf[cfhead_Flags]);
+ if (cab->base.flags & cfheadRESERVE_PRESENT) {
+ if (sys->read(fh, &buf[0], cfheadext_SIZEOF) != cfheadext_SIZEOF) {
+ return MSPACK_ERR_READ;
+ }
+ cab->base.header_resv = EndGetI16(&buf[cfheadext_HeaderReserved]);
+ folder_resv = buf[cfheadext_FolderReserved];
+ cab->block_resv = buf[cfheadext_DataReserved];
+
+ if (cab->base.header_resv > 60000) {
+ if (!quiet) fprintf(stderr, "WARNING; reserved header > 60000.");
+ }
+
+ if (cab->base.header_resv) {
+ if (sys->seek(fh, (off_t) cab->base.header_resv, MSPACK_SYS_SEEK_CUR)) {
+ return MSPACK_ERR_SEEK;
+ }
+ }
+ }
+ else {
+ cab->base.header_resv = 0;
+ folder_resv = 0;
+ cab->block_resv = 0;
+ }
+
+ if (cab->base.flags & cfheadPREV_CABINET) {
+ cab->base.prevname = cabd_read_string(sys, fh, cab, &x); if (x) return x;
+ cab->base.previnfo = cabd_read_string(sys, fh, cab, &x); if (x) return x;
+ }
+
+ if (cab->base.flags & cfheadNEXT_CABINET) {
+ cab->base.nextname = cabd_read_string(sys, fh, cab, &x); if (x) return x;
+ cab->base.nextinfo = cabd_read_string(sys, fh, cab, &x); if (x) return x;
+ }
+
+ for (i = 0; i < num_folders; i++) {
+ if (sys->read(fh, &buf[0], cffold_SIZEOF) != cffold_SIZEOF) {
+ return MSPACK_ERR_READ;
+ }
+ if (folder_resv) {
+ if (sys->seek(fh, (off_t) folder_resv, MSPACK_SYS_SEEK_CUR)) {
+ return MSPACK_ERR_SEEK;
+ }
+ }
+
+ if (!(fol = (struct mscabd_folder_p *)malloc(sizeof(struct mscabd_folder_p)))) {
+ return MSPACK_ERR_NOMEMORY;
+ }
+ fol->base.next = NULL;
+ fol->base.comp_type = EndGetI16(&buf[cffold_CompType]);
+ fol->base.num_blocks = EndGetI16(&buf[cffold_NumBlocks]);
+ fol->data.next = NULL;
+ fol->data.cab = (struct mscabd_cabinet_p *) cab;
+ fol->data.offset = offset + (off_t)
+ ( (unsigned int) EndGetI32(&buf[cffold_DataOffset]) );
+ fol->merge_prev = NULL;
+ fol->merge_next = NULL;
+
+ if (!linkfol) cab->base.folders = (struct mscabd_folder *) fol;
+ else linkfol->base.next = (struct mscabd_folder *) fol;
+ linkfol = fol;
+ }
+
+ for (i = 0; i < num_files; i++) {
+ if (sys->read(fh, &buf[0], cffile_SIZEOF) != cffile_SIZEOF) {
+ return MSPACK_ERR_READ;
+ }
+
+ if (!(file = (struct mscabd_file *)malloc(sizeof(struct mscabd_file)))) {
+ return MSPACK_ERR_NOMEMORY;
+ }
+
+ file->next = NULL;
+ file->length = EndGetI32(&buf[cffile_UncompressedSize]);
+ file->attribs = EndGetI16(&buf[cffile_Attribs]);
+ file->offset = EndGetI32(&buf[cffile_FolderOffset]);
+
+ x = EndGetI16(&buf[cffile_FolderIndex]);
+ if (x < cffileCONTINUED_FROM_PREV) {
+ struct mscabd_folder *ifol = cab->base.folders;
+ while (x--) if (ifol) ifol = ifol->next;
+ file->folder = ifol;
+
+ if (!ifol) {
+ free(file);
+ return MSPACK_ERR_DATAFORMAT;
+ }
+ }
+ else {
+ if ((x == cffileCONTINUED_TO_NEXT) ||
+ (x == cffileCONTINUED_PREV_AND_NEXT))
+ {
+ struct mscabd_folder *ifol = cab->base.folders;
+ while (ifol->next) ifol = ifol->next;
+ file->folder = ifol;
+
+ fol = (struct mscabd_folder_p *) ifol;
+ if (!fol->merge_next) fol->merge_next = file;
+ }
+
+ if ((x == cffileCONTINUED_FROM_PREV) ||
+ (x == cffileCONTINUED_PREV_AND_NEXT))
+ {
+ file->folder = cab->base.folders;
+
+ fol = (struct mscabd_folder_p *) file->folder;
+ if (!fol->merge_prev) fol->merge_prev = file;
+ }
+ }
+
+ x = EndGetI16(&buf[cffile_Time]);
+ file->time_h = x >> 11;
+ file->time_m = (x >> 5) & 0x3F;
+ file->time_s = (x << 1) & 0x3E;
+
+ x = EndGetI16(&buf[cffile_Date]);
+ file->date_d = x & 0x1F;
+ file->date_m = (x >> 5) & 0xF;
+ file->date_y = (x >> 9) + 1980;
+
+ file->filename = cabd_read_string(sys, fh, cab, &x);
+ if (x) {
+ free(file);
+ return x;
+ }
+
+ if (!linkfile) cab->base.files = file;
+ else linkfile->next = file;
+ linkfile = file;
+ }
+
+ return MSPACK_ERR_OK;
+ }
+
+ static char *cabd_read_string(struct mspack_system *sys,
+ struct mspack_file *fh,
+ struct mscabd_cabinet_p *, int *error)
+ {
+ off_t base = sys->tell(fh);
+ char buf[256], *str;
+ unsigned int len, i, ok;
+
+ len = sys->read(fh, &buf[0], 256);
+
+ for (i = 0, ok = 0; i < len; i++) if (!buf[i]) { ok = 1; break; }
+ if (!ok) {
+ *error = MSPACK_ERR_DATAFORMAT;
+ return NULL;
+ }
+
+ len = i + 1;
+
+ if (sys->seek(fh, base + (off_t)len, MSPACK_SYS_SEEK_START)) {
+ *error = MSPACK_ERR_SEEK;
+ return NULL;
+ }
+
+ if (!(str = (char *)malloc(len))) {
+ *error = MSPACK_ERR_NOMEMORY;
+ return NULL;
+ }
+
+ memcpy(str, &buf[0], len);
+ *error = MSPACK_ERR_OK;
+ return str;
+ }
+
+ static int cabd_extract(struct mscab_decompressor *base,
+ struct mscabd_file *file, char *filename)
+ {
+ struct mscab_decompressor_p *handle = (struct mscab_decompressor_p *) base;
+ struct mscabd_folder_p *fol;
+ struct mspack_system *sys;
+ struct mspack_file *fh;
+
+ if (!handle) return MSPACK_ERR_ARGS;
+ if (!file) return handle->error = MSPACK_ERR_ARGS;
+
+ sys = handle->system;
+ fol = (struct mscabd_folder_p *) file->folder;
+
+ /* check if file can be extracted */
+ if ((!fol) || (fol->merge_prev) ||
+ (((file->offset + file->length) / CAB_BLOCKMAX) > fol->base.num_blocks))
+ {
+ fprintf(stderr, "ERROR; file \"%s\" cannot be extracted, "
+ "cabinet set is incomplete.", file->filename);
+ return handle->error = MSPACK_ERR_DATAFORMAT;
+ }
+
+ if (!handle->d) {
+ handle->d = (mscabd_decompress_state *)malloc(sizeof(struct mscabd_decompress_state));
+ if (!handle->d) return handle->error = MSPACK_ERR_NOMEMORY;
+ handle->d->folder = NULL;
+ handle->d->data = NULL;
+ handle->d->sys = *sys;
+ handle->d->sys.read = &cabd_sys_read;
+ handle->d->sys.write = &cabd_sys_write;
+ handle->d->state = NULL;
+ handle->d->infh = NULL;
+ handle->d->incab = NULL;
+ }
+
+ if ((handle->d->folder != fol) || (handle->d->offset > file->offset)) {
+ if (!handle->d->infh || (fol->data.cab != handle->d->incab)) {
+ if (handle->d->infh) sys->close(handle->d->infh);
+ handle->d->incab = fol->data.cab;
+ handle->d->infh = sys->open(sys, fol->data.cab->base.filename,
+ MSPACK_SYS_OPEN_READ);
+ if (!handle->d->infh) return handle->error = MSPACK_ERR_OPEN;
+ }
+ if (sys->seek(handle->d->infh, fol->data.offset, MSPACK_SYS_SEEK_START)) {
+ return handle->error = MSPACK_ERR_SEEK;
+ }
+
+ if (cabd_init_decomp(handle, (unsigned int) fol->base.comp_type)) {
+ return handle->error;
+ }
+
+ handle->d->folder = fol;
+ handle->d->data = &fol->data;
+ handle->d->offset = 0;
+ handle->d->block = 0;
+ handle->d->i_ptr = handle->d->i_end = &handle->d->input[0];
+ }
+
+ if (!(fh = sys->open(sys, filename, MSPACK_SYS_OPEN_WRITE))) {
+ return handle->error = MSPACK_ERR_OPEN;
+ }
+
+ handle->error = MSPACK_ERR_OK;
+
+ if (file->length) {
+ off_t bytes;
+ int error;
+ handle->d->outfh = NULL;
+ if ((bytes = file->offset - handle->d->offset)) {
+ error = handle->d->decompress(handle->d->state, bytes);
+ if (error != MSPACK_ERR_READ) handle->error = error;
+ }
+
+ if (!handle->error) {
+ handle->d->outfh = fh;
+ error = handle->d->decompress(handle->d->state, (off_t) file->length);
+ if (error != MSPACK_ERR_READ) handle->error = error;
+ }
+ }
+
+ sys->close(fh);
+ handle->d->outfh = NULL;
+
+ return handle->error;
+ }
+
+ static int cabd_init_decomp(struct mscab_decompressor_p *handle, unsigned int ct)
+ {
+ struct mspack_file *fh = (struct mspack_file *) handle;
+
+ if (!handle || !handle->d) {
+ return handle->error = MSPACK_ERR_ARGS;
+ }
+
+ cabd_free_decomp(handle);
+
+ handle->d->comp_type = ct;
+
+ switch (ct & cffoldCOMPTYPE_MASK) {
+ case cffoldCOMPTYPE_MSZIP:
+ handle->d->decompress = (int (*)(void *, off_t)) &mszipd_decompress;
+ handle->d->state = mszipd_init(&handle->d->sys, fh, fh,
+ handle->param[MSCABD_PARAM_DECOMPBUF],
+ handle->param[MSCABD_PARAM_FIXMSZIP]);
+ break;
+ default:
+ return handle->error = MSPACK_ERR_DATAFORMAT;
+ }
+ return handle->error = (handle->d->state) ? MSPACK_ERR_OK : MSPACK_ERR_NOMEMORY;
+ }
+
+ static void cabd_free_decomp(struct mscab_decompressor_p *handle) {
+ if (!handle || !handle->d || !handle->d->folder || !handle->d->state) return;
+
+ switch (handle->d->comp_type & cffoldCOMPTYPE_MASK) {
+ case cffoldCOMPTYPE_MSZIP: mszipd_free((mszipd_stream *)handle->d->state); break;
+ }
+ handle->d->decompress = NULL;
+ handle->d->state = NULL;
+ }
+
+ static int cabd_sys_read(struct mspack_file *file, void *buffer, int bytes) {
+ struct mscab_decompressor_p *handle = (struct mscab_decompressor_p *) file;
+ unsigned char *buf = (unsigned char *) buffer;
+ struct mspack_system *sys = handle->system;
+ int avail, todo, outlen = 0, ignore_cksum;
+
+ ignore_cksum = handle->param[MSCABD_PARAM_FIXMSZIP] &&
+ ((handle->d->comp_type & cffoldCOMPTYPE_MASK) == cffoldCOMPTYPE_MSZIP);
+
+ todo = bytes;
+ while (todo > 0) {
+ avail = handle->d->i_end - handle->d->i_ptr;
+
+ if (avail) {
+ if (avail > todo) avail = todo;
+ memcpy(buf, handle->d->i_ptr, (size_t) avail);
+ handle->d->i_ptr += avail;
+ buf += avail;
+ todo -= avail;
+ }
+ else {
+ if (handle->d->block++ >= handle->d->folder->base.num_blocks) {
+ handle->error = MSPACK_ERR_DATAFORMAT;
+ break;
+ }
+
+ handle->error = cabd_sys_read_block(sys, handle->d, &outlen, ignore_cksum);
+ if (handle->error) return -1;
+
+ if (handle->d->block >= handle->d->folder->base.num_blocks) {
+ } else {
+ if (outlen != CAB_BLOCKMAX) {
+ fprintf(stderr, "WARNING; non-maximal data block");
+ }
+ }
+ }
+ }
+ return bytes - todo;
+ }
+
+ static int cabd_sys_write(struct mspack_file *file, void *buffer, int bytes) {
+ struct mscab_decompressor_p *handle = (struct mscab_decompressor_p *) file;
+ handle->d->offset += bytes;
+ if (handle->d->outfh) {
+ return handle->system->write(handle->d->outfh, buffer, bytes);
+ }
+ return bytes;
+ }
+
+ static int cabd_sys_read_block(struct mspack_system *sys,
+ struct mscabd_decompress_state *d,
+ int *out, int ignore_cksum)
+ {
+ unsigned char hdr[cfdata_SIZEOF];
+ unsigned int cksum;
+ int len;
+
+ d->i_ptr = d->i_end = &d->input[0];
+
+ do {
+ if (sys->read(d->infh, &hdr[0], cfdata_SIZEOF) != cfdata_SIZEOF) {
+ return MSPACK_ERR_READ;
+ }
+
+ if (d->data->cab->block_resv &&
+ sys->seek(d->infh, (off_t) d->data->cab->block_resv,
+ MSPACK_SYS_SEEK_CUR))
+ {
+ return MSPACK_ERR_SEEK;
+ }
+
+ len = EndGetI16(&hdr[cfdata_CompressedSize]);
+ if (((d->i_end - d->i_ptr) + len) > CAB_INPUTMAX) {
+ return MSPACK_ERR_DATAFORMAT;
+ }
+
+ if (EndGetI16(&hdr[cfdata_UncompressedSize]) > CAB_BLOCKMAX) {
+ return MSPACK_ERR_DATAFORMAT;
+ }
+
+ if (sys->read(d->infh, d->i_end, len) != len) {
+ return MSPACK_ERR_READ;
+ }
+
+ if ((cksum = EndGetI32(&hdr[cfdata_CheckSum]))) {
+ unsigned int sum2 = cabd_checksum(d->i_end, (unsigned int) len, 0);
+ if (cabd_checksum(&hdr[4], 4, sum2) != cksum) {
+ if (!ignore_cksum) return MSPACK_ERR_CHECKSUM;
+ fprintf(stderr, "WARNING; bad block checksum found");
+ }
+ }
+
+ d->i_end += len;
+
+ if ((*out = EndGetI16(&hdr[cfdata_UncompressedSize]))) {
+ return MSPACK_ERR_OK;
+ }
+
+ sys->close(d->infh);
+ d->infh = NULL;
+
+ if (!(d->data = d->data->next)) {
+ return MSPACK_ERR_DATAFORMAT;
+ }
+
+ d->incab = d->data->cab;
+ if (!(d->infh = sys->open(sys, d->incab->base.filename,
+ MSPACK_SYS_OPEN_READ)))
+ {
+ return MSPACK_ERR_OPEN;
+ }
+
+ if (sys->seek(d->infh, d->data->offset, MSPACK_SYS_SEEK_START)) {
+ return MSPACK_ERR_SEEK;
+ }
+ } while (1);
+
+ return MSPACK_ERR_OK;
+ }
+
+ static unsigned int cabd_checksum(unsigned char *data, unsigned int bytes,
+ unsigned int cksum)
+ {
+ unsigned int len, ul = 0;
+
+ for (len = bytes >> 2; len--; data += 4) {
+ cksum ^= ((data[0]) | (data[1]<<8) | (data[2]<<16) | (data[3]<<24));
+ }
+
+ switch (bytes & 3) {
+ case 3: ul |= *data++ << 16;
+ case 2: ul |= *data++ << 8;
+ case 1: ul |= *data;
+ }
+ cksum ^= ul;
+
+ return cksum;
+ }
+
+ static int cabd_error(struct mscab_decompressor *base) {
+ struct mscab_decompressor_p *handle = (struct mscab_decompressor_p *) base;
+ return (handle) ? handle->error : MSPACK_ERR_ARGS;
+ }
diff --cc engines/grim/patchex/mspack.h
index 000000000,b6dc1903f..39be6538b
mode 000000,100644..100644
--- a/engines/grim/patchex/mspack.h
+++ b/engines/grim/patchex/mspack.h
@@@ -1,0 -1,169 +1,169 @@@
+ /* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+ /* libmspack -- a library for working with Microsoft compression formats.
+ * (C) 2003-2004 Stuart Caie <kyzer at 4u.net>
+ *
- * This source code is adopted and striped for Residual project.
++ * This source code is adopted and striped for ScummVM project.
+ *
+ * libmspack is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License (LGPL) version 2.1
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+ #ifndef LIB_MSPACK_H
+ #define LIB_MSPACK_H
+
+ #include <sys/types.h>
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <string.h>
+
+ struct mspack_system {
+ struct mspack_file * (*open)(struct mspack_system *self,
+ const char *filename,
+ int mode);
+ void (*close)(struct mspack_file *file);
+ int (*read)(struct mspack_file *file,
+ void *buffer,
+ int bytes);
+ int (*write)(struct mspack_file *file,
+ void *buffer,
+ int bytes);
+ int (*seek)(struct mspack_file *file,
+ off_t offset,
+ int mode);
+ off_t (*tell)(struct mspack_file *file);
+ void *null_ptr;
+ };
+
+ #define MSPACK_SYS_OPEN_READ (0)
+ #define MSPACK_SYS_OPEN_WRITE (1)
+ #define MSPACK_SYS_OPEN_UPDATE (2)
+ #define MSPACK_SYS_OPEN_APPEND (3)
+
+ #define MSPACK_SYS_SEEK_START (0)
+ #define MSPACK_SYS_SEEK_CUR (1)
+ #define MSPACK_SYS_SEEK_END (2)
+
+ struct mspack_file {
+ int dummy;
+ };
+
+ #define MSPACK_ERR_OK (0)
+ #define MSPACK_ERR_ARGS (1)
+ #define MSPACK_ERR_OPEN (2)
+ #define MSPACK_ERR_READ (3)
+ #define MSPACK_ERR_WRITE (4)
+ #define MSPACK_ERR_SEEK (5)
+ #define MSPACK_ERR_NOMEMORY (6)
+ #define MSPACK_ERR_SIGNATURE (7)
+ #define MSPACK_ERR_DATAFORMAT (8)
+ #define MSPACK_ERR_CHECKSUM (9)
+ #define MSPACK_ERR_CRUNCH (10)
+ #define MSPACK_ERR_DECRUNCH (11)
+
+ extern struct mscab_decompressor *
+ mspack_create_cab_decompressor(struct mspack_system *sys);
+
+ extern void mspack_destroy_cab_decompressor(struct mscab_decompressor *self);
+
+ struct mscabd_cabinet {
+ struct mscabd_cabinet *next;
+ char *filename;
+ off_t base_offset;
+ unsigned int length;
+ struct mscabd_cabinet *prevcab;
+ struct mscabd_cabinet *nextcab;
+ char *prevname;
+ char *nextname;
+ char *previnfo;
+ char *nextinfo;
+ struct mscabd_file *files;
+ struct mscabd_folder *folders;
+ unsigned short set_id;
+ unsigned short set_index;
+ unsigned short header_resv;
+ int flags;
+ };
+
+ #define MSCAB_HDR_RESV_OFFSET (0x28)
+ #define MSCAB_HDR_PREVCAB (0x01)
+ #define MSCAB_HDR_NEXTCAB (0x02)
+ #define MSCAB_HDR_RESV (0x04)
+
+ struct mscabd_folder {
+ struct mscabd_folder *next;
+ int comp_type;
+ unsigned int num_blocks;
+ };
+
+ #define MSCABD_COMP_METHOD(comp_type) ((comp_type) & 0x0F)
+ #define MSCABD_COMP_LEVEL(comp_type) (((comp_type) >> 8) & 0x1F)
+ #define MSCAB_COMP_MSZIP (1)
+
+ struct mscabd_file {
+ struct mscabd_file *next;
+ char *filename;
+ unsigned int length;
+ int attribs;
+ char time_h;
+ char time_m;
+ char time_s;
+ char date_d;
+ char date_m;
+ int date_y;
+ struct mscabd_folder *folder;
+ unsigned int offset;
+ };
+
+ #define MSCAB_ATTRIB_RDONLY (0x01)
+ #define MSCAB_ATTRIB_HIDDEN (0x02)
+ #define MSCAB_ATTRIB_SYSTEM (0x04)
+ #define MSCAB_ATTRIB_ARCH (0x20)
+ #define MSCAB_ATTRIB_EXEC (0x40)
+ #define MSCAB_ATTRIB_UTF_NAME (0x80)
+
+ #define MSCABD_PARAM_SEARCHBUF (0)
+ #define MSCABD_PARAM_FIXMSZIP (1)
+ #define MSCABD_PARAM_DECOMPBUF (2)
+
+ struct mscab_decompressor {
+ struct mscabd_cabinet * (*open) (struct mscab_decompressor *self,
+ char *filename);
+ void (*close)(struct mscab_decompressor *self,
+ struct mscabd_cabinet *cab);
+ int (*extract)(struct mscab_decompressor *self,
+ struct mscabd_file *file,
+ char *filename);
+ int (*last_error)(struct mscab_decompressor *self);
+ };
+
+ #endif
diff --cc engines/grim/patchex/mszip.h
index 000000000,5c5321ebf..3a4962e82
mode 000000,100644..100644
--- a/engines/grim/patchex/mszip.h
+++ b/engines/grim/patchex/mszip.h
@@@ -1,0 -1,95 +1,95 @@@
+ /* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+ /* This file is part of libmspack.
+ * (C) 2003-2004 Stuart Caie.
+ *
- * This source code is adopted and striped for Residual project.
++ * This source code is adopted and striped for ScummVM project.
+ *
+ * The deflate method was created by Phil Katz. MSZIP is equivalent to the
+ * deflate method.
+ *
+ * libmspack is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License (LGPL) version 2.1
+ *
+ * For further details, see the file COPYING.LIB distributed with libmspack
+ */
+
+ #ifndef MSPACK_MSZIP_H
+ #define MSPACK_MSZIP_H 1
+
+ #include "tools/patchex/mspack.h"
+
+ #define MSZIP_FRAME_SIZE (32768)
+ #define MSZIP_MAX_HUFFBITS (16)
+ #define MSZIP_LITERAL_MAXSYMBOLS (288)
+ #define MSZIP_LITERAL_TABLEBITS (9)
+ #define MSZIP_DISTANCE_MAXSYMBOLS (32)
+ #define MSZIP_DISTANCE_TABLEBITS (6)
+
+ #if (1 << MSZIP_LITERAL_TABLEBITS) < (MSZIP_LITERAL_MAXSYMBOLS * 2)
+ # define MSZIP_LITERAL_TABLESIZE (MSZIP_LITERAL_MAXSYMBOLS * 4)
+ #else
+ # define MSZIP_LITERAL_TABLESIZE ((1 << MSZIP_LITERAL_TABLEBITS) + \
+ (MSZIP_LITERAL_MAXSYMBOLS * 2))
+ #endif
+
+ #if (1 << MSZIP_DISTANCE_TABLEBITS) < (MSZIP_DISTANCE_MAXSYMBOLS * 2)
+ # define MSZIP_DISTANCE_TABLESIZE (MSZIP_DISTANCE_MAXSYMBOLS * 4)
+ #else
+ # define MSZIP_DISTANCE_TABLESIZE ((1 << MSZIP_DISTANCE_TABLEBITS) + \
+ (MSZIP_DISTANCE_MAXSYMBOLS * 2))
+ #endif
+
+ struct mszipd_stream {
+ struct mspack_system *sys;
+ struct mspack_file *input;
+ struct mspack_file *output;
+ unsigned int window_posn;
+
+ int (*flush_window)(struct mszipd_stream *, unsigned int);
+
+ int error, repair_mode, bytes_output;
+
+ unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end;
+ unsigned int bit_buffer, bits_left, inbuf_size;
+
+ unsigned char LITERAL_len[MSZIP_LITERAL_MAXSYMBOLS];
+ unsigned char DISTANCE_len[MSZIP_DISTANCE_MAXSYMBOLS];
+
+ unsigned short LITERAL_table [MSZIP_LITERAL_TABLESIZE];
+ unsigned short DISTANCE_table[MSZIP_DISTANCE_TABLESIZE];
+
+ unsigned char window[MSZIP_FRAME_SIZE];
+ };
+
+ extern struct mszipd_stream *mszipd_init(struct mspack_system *system,
+ struct mspack_file *input,
+ struct mspack_file *output,
+ int input_buffer_size,
+ int repair_mode);
+
+ extern int mszipd_decompress(struct mszipd_stream *zip, off_t out_bytes);
+
+ void mszipd_free(struct mszipd_stream *zip);
+
+ #endif
diff --cc engines/grim/patchex/mszipd.cpp
index 000000000,ef8661d9a..0cced0072
mode 000000,100644..100644
--- a/engines/grim/patchex/mszipd.cpp
+++ b/engines/grim/patchex/mszipd.cpp
@@@ -1,0 -1,564 +1,564 @@@
+ /* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+ /* This file is part of libmspack.
+ * (C) 2003-2004 Stuart Caie.
+ *
- * This source code is adopted and striped for Residual project.
++ * This source code is adopted and striped for ScummVM project.
+ *
+ * The deflate method was created by Phil Katz. MSZIP is equivalent to the
+ * deflate method.
+ *
+ * libmspack is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License (LGPL) version 2.1
+ *
+ * For further details, see the file COPYING.LIB distributed with libmspack
+ */
+
+ #include "tools/patchex/mszip.h"
+
+ static const unsigned short lit_lengths[29] = {
+ 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 unsigned short dist_offsets[30] = {
+ 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 unsigned char lit_extrabits[29] = {
+ 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 unsigned char dist_extrabits[30] = {
+ 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
+ };
+
+ static const unsigned char bitlen_order[19] = {
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+ };
+
+ static const unsigned short bit_mask[17] = {
+ 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
+ 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
+ };
+
+ #define STORE_BITS do { \
+ zip->i_ptr = i_ptr; \
+ zip->i_end = i_end; \
+ zip->bit_buffer = bit_buffer; \
+ zip->bits_left = bits_left; \
+ } while (0)
+
+ #define RESTORE_BITS do { \
+ i_ptr = zip->i_ptr; \
+ i_end = zip->i_end; \
+ bit_buffer = zip->bit_buffer; \
+ bits_left = zip->bits_left; \
+ } while (0)
+
+ #define ENSURE_BITS(nbits) do { \
+ while (bits_left < (nbits)) { \
+ if (i_ptr >= i_end) { \
+ if (zipd_read_input(zip)) return zip->error; \
+ i_ptr = zip->i_ptr; \
+ i_end = zip->i_end; \
+ } \
+ bit_buffer |= *i_ptr++ << bits_left; bits_left += 8; \
+ } \
+ } while (0)
+
+ #define PEEK_BITS(nbits) (bit_buffer & ((1<<(nbits))-1))
+ #define PEEK_BITS_T(nbits) (bit_buffer & bit_mask[(nbits)])
+
+ #define REMOVE_BITS(nbits) ((bit_buffer >>= (nbits)), (bits_left -= (nbits)))
+
+ #define READ_BITS(val, nbits) do { \
+ ENSURE_BITS(nbits); (val) = PEEK_BITS(nbits); REMOVE_BITS(nbits); \
+ } while (0)
+
+ #define READ_BITS_T(val, nbits) do { \
+ ENSURE_BITS(nbits); (val) = PEEK_BITS_T(nbits); REMOVE_BITS(nbits); \
+ } while (0)
+
+ static int zipd_read_input(struct mszipd_stream *zip) {
+ int read = zip->sys->read(zip->input, &zip->inbuf[0], (int)zip->inbuf_size);
+ if (read < 0) return zip->error = MSPACK_ERR_READ;
+ zip->i_ptr = &zip->inbuf[0];
+ zip->i_end = &zip->inbuf[read];
+
+ return MSPACK_ERR_OK;
+ }
+
+ #define INF_ERR_BLOCKTYPE (-1)
+ #define INF_ERR_COMPLEMENT (-2)
+ #define INF_ERR_FLUSH (-3)
+ #define INF_ERR_BITBUF (-4)
+ #define INF_ERR_SYMLENS (-5)
+ #define INF_ERR_BITLENTBL (-6)
+ #define INF_ERR_LITERALTBL (-7)
+ #define INF_ERR_DISTANCETBL (-8)
+ #define INF_ERR_BITOVERRUN (-9)
+ #define INF_ERR_BADBITLEN (-10)
+ #define INF_ERR_LITCODE (-11)
+ #define INF_ERR_DISTCODE (-12)
+ #define INF_ERR_DISTANCE (-13)
+ #define INF_ERR_HUFFSYM (-14)
+
+ static int make_decode_table(unsigned int nsyms, unsigned int nbits,
+ unsigned char *length, unsigned short *table)
+ {
+ register unsigned int leaf, reverse, fill;
+ register unsigned short sym, next_sym;
+ register unsigned char bit_num;
+ unsigned int pos = 0;
+ unsigned int table_mask = 1 << nbits;
+ unsigned int bmask = table_mask >> 1;
+
+ for (bit_num = 1; bit_num <= nbits; bit_num++) {
+ for (sym = 0; sym < nsyms; sym++) {
+ if (length[sym] != bit_num) continue;
+
+ fill = length[sym]; reverse = pos >> (nbits - fill); leaf = 0;
+ do {leaf <<= 1; leaf |= reverse & 1; reverse >>= 1;} while (--fill);
+
+ if((pos += bmask) > table_mask) return 1;
+
+ fill = bmask; next_sym = 1 << bit_num;
+ do { table[leaf] = sym; leaf += next_sym; } while (--fill);
+ }
+ bmask >>= 1;
+ }
+
+ if (pos == table_mask) return 0;
+
+ for (sym = pos; sym < table_mask; sym++) {
+ reverse = sym; leaf = 0; fill = nbits;
+ do { leaf <<= 1; leaf |= reverse & 1; reverse >>= 1; } while (--fill);
+ table[leaf] = 0xFFFF;
+ }
+
+ next_sym = ((table_mask >> 1) < nsyms) ? nsyms : (table_mask >> 1);
+
+ pos <<= 16;
+ table_mask <<= 16;
+ bmask = 1 << 15;
+
+ for (bit_num = nbits+1; bit_num <= MSZIP_MAX_HUFFBITS; bit_num++) {
+ for (sym = 0; sym < nsyms; sym++) {
+ if (length[sym] != bit_num) continue;
+
+ reverse = pos >> 16; leaf = 0; fill = nbits;
+ do {leaf <<= 1; leaf |= reverse & 1; reverse >>= 1;} while (--fill);
+
+ for (fill = 0; fill < (bit_num - nbits); fill++) {
+ if (table[leaf] == 0xFFFF) {
+ table[(next_sym << 1) ] = 0xFFFF;
+ table[(next_sym << 1) + 1 ] = 0xFFFF;
+ table[leaf] = next_sym++;
+ }
+ leaf = (table[leaf] << 1) | ((pos >> (15 - fill)) & 1);
+ }
+ table[leaf] = sym;
+
+ if ((pos += bmask) > table_mask) return 1;
+ }
+ bmask >>= 1;
+ }
+
+ return (pos != table_mask) ? 1 : 0;
+ }
+
+ #define READ_HUFFSYM(tbl, var) do { \
+ ENSURE_BITS(MSZIP_MAX_HUFFBITS); \
+ sym = zip->tbl##_table[PEEK_BITS(MSZIP_##tbl##_TABLEBITS)]; \
+ if (sym >= MSZIP_##tbl##_MAXSYMBOLS) { \
+ i = MSZIP_##tbl##_TABLEBITS - 1; \
+ do { \
+ if (i++ > MSZIP_MAX_HUFFBITS) { \
+ return INF_ERR_HUFFSYM; \
+ } \
+ sym = zip->tbl##_table[(sym << 1) | ((bit_buffer >> i) & 1)]; \
+ } while (sym >= MSZIP_##tbl##_MAXSYMBOLS); \
+ } \
+ (var) = sym; \
+ i = zip->tbl##_len[sym]; \
+ REMOVE_BITS(i); \
+ } while (0)
+
+ static int zip_read_lens(struct mszipd_stream *zip) {
+ register unsigned int bit_buffer;
+ register int bits_left;
+ unsigned char *i_ptr, *i_end;
+
+ unsigned short bl_table[(1 << 7)];
+ unsigned char bl_len[19];
+
+ unsigned char lens[MSZIP_LITERAL_MAXSYMBOLS + MSZIP_DISTANCE_MAXSYMBOLS];
+ unsigned int lit_codes, dist_codes, code, last_code=0, bitlen_codes, i, run;
+
+ RESTORE_BITS;
+
+ READ_BITS(lit_codes, 5); lit_codes += 257;
+ READ_BITS(dist_codes, 5); dist_codes += 1;
+ READ_BITS(bitlen_codes, 4); bitlen_codes += 4;
+ if (lit_codes > MSZIP_LITERAL_MAXSYMBOLS) return INF_ERR_SYMLENS;
+ if (dist_codes > MSZIP_DISTANCE_MAXSYMBOLS) return INF_ERR_SYMLENS;
+
+ for (i = 0; i < bitlen_codes; i++) READ_BITS(bl_len[bitlen_order[i]], 3);
+ while (i < 19) bl_len[bitlen_order[i++]] = 0;
+
+ if (make_decode_table(19, 7, &bl_len[0], &bl_table[0])) {
+ return INF_ERR_BITLENTBL;
+ }
+
+ for (i = 0; i < (lit_codes + dist_codes); i++) {
+ ENSURE_BITS(7);
+ code = bl_table[PEEK_BITS(7)];
+ REMOVE_BITS(bl_len[code]);
+
+ if (code < 16) lens[i] = last_code = code;
+ else {
+ switch (code) {
+ case 16: READ_BITS(run, 2); run += 3; code = last_code; break;
+ case 17: READ_BITS(run, 3); run += 3; code = 0; break;
+ case 18: READ_BITS(run, 7); run += 11; code = 0; break;
+ default: return INF_ERR_BADBITLEN;
+ }
+ if ((i + run) > (lit_codes + dist_codes)) return INF_ERR_BITOVERRUN;
+ while (run--) lens[i++] = code;
+ i--;
+ }
+ }
+
+ i = lit_codes;
+ memcpy(&zip->LITERAL_len[0], &lens[0], i);
+ while (i < MSZIP_LITERAL_MAXSYMBOLS) zip->LITERAL_len[i++] = 0;
+
+ i = dist_codes;
+ memcpy(&zip->DISTANCE_len[0], &lens[lit_codes], i);
+ while (i < MSZIP_DISTANCE_MAXSYMBOLS) zip->DISTANCE_len[i++] = 0;
+
+ STORE_BITS;
+ return 0;
+ }
+
+ static int inflate(struct mszipd_stream *zip) {
+ unsigned int last_block, block_type, distance, length, this_run, i;
+
+ register unsigned int bit_buffer;
+ register int bits_left;
+ register unsigned short sym;
+ unsigned char *i_ptr, *i_end;
+
+ RESTORE_BITS;
+
+ do {
+ READ_BITS(last_block, 1);
+
+ READ_BITS(block_type, 2);
+
+ if (block_type == 0) {
+ unsigned char lens_buf[4];
+
+ i = bits_left & 7; REMOVE_BITS(i);
+
+ for (i = 0; (bits_left >= 8); i++) {
+ if (i == 4) return INF_ERR_BITBUF;
+ lens_buf[i] = PEEK_BITS(8);
+ REMOVE_BITS(8);
+ }
+ if (bits_left != 0) return INF_ERR_BITBUF;
+ while (i < 4) {
+ if (i_ptr >= i_end) {
+ if (zipd_read_input(zip)) return zip->error;
+ i_ptr = zip->i_ptr;
+ i_end = zip->i_end;
+ }
+ lens_buf[i++] = *i_ptr++;
+ }
+
+ length = lens_buf[0] | (lens_buf[1] << 8);
+ i = lens_buf[2] | (lens_buf[3] << 8);
+ if (length != (~i & 0xFFFF)) return INF_ERR_COMPLEMENT;
+
+ while (length > 0) {
+ if (i_ptr >= i_end) {
+ if (zipd_read_input(zip)) return zip->error;
+ i_ptr = zip->i_ptr;
+ i_end = zip->i_end;
+ }
+
+ this_run = length;
+ if (this_run > (unsigned int)(i_end - i_ptr)) this_run = i_end - i_ptr;
+ if (this_run > (MSZIP_FRAME_SIZE - zip->window_posn))
+ this_run = MSZIP_FRAME_SIZE - zip->window_posn;
+
+ memcpy(&zip->window[zip->window_posn], i_ptr, this_run);
+ zip->window_posn += this_run;
+ i_ptr += this_run;
+ length -= this_run;
+
+ if (zip->window_posn == MSZIP_FRAME_SIZE) {
+ if (zip->flush_window(zip, MSZIP_FRAME_SIZE)) return INF_ERR_FLUSH;
+ zip->window_posn = 0;
+ }
+ }
+ }
+ else if ((block_type == 1) || (block_type == 2)) {
+ unsigned int window_posn, match_posn, code;
+
+ if (block_type == 1) {
+ i = 0;
+ while (i < 144) zip->LITERAL_len[i++] = 8;
+ while (i < 256) zip->LITERAL_len[i++] = 9;
+ while (i < 280) zip->LITERAL_len[i++] = 7;
+ while (i < 288) zip->LITERAL_len[i++] = 8;
+ for (i = 0; i < 32; i++) zip->DISTANCE_len[i] = 5;
+ }
+ else {
+ STORE_BITS;
+ if ((i = zip_read_lens(zip))) return i;
+ RESTORE_BITS;
+ }
+
+ if (make_decode_table(MSZIP_LITERAL_MAXSYMBOLS, MSZIP_LITERAL_TABLEBITS,
+ &zip->LITERAL_len[0], &zip->LITERAL_table[0]))
+ {
+ return INF_ERR_LITERALTBL;
+ }
+
+ if (make_decode_table(MSZIP_DISTANCE_MAXSYMBOLS,MSZIP_DISTANCE_TABLEBITS,
+ &zip->DISTANCE_len[0], &zip->DISTANCE_table[0]))
+ {
+ return INF_ERR_DISTANCETBL;
+ }
+
+ window_posn = zip->window_posn;
+ while (1) {
+ READ_HUFFSYM(LITERAL, code);
+ if (code < 256) {
+ zip->window[window_posn++] = (unsigned char) code;
+ if (window_posn == MSZIP_FRAME_SIZE) {
+ if (zip->flush_window(zip, MSZIP_FRAME_SIZE)) return INF_ERR_FLUSH;
+ window_posn = 0;
+ }
+ }
+ else if (code == 256) {
+ break;
+ }
+ else {
+ code -= 257;
+ if (code > 29) return INF_ERR_LITCODE;
+ READ_BITS_T(length, lit_extrabits[code]);
+ length += lit_lengths[code];
+
+ READ_HUFFSYM(DISTANCE, code);
+ if (code > 30) return INF_ERR_DISTCODE;
+ READ_BITS_T(distance, dist_extrabits[code]);
+ distance += dist_offsets[code];
+
+ match_posn = ((distance > window_posn) ? MSZIP_FRAME_SIZE : 0)
+ + window_posn - distance;
+
+ if (length < 12) {
+ while (length--) {
+ zip->window[window_posn++] = zip->window[match_posn++];
+ match_posn &= MSZIP_FRAME_SIZE - 1;
+
+ if (window_posn == MSZIP_FRAME_SIZE) {
+ if (zip->flush_window(zip, MSZIP_FRAME_SIZE))
+ return INF_ERR_FLUSH;
+ window_posn = 0;
+ }
+ }
+ }
+ else {
+ unsigned char *runsrc, *rundest;
+ do {
+ this_run = length;
+ if ((match_posn + this_run) > MSZIP_FRAME_SIZE)
+ this_run = MSZIP_FRAME_SIZE - match_posn;
+ if ((window_posn + this_run) > MSZIP_FRAME_SIZE)
+ this_run = MSZIP_FRAME_SIZE - window_posn;
+
+ rundest = &zip->window[window_posn]; window_posn += this_run;
+ runsrc = &zip->window[match_posn]; match_posn += this_run;
+ length -= this_run;
+ while (this_run--) *rundest++ = *runsrc++;
+
+ if (window_posn == MSZIP_FRAME_SIZE) {
+ if (zip->flush_window(zip, MSZIP_FRAME_SIZE))
+ return INF_ERR_FLUSH;
+ window_posn = 0;
+ }
+ if (match_posn == MSZIP_FRAME_SIZE) match_posn = 0;
+ } while (length > 0);
+ }
+
+ }
+
+ }
+ zip->window_posn = window_posn;
+ }
+ else {
+ return INF_ERR_BLOCKTYPE;
+ }
+ } while (!last_block);
+
+ if (zip->window_posn) {
+ if (zip->flush_window(zip, zip->window_posn)) return INF_ERR_FLUSH;
+ }
+ STORE_BITS;
+
+ return 0;
+ }
+
+ static int mszipd_flush_window(struct mszipd_stream *zip,
+ unsigned int data_flushed)
+ {
+ zip->bytes_output += data_flushed;
+ if (zip->bytes_output > MSZIP_FRAME_SIZE) {
+ return 1;
+ }
+ return 0;
+ }
+
+ struct mszipd_stream *mszipd_init(struct mspack_system *system,
+ struct mspack_file *input,
+ struct mspack_file *output,
+ int input_buffer_size,
+ int repair_mode)
+ {
+ struct mszipd_stream *zip;
+
+ if (!system) return NULL;
+
+ input_buffer_size = (input_buffer_size + 1) & -2;
+ if (!input_buffer_size) return NULL;
+
+ if (!(zip = (mszipd_stream *)malloc(sizeof(struct mszipd_stream)))) {
+ return NULL;
+ }
+
+ zip->inbuf = (unsigned char *)malloc((size_t) input_buffer_size);
+ if (!zip->inbuf) {
+ free(zip);
+ return NULL;
+ }
+
+ zip->sys = system;
+ zip->input = input;
+ zip->output = output;
+ zip->inbuf_size = input_buffer_size;
+ zip->error = MSPACK_ERR_OK;
+ zip->repair_mode = repair_mode;
+ zip->flush_window = &mszipd_flush_window;
+
+ zip->i_ptr = zip->i_end = &zip->inbuf[0];
+ zip->o_ptr = zip->o_end = NULL;
+ zip->bit_buffer = 0; zip->bits_left = 0;
+ return zip;
+ }
+
+ int mszipd_decompress(struct mszipd_stream *zip, off_t out_bytes) {
+ register unsigned int bit_buffer;
+ register int bits_left;
+ unsigned char *i_ptr, *i_end;
+
+ int i, state, error;
+
+ if (!zip || (out_bytes < 0)) return MSPACK_ERR_ARGS;
+ if (zip->error) return zip->error;
+
+ i = zip->o_end - zip->o_ptr;
+ if ((off_t) i > out_bytes) i = (int) out_bytes;
+ if (i) {
+ if (zip->sys->write(zip->output, zip->o_ptr, i) != i) {
+ return zip->error = MSPACK_ERR_WRITE;
+ }
+ zip->o_ptr += i;
+ out_bytes -= i;
+ }
+ if (out_bytes == 0) return MSPACK_ERR_OK;
+
+
+ while (out_bytes > 0) {
+ RESTORE_BITS;
+
+ i = bits_left & 7; REMOVE_BITS(i);
+ state = 0;
+ do {
+ READ_BITS(i, 8);
+ if (i == 'C') state = 1;
+ else if ((state == 1) && (i == 'K')) state = 2;
+ else state = 0;
+ } while (state != 2);
+
+ zip->window_posn = 0;
+ zip->bytes_output = 0;
+ STORE_BITS;
+ if ((error = inflate(zip))) {
+ if (zip->repair_mode) {
+ fprintf(stderr, "MSZIP error, %u bytes of data lost.",
+ MSZIP_FRAME_SIZE - zip->bytes_output);
+ for (i = zip->bytes_output; i < MSZIP_FRAME_SIZE; i++) {
+ zip->window[i] = '\0';
+ }
+ zip->bytes_output = MSZIP_FRAME_SIZE;
+ }
+ else {
+ return zip->error = (error > 0) ? error : MSPACK_ERR_DECRUNCH;
+ }
+ }
+ zip->o_ptr = &zip->window[0];
+ zip->o_end = &zip->o_ptr[zip->bytes_output];
+
+ i = (out_bytes < (off_t)zip->bytes_output) ?
+ (int)out_bytes : zip->bytes_output;
+ if (zip->sys->write(zip->output, zip->o_ptr, i) != i) {
+ return zip->error = MSPACK_ERR_WRITE;
+ }
+
+ if ((error > 0) && zip->repair_mode) return error;
+
+ zip->o_ptr += i;
+ out_bytes -= i;
+ }
+
+ if (out_bytes) {
+ return zip->error = MSPACK_ERR_DECRUNCH;
+ }
+ return MSPACK_ERR_OK;
+ }
+
+ void mszipd_free(struct mszipd_stream *zip) {
+ struct mspack_system *sys;
+ if (zip) {
+ sys = zip->sys;
+ free(zip->inbuf);
+ free(zip);
+ }
+ }
diff --cc engines/grim/patchex/patchex.cpp
index 000000000,0edd17111..c4b9893ca
mode 000000,100644..100644
--- a/engines/grim/patchex/patchex.cpp
+++ b/engines/grim/patchex/patchex.cpp
@@@ -1,0 -1,385 +1,385 @@@
+ /* ResidualVM - A 3D game interpreter
+ *
+ * ResidualVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ */
+
+ /* Patch extractor
+ * (C) 2008 Andrea Corna
- *
- * This source code is adopted and striped for ResidualVM project.
++ *
++ * This source code is adopted and striped for ScummVM project.
+ *
+ * res_system functions are taken from system.c written by Stuart Caie
+ * from libmspack (http://www.cabextract.org.uk/libmspack/).
+ *
+ * Patch Extractor is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License (LGPL) version 2.1
+ *
+ * For further details, see the file COPYING.LIB distributed with libmspack
+ */
+
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <stdarg.h>
+ #include <sys/types.h>
+
+ #include "tools/patchex/mspack.h"
+ #include "common/endian.h"
+
+ // Languages codes
+ #define LANG_ALL "@@"
+ const char *kLanguages_ext[] = { "English", "French", "German", "Italian", "Portuguese", "Spanish", NULL};
+ const char *kLanguages_code[] = { "US", "FR", "GE", "IT", "PT", "SP", NULL };
+
+ // Extraction constans
+ #define RAND_A (0x343FD)
+ #define RAND_B (0x269EC3)
+ #define CODE_TABLE_SIZE (0x100)
+
+ #define BUFFER_SIZE 102400
+ int lang = -1;
+ struct mscab_decompressor *cabd = NULL;
+ struct mscabd_cabinet *cab = NULL;
+
+ struct mspack_file_p {
+ FILE *fh;
+ const char *name;
+ uint16 *CodeTable;
+ off_t cabinet_offset;
+ };
+
+ uint16 *create_dec_table(uint32 key) {
+ uint32 value;
+ uint16 *dectable;
+ unsigned int i;
+
+ value = key;
+ dectable = (uint16 *)malloc(CODE_TABLE_SIZE * 2);
+
+ for (i = 0; i < CODE_TABLE_SIZE; i++) {
+ value = RAND_A * value + RAND_B;
+ dectable[i] = (uint16)((value >> 16) & 0x7FFF);
+ }
+
+ return dectable;
+ }
+
+ static struct mspack_file *res_open(struct mspack_system *handle, const char *filename, int mode) {
+ struct mspack_file_p *fh;
+ const char *fmode;
+ char magic[4];
+ uint32 key;
+ uint8 count;
+
+ switch (mode) {
+ case MSPACK_SYS_OPEN_READ: fmode = "rb"; break;
+ case MSPACK_SYS_OPEN_WRITE: fmode = "wb"; break;
+ case MSPACK_SYS_OPEN_UPDATE: fmode = "r+b"; break;
+ case MSPACK_SYS_OPEN_APPEND: fmode = "ab"; break;
+ default: return NULL;
+ }
+
+ fh = (mspack_file_p *)malloc(sizeof(struct mspack_file_p));
+
+ fh->name = filename;
+ if (!(fh->fh = fopen(filename, fmode))) {
+ free(fh);
+ return NULL;
+ }
+
+ fh->CodeTable = NULL;
+
+ if (mode != MSPACK_SYS_OPEN_READ)
+ return (struct mspack_file *)fh;
+
+ //Search for data
+ while(!feof(fh->fh)) {
+ //Check for content signature
+ count = handle->read((struct mspack_file *) fh, magic, 4);
+ if (count == 4 && READ_BE_UINT32(magic) == MKTAG('1','C','N','T')) {
+ handle->read((struct mspack_file *)fh, &key, 4);
+ key = READ_LE_UINT32(&key);
+ fh->CodeTable = create_dec_table(key);
+ fh->cabinet_offset = ftell(fh->fh);
+
+ //Check for cabinet signature
+ count = handle->read((struct mspack_file *) fh, magic, 4);
+ if (count == 4 && READ_BE_UINT32(magic) == MKTAG('M','S','C','F')) {
+ break;
+ } else {
+ free(fh->CodeTable);
+ fh->CodeTable = NULL;
+ continue;
+ }
+ }
+ }
+
+ handle->seek((struct mspack_file *)fh, (off_t) 0, MSPACK_SYS_SEEK_START);
+
+ return (struct mspack_file *)fh;
+ }
+
+ static void res_close(struct mspack_file *file) {
+ struct mspack_file_p *handle = (struct mspack_file_p *)file;
+
+ if (handle) {
+ if (handle->CodeTable)
+ free(handle->CodeTable);
+ fclose(handle->fh);
+ free(handle);
+ }
+ }
+
+ static int res_seek(struct mspack_file *file, off_t offset, int mode) {
+ struct mspack_file_p *handle = (struct mspack_file_p *)file;
+
+ if (handle) {
+ switch (mode) {
+ case MSPACK_SYS_SEEK_START:
+ mode = SEEK_SET;
+ if (handle->CodeTable)
+ offset += handle->cabinet_offset;
+ break;
+ case MSPACK_SYS_SEEK_CUR: mode = SEEK_CUR; break;
+ case MSPACK_SYS_SEEK_END: mode = SEEK_END; break;
+ default: return -1;
+ }
+ return fseek(handle->fh, (int)offset, mode);
+ }
+ return -1;
+ }
+
+ static off_t res_tell(struct mspack_file *file) {
+ struct mspack_file_p *handle = (struct mspack_file_p *)file;
+
+ if (handle) {
+ off_t offset = ftell(handle->fh);
+ if (handle->CodeTable)
+ offset -= handle->cabinet_offset;
+ return offset;
+ } else
+ return 0;
+ }
+
+ void decode(uint8 *data, unsigned int size, uint16 *dectable, unsigned int start_point) {
+ unsigned int i;
+ for (i = 0; i < size; i++)
+ data[i] = (data[i] ^ (uint8) dectable[(i + start_point) % CODE_TABLE_SIZE]) - (uint8)(dectable[(i + start_point) % CODE_TABLE_SIZE] >> 8);
+ }
+
+ static int res_read(struct mspack_file *file, void *buffer, int bytes) {
+ struct mspack_file_p *handle = (struct mspack_file_p *)file;
+
+ if (handle) {
+ unsigned int start_point = (unsigned int)res_tell(file);
+ size_t count = fread(buffer, 1, (size_t) bytes, handle->fh);
+
+ if (!ferror(handle->fh)) {
+ if (handle->CodeTable)
+ decode((uint8*)buffer, count, handle->CodeTable, start_point);
+ return (int) count;
+ }
+ }
+ return -1;
+ }
+
+ static int res_write(struct mspack_file *file, void *buffer, int bytes) {
+ struct mspack_file_p *handle = (struct mspack_file_p *)file;
+
+ if (handle) {
+ if (handle->CodeTable)
+ return -1;
+ size_t count = fwrite(buffer, 1, (size_t)bytes, handle->fh);
+ if (!ferror(handle->fh)) return (int) count;
+ }
+ return -1;
+ }
+
+ static struct mspack_system res_system = {
+ &res_open, &res_close, &res_read, &res_write, &res_seek,
+ &res_tell, NULL
+ };
+
+ void extract_cabinet(char *filename, unsigned int lenght) {
+ struct mspack_file *original_executable, *destination_cabinet;
+ void *buffer;
+ unsigned int copied_bytes, remBytes;
+ int count, writeResult;
+
+ original_executable = res_open(&res_system, filename, MSPACK_SYS_OPEN_READ);
+ destination_cabinet = res_open(&res_system, "original.cab", MSPACK_SYS_OPEN_WRITE);
+
+ buffer = malloc(BUFFER_SIZE);
+ copied_bytes = 0;
+
+ while (copied_bytes < lenght) {
+ remBytes = lenght - copied_bytes;
+ count = res_read(original_executable, buffer, (remBytes < BUFFER_SIZE) ? remBytes : BUFFER_SIZE);
+ writeResult = res_write(destination_cabinet, buffer, count);
+ copied_bytes += count;
+ if (count < 0 || writeResult < 0) {
+ printf("I/O Error!\n");
+ free(buffer);
+ res_close(original_executable);
+ res_close(destination_cabinet);
+ exit(1);
+ }
+ }
+ printf("Update cabinet extracted as original.cab.\n");
+
+ free(buffer);
+ res_close(original_executable);
+ res_close(destination_cabinet);
+ }
+
+ char *file_filter(const struct mscabd_file *file) {
+ char *filename;
+ unsigned int filename_size;
+
+ filename_size = strlen(file->filename);
+
- /*Skip executables and libraries
- * These files are useless for ResidualVM and a proper extraction of these
++ /* Skip executables and libraries
++ * These files are useless for ScummVM and a proper extraction of these
+ * requires sub-folder support, so it isn't implemented. */
+ char *ext = file->filename + (filename_size - 3);
+ if (strcasecmp(ext, "exe") == 0 ||
+ strcasecmp(ext, "dll") == 0 ||
+ strcasecmp(ext, "flt") == 0 ||
+ strcasecmp(ext, "asi") == 0) {
+ return NULL;
+ }
+
+ filename = (char *)malloc(filename_size + 1);
+
+ /*Folder-style localization (EMI). Because EMI updates aren't multi-language,
+ * every file is extracted (except for Win's binaries). Subfolders are ignored.*/
+ char *fn = strchr(file->filename, '\\');
+ if (fn != NULL && fn[0] != 0) {
+ strcpy(filename, fn + 1);
+ return filename;
+ }
+
+ //Old-style localization (Grimfandango)
+ if (lang == -1) {
+ printf("No language specified or unknown language!\n");
+ free(filename);
+ exit(1);
+ }
+
+ if (filename_size > 3 && file->filename[2] == '_') {
+ char file_lang[3];
+ sscanf(file->filename, "%2s_%s",file_lang, filename);
+ if (strcmp(file_lang, kLanguages_code[lang]) == 0 || strcmp(file_lang, LANG_ALL) == 0)
+ return filename;
+ }
+
+ //Cleanup
+ free(filename);
+ return NULL;
+ }
+
+ void extract_files(struct mscab_decompressor *cabdec, struct mscabd_cabinet *cabinet) {
+ unsigned int files_extracted = 0;
+ struct mscabd_file *file;
+ char *filename;
+
+ for (file = cabinet->files; file; file = file->next) {
+ if ((filename = file_filter(file))) {
+ if (cabdec->extract(cabdec, file, filename) != MSPACK_ERR_OK) {
+ printf("Extract error on %s!\n", file->filename);
+ free(filename);
+ continue;
+ }
+ printf("%s extracted as %s\n", file->filename, filename);
+ ++files_extracted;
+ free(filename);
+ }
+ }
+
+ printf("%d file(s) extracted.\n", files_extracted);
+ }
+
+ void cleanup() {
+ if (cabd) {
+ if (cab)
+ cabd->close(cabd, cab);
+ mspack_destroy_cab_decompressor(cabd);
+ }
+ }
+
+ int main(int argc, char *argv[]) {
+ int i;
+ unsigned int length;
+ bool wholeCabinet = false;
+
+ // Argument checks and usage display
+ if (argc < 2) {
+ printf("Usage: patchex PATCH_EXECUTABLE [LANGUAGE]\n\n");
+ printf("Extract update files of game update from PATCH_EXECUTABLE\n");
+ printf("-For GrimFandango (gfupd101.exe) you must specify a language,\n");
+ printf("-For Monkey Island (MonkeyUpdate[_LANG].exe) this parameter is ignored,\n");
+ printf("please select the update executable according to your version.\n");
+ printf("Available languages:\n");
+ for (i = 0; kLanguages_code[i]; i++)
+ printf("- %s\n", kLanguages_ext[i]);
+ printf("Alternately original archive could be extracted as original.cab with CABINET keyword instead of language.\n");
+ exit(1);
+ }
+
+ if (argc == 3) {
+ // Cabinet check
+ if (strncasecmp("CABINET", argv[2], strlen(argv[2])) == 0) {
+ printf("Cabinet extraction selected\n");
+ wholeCabinet = true;
+ }
+
+ // Language check
+ for(i = 0; kLanguages_code[i]; i++)
+ if (strncasecmp(kLanguages_ext[i], argv[2], strlen(argv[2])) == 0) {
+ printf("%s selected.\n", kLanguages_ext[i]);
+ lang = i;
+ break;
+ }
+ }
+
+ //Initializations
+ atexit(cleanup);
+ if ((cabd = mspack_create_cab_decompressor(&res_system)) == NULL) {
+ printf("Internal error!\n");
+ exit(1);
+ }
+
+ cab = cabd->open(cabd, argv[1]);
+ if (cabd->last_error(cabd) != MSPACK_ERR_OK) {
+ printf("Unable to open %s!\n", argv[1]);
+ exit(1);
+ }
+
+ //Extraction !
+ if (wholeCabinet) {
+ length = cab->length;
+ cabd->close(cabd, cab);
+ cab = NULL;
+ extract_cabinet(argv[1], length);
+ } else
+ extract_files(cabd, cab);
+
+ return 0;
+ }
diff --cc engines/grim/patchr.cpp
index 000000000,41850423c..41850423c
mode 000000,100644..100644
--- a/engines/grim/patchr.cpp
+++ b/engines/grim/patchr.cpp
diff --cc engines/grim/set2fig.cpp
index 000000000,9a47e597d..9a47e597d
mode 000000,100644..100644
--- a/engines/grim/set2fig.cpp
+++ b/engines/grim/set2fig.cpp
diff --cc engines/grim/unlab.cpp
index 000000000,ba82bdc52..ba82bdc52
mode 000000,100644..100644
--- a/engines/grim/unlab.cpp
+++ b/engines/grim/unlab.cpp
diff --cc engines/grim/vima.cpp
index 000000000,110337abc..110337abc
mode 000000,100644..100644
--- a/engines/grim/vima.cpp
+++ b/engines/grim/vima.cpp
More information about the Scummvm-git-logs
mailing list