diff options
Diffstat (limited to 'dep')
95 files changed, 3062 insertions, 1399 deletions
diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index a38dcbe068d..f829956b7bf 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -8,10 +8,10 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -if( CMAKE_COMPILER_IS_GNUCXX ) - add_definitions(--no-warnings) -elseif( MSVC ) +if( MSVC ) add_definitions(/W0) +else() + add_definitions(-w) endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux") @@ -32,10 +32,10 @@ endif() if(SERVERS OR TOOLS) add_subdirectory(g3dlite) add_subdirectory(recastnavigation) + add_subdirectory(cppformat) endif() if(SERVERS) - add_subdirectory(cppformat) add_subdirectory(gsoap) endif() diff --git a/dep/PackageList.txt b/dep/PackageList.txt index 9c5e66a955e..e84fef8d3b2 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -14,7 +14,7 @@ bzip2 (a freely available, patent free, high-quality data compressor) cppformat (type safe format library) https://github.com/cppformat/cppformat - Version: 1.1.0 fd53bb6fb88a23e38ec4fe331bfe95d7372d49c9 + Version: 5c76d107cbaf5e851bd66b6c563e4fc7c90be7ad G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License) http://g3d.sourceforge.net/ @@ -25,8 +25,8 @@ jemalloc (a general-purpose scalable concurrent malloc-implementation) Version: 3.6.0 libMPQ (a library for reading MPQ files) - https://libmpq.org/ - Version: 1.0.4 + https://github.com/mbroemme/libmpq/ + Version: d59b4cf1d107b5f6a0f67d6bc545c6c6ebef3d74 SFMT (SIMD-oriented Fast Mersenne Twister) Based on http://agner.org/random/ @@ -46,4 +46,4 @@ gSOAP (a portable development toolkit for C and C++ XML Web services and XML dat recastnavigation (Recast is state of the art navigation mesh construction toolset for games) https://github.com/memononen/recastnavigation - Version: 42b96b7306d39bb7680ddb0f89d480a8296c83ff + Version: 1dd5cf1883d61e723fef3d4957cf758c50e7a52b diff --git a/dep/SFMT/SFMT-hotfix1.diff b/dep/SFMT/SFMT-hotfix1.diff new file mode 100644 index 00000000000..ba7810dc100 --- /dev/null +++ b/dep/SFMT/SFMT-hotfix1.diff @@ -0,0 +1,14 @@ +diff --git a/dep/SFMT/SFMT.h b/dep/SFMT/SFMT.h +index 3d15d65..ccf21ce 100644 +--- a/dep/SFMT/SFMT.h ++++ b/dep/SFMT/SFMT.h +@@ -173,7 +173,8 @@ public: + uint32_t statesize = SFMT_N*4; // Size of state vector + + // Fill state vector with random numbers from seed +- ((uint32_t*)state)[0] = y; ++ uint32_t* s = (uint32_t*)&state; ++ s[0] = y; + const uint32_t factor = 1812433253U;// Multiplication factor + + for (i = 1; i < statesize; i++) { diff --git a/dep/SFMT/SFMT.h b/dep/SFMT/SFMT.h index 3d15d651e5b..ccf21cecd5f 100644 --- a/dep/SFMT/SFMT.h +++ b/dep/SFMT/SFMT.h @@ -173,7 +173,8 @@ public: uint32_t statesize = SFMT_N*4; // Size of state vector // Fill state vector with random numbers from seed - ((uint32_t*)state)[0] = y; + uint32_t* s = (uint32_t*)&state; + s[0] = y; const uint32_t factor = 1812433253U;// Multiplication factor for (i = 1; i < statesize; i++) { diff --git a/dep/cppformat/CMakeLists.txt b/dep/cppformat/CMakeLists.txt index ea02185811f..3be3e5f6dbb 100644 --- a/dep/cppformat/CMakeLists.txt +++ b/dep/cppformat/CMakeLists.txt @@ -6,12 +6,7 @@ set(FMT_SOURCES format.cc format.h) # Use variadic templates add_definitions(-DFMT_VARIADIC_TEMPLATES=1) -# Check if initializer lists are supported. -check_cxx_source_compiles(" - #include <initializer_list> - int main() {}" FMT_INITIALIZER_LIST) - -# Use delete +# Use deleted functions add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1) # Use static assert @@ -22,6 +17,7 @@ if (WIN32) else () check_symbol_exists(open fcntl.h HAVE_OPEN) endif () + if (HAVE_OPEN) add_definitions(-DFMT_USE_FILE_DESCRIPTORS=1) set(FMT_SOURCES ${FMT_SOURCES} posix.cc posix.h) diff --git a/dep/cppformat/ChangeLog.rst b/dep/cppformat/ChangeLog.rst index fe780ae010c..d2a77f8712f 100644 --- a/dep/cppformat/ChangeLog.rst +++ b/dep/cppformat/ChangeLog.rst @@ -1,3 +1,356 @@ +2.0.0 - 2015-12-01 +------------------ + +General +~~~~~~~ + +* [Breaking] Named arguments + (`#169 <https://github.com/cppformat/cppformat/pull/169>`_, + `#173 <https://github.com/cppformat/cppformat/pull/173>`_, + `#174 <https://github.com/cppformat/cppformat/pull/174>`_): + + .. code:: c++ + + fmt::print("The answer is {answer}.", fmt::arg("answer", 42)); + + Thanks to `@jamboree <https://github.com/jamboree>`_. + +* [Experimental] User-defined literals for format and named arguments + (`#204 <https://github.com/cppformat/cppformat/pull/204>`_, + `#206 <https://github.com/cppformat/cppformat/pull/206>`_, + `#207 <https://github.com/cppformat/cppformat/pull/207>`_): + + .. code:: c++ + + using namespace fmt::literals; + fmt::print("The answer is {answer}.", "answer"_a=42); + + Thanks to `@dean0x7d (Dean Moldovan) <https://github.com/dean0x7d>`_. + +* [Breaking] Formatting of more than 16 arguments is now supported when using + variadic templates + (`#141 <https://github.com/cppformat/cppformat/issues/141>`_). + Thanks to `@Shauren <https://github.com/Shauren>`_. + +* Runtime width specification + (`#168 <https://github.com/cppformat/cppformat/pull/168>`_): + + .. code:: c++ + + fmt::format("{0:{1}}", 42, 5); // gives " 42" + + Thanks to `@jamboree <https://github.com/jamboree>`_. + +* [Breaking] Enums are now formatted with an overloaded ``std::ostream`` insertion + operator (``operator<<``) if available + (`#232 <https://github.com/cppformat/cppformat/issues/232>`_). + +* [Breaking] Changed default ``bool`` format to textual, "true" or "false" + (`#170 <https://github.com/cppformat/cppformat/issues/170>`_): + + .. code:: c++ + + fmt::print("{}", true); // prints "true" + + To print ``bool`` as a number use numeric format specifier such as ``d``: + + .. code:: c++ + + fmt::print("{:d}", true); // prints "1" + +* ``fmt::printf`` and ``fmt::sprintf`` now support formatting of ``bool`` with the + ``%s`` specifier giving textual output, "true" or "false" + (`#223 <https://github.com/cppformat/cppformat/pull/223>`_): + + .. code:: c++ + + fmt::printf("%s", true); // prints "true" + + Thanks to `@LarsGullik <https://github.com/LarsGullik>`_. + +* [Breaking] ``signed char`` and ``unsigned char`` are now formatted as integers by default + (`#217 <https://github.com/cppformat/cppformat/pull/217>`_). + +* [Breaking] Pointers to C strings can now be formatted with the ``p`` specifier + (`#223 <https://github.com/cppformat/cppformat/pull/223>`_): + + .. code:: c++ + + fmt::print("{:p}", "test"); // prints pointer value + + Thanks to `@LarsGullik <https://github.com/LarsGullik>`_. + +* [Breaking] ``fmt::printf`` and ``fmt::sprintf`` now print null pointers as ``(nil)`` + and null strings as ``(null)`` for consistency with glibc + (`#226 <https://github.com/cppformat/cppformat/pull/226>`_). + Thanks to `@LarsGullik <https://github.com/LarsGullik>`_. + +* [Breaking] ``fmt::(s)printf`` now supports formatting of objects of user-defined types + that provide an overloaded ``std::ostream`` insertion operator (``operator<<``) + (`#201 <https://github.com/cppformat/cppformat/issues/201>`_): + + .. code:: c++ + + fmt::printf("The date is %s", Date(2012, 12, 9)); + +* [Breaking] The ``Buffer`` template is now part of the public API and can be used + to implement custom memory buffers + (`#140 <https://github.com/cppformat/cppformat/issues/140>`_). + Thanks to `@polyvertex (Jean-Charles Lefebvre) <https://github.com/polyvertex>`_. + +* [Breaking] Improved compatibility between ``BasicStringRef`` and + `std::experimental::basic_string_view + <http://en.cppreference.com/w/cpp/experimental/basic_string_view>`_ + (`#100 <https://github.com/cppformat/cppformat/issues/100>`_, + `#159 <https://github.com/cppformat/cppformat/issues/159>`_, + `#183 <https://github.com/cppformat/cppformat/issues/183>`_): + + - Comparison operators now compare string content, not pointers + - ``BasicStringRef::c_str`` replaced by ``BasicStringRef::data`` + - ``BasicStringRef`` is no longer assumed to be null-terminated + + References to null-terminated strings are now represented by a new class, + ``BasicCStringRef``. + +* Dependency on pthreads introduced by Google Test is now optional + (`#185 <https://github.com/cppformat/cppformat/issues/185>`_). + +* New CMake options ``FMT_DOC``, ``FMT_INSTALL`` and ``FMT_TEST`` to control + generation of ``doc``, ``install`` and ``test`` targets respectively, on by default + (`#197 <https://github.com/cppformat/cppformat/issues/197>`_, + `#198 <https://github.com/cppformat/cppformat/issues/198>`_, + `#200 <https://github.com/cppformat/cppformat/issues/200>`_). + Thanks to `@maddinat0r (Alex Martin) <https://github.com/maddinat0r>`_. + +* ``noexcept`` is now used when compiling with MSVC2015 + (`#215 <https://github.com/cppformat/cppformat/pull/215>`_). + Thanks to `@dmkrepo (Dmitriy) <https://github.com/dmkrepo>`_. + +* Added an option to disable use of ``windows.h`` when ``FMT_USE_WINDOWS_H`` + is defined as 0 before including ``format.h`` + (`#171 <https://github.com/cppformat/cppformat/issues/171>`_). + Thanks to `@alfps (Alf P. Steinbach) <https://github.com/alfps>`_. + +* [Breaking] ``windows.h`` is now included with ``NOMINMAX`` unless + ``FMT_WIN_MINMAX`` is defined. This is done to prevent breaking code using + ``std::min`` and ``std::max`` and only affects the header-only configuration + (`#152 <https://github.com/cppformat/cppformat/issues/152>`_, + `#153 <https://github.com/cppformat/cppformat/pull/153>`_, + `#154 <https://github.com/cppformat/cppformat/pull/154>`_). + Thanks to `@DevO2012 <https://github.com/DevO2012>`_. + +* Improved support for custom character types + (`#171 <https://github.com/cppformat/cppformat/issues/171>`_). + Thanks to `@alfps (Alf P. Steinbach) <https://github.com/alfps>`_. + +* Added an option to disable use of IOStreams when ``FMT_USE_IOSTREAMS`` + is defined as 0 before including ``format.h`` + (`#205 <https://github.com/cppformat/cppformat/issues/205>`_, + `#208 <https://github.com/cppformat/cppformat/pull/208>`_). + Thanks to `@JodiTheTigger <https://github.com/JodiTheTigger>`_. + +* Improved detection of ``isnan``, ``isinf`` and ``signbit``. + +Optimization +~~~~~~~~~~~~ + +* Made formatting of user-defined types more efficient with a custom stream buffer + (`#92 <https://github.com/cppformat/cppformat/issues/92>`_, + `#230 <https://github.com/cppformat/cppformat/pull/230>`_). + Thanks to `@NotImplemented <https://github.com/NotImplemented>`_. + +* Further improved performance of ``fmt::Writer`` on integer formatting + and fixed a minor regression. Now it is ~7% faster than ``karma::generate`` + on Karma's benchmark + (`#186 <https://github.com/cppformat/cppformat/issues/186>`_). + +* [Breaking] Reduced `compiled code size + <https://github.com/cppformat/cppformat#compile-time-and-code-bloat>`_ + (`#143 <https://github.com/cppformat/cppformat/issues/143>`_, + `#149 <https://github.com/cppformat/cppformat/pull/149>`_). + +Distribution +~~~~~~~~~~~~ + +* [Breaking] Headers are now installed in + ``${CMAKE_INSTALL_PREFIX}/include/cppformat`` + (`#178 <https://github.com/cppformat/cppformat/issues/178>`_). + Thanks to `@jackyf (Eugene V. Lyubimkin) <https://github.com/jackyf>`_. + +* [Breaking] Changed the library name from ``format`` to ``cppformat`` + for consistency with the project name and to avoid potential conflicts + (`#178 <https://github.com/cppformat/cppformat/issues/178>`_). + Thanks to `@jackyf (Eugene V. Lyubimkin) <https://github.com/jackyf>`_. + +* C++ Format is now available in `Debian <https://www.debian.org/>`_ GNU/Linux + (`stretch <https://packages.debian.org/source/stretch/cppformat>`_, + `sid <https://packages.debian.org/source/sid/cppformat>`_) and + derived distributions such as + `Ubuntu <https://launchpad.net/ubuntu/+source/cppformat>`_ 15.10 and later + (`#155 <https://github.com/cppformat/cppformat/issues/155>`_):: + + $ sudo apt-get install libcppformat1-dev + + Thanks to `@jackyf (Eugene V. Lyubimkin) <https://github.com/jackyf>`_. + +* `Packages for Fedora and RHEL <https://admin.fedoraproject.org/pkgdb/package/cppformat/>`_ + are now available. Thanks to Dave Johansen. + +* C++ Format can now be installed via `Homebrew <http://brew.sh/>`_ on OS X + (`#157 <https://github.com/cppformat/cppformat/issues/157>`_):: + + $ brew install cppformat + + Thanks to `@ortho <https://github.com/ortho>`_, Anatoliy Bulukin. + +Documentation +~~~~~~~~~~~~~ + +* Migrated from ReadTheDocs to GitHub Pages for better responsiveness + and reliability + (`#128 <https://github.com/cppformat/cppformat/issues/128>`_). + New documentation address is http://cppformat.github.io/. + + +* Added `Building the documentation + <http://cppformat.github.io/dev/usage.html#building-the-documentation>`_ + section to the documentation. + +* Documentation build script is now compatible with Python 3 and newer pip versions. + (`#189 <https://github.com/cppformat/cppformat/pull/189>`_, + `#209 <https://github.com/cppformat/cppformat/issues/209>`_). + Thanks to `@JodiTheTigger <https://github.com/JodiTheTigger>`_ and + `@xentec <https://github.com/xentec>`_. + +* Documentation fixes and improvements + (`#36 <https://github.com/cppformat/cppformat/issues/36>`_, + `#75 <https://github.com/cppformat/cppformat/issues/75>`_, + `#125 <https://github.com/cppformat/cppformat/issues/125>`_, + `#160 <https://github.com/cppformat/cppformat/pull/160>`_, + `#161 <https://github.com/cppformat/cppformat/pull/161>`_, + `#162 <https://github.com/cppformat/cppformat/issues/162>`_, + `#165 <https://github.com/cppformat/cppformat/issues/165>`_, + `#210 <https://github.com/cppformat/cppformat/issues/210>`_). + Thanks to `@syohex (Syohei YOSHIDA) <https://github.com/syohex>`_ and + bug reporters. + +* Fixed out-of-tree documentation build + (`#177 <https://github.com/cppformat/cppformat/issues/177>`_). + Thanks to `@jackyf (Eugene V. Lyubimkin) <https://github.com/jackyf>`_. + +Fixes +~~~~~ + +* Fixed ``initializer_list`` detection + (`#136 <https://github.com/cppformat/cppformat/issues/136>`_). + Thanks to `@Gachapen (Magnus Bjerke Vik) <https://github.com/Gachapen>`_. + +* [Breaking] Fixed formatting of enums with numeric format specifiers in + ``fmt::(s)printf`` + (`#131 <https://github.com/cppformat/cppformat/issues/131>`_, + `#139 <https://github.com/cppformat/cppformat/issues/139>`_): + + .. code:: c++ + + enum { ANSWER = 42 }; + fmt::printf("%d", ANSWER); + + Thanks to `@Naios <https://github.com/Naios>`_. + +* Improved compatibility with old versions of MinGW + (`#129 <https://github.com/cppformat/cppformat/issues/129>`_, + `#130 <https://github.com/cppformat/cppformat/pull/130>`_, + `#132 <https://github.com/cppformat/cppformat/issues/132>`_). + Thanks to `@cstamford (Christopher Stamford) <https://github.com/cstamford>`_. + +* Fixed a compile error on MSVC with disabled exceptions + (`#144 <https://github.com/cppformat/cppformat/issues/144>`_). + +* Added a workaround for broken implementation of variadic templates in MSVC2012 + (`#148 <https://github.com/cppformat/cppformat/issues/148>`_). + +* Placed the anonymous namespace within ``fmt`` namespace for the header-only + configuration + (`#171 <https://github.com/cppformat/cppformat/issues/171>`_). + Thanks to `@alfps (Alf P. Steinbach) <https://github.com/alfps>`_. + +* Fixed issues reported by Coverity Scan + (`#187 <https://github.com/cppformat/cppformat/issues/187>`_, + `#192 <https://github.com/cppformat/cppformat/issues/192>`_). + +* Implemented a workaround for a name lookup bug in MSVC2010 + (`#188 <https://github.com/cppformat/cppformat/issues/188>`_). + +* Fixed compiler warnings + (`#95 <https://github.com/cppformat/cppformat/issues/95>`_, + `#96 <https://github.com/cppformat/cppformat/issues/96>`_, + `#114 <https://github.com/cppformat/cppformat/pull/114>`_, + `#135 <https://github.com/cppformat/cppformat/issues/135>`_, + `#142 <https://github.com/cppformat/cppformat/issues/142>`_, + `#145 <https://github.com/cppformat/cppformat/issues/145>`_, + `#146 <https://github.com/cppformat/cppformat/issues/146>`_, + `#158 <https://github.com/cppformat/cppformat/issues/158>`_, + `#163 <https://github.com/cppformat/cppformat/issues/163>`_, + `#175 <https://github.com/cppformat/cppformat/issues/175>`_, + `#190 <https://github.com/cppformat/cppformat/issues/190>`_, + `#191 <https://github.com/cppformat/cppformat/pull/191>`_, + `#194 <https://github.com/cppformat/cppformat/issues/194>`_, + `#196 <https://github.com/cppformat/cppformat/pull/196>`_, + `#216 <https://github.com/cppformat/cppformat/issues/216>`_, + `#218 <https://github.com/cppformat/cppformat/pull/218>`_, + `#220 <https://github.com/cppformat/cppformat/pull/220>`_, + `#229 <https://github.com/cppformat/cppformat/pull/229>`_, + `#233 <https://github.com/cppformat/cppformat/issues/233>`_, + `#234 <https://github.com/cppformat/cppformat/issues/234>`_, + `#236 <https://github.com/cppformat/cppformat/pull/236>`_). + Thanks to `@seanmiddleditch (Sean Middleditch) <https://github.com/seanmiddleditch>`_, + `@dixlorenz (Dix Lorenz) <https://github.com/dixlorenz>`_, + `@CarterLi (李通洲) <https://github.com/CarterLi>`_, + `@Naios <https://github.com/Naios>`_, + `@fmatthew5876 (Matthew Fioravante) <https://github.com/fmatthew5876>`_, + `@LevskiWeng (Levski Weng) <https://github.com/LevskiWeng>`_, + `@rpopescu <https://github.com/rpopescu>`_, + `@gabime (Gabi Melman) <https://github.com/gabime>`_, + `@cubicool (Jeremy Moles) <https://github.com/cubicool>`_, + `@jkflying (Julian Kent) <https://github.com/jkflying>`_, + `@LogicalKnight (Sean L) <https://github.com/LogicalKnight>`_, + `@inguin (Ingo van Lil) <https://github.com/inguin>`_ and + `@Jopie64 (Johan) <https://github.com/Jopie64>`_. + +* Fixed portability issues (mostly causing test failures) on ARM, ppc64, ppc64le, + s390x and SunOS 5.11 i386 ( + `#138 <https://github.com/cppformat/cppformat/issues/138>`_, + `#179 <https://github.com/cppformat/cppformat/issues/179>`_, + `#180 <https://github.com/cppformat/cppformat/issues/180>`_, + `#202 <https://github.com/cppformat/cppformat/issues/202>`_, + `#225 <https://github.com/cppformat/cppformat/issues/225>`_, + `Red Hat Bugzilla Bug 1260297 <https://bugzilla.redhat.com/show_bug.cgi?id=1260297>`_). + Thanks to `@Naios <https://github.com/Naios>`_, + `@jackyf (Eugene V. Lyubimkin) <https://github.com/jackyf>`_ and Dave Johansen. + +* Fixed a name conflict with macro ``free`` defined in + ``crtdbg.h`` when ``_CRTDBG_MAP_ALLOC`` is set + (`#211 <https://github.com/cppformat/cppformat/issues/211>`_). + +* Fixed shared library build on OS X + (`#212 <https://github.com/cppformat/cppformat/pull/212>`_). + Thanks to `@dean0x7d (Dean Moldovan) <https://github.com/dean0x7d>`_. + +* Fixed an overload conflict on MSVC when ``/Zc:wchar_t-`` option is specified + (`#214 <https://github.com/cppformat/cppformat/pull/214>`_). + Thanks to `@slavanap (Vyacheslav Napadovsky) <https://github.com/slavanap>`_. + +* Improved compatibility with MSVC 2008 + (`#236 <https://github.com/cppformat/cppformat/pull/236>`_). + Thanks to `@Jopie64 (Johan) <https://github.com/Jopie64>`_. + +* Improved compatibility with bcc32 + (`#227 <https://github.com/cppformat/cppformat/issues/227>`_). + +* Fixed ``static_assert`` detection on Clang + (`#228 <https://github.com/cppformat/cppformat/pull/228>`_). + Thanks to `@dean0x7d (Dean Moldovan) <https://github.com/dean0x7d>`_. + 1.1.0 - 2015-03-06 ------------------ @@ -66,12 +419,7 @@ * Fixed packaging issues (`#94 <https://github.com/cppformat/cppformat/issues/94>`_). -* Fixed warnings in GCC, MSVC and Xcode/Clang - (`#95 <https://github.com/cppformat/cppformat/issues/95>`_, - `#96 <https://github.com/cppformat/cppformat/issues/96>`_ and - `#114 <https://github.com/cppformat/cppformat/pull/114>`_). - -* Added `changelog <https://github.com/cppformat/cppformat/edit/master/ChangeLog.rst>`_ +* Added `changelog <https://github.com/cppformat/cppformat/blob/master/ChangeLog.rst>`_ (`#103 <https://github.com/cppformat/cppformat/issues/103>`_). 1.0.0 - 2015-02-05 diff --git a/dep/cppformat/LICENSE b/dep/cppformat/LICENSE.rst index 2ee9ec93495..b1c96ca02c8 100644 --- a/dep/cppformat/LICENSE +++ b/dep/cppformat/LICENSE.rst @@ -1,4 +1,5 @@ -Copyright (c) 2014 - 2015, Victor Zverovich +Copyright (c) 2012 - 2015, Victor Zverovich + All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/dep/cppformat/README.rst b/dep/cppformat/README.rst new file mode 100644 index 00000000000..fb4399f0af4 --- /dev/null +++ b/dep/cppformat/README.rst @@ -0,0 +1,412 @@ +C++ Format +========== + +.. image:: https://travis-ci.org/cppformat/cppformat.png?branch=master + :target: https://travis-ci.org/cppformat/cppformat + +.. image:: https://ci.appveyor.com/api/projects/status/qk0bhyhqp1ekpat8 + :target: https://ci.appveyor.com/project/vitaut/cppformat + +.. image:: https://badges.gitter.im/Join%20Chat.svg + :alt: Join the chat at https://gitter.im/cppformat/cppformat + :target: https://gitter.im/cppformat/cppformat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge + +C++ Format is an open-source formatting library for C++. +It can be used as a safe alternative to printf or as a fast +alternative to IOStreams. + +`Documentation <http://cppformat.github.io/latest/>`_ + +Features +-------- + +* Two APIs: faster concatenation-based write API and slower (but still + very fast) replacement-based format API with positional arguments for + localization. +* Write API similar to the one used by IOStreams but stateless allowing + faster implementation. +* Format API with `format string syntax + <http://cppformat.github.io/latest/syntax.html>`_ + similar to the one used by `str.format + <http://docs.python.org/2/library/stdtypes.html#str.format>`_ in Python. +* Safe `printf implementation + <http://cppformat.github.io/latest/reference.html#printf-formatting-functions>`_ + including the POSIX extension for positional arguments. +* Support for user-defined types. +* High speed: performance of the format API is close to that of + glibc's `printf <http://en.cppreference.com/w/cpp/io/c/fprintf>`_ + and better than performance of IOStreams. See `Speed tests`_ and + `Fast integer to string conversion in C++ + <http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_. +* Small code size both in terms of source code (format consists of a single + header file and a single source file) and compiled code. + See `Compile time and code bloat`_. +* Reliability: the library has an extensive set of `unit tests + <https://github.com/cppformat/cppformat/tree/master/test>`_. +* Safety: the library is fully type safe, errors in format strings are + reported using exceptions, automatic memory management prevents buffer + overflow errors. +* Ease of use: small self-contained code base, no external dependencies, + permissive BSD `license + <https://github.com/cppformat/cppformat/blob/master/LICENSE.rst>`_ +* `Portability <http://cppformat.github.io#portability>`_ with consistent output + across platforms and support for older compilers. +* Clean warning-free codebase even on high warning levels + (-Wall -Wextra -pedantic). +* Support for wide strings. +* Optional header-only configuration enabled with the ``FMT_HEADER_ONLY`` macro. + +See the `documentation <http://cppformat.github.io/latest/>`_ for more details. + +Examples +-------- + +This prints ``Hello, world!`` to stdout: + +.. code:: c++ + + fmt::print("Hello, {}!", "world"); // uses Python-like format string syntax + fmt::printf("Hello, %s!", "world"); // uses printf format string syntax + +Arguments can be accessed by position and arguments' indices can be repeated: + +.. code:: c++ + + std::string s = fmt::format("{0}{1}{0}", "abra", "cad"); + // s == "abracadabra" + +C++ Format can be used as a safe portable replacement for ``itoa``: + +.. code:: c++ + + fmt::MemoryWriter w; + w << 42; // replaces itoa(42, buffer, 10) + w << fmt::hex(42); // replaces itoa(42, buffer, 16) + // access the string using w.str() or w.c_str() + +An object of any user-defined type for which there is an overloaded +:code:`std::ostream` insertion operator (``operator<<``) can be formatted: + +.. code:: c++ + + class Date { + int year_, month_, day_; + public: + Date(int year, int month, int day) : year_(year), month_(month), day_(day) {} + + friend std::ostream &operator<<(std::ostream &os, const Date &d) { + return os << d.year_ << '-' << d.month_ << '-' << d.day_; + } + }; + + std::string s = fmt::format("The date is {}", Date(2012, 12, 9)); + // s == "The date is 2012-12-9" + +You can use the `FMT_VARIADIC +<http://cppformat.github.io/latest/reference.html#utilities>`_ +macro to create your own functions similar to `format +<http://cppformat.github.io/latest/reference.html#format>`_ and +`print <http://cppformat.github.io/latest/reference.html#print>`_ +which take arbitrary arguments: + +.. code:: c++ + + // Prints formatted error message. + void report_error(const char *format, fmt::ArgList args) { + fmt::print("Error: "); + fmt::print(format, args); + } + FMT_VARIADIC(void, report_error, const char *) + + report_error("file not found: {}", path); + +Note that you only need to define one function that takes ``fmt::ArgList`` +argument. ``FMT_VARIADIC`` automatically defines necessary wrappers that +accept variable number of arguments. + +Projects using this library +--------------------------- + +* `0 A.D. <http://play0ad.com/>`_: A free, open-source, cross-platform real-time strategy game + +* `AMPL/MP <https://github.com/ampl/mp>`_: + An open-source library for mathematical programming + +* `HarpyWar/pvpgn <https://github.com/HarpyWar/pvpgn>`_: + Player vs Player Gaming Network with tweaks + +* `KBEngine <http://www.kbengine.org/>`_: An open-source MMOG server engine + +* `Lifeline <https://github.com/peter-clark/lifeline>`_: A 2D game + +* `PenUltima Online (POL) <http://www.polserver.com/>`_: + An MMO server, compatible with most Ultima Online clients + +* `quasardb <https://www.quasardb.net/>`_: A distributed, high-performance, associative database + +* `readpe <https://bitbucket.org/sys_dev/readpe>`_: Read Portable Executable + +* `redis-cerberus <https://github.com/HunanTV/redis-cerberus>`_: A Redis cluster proxy + +* `Saddy <https://code.google.com/p/saddy/>`_: + Small crossplatform 2D graphic engine + +* `Salesforce Analytics Cloud <http://www.salesforce.com/analytics-cloud/overview/>`_: + Business intelligence software + +* `spdlog <https://github.com/gabime/spdlog>`_: Super fast C++ logging library + +* `Stellar <https://www.stellar.org/>`_: Financial platform + +* `Touch Surgery <https://www.touchsurgery.com/>`_: Surgery simulator + +* `TrinityCore <https://github.com/TrinityCore/TrinityCore>`_: Open-source MMORPG framework + +`More... <https://github.com/search?q=cppformat&type=Code>`_ + +If you are aware of other projects using this library, please let me know +by `email <mailto:victor.zverovich@gmail.com>`_ or by submitting an +`issue <https://github.com/cppformat/cppformat/issues>`_. + +Motivation +---------- + +So why yet another formatting library? + +There are plenty of methods for doing this task, from standard ones like +the printf family of function and IOStreams to Boost Format library and +FastFormat. The reason for creating a new library is that every existing +solution that I found either had serious issues or didn't provide +all the features I needed. + +Printf +~~~~~~ + +The good thing about printf is that it is pretty fast and readily available +being a part of the C standard library. The main drawback is that it +doesn't support user-defined types. Printf also has safety issues although +they are mostly solved with `__attribute__ ((format (printf, ...)) +<http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html>`_ in GCC. +There is a POSIX extension that adds positional arguments required for +`i18n <http://en.wikipedia.org/wiki/Internationalization_and_localization>`_ +to printf but it is not a part of C99 and may not be available on some +platforms. + +IOStreams +~~~~~~~~~ + +The main issue with IOStreams is best illustrated with an example: + +.. code:: c++ + + std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n"; + +which is a lot of typing compared to printf: + +.. code:: c++ + + printf("%.2f\n", 1.23456); + +Matthew Wilson, the author of FastFormat, referred to this situation with +IOStreams as "chevron hell". IOStreams doesn't support positional arguments +by design. + +The good part is that IOStreams supports user-defined types and is safe +although error reporting is awkward. + +Boost Format library +~~~~~~~~~~~~~~~~~~~~ + +This is a very powerful library which supports both printf-like format +strings and positional arguments. The main its drawback is performance. +According to various benchmarks it is much slower than other methods +considered here. Boost Format also has excessive build times and severe +code bloat issues (see `Benchmarks`_). + +FastFormat +~~~~~~~~~~ + +This is an interesting library which is fast, safe and has positional +arguments. However it has significant limitations, citing its author: + + Three features that have no hope of being accommodated within the + current design are: + + * Leading zeros (or any other non-space padding) + * Octal/hexadecimal encoding + * Runtime width/alignment specification + +It is also quite big and has a heavy dependency, STLSoft, which might be +too restrictive for using it in some projects. + +Loki SafeFormat +~~~~~~~~~~~~~~~ + +SafeFormat is a formatting library which uses printf-like format strings +and is type safe. It doesn't support user-defined types or positional +arguments. It makes unconventional use of ``operator()`` for passing +format arguments. + +Tinyformat +~~~~~~~~~~ + +This library supports printf-like format strings and is very small and +fast. Unfortunately it doesn't support positional arguments and wrapping +it in C++98 is somewhat difficult. Also its performance and code compactness +are limited by IOStreams. + +Boost Spirit.Karma +~~~~~~~~~~~~~~~~~~ + +This is not really a formatting library but I decided to include it here +for completeness. As IOStreams it suffers from the problem of mixing +verbatim text with arguments. The library is pretty fast, but slower +on integer formatting than ``fmt::Writer`` on Karma's own benchmark, +see `Fast integer to string conversion in C++ +<http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_. + +Benchmarks +---------- + +Speed tests +~~~~~~~~~~~ + +The following speed tests results were generated by building +``tinyformat_test.cpp`` on Ubuntu GNU/Linux 14.04.1 with +``g++-4.8.2 -O3 -DSPEED_TEST -DHAVE_FORMAT``, and taking the best of three +runs. In the test, the format string ``"%0.10f:%04d:%+g:%s:%p:%c:%%\n"`` or +equivalent is filled 2000000 times with output sent to ``/dev/null``; for +further details see the `source +<https://github.com/cppformat/format-benchmark/blob/master/tinyformat_test.cpp>`_. + +================= ============= =========== +Library Method Run Time, s +================= ============= =========== +EGLIBC 2.19 printf 1.30 +libstdc++ 4.8.2 std::ostream 1.85 +C++ Format 1.0 fmt::print 1.42 +tinyformat 2.0.1 tfm::printf 2.25 +Boost Format 1.54 boost::format 9.94 +================= ============= =========== + +As you can see ``boost::format`` is much slower than the alternative methods; this +is confirmed by `other tests <http://accu.org/index.php/journals/1539>`_. +Tinyformat is quite good coming close to IOStreams. Unfortunately tinyformat +cannot be faster than the IOStreams because it uses them internally. +Performance of cppformat is close to that of printf, being `faster than printf on integer +formatting <http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html>`_, +but slower on floating-point formatting which dominates this benchmark. + +Compile time and code bloat +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The script `bloat-test.py +<https://github.com/cppformat/format-benchmark/blob/master/bloat-test.py>`_ +from `format-benchmark <https://github.com/cppformat/format-benchmark>`_ +tests compile time and code bloat for nontrivial projects. +It generates 100 translation units and uses ``printf()`` or its alternative +five times in each to simulate a medium sized project. The resulting +executable size and compile time (g++-4.8.1, Ubuntu GNU/Linux 13.10, +best of three) is shown in the following tables. + +**Optimized build (-O3)** + +============ =============== ==================== ================== +Method Compile Time, s Executable size, KiB Stripped size, KiB +============ =============== ==================== ================== +printf 2.6 41 30 +IOStreams 19.4 92 70 +C++ Format 46.8 46 34 +tinyformat 64.6 418 386 +Boost Format 222.8 990 923 +============ =============== ==================== ================== + +As you can see, C++ Format has two times less overhead in terms of resulting +code size compared to IOStreams and comes pretty close to ``printf``. +Boost Format has by far the largest overheads. + +**Non-optimized build** + +============ =============== ==================== ================== +Method Compile Time, s Executable size, KiB Stripped size, KiB +============ =============== ==================== ================== +printf 2.1 41 30 +IOStreams 19.7 86 62 +C++ Format 47.9 108 86 +tinyformat 27.7 234 190 +Boost Format 122.6 884 763 +============ =============== ==================== ================== + +``libc``, ``libstdc++`` and ``libformat`` are all linked as shared +libraries to compare formatting function overhead only. Boost Format +and tinyformat are header-only libraries so they don't provide any +linkage options. + +Running the tests +~~~~~~~~~~~~~~~~~ + +Please refer to `Building the library`__ for the instructions on how to build +the library and run the unit tests. + +__ http://cppformat.github.io/latest/usage.html#building-the-library + +Benchmarks reside in a separate repository, +`format-benchmarks <https://github.com/cppformat/format-benchmark>`_, +so to run the benchmarks you first need to clone this repository and +generate Makefiles with CMake:: + + $ git clone --recursive https://github.com/cppformat/format-benchmark.git + $ cd format-benchmark + $ cmake . + +Then you can run the speed test:: + + $ make speed-test + +or the bloat test:: + + $ make bloat-test + +License +------- + +C++ Format is distributed under the BSD `license +<https://github.com/cppformat/cppformat/blob/master/LICENSE.rst>`_. + +The `Format String Syntax +<http://cppformat.github.io/latest/syntax.html>`_ +section in the documentation is based on the one from Python `string module +documentation <http://docs.python.org/3/library/string.html#module-string>`_ +adapted for the current library. For this reason the documentation is +distributed under the Python Software Foundation license available in +`doc/python-license.txt +<https://raw.github.com/cppformat/cppformat/master/doc/python-license.txt>`_. +It only applies if you distribute the documentation of C++ Format. + +Links +----- + +`API changes/compatibility report <http://upstream-tracker.org/versions/cppformat.html>`_ + +Acknowledgments +--------------- + +The benchmark section of this readme file and the performance tests are taken +from the excellent `tinyformat <https://github.com/c42f/tinyformat>`_ library +written by Chris Foster. Boost Format library is acknowledged transitively +since it had some influence on tinyformat. +Some ideas used in the implementation are borrowed from `Loki +<http://loki-lib.sourceforge.net/>`_ SafeFormat and `Diagnostic API +<http://clang.llvm.org/doxygen/classclang_1_1Diagnostic.html>`_ in +`Clang <http://clang.llvm.org/>`_. +Format string syntax and the documentation are based on Python's `str.format +<http://docs.python.org/2/library/stdtypes.html#str.format>`_. +Thanks `Doug Turnbull <https://github.com/softwaredoug>`_ for his valuable +comments and contribution to the design of the type-safe API and +`Gregory Czajkowski <https://github.com/gcflymoto>`_ for implementing binary +formatting. Thanks `Ruslan Baratov <https://github.com/ruslo>`_ for comprehensive +`comparison of integer formatting algorithms <https://github.com/ruslo/int-dec-format-tests>`_ +and useful comments regarding performance, `Boris Kaul <https://github.com/localvoid>`_ for +`C++ counting digits benchmark <https://github.com/localvoid/cxx-benchmark-count-digits>`_. +Thanks to `CarterLi <https://github.com/CarterLi>`_ for contributing various +improvements to the code. diff --git a/dep/cppformat/format.cc b/dep/cppformat/format.cc index fe4f1b18733..1970d53c500 100644 --- a/dep/cppformat/format.cc +++ b/dep/cppformat/format.cc @@ -34,27 +34,24 @@ #include <climits> #include <cmath> #include <cstdarg> +#include <cstddef> // for std::ptrdiff_t -#ifdef _WIN32 -# ifdef __MINGW32__ -# include <cstring> +#if defined(_WIN32) && defined(__MINGW32__) +# include <cstring> +#endif + +#if FMT_USE_WINDOWS_H +# if defined(NOMINMAX) || defined(FMT_WIN_MINMAX) +# include <windows.h> +# else +# define NOMINMAX +# include <windows.h> +# undef NOMINMAX # endif -# include <windows.h> #endif using fmt::internal::Arg; -// Check if exceptions are disabled. -#if __GNUC__ && !__EXCEPTIONS -# define FMT_EXCEPTIONS 0 -#endif -#if _MSC_VER && !_HAS_EXCEPTIONS -# define FMT_EXCEPTIONS 0 -#endif -#ifndef FMT_EXCEPTIONS -# define FMT_EXCEPTIONS 1 -#endif - #if FMT_EXCEPTIONS # define FMT_TRY try # define FMT_CATCH(x) catch (x) @@ -63,21 +60,13 @@ using fmt::internal::Arg; # define FMT_CATCH(x) if (false) #endif -#ifndef FMT_THROW -# if FMT_EXCEPTIONS -# define FMT_THROW(x) throw x -# else -# define FMT_THROW(x) assert(false) -# endif -#endif - #ifdef FMT_HEADER_ONLY # define FMT_FUNC inline #else # define FMT_FUNC #endif -#if _MSC_VER +#ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4127) // conditional expression is constant # pragma warning(disable: 4702) // unreachable code @@ -88,13 +77,14 @@ using fmt::internal::Arg; // Dummy implementations of strerror_r and strerror_s called if corresponding // system functions are not available. -static inline fmt::internal::None<> strerror_r(int, char *, ...) { - return fmt::internal::None<>(); +static inline fmt::internal::Null<> strerror_r(int, char *, ...) { + return fmt::internal::Null<>(); } -static inline fmt::internal::None<> strerror_s(char *, std::size_t, ...) { - return fmt::internal::None<>(); +static inline fmt::internal::Null<> strerror_s(char *, std::size_t, ...) { + return fmt::internal::Null<>(); } +namespace fmt { namespace { #ifndef _MSC_VER @@ -125,6 +115,7 @@ struct IntChecker { unsigned max = INT_MAX; return value <= max; } + static bool fits_in_int(bool) { return true; } }; template <> @@ -133,6 +124,7 @@ struct IntChecker<true> { static bool fits_in_int(T value) { return value >= INT_MIN && value <= INT_MAX; } + static bool fits_in_int(int) { return true; } }; const char RESET_COLOR[] = "\x1b[0m"; @@ -150,7 +142,7 @@ typedef void (*FormatFunc)(fmt::Writer &, int, fmt::StringRef); // Buffer should be at least of size 1. int safe_strerror( int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT { - assert(buffer != 0 && buffer_size != 0); + FMT_ASSERT(buffer != 0 && buffer_size != 0, "invalid buffer"); class StrError { private: @@ -177,7 +169,7 @@ int safe_strerror( } // Handle the case when strerror_r is not available. - int handle(fmt::internal::None<>) { + int handle(fmt::internal::Null<>) { return fallback(strerror_s(buffer_, buffer_size_, error_code_)); } @@ -189,17 +181,20 @@ int safe_strerror( } // Fallback to strerror if strerror_r and strerror_s are not available. - int fallback(fmt::internal::None<>) { + int fallback(fmt::internal::Null<>) { errno = 0; buffer_ = strerror(error_code_); return errno; } public: - StrError(int error_code, char *&buffer, std::size_t buffer_size) - : error_code_(error_code), buffer_(buffer), buffer_size_(buffer_size) {} + StrError(int err_code, char *&buf, std::size_t buf_size) + : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} - int run() { return handle(strerror_r(error_code_, buffer_, buffer_size_)); } + int run() { + strerror_r(0, 0, ""); // Suppress a warning about unused strerror_r. + return handle(strerror_r(error_code_, buffer_, buffer_size_)); + } }; return StrError(error_code, buffer, buffer_size).run(); } @@ -239,45 +234,6 @@ class IsZeroInt : public fmt::internal::ArgVisitor<IsZeroInt, bool> { bool visit_any_int(T value) { return value == 0; } }; -// Parses an unsigned integer advancing s to the end of the parsed input. -// This function assumes that the first character of s is a digit. -template <typename Char> -int parse_nonnegative_int(const Char *&s) { - assert('0' <= *s && *s <= '9'); - unsigned value = 0; - do { - unsigned new_value = value * 10 + (*s++ - '0'); - // Check if value wrapped around. - if (new_value < value) { - value = UINT_MAX; - break; - } - value = new_value; - } while ('0' <= *s && *s <= '9'); - if (value > INT_MAX) - FMT_THROW(fmt::FormatError("number is too big")); - return value; -} - -inline void require_numeric_argument(const Arg &arg, char spec) { - if (arg.type > Arg::LAST_NUMERIC_TYPE) { - std::string message = - fmt::format("format specifier '{}' requires numeric argument", spec); - FMT_THROW(fmt::FormatError(message)); - } -} - -template <typename Char> -void check_sign(const Char *&s, const Arg &arg) { - char sign = static_cast<char>(*s); - require_numeric_argument(arg, sign); - if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) { - FMT_THROW(fmt::FormatError(fmt::format( - "format specifier '{}' requires signed argument", sign))); - } - ++s; -} - // Checks if an argument is a valid printf width specifier and sets // left alignment if it is negative. class WidthHandler : public fmt::internal::ArgVisitor<WidthHandler, unsigned> { @@ -335,6 +291,11 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> { ArgConverter(fmt::internal::Arg &arg, wchar_t type) : arg_(arg), type_(type) {} + void visit_bool(bool value) { + if (type_ != 's') + visit_any_int(value); + } + template <typename U> void visit_any_int(U value) { bool is_signed = type_ == 'd' || type_ == 'i'; @@ -379,24 +340,83 @@ class CharConverter : public fmt::internal::ArgVisitor<CharConverter, void> { arg_.int_value = static_cast<char>(value); } }; +} // namespace + +namespace internal { -// This function template is used to prevent compile errors when handling -// incompatible string arguments, e.g. handling a wide string in a narrow -// string formatter. template <typename Char> -Arg::StringValue<Char> ignore_incompatible_str(Arg::StringValue<wchar_t>); +class PrintfArgFormatter : + public ArgFormatterBase<PrintfArgFormatter<Char>, Char> { -template <> -inline Arg::StringValue<char> ignore_incompatible_str( - Arg::StringValue<wchar_t>) { return Arg::StringValue<char>(); } + void write_null_pointer() { + this->spec().type_ = 0; + this->write("(nil)"); + } -template <> -inline Arg::StringValue<wchar_t> ignore_incompatible_str( - Arg::StringValue<wchar_t> s) { return s; } -} // namespace + typedef ArgFormatterBase<PrintfArgFormatter<Char>, Char> Base; + + public: + PrintfArgFormatter(BasicWriter<Char> &w, FormatSpec &s) + : ArgFormatterBase<PrintfArgFormatter<Char>, Char>(w, s) {} + + void visit_bool(bool value) { + FormatSpec &fmt_spec = this->spec(); + if (fmt_spec.type_ != 's') + return this->visit_any_int(value); + fmt_spec.type_ = 0; + this->write(value); + } + + void visit_char(int value) { + const FormatSpec &fmt_spec = this->spec(); + BasicWriter<Char> &w = this->writer(); + if (fmt_spec.type_ && fmt_spec.type_ != 'c') + w.write_int(value, fmt_spec); + typedef typename BasicWriter<Char>::CharPtr CharPtr; + CharPtr out = CharPtr(); + if (fmt_spec.width_ > 1) { + Char fill = ' '; + out = w.grow_buffer(fmt_spec.width_); + if (fmt_spec.align_ != ALIGN_LEFT) { + std::fill_n(out, fmt_spec.width_ - 1, fill); + out += fmt_spec.width_ - 1; + } else { + std::fill_n(out + 1, fmt_spec.width_ - 1, fill); + } + } else { + out = w.grow_buffer(1); + } + *out = static_cast<Char>(value); + } + + void visit_cstring(const char *value) { + if (value) + Base::visit_cstring(value); + else if (this->spec().type_ == 'p') + write_null_pointer(); + else + this->write("(null)"); + } + + void visit_pointer(const void *value) { + if (value) + return Base::visit_pointer(value); + this->spec().type_ = 0; + write_null_pointer(); + } + + void visit_custom(Arg::CustomValue c) { + BasicFormatter<Char> formatter(ArgList(), this->writer()); + const Char format_str[] = {'}', 0}; + const Char *format = format_str; + c.format(&formatter, c.value, &format); + } +}; +} // namespace internal +} // namespace fmt FMT_FUNC void fmt::SystemError::init( - int err_code, StringRef format_str, ArgList args) { + int err_code, CStringRef format_str, ArgList args) { error_code_ = err_code; MemoryWriter w; internal::format_system_error(w, err_code, format(format_str, args)); @@ -477,19 +497,23 @@ FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) { static_cast<unsigned>(code), type))); } -#ifdef _WIN32 +#if FMT_USE_WINDOWS_H FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) { - int length = MultiByteToWideChar( - CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, 0, 0); static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16"; + if (s.size() > INT_MAX) + FMT_THROW(WindowsError(ERROR_INVALID_PARAMETER, ERROR_MSG)); + int s_size = static_cast<int>(s.size()); + int length = MultiByteToWideChar( + CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, 0, 0); if (length == 0) FMT_THROW(WindowsError(GetLastError(), ERROR_MSG)); - buffer_.resize(length); + buffer_.resize(length + 1); length = MultiByteToWideChar( - CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, &buffer_[0], length); + CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, &buffer_[0], length); if (length == 0) FMT_THROW(WindowsError(GetLastError(), ERROR_MSG)); + buffer_[length] = 0; } FMT_FUNC fmt::internal::UTF16ToUTF8::UTF16ToUTF8(fmt::WStringRef s) { @@ -500,19 +524,23 @@ FMT_FUNC fmt::internal::UTF16ToUTF8::UTF16ToUTF8(fmt::WStringRef s) { } FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) { - int length = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, 0, 0, 0, 0); + if (s.size() > INT_MAX) + return ERROR_INVALID_PARAMETER; + int s_size = static_cast<int>(s.size()); + int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, 0, 0, 0, 0); if (length == 0) return GetLastError(); - buffer_.resize(length); + buffer_.resize(length + 1); length = WideCharToMultiByte( - CP_UTF8, 0, s.c_str(), -1, &buffer_[0], length, 0, 0); + CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, 0, 0); if (length == 0) return GetLastError(); + buffer_[length] = 0; return 0; } FMT_FUNC void fmt::WindowsError::init( - int err_code, StringRef format_str, ArgList args) { + int err_code, CStringRef format_str, ArgList args) { error_code_ = err_code; MemoryWriter w; internal::format_windows_error(w, err_code, format(format_str, args)); @@ -520,30 +548,6 @@ FMT_FUNC void fmt::WindowsError::init( base = std::runtime_error(w.str()); } -#endif - -FMT_FUNC void fmt::internal::format_system_error( - fmt::Writer &out, int error_code, - fmt::StringRef message) FMT_NOEXCEPT { - FMT_TRY { - MemoryBuffer<char, INLINE_BUFFER_SIZE> buffer; - buffer.resize(INLINE_BUFFER_SIZE); - for (;;) { - char *system_message = &buffer[0]; - int result = safe_strerror(error_code, system_message, buffer.size()); - if (result == 0) { - out << message << ": " << system_message; - return; - } - if (result != ERANGE) - break; // Can't get error message, report error code instead. - buffer.resize(buffer.size() * 2); - } - } FMT_CATCH(...) {} - format_error_code(out, error_code, message); -} - -#ifdef _WIN32 FMT_FUNC void fmt::internal::format_windows_error( fmt::Writer &out, int error_code, fmt::StringRef message) FMT_NOEXCEPT { @@ -570,146 +574,95 @@ FMT_FUNC void fmt::internal::format_windows_error( } } } FMT_CATCH(...) {} - format_error_code(out, error_code, message); + fmt::format_error_code(out, error_code, message); // 'fmt::' is for bcc32. } -#endif -// An argument formatter. -template <typename Char> -class fmt::internal::ArgFormatter : - public fmt::internal::ArgVisitor<fmt::internal::ArgFormatter<Char>, void> { - private: - fmt::BasicFormatter<Char> &formatter_; - fmt::BasicWriter<Char> &writer_; - fmt::FormatSpec &spec_; - const Char *format_; - - FMT_DISALLOW_COPY_AND_ASSIGN(ArgFormatter); - - public: - ArgFormatter( - fmt::BasicFormatter<Char> &f,fmt::FormatSpec &s, const Char *fmt) - : formatter_(f), writer_(f.writer()), spec_(s), format_(fmt) {} +#endif // FMT_USE_WINDOWS_H - template <typename T> - void visit_any_int(T value) { writer_.write_int(value, spec_); } - - template <typename T> - void visit_any_double(T value) { writer_.write_double(value, spec_); } - - void visit_char(int value) { - if (spec_.type_ && spec_.type_ != 'c') { - spec_.flags_ |= CHAR_FLAG; - writer_.write_int(value, spec_); - return; - } - if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0) - FMT_THROW(FormatError("invalid format specifier for char")); - typedef typename fmt::BasicWriter<Char>::CharPtr CharPtr; - Char fill = static_cast<Char>(spec_.fill()); - if (spec_.precision_ == 0) { - std::fill_n(writer_.grow_buffer(spec_.width_), spec_.width_, fill); - return; - } - CharPtr out = CharPtr(); - if (spec_.width_ > 1) { - out = writer_.grow_buffer(spec_.width_); - if (spec_.align_ == fmt::ALIGN_RIGHT) { - std::fill_n(out, spec_.width_ - 1, fill); - out += spec_.width_ - 1; - } else if (spec_.align_ == fmt::ALIGN_CENTER) { - out = writer_.fill_padding(out, spec_.width_, 1, fill); - } else { - std::fill_n(out + 1, spec_.width_ - 1, fill); +FMT_FUNC void fmt::internal::format_system_error( + fmt::Writer &out, int error_code, + fmt::StringRef message) FMT_NOEXCEPT { + FMT_TRY { + MemoryBuffer<char, INLINE_BUFFER_SIZE> buffer; + buffer.resize(INLINE_BUFFER_SIZE); + for (;;) { + char *system_message = &buffer[0]; + int result = safe_strerror(error_code, system_message, buffer.size()); + if (result == 0) { + out << message << ": " << system_message; + return; } - } else { - out = writer_.grow_buffer(1); + if (result != ERANGE) + break; // Can't get error message, report error code instead. + buffer.resize(buffer.size() * 2); } - *out = static_cast<Char>(value); - } + } FMT_CATCH(...) {} + fmt::format_error_code(out, error_code, message); // 'fmt::' is for bcc32. +} - void visit_string(Arg::StringValue<char> value) { - writer_.write_str(value, spec_); - } - void visit_wstring(Arg::StringValue<wchar_t> value) { - writer_.write_str(ignore_incompatible_str<Char>(value), spec_); +template <typename Char> +void fmt::internal::ArgMap<Char>::init(const ArgList &args) { + if (!map_.empty()) + return; + typedef internal::NamedArg<Char> NamedArg; + const NamedArg *named_arg = 0; + bool use_values = + args.type(ArgList::MAX_PACKED_ARGS - 1) == internal::Arg::NONE; + if (use_values) { + for (unsigned i = 0;/*nothing*/; ++i) { + internal::Arg::Type arg_type = args.type(i); + switch (arg_type) { + case internal::Arg::NONE: + return; + case internal::Arg::NAMED_ARG: + named_arg = static_cast<const NamedArg*>(args.values_[i].pointer); + map_.insert(Pair(named_arg->name, *named_arg)); + break; + default: + /*nothing*/; + } + } + return; } - - void visit_pointer(const void *value) { - if (spec_.type_ && spec_.type_ != 'p') - fmt::internal::report_unknown_type(spec_.type_, "pointer"); - spec_.flags_ = fmt::HASH_FLAG; - spec_.type_ = 'x'; - writer_.write_int(reinterpret_cast<uintptr_t>(value), spec_); + for (unsigned i = 0; i != ArgList::MAX_PACKED_ARGS; ++i) { + internal::Arg::Type arg_type = args.type(i); + if (arg_type == internal::Arg::NAMED_ARG) { + named_arg = static_cast<const NamedArg*>(args.args_[i].pointer); + map_.insert(Pair(named_arg->name, *named_arg)); + } } - - void visit_custom(Arg::CustomValue c) { - c.format(&formatter_, c.value, &format_); + for (unsigned i = ArgList::MAX_PACKED_ARGS;/*nothing*/; ++i) { + switch (args.args_[i].type) { + case internal::Arg::NONE: + return; + case internal::Arg::NAMED_ARG: + named_arg = static_cast<const NamedArg*>(args.args_[i].pointer); + map_.insert(Pair(named_arg->name, *named_arg)); + break; + default: + /*nothing*/; + } } -}; +} template <typename Char> void fmt::internal::FixedBuffer<Char>::grow(std::size_t) { FMT_THROW(std::runtime_error("buffer overflow")); } -template <typename Char> -template <typename StrChar> -void fmt::BasicWriter<Char>::write_str( - const Arg::StringValue<StrChar> &s, const FormatSpec &spec) { - // Check if StrChar is convertible to Char. - internal::CharTraits<Char>::convert(StrChar()); - if (spec.type_ && spec.type_ != 's') - internal::report_unknown_type(spec.type_, "string"); - const StrChar *str_value = s.value; - std::size_t str_size = s.size; - if (str_size == 0) { - if (!str_value) - FMT_THROW(FormatError("string pointer is null")); - if (*str_value) - str_size = std::char_traits<StrChar>::length(str_value); - } - std::size_t precision = spec.precision_; - if (spec.precision_ >= 0 && precision < str_size) - str_size = spec.precision_; - write_str(str_value, str_size, spec); -} - -template <typename Char> -inline Arg fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) { - const char *error = 0; - Arg arg = *s < '0' || *s > '9' ? - next_arg(error) : get_arg(parse_nonnegative_int(s), error); - if (error) { - FMT_THROW(FormatError( - *s != '}' && *s != ':' ? "invalid format string" : error)); - } - return arg; -} - FMT_FUNC Arg fmt::internal::FormatterBase::do_get_arg( unsigned arg_index, const char *&error) { Arg arg = args_[arg_index]; - if (arg.type == Arg::NONE) + switch (arg.type) { + case Arg::NONE: error = "argument index out of range"; - return arg; -} - -inline Arg fmt::internal::FormatterBase::next_arg(const char *&error) { - if (next_arg_index_ >= 0) - return do_get_arg(next_arg_index_++, error); - error = "cannot switch from manual to automatic argument indexing"; - return Arg(); -} - -inline Arg fmt::internal::FormatterBase::get_arg( - unsigned arg_index, const char *&error) { - if (next_arg_index_ <= 0) { - next_arg_index_ = -1; - return do_get_arg(arg_index, error); + break; + case Arg::NAMED_ARG: + arg = *static_cast<const internal::Arg*>(arg.pointer); + default: + /*nothing*/; } - error = "cannot switch from automatic to manual argument indexing"; - return Arg(); + return arg; } template <typename Char> @@ -787,10 +740,8 @@ unsigned fmt::internal::PrintfFormatter<Char>::parse_header( template <typename Char> void fmt::internal::PrintfFormatter<Char>::format( - BasicWriter<Char> &writer, BasicStringRef<Char> format_str, - const ArgList &args) { + BasicWriter<Char> &writer, BasicCStringRef<Char> format_str) { const Char *start = format_str.c_str(); - set_args(args); const Char *s = start; while (*s) { Char c = *s++; @@ -847,10 +798,10 @@ void fmt::internal::PrintfFormatter<Char>::format( ArgConverter<intmax_t>(arg, *s).visit(arg); break; case 'z': - ArgConverter<size_t>(arg, *s).visit(arg); + ArgConverter<std::size_t>(arg, *s).visit(arg); break; case 't': - ArgConverter<ptrdiff_t>(arg, *s).visit(arg); + ArgConverter<std::ptrdiff_t>(arg, *s).visit(arg); break; case 'L': // printf produces garbage when 'L' is omitted for long double, no @@ -881,274 +832,50 @@ void fmt::internal::PrintfFormatter<Char>::format( start = s; // Format argument. - switch (arg.type) { - case Arg::INT: - writer.write_int(arg.int_value, spec); - break; - case Arg::UINT: - writer.write_int(arg.uint_value, spec); - break; - case Arg::LONG_LONG: - writer.write_int(arg.long_long_value, spec); - break; - case Arg::ULONG_LONG: - writer.write_int(arg.ulong_long_value, spec); - break; - case Arg::CHAR: { - if (spec.type_ && spec.type_ != 'c') - writer.write_int(arg.int_value, spec); - typedef typename BasicWriter<Char>::CharPtr CharPtr; - CharPtr out = CharPtr(); - if (spec.width_ > 1) { - Char fill = ' '; - out = writer.grow_buffer(spec.width_); - if (spec.align_ != ALIGN_LEFT) { - std::fill_n(out, spec.width_ - 1, fill); - out += spec.width_ - 1; - } else { - std::fill_n(out + 1, spec.width_ - 1, fill); - } - } else { - out = writer.grow_buffer(1); - } - *out = static_cast<Char>(arg.int_value); - break; - } - case Arg::DOUBLE: - writer.write_double(arg.double_value, spec); - break; - case Arg::LONG_DOUBLE: - writer.write_double(arg.long_double_value, spec); - break; - case Arg::CSTRING: - arg.string.size = 0; - writer.write_str(arg.string, spec); - break; - case Arg::STRING: - writer.write_str(arg.string, spec); - break; - case Arg::WSTRING: - writer.write_str(ignore_incompatible_str<Char>(arg.wstring), spec); - break; - case Arg::POINTER: - if (spec.type_ && spec.type_ != 'p') - internal::report_unknown_type(spec.type_, "pointer"); - spec.flags_= HASH_FLAG; - spec.type_ = 'x'; - writer.write_int(reinterpret_cast<uintptr_t>(arg.pointer), spec); - break; - case Arg::CUSTOM: { - if (spec.type_) - internal::report_unknown_type(spec.type_, "object"); - const void *str_format = "s"; - arg.custom.format(&writer, arg.custom.value, &str_format); - break; - } - default: - assert(false); - break; - } + internal::PrintfArgFormatter<Char>(writer, spec).visit(arg); } write(writer, start, s); } -template <typename Char> -const Char *fmt::BasicFormatter<Char>::format( - const Char *&format_str, const Arg &arg) { - const Char *s = format_str; - FormatSpec spec; - if (*s == ':') { - if (arg.type == Arg::CUSTOM) { - arg.custom.format(this, arg.custom.value, &s); - return s; - } - ++s; - // Parse fill and alignment. - if (Char c = *s) { - const Char *p = s + 1; - spec.align_ = ALIGN_DEFAULT; - do { - switch (*p) { - case '<': - spec.align_ = ALIGN_LEFT; - break; - case '>': - spec.align_ = ALIGN_RIGHT; - break; - case '=': - spec.align_ = ALIGN_NUMERIC; - break; - case '^': - spec.align_ = ALIGN_CENTER; - break; - } - if (spec.align_ != ALIGN_DEFAULT) { - if (p != s) { - if (c == '}') break; - if (c == '{') - FMT_THROW(FormatError("invalid fill character '{'")); - s += 2; - spec.fill_ = c; - } else ++s; - if (spec.align_ == ALIGN_NUMERIC) - require_numeric_argument(arg, '='); - break; - } - } while (--p >= s); - } - - // Parse sign. - switch (*s) { - case '+': - check_sign(s, arg); - spec.flags_ |= SIGN_FLAG | PLUS_FLAG; - break; - case '-': - check_sign(s, arg); - spec.flags_ |= MINUS_FLAG; - break; - case ' ': - check_sign(s, arg); - spec.flags_ |= SIGN_FLAG; - break; - } - - if (*s == '#') { - require_numeric_argument(arg, '#'); - spec.flags_ |= HASH_FLAG; - ++s; - } - - // Parse width and zero flag. - if ('0' <= *s && *s <= '9') { - if (*s == '0') { - require_numeric_argument(arg, '0'); - spec.align_ = ALIGN_NUMERIC; - spec.fill_ = '0'; - } - // Zero may be parsed again as a part of the width, but it is simpler - // and more efficient than checking if the next char is a digit. - spec.width_ = parse_nonnegative_int(s); - } - - // Parse precision. - if (*s == '.') { - ++s; - spec.precision_ = 0; - if ('0' <= *s && *s <= '9') { - spec.precision_ = parse_nonnegative_int(s); - } else if (*s == '{') { - ++s; - const Arg &precision_arg = parse_arg_index(s); - if (*s++ != '}') - FMT_THROW(FormatError("invalid format string")); - ULongLong value = 0; - switch (precision_arg.type) { - case Arg::INT: - if (precision_arg.int_value < 0) - FMT_THROW(FormatError("negative precision")); - value = precision_arg.int_value; - break; - case Arg::UINT: - value = precision_arg.uint_value; - break; - case Arg::LONG_LONG: - if (precision_arg.long_long_value < 0) - FMT_THROW(FormatError("negative precision")); - value = precision_arg.long_long_value; - break; - case Arg::ULONG_LONG: - value = precision_arg.ulong_long_value; - break; - default: - FMT_THROW(FormatError("precision is not integer")); - } - if (value > INT_MAX) - FMT_THROW(FormatError("number is too big")); - spec.precision_ = static_cast<int>(value); - } else { - FMT_THROW(FormatError("missing precision specifier")); - } - if (arg.type < Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER) { - FMT_THROW(FormatError( - fmt::format("precision not allowed in {} format specifier", - arg.type == Arg::POINTER ? "pointer" : "integer"))); - } - } - - // Parse type. - if (*s != '}' && *s) - spec.type_ = static_cast<char>(*s++); - } - - if (*s++ != '}') - FMT_THROW(FormatError("missing '}' in format string")); - start_ = s; - - // Format argument. - internal::ArgFormatter<Char>(*this, spec, s - 1).visit(arg); - return s; -} - -template <typename Char> -void fmt::BasicFormatter<Char>::format( - BasicStringRef<Char> format_str, const ArgList &args) { - const Char *s = start_ = format_str.c_str(); - set_args(args); - while (*s) { - Char c = *s++; - if (c != '{' && c != '}') continue; - if (*s == c) { - write(writer_, start_, s); - start_ = ++s; - continue; - } - if (c == '}') - FMT_THROW(FormatError("unmatched '}' in format string")); - write(writer_, start_, s - 1); - Arg arg = parse_arg_index(s); - s = format(s, arg); - } - write(writer_, start_, s); -} - FMT_FUNC void fmt::report_system_error( int error_code, fmt::StringRef message) FMT_NOEXCEPT { - report_error(internal::format_system_error, error_code, message); + // 'fmt::' is for bcc32. + fmt::report_error(internal::format_system_error, error_code, message); } -#ifdef _WIN32 +#if FMT_USE_WINDOWS_H FMT_FUNC void fmt::report_windows_error( int error_code, fmt::StringRef message) FMT_NOEXCEPT { - report_error(internal::format_windows_error, error_code, message); + // 'fmt::' is for bcc32. + fmt::report_error(internal::format_windows_error, error_code, message); } #endif -FMT_FUNC void fmt::print(std::FILE *f, StringRef format_str, ArgList args) { +FMT_FUNC void fmt::print(std::FILE *f, CStringRef format_str, ArgList args) { MemoryWriter w; w.write(format_str, args); std::fwrite(w.data(), 1, w.size(), f); } -FMT_FUNC void fmt::print(StringRef format_str, ArgList args) { +FMT_FUNC void fmt::print(CStringRef format_str, ArgList args) { print(stdout, format_str, args); } -FMT_FUNC void fmt::print(std::ostream &os, StringRef format_str, ArgList args) { +FMT_FUNC void fmt::print(std::ostream &os, CStringRef format_str, ArgList args) { MemoryWriter w; w.write(format_str, args); os.write(w.data(), w.size()); } -FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) { +FMT_FUNC void fmt::print_colored(Color c, CStringRef format, ArgList args) { char escape[] = "\x1b[30m"; - escape[3] = '0' + static_cast<char>(c); + escape[3] = static_cast<char>('0' + c); std::fputs(escape, stdout); print(format, args); std::fputs(RESET_COLOR, stdout); } -FMT_FUNC int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) { +FMT_FUNC int fmt::fprintf(std::FILE *f, CStringRef format, ArgList args) { MemoryWriter w; printf(w, format, args); std::size_t size = w.size(); @@ -1157,18 +884,16 @@ FMT_FUNC int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) { #ifndef FMT_HEADER_ONLY +template struct fmt::internal::BasicData<void>; + // Explicit instantiations for char. template void fmt::internal::FixedBuffer<char>::grow(std::size_t); -template const char *fmt::BasicFormatter<char>::format( - const char *&format_str, const fmt::internal::Arg &arg); - -template void fmt::BasicFormatter<char>::format( - BasicStringRef<char> format, const ArgList &args); +template void fmt::internal::ArgMap<char>::init(const fmt::ArgList &args); template void fmt::internal::PrintfFormatter<char>::format( - BasicWriter<char> &writer, BasicStringRef<char> format, const ArgList &args); + BasicWriter<char> &writer, CStringRef format); template int fmt::internal::CharTraits<char>::format_float( char *buffer, std::size_t size, const char *format, @@ -1182,15 +907,10 @@ template int fmt::internal::CharTraits<char>::format_float( template void fmt::internal::FixedBuffer<wchar_t>::grow(std::size_t); -template const wchar_t *fmt::BasicFormatter<wchar_t>::format( - const wchar_t *&format_str, const fmt::internal::Arg &arg); - -template void fmt::BasicFormatter<wchar_t>::format( - BasicStringRef<wchar_t> format, const ArgList &args); +template void fmt::internal::ArgMap<wchar_t>::init(const fmt::ArgList &args); template void fmt::internal::PrintfFormatter<wchar_t>::format( - BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format, - const ArgList &args); + BasicWriter<wchar_t> &writer, WCStringRef format); template int fmt::internal::CharTraits<wchar_t>::format_float( wchar_t *buffer, std::size_t size, const wchar_t *format, @@ -1202,6 +922,6 @@ template int fmt::internal::CharTraits<wchar_t>::format_float( #endif // FMT_HEADER_ONLY -#if _MSC_VER +#ifdef _MSC_VER # pragma warning(pop) #endif diff --git a/dep/cppformat/format.h b/dep/cppformat/format.h index 8d54bf521c7..a98a166091b 100644 --- a/dep/cppformat/format.h +++ b/dep/cppformat/format.h @@ -28,19 +28,39 @@ #ifndef FMT_FORMAT_H_ #define FMT_FORMAT_H_ +#if defined _MSC_VER && _MSC_VER <= 1500 +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef long long intmax_t; +#else #include <stdint.h> +#endif #include <cassert> #include <cmath> -#include <cstddef> // for std::ptrdiff_t #include <cstdio> -#include <algorithm> +#include <cstring> #include <limits> +#include <memory> #include <stdexcept> #include <string> -#include <sstream> +#include <map> + +#ifndef FMT_USE_IOSTREAMS +# define FMT_USE_IOSTREAMS 1 +#endif + +#if FMT_USE_IOSTREAMS +# include <ostream> +#endif -#if _SECURE_SCL +#ifdef _SECURE_SCL +# define FMT_SECURE_SCL _SECURE_SCL +#else +# define FMT_SECURE_SCL 0 +#endif + +#if FMT_SECURE_SCL # include <iterator> #endif @@ -91,6 +111,9 @@ inline uint32_t clzll(uint64_t x) { // Disable the warning about declaration shadowing because it affects too // many valid cases. # pragma GCC diagnostic ignored "-Wshadow" +// Disable the warning about implicit conversions that may change the sign of +// an integer; silencing it otherwise would require many explicit casts. +# pragma GCC diagnostic ignored "-Wsign-conversion" # endif # if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ # define FMT_HAS_GXX_CXX11 1 @@ -99,7 +122,7 @@ inline uint32_t clzll(uint64_t x) { # define FMT_GCC_EXTENSION #endif -#ifdef __clang__ +#if defined(__clang__) && !defined(__INTEL_COMPILER) # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdocumentation" #endif @@ -152,26 +175,144 @@ inline uint32_t clzll(uint64_t x) { #endif // Define FMT_USE_NOEXCEPT to make C++ Format use noexcept (C++11 feature). -#if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ - (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) -# define FMT_NOEXCEPT noexcept -#else -# define FMT_NOEXCEPT throw() +#ifndef FMT_USE_NOEXCEPT +# define FMT_USE_NOEXCEPT 0 +#endif + +#ifndef FMT_NOEXCEPT +# if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ + (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \ + _MSC_VER >= 1900 +# define FMT_NOEXCEPT noexcept +# else +# define FMT_NOEXCEPT throw() +# endif +#endif + +// Check if exceptions are disabled. +#if defined(__GNUC__) && !defined(__EXCEPTIONS) +# define FMT_EXCEPTIONS 0 +#endif +#if defined(_MSC_VER) && !_HAS_EXCEPTIONS +# define FMT_EXCEPTIONS 0 +#endif +#ifndef FMT_EXCEPTIONS +# define FMT_EXCEPTIONS 1 +#endif + +#ifndef FMT_THROW +# if FMT_EXCEPTIONS +# define FMT_THROW(x) throw x +# else +# define FMT_THROW(x) assert(false) +# endif #endif // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class +#ifndef FMT_USE_DELETED_FUNCTIONS +# define FMT_USE_DELETED_FUNCTIONS 0 +#endif + #if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \ (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800 +# define FMT_DELETED_OR_UNDEFINED = delete # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&) = delete; \ TypeName& operator=(const TypeName&) = delete #else +# define FMT_DELETED_OR_UNDEFINED # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&); \ TypeName& operator=(const TypeName&) #endif +#ifndef FMT_USE_USER_DEFINED_LITERALS +// All compilers which support UDLs also support variadic templates. This +// makes the fmt::literals implementation easier. However, an explicit check +// for variadic templates is added here just in case. +# define FMT_USE_USER_DEFINED_LITERALS \ + FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES && \ + (FMT_HAS_FEATURE(cxx_user_literals) || \ + (FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1900) +#endif + +#ifndef FMT_ASSERT +# define FMT_ASSERT(condition, message) assert((condition) && message) +#endif + +namespace fmt { +namespace internal { +struct DummyInt { + int data[2]; + operator int() const { return 0; } +}; +typedef std::numeric_limits<fmt::internal::DummyInt> FPUtil; + +// Dummy implementations of system functions such as signbit and ecvt called +// if the latter are not available. +inline DummyInt signbit(...) { return DummyInt(); } +inline DummyInt _ecvt_s(...) { return DummyInt(); } +inline DummyInt isinf(...) { return DummyInt(); } +inline DummyInt _finite(...) { return DummyInt(); } +inline DummyInt isnan(...) { return DummyInt(); } +inline DummyInt _isnan(...) { return DummyInt(); } + +// A helper function to suppress bogus "conditional expression is constant" +// warnings. +template <typename T> +inline T check(T value) { return value; } +} +} // namespace fmt + +namespace std { +// Standard permits specialization of std::numeric_limits. This specialization +// is used to resolve ambiguity between isinf and std::isinf in glibc: +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891 +// and the same for isnan and signbit. +template <> +class numeric_limits<fmt::internal::DummyInt> : + public std::numeric_limits<int> { + public: + // Portable version of isinf. + template <typename T> + static bool isinfinity(T x) { + using namespace fmt::internal; + // The resolution "priority" is: + // isinf macro > std::isinf > ::isinf > fmt::internal::isinf + if (check(sizeof(isinf(x)) == sizeof(bool) || + sizeof(isinf(x)) == sizeof(int))) { + return isinf(x) != 0; + } + return !_finite(static_cast<double>(x)); + } + + // Portable version of isnan. + template <typename T> + static bool isnotanumber(T x) { + using namespace fmt::internal; + if (check(sizeof(isnan(x)) == sizeof(bool) || + sizeof(isnan(x)) == sizeof(int))) { + return isnan(x) != 0; + } + return _isnan(static_cast<double>(x)) != 0; + } + + // Portable version of signbit. + static bool isnegative(double x) { + using namespace fmt::internal; + if (check(sizeof(signbit(x)) == sizeof(int))) + return signbit(x) != 0; + if (x < 0) return true; + if (!isnotanumber(x)) return false; + int dec = 0, sign = 0; + char buffer[2]; // The buffer size must be >= 2 or _ecvt_s will fail. + _ecvt_s(buffer, sizeof(buffer), x, 0, &dec, &sign); + return sign != 0; + } +}; +} // namespace std + namespace fmt { // Fix the warning about long long on older versions of GCC @@ -197,9 +338,8 @@ void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value); /** \rst - A string reference. It can be constructed from a C string or - ``std::string``. - + A string reference. It can be constructed from a C string or ``std::string``. + You can use one of the following typedefs for common character types: +------------+-------------------------+ @@ -227,46 +367,67 @@ class BasicStringRef { std::size_t size_; public: - /** - Constructs a string reference object from a C string and a size. - */ + /** Constructs a string reference object from a C string and a size. */ BasicStringRef(const Char *s, std::size_t size) : data_(s), size_(size) {} /** + \rst Constructs a string reference object from a C string computing the size with ``std::char_traits<Char>::length``. + \endrst */ BasicStringRef(const Char *s) : data_(s), size_(std::char_traits<Char>::length(s)) {} /** - Constructs a string reference from an `std::string` object. + \rst + Constructs a string reference from an ``std::string`` object. + \endrst */ BasicStringRef(const std::basic_string<Char> &s) : data_(s.c_str()), size_(s.size()) {} /** - Converts a string reference to an `std::string` object. + \rst + Converts a string reference to an ``std::string`` object. + \endrst */ - operator std::basic_string<Char>() const { - return std::basic_string<Char>(data_, size()); + std::basic_string<Char> to_string() const { + return std::basic_string<Char>(data_, size_); } - /** - Returns the pointer to a C string. - */ - const Char *c_str() const { return data_; } + /** Returns the pointer to a C string. */ + const Char *data() const { return data_; } - /** - Returns the string size. - */ + /** Returns the string size. */ std::size_t size() const { return size_; } + // Lexicographically compare this string reference to other. + int compare(BasicStringRef other) const { + std::size_t size = size_ < other.size_ ? size_ : other.size_; + int result = std::char_traits<Char>::compare(data_, other.data_, size); + if (result == 0) + result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1); + return result; + } + friend bool operator==(BasicStringRef lhs, BasicStringRef rhs) { - return lhs.data_ == rhs.data_; + return lhs.compare(rhs) == 0; } friend bool operator!=(BasicStringRef lhs, BasicStringRef rhs) { - return lhs.data_ != rhs.data_; + return lhs.compare(rhs) != 0; + } + friend bool operator<(BasicStringRef lhs, BasicStringRef rhs) { + return lhs.compare(rhs) < 0; + } + friend bool operator<=(BasicStringRef lhs, BasicStringRef rhs) { + return lhs.compare(rhs) <= 0; + } + friend bool operator>(BasicStringRef lhs, BasicStringRef rhs) { + return lhs.compare(rhs) > 0; + } + friend bool operator>=(BasicStringRef lhs, BasicStringRef rhs) { + return lhs.compare(rhs) >= 0; } }; @@ -274,11 +435,59 @@ typedef BasicStringRef<char> StringRef; typedef BasicStringRef<wchar_t> WStringRef; /** + \rst + A reference to a null terminated string. It can be constructed from a C + string or ``std::string``. + + You can use one of the following typedefs for common character types: + + +-------------+--------------------------+ + | Type | Definition | + +=============+==========================+ + | CStringRef | BasicCStringRef<char> | + +-------------+--------------------------+ + | WCStringRef | BasicCStringRef<wchar_t> | + +-------------+--------------------------+ + + This class is most useful as a parameter type to allow passing + different types of strings to a function, for example:: + + template <typename... Args> + std::string format(CStringRef format_str, const Args & ... args); + + format("{}", 42); + format(std::string("{}"), 42); + \endrst + */ +template <typename Char> +class BasicCStringRef { + private: + const Char *data_; + + public: + /** Constructs a string reference object from a C string. */ + BasicCStringRef(const Char *s) : data_(s) {} + + /** + \rst + Constructs a string reference from an ``std::string`` object. + \endrst + */ + BasicCStringRef(const std::basic_string<Char> &s) : data_(s.c_str()) {} + + /** Returns the pointer to a C string. */ + const Char *c_str() const { return data_; } +}; + +typedef BasicCStringRef<char> CStringRef; +typedef BasicCStringRef<wchar_t> WCStringRef; + +/** A formatting error such as invalid format string. */ class FormatError : public std::runtime_error { public: - explicit FormatError(StringRef message) + explicit FormatError(CStringRef message) : std::runtime_error(message.c_str()) {} }; @@ -287,7 +496,7 @@ namespace internal { // to avoid dynamic memory allocation. enum { INLINE_BUFFER_SIZE = 500 }; -#if _SECURE_SCL +#if FMT_SECURE_SCL // Use checked iterator to avoid warnings on MSVC. template <typename T> inline stdext::checked_array_iterator<T*> make_ptr(T *ptr, std::size_t size) { @@ -299,7 +508,11 @@ inline T *make_ptr(T *ptr, std::size_t) { return ptr; } #endif } // namespace internal -/** A buffer supporting a subset of ``std::vector``'s operations. */ +/** + \rst + A buffer supporting a subset of ``std::vector``'s operations. + \endrst + */ template <typename T> class Buffer { private: @@ -314,8 +527,10 @@ class Buffer { : ptr_(ptr), size_(0), capacity_(capacity) {} /** + \rst Increases the buffer capacity to hold at least *size* elements updating ``ptr_`` and ``capacity_``. + \endrst */ virtual void grow(std::size_t size) = 0; @@ -337,7 +552,11 @@ class Buffer { size_ = new_size; } - /** Reserves space to store at least *capacity* elements. */ + /** + \rst + Reserves space to store at least *capacity* elements. + \endrst + */ void reserve(std::size_t capacity) { if (capacity > capacity_) grow(capacity); @@ -352,19 +571,23 @@ class Buffer { } /** Appends data to the end of the buffer. */ - void append(const T *begin, const T *end); + template <typename U> + void append(const U *begin, const U *end); T &operator[](std::size_t index) { return ptr_[index]; } const T &operator[](std::size_t index) const { return ptr_[index]; } }; template <typename T> -void Buffer<T>::append(const T *begin, const T *end) { - std::ptrdiff_t num_elements = end - begin; - if (size_ + num_elements > capacity_) - grow(size_ + num_elements); - std::copy(begin, end, internal::make_ptr(ptr_, capacity_) + size_); - size_ += num_elements; +template <typename U> +void Buffer<T>::append(const U *begin, const U *end) { + assert(begin <= end); + std::size_t new_size = size_ + (end - begin); + if (new_size > capacity_) + grow(new_size); + std::uninitialized_copy(begin, end, + internal::make_ptr(ptr_, capacity_) + size_); + size_ = new_size; } namespace internal { @@ -376,9 +599,9 @@ class MemoryBuffer : private Allocator, public Buffer<T> { private: T data_[SIZE]; - // Free memory allocated by the buffer. - void free() { - if (this->ptr_ != data_) this->deallocate(this->ptr_, this->capacity_); + // Deallocate memory allocated by the buffer. + void deallocate() { + if (this->ptr_ != data_) Allocator::deallocate(this->ptr_, this->capacity_); } protected: @@ -387,7 +610,7 @@ class MemoryBuffer : private Allocator, public Buffer<T> { public: explicit MemoryBuffer(const Allocator &alloc = Allocator()) : Allocator(alloc), Buffer<T>(data_, SIZE) {} - ~MemoryBuffer() { free(); } + ~MemoryBuffer() { deallocate(); } #if FMT_USE_RVALUE_REFERENCES private: @@ -399,12 +622,12 @@ class MemoryBuffer : private Allocator, public Buffer<T> { this->capacity_ = other.capacity_; if (other.ptr_ == other.data_) { this->ptr_ = data_; - std::copy(other.data_, - other.data_ + this->size_, make_ptr(data_, this->capacity_)); + std::uninitialized_copy(other.data_, other.data_ + this->size_, + make_ptr(data_, this->capacity_)); } else { this->ptr_ = other.ptr_; // Set pointer to the inline array so that delete is not called - // when freeing. + // when deallocating. other.ptr_ = other.data_; } } @@ -416,7 +639,7 @@ class MemoryBuffer : private Allocator, public Buffer<T> { MemoryBuffer &operator=(MemoryBuffer &&other) { assert(this != &other); - free(); + deallocate(); move(other); return *this; } @@ -428,12 +651,13 @@ class MemoryBuffer : private Allocator, public Buffer<T> { template <typename T, std::size_t SIZE, typename Allocator> void MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t size) { - std::size_t new_capacity = - (std::max)(size, this->capacity_ + this->capacity_ / 2); + std::size_t new_capacity = this->capacity_ + this->capacity_ / 2; + if (size > new_capacity) + new_capacity = size; T *new_ptr = this->allocate(new_capacity); // The following code doesn't throw, so the raw pointer above doesn't leak. - std::copy(this->ptr_, - this->ptr_ + this->size_, make_ptr(new_ptr, new_capacity)); + std::uninitialized_copy(this->ptr_, this->ptr_ + this->size_, + make_ptr(new_ptr, new_capacity)); std::size_t old_capacity = this->capacity_; T *old_ptr = this->ptr_; this->capacity_ = new_capacity; @@ -442,7 +666,7 @@ void MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t size) { // the buffer already uses the new storage and will deallocate it in case // of exception. if (old_ptr != data_) - this->deallocate(old_ptr, old_capacity); + Allocator::deallocate(old_ptr, old_capacity); } // A fixed-size buffer. @@ -455,47 +679,15 @@ class FixedBuffer : public fmt::Buffer<Char> { void grow(std::size_t size); }; -#ifndef _MSC_VER -// Portable version of signbit. -inline int getsign(double x) { - // When compiled in C++11 mode signbit is no longer a macro but a function - // defined in namespace std and the macro is undefined. -# ifdef signbit - return signbit(x); -# else - return std::signbit(x); -# endif -} - -// Portable version of isinf. -# ifdef isinf -inline int isinfinity(double x) { return isinf(x); } -inline int isinfinity(long double x) { return isinf(x); } -# else -inline int isinfinity(double x) { return std::isinf(x); } -inline int isinfinity(long double x) { return std::isinf(x); } -# endif -#else -inline int getsign(double value) { - if (value < 0) return 1; - if (value == value) return 0; - int dec = 0, sign = 0; - char buffer[2]; // The buffer size must be >= 2 or _ecvt_s will fail. - _ecvt_s(buffer, sizeof(buffer), value, 0, &dec, &sign); - return sign; -} -inline int isinfinity(double x) { return !_finite(x); } -inline int isinfinity(long double x) { return !_finite(static_cast<double>(x)); } -#endif - template <typename Char> class BasicCharTraits { public: -#if _SECURE_SCL +#if FMT_SECURE_SCL typedef stdext::checked_array_iterator<Char*> CharPtr; #else typedef Char *CharPtr; #endif + static Char cast(int value) { return static_cast<Char>(value); } }; template <typename Char> @@ -507,7 +699,7 @@ class CharTraits<char> : public BasicCharTraits<char> { // Conversion from wchar_t to char is not allowed. static char convert(wchar_t); -public: + public: static char convert(char value) { return value; } // Formats a floating-point number. @@ -636,27 +828,34 @@ inline unsigned count_digits(uint32_t n) { // Formats a decimal unsigned integer value writing into buffer. template <typename UInt, typename Char> inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) { - --num_digits; + buffer += num_digits; while (value >= 100) { // Integer division is slow so do it for a group of two digits instead // of for every digit. The idea comes from the talk by Alexandrescu // "Three Optimization Tips for C++". See speed-test for a comparison. - unsigned index = (value % 100) * 2; + unsigned index = static_cast<unsigned>((value % 100) * 2); value /= 100; - buffer[num_digits] = Data::DIGITS[index + 1]; - buffer[num_digits - 1] = Data::DIGITS[index]; - num_digits -= 2; + *--buffer = Data::DIGITS[index + 1]; + *--buffer = Data::DIGITS[index]; } if (value < 10) { - *buffer = static_cast<char>('0' + value); + *--buffer = static_cast<char>('0' + value); return; } unsigned index = static_cast<unsigned>(value * 2); - buffer[1] = Data::DIGITS[index + 1]; - buffer[0] = Data::DIGITS[index]; + *--buffer = Data::DIGITS[index + 1]; + *--buffer = Data::DIGITS[index]; } -#ifdef _WIN32 +#ifndef _WIN32 +# define FMT_USE_WINDOWS_H 0 +#elif !defined(FMT_USE_WINDOWS_H) +# define FMT_USE_WINDOWS_H 1 +#endif + +// Define FMT_USE_WINDOWS_H to 0 to disable use of windows.h. +// All the functionality that relies on it will be disabled too. +#if FMT_USE_WINDOWS_H // A converter from UTF-8 to UTF-16. // It is only provided for Windows since other systems support UTF-8 natively. class UTF8ToUTF16 { @@ -690,26 +889,16 @@ class UTF16ToUTF8 { // in case of memory allocation error. int convert(WStringRef s); }; -#endif - -void format_system_error(fmt::Writer &out, int error_code, - fmt::StringRef message) FMT_NOEXCEPT; -#ifdef _WIN32 void format_windows_error(fmt::Writer &out, int error_code, fmt::StringRef message) FMT_NOEXCEPT; #endif -// Computes max(N, 1) at compile time. It is used to avoid errors about -// allocating an array of 0 size. -template <unsigned N> -struct NonZero { - enum { VALUE = N > 0 ? N : 1 }; -}; +void format_system_error(fmt::Writer &out, int error_code, + fmt::StringRef message) FMT_NOEXCEPT; -// A formatting argument. It is a POD type to allow storage in -// internal::MemoryBuffer. -struct Arg { +// A formatting argument value. +struct Value { template <typename Char> struct StringValue { const Char *value; @@ -740,59 +929,99 @@ struct Arg { }; enum Type { - NONE, + NONE, NAMED_ARG, // Integer types should go first, - INT, UINT, LONG_LONG, ULONG_LONG, CHAR, LAST_INTEGER_TYPE = CHAR, + INT, UINT, LONG_LONG, ULONG_LONG, BOOL, CHAR, LAST_INTEGER_TYPE = CHAR, // followed by floating-point types. DOUBLE, LONG_DOUBLE, LAST_NUMERIC_TYPE = LONG_DOUBLE, CSTRING, STRING, WSTRING, POINTER, CUSTOM }; +}; + +// A formatting argument. It is a POD type to allow storage in +// internal::MemoryBuffer. +struct Arg : Value { Type type; }; +template <typename Char> +struct NamedArg; + template <typename T = void> -struct None {}; +struct Null {}; // A helper class template to enable or disable overloads taking wide // characters and strings in MakeValue. template <typename T, typename Char> struct WCharHelper { - typedef None<T> Supported; + typedef Null<T> Supported; typedef T Unsupported; }; template <typename T> struct WCharHelper<T, wchar_t> { typedef T Supported; - typedef None<T> Unsupported; + typedef Null<T> Unsupported; }; +typedef char Yes[1]; +typedef char No[2]; + +// These are non-members to workaround an overload resolution bug in bcc32. +Yes &convert(fmt::ULongLong); +Yes &convert(std::ostream &); +No &convert(...); + template <typename T> -class IsConvertibleToInt { - private: - typedef char yes[1]; - typedef char no[2]; +T &get(); - static const T &get(); +struct DummyStream : std::ostream { + // Hide all operator<< overloads from std::ostream. + void operator<<(Null<>); +}; - static yes &check(fmt::ULongLong); - static no &check(...); - - public: - enum { value = (sizeof(check(get())) == sizeof(yes)) }; +No &operator<<(std::ostream &, int); + +template<typename T, bool ENABLE_CONVERSION> +struct ConvertToIntImpl { + enum { value = false }; }; -#define FMT_CONVERTIBLE_TO_INT(Type) \ +template<typename T> +struct ConvertToIntImpl<T, true> { + // Convert to int only if T doesn't have an overloaded operator<<. + enum { + value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(No) + }; +}; + +template<typename T, bool ENABLE_CONVERSION> +struct ConvertToIntImpl2 { + enum { value = false }; +}; + +template<typename T> +struct ConvertToIntImpl2<T, true> { + enum { + // Don't convert numeric types. + value = ConvertToIntImpl<T, !std::numeric_limits<T>::is_specialized>::value + }; +}; + +template<typename T> +struct ConvertToInt { + enum { enable_conversion = sizeof(convert(get<T>())) == sizeof(Yes) }; + enum { value = ConvertToIntImpl2<T, enable_conversion>::value }; +}; + +#define FMT_DISABLE_CONVERSION_TO_INT(Type) \ template <> \ - class IsConvertibleToInt<Type> { \ - public: \ - enum { value = 1 }; \ - } + struct ConvertToInt<Type> { enum { value = 0 }; } // Silence warnings about convering float to int. -FMT_CONVERTIBLE_TO_INT(float); -FMT_CONVERTIBLE_TO_INT(double); -FMT_CONVERTIBLE_TO_INT(long double); +FMT_DISABLE_CONVERSION_TO_INT(float); +FMT_DISABLE_CONVERSION_TO_INT(double); +FMT_DISABLE_CONVERSION_TO_INT(long double); template<bool B, class T = void> struct EnableIf {}; @@ -800,13 +1029,25 @@ struct EnableIf {}; template<class T> struct EnableIf<true, T> { typedef T type; }; -// A helper function to suppress bogus "conditional expression is constant" -// warnings. -inline bool check(bool value) { return value; } +template<bool B, class T, class F> +struct Conditional { typedef T type; }; + +template<class T, class F> +struct Conditional<false, T, F> { typedef F type; }; + +// For bcc32 which doesn't understand ! in template arguments. +template<bool> +struct Not { enum { value = 0 }; }; + +template<> +struct Not<false> { enum { value = 1 }; }; // Makes an Arg object from any type. -template <typename Char> +template <typename Formatter> class MakeValue : public Arg { + public: + typedef typename Formatter::Char Char; + private: // The following two methods are private to disallow formatting of // arbitrary pointers. If you want to output a pointer cast it to @@ -822,19 +1063,21 @@ class MakeValue : public Arg { // characters and strings into narrow strings as in // fmt::format("{}", L"test"); // To fix this, use a wide format string: fmt::format(L"{}", L"test"). +#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) MakeValue(typename WCharHelper<wchar_t, Char>::Unsupported); +#endif MakeValue(typename WCharHelper<wchar_t *, Char>::Unsupported); MakeValue(typename WCharHelper<const wchar_t *, Char>::Unsupported); MakeValue(typename WCharHelper<const std::wstring &, Char>::Unsupported); MakeValue(typename WCharHelper<WStringRef, Char>::Unsupported); void set_string(StringRef str) { - string.value = str.c_str(); + string.value = str.data(); string.size = str.size(); } void set_string(WStringRef str) { - wstring.value = str.c_str(); + wstring.value = str.data(); wstring.size = str.size(); } @@ -842,7 +1085,7 @@ class MakeValue : public Arg { template <typename T> static void format_custom_arg( void *formatter, const void *arg, void *format_str_ptr) { - format(*static_cast<BasicFormatter<Char>*>(formatter), + format(*static_cast<Formatter*>(formatter), *static_cast<const Char**>(format_str_ptr), *static_cast<const T*>(arg)); } @@ -850,11 +1093,14 @@ class MakeValue : public Arg { public: MakeValue() {} -#define FMT_MAKE_VALUE(Type, field, TYPE) \ - MakeValue(Type value) { field = value; } \ +#define FMT_MAKE_VALUE_(Type, field, TYPE, rhs) \ + MakeValue(Type value) { field = rhs; } \ static uint64_t type(Type) { return Arg::TYPE; } - FMT_MAKE_VALUE(bool, int_value, INT) +#define FMT_MAKE_VALUE(Type, field, TYPE) \ + FMT_MAKE_VALUE_(Type, field, TYPE, value) + + FMT_MAKE_VALUE(bool, int_value, BOOL) FMT_MAKE_VALUE(short, int_value, INT) FMT_MAKE_VALUE(unsigned short, uint_value, UINT) FMT_MAKE_VALUE(int, int_value, INT) @@ -888,14 +1134,16 @@ class MakeValue : public Arg { FMT_MAKE_VALUE(float, double_value, DOUBLE) FMT_MAKE_VALUE(double, double_value, DOUBLE) FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE) - FMT_MAKE_VALUE(signed char, int_value, CHAR) - FMT_MAKE_VALUE(unsigned char, int_value, CHAR) + FMT_MAKE_VALUE(signed char, int_value, INT) + FMT_MAKE_VALUE(unsigned char, uint_value, UINT) FMT_MAKE_VALUE(char, int_value, CHAR) +#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) MakeValue(typename WCharHelper<wchar_t, Char>::Supported value) { int_value = value; } static uint64_t type(wchar_t) { return Arg::CHAR; } +#endif #define FMT_MAKE_STR_VALUE(Type, TYPE) \ MakeValue(Type value) { set_string(value); } \ @@ -907,6 +1155,7 @@ class MakeValue : public Arg { FMT_MAKE_VALUE(const unsigned char *, ustring.value, CSTRING) FMT_MAKE_STR_VALUE(const std::string &, STRING) FMT_MAKE_STR_VALUE(StringRef, STRING) + FMT_MAKE_VALUE_(CStringRef, string.value, CSTRING, value.c_str()) #define FMT_MAKE_WSTR_VALUE(Type, TYPE) \ MakeValue(typename WCharHelper<Type, Char>::Supported value) { \ @@ -924,20 +1173,42 @@ class MakeValue : public Arg { template <typename T> MakeValue(const T &value, - typename EnableIf<!IsConvertibleToInt<T>::value, int>::type = 0) { + typename EnableIf<Not< + ConvertToInt<T>::value>::value, int>::type = 0) { custom.value = &value; custom.format = &format_custom_arg<T>; } template <typename T> MakeValue(const T &value, - typename EnableIf<IsConvertibleToInt<T>::value, int>::type = 0) { + typename EnableIf<ConvertToInt<T>::value, int>::type = 0) { int_value = value; } template <typename T> static uint64_t type(const T &) { - return IsConvertibleToInt<T>::value ? Arg::INT : Arg::CUSTOM; + return ConvertToInt<T>::value ? Arg::INT : Arg::CUSTOM; + } + + // Additional template param `Char_` is needed here because make_type always + // uses char. + template <typename Char_> + MakeValue(const NamedArg<Char_> &value) { pointer = &value; } + + template <typename Char_> + static uint64_t type(const NamedArg<Char_> &) { return Arg::NAMED_ARG; } +}; + +template <typename Char> +struct NamedArg : Arg { + BasicStringRef<Char> name; + + typedef internal::MakeValue< BasicFormatter<Char> > MakeValue; + + template <typename T> + NamedArg(BasicStringRef<Char> argname, const T &value) + : Arg(MakeValue(value)), name(argname) { + type = static_cast<Arg::Type>(MakeValue::type(value)); } }; @@ -985,6 +1256,9 @@ class ArgVisitor { Result visit_ulong_long(ULongLong value) { return FMT_DISPATCH(visit_any_int(value)); } + Result visit_bool(bool value) { + return FMT_DISPATCH(visit_any_int(value)); + } Result visit_char(int value) { return FMT_DISPATCH(visit_any_int(value)); } @@ -1004,6 +1278,9 @@ class ArgVisitor { return FMT_DISPATCH(visit_unhandled_arg()); } + Result visit_cstring(const char *) { + return FMT_DISPATCH(visit_unhandled_arg()); + } Result visit_string(Arg::StringValue<char>) { return FMT_DISPATCH(visit_unhandled_arg()); } @@ -1020,7 +1297,7 @@ class ArgVisitor { Result visit(const Arg &arg) { switch (arg.type) { default: - assert(false); + FMT_ASSERT(false, "invalid argument type"); return Result(); case Arg::INT: return FMT_DISPATCH(visit_int(arg.int_value)); @@ -1030,17 +1307,16 @@ class ArgVisitor { return FMT_DISPATCH(visit_long_long(arg.long_long_value)); case Arg::ULONG_LONG: return FMT_DISPATCH(visit_ulong_long(arg.ulong_long_value)); + case Arg::BOOL: + return FMT_DISPATCH(visit_bool(arg.int_value != 0)); + case Arg::CHAR: + return FMT_DISPATCH(visit_char(arg.int_value)); case Arg::DOUBLE: return FMT_DISPATCH(visit_double(arg.double_value)); case Arg::LONG_DOUBLE: return FMT_DISPATCH(visit_long_double(arg.long_double_value)); - case Arg::CHAR: - return FMT_DISPATCH(visit_char(arg.int_value)); - case Arg::CSTRING: { - Arg::StringValue<char> str = arg.string; - str.size = 0; - return FMT_DISPATCH(visit_string(str)); - } + case Arg::CSTRING: + return FMT_DISPATCH(visit_cstring(arg.string.value)); case Arg::STRING: return FMT_DISPATCH(visit_string(arg.string)); case Arg::WSTRING: @@ -1059,7 +1335,10 @@ class RuntimeError : public std::runtime_error { }; template <typename Char> -class ArgFormatter; +class PrintfArgFormatter; + +template <typename Char> +class ArgMap; } // namespace internal /** An argument list. */ @@ -1068,7 +1347,15 @@ class ArgList { // To reduce compiled code size per formatting function call, types of first // MAX_PACKED_ARGS arguments are passed in the types_ field. uint64_t types_; - const internal::Arg *args_; + union { + // If the number of arguments is less than MAX_PACKED_ARGS, the argument + // values are stored in values_, otherwise they are stored in args_. + // This is done to reduce compiled code size as storing larger objects + // may require more code (at least on x86-64) even if the same amount of + // data is actually copied to stack. It saves ~10% on the bloat test. + const internal::Value *values_; + const internal::Arg *args_; + }; internal::Arg::Type type(unsigned index) const { unsigned shift = index * 4; @@ -1077,11 +1364,17 @@ class ArgList { (types_ & (mask << shift)) >> shift); } + template <typename Char> + friend class internal::ArgMap; + public: // Maximum number of arguments with packed types. enum { MAX_PACKED_ARGS = 16 }; ArgList() : types_(0) {} + + ArgList(ULongLong types, const internal::Value *values) + : types_(types), values_(values) {} ArgList(ULongLong types, const internal::Arg *args) : types_(types), args_(args) {} @@ -1089,14 +1382,18 @@ class ArgList { internal::Arg operator[](unsigned index) const { using internal::Arg; Arg arg; + bool use_values = type(MAX_PACKED_ARGS - 1) == Arg::NONE; if (index < MAX_PACKED_ARGS) { Arg::Type arg_type = type(index); + internal::Value &val = arg; if (arg_type != Arg::NONE) - arg = args_[index]; + val = use_values ? values_[index] : args_[index]; arg.type = arg_type; return arg; } - if (type(MAX_PACKED_ARGS - 1) == Arg::NONE) { + if (use_values) { + // The index is greater than the number of arguments that can be stored + // in values, so return a "none" argument. arg.type = Arg::NONE; return arg; } @@ -1108,80 +1405,6 @@ class ArgList { } }; -struct FormatSpec; - -namespace internal { - -class FormatterBase { - private: - ArgList args_; - int next_arg_index_; - - // Returns the argument with specified index. - Arg do_get_arg(unsigned arg_index, const char *&error); - - protected: - void set_args(const ArgList &args) { - args_ = args; - next_arg_index_ = 0; - } - - // Returns the next argument. - Arg next_arg(const char *&error); - - // Checks if manual indexing is used and returns the argument with - // specified index. - Arg get_arg(unsigned arg_index, const char *&error); - - template <typename Char> - void write(BasicWriter<Char> &w, const Char *start, const Char *end) { - if (start != end) - w << BasicStringRef<Char>(start, end - start); - } -}; - -// A printf formatter. -template <typename Char> -class PrintfFormatter : private FormatterBase { - private: - void parse_flags(FormatSpec &spec, const Char *&s); - - // Returns the argument with specified index or, if arg_index is equal - // to the maximum unsigned value, the next argument. - Arg get_arg(const Char *s, - unsigned arg_index = (std::numeric_limits<unsigned>::max)()); - - // Parses argument index, flags and width and returns the argument index. - unsigned parse_header(const Char *&s, FormatSpec &spec); - - public: - void format(BasicWriter<Char> &writer, - BasicStringRef<Char> format_str, const ArgList &args); -}; -} // namespace internal - -// A formatter. -template <typename Char> -class BasicFormatter : private internal::FormatterBase { - private: - BasicWriter<Char> &writer_; - const Char *start_; - - FMT_DISALLOW_COPY_AND_ASSIGN(BasicFormatter); - - // Parses argument index and returns corresponding argument. - internal::Arg parse_arg_index(const Char *&s); - - public: - explicit BasicFormatter(BasicWriter<Char> &w) : writer_(w) {} - - BasicWriter<Char> &writer() { return writer_; } - - void format(BasicStringRef<Char> format_str, const ArgList &args); - - const Char *format(const Char *&format_str, const internal::Arg &arg); -}; - enum Alignment { ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC }; @@ -1269,16 +1492,19 @@ class IntFormatSpec : public SpecT { }; // A string format specifier. -template <typename T> +template <typename Char> class StrFormatSpec : public AlignSpec { private: - const T *str_; + const Char *str_; public: - StrFormatSpec(const T *str, unsigned width, wchar_t fill) - : AlignSpec(width, fill), str_(str) {} + template <typename FillChar> + StrFormatSpec(const Char *str, unsigned width, FillChar fill) + : AlignSpec(width, fill), str_(str) { + internal::CharTraits<Char>::convert(FillChar()); + } - const T *str() const { return str_; } + const Char *str() const { return str_; } }; /** @@ -1400,6 +1626,242 @@ inline StrFormatSpec<wchar_t> pad( return StrFormatSpec<wchar_t>(str, width, fill); } +namespace internal { + +template <typename Char> +class ArgMap { + private: + typedef std::map<fmt::BasicStringRef<Char>, internal::Arg> MapType; + typedef typename MapType::value_type Pair; + + MapType map_; + + public: + void init(const ArgList &args); + + const internal::Arg* find(const fmt::BasicStringRef<Char> &name) const { + typename MapType::const_iterator it = map_.find(name); + return it != map_.end() ? &it->second : 0; + } +}; + +template <typename Impl, typename Char> +class ArgFormatterBase : public ArgVisitor<Impl, void> { + private: + BasicWriter<Char> &writer_; + FormatSpec &spec_; + + FMT_DISALLOW_COPY_AND_ASSIGN(ArgFormatterBase); + + void write_pointer(const void *p) { + spec_.flags_ = HASH_FLAG; + spec_.type_ = 'x'; + writer_.write_int(reinterpret_cast<uintptr_t>(p), spec_); + } + + protected: + BasicWriter<Char> &writer() { return writer_; } + FormatSpec &spec() { return spec_; } + + void write(bool value) { + const char *str_value = value ? "true" : "false"; + Arg::StringValue<char> str = { str_value, std::strlen(str_value) }; + writer_.write_str(str, spec_); + } + + void write(const char *value) { + Arg::StringValue<char> str = {value, value != 0 ? std::strlen(value) : 0}; + writer_.write_str(str, spec_); + } + + public: + ArgFormatterBase(BasicWriter<Char> &w, FormatSpec &s) + : writer_(w), spec_(s) {} + + template <typename T> + void visit_any_int(T value) { writer_.write_int(value, spec_); } + + template <typename T> + void visit_any_double(T value) { writer_.write_double(value, spec_); } + + void visit_bool(bool value) { + if (spec_.type_) + return visit_any_int(value); + write(value); + } + + void visit_char(int value) { + if (spec_.type_ && spec_.type_ != 'c') { + spec_.flags_ |= CHAR_FLAG; + writer_.write_int(value, spec_); + return; + } + if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0) + FMT_THROW(FormatError("invalid format specifier for char")); + typedef typename BasicWriter<Char>::CharPtr CharPtr; + Char fill = internal::CharTraits<Char>::cast(spec_.fill()); + CharPtr out = CharPtr(); + const unsigned CHAR_WIDTH = 1; + if (spec_.width_ > CHAR_WIDTH) { + out = writer_.grow_buffer(spec_.width_); + if (spec_.align_ == ALIGN_RIGHT) { + std::uninitialized_fill_n(out, spec_.width_ - CHAR_WIDTH, fill); + out += spec_.width_ - CHAR_WIDTH; + } else if (spec_.align_ == ALIGN_CENTER) { + out = writer_.fill_padding(out, spec_.width_, + internal::check(CHAR_WIDTH), fill); + } else { + std::uninitialized_fill_n(out + CHAR_WIDTH, + spec_.width_ - CHAR_WIDTH, fill); + } + } else { + out = writer_.grow_buffer(CHAR_WIDTH); + } + *out = internal::CharTraits<Char>::cast(value); + } + + void visit_cstring(const char *value) { + if (spec_.type_ == 'p') + return write_pointer(value); + write(value); + } + + void visit_string(Arg::StringValue<char> value) { + writer_.write_str(value, spec_); + } + + using ArgVisitor<Impl, void>::visit_wstring; + + void visit_wstring(Arg::StringValue<Char> value) { + writer_.write_str(value, spec_); + } + + void visit_pointer(const void *value) { + if (spec_.type_ && spec_.type_ != 'p') + report_unknown_type(spec_.type_, "pointer"); + write_pointer(value); + } +}; + +// An argument formatter. +template <typename Char> +class BasicArgFormatter : + public ArgFormatterBase<BasicArgFormatter<Char>, Char> { + private: + BasicFormatter<Char> &formatter_; + const Char *format_; + + public: + BasicArgFormatter(BasicFormatter<Char> &f, FormatSpec &s, const Char *fmt) + : ArgFormatterBase<BasicArgFormatter<Char>, Char>(f.writer(), s), + formatter_(f), format_(fmt) {} + + void visit_custom(Arg::CustomValue c) { + c.format(&formatter_, c.value, &format_); + } +}; + +class FormatterBase { + private: + ArgList args_; + int next_arg_index_; + + // Returns the argument with specified index. + Arg do_get_arg(unsigned arg_index, const char *&error); + + protected: + const ArgList &args() const { return args_; } + + explicit FormatterBase(const ArgList &args) { + args_ = args; + next_arg_index_ = 0; + } + + // Returns the next argument. + Arg next_arg(const char *&error) { + if (next_arg_index_ >= 0) + return do_get_arg(next_arg_index_++, error); + error = "cannot switch from manual to automatic argument indexing"; + return Arg(); + } + + // Checks if manual indexing is used and returns the argument with + // specified index. + Arg get_arg(unsigned arg_index, const char *&error) { + return check_no_auto_index(error) ? do_get_arg(arg_index, error) : Arg(); + } + + bool check_no_auto_index(const char *&error) { + if (next_arg_index_ > 0) { + error = "cannot switch from automatic to manual argument indexing"; + return false; + } + next_arg_index_ = -1; + return true; + } + + template <typename Char> + void write(BasicWriter<Char> &w, const Char *start, const Char *end) { + if (start != end) + w << BasicStringRef<Char>(start, end - start); + } +}; + +// A printf formatter. +template <typename Char> +class PrintfFormatter : private FormatterBase { + private: + void parse_flags(FormatSpec &spec, const Char *&s); + + // Returns the argument with specified index or, if arg_index is equal + // to the maximum unsigned value, the next argument. + Arg get_arg(const Char *s, + unsigned arg_index = (std::numeric_limits<unsigned>::max)()); + + // Parses argument index, flags and width and returns the argument index. + unsigned parse_header(const Char *&s, FormatSpec &spec); + + public: + explicit PrintfFormatter(const ArgList &args) : FormatterBase(args) {} + void format(BasicWriter<Char> &writer, BasicCStringRef<Char> format_str); +}; +} // namespace internal + +// A formatter. +template <typename CharType> +class BasicFormatter : private internal::FormatterBase { + public: + typedef CharType Char; + + private: + BasicWriter<Char> &writer_; + internal::ArgMap<Char> map_; + + FMT_DISALLOW_COPY_AND_ASSIGN(BasicFormatter); + + using internal::FormatterBase::get_arg; + + // Checks if manual indexing is used and returns the argument with + // specified name. + internal::Arg get_arg(BasicStringRef<Char> arg_name, const char *&error); + + // Parses argument index and returns corresponding argument. + internal::Arg parse_arg_index(const Char *&s); + + // Parses argument name and returns corresponding argument. + internal::Arg parse_arg_name(const Char *&s); + + public: + BasicFormatter(const ArgList &args, BasicWriter<Char> &w) + : internal::FormatterBase(args), writer_(w) {} + + BasicWriter<Char> &writer() { return writer_; } + + void format(BasicCStringRef<Char> format_str); + + const Char *format(const Char *&format_str, const internal::Arg &arg); +}; + // Generates a comma-separated list with results of applying f to // numbers 0..n-1. # define FMT_GEN(n, f) FMT_GEN##n(f) @@ -1423,13 +1885,69 @@ namespace internal { inline uint64_t make_type() { return 0; } template <typename T> -inline uint64_t make_type(const T &arg) { return MakeValue<char>::type(arg); } +inline uint64_t make_type(const T &arg) { + return MakeValue< BasicFormatter<char> >::type(arg); +} + +template <unsigned N> +struct ArgArray { + // Computes the argument array size by adding 1 to N, which is the number of + // arguments, if N is zero, because array of zero size is invalid, or if N + // is greater than ArgList::MAX_PACKED_ARGS to accommodate for an extra + // argument that marks the end of the list. + enum { SIZE = N + (N == 0 || N >= ArgList::MAX_PACKED_ARGS ? 1 : 0) }; + + typedef typename Conditional< + (N < ArgList::MAX_PACKED_ARGS), Value, Arg>::type Type[SIZE]; +}; #if FMT_USE_VARIADIC_TEMPLATES template <typename Arg, typename... Args> inline uint64_t make_type(const Arg &first, const Args & ... tail) { return make_type(first) | (make_type(tail...) << 4); } + +inline void do_set_types(Arg *) {} + +template <typename T, typename... Args> +inline void do_set_types(Arg *args, const T &arg, const Args & ... tail) { + args->type = static_cast<Arg::Type>( + MakeValue< BasicFormatter<char> >::type(arg)); + do_set_types(args + 1, tail...); +} + +template <typename... Args> +inline void set_types(Arg *array, const Args & ... args) { + if (check(sizeof...(Args) > ArgList::MAX_PACKED_ARGS)) + do_set_types(array, args...); + array[sizeof...(Args)].type = Arg::NONE; +} + +template <typename... Args> +inline void set_types(Value *, const Args & ...) { + // Do nothing as types are passed separately from values. +} + +template <typename Formatter, typename Value> +inline void store_args(Value *) {} + +template <typename Formatter, typename Arg, typename T, typename... Args> +inline void store_args(Arg *args, const T &arg, const Args & ... tail) { + // Assign only the Value subobject of Arg and don't overwrite type (if any) + // that is assigned by set_types. + Value &value = *args; + value = MakeValue<Formatter>(arg); + store_args<Formatter>(args + 1, tail...); +} + +template <typename Formatter, typename... Args> +ArgList make_arg_list(typename ArgArray<sizeof...(Args)>::Type array, + const Args & ... args) { + if (check(sizeof...(Args) >= ArgList::MAX_PACKED_ARGS)) + set_types(array, args...); + store_args<Formatter>(array, args...); + return ArgList(make_type(args...), array); +} #else struct ArgType { @@ -1450,41 +1968,71 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { (t12.type << 48) | (t13.type << 52) | (t14.type << 56); } #endif + +template <class Char> +class FormatBuf : public std::basic_streambuf<Char> { + private: + typedef typename std::basic_streambuf<Char>::int_type int_type; + typedef typename std::basic_streambuf<Char>::traits_type traits_type; + + Buffer<Char> &buffer_; + Char *start_; + + public: + FormatBuf(Buffer<Char> &buffer) : buffer_(buffer), start_(&buffer[0]) { + this->setp(start_, start_ + buffer_.capacity()); + } + + int_type overflow(int_type ch = traits_type::eof()) { + if (!traits_type::eq_int_type(ch, traits_type::eof())) { + size_t size = this->pptr() - start_; + buffer_.resize(size); + buffer_.reserve(size * 2); + + start_ = &buffer_[0]; + start_[size] = traits_type::to_char_type(ch); + this->setp(start_+ size + 1, start_ + size * 2); + } + return ch; + } + + size_t size() const { + return this->pptr() - start_; + } +}; } // namespace internal # define FMT_MAKE_TEMPLATE_ARG(n) typename T##n # define FMT_MAKE_ARG_TYPE(n) T##n # define FMT_MAKE_ARG(n) const T##n &v##n -# define FMT_MAKE_REF_char(n) fmt::internal::MakeValue<char>(v##n) -# define FMT_MAKE_REF_wchar_t(n) fmt::internal::MakeValue<wchar_t>(v##n) +# define FMT_ASSIGN_char(n) \ + arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<char> >(v##n) +# define FMT_ASSIGN_wchar_t(n) \ + arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<wchar_t> >(v##n) #if FMT_USE_VARIADIC_TEMPLATES // Defines a variadic function returning void. # define FMT_VARIADIC_VOID(func, arg_type) \ template <typename... Args> \ - void func(arg_type arg1, const Args & ... args) { \ - const fmt::internal::Arg array[ \ - fmt::internal::NonZero<sizeof...(Args)>::VALUE] = { \ - fmt::internal::MakeValue<Char>(args)... \ - }; \ - func(arg1, ArgList(fmt::internal::make_type(args...), array)); \ + void func(arg_type arg0, const Args & ... args) { \ + typename fmt::internal::ArgArray<sizeof...(Args)>::Type array; \ + func(arg0, fmt::internal::make_arg_list< \ + fmt::BasicFormatter<Char> >(array, args...)); \ } // Defines a variadic constructor. # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \ template <typename... Args> \ ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \ - using fmt::internal::MakeValue; \ - const fmt::internal::Arg array[ \ - fmt::internal::NonZero<sizeof...(Args)>::VALUE] = { \ - MakeValue<Char>(args)... \ - }; \ - func(arg0, arg1, ArgList(fmt::internal::make_type(args...), array)); \ + typename fmt::internal::ArgArray<sizeof...(Args)>::Type array; \ + func(arg0, arg1, fmt::internal::make_arg_list< \ + fmt::BasicFormatter<Char> >(array, args...)); \ } #else -# define FMT_MAKE_REF(n) fmt::internal::MakeValue<Char>(v##n) +# define FMT_MAKE_REF(n) \ + fmt::internal::MakeValue< fmt::BasicFormatter<Char> >(v##n) # define FMT_MAKE_REF2(n) v##n // Defines a wrapper for a function taking one argument of type arg_type @@ -1492,9 +2040,9 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { # define FMT_WRAP1(func, arg_type, n) \ template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ - const fmt::internal::Arg args[] = {FMT_GEN(n, FMT_MAKE_REF)}; \ + const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \ func(arg1, fmt::ArgList( \ - fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), args)); \ + fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \ } // Emulates a variadic function returning void on a pre-C++11 compiler. @@ -1509,9 +2057,9 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { # define FMT_CTOR(ctor, func, arg0_type, arg1_type, n) \ template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \ - const fmt::internal::Arg args[] = {FMT_GEN(n, FMT_MAKE_REF)}; \ + const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \ func(arg0, arg1, fmt::ArgList( \ - fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), args)); \ + fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \ } // Emulates a variadic constructor on a pre-C++11 compiler. @@ -1556,7 +2104,7 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { */ class SystemError : public internal::RuntimeError { private: - void init(int err_code, StringRef format_str, ArgList args); + void init(int err_code, CStringRef format_str, ArgList args); protected: int error_code_; @@ -1579,7 +2127,7 @@ class SystemError : public internal::RuntimeError { *error_code* is a system error code as given by ``errno``. If *error_code* is not a valid error code such as -1, the system message may look like "Unknown error -1" and is platform-dependent. - + **Example**:: // This throws a SystemError with the description @@ -1591,10 +2139,10 @@ class SystemError : public internal::RuntimeError { throw fmt::SystemError(errno, "cannot open file '{}'", filename); \endrst */ - SystemError(int error_code, StringRef message) { + SystemError(int error_code, CStringRef message) { init(error_code, message, ArgList()); } - FMT_VARIADIC_CTOR(SystemError, init, int, StringRef) + FMT_VARIADIC_CTOR(SystemError, init, int, CStringRef) int error_code() const { return error_code_; } }; @@ -1627,7 +2175,7 @@ class BasicWriter { typedef typename internal::CharTraits<Char>::CharPtr CharPtr; -#if _SECURE_SCL +#if FMT_SECURE_SCL // Returns pointer value. static Char *get(CharPtr p) { return p.base(); } #else @@ -1647,12 +2195,33 @@ class BasicWriter { return internal::make_ptr(&buffer_[size], n); } + // Writes an unsigned decimal integer. + template <typename UInt> + Char *write_unsigned_decimal(UInt value, unsigned prefix_size = 0) { + unsigned num_digits = internal::count_digits(value); + Char *ptr = get(grow_buffer(prefix_size + num_digits)); + internal::format_decimal(ptr + prefix_size, value, num_digits); + return ptr; + } + + // Writes a decimal integer. + template <typename Int> + void write_decimal(Int value) { + typename internal::IntTraits<Int>::MainType abs_value = value; + if (internal::is_negative(value)) { + abs_value = 0 - abs_value; + *write_unsigned_decimal(abs_value, 1) = '-'; + } else { + write_unsigned_decimal(abs_value, 0); + } + } + // Prepare a buffer for integer formatting. CharPtr prepare_int_buffer(unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size) { unsigned size = prefix_size + num_digits; CharPtr p = grow_buffer(size); - std::copy(prefix, prefix + prefix_size, p); + std::uninitialized_copy(prefix, prefix + prefix_size, p); return p + size - 1; } @@ -1670,12 +2239,11 @@ class BasicWriter { // Writes a formatted string. template <typename StrChar> - CharPtr write_str( - const StrChar *s, std::size_t size, const AlignSpec &spec); + CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec); template <typename StrChar> - void write_str( - const internal::Arg::StringValue<StrChar> &str, const FormatSpec &spec); + void write_str(const internal::Arg::StringValue<StrChar> &str, + const FormatSpec &spec); // This following methods are private to disallow writing wide characters // and strings to a char stream. If you want to print a wide string as a @@ -1694,8 +2262,10 @@ class BasicWriter { template<typename T> void append_float_length(Char *&, T) {} - friend class internal::ArgFormatter<Char>; - friend class internal::PrintfFormatter<Char>; + template <typename Impl, typename Char_> + friend class internal::ArgFormatterBase; + + friend class internal::PrintfArgFormatter<Char>; protected: /** @@ -1705,7 +2275,9 @@ class BasicWriter { public: /** + \rst Destroys a ``BasicWriter`` object. + \endrst */ virtual ~BasicWriter() {} @@ -1732,7 +2304,9 @@ class BasicWriter { } /** + \rst Returns the content of the output buffer as an `std::string`. + \endrst */ std::basic_string<Char> str() const { return std::basic_string<Char>(&buffer_[0], buffer_.size()); @@ -1741,7 +2315,7 @@ class BasicWriter { /** \rst Writes formatted data. - + *args* is an argument list representing arbitrary arguments. **Example**:: @@ -1763,29 +2337,34 @@ class BasicWriter { See also :ref:`syntax`. \endrst */ - void write(BasicStringRef<Char> format, ArgList args) { - BasicFormatter<Char>(*this).format(format, args); + void write(BasicCStringRef<Char> format, ArgList args) { + BasicFormatter<Char>(args, *this).format(format); } - FMT_VARIADIC_VOID(write, BasicStringRef<Char>) + FMT_VARIADIC_VOID(write, BasicCStringRef<Char>) BasicWriter &operator<<(int value) { - return *this << IntFormatSpec<int>(value); + write_decimal(value); + return *this; } BasicWriter &operator<<(unsigned value) { return *this << IntFormatSpec<unsigned>(value); } BasicWriter &operator<<(long value) { - return *this << IntFormatSpec<long>(value); + write_decimal(value); + return *this; } BasicWriter &operator<<(unsigned long value) { return *this << IntFormatSpec<unsigned long>(value); } BasicWriter &operator<<(LongLong value) { - return *this << IntFormatSpec<LongLong>(value); + write_decimal(value); + return *this; } /** + \rst Formats *value* and writes it to the stream. + \endrst */ BasicWriter &operator<<(ULongLong value) { return *this << IntFormatSpec<ULongLong>(value); @@ -1797,8 +2376,10 @@ class BasicWriter { } /** + \rst Formats *value* using the general format for floating-point numbers (``'g'``) and writes it to the stream. + \endrst */ BasicWriter &operator<<(long double value) { write_double(value, FormatSpec()); @@ -1820,10 +2401,19 @@ class BasicWriter { } /** + \rst Writes *value* to the stream. + \endrst */ BasicWriter &operator<<(fmt::BasicStringRef<Char> value) { - const Char *str = value.c_str(); + const Char *str = value.data(); + buffer_.append(str, str + value.size()); + return *this; + } + + BasicWriter &operator<<( + typename internal::WCharHelper<StringRef, Char>::Supported value) { + const char *str = value.data(); buffer_.append(str, str + value.size()); return *this; } @@ -1838,7 +2428,6 @@ class BasicWriter { template <typename StrChar> BasicWriter &operator<<(const StrFormatSpec<StrChar> &spec) { const StrChar *s = spec.str(); - // TODO: error if fill is not convertible to Char write_str(s, std::char_traits<Char>::length(s), spec); return *this; } @@ -1853,34 +2442,57 @@ typename BasicWriter<Char>::CharPtr BasicWriter<Char>::write_str( CharPtr out = CharPtr(); if (spec.width() > size) { out = grow_buffer(spec.width()); - Char fill = static_cast<Char>(spec.fill()); + Char fill = internal::CharTraits<Char>::cast(spec.fill()); if (spec.align() == ALIGN_RIGHT) { - std::fill_n(out, spec.width() - size, fill); + std::uninitialized_fill_n(out, spec.width() - size, fill); out += spec.width() - size; } else if (spec.align() == ALIGN_CENTER) { out = fill_padding(out, spec.width(), size, fill); } else { - std::fill_n(out + size, spec.width() - size, fill); + std::uninitialized_fill_n(out + size, spec.width() - size, fill); } } else { out = grow_buffer(size); } - std::copy(s, s + size, out); + std::uninitialized_copy(s, s + size, out); return out; } template <typename Char> +template <typename StrChar> +void BasicWriter<Char>::write_str( + const internal::Arg::StringValue<StrChar> &s, const FormatSpec &spec) { + // Check if StrChar is convertible to Char. + internal::CharTraits<Char>::convert(StrChar()); + if (spec.type_ && spec.type_ != 's') + internal::report_unknown_type(spec.type_, "string"); + const StrChar *str_value = s.value; + std::size_t str_size = s.size; + if (str_size == 0) { + if (!str_value) { + FMT_THROW(FormatError("string pointer is null")); + return; + } + } + std::size_t precision = spec.precision_; + if (spec.precision_ >= 0 && precision < str_size) + str_size = spec.precision_; + write_str(str_value, str_size, spec); +} + +template <typename Char> typename BasicWriter<Char>::CharPtr BasicWriter<Char>::fill_padding( CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill) { std::size_t padding = total_size - content_size; std::size_t left_padding = padding / 2; - Char fill_char = static_cast<Char>(fill); - std::fill_n(buffer, left_padding, fill_char); + Char fill_char = internal::CharTraits<Char>::cast(fill); + std::uninitialized_fill_n(buffer, left_padding, fill_char); buffer += left_padding; CharPtr content = buffer; - std::fill_n(buffer + content_size, padding - left_padding, fill_char); + std::uninitialized_fill_n(buffer + content_size, + padding - left_padding, fill_char); return content; } @@ -1892,7 +2504,7 @@ typename BasicWriter<Char>::CharPtr const char *prefix, unsigned prefix_size) { unsigned width = spec.width(); Alignment align = spec.align(); - Char fill = static_cast<Char>(spec.fill()); + Char fill = internal::CharTraits<Char>::cast(spec.fill()); if (spec.precision() > static_cast<int>(num_digits)) { // Octal prefix '0' is counted as a digit, so ignore it if precision // is specified. @@ -1906,42 +2518,42 @@ typename BasicWriter<Char>::CharPtr unsigned fill_size = width - number_size; if (align != ALIGN_LEFT) { CharPtr p = grow_buffer(fill_size); - std::fill(p, p + fill_size, fill); + std::uninitialized_fill(p, p + fill_size, fill); } CharPtr result = prepare_int_buffer( num_digits, subspec, prefix, prefix_size); if (align == ALIGN_LEFT) { CharPtr p = grow_buffer(fill_size); - std::fill(p, p + fill_size, fill); + std::uninitialized_fill(p, p + fill_size, fill); } return result; } unsigned size = prefix_size + num_digits; if (width <= size) { CharPtr p = grow_buffer(size); - std::copy(prefix, prefix + prefix_size, p); + std::uninitialized_copy(prefix, prefix + prefix_size, p); return p + size - 1; } CharPtr p = grow_buffer(width); CharPtr end = p + width; if (align == ALIGN_LEFT) { - std::copy(prefix, prefix + prefix_size, p); + std::uninitialized_copy(prefix, prefix + prefix_size, p); p += size; - std::fill(p, end, fill); + std::uninitialized_fill(p, end, fill); } else if (align == ALIGN_CENTER) { p = fill_padding(p, width, size, fill); - std::copy(prefix, prefix + prefix_size, p); + std::uninitialized_copy(prefix, prefix + prefix_size, p); p += size; } else { if (align == ALIGN_NUMERIC) { if (prefix_size != 0) { - p = std::copy(prefix, prefix + prefix_size, p); + p = std::uninitialized_copy(prefix, prefix + prefix_size, p); size -= prefix_size; } } else { - std::copy(prefix, prefix + prefix_size, end - size); + std::uninitialized_copy(prefix, prefix + prefix_size, end - size); } - std::fill(p, end - size, fill); + std::uninitialized_fill(p, end - size, fill); p = end; } return p - 1; @@ -2003,7 +2615,7 @@ void BasicWriter<Char>::write_int(T value, Spec spec) { Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size)); n = abs_value; do { - *p-- = '0' + (n & 1); + *p-- = static_cast<Char>('0' + (n & 1)); } while ((n >>= 1) != 0); break; } @@ -2018,7 +2630,7 @@ void BasicWriter<Char>::write_int(T value, Spec spec) { Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size)); n = abs_value; do { - *p-- = '0' + (n & 7); + *p-- = static_cast<Char>('0' + (n & 7)); } while ((n >>= 3) != 0); break; } @@ -2057,16 +2669,16 @@ void BasicWriter<Char>::write_double( } char sign = 0; - // Use getsign instead of value < 0 because the latter is always + // Use isnegative instead of value < 0 because the latter is always // false for NaN. - if (internal::getsign(static_cast<double>(value))) { + if (internal::FPUtil::isnegative(static_cast<double>(value))) { sign = '-'; value = -value; } else if (spec.flag(SIGN_FLAG)) { sign = spec.flag(PLUS_FLAG) ? '+' : ' '; } - if (value != value) { + if (internal::FPUtil::isnotanumber(value)) { // Format NaN ourselves because sprintf's output is not consistent // across platforms. std::size_t nan_size = 4; @@ -2081,7 +2693,7 @@ void BasicWriter<Char>::write_double( return; } - if (internal::isinfinity(value)) { + if (internal::FPUtil::isinfinity(value)) { // Format infinity ourselves because sprintf's output is not consistent // across platforms. std::size_t inf_size = 4; @@ -2099,7 +2711,7 @@ void BasicWriter<Char>::write_double( std::size_t offset = buffer_.size(); unsigned width = spec.width(); if (sign) { - buffer_.reserve(buffer_.size() + (std::max)(width, 1u)); + buffer_.reserve(buffer_.size() + (width > 1u ? width : 1u)); if (width > 0) --width; ++offset; @@ -2131,10 +2743,10 @@ void BasicWriter<Char>::write_double( *format_ptr = '\0'; // Format using snprintf. - Char fill = static_cast<Char>(spec.fill()); + Char fill = internal::CharTraits<Char>::cast(spec.fill()); for (;;) { std::size_t buffer_size = buffer_.capacity() - offset; -#if _MSC_VER +#ifdef _MSC_VER // MSVC's vsnprintf_s doesn't work with zero size, so reserve // space for at least one extra character to make the size non-zero. // Note that the buffer's capacity will increase by more than 1. @@ -2161,7 +2773,7 @@ void BasicWriter<Char>::write_double( spec.width() > static_cast<unsigned>(n)) { width = spec.width(); CharPtr p = grow_buffer(width); - std::copy(p, p + n, p + (width - n) / 2); + std::memmove(get(p) + (width - n) / 2, get(p), n * sizeof(Char)); fill_padding(p, spec.width(), n, fill); return; } @@ -2254,7 +2866,7 @@ typedef BasicMemoryWriter<wchar_t> WMemoryWriter; This class template provides operations for formatting and writing data into a fixed-size array. For writing into a dynamically growing buffer use :class:`fmt::BasicMemoryWriter`. - + Any write method will throw ``std::runtime_error`` if the output doesn't fit into the array. @@ -2284,8 +2896,7 @@ class BasicArrayWriter : public BasicWriter<Char> { BasicArrayWriter(Char *array, std::size_t size) : BasicWriter<Char>(buffer_), buffer_(array, size) {} - // FIXME: this is temporary undocumented due to a bug in Sphinx - /* + /** \rst Constructs a :class:`fmt::BasicArrayWriter` object for *array* of the size known at compile time. @@ -2302,12 +2913,16 @@ typedef BasicArrayWriter<wchar_t> WArrayWriter; // Formats a value. template <typename Char, typename T> void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) { - std::basic_ostringstream<Char> os; - os << value; - std::basic_string<Char> str = os.str(); - internal::Arg arg = internal::MakeValue<Char>(str); - arg.type = static_cast<internal::Arg::Type>( - internal::MakeValue<Char>::type(str)); + internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer; + + internal::FormatBuf<Char> format_buf(buffer); + std::basic_ostream<Char> output(&format_buf); + output << value; + + BasicStringRef<Char> str(&buffer[0], format_buf.size()); + typedef internal::MakeValue< BasicFormatter<Char> > MakeValue; + internal::Arg arg = MakeValue(str); + arg.type = static_cast<internal::Arg::Type>(MakeValue::type(str)); format_str = f.format(format_str, arg); } @@ -2315,12 +2930,12 @@ void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) { // Can be used to report errors from destructors. void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT; -#ifdef _WIN32 +#if FMT_USE_WINDOWS_H /** A Windows error. */ class WindowsError : public SystemError { private: - void init(int error_code, StringRef format_str, ArgList args); + void init(int error_code, CStringRef format_str, ArgList args); public: /** @@ -2351,10 +2966,10 @@ class WindowsError : public SystemError { } \endrst */ - WindowsError(int error_code, StringRef message) { + WindowsError(int error_code, CStringRef message) { init(error_code, message, ArgList()); } - FMT_VARIADIC_CTOR(WindowsError, init, int, StringRef) + FMT_VARIADIC_CTOR(WindowsError, init, int, CStringRef) }; // Reports a Windows error without throwing an exception. @@ -2369,9 +2984,9 @@ enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE }; Formats a string and prints it to stdout using ANSI escape sequences to specify color (experimental). Example: - PrintColored(fmt::RED, "Elapsed time: {0:.2f} seconds") << 1.23; + print_colored(fmt::RED, "Elapsed time: {0:.2f} seconds", 1.23); */ -void print_colored(Color c, StringRef format, ArgList args); +void print_colored(Color c, CStringRef format, ArgList args); /** \rst @@ -2382,13 +2997,13 @@ void print_colored(Color c, StringRef format, ArgList args); std::string message = format("The answer is {}", 42); \endrst */ -inline std::string format(StringRef format_str, ArgList args) { +inline std::string format(CStringRef format_str, ArgList args) { MemoryWriter w; w.write(format_str, args); return w.str(); } -inline std::wstring format(WStringRef format_str, ArgList args) { +inline std::wstring format(WCStringRef format_str, ArgList args) { WMemoryWriter w; w.write(format_str, args); return w.str(); @@ -2403,7 +3018,7 @@ inline std::wstring format(WStringRef format_str, ArgList args) { print(stderr, "Don't {}!", "panic"); \endrst */ -void print(std::FILE *f, StringRef format_str, ArgList args); +void print(std::FILE *f, CStringRef format_str, ArgList args); /** \rst @@ -2414,22 +3029,11 @@ void print(std::FILE *f, StringRef format_str, ArgList args); print("Elapsed time: {0:.2f} seconds", 1.23); \endrst */ -void print(StringRef format_str, ArgList args); - -/** - \rst - Prints formatted data to the stream *os*. - - **Example**:: - - print(cerr, "Don't {}!", "panic"); - \endrst - */ -void print(std::ostream &os, StringRef format_str, ArgList args); +void print(CStringRef format_str, ArgList args); template <typename Char> -void printf(BasicWriter<Char> &w, BasicStringRef<Char> format, ArgList args) { - internal::PrintfFormatter<Char>().format(w, format, args); +void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) { + internal::PrintfFormatter<Char>(args).format(w, format); } /** @@ -2441,12 +3045,18 @@ void printf(BasicWriter<Char> &w, BasicStringRef<Char> format, ArgList args) { std::string message = fmt::sprintf("The answer is %d", 42); \endrst */ -inline std::string sprintf(StringRef format, ArgList args) { +inline std::string sprintf(CStringRef format, ArgList args) { MemoryWriter w; printf(w, format, args); return w.str(); } +inline std::wstring sprintf(WCStringRef format, ArgList args) { + WMemoryWriter w; + printf(w, format, args); + return w.str(); +} + /** \rst Prints formatted data to the file *f*. @@ -2456,7 +3066,7 @@ inline std::string sprintf(StringRef format, ArgList args) { fmt::fprintf(stderr, "Don't %s!", "panic"); \endrst */ -int fprintf(std::FILE *f, StringRef format, ArgList args); +int fprintf(std::FILE *f, CStringRef format, ArgList args); /** \rst @@ -2467,7 +3077,7 @@ int fprintf(std::FILE *f, StringRef format, ArgList args); fmt::printf("Elapsed time: %.2f seconds", 1.23); \endrst */ -inline int printf(StringRef format, ArgList args) { +inline int printf(CStringRef format, ArgList args) { return fprintf(stdout, format, args); } @@ -2489,7 +3099,7 @@ class FormatInt { // Integer division is slow so do it for a group of two digits instead // of for every digit. The idea comes from the talk by Alexandrescu // "Three Optimization Tips for C++". See speed-test for a comparison. - unsigned index = (value % 100) * 2; + unsigned index = static_cast<unsigned>((value % 100) * 2); value /= 100; *--buffer_end = internal::Data::DIGITS[index + 1]; *--buffer_end = internal::Data::DIGITS[index]; @@ -2543,7 +3153,9 @@ class FormatInt { } /** - Returns the content of the output buffer as an `std::string`. + \rst + Returns the content of the output buffer as an ``std::string``. + \endrst */ std::string str() const { return std::string(str_, size()); } }; @@ -2572,6 +3184,33 @@ inline void format_decimal(char *&buffer, T value) { internal::format_decimal(buffer, abs_value, num_digits); buffer += num_digits; } + +/** + \rst + Returns a named argument for formatting functions. + + **Example**:: + + print("Elapsed time: {s:.2f} seconds", arg("s", 1.23)); + + \endrst + */ +template <typename T> +inline internal::NamedArg<char> arg(StringRef name, const T &arg) { + return internal::NamedArg<char>(name, arg); +} + +template <typename T> +inline internal::NamedArg<wchar_t> arg(WStringRef name, const T &arg) { + return internal::NamedArg<wchar_t>(name, arg); +} + +// The following two functions are deleted intentionally to disable +// nested named arguments as in ``format("{}", arg("a", arg("b", 42)))``. +template <typename Char> +void arg(StringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED; +template <typename Char> +void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED; } #if FMT_GCC_VERSION @@ -2602,46 +3241,14 @@ inline void format_decimal(char *&buffer, T value) { #define FMT_GET_ARG_NAME(type, index) arg##index #if FMT_USE_VARIADIC_TEMPLATES - -namespace fmt { -namespace internal { -inline void do_set_types(Arg *) {} - -template <typename T, typename... Args> -inline void do_set_types(Arg *args, const T &arg, const Args & ... tail) { - args->type = static_cast<Arg::Type>(MakeValue<T>::type(arg)); - do_set_types(args + 1, tail...); -} - -template <typename... Args> -inline void set_types(Arg *array, const Args & ... args) { - do_set_types(array, args...); - array[sizeof...(Args)].type = Arg::NONE; -} - -// Computes the argument array size by adding 1 to N, which is the number of -// arguments, if N is zero, because array of zero size is invalid, or if N -// is greater than ArgList::MAX_PACKED_ARGS to accommodate for an extra -// argument that marks the end of the list. -template <unsigned N> -struct ArgArraySize { - enum { VALUE = N + (N == 0 || N > ArgList::MAX_PACKED_ARGS ? 1 : 0) }; -}; -} -} - # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \ template <typename... Args> \ ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ const Args & ... args) { \ - using fmt::internal::Arg; \ - Arg array[fmt::internal::ArgArraySize<sizeof...(Args)>::VALUE] = { \ - fmt::internal::MakeValue<Char>(args)... \ - }; \ - if (fmt::internal::check((sizeof...(Args) > fmt::ArgList::MAX_PACKED_ARGS))) \ - set_types(array, args...); \ + typename fmt::internal::ArgArray<sizeof...(Args)>::Type array; \ call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \ - fmt::ArgList(fmt::internal::make_type(args...), array)); \ + fmt::internal::make_arg_list< \ + fmt::BasicFormatter<Char> >(array, args...)); \ } #else // Defines a wrapper for a function taking __VA_ARGS__ arguments @@ -2650,9 +3257,10 @@ struct ArgArraySize { template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \ inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \ FMT_GEN(n, FMT_MAKE_ARG)) { \ - const fmt::internal::Arg args[] = {FMT_GEN(n, FMT_MAKE_REF_##Char)}; \ + fmt::internal::ArgArray<n>::Type arr; \ + FMT_GEN(n, FMT_ASSIGN_##Char); \ call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList( \ - fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), args)); \ + fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), arr)); \ } # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \ @@ -2709,24 +3317,405 @@ struct ArgArraySize { #define FMT_VARIADIC_W(ReturnType, func, ...) \ FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__) +#define FMT_CAPTURE_ARG_(id, index) ::fmt::arg(#id, id) + +#define FMT_CAPTURE_ARG_W_(id, index) ::fmt::arg(L###id, id) + +/** + \rst + Convenient macro to capture the arguments' names and values into several + ``fmt::arg(name, value)``. + + **Example**:: + + int x = 1, y = 2; + print("point: ({x}, {y})", FMT_CAPTURE(x, y)); + // same as: + // print("point: ({x}, {y})", arg("x", x), arg("y", y)); + + \endrst + */ +#define FMT_CAPTURE(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_, __VA_ARGS__) + +#define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__) + namespace fmt { -FMT_VARIADIC(std::string, format, StringRef) -FMT_VARIADIC_W(std::wstring, format, WStringRef) -FMT_VARIADIC(void, print, StringRef) -FMT_VARIADIC(void, print, std::FILE *, StringRef) -FMT_VARIADIC(void, print, std::ostream &, StringRef) -FMT_VARIADIC(void, print_colored, Color, StringRef) -FMT_VARIADIC(std::string, sprintf, StringRef) -FMT_VARIADIC(int, printf, StringRef) -FMT_VARIADIC(int, fprintf, std::FILE *, StringRef) +FMT_VARIADIC(std::string, format, CStringRef) +FMT_VARIADIC_W(std::wstring, format, WCStringRef) +FMT_VARIADIC(void, print, CStringRef) +FMT_VARIADIC(void, print, std::FILE *, CStringRef) + +FMT_VARIADIC(void, print_colored, Color, CStringRef) +FMT_VARIADIC(std::string, sprintf, CStringRef) +FMT_VARIADIC_W(std::wstring, sprintf, WCStringRef) +FMT_VARIADIC(int, printf, CStringRef) +FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef) + +#if FMT_USE_IOSTREAMS +/** + \rst + Prints formatted data to the stream *os*. + + **Example**:: + + print(cerr, "Don't {}!", "panic"); + \endrst + */ +void print(std::ostream &os, CStringRef format_str, ArgList args); +FMT_VARIADIC(void, print, std::ostream &, CStringRef) +#endif + +namespace internal { +template <typename Char> +inline bool is_name_start(Char c) { + return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '_' == c; +} + +// Parses an unsigned integer advancing s to the end of the parsed input. +// This function assumes that the first character of s is a digit. +template <typename Char> +int parse_nonnegative_int(const Char *&s) { + assert('0' <= *s && *s <= '9'); + unsigned value = 0; + do { + unsigned new_value = value * 10 + (*s++ - '0'); + // Check if value wrapped around. + if (new_value < value) { + value = (std::numeric_limits<unsigned>::max)(); + break; + } + value = new_value; + } while ('0' <= *s && *s <= '9'); + // Convert to unsigned to prevent a warning. + unsigned max_int = (std::numeric_limits<int>::max)(); + if (value > max_int) + FMT_THROW(FormatError("number is too big")); + return value; +} + +inline void require_numeric_argument(const Arg &arg, char spec) { + if (arg.type > Arg::LAST_NUMERIC_TYPE) { + std::string message = + fmt::format("format specifier '{}' requires numeric argument", spec); + FMT_THROW(fmt::FormatError(message)); + } +} + +template <typename Char> +void check_sign(const Char *&s, const Arg &arg) { + char sign = static_cast<char>(*s); + require_numeric_argument(arg, sign); + if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG) { + FMT_THROW(FormatError(fmt::format( + "format specifier '{}' requires signed argument", sign))); + } + ++s; +} +} // namespace internal + +template <typename Char> +inline internal::Arg BasicFormatter<Char>::get_arg( + BasicStringRef<Char> arg_name, const char *&error) { + if (check_no_auto_index(error)) { + map_.init(args()); + const internal::Arg *arg = map_.find(arg_name); + if (arg) + return *arg; + error = "argument not found"; + } + return internal::Arg(); +} + +template <typename Char> +inline internal::Arg BasicFormatter<Char>::parse_arg_index(const Char *&s) { + const char *error = 0; + internal::Arg arg = *s < '0' || *s > '9' ? + next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error); + if (error) { + FMT_THROW(FormatError( + *s != '}' && *s != ':' ? "invalid format string" : error)); + } + return arg; +} + +template <typename Char> +inline internal::Arg BasicFormatter<Char>::parse_arg_name(const Char *&s) { + assert(internal::is_name_start(*s)); + const Char *start = s; + Char c; + do { + c = *++s; + } while (internal::is_name_start(c) || ('0' <= c && c <= '9')); + const char *error = 0; + internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error); + if (error) + FMT_THROW(FormatError(error)); + return arg; } +// Should be after FormatSpec +template <typename Char> +const Char *BasicFormatter<Char>::format( + const Char *&format_str, const internal::Arg &arg) { + using internal::Arg; + const Char *s = format_str; + FormatSpec spec; + if (*s == ':') { + if (arg.type == Arg::CUSTOM) { + arg.custom.format(this, arg.custom.value, &s); + return s; + } + ++s; + // Parse fill and alignment. + if (Char c = *s) { + const Char *p = s + 1; + spec.align_ = ALIGN_DEFAULT; + do { + switch (*p) { + case '<': + spec.align_ = ALIGN_LEFT; + break; + case '>': + spec.align_ = ALIGN_RIGHT; + break; + case '=': + spec.align_ = ALIGN_NUMERIC; + break; + case '^': + spec.align_ = ALIGN_CENTER; + break; + } + if (spec.align_ != ALIGN_DEFAULT) { + if (p != s) { + if (c == '}') break; + if (c == '{') + FMT_THROW(FormatError("invalid fill character '{'")); + s += 2; + spec.fill_ = c; + } else ++s; + if (spec.align_ == ALIGN_NUMERIC) + require_numeric_argument(arg, '='); + break; + } + } while (--p >= s); + } + + // Parse sign. + switch (*s) { + case '+': + check_sign(s, arg); + spec.flags_ |= SIGN_FLAG | PLUS_FLAG; + break; + case '-': + check_sign(s, arg); + spec.flags_ |= MINUS_FLAG; + break; + case ' ': + check_sign(s, arg); + spec.flags_ |= SIGN_FLAG; + break; + } + + if (*s == '#') { + require_numeric_argument(arg, '#'); + spec.flags_ |= HASH_FLAG; + ++s; + } + + // Parse zero flag. + if (*s == '0') { + require_numeric_argument(arg, '0'); + spec.align_ = ALIGN_NUMERIC; + spec.fill_ = '0'; + ++s; + } + + // Parse width. + if ('0' <= *s && *s <= '9') { + spec.width_ = internal::parse_nonnegative_int(s); + } else if (*s == '{') { + ++s; + Arg width_arg = internal::is_name_start(*s) ? + parse_arg_name(s) : parse_arg_index(s); + if (*s++ != '}') + FMT_THROW(FormatError("invalid format string")); + ULongLong value = 0; + switch (width_arg.type) { + case Arg::INT: + if (width_arg.int_value < 0) + FMT_THROW(FormatError("negative width")); + value = width_arg.int_value; + break; + case Arg::UINT: + value = width_arg.uint_value; + break; + case Arg::LONG_LONG: + if (width_arg.long_long_value < 0) + FMT_THROW(FormatError("negative width")); + value = width_arg.long_long_value; + break; + case Arg::ULONG_LONG: + value = width_arg.ulong_long_value; + break; + default: + FMT_THROW(FormatError("width is not integer")); + } + if (value > (std::numeric_limits<int>::max)()) + FMT_THROW(FormatError("number is too big")); + spec.width_ = static_cast<int>(value); + } + + // Parse precision. + if (*s == '.') { + ++s; + spec.precision_ = 0; + if ('0' <= *s && *s <= '9') { + spec.precision_ = internal::parse_nonnegative_int(s); + } else if (*s == '{') { + ++s; + Arg precision_arg = internal::is_name_start(*s) ? + parse_arg_name(s) : parse_arg_index(s); + if (*s++ != '}') + FMT_THROW(FormatError("invalid format string")); + ULongLong value = 0; + switch (precision_arg.type) { + case Arg::INT: + if (precision_arg.int_value < 0) + FMT_THROW(FormatError("negative precision")); + value = precision_arg.int_value; + break; + case Arg::UINT: + value = precision_arg.uint_value; + break; + case Arg::LONG_LONG: + if (precision_arg.long_long_value < 0) + FMT_THROW(FormatError("negative precision")); + value = precision_arg.long_long_value; + break; + case Arg::ULONG_LONG: + value = precision_arg.ulong_long_value; + break; + default: + FMT_THROW(FormatError("precision is not integer")); + } + if (value > (std::numeric_limits<int>::max)()) + FMT_THROW(FormatError("number is too big")); + spec.precision_ = static_cast<int>(value); + } else { + FMT_THROW(FormatError("missing precision specifier")); + } + if (arg.type <= Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER) { + FMT_THROW(FormatError( + fmt::format("precision not allowed in {} format specifier", + arg.type == Arg::POINTER ? "pointer" : "integer"))); + } + } + + // Parse type. + if (*s != '}' && *s) + spec.type_ = static_cast<char>(*s++); + } + + if (*s++ != '}') + FMT_THROW(FormatError("missing '}' in format string")); + + // Format argument. + internal::BasicArgFormatter<Char>(*this, spec, s - 1).visit(arg); + return s; +} + +template <typename Char> +void BasicFormatter<Char>::format(BasicCStringRef<Char> format_str) { + const Char *s = format_str.c_str(); + const Char *start = s; + while (*s) { + Char c = *s++; + if (c != '{' && c != '}') continue; + if (*s == c) { + write(writer_, start, s); + start = ++s; + continue; + } + if (c == '}') + FMT_THROW(FormatError("unmatched '}' in format string")); + write(writer_, start, s - 1); + internal::Arg arg = internal::is_name_start(*s) ? + parse_arg_name(s) : parse_arg_index(s); + start = s = format(s, arg); + } + write(writer_, start, s); +} +} // namespace fmt + +#if FMT_USE_USER_DEFINED_LITERALS +namespace fmt { +namespace internal { + +template <typename Char> +struct UdlFormat { + const Char *str; + + template <typename... Args> + auto operator()(Args && ... args) const + -> decltype(format(str, std::forward<Args>(args)...)) { + return format(str, std::forward<Args>(args)...); + } +}; + +template <typename Char> +struct UdlArg { + const Char *str; + + template <typename T> + NamedArg<Char> operator=(T &&value) const { + return {str, std::forward<T>(value)}; + } +}; + +} // namespace internal + +inline namespace literals { + +/** + \rst + C++11 literal equivalent of :func:`fmt::format`. + + **Example**:: + + using namespace fmt::literals; + std::string message = "The answer is {}"_format(42); + \endrst + */ +inline internal::UdlFormat<char> +operator"" _format(const char *s, std::size_t) { return {s}; } +inline internal::UdlFormat<wchar_t> +operator"" _format(const wchar_t *s, std::size_t) { return {s}; } + +/** + \rst + C++11 literal equivalent of :func:`fmt::arg`. + + **Example**:: + + using namespace fmt::literals; + print("Elapsed time: {s:.2f} seconds", "s"_a=1.23); + \endrst + */ +inline internal::UdlArg<char> +operator"" _a(const char *s, std::size_t) { return {s}; } +inline internal::UdlArg<wchar_t> +operator"" _a(const wchar_t *s, std::size_t) { return {s}; } + +} // inline namespace literals +} // namespace fmt +#endif // FMT_USE_USER_DEFINED_LITERALS + // Restore warnings. #if FMT_GCC_VERSION >= 406 # pragma GCC diagnostic pop #endif -#ifdef __clang__ +#if defined(__clang__) && !defined(__INTEL_COMPILER) # pragma clang diagnostic pop #endif diff --git a/dep/cppformat/posix.cc b/dep/cppformat/posix.cc index 0efb5aff3d0..756281a0ebd 100644 --- a/dep/cppformat/posix.cc +++ b/dep/cppformat/posix.cc @@ -55,11 +55,14 @@ # ifdef __MINGW32__ # define _SH_DENYNO 0x40 -# undef fileno # endif #endif // _WIN32 +#ifdef fileno +# undef fileno +#endif + namespace { #ifdef _WIN32 // Return type of read and write functions. @@ -83,7 +86,8 @@ fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT { fmt::report_system_error(errno, "cannot close file"); } -fmt::BufferedFile::BufferedFile(fmt::StringRef filename, fmt::StringRef mode) { +fmt::BufferedFile::BufferedFile( + fmt::CStringRef filename, fmt::CStringRef mode) { FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0); if (!file_) throw SystemError(errno, "cannot open file {}", filename); @@ -108,7 +112,7 @@ int fmt::BufferedFile::fileno() const { return fd; } -fmt::File::File(fmt::StringRef path, int oflag) { +fmt::File::File(fmt::CStringRef path, int oflag) { int mode = S_IRUSR | S_IWUSR; #if defined(_WIN32) && !defined(__MINGW32__) fd_ = -1; @@ -151,8 +155,8 @@ fmt::LongLong fmt::File::size() const { if (error != NO_ERROR) throw WindowsError(GetLastError(), "cannot get file size"); } - fmt::ULongLong size = size_upper; - return (size << sizeof(DWORD) * CHAR_BIT) | size_lower; + fmt::ULongLong long_size = size_upper; + return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower; #else typedef struct stat Stat; Stat file_stat = Stat(); diff --git a/dep/cppformat/posix.h b/dep/cppformat/posix.h index 70a0db1a560..88bcb4f557b 100644 --- a/dep/cppformat/posix.h +++ b/dep/cppformat/posix.h @@ -41,10 +41,6 @@ #include "format.h" -#ifdef FMT_INCLUDE_POSIX_TEST -# include "test/posix-test.h" -#endif - #ifndef FMT_POSIX # if defined(_WIN32) && !defined(__MINGW32__) // Fix warnings about deprecated symbols. @@ -73,7 +69,11 @@ # define FMT_UNUSED #endif -#if FMT_USE_STATIC_ASSERT || FMT_HAS_CPP_ATTRIBUTE(cxx_static_assert) || \ +#ifndef FMT_USE_STATIC_ASSERT +# define FMT_USE_STATIC_ASSERT 0 +#endif + +#if FMT_USE_STATIC_ASSERT || FMT_HAS_FEATURE(cxx_static_assert) || \ (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600 # define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message) #else @@ -185,7 +185,7 @@ public: #endif // Opens a file. - BufferedFile(fmt::StringRef filename, fmt::StringRef mode); + BufferedFile(CStringRef filename, CStringRef mode); // Closes the file. void close(); @@ -197,10 +197,10 @@ public: // of MinGW that define fileno as a macro. int (fileno)() const; - void print(fmt::StringRef format_str, const ArgList &args) { + void print(CStringRef format_str, const ArgList &args) { fmt::print(file_, format_str, args); } - FMT_VARIADIC(void, print, fmt::StringRef) + FMT_VARIADIC(void, print, CStringRef) }; // A file. Closed file is represented by a File object with descriptor -1. @@ -228,7 +228,7 @@ class File { File() FMT_NOEXCEPT : fd_(-1) {} // Opens a file and constructs a File object representing this file. - File(fmt::StringRef path, int oflag); + File(CStringRef path, int oflag); #if !FMT_USE_RVALUE_REFERENCES // Emulate a move constructor and a move assignment operator if rvalue @@ -300,7 +300,7 @@ class File { void close(); // Returns the file size. - fmt::LongLong size() const; + LongLong size() const; // Attempts to read count bytes from the file into the specified buffer. std::size_t read(void *buffer, std::size_t count); diff --git a/dep/g3dlite/G3D-v9.0 hotfix3.diff b/dep/g3dlite/G3D-v9.0 hotfix3.diff new file mode 100644 index 00000000000..ff5a662684c --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix3.diff @@ -0,0 +1,117 @@ + dep/g3dlite/Readme.txt | 3 ++- + dep/g3dlite/include/G3D/Log.h | 2 +- + dep/g3dlite/include/G3D/Rect2D.h | 2 +- + dep/g3dlite/source/FileSystem.cpp | 3 +++ + dep/g3dlite/source/debugAssert.cpp | 2 ++ + dep/g3dlite/source/fileutils.cpp | 10 ++++++++++ + dep/g3dlite/source/prompt.cpp | 2 ++ + 7 files changed, 21 insertions(+), 3 deletions(-) + +diff --git a/dep/g3dlite/Readme.txt b/dep/g3dlite/Readme.txt +index 7fab7f8..7439943 100644 +--- a/dep/g3dlite/Readme.txt ++++ b/dep/g3dlite/Readme.txt +@@ -11,4 +11,5 @@ G3D-v8.0_hotfix7.diff - 2013-08-31 - fix typo in Matrix4 == operator + G3D-v8.0_hotfix8.diff - 2013-09-01 - fix typo in Vector3int32 += operator + G3D-v8.0_hotfix9.diff - 2014-06-01 - only VS < 10 don't ship inttypes.h + G3D-v9.0 hotfix1.diff - 2014-08-22 - updated to G3D9, reapplied previous patches and removed unneeded changes +-G3D-v9.0 hotfix2.diff - 2014-08-23 - fix some -Wconversion warnings +\ No newline at end of file ++G3D-v9.0 hotfix2.diff - 2014-08-23 - fix some -Wconversion warnings ++G3D-v9.0 hotfix3.diff - 2015-06-28 - fix some warnings +diff --git a/dep/g3dlite/include/G3D/Log.h b/dep/g3dlite/include/G3D/Log.h +index 2aedb13..c8a5d53 100644 +--- a/dep/g3dlite/include/G3D/Log.h ++++ b/dep/g3dlite/include/G3D/Log.h +@@ -57,9 +57,9 @@ private: + + static Log* commonLog; + ++public: + int stripFromStackBottom; + +-public: + + /** + @param stripFromStackBottom Number of call stacks to strip from the +diff --git a/dep/g3dlite/include/G3D/Rect2D.h b/dep/g3dlite/include/G3D/Rect2D.h +index f72dd08..93dd0e6 100644 +--- a/dep/g3dlite/include/G3D/Rect2D.h ++++ b/dep/g3dlite/include/G3D/Rect2D.h +@@ -118,7 +118,7 @@ private: + } + + /** Uninitialized constructor */ +- Rect2D(bool b) {} ++ Rect2D(bool /*b*/) {} + public: + + /** \param any Must either Rect2D::xywh(#, #, #, #) or Rect2D::xyxy(#, #, #, #)*/ +diff --git a/dep/g3dlite/source/FileSystem.cpp b/dep/g3dlite/source/FileSystem.cpp +index 32a84e7..06e6ff0 100644 +--- a/dep/g3dlite/source/FileSystem.cpp ++++ b/dep/g3dlite/source/FileSystem.cpp +@@ -137,6 +137,9 @@ void FileSystem::Dir::computeZipListing(const std::string& zipfile, const std::s + + zip_close(z); + z = NULL; ++#else ++ (void)zipfile; ++ (void)_pathInsideZipfile; + #endif + } + +diff --git a/dep/g3dlite/source/debugAssert.cpp b/dep/g3dlite/source/debugAssert.cpp +index 92ce237..cfccf9a 100644 +--- a/dep/g3dlite/source/debugAssert.cpp ++++ b/dep/g3dlite/source/debugAssert.cpp +@@ -121,6 +121,8 @@ static void createErrorMessage( + const char* moduleName = strrchr(modulePath, '\\'); + outTitle = outTitle + string(" - ") + string(moduleName ? (moduleName + 1) : modulePath); + ++ #else ++ (void)outTitle; + #endif + + // Build the message. +diff --git a/dep/g3dlite/source/fileutils.cpp b/dep/g3dlite/source/fileutils.cpp +index 966cca7..2788ada 100644 +--- a/dep/g3dlite/source/fileutils.cpp ++++ b/dep/g3dlite/source/fileutils.cpp +@@ -396,6 +396,10 @@ bool zipfileExists(const std::string& filename, std::string& outZipfile, + } + + } ++#else ++ (void)filename; ++ (void)outZipfile; ++ (void)outInternalFile; + #endif + // not a valid directory structure ever, + // obviously no .zip was found within the path +@@ -756,6 +760,12 @@ static void getFileOrDirListZip(const std::string& path, + zip_close( z ); + + fileSet.getMembers(files); ++#else ++ (void)path; ++ (void)prefix; ++ (void)files; ++ (void)wantFiles; ++ (void)includePath; + #endif + } + +diff --git a/dep/g3dlite/source/prompt.cpp b/dep/g3dlite/source/prompt.cpp +index ee520d8..6927fd0 100644 +--- a/dep/g3dlite/source/prompt.cpp ++++ b/dep/g3dlite/source/prompt.cpp +@@ -572,6 +572,8 @@ int prompt( + return result; + } + #endif ++#else ++ (void)useGui; + #endif /* G3DFIX: exclude GUI prompt code */ + return textPrompt(windowTitle, prompt, choice, numChoices); + } diff --git a/dep/g3dlite/G3D-v9.0 hotfix4.diff b/dep/g3dlite/G3D-v9.0 hotfix4.diff new file mode 100644 index 00000000000..71589d226ae --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix4.diff @@ -0,0 +1,16 @@ + dep/g3dlite/source/Matrix4.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/dep/g3dlite/source/Matrix4.cpp b/dep/g3dlite/source/Matrix4.cpp +index f3b25ad..0588cb6 100644 +--- a/dep/g3dlite/source/Matrix4.cpp ++++ b/dep/g3dlite/source/Matrix4.cpp +@@ -606,7 +606,7 @@ bool Matrix4float64::operator==(const Matrix4float64& other) const { + // If the bit patterns are identical, they must be + // the same matrix. If not, they *might* still have + // equal elements due to floating point weirdness. +- if (memcmp(this, &other, sizeof(Matrix4float64) == 0)) { ++ if (memcmp(this, &other, sizeof(Matrix4float64)) == 0) { + return true; + } + diff --git a/dep/g3dlite/G3D-v9.0 hotfix5.diff b/dep/g3dlite/G3D-v9.0 hotfix5.diff new file mode 100644 index 00000000000..7bc4073ef62 --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix5.diff @@ -0,0 +1,28 @@ +diff --git a/dep/g3dlite/include/G3D/Quat.h b/dep/g3dlite/include/G3D/Quat.h +index 04e11e0..b26708a 100644 +--- a/dep/g3dlite/include/G3D/Quat.h ++++ b/dep/g3dlite/include/G3D/Quat.h +@@ -335,8 +335,8 @@ public: + Note that q.pow(a).pow(b) == q.pow(a + b) + @cite Dam98 pg 21 + */ +- inline Quat pow(float x) const { +- return (log() * x).exp(); ++ inline Quat pow(float r) const { ++ return (log() * r).exp(); + } + + /** Make unit length in place */ +@@ -349,9 +349,9 @@ public: + the magnitude. + */ + Quat toUnit() const { +- Quat x = *this; +- x.unitize(); +- return x; ++ Quat copyOfThis = *this; ++ copyOfThis.unitize(); ++ return copyOfThis; + } + + /** diff --git a/dep/g3dlite/G3D-v9.0 hotfix6.diff b/dep/g3dlite/G3D-v9.0 hotfix6.diff new file mode 100644 index 00000000000..3ff735c734e --- /dev/null +++ b/dep/g3dlite/G3D-v9.0 hotfix6.diff @@ -0,0 +1,32 @@ +diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h +index 17e3bf2..439495a 100644 +--- a/dep/g3dlite/include/G3D/platform.h ++++ b/dep/g3dlite/include/G3D/platform.h +@@ -364,13 +364,18 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {\ + #endif + #if (!defined(_LIBCPP_VERSION) && defined(__APPLE__)) || (!defined(_LIBCPP_VERSION) && defined(__linux__)) + # include <tr1/memory> ++#else ++# include <memory> ++#endif ++ ++namespace G3D { ++#if (!defined(_LIBCPP_VERSION) && defined(__APPLE__)) || (!defined(_LIBCPP_VERSION) && defined(__linux__)) + using std::tr1::shared_ptr; + using std::tr1::weak_ptr; + using std::tr1::dynamic_pointer_cast; + using std::tr1::static_pointer_cast; + using std::tr1::enable_shared_from_this; + #else +-# include <memory> + using std::shared_ptr; + using std::weak_ptr; + using std::dynamic_pointer_cast; +@@ -378,7 +383,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {\ + using std::enable_shared_from_this; + #endif + +-namespace G3D { + /** Options for initG3D and initGLG3D. */ + class G3DSpecification { + public: diff --git a/dep/g3dlite/Readme.txt b/dep/g3dlite/Readme.txt index 7fab7f83e8d..d4e3fa5d06b 100644 --- a/dep/g3dlite/Readme.txt +++ b/dep/g3dlite/Readme.txt @@ -11,4 +11,8 @@ G3D-v8.0_hotfix7.diff - 2013-08-31 - fix typo in Matrix4 == operator G3D-v8.0_hotfix8.diff - 2013-09-01 - fix typo in Vector3int32 += operator G3D-v8.0_hotfix9.diff - 2014-06-01 - only VS < 10 don't ship inttypes.h G3D-v9.0 hotfix1.diff - 2014-08-22 - updated to G3D9, reapplied previous patches and removed unneeded changes -G3D-v9.0 hotfix2.diff - 2014-08-23 - fix some -Wconversion warnings
\ No newline at end of file +G3D-v9.0 hotfix2.diff - 2014-08-23 - fix some -Wconversion warnings +G3D-v9.0 hotfix3.diff - 2015-06-28 - fix some warnings +G3D-v9.0 hotfix4.diff - 2015-07-02 - backport G3D10 fix +G3D-v9.0 hotfix5.diff - 2015-07-31 - fix MSVC 2015 warning: dep/g3dlite/include/G3D/Quat.h(352): warning C4458: declaration of 'x' hides class member +G3D-v9.0 hotfix6.diff - 2015-11-04 - fix adding std::shared_ptr, std::weak_ptr, std::dynamic_pointer_cast, std::static_pointer_cast and std::enable_shared_from_this to global namespace diff --git a/dep/g3dlite/include/G3D/Log.h b/dep/g3dlite/include/G3D/Log.h index 2aedb13dcdc..c8a5d53f887 100644 --- a/dep/g3dlite/include/G3D/Log.h +++ b/dep/g3dlite/include/G3D/Log.h @@ -57,9 +57,9 @@ private: static Log* commonLog; +public: int stripFromStackBottom; -public: /** @param stripFromStackBottom Number of call stacks to strip from the diff --git a/dep/g3dlite/include/G3D/Quat.h b/dep/g3dlite/include/G3D/Quat.h index 04e11e084a0..73e661a4f48 100644 --- a/dep/g3dlite/include/G3D/Quat.h +++ b/dep/g3dlite/include/G3D/Quat.h @@ -335,8 +335,8 @@ public: Note that q.pow(a).pow(b) == q.pow(a + b) @cite Dam98 pg 21 */ - inline Quat pow(float x) const { - return (log() * x).exp(); + inline Quat pow(float r) const { + return (log() * r).exp(); } /** Make unit length in place */ @@ -349,9 +349,9 @@ public: the magnitude. */ Quat toUnit() const { - Quat x = *this; - x.unitize(); - return x; + Quat copyOfThis = *this; + copyOfThis.unitize(); + return copyOfThis; } /** diff --git a/dep/g3dlite/include/G3D/Rect2D.h b/dep/g3dlite/include/G3D/Rect2D.h index f72dd082ad8..93dd0e619cc 100644 --- a/dep/g3dlite/include/G3D/Rect2D.h +++ b/dep/g3dlite/include/G3D/Rect2D.h @@ -118,7 +118,7 @@ private: } /** Uninitialized constructor */ - Rect2D(bool b) {} + Rect2D(bool /*b*/) {} public: /** \param any Must either Rect2D::xywh(#, #, #, #) or Rect2D::xyxy(#, #, #, #)*/ diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h index 17e3bf279eb..439495ab131 100644 --- a/dep/g3dlite/include/G3D/platform.h +++ b/dep/g3dlite/include/G3D/platform.h @@ -364,13 +364,18 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {\ #endif #if (!defined(_LIBCPP_VERSION) && defined(__APPLE__)) || (!defined(_LIBCPP_VERSION) && defined(__linux__)) # include <tr1/memory> +#else +# include <memory> +#endif + +namespace G3D { +#if (!defined(_LIBCPP_VERSION) && defined(__APPLE__)) || (!defined(_LIBCPP_VERSION) && defined(__linux__)) using std::tr1::shared_ptr; using std::tr1::weak_ptr; using std::tr1::dynamic_pointer_cast; using std::tr1::static_pointer_cast; using std::tr1::enable_shared_from_this; #else -# include <memory> using std::shared_ptr; using std::weak_ptr; using std::dynamic_pointer_cast; @@ -378,7 +383,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {\ using std::enable_shared_from_this; #endif -namespace G3D { /** Options for initG3D and initGLG3D. */ class G3DSpecification { public: diff --git a/dep/g3dlite/source/FileSystem.cpp b/dep/g3dlite/source/FileSystem.cpp index 32a84e77048..06e6ff00a5e 100644 --- a/dep/g3dlite/source/FileSystem.cpp +++ b/dep/g3dlite/source/FileSystem.cpp @@ -137,6 +137,9 @@ void FileSystem::Dir::computeZipListing(const std::string& zipfile, const std::s zip_close(z); z = NULL; +#else + (void)zipfile; + (void)_pathInsideZipfile; #endif } diff --git a/dep/g3dlite/source/Matrix4.cpp b/dep/g3dlite/source/Matrix4.cpp index f3b25ad5837..0588cb6ff46 100644 --- a/dep/g3dlite/source/Matrix4.cpp +++ b/dep/g3dlite/source/Matrix4.cpp @@ -606,7 +606,7 @@ bool Matrix4float64::operator==(const Matrix4float64& other) const { // If the bit patterns are identical, they must be // the same matrix. If not, they *might* still have // equal elements due to floating point weirdness. - if (memcmp(this, &other, sizeof(Matrix4float64) == 0)) { + if (memcmp(this, &other, sizeof(Matrix4float64)) == 0) { return true; } diff --git a/dep/g3dlite/source/debugAssert.cpp b/dep/g3dlite/source/debugAssert.cpp index 92ce2376490..cfccf9a0cc5 100644 --- a/dep/g3dlite/source/debugAssert.cpp +++ b/dep/g3dlite/source/debugAssert.cpp @@ -121,6 +121,8 @@ static void createErrorMessage( const char* moduleName = strrchr(modulePath, '\\'); outTitle = outTitle + string(" - ") + string(moduleName ? (moduleName + 1) : modulePath); + #else + (void)outTitle; #endif // Build the message. diff --git a/dep/g3dlite/source/fileutils.cpp b/dep/g3dlite/source/fileutils.cpp index 966cca7d4bf..2788adad3bc 100644 --- a/dep/g3dlite/source/fileutils.cpp +++ b/dep/g3dlite/source/fileutils.cpp @@ -396,6 +396,10 @@ bool zipfileExists(const std::string& filename, std::string& outZipfile, } } +#else + (void)filename; + (void)outZipfile; + (void)outInternalFile; #endif // not a valid directory structure ever, // obviously no .zip was found within the path @@ -756,6 +760,12 @@ static void getFileOrDirListZip(const std::string& path, zip_close( z ); fileSet.getMembers(files); +#else + (void)path; + (void)prefix; + (void)files; + (void)wantFiles; + (void)includePath; #endif } diff --git a/dep/g3dlite/source/prompt.cpp b/dep/g3dlite/source/prompt.cpp index ee520d85db7..6927fd03b85 100644 --- a/dep/g3dlite/source/prompt.cpp +++ b/dep/g3dlite/source/prompt.cpp @@ -572,6 +572,8 @@ int prompt( return result; } #endif +#else + (void)useGui; #endif /* G3DFIX: exclude GUI prompt code */ return textPrompt(windowTitle, prompt, choice, numChoices); } diff --git a/dep/jemalloc/CMakeLists.txt b/dep/jemalloc/CMakeLists.txt index db3c18dbb02..8f0692fc82c 100644 --- a/dep/jemalloc/CMakeLists.txt +++ b/dep/jemalloc/CMakeLists.txt @@ -53,6 +53,7 @@ set(jemalloc_STAT_SRC include_directories( ${BUILDDIR}/ ${CMAKE_CURRENT_SOURCE_DIR}/include + ${VALGRIND_INCLUDE_DIR} ) add_definitions(-D_GNU_SOURCE -D_REENTRANT) diff --git a/dep/libmpq/AUTHORS b/dep/libmpq/AUTHORS index 3d7da7bec9a..daac7662eee 100644 --- a/dep/libmpq/AUTHORS +++ b/dep/libmpq/AUTHORS @@ -1,10 +1,10 @@ Project Initiator: - * Maik Broemme <mbroemme@plusserver.de> + * Maik Broemme <mbroemme@libmpq.org> Developers: - * Maik Broemme <mbroemme@plusserver.de> + * Maik Broemme <mbroemme@libmpq.org> * Tilman Sauerbeck <tilman@code-monkey.de> * Forrest Voight <voights@gmail.com> * Georg Lukas <georg@op-co.de> diff --git a/dep/libmpq/FAQ b/dep/libmpq/FAQ index 52ca9f3c705..61cad93b6fc 100644 --- a/dep/libmpq/FAQ +++ b/dep/libmpq/FAQ @@ -57,7 +57,7 @@ A: Of course :) The example below takes first parameter as mpq archive libmpq__archive_open(&mpq_archive, argv[1], -1); /* get size of first file (0) and malloc output buffer. */ - libmpq__file_unpacked_size(mpq_archive, 0, &out_size); + libmpq__file_size_unpacked(mpq_archive, 0, &out_size); out_buf = malloc(out_size); /* read, decrypt and unpack file to output buffer. */ diff --git a/dep/libmpq/README b/dep/libmpq/README index 3f1bd3a1e9f..9d3f80e01c6 100644 --- a/dep/libmpq/README +++ b/dep/libmpq/README @@ -26,9 +26,9 @@ Reporting Bugs Bug reports for 'libmpq' can be send to me directly. - * Maik Broemme <mbroemme@plusserver.de> + * Maik Broemme <mbroemme@libmpq.org> Enjoy! -Maik Broemme <mbroemme@plusserver.de> -http://www.babelize.org/ +Maik Broemme <mbroemme@libmpq.org> +http://libmpq.org/ diff --git a/dep/libmpq/THANKS b/dep/libmpq/THANKS index 42da1235476..384e9f1f9e6 100644 --- a/dep/libmpq/THANKS +++ b/dep/libmpq/THANKS @@ -1,4 +1,4 @@ -'libmpq' was originaly created by Maik Broemme <mbroemme@plusserver.de> +'libmpq' was originaly created by Maik Broemme <mbroemme@libmpq.org> and i want to thank some people which helped by supplying knowledge, code or something else. diff --git a/dep/libmpq/bindings/d/mpq.d b/dep/libmpq/bindings/d/mpq.d index d72c2d2a986..cb3cf100070 100644 --- a/dep/libmpq/bindings/d/mpq.d +++ b/dep/libmpq/bindings/d/mpq.d @@ -1,7 +1,7 @@ /* * mpq.d -- D programming language module for libmpq * - * Copyright (c) 2008 Georg Lukas <georg@op-co.de> + * Copyright (c) 2008-2011 Georg Lukas <georg@op-co.de> * * 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 @@ -58,15 +58,15 @@ char *libmpq__version(); /* libmpq__generic mpq archive information. */ int libmpq__archive_open(mpq_archive_s **mpq_archive, char *mpq_filename, off_t archive_offset); int libmpq__archive_close(mpq_archive_s *mpq_archive); -int libmpq__archive_packed_size(mpq_archive_s *mpq_archive, off_t *packed_size); -int libmpq__archive_unpacked_size(mpq_archive_s *mpq_archive, off_t *unpacked_size); +int libmpq__archive_size_packed(mpq_archive_s *mpq_archive, off_t *packed_size); +int libmpq__archive_size_unpacked(mpq_archive_s *mpq_archive, off_t *unpacked_size); int libmpq__archive_offset(mpq_archive_s *mpq_archive, off_t *offset); int libmpq__archive_version(mpq_archive_s *mpq_archive, uint *version_); int libmpq__archive_files(mpq_archive_s *mpq_archive, uint *files); /* libmpq__generic file processing functions. */ -int libmpq__file_packed_size(mpq_archive_s *mpq_archive, uint file_number, off_t *packed_size); -int libmpq__file_unpacked_size(mpq_archive_s *mpq_archive, uint file_number, off_t *unpacked_size); +int libmpq__file_size_packed(mpq_archive_s *mpq_archive, uint file_number, off_t *packed_size); +int libmpq__file_size_unpacked(mpq_archive_s *mpq_archive, uint file_number, off_t *unpacked_size); int libmpq__file_offset(mpq_archive_s *mpq_archive, uint file_number, off_t *offset); int libmpq__file_blocks(mpq_archive_s *mpq_archive, uint file_number, uint *blocks); int libmpq__file_encrypted(mpq_archive_s *mpq_archive, uint file_number, uint *encrypted); @@ -78,7 +78,7 @@ int libmpq__file_read(mpq_archive_s *mpq_archive, uint file_number, ubyte *out_b /* libmpq__generic block processing functions. */ int libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint file_number); int libmpq__block_close_offset(mpq_archive_s *mpq_archive, uint file_number); -int libmpq__block_unpacked_size(mpq_archive_s *mpq_archive, uint file_number, uint block_number, off_t *unpacked_size); +int libmpq__block_size_unpacked(mpq_archive_s *mpq_archive, uint file_number, uint block_number, off_t *unpacked_size); int libmpq__block_read(mpq_archive_s *mpq_archive, uint file_number, uint block_number, ubyte *out_buf, off_t out_size, off_t *transferred); } diff --git a/dep/libmpq/bindings/python/mpq.py b/dep/libmpq/bindings/python/mpq.py index cf6ecaae800..0f4ca37cfba 100644 --- a/dep/libmpq/bindings/python/mpq.py +++ b/dep/libmpq/bindings/python/mpq.py @@ -50,14 +50,14 @@ libmpq.libmpq__version.restype = ctypes.c_char_p libmpq.libmpq__archive_open.errcheck = check_error libmpq.libmpq__archive_close.errcheck = check_error -libmpq.libmpq__archive_packed_size.errcheck = check_error -libmpq.libmpq__archive_unpacked_size.errcheck = check_error +libmpq.libmpq__archive_size_packed.errcheck = check_error +libmpq.libmpq__archive_size_unpacked.errcheck = check_error libmpq.libmpq__archive_offset.errcheck = check_error libmpq.libmpq__archive_version.errcheck = check_error libmpq.libmpq__archive_files.errcheck = check_error -libmpq.libmpq__file_packed_size.errcheck = check_error -libmpq.libmpq__file_unpacked_size.errcheck = check_error +libmpq.libmpq__file_size_packed.errcheck = check_error +libmpq.libmpq__file_size_unpacked.errcheck = check_error libmpq.libmpq__file_offset.errcheck = check_error libmpq.libmpq__file_blocks.errcheck = check_error libmpq.libmpq__file_encrypted.errcheck = check_error @@ -68,7 +68,7 @@ libmpq.libmpq__file_read.errcheck = check_error libmpq.libmpq__block_open_offset.errcheck = check_error libmpq.libmpq__block_close_offset.errcheck = check_error -libmpq.libmpq__block_unpacked_size.errcheck = check_error +libmpq.libmpq__block_size_unpacked.errcheck = check_error libmpq.libmpq__block_read.errcheck = check_error __version__ = libmpq.libmpq__version() @@ -112,7 +112,7 @@ class Reader(object): def _read_block(self, ctypes=ctypes, libmpq=libmpq): block_size = ctypes.c_uint64() - libmpq.libmpq__block_unpacked_size(self._file._archive._mpq, + libmpq.libmpq__block_size_unpacked(self._file._archive._mpq, self._file.number, self._cur_block, ctypes.byref(block_size)) block_data = ctypes.create_string_buffer(block_size.value) libmpq.libmpq__block_read(self._file._archive._mpq, diff --git a/dep/libmpq/configure.ac b/dep/libmpq/configure.ac index d274eab07c6..ce5f90016da 100644 --- a/dep/libmpq/configure.ac +++ b/dep/libmpq/configure.ac @@ -1,5 +1,6 @@ # the autoconf initilization. -AC_INIT(libmpq, 0.4.2, [mbroemme@plusserver.de], [libmpq]) +AC_INIT(libmpq, 0.4.2, [mbroemme@libmpq.org], [libmpq]) +AC_SUBST(LIBMPQ_ABI, [1:0:0]) # detect the canonical host and target build environment. AC_CANONICAL_SYSTEM diff --git a/dep/libmpq/debian/control b/dep/libmpq/debian/control index f35bb060015..b25a3a36c28 100644 --- a/dep/libmpq/debian/control +++ b/dep/libmpq/debian/control @@ -4,7 +4,7 @@ Maintainer: Georg Lukas <georg@op-co.de> Build-Depends: debhelper (>= 7), autotools-dev, libbz2-dev Standards-Version: 3.7.3 Section: libs -Homepage: https://libmpq.org/ +Homepage: http://libmpq.org/ Package: libmpq-dev Section: libdevel diff --git a/dep/libmpq/debian/copyright b/dep/libmpq/debian/copyright index f014cf14de7..5a86a7f1157 100644 --- a/dep/libmpq/debian/copyright +++ b/dep/libmpq/debian/copyright @@ -1,15 +1,15 @@ This package was debianized by Georg Lukas <georg@op-co.de> on Fri, 04 Jul 2008 18:17:08 +0200. -It was downloaded from <https://libmpq.org/> +It was downloaded from <http://libmpq.org/> Upstream Author: - Maik Broemme <mbroemme@plusserver.de> + Maik Broemme <mbroemme@libmpq.org> Copyright: - Copyright (C) 2008 Maik Broemme + Copyright (C) 2003-2011 Maik Broemme License: @@ -19,5 +19,5 @@ License: (at your option) any later version. -The Debian packaging is (C) 2008, Georg Lukas <georg@op-co.de> and +The Debian packaging is (C) 2008-2011, Georg Lukas <georg@op-co.de> and is licensed under the GPL, see `/usr/share/common-licenses/GPL'. diff --git a/dep/libmpq/doc/man1/libmpq-config.1 b/dep/libmpq/doc/man1/libmpq-config.1 index c025f5ce4f4..01caf2ff664 100644 --- a/dep/libmpq/doc/man1/libmpq-config.1 +++ b/dep/libmpq/doc/man1/libmpq-config.1 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 1 2008-02-10 "The MoPaQ archive library" +.TH libmpq 1 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq-config \- script to get information about the installed version of libmpq. .SH SYNOPSIS @@ -63,7 +63,7 @@ Instead of using this configuration script you should better use the pkg-config .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/Makefile.am b/dep/libmpq/doc/man3/Makefile.am index cad3d865dc1..443df545c14 100644 --- a/dep/libmpq/doc/man3/Makefile.am +++ b/dep/libmpq/doc/man3/Makefile.am @@ -11,21 +11,21 @@ man_MANS = \ libmpq__archive_files.3 \ libmpq__archive_offset.3 \ libmpq__archive_open.3 \ - libmpq__archive_packed_size.3 \ - libmpq__archive_unpacked_size.3 \ + libmpq__archive_size_packed.3 \ + libmpq__archive_size_unpacked.3 \ libmpq__archive_version.3 \ libmpq__block_close_offset.3 \ libmpq__block_open_offset.3 \ libmpq__block_read.3 \ - libmpq__block_unpacked_size.3 \ + libmpq__block_size_unpacked.3 \ libmpq__file_blocks.3 \ libmpq__file_compressed.3 \ libmpq__file_encrypted.3 \ libmpq__file_imploded.3 \ libmpq__file_number.3 \ libmpq__file_offset.3 \ - libmpq__file_packed_size.3 \ libmpq__file_read.3 \ - libmpq__file_unpacked_size.3 \ + libmpq__file_size_packed.3 \ + libmpq__file_size_unpacked.3 \ libmpq__strerror.3 \ libmpq__version.3 diff --git a/dep/libmpq/doc/man3/libmpq.3 b/dep/libmpq/doc/man3/libmpq.3 index 768dab0a712..acea1bcef2b 100644 --- a/dep/libmpq/doc/man3/libmpq.3 +++ b/dep/libmpq/doc/man3/libmpq.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-04-29 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -41,12 +41,12 @@ libmpq \- cross-platform C library for manipulating mpq archives. .BI " mpq_archive_s *" "mpq_archive" .BI ");" .sp -.BI "int32_t libmpq__archive_packed_size(" +.BI "int32_t libmpq__archive_size_packed(" .BI " mpq_archive_s *" "mpq_archive", .BI " off_t *" "packed_size" .BI ");" .sp -.BI "int32_t libmpq__archive_unpacked_size(" +.BI "int32_t libmpq__archive_size_unpacked(" .BI " mpq_archive_s *" "mpq_archive", .BI " off_t *" "unpacked_size" .BI ");" @@ -66,13 +66,13 @@ libmpq \- cross-platform C library for manipulating mpq archives. .BI " uint32_t *" "files" .BI ");" .sp -.BI "int32_t libmpq__file_packed_size(" +.BI "int32_t libmpq__file_size_packed(" .BI " mpq_archive_s *" "mpq_archive", .BI " uint32_t " "file_number", .BI " off_t *" "packed_size" .BI ");" .sp -.BI "int32_t libmpq__file_unpacked_size(" +.BI "int32_t libmpq__file_size_unpacked(" .BI " mpq_archive_s *" "mpq_archive", .BI " uint32_t " "file_number", .BI " off_t *" "unpacked_size" @@ -132,14 +132,14 @@ libmpq \- cross-platform C library for manipulating mpq archives. .BI " uint32_t " "file_number" .BI ");" .sp -.BI "int32_t libmpq__block_packed_size(" +.BI "int32_t libmpq__block_size_packed(" .BI " mpq_archive_s *" "mpq_archive", .BI " uint32_t " "file_number", .BI " uint32_t " "block_number", .BI " off_t *" "packed_size" .BI ");" .sp -.BI "int32_t libmpq__block_unpacked_size(" +.BI "int32_t libmpq__block_size_unpacked(" .BI " mpq_archive_s *" "mpq_archive", .BI " uint32_t " "file_number", .BI " uint32_t " "block_number", @@ -177,13 +177,13 @@ The \fIlibmpq\fP library supports decrypting, decompressing, exploding and vario .BR libmpq__strerror (3), .BR libmpq__archive_open (3), .BR libmpq__archive_close (3), -.BR libmpq__archive_packed_size (3), -.BR libmpq__archive_unpacked_size (3), +.BR libmpq__archive_size_packed (3), +.BR libmpq__archive_size_unpacked (3), .BR libmpq__archive_offset (3), .BR libmpq__archive_version (3), .BR libmpq__archive_files (3), -.BR libmpq__file_packed_size (3), -.BR libmpq__file_unpacked_size (3), +.BR libmpq__file_size_packed (3), +.BR libmpq__file_size_unpacked (3), .BR libmpq__file_offset (3), .BR libmpq__file_blocks (3), .BR libmpq__file_encrypted (3), @@ -193,15 +193,15 @@ The \fIlibmpq\fP library supports decrypting, decompressing, exploding and vario .BR libmpq__file_read (3), .BR libmpq__block_open_offset (3), .BR libmpq__block_close_offset (3), -.BR libmpq__block_packed_size (3), -.BR libmpq__block_unpacked_size (3), +.BR libmpq__block_size_packed (3), +.BR libmpq__block_size_unpacked (3), .BR libmpq__block_offset (3), .BR libmpq__block_seed (3), .BR libmpq__block_read (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__archive_close.3 b/dep/libmpq/doc/man3/libmpq__archive_close.3 index dfc652a6721..c529815f668 100644 --- a/dep/libmpq/doc/man3/libmpq__archive_close.3 +++ b/dep/libmpq/doc/man3/libmpq__archive_close.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-04-29 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -43,15 +43,15 @@ On success, a zero is returned and on error one of the following constants. The given file could not be closed. .SH SEE ALSO .BR libmpq__archive_open (3), -.BR libmpq__archive_packed_size (3), -.BR libmpq__archive_unpacked_size (3), +.BR libmpq__archive_size_packed (3), +.BR libmpq__archive_size_unpacked (3), .BR libmpq__archive_offset (3), .BR libmpq__archive_version (3), .BR libmpq__archive_files (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__archive_files.3 b/dep/libmpq/doc/man3/libmpq__archive_files.3 index 6663b99161a..3cd1de4edf3 100644 --- a/dep/libmpq/doc/man3/libmpq__archive_files.3 +++ b/dep/libmpq/doc/man3/libmpq__archive_files.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-14 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -44,7 +44,7 @@ On success, a zero is returned. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__archive_offset.3 b/dep/libmpq/doc/man3/libmpq__archive_offset.3 index 696ac5e809f..3aee44c9577 100644 --- a/dep/libmpq/doc/man3/libmpq__archive_offset.3 +++ b/dep/libmpq/doc/man3/libmpq__archive_offset.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-14 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -45,7 +45,7 @@ On success, a zero is returned. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__archive_open.3 b/dep/libmpq/doc/man3/libmpq__archive_open.3 index 02c021f8948..bc400c444fd 100644 --- a/dep/libmpq/doc/man3/libmpq__archive_open.3 +++ b/dep/libmpq/doc/man3/libmpq__archive_open.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-04-29 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -57,15 +57,15 @@ The given file is no valid mpq archive. Reading in archive failed. .SH SEE ALSO .BR libmpq__archive_close (3), -.BR libmpq__archive_packed_size (3), -.BR libmpq__archive_unpacked_size (3), +.BR libmpq__archive_size_packed (3), +.BR libmpq__archive_size_unpacked (3), .BR libmpq__archive_offset (3), .BR libmpq__archive_version (3), .BR libmpq__archive_files (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__archive_packed_size.3 b/dep/libmpq/doc/man3/libmpq__archive_size_packed.3 index 6c3061f2031..30de1e33c5a 100644 --- a/dep/libmpq/doc/man3/libmpq__archive_packed_size.3 +++ b/dep/libmpq/doc/man3/libmpq__archive_size_packed.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-04-29 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -27,25 +27,25 @@ libmpq \- cross-platform C library for manipulating mpq archives. .B #include <mpq.h> .sp -.BI "int32_t libmpq__archive_packed_size(" +.BI "int32_t libmpq__archive_size_packed(" .BI " mpq_archive_s *" "mpq_archive", .BI " off_t *" "packed_size" .BI ");" .fi .SH DESCRIPTION .PP -Call \fBlibmpq__archive_packed_size\fP() to get the packed size of all files in the archive. It will count compressed and imploded files as well as stored only. +Call \fBlibmpq__archive_size_packed\fP() to get the packed size of all files in the archive. It will count compressed and imploded files as well as stored only. .LP -The \fBlibmpq__archive_packed_size\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument is a reference to the compressed, imploded or stored size \fIpacked_size\fP of file. +The \fBlibmpq__archive_size_packed\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument is a reference to the compressed, imploded or stored size \fIpacked_size\fP of file. .SH RETURN VALUE On success, a zero is returned. .SH SEE ALSO -.BR libmpq__file_packed_size (3), -.BR libmpq__block_packed_size (3) +.BR libmpq__file_size_packed (3), +.BR libmpq__block_size_packed (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__archive_unpacked_size.3 b/dep/libmpq/doc/man3/libmpq__archive_size_unpacked.3 index d2ba923c8f0..5ca04e79dbd 100644 --- a/dep/libmpq/doc/man3/libmpq__archive_unpacked_size.3 +++ b/dep/libmpq/doc/man3/libmpq__archive_size_unpacked.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-04-29 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -27,25 +27,25 @@ libmpq \- cross-platform C library for manipulating mpq archives. .B #include <mpq.h> .sp -.BI "int32_t libmpq__archive_unpacked_size(" +.BI "int32_t libmpq__archive_size_unpacked(" .BI " mpq_archive_s *" "mpq_archive", .BI " off_t *" "unpacked_size" .BI ");" .fi .SH DESCRIPTION .PP -Call \fBlibmpq__archive_unpacked_size\fP() to get the unpacked size of all files in the archive. It will count uncompressed and exploded files as well as stored only. +Call \fBlibmpq__archive_size_unpacked\fP() to get the unpacked size of all files in the archive. It will count uncompressed and exploded files as well as stored only. .LP -The \fBlibmpq__archive_unpacked_size\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument is a reference to the uncompressed, exploded or stored size \fIunpacked_size\fP of file. +The \fBlibmpq__archive_size_unpacked\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument is a reference to the uncompressed, exploded or stored size \fIunpacked_size\fP of file. .SH RETURN VALUE On success, a zero is returned. .SH SEE ALSO -.BR libmpq__file_unpacked_size (3), -.BR libmpq__block_unpacked_size (3) +.BR libmpq__file_size_unpacked (3), +.BR libmpq__block_size_unpacked (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__archive_version.3 b/dep/libmpq/doc/man3/libmpq__archive_version.3 index 1764046895a..5962fc84c41 100644 --- a/dep/libmpq/doc/man3/libmpq__archive_version.3 +++ b/dep/libmpq/doc/man3/libmpq__archive_version.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-14 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -42,7 +42,7 @@ On success, a zero is returned. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__block_close_offset.3 b/dep/libmpq/doc/man3/libmpq__block_close_offset.3 index 1ec0c06f70d..d3cc08e7a52 100644 --- a/dep/libmpq/doc/man3/libmpq__block_close_offset.3 +++ b/dep/libmpq/doc/man3/libmpq__block_close_offset.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -47,7 +47,7 @@ File or block does not exist in archive. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__block_open_offset.3 b/dep/libmpq/doc/man3/libmpq__block_open_offset.3 index a60b133f406..ae51fb9fd2a 100644 --- a/dep/libmpq/doc/man3/libmpq__block_open_offset.3 +++ b/dep/libmpq/doc/man3/libmpq__block_open_offset.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -59,7 +59,7 @@ Decrypting block failed. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__block_read.3 b/dep/libmpq/doc/man3/libmpq__block_read.3 index 3272c64c7ed..46847ca1b88 100644 --- a/dep/libmpq/doc/man3/libmpq__block_read.3 +++ b/dep/libmpq/doc/man3/libmpq__block_read.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -72,7 +72,7 @@ Unpacking block failed. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__block_unpacked_size.3 b/dep/libmpq/doc/man3/libmpq__block_size_unpacked.3 index a21ca48159a..19c913ce8f0 100644 --- a/dep/libmpq/doc/man3/libmpq__block_unpacked_size.3 +++ b/dep/libmpq/doc/man3/libmpq__block_size_unpacked.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -27,7 +27,7 @@ libmpq \- cross-platform C library for manipulating mpq archives. .B #include <mpq.h> .sp -.BI "int32_t libmpq__block_unpacked_size(" +.BI "int32_t libmpq__block_size_unpacked(" .BI " mpq_archive_s *" "mpq_archive", .BI " uint32_t " "file_number", .BI " uint32_t " "block_number", @@ -36,9 +36,9 @@ libmpq \- cross-platform C library for manipulating mpq archives. .fi .SH DESCRIPTION .PP -Call \fBlibmpq__block_unpacked_size\fP() to get the unpacked size of a given block in the file. It will return a valid size for compressed and imploded blocks as well as stored only. +Call \fBlibmpq__block_size_unpacked\fP() to get the unpacked size of a given block in the file. It will return a valid size for compressed and imploded blocks as well as stored only. .LP -The \fBlibmpq__block_unpacked_size\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument \fIfile_number\fP is the number of file, the third argument \fIblock_number\fP is the number of block and the fourth argument is a reference to the uncompressed, exploded or stored size \fIunpacked_size\fP of block. +The \fBlibmpq__block_size_unpacked\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument \fIfile_number\fP is the number of file, the third argument \fIblock_number\fP is the number of block and the fourth argument is a reference to the uncompressed, exploded or stored size \fIunpacked_size\fP of block. .SH RETURN VALUE On success, a zero is returned and on error one of the following constants. .TP @@ -48,12 +48,12 @@ File or block does not exist in archive. .B LIBMPQ_ERROR_OPEN Block offset table was not opened by calling \fBlibmpq__block_open_offset\fP(), or it was closed by an \fBlibmpq__block_close_offset\fP() call. .SH SEE ALSO -.BR libmpq__archive_unpacked_size (3), -.BR libmpq__file_unpacked_size (3) +.BR libmpq__archive_size_unpacked (3), +.BR libmpq__file_size_unpacked (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_blocks.3 b/dep/libmpq/doc/man3/libmpq__file_blocks.3 index 85baeffc603..0ce1fbbac08 100644 --- a/dep/libmpq/doc/man3/libmpq__file_blocks.3 +++ b/dep/libmpq/doc/man3/libmpq__file_blocks.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -48,7 +48,7 @@ File does not exist in archive. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_compressed.3 b/dep/libmpq/doc/man3/libmpq__file_compressed.3 index 24b44f0b666..317f6cbfc8f 100644 --- a/dep/libmpq/doc/man3/libmpq__file_compressed.3 +++ b/dep/libmpq/doc/man3/libmpq__file_compressed.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -48,7 +48,7 @@ File does not exist in archive. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_encrypted.3 b/dep/libmpq/doc/man3/libmpq__file_encrypted.3 index 798f4019c7a..2036b9f413d 100644 --- a/dep/libmpq/doc/man3/libmpq__file_encrypted.3 +++ b/dep/libmpq/doc/man3/libmpq__file_encrypted.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -48,7 +48,7 @@ File does not exist in archive. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_imploded.3 b/dep/libmpq/doc/man3/libmpq__file_imploded.3 index 9adce38cb5f..6b549f9cef5 100644 --- a/dep/libmpq/doc/man3/libmpq__file_imploded.3 +++ b/dep/libmpq/doc/man3/libmpq__file_imploded.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -48,7 +48,7 @@ File does not exist in archive. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_number.3 b/dep/libmpq/doc/man3/libmpq__file_number.3 index 8d7a47769ee..5849c556108 100644 --- a/dep/libmpq/doc/man3/libmpq__file_number.3 +++ b/dep/libmpq/doc/man3/libmpq__file_number.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -46,7 +46,7 @@ File does not exist in archive. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_offset.3 b/dep/libmpq/doc/man3/libmpq__file_offset.3 index 392a66d0b04..ec7fc75e73c 100644 --- a/dep/libmpq/doc/man3/libmpq__file_offset.3 +++ b/dep/libmpq/doc/man3/libmpq__file_offset.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-15 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -49,7 +49,7 @@ File does not exist in archive. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_read.3 b/dep/libmpq/doc/man3/libmpq__file_read.3 index cbfafbd0f4f..bc6f3d22478 100644 --- a/dep/libmpq/doc/man3/libmpq__file_read.3 +++ b/dep/libmpq/doc/man3/libmpq__file_read.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-16 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -71,7 +71,7 @@ Unpacking file failed. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_packed_size.3 b/dep/libmpq/doc/man3/libmpq__file_size_packed.3 index b584ddf77dd..b01f626d828 100644 --- a/dep/libmpq/doc/man3/libmpq__file_packed_size.3 +++ b/dep/libmpq/doc/man3/libmpq__file_size_packed.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-15 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -27,7 +27,7 @@ libmpq \- cross-platform C library for manipulating mpq archives. .B #include <mpq.h> .sp -.BI "int32_t libmpq__file_packed_size(" +.BI "int32_t libmpq__file_size_packed(" .BI " mpq_archive_s *" "mpq_archive", .BI " uint32_t " "file_number", .BI " off_t *" "packed_size" @@ -35,21 +35,21 @@ libmpq \- cross-platform C library for manipulating mpq archives. .fi .SH DESCRIPTION .PP -Call \fBlibmpq__file_packed_size\fP() to get the packed size of a given file in the archive. It will return a valid size for compressed and imploded files as well as stored only. +Call \fBlibmpq__file_size_packed\fP() to get the packed size of a given file in the archive. It will return a valid size for compressed and imploded files as well as stored only. .LP -The \fBlibmpq__file_packed_size\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument \fIfile_number\fP is the number of file and the third argument is a reference to the compressed, imploded or stored size \fIpacked_size\fP of file. +The \fBlibmpq__file_size_packed\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument \fIfile_number\fP is the number of file and the third argument is a reference to the compressed, imploded or stored size \fIpacked_size\fP of file. .SH RETURN VALUE On success, a zero is returned and on error one of the following constants. .TP .B LIBMPQ_ERROR_EXIST File does not exist in archive. .SH SEE ALSO -.BR libmpq__archive_packed_size (3), -.BR libmpq__block_packed_size (3) +.BR libmpq__archive_size_packed (3), +.BR libmpq__block_size_packed (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__file_unpacked_size.3 b/dep/libmpq/doc/man3/libmpq__file_size_unpacked.3 index a81cf7a4e76..4569a5cf062 100644 --- a/dep/libmpq/doc/man3/libmpq__file_unpacked_size.3 +++ b/dep/libmpq/doc/man3/libmpq__file_size_unpacked.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-05-15 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -27,7 +27,7 @@ libmpq \- cross-platform C library for manipulating mpq archives. .B #include <mpq.h> .sp -.BI "int32_t libmpq__file_unpacked_size(" +.BI "int32_t libmpq__file_size_unpacked(" .BI " mpq_archive_s *" "mpq_archive", .BI " uint32_t " "file_number", .BI " off_t *" "unpacked_size" @@ -35,21 +35,21 @@ libmpq \- cross-platform C library for manipulating mpq archives. .fi .SH DESCRIPTION .PP -Call \fBlibmpq__file_unpacked_size\fP() to get the unpacked size of a given file in the archive. It will return a valid size for compressed and imploded files as well as stored only. +Call \fBlibmpq__file_size_unpacked\fP() to get the unpacked size of a given file in the archive. It will return a valid size for compressed and imploded files as well as stored only. .LP -The \fBlibmpq__file_unpacked_size\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument \fIfile_number\fP is the number of file and the third argument is a reference to the uncompressed, exploded or stored size \fIunpacked_size\fP of file. +The \fBlibmpq__file_size_unpacked\fP() function takes as first argument the archive structure \fImpq_archive\fP which have to be allocated first and opened by \fBlibmpq__archive_open\fP(). The second argument \fIfile_number\fP is the number of file and the third argument is a reference to the uncompressed, exploded or stored size \fIunpacked_size\fP of file. .SH RETURN VALUE On success, a zero is returned and on error one of the following constants. .TP .B LIBMPQ_ERROR_EXIST File does not exist in archive. .SH SEE ALSO -.BR libmpq__archive_unpacked_size (3), -.BR libmpq__block_unpacked_size (3) +.BR libmpq__archive_size_unpacked (3), +.BR libmpq__block_size_unpacked (3) .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__strerror.3 b/dep/libmpq/doc/man3/libmpq__strerror.3 index 246f422eed0..ac23d7fb8f0 100644 --- a/dep/libmpq/doc/man3/libmpq__strerror.3 +++ b/dep/libmpq/doc/man3/libmpq__strerror.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2010 Georg Lukas <georg@op-co.de> +.\" Copyright (c) 2010-2011 Georg Lukas <georg@op-co.de> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2010-07-18 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq__strerror \- return string describing libmpq error number .SH SYNOPSIS @@ -39,7 +39,7 @@ The function returns a string pointer to non-writable memory or NULL if \fBretur .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/doc/man3/libmpq__version.3 b/dep/libmpq/doc/man3/libmpq__version.3 index 5500d7314f5..dcd072cbd3b 100644 --- a/dep/libmpq/doc/man3/libmpq__version.3 +++ b/dep/libmpq/doc/man3/libmpq__version.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> +.\" Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as @@ -19,7 +19,7 @@ .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. -.TH libmpq 3 2008-03-31 "The MoPaQ archive library" +.TH libmpq 3 2011-11-06 "The MoPaQ archive library" .SH NAME libmpq \- cross-platform C library for manipulating mpq archives. .SH SYNOPSIS @@ -39,7 +39,7 @@ The function returns the library version. .SH AUTHOR Check documentation. .TP -libmpq is (c) 2003-2008 -.B Maik Broemme <mbroemme@plusserver.de> +libmpq is (c) 2003-2011 +.B Maik Broemme <mbroemme@libmpq.org> .PP The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/dep/libmpq/libmpq-hotfix1.diff b/dep/libmpq/libmpq-hotfix1.diff new file mode 100644 index 00000000000..fba4c7160c6 --- /dev/null +++ b/dep/libmpq/libmpq-hotfix1.diff @@ -0,0 +1,38 @@ + dep/libmpq/libmpq/extract.c | 1 + + dep/libmpq/libmpq/mpq.c | 4 ++-- + 2 files changed, 3 insertions(+), 2 deletions(-) + +diff --git a/dep/libmpq/libmpq/extract.c b/dep/libmpq/libmpq/extract.c +index f4ebb29..dc970b7 100644 +--- a/dep/libmpq/libmpq/extract.c ++++ b/dep/libmpq/libmpq/extract.c +@@ -49,6 +49,7 @@ static decompress_table_s dcmp_table[] = { + /* this function decompress a stream using huffman algorithm. */ + int32_t libmpq__decompress_huffman(uint8_t *in_buf, uint32_t in_size, uint8_t *out_buf, uint32_t out_size) { + ++ (void)in_size; + /* TODO: make typdefs of this structs? */ + /* some common variables. */ + int32_t tb = 0; +diff --git a/dep/libmpq/libmpq/mpq.c b/dep/libmpq/libmpq/mpq.c +index 1936f25..71081b5 100644 +--- a/dep/libmpq/libmpq/mpq.c ++++ b/dep/libmpq/libmpq/mpq.c +@@ -65,7 +65,7 @@ const char *libmpq__version(void) { + const char *libmpq__strerror(int32_t return_code) { + + /* check for array bounds */ +- if (-return_code < 0 || -return_code > sizeof(__libmpq_error_strings)/sizeof(char*)) ++ if (-return_code < 0 || (size_t)-return_code > sizeof(__libmpq_error_strings)/sizeof(char*)) + return NULL; + + /* return appropriate string */ +@@ -912,7 +912,7 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin + } + + /* read block from file. */ +- if (fread(in_buf, 1, in_size, mpq_archive->fp) != in_size) { ++ if ((libmpq__off_t)fread(in_buf, 1, in_size, mpq_archive->fp) != in_size) { + + /* free buffers. */ + free(in_buf); diff --git a/dep/libmpq/libmpq/Makefile.am b/dep/libmpq/libmpq/Makefile.am index 409e3dfe02f..7653a551a31 100644 --- a/dep/libmpq/libmpq/Makefile.am +++ b/dep/libmpq/libmpq/Makefile.am @@ -12,7 +12,7 @@ libmpq_includedir = $(includedir)/libmpq libmpq_include_HEADERS = mpq.h libmpq_la_SOURCES = $(GENERAL_SRCS) -libmpq_la_LDFLAGS = -release $(PACKAGE_VERSION) +libmpq_la_LDFLAGS = -version-info @LIBMPQ_ABI@ GENERAL_SRCS = \ common.c \ diff --git a/dep/libmpq/libmpq/common.c b/dep/libmpq/libmpq/common.c index 879bd902b58..ca7bca5c391 100644 --- a/dep/libmpq/libmpq/common.c +++ b/dep/libmpq/libmpq/common.c @@ -1,7 +1,7 @@ /* * common.c -- shared functions used by mpq-tools. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * 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 @@ -175,7 +175,7 @@ int32_t libmpq__decompress_block(uint8_t *in_buf, uint32_t in_size, uint8_t *out /* check if one compression mode is used. */ else if (compression_type == LIBMPQ_FLAG_COMPRESS_PKZIP || - compression_type == LIBMPQ_FLAG_COMPRESS_MULTI) { + compression_type == LIBMPQ_FLAG_COMPRESS_MULTI) { /* check if block is really compressed, some blocks have set the compression flag, but are not compressed. */ if (in_size < out_size) { diff --git a/dep/libmpq/libmpq/common.h b/dep/libmpq/libmpq/common.h index b9e03126434..93949b4739c 100644 --- a/dep/libmpq/libmpq/common.h +++ b/dep/libmpq/libmpq/common.h @@ -1,7 +1,7 @@ /* * common.h -- header functions used by mpq-tools. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * 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 diff --git a/dep/libmpq/libmpq/explode.c b/dep/libmpq/libmpq/explode.c index 2d778d25c39..eca5b1a078e 100644 --- a/dep/libmpq/libmpq/explode.c +++ b/dep/libmpq/libmpq/explode.c @@ -1,7 +1,7 @@ /* * explode.c -- explode function of pkware data compression library. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * This source was adepted from the C++ version of pkware.cpp included * in stormlib. The C++ version belongs to the following authors: diff --git a/dep/libmpq/libmpq/explode.h b/dep/libmpq/libmpq/explode.h index 1d14dfc0e0a..2724e02d1f5 100644 --- a/dep/libmpq/libmpq/explode.h +++ b/dep/libmpq/libmpq/explode.h @@ -2,7 +2,7 @@ * explode.h -- header file for pkware data decompression library * used by mpq-tools. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * This source was adepted from the C++ version of pklib.h included * in stormlib. The C++ version belongs to the following authors: diff --git a/dep/libmpq/libmpq/extract.c b/dep/libmpq/libmpq/extract.c index 11de1071683..dc970b75ce2 100644 --- a/dep/libmpq/libmpq/extract.c +++ b/dep/libmpq/libmpq/extract.c @@ -2,7 +2,7 @@ * extract.c -- global extracting function for all known file compressions * in a mpq archive. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * 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 @@ -49,6 +49,7 @@ static decompress_table_s dcmp_table[] = { /* this function decompress a stream using huffman algorithm. */ int32_t libmpq__decompress_huffman(uint8_t *in_buf, uint32_t in_size, uint8_t *out_buf, uint32_t out_size) { + (void)in_size; /* TODO: make typdefs of this structs? */ /* some common variables. */ int32_t tb = 0; diff --git a/dep/libmpq/libmpq/extract.h b/dep/libmpq/libmpq/extract.h index d6ea794f162..1243af65440 100644 --- a/dep/libmpq/libmpq/extract.h +++ b/dep/libmpq/libmpq/extract.h @@ -1,7 +1,7 @@ /* * extract.h -- header for the extraction functions used by mpq-tools. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * 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 diff --git a/dep/libmpq/libmpq/huffman.c b/dep/libmpq/libmpq/huffman.c index 8fc87be2f60..3760f7f8d8e 100644 --- a/dep/libmpq/libmpq/huffman.c +++ b/dep/libmpq/libmpq/huffman.c @@ -2,7 +2,7 @@ * huffman.c -- functions do decompress files in mpq files which * uses a modified huffman version. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * Differences between C++ and C version: * diff --git a/dep/libmpq/libmpq/huffman.h b/dep/libmpq/libmpq/huffman.h index 6f691088fa0..9a8b86eab5f 100644 --- a/dep/libmpq/libmpq/huffman.h +++ b/dep/libmpq/libmpq/huffman.h @@ -1,7 +1,7 @@ /* * huffman.h -- structures used for huffman compression. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * This source was adepted from the C++ version of huffman.h included * in stormlib. The C++ version belongs to the following authors: diff --git a/dep/libmpq/libmpq/mpq-internal.h b/dep/libmpq/libmpq/mpq-internal.h index 76eabe4190a..e6146cecd4e 100644 --- a/dep/libmpq/libmpq/mpq-internal.h +++ b/dep/libmpq/libmpq/mpq-internal.h @@ -2,7 +2,7 @@ * mpq-internal.h -- some default types and defines, but only required for * compilation of the library. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * 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 diff --git a/dep/libmpq/libmpq/mpq.c b/dep/libmpq/libmpq/mpq.c index a6ab5db82d9..71081b57945 100644 --- a/dep/libmpq/libmpq/mpq.c +++ b/dep/libmpq/libmpq/mpq.c @@ -1,7 +1,7 @@ /* * mpq.c -- functions for developers using libmpq. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * 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 @@ -37,6 +37,23 @@ /* support for platform specific things */ #include "platform.h" +/* static error constants. */ +static const char *__libmpq_error_strings[] = { + "success", + "open error on file", + "close error on file", + "lseek error on file", + "read error on file", + "write error on file", + "memory allocation error", + "format errror", + "init() wasn't called", + "buffer size is to small", + "file or block does not exist in archive", + "we don't know the decryption seed", + "error on unpacking file" +}; + /* this function returns the library version information. */ const char *libmpq__version(void) { @@ -44,41 +61,25 @@ const char *libmpq__version(void) { return VERSION; } -static const char *__libmpq_error_strings[] = { - "success", - "open error on file", - "close error on file", - "lseek error on file", - "read error on file", - "write error on file", - "memory allocation error", - "format errror", - "init() wasn't called", - "buffer size is to small", - "file or block does not exist in archive", - "we don't know the decryption seed", - "error on unpacking file" - }; - /* this function returns a string message for a return code. */ -const char *libmpq__strerror(int32_t returncode) { +const char *libmpq__strerror(int32_t return_code) { + /* check for array bounds */ - if (-returncode < 0 || -returncode > sizeof(__libmpq_error_strings)/sizeof(char*)) + if (-return_code < 0 || (size_t)-return_code > sizeof(__libmpq_error_strings)/sizeof(char*)) return NULL; /* return appropriate string */ - return __libmpq_error_strings[-returncode]; + return __libmpq_error_strings[-return_code]; } /* this function read a file and verify if it is a valid mpq archive, then it read and decrypt the hash table. */ int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filename, libmpq__off_t archive_offset) { /* some common variables. */ - uint32_t rb = 0; - uint32_t i = 0; - uint32_t count = 0; - int32_t result = 0; - uint32_t header_search = FALSE; + uint32_t i = 0; + uint32_t count = 0; + int32_t result = 0; + uint32_t header_search = FALSE; if (archive_offset == -1) { archive_offset = 0; @@ -118,7 +119,7 @@ int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filena } /* read header from file. */ - if ((rb = fread(&(*mpq_archive)->mpq_header, 1, sizeof(mpq_header_s), (*mpq_archive)->fp)) != sizeof(mpq_header_s)) { + if (fread(&(*mpq_archive)->mpq_header, 1, sizeof(mpq_header_s), (*mpq_archive)->fp) != sizeof(mpq_header_s)) { /* no valid mpq archive. */ result = LIBMPQ_ERROR_FORMAT; @@ -182,7 +183,7 @@ int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filena } /* read header from file. */ - if ((rb = fread(&(*mpq_archive)->mpq_header_ex, 1, sizeof(mpq_header_ex_s), (*mpq_archive)->fp)) != sizeof(mpq_header_ex_s)) { + if (fread(&(*mpq_archive)->mpq_header_ex, 1, sizeof(mpq_header_ex_s), (*mpq_archive)->fp) != sizeof(mpq_header_ex_s)) { /* no valid mpq archive. */ result = LIBMPQ_ERROR_FORMAT; @@ -211,7 +212,7 @@ int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filena } /* read the hash table into the buffer. */ - if ((rb = fread((*mpq_archive)->mpq_hash, 1, (*mpq_archive)->mpq_header.hash_table_count * sizeof(mpq_hash_s), (*mpq_archive)->fp)) < 0) { + if (fread((*mpq_archive)->mpq_hash, 1, (*mpq_archive)->mpq_header.hash_table_count * sizeof(mpq_hash_s), (*mpq_archive)->fp) != (*mpq_archive)->mpq_header.hash_table_count * sizeof(mpq_hash_s)) { /* something on read failed. */ result = LIBMPQ_ERROR_READ; @@ -230,7 +231,7 @@ int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filena } /* read the block table into the buffer. */ - if ((rb = fread((*mpq_archive)->mpq_block, 1, (*mpq_archive)->mpq_header.block_table_count * sizeof(mpq_block_s), (*mpq_archive)->fp)) < 0) { + if (fread((*mpq_archive)->mpq_block, 1, (*mpq_archive)->mpq_header.block_table_count * sizeof(mpq_block_s), (*mpq_archive)->fp) != (*mpq_archive)->mpq_header.block_table_count * sizeof(mpq_block_s)) { /* something on read failed. */ result = LIBMPQ_ERROR_READ; @@ -252,7 +253,7 @@ int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filena } /* read header from file. */ - if ((rb = fread((*mpq_archive)->mpq_block_ex, 1, (*mpq_archive)->mpq_header.block_table_count * sizeof(mpq_block_ex_s), (*mpq_archive)->fp)) < 0) { + if (fread((*mpq_archive)->mpq_block_ex, 1, (*mpq_archive)->mpq_header.block_table_count * sizeof(mpq_block_ex_s), (*mpq_archive)->fp) != (*mpq_archive)->mpq_header.block_table_count * sizeof(mpq_block_ex_s)) { /* no valid mpq archive. */ result = LIBMPQ_ERROR_FORMAT; @@ -327,7 +328,7 @@ int32_t libmpq__archive_close(mpq_archive_s *mpq_archive) { } /* this function return the packed size of all files in the archive. */ -int32_t libmpq__archive_packed_size(mpq_archive_s *mpq_archive, libmpq__off_t *packed_size) { +int32_t libmpq__archive_size_packed(mpq_archive_s *mpq_archive, libmpq__off_t *packed_size) { /* some common variables. */ uint32_t i; @@ -342,7 +343,7 @@ int32_t libmpq__archive_packed_size(mpq_archive_s *mpq_archive, libmpq__off_t *p } /* this function return the unpacked size of all files in the archive. */ -int32_t libmpq__archive_unpacked_size(mpq_archive_s *mpq_archive, libmpq__off_t *unpacked_size) { +int32_t libmpq__archive_size_unpacked(mpq_archive_s *mpq_archive, libmpq__off_t *unpacked_size) { /* some common variables. */ uint32_t i; @@ -397,7 +398,7 @@ int32_t libmpq__archive_files(mpq_archive_s *mpq_archive, uint32_t *files) { } /* this function return the packed size of the given files in the archive. */ -int32_t libmpq__file_packed_size(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *packed_size) { +int32_t libmpq__file_size_packed(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *packed_size) { /* check if given file number is not out of range. */ CHECK_FILE_NUM(file_number, mpq_archive) @@ -410,7 +411,7 @@ int32_t libmpq__file_packed_size(mpq_archive_s *mpq_archive, uint32_t file_numbe } /* this function return the unpacked size of the given file in the archive. */ -int32_t libmpq__file_unpacked_size(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *unpacked_size) { +int32_t libmpq__file_size_unpacked(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *unpacked_size) { /* check if given file number is not out of range. */ CHECK_FILE_NUM(file_number, mpq_archive) @@ -534,8 +535,8 @@ int32_t libmpq__file_read(mpq_archive_s *mpq_archive, uint32_t file_number, uint /* some common variables. */ uint32_t i; - uint32_t blocks = 0; - int32_t result = 0; + uint32_t blocks = 0; + int32_t result = 0; libmpq__off_t file_offset = 0; libmpq__off_t unpacked_size = 0; libmpq__off_t transferred_block = 0; @@ -545,7 +546,7 @@ int32_t libmpq__file_read(mpq_archive_s *mpq_archive, uint32_t file_number, uint CHECK_FILE_NUM(file_number, mpq_archive) /* get target size of block. */ - libmpq__file_unpacked_size(mpq_archive, file_number, &unpacked_size); + libmpq__file_size_unpacked(mpq_archive, file_number, &unpacked_size); /* check if target buffer is to small. */ if (unpacked_size > out_size) { @@ -574,7 +575,7 @@ int32_t libmpq__file_read(mpq_archive_s *mpq_archive, uint32_t file_number, uint unpacked_size = 0; /* get unpacked block size. */ - libmpq__block_unpacked_size(mpq_archive, file_number, i, &unpacked_size); + libmpq__block_size_unpacked(mpq_archive, file_number, i, &unpacked_size); /* read block. */ if ((result = libmpq__block_read(mpq_archive, file_number, i, out_buf + transferred_total, unpacked_size, &transferred_block)) < 0) { @@ -610,7 +611,6 @@ int32_t libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint32_t file_numb /* some common variables. */ uint32_t i; uint32_t packed_size; - int32_t rb = 0; int32_t result = 0; /* check if given file number is not out of range. */ @@ -673,7 +673,7 @@ int32_t libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint32_t file_numb } /* read block positions from begin of file. */ - if ((rb = fread(mpq_archive->mpq_file[file_number]->packed_offset, 1, packed_size, mpq_archive->fp)) < 0) { + if (fread(mpq_archive->mpq_file[file_number]->packed_offset, 1, packed_size, mpq_archive->fp) != packed_size) { /* something on read from archive failed. */ result = LIBMPQ_ERROR_READ; @@ -683,8 +683,8 @@ int32_t libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint32_t file_numb /* check if the archive is protected some way, sometimes the file appears not to be encrypted, but it is. * a special case are files with an additional sector but LIBMPQ_FLAG_CRC not set. we don't want to handle * them as encrypted. */ - if (mpq_archive->mpq_file[file_number]->packed_offset[0] != rb && - mpq_archive->mpq_file[file_number]->packed_offset[0] != rb + 4) { + if (mpq_archive->mpq_file[file_number]->packed_offset[0] != packed_size && + mpq_archive->mpq_file[file_number]->packed_offset[0] != packed_size + 4) { /* file is encrypted. */ mpq_archive->mpq_block[mpq_archive->mpq_map[file_number].block_table_indices].flags |= LIBMPQ_FLAG_ENCRYPTED; @@ -789,7 +789,7 @@ int32_t libmpq__block_close_offset(mpq_archive_s *mpq_archive, uint32_t file_num } /* this function return the unpacked size of the given file and block in the archive. */ -int32_t libmpq__block_unpacked_size(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t block_number, libmpq__off_t *unpacked_size) { +int32_t libmpq__block_size_unpacked(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t block_number, libmpq__off_t *unpacked_size) { /* check if given file number is not out of range. */ CHECK_FILE_NUM(file_number, mpq_archive) @@ -860,13 +860,13 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin /* some common variables. */ uint8_t *in_buf; - uint32_t seed = 0; - uint32_t encrypted = 0; - uint32_t compressed = 0; - uint32_t imploded = 0; - int32_t tb = 0; + uint32_t seed = 0; + uint32_t encrypted = 0; + uint32_t compressed = 0; + uint32_t imploded = 0; + int32_t tb = 0; libmpq__off_t block_offset = 0; - off_t in_size = 0; + libmpq__off_t in_size = 0; libmpq__off_t unpacked_size = 0; /* check if given file number is not out of range. */ @@ -884,7 +884,7 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin } /* get target size of block. */ - libmpq__block_unpacked_size(mpq_archive, file_number, block_number, &unpacked_size); + libmpq__block_size_unpacked(mpq_archive, file_number, block_number, &unpacked_size); /* check if target buffer is to small. */ if (unpacked_size > out_size) { @@ -912,7 +912,7 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin } /* read block from file. */ - if (fread(in_buf, 1, in_size, mpq_archive->fp) < 0) { + if ((libmpq__off_t)fread(in_buf, 1, in_size, mpq_archive->fp) != in_size) { /* free buffers. */ free(in_buf); @@ -925,7 +925,7 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin libmpq__file_encrypted(mpq_archive, file_number, &encrypted); /* check if file is encrypted. */ - if (encrypted == 1) { + if (encrypted) { /* get decryption key. */ libmpq__block_seed(mpq_archive, file_number, block_number, &seed); @@ -945,7 +945,7 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin libmpq__file_compressed(mpq_archive, file_number, &compressed); /* check if file is compressed. */ - if (compressed == 1) { + if (compressed) { /* decompress block. */ if ((tb = libmpq__decompress_block(in_buf, in_size, out_buf, out_size, LIBMPQ_FLAG_COMPRESS_MULTI)) < 0) { @@ -962,7 +962,7 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin libmpq__file_imploded(mpq_archive, file_number, &imploded); /* check if file is imploded. */ - if (imploded == 1) { + if (imploded) { /* explode block. */ if ((tb = libmpq__decompress_block(in_buf, in_size, out_buf, out_size, LIBMPQ_FLAG_COMPRESS_PKZIP)) < 0) { @@ -975,8 +975,17 @@ int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uin } } + /* files should not be compressed and imploded */ + if (compressed && imploded) { + /* free temporary buffer. */ + free(in_buf); + + /* something on decompressing block failed. */ + return LIBMPQ_ERROR_UNPACK; + } + /* check if file is neither compressed nor imploded. */ - if (compressed == 0 && imploded == 0) { + if (!compressed && !imploded) { /* copy block. */ if ((tb = libmpq__decompress_block(in_buf, in_size, out_buf, out_size, LIBMPQ_FLAG_COMPRESS_NONE)) < 0) { diff --git a/dep/libmpq/libmpq/mpq.h b/dep/libmpq/libmpq/mpq.h index abd4862c334..c367ab3776e 100644 --- a/dep/libmpq/libmpq/mpq.h +++ b/dep/libmpq/libmpq/mpq.h @@ -1,7 +1,7 @@ /* * mpq.h -- some default types and defines. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * Some parts (the encryption and decryption stuff) were adapted from * the C++ version of StormLib.h and StormPort.h included in stormlib. @@ -66,20 +66,20 @@ typedef int64_t libmpq__off_t; extern LIBMPQ_API const char *libmpq__version(void); /* string error message for a libmpq return code. */ -extern LIBMPQ_API const char *libmpq__strerror(int32_t returncode); +extern LIBMPQ_API const char *libmpq__strerror(int32_t return_code); /* generic mpq archive information. */ extern LIBMPQ_API int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filename, libmpq__off_t archive_offset); extern LIBMPQ_API int32_t libmpq__archive_close(mpq_archive_s *mpq_archive); -extern LIBMPQ_API int32_t libmpq__archive_packed_size(mpq_archive_s *mpq_archive, libmpq__off_t *packed_size); -extern LIBMPQ_API int32_t libmpq__archive_unpacked_size(mpq_archive_s *mpq_archive, libmpq__off_t *unpacked_size); +extern LIBMPQ_API int32_t libmpq__archive_size_packed(mpq_archive_s *mpq_archive, libmpq__off_t *packed_size); +extern LIBMPQ_API int32_t libmpq__archive_size_unpacked(mpq_archive_s *mpq_archive, libmpq__off_t *unpacked_size); extern LIBMPQ_API int32_t libmpq__archive_offset(mpq_archive_s *mpq_archive, libmpq__off_t *offset); extern LIBMPQ_API int32_t libmpq__archive_version(mpq_archive_s *mpq_archive, uint32_t *version); extern LIBMPQ_API int32_t libmpq__archive_files(mpq_archive_s *mpq_archive, uint32_t *files); /* generic file processing functions. */ -extern LIBMPQ_API int32_t libmpq__file_packed_size(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *packed_size); -extern LIBMPQ_API int32_t libmpq__file_unpacked_size(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *unpacked_size); +extern LIBMPQ_API int32_t libmpq__file_size_packed(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *packed_size); +extern LIBMPQ_API int32_t libmpq__file_size_unpacked(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *unpacked_size); extern LIBMPQ_API int32_t libmpq__file_offset(mpq_archive_s *mpq_archive, uint32_t file_number, libmpq__off_t *offset); extern LIBMPQ_API int32_t libmpq__file_blocks(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t *blocks); extern LIBMPQ_API int32_t libmpq__file_encrypted(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t *encrypted); @@ -91,7 +91,7 @@ extern LIBMPQ_API int32_t libmpq__file_read(mpq_archive_s *mpq_archive, uint32_t /* generic block processing functions. */ extern LIBMPQ_API int32_t libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint32_t file_number); extern LIBMPQ_API int32_t libmpq__block_close_offset(mpq_archive_s *mpq_archive, uint32_t file_number); -extern LIBMPQ_API int32_t libmpq__block_unpacked_size(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t block_number, libmpq__off_t *unpacked_size); +extern LIBMPQ_API int32_t libmpq__block_size_unpacked(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t block_number, libmpq__off_t *unpacked_size); extern LIBMPQ_API int32_t libmpq__block_read(mpq_archive_s *mpq_archive, uint32_t file_number, uint32_t block_number, uint8_t *out_buf, libmpq__off_t out_size, libmpq__off_t *transferred); #ifdef __cplusplus diff --git a/dep/libmpq/libmpq/pack_begin.h b/dep/libmpq/libmpq/pack_begin.h index eb4a6ddebbb..eff141c57ce 100644 --- a/dep/libmpq/libmpq/pack_begin.h +++ b/dep/libmpq/libmpq/pack_begin.h @@ -1,7 +1,7 @@ /* * pack_begin.h -- header file for struct packing used by libmpq. * - * Copyright (c) 2010 Georg Lukas <georg@op-co.de> + * Copyright (c) 2010-2011 Georg Lukas <georg@op-co.de> * * 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 diff --git a/dep/libmpq/libmpq/pack_end.h b/dep/libmpq/libmpq/pack_end.h index a8a35113bfb..60b1b1db9d2 100644 --- a/dep/libmpq/libmpq/pack_end.h +++ b/dep/libmpq/libmpq/pack_end.h @@ -1,7 +1,7 @@ /* * pack_end.h -- header file for struct packing used by libmpq. * - * Copyright (c) 2010 Georg Lukas <georg@op-co.de> + * Copyright (c) 2010-2011 Georg Lukas <georg@op-co.de> * * 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 diff --git a/dep/libmpq/libmpq/platform.h b/dep/libmpq/libmpq/platform.h index 68fdfdc5ded..cdffccabbf1 100644 --- a/dep/libmpq/libmpq/platform.h +++ b/dep/libmpq/libmpq/platform.h @@ -1,7 +1,7 @@ /* * platform.h -- header file for platform specific parts. * - * Copyright (c) 2010 Georg Lukas <georg@op-co.de> + * Copyright (c) 2010-2011 Georg Lukas <georg@op-co.de> * * 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 diff --git a/dep/libmpq/libmpq/wave.c b/dep/libmpq/libmpq/wave.c index 628593fce83..9df58a0baf6 100644 --- a/dep/libmpq/libmpq/wave.c +++ b/dep/libmpq/libmpq/wave.c @@ -2,7 +2,7 @@ * wave.c -- this file contains decompression methods used by mpq-tools * to decompress wave files. * - * Copyright (c) 2003-2007 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * This source was adepted from the C++ version of wave.cpp included * in stormlib. The C++ version belongs to the following authors: diff --git a/dep/libmpq/libmpq/wave.h b/dep/libmpq/libmpq/wave.h index 1b9491bd70a..7496b1cf9bb 100644 --- a/dep/libmpq/libmpq/wave.h +++ b/dep/libmpq/libmpq/wave.h @@ -1,7 +1,7 @@ /* * wave.h -- header file for wav unplode functions used by mpq-tools. * - * Copyright (c) 2003-2007 Maik Broemme <mbroemme@plusserver.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> * * This source was adepted from the C++ version of wave.h included * in stormlib. The C++ version belongs to the following authors: diff --git a/dep/libmpq/tools/crypt_buf_gen.c b/dep/libmpq/tools/crypt_buf_gen.c index 3d150fc661f..c6b1cbc60a6 100644 --- a/dep/libmpq/tools/crypt_buf_gen.c +++ b/dep/libmpq/tools/crypt_buf_gen.c @@ -1,8 +1,8 @@ /* * crypt_buf_gen.c -- tool to re-create the static decryption buffer. * - * Copyright (c) 2003-2008 Maik Broemme <mbroemme@plusserver.de> - * Copyright (c) 2008 Georg Lukas <georg@op-co.de> + * Copyright (c) 2003-2011 Maik Broemme <mbroemme@libmpq.org> + * Copyright (c) 2008-2011 Georg Lukas <georg@op-co.de> * * 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 diff --git a/dep/recastnavigation/Detour/Include/DetourCommon.h b/dep/recastnavigation/Detour/Include/DetourCommon.h index 0888614ea9b..2afba0d780b 100644 --- a/dep/recastnavigation/Detour/Include/DetourCommon.h +++ b/dep/recastnavigation/Detour/Include/DetourCommon.h @@ -19,6 +19,8 @@ #ifndef DETOURCOMMON_H #define DETOURCOMMON_H +#include "DetourMath.h" + /** @defgroup detour Detour @@ -71,11 +73,6 @@ template<class T> inline T dtSqr(T a) { return a*a; } /// @return The value, clamped to the specified range. template<class T> inline T dtClamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); } -/// Returns the square root of the value. -/// @param[in] x The value. -/// @return The square root of the vlaue. -float dtSqrt(float x); - /// @} /// @name Vector helper functions. /// @{ @@ -202,7 +199,7 @@ inline void dtVcopy(float* dest, const float* a) /// @return The scalar length of the vector. inline float dtVlen(const float* v) { - return dtSqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); + return dtMathSqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); } /// Derives the square of the scalar length of the vector. (len * len) @@ -222,7 +219,7 @@ inline float dtVdist(const float* v1, const float* v2) const float dx = v2[0] - v1[0]; const float dy = v2[1] - v1[1]; const float dz = v2[2] - v1[2]; - return dtSqrt(dx*dx + dy*dy + dz*dz); + return dtMathSqrtf(dx*dx + dy*dy + dz*dz); } /// Returns the square of the distance between two points. @@ -247,7 +244,7 @@ inline float dtVdist2D(const float* v1, const float* v2) { const float dx = v2[0] - v1[0]; const float dz = v2[2] - v1[2]; - return dtSqrt(dx*dx + dz*dz); + return dtMathSqrtf(dx*dx + dz*dz); } /// Derives the square of the distance between the specified points on the xz-plane. @@ -265,7 +262,7 @@ inline float dtVdist2DSqr(const float* v1, const float* v2) /// @param[in,out] v The vector to normalize. [(x, y, z)] inline void dtVnormalize(float* v) { - float d = 1.0f / dtSqrt(dtSqr(v[0]) + dtSqr(v[1]) + dtSqr(v[2])); + float d = 1.0f / dtMathSqrtf(dtSqr(v[0]) + dtSqr(v[1]) + dtSqr(v[2])); v[0] *= d; v[1] *= d; v[2] *= d; diff --git a/dep/recastnavigation/Detour/Include/DetourMath.h b/dep/recastnavigation/Detour/Include/DetourMath.h new file mode 100644 index 00000000000..95e14f8843b --- /dev/null +++ b/dep/recastnavigation/Detour/Include/DetourMath.h @@ -0,0 +1,20 @@ +/** +@defgroup detour Detour + +Members in this module are wrappers around the standard math library +*/ + +#ifndef DETOURMATH_H +#define DETOURMATH_H + +#include <math.h> + +inline float dtMathFabsf(float x) { return fabsf(x); } +inline float dtMathSqrtf(float x) { return sqrtf(x); } +inline float dtMathFloorf(float x) { return floorf(x); } +inline float dtMathCeilf(float x) { return ceilf(x); } +inline float dtMathCosf(float x) { return cosf(x); } +inline float dtMathSinf(float x) { return sinf(x); } +inline float dtMathAtan2f(float y, float x) { return atan2f(y, x); } + +#endif diff --git a/dep/recastnavigation/Detour/Source/DetourCommon.cpp b/dep/recastnavigation/Detour/Source/DetourCommon.cpp index b5700f5930b..26fe65c1781 100644 --- a/dep/recastnavigation/Detour/Source/DetourCommon.cpp +++ b/dep/recastnavigation/Detour/Source/DetourCommon.cpp @@ -16,16 +16,11 @@ // 3. This notice may not be removed or altered from any source distribution. // -#include <math.h> #include "DetourCommon.h" +#include "DetourMath.h" ////////////////////////////////////////////////////////////////////////////////////////// -float dtSqrt(float x) -{ - return sqrtf(x); -} - void dtClosestPtPointTriangle(float* closest, const float* p, const float* a, const float* b, const float* c) { @@ -360,7 +355,7 @@ void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas, acc += dacc; } - float v = dtSqrt(t); + float v = dtMathSqrtf(t); const float a = 1 - v; const float b = (1 - u) * v; diff --git a/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp b/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp index 51740509950..e8a679bb5d1 100644 --- a/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp @@ -16,13 +16,13 @@ // 3. This notice may not be removed or altered from any source distribution. // -#include <math.h> #include <float.h> #include <string.h> #include <stdio.h> #include "DetourNavMesh.h" #include "DetourNode.h" #include "DetourCommon.h" +#include "DetourMath.h" #include "DetourAlloc.h" #include "DetourAssert.h" #include <new> @@ -709,7 +709,7 @@ dtPolyRef dtNavMesh::findNearestPolyInTile(const dtMeshTile* tile, float closestPtPoly[3]; float diff[3]; bool posOverPoly = false; - float d = 0; + float d; closestPointOnPoly(ref, center, closestPtPoly, &posOverPoly); // If a point is directly over a polygon and closer than diff --git a/dep/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp b/dep/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp index 9d8471b96a1..1bf271bed7a 100644 --- a/dep/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp @@ -16,13 +16,13 @@ // 3. This notice may not be removed or altered from any source distribution. // -#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <float.h> #include "DetourNavMesh.h" #include "DetourCommon.h" +#include "DetourMath.h" #include "DetourNavMeshBuilder.h" #include "DetourAlloc.h" #include "DetourAssert.h" @@ -202,8 +202,8 @@ static int createBVTree(const unsigned short* verts, const int /*nverts*/, if (z > it.bmax[2]) it.bmax[2] = z; } // Remap y - it.bmin[1] = (unsigned short)floorf((float)it.bmin[1]*ch/cs); - it.bmax[1] = (unsigned short)ceilf((float)it.bmax[1]*ch/cs); + it.bmin[1] = (unsigned short)dtMathFloorf((float)it.bmin[1]*ch/cs); + it.bmax[1] = (unsigned short)dtMathCeilf((float)it.bmax[1]*ch/cs); } int curNode = 0; diff --git a/dep/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp b/dep/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp index ec3a2946ea5..fbf3724e85b 100644 --- a/dep/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp @@ -16,13 +16,13 @@ // 3. This notice may not be removed or altered from any source distribution. // -#include <math.h> #include <float.h> #include <string.h> #include "DetourNavMeshQuery.h" #include "DetourNavMesh.h" #include "DetourNode.h" #include "DetourCommon.h" +#include "DetourMath.h" #include "DetourAlloc.h" #include "DetourAssert.h" #include <new> @@ -99,9 +99,9 @@ inline float dtQueryFilter::getCost(const float* pa, const float* pb, return dtVdist(pa, pb) * m_areaCost[curPoly->getArea()]; } #endif - + // Edited by TC -static const float H_SCALE = 2.0f; // Search heuristic scale. +static const float H_SCALE = 2.0f; // Search heuristic scale. dtNavMeshQuery* dtAllocNavMeshQuery() @@ -309,7 +309,7 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr return DT_SUCCESS; } -dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const float* centerPos, const float radius, +dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const float* centerPos, const float maxRadius, const dtQueryFilter* filter, float (*frand)(), dtPolyRef* randomRef, float* randomPt) const { @@ -341,7 +341,7 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f dtStatus status = DT_SUCCESS; - const float radiusSqr = dtSqr(radius); + const float radiusSqr = dtSqr(maxRadius); float areaSum = 0.0f; const dtMeshTile* randomTile = 0; @@ -705,7 +705,7 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h /// @p nearestRef before using @p nearestPt. /// /// @warning This function is not suitable for large area searches. If the search -/// extents overlaps more than 128 polygons it may return an invalid result. +/// extents overlaps more than MAX_SEARCH (128) polygons it may return an invalid result. /// dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* extents, const dtQueryFilter* filter, @@ -716,9 +716,10 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten *nearestRef = 0; // Get nearby polygons from proximity grid. - dtPolyRef polys[128]; + const int MAX_SEARCH = 128; + dtPolyRef polys[MAX_SEARCH]; int polyCount = 0; - if (dtStatusFailed(queryPolygons(center, extents, filter, polys, &polyCount, 128))) + if (dtStatusFailed(queryPolygons(center, extents, filter, polys, &polyCount, MAX_SEARCH))) return DT_FAILURE | DT_INVALID_PARAM; // Find nearest polygon amongst the nearby polygons. @@ -1304,12 +1305,8 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters) if (!m_query.filter->passFilter(neighbourRef, neighbourTile, neighbourPoly)) continue; - // deal explicitly with crossing tile boundaries - unsigned char crossSide = 0; - if (bestTile->links[i].side != 0xff) - crossSide = bestTile->links[i].side >> 1; - - dtNode* neighbourNode = m_nodePool->getNode(neighbourRef, crossSide); + // get the neighbor node + dtNode* neighbourNode = m_nodePool->getNode(neighbourRef, 0); if (!neighbourNode) { m_query.status |= DT_OUT_OF_NODES; diff --git a/dep/recastnavigation/Recast/Include/Recast.h b/dep/recastnavigation/Recast/Include/Recast.h index 66974cdbcc3..d3e9219a9f6 100644 --- a/dep/recastnavigation/Recast/Include/Recast.h +++ b/dep/recastnavigation/Recast/Include/Recast.h @@ -1083,7 +1083,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, /// @returns True if the operation completed successfully. bool rcBuildContours(rcContext* ctx, rcCompactHeightfield& chf, const float maxError, const int maxEdgeLen, - rcContourSet& cset, const int flags = RC_CONTOUR_TESS_WALL_EDGES); + rcContourSet& cset, const int buildFlags = RC_CONTOUR_TESS_WALL_EDGES); /// Builds a polygon mesh from the provided contours. /// @ingroup recast diff --git a/dep/recastnavigation/Recast/Source/Recast.cpp b/dep/recastnavigation/Recast/Source/Recast.cpp index b9d86036c3f..59d99609446 100644 --- a/dep/recastnavigation/Recast/Source/Recast.cpp +++ b/dep/recastnavigation/Recast/Source/Recast.cpp @@ -238,7 +238,7 @@ static void calcTriNormal(const float* v0, const float* v1, const float* v2, flo /// @par /// -/// Only sets the aread id's for the walkable triangles. Does not alter the +/// Only sets the area id's for the walkable triangles. Does not alter the /// area id's for unwalkable triangles. /// /// See the #rcConfig documentation for more information on the configuration parameters. @@ -267,7 +267,7 @@ void rcMarkWalkableTriangles(rcContext* ctx, const float walkableSlopeAngle, /// @par /// -/// Only sets the aread id's for the unwalkable triangles. Does not alter the +/// Only sets the area id's for the unwalkable triangles. Does not alter the /// area id's for walkable triangles. /// /// See the #rcConfig documentation for more information on the configuration parameters. @@ -318,7 +318,7 @@ int rcGetHeightFieldSpanCount(rcContext* ctx, rcHeightfield& hf) /// @par /// /// This is just the beginning of the process of fully building a compact heightfield. -/// Various filters may be applied applied, then the distance field and regions built. +/// Various filters may be applied, then the distance field and regions built. /// E.g: #rcBuildDistanceField and #rcBuildRegions /// /// See the #rcConfig documentation for more information on the configuration parameters. @@ -486,4 +486,4 @@ static int getCompactHeightFieldMemoryusage(const rcCompactHeightfield& chf) size += sizeof(rcCompactCell) * chf.width * chf.height; return size; } -*/
\ No newline at end of file +*/ diff --git a/dep/recastnavigation/Recast/Source/RecastContour.cpp b/dep/recastnavigation/Recast/Source/RecastContour.cpp index 8aa9d1d92a1..a7be6691f3e 100644 --- a/dep/recastnavigation/Recast/Source/RecastContour.cpp +++ b/dep/recastnavigation/Recast/Source/RecastContour.cpp @@ -464,7 +464,7 @@ static int calcAreaOfPolygon2D(const int* verts, const int nverts) } // TODO: these are the same as in RecastMesh.cpp, consider using the same. - +// Last time I checked the if version got compiled using cmov, which was a lot faster than module (with idiv). inline int prev(int i, int n) { return i-1 >= 0 ? i-1 : n-1; } inline int next(int i, int n) { return i+1 < n ? i+1 : 0; } diff --git a/dep/recastnavigation/Recast/Source/RecastLayers.cpp b/dep/recastnavigation/Recast/Source/RecastLayers.cpp index cb1a39f4bda..41458c1ea68 100644 --- a/dep/recastnavigation/Recast/Source/RecastLayers.cpp +++ b/dep/recastnavigation/Recast/Source/RecastLayers.cpp @@ -38,7 +38,7 @@ struct rcLayerRegion unsigned char layerId; // Layer ID unsigned char nlayers; // Layer count unsigned char nneis; // Neighbour count - unsigned char base; // Flag indicating if the region is the base of merged regions. + unsigned char base; // Flag indicating if the region is the base of merged regions. }; @@ -293,7 +293,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, for (int i = 0; i < nregs; ++i) { rcLayerRegion& root = regs[i]; - // Skip alreadu visited. + // Skip already visited. if (root.layerId != 0xff) continue; @@ -368,7 +368,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, rcLayerRegion& rj = regs[j]; if (!rj.base) continue; - // Skip if teh regions are not close to each other. + // Skip if the regions are not close to each other. if (!overlapRange(ri.ymin,ri.ymax+mergeHeight, rj.ymin,rj.ymax+mergeHeight)) continue; // Skip if the height range would become too large. @@ -377,7 +377,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, if ((ymax - ymin) >= 255) continue; - // Make sure that there is no overlap when mergin 'ri' and 'rj'. + // Make sure that there is no overlap when merging 'ri' and 'rj'. bool overlap = false; // Iterate over all regions which have the same layerId as 'rj' for (int k = 0; k < nregs; ++k) @@ -417,7 +417,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, // Add overlaid layers from 'rj' to 'ri'. for (int k = 0; k < rj.nlayers; ++k) addUnique(ri.layers, ri.nlayers, rj.layers[k]); - // Update heigh bounds. + // Update height bounds. ri.ymin = rcMin(ri.ymin, rj.ymin); ri.ymax = rcMax(ri.ymax, rj.ymax); } @@ -481,10 +481,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, for (int i = 0; i < lset.nlayers; ++i) { unsigned char curId = (unsigned char)i; - - // Allocate memory for the current layer. + rcHeightfieldLayer* layer = &lset.layers[i]; - memset(layer, 0, sizeof(rcHeightfieldLayer)); const int gridSize = sizeof(unsigned char)*lw*lh; @@ -528,7 +526,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, layer->cs = chf.cs; layer->ch = chf.ch; - // Adjust the bbox to fit the heighfield. + // Adjust the bbox to fit the heightfield. rcVcopy(layer->bmin, bmin); rcVcopy(layer->bmax, bmax); layer->bmin[1] = bmin[1] + hmin*chf.ch; @@ -542,7 +540,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, layer->miny = layer->height; layer->maxy = 0; - // Copy height and area from compact heighfield. + // Copy height and area from compact heightfield. for (int y = 0; y < lh; ++y) { for (int x = 0; x < lw; ++x) diff --git a/dep/recastnavigation/Recast/Source/RecastMesh.cpp b/dep/recastnavigation/Recast/Source/RecastMesh.cpp index e4f9c4b3629..c8853444019 100644 --- a/dep/recastnavigation/Recast/Source/RecastMesh.cpp +++ b/dep/recastnavigation/Recast/Source/RecastMesh.cpp @@ -160,6 +160,7 @@ static unsigned short addVertex(unsigned short x, unsigned short y, unsigned sho return (unsigned short)i; } +// Last time I checked the if version got compiled using cmov, which was a lot faster than module (with idiv). inline int prev(int i, int n) { return i-1 >= 0 ? i-1 : n-1; } inline int next(int i, int n) { return i+1 < n ? i+1 : 0; } @@ -746,7 +747,7 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short } // Remove vertex. - for (int i = (int)rem; i < mesh.nverts; ++i) + for (int i = (int)rem; i < mesh.nverts - 1; ++i) { mesh.verts[i*3+0] = mesh.verts[(i+1)*3+0]; mesh.verts[i*3+1] = mesh.verts[(i+1)*3+1]; @@ -836,7 +837,7 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short } rcScopedDelete<int> thole = (int*)rcAlloc(sizeof(int)*nhole, RC_ALLOC_TEMP); - if (!tverts) + if (!thole) { ctx->log(RC_LOG_WARNING, "removeVertex: Out of memory 'thole' (%d).", nhole); return false; @@ -875,7 +876,7 @@ static bool removeVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned short return false; } rcScopedDelete<unsigned char> pareas = (unsigned char*)rcAlloc(sizeof(unsigned char)*ntris, RC_ALLOC_TEMP); - if (!pregs) + if (!pareas) { ctx->log(RC_LOG_ERROR, "removeVertex: Out of memory 'pareas' (%d).", ntris); return false; diff --git a/dep/recastnavigation/Recast/Source/RecastMeshDetail.cpp b/dep/recastnavigation/Recast/Source/RecastMeshDetail.cpp index 5cc2adf0320..56b059d7dd5 100644 --- a/dep/recastnavigation/Recast/Source/RecastMeshDetail.cpp +++ b/dep/recastnavigation/Recast/Source/RecastMeshDetail.cpp @@ -237,8 +237,8 @@ static unsigned short getHeight(const float fx, const float fy, const float fz, enum EdgeValues { - UNDEF = -1, - HULL = -2, + EV_UNDEF = -1, + EV_HULL = -2, }; static int findEdge(const int* edges, int nedges, int s, int t) @@ -249,7 +249,7 @@ static int findEdge(const int* edges, int nedges, int s, int t) if ((e[0] == s && e[1] == t) || (e[0] == t && e[1] == s)) return i; } - return UNDEF; + return EV_UNDEF; } static int addEdge(rcContext* ctx, int* edges, int& nedges, const int maxEdges, int s, int t, int l, int r) @@ -257,12 +257,12 @@ static int addEdge(rcContext* ctx, int* edges, int& nedges, const int maxEdges, if (nedges >= maxEdges) { ctx->log(RC_LOG_ERROR, "addEdge: Too many edges (%d/%d).", nedges, maxEdges); - return UNDEF; + return EV_UNDEF; } // Add edge if not already in the triangulation. int e = findEdge(edges, nedges, s, t); - if (e == UNDEF) + if (e == EV_UNDEF) { int* edge = &edges[nedges*4]; edge[0] = s; @@ -273,15 +273,15 @@ static int addEdge(rcContext* ctx, int* edges, int& nedges, const int maxEdges, } else { - return UNDEF; + return EV_UNDEF; } } static void updateLeftFace(int* e, int s, int t, int f) { - if (e[0] == s && e[1] == t && e[2] == UNDEF) + if (e[0] == s && e[1] == t && e[2] == EV_UNDEF) e[2] = f; - else if (e[1] == s && e[0] == t && e[3] == UNDEF) + else if (e[1] == s && e[0] == t && e[3] == EV_UNDEF) e[3] = f; } @@ -322,12 +322,12 @@ static void completeFacet(rcContext* ctx, const float* pts, int npts, int* edges // Cache s and t. int s,t; - if (edge[2] == UNDEF) + if (edge[2] == EV_UNDEF) { s = edge[0]; t = edge[1]; } - else if (edge[3] == UNDEF) + else if (edge[3] == EV_UNDEF) { s = edge[1]; t = edge[0]; @@ -390,15 +390,15 @@ static void completeFacet(rcContext* ctx, const float* pts, int npts, int* edges // Add new edge or update face info of old edge. e = findEdge(edges, nedges, pt, s); - if (e == UNDEF) - addEdge(ctx, edges, nedges, maxEdges, pt, s, nfaces, UNDEF); + if (e == EV_UNDEF) + addEdge(ctx, edges, nedges, maxEdges, pt, s, nfaces, EV_UNDEF); else updateLeftFace(&edges[e*4], pt, s, nfaces); // Add new edge or update face info of old edge. e = findEdge(edges, nedges, t, pt); - if (e == UNDEF) - addEdge(ctx, edges, nedges, maxEdges, t, pt, nfaces, UNDEF); + if (e == EV_UNDEF) + addEdge(ctx, edges, nedges, maxEdges, t, pt, nfaces, EV_UNDEF); else updateLeftFace(&edges[e*4], t, pt, nfaces); @@ -406,7 +406,7 @@ static void completeFacet(rcContext* ctx, const float* pts, int npts, int* edges } else { - updateLeftFace(&edges[e*4], s, t, HULL); + updateLeftFace(&edges[e*4], s, t, EV_HULL); } } @@ -420,14 +420,14 @@ static void delaunayHull(rcContext* ctx, const int npts, const float* pts, edges.resize(maxEdges*4); for (int i = 0, j = nhull-1; i < nhull; j=i++) - addEdge(ctx, &edges[0], nedges, maxEdges, hull[j],hull[i], HULL, UNDEF); + addEdge(ctx, &edges[0], nedges, maxEdges, hull[j],hull[i], EV_HULL, EV_UNDEF); int currentEdge = 0; while (currentEdge < nedges) { - if (edges[currentEdge*4+2] == UNDEF) + if (edges[currentEdge*4+2] == EV_UNDEF) completeFacet(ctx, pts, npts, &edges[0], nedges, maxEdges, nfaces, currentEdge); - if (edges[currentEdge*4+3] == UNDEF) + if (edges[currentEdge*4+3] == EV_UNDEF) completeFacet(ctx, pts, npts, &edges[0], nedges, maxEdges, nfaces, currentEdge); currentEdge++; } @@ -507,17 +507,11 @@ static float polyMinExtent(const float* verts, const int nverts) return rcSqrt(minDist); } -inline int next(int i, int n) -{ - return (i+1) % n; -} - -inline int prev(int i, int n) -{ - return (i + n-1) % n; -} +// Last time I checked the if version got compiled using cmov, which was a lot faster than module (with idiv). +inline int prev(int i, int n) { return i-1 >= 0 ? i-1 : n-1; } +inline int next(int i, int n) { return i+1 < n ? i+1 : 0; } -static void triangulateHull(const int nverts, const float* verts, const int nhull, const int* hull, rcIntArray& tris) +static void triangulateHull(const int /*nverts*/, const float* verts, const int nhull, const int* hull, rcIntArray& tris) { int start = 0, left = 1, right = nhull-1; diff --git a/dep/recastnavigation/Recast/Source/RecastRasterization.cpp b/dep/recastnavigation/Recast/Source/RecastRasterization.cpp index 45a7d35bf3e..c3bda80cd71 100644 --- a/dep/recastnavigation/Recast/Source/RecastRasterization.cpp +++ b/dep/recastnavigation/Recast/Source/RecastRasterization.cpp @@ -50,7 +50,7 @@ static rcSpan* allocSpan(rcHeightfield& hf) // Allocate memory for the new pool. rcSpanPool* pool = (rcSpanPool*)rcAlloc(sizeof(rcSpanPool), RC_ALLOC_PERM); if (!pool) return 0; - pool->next = 0; + // Add the pool into the list of pools. pool->next = hf.pools; hf.pools = pool; diff --git a/dep/recastnavigation/Recast/Source/RecastRegion.cpp b/dep/recastnavigation/Recast/Source/RecastRegion.cpp index 38bc4ff476f..352ba579e5f 100644 --- a/dep/recastnavigation/Recast/Source/RecastRegion.cpp +++ b/dep/recastnavigation/Recast/Source/RecastRegion.cpp @@ -1041,7 +1041,7 @@ static void addUniqueConnection(rcRegion& reg, int n) static bool mergeAndFilterLayerRegions(rcContext* ctx, int minRegionArea, unsigned short& maxRegionId, rcCompactHeightfield& chf, - unsigned short* srcReg, rcIntArray& overlaps) + unsigned short* srcReg, rcIntArray& /*overlaps*/) { const int w = chf.width; const int h = chf.height; diff --git a/dep/recastnavigation/recastnavigation.diff b/dep/recastnavigation/recastnavigation.diff index 42bab6474e3..0be25bc11d1 100644 --- a/dep/recastnavigation/recastnavigation.diff +++ b/dep/recastnavigation/recastnavigation.diff @@ -1,18 +1,17 @@ -From b84e9ffbd1d1e1fb2f5d78cc53d2bb7b56c3fce3 Mon Sep 17 00:00:00 2001 +From 37b4c6d3d78ea676d8b300a282013a27a51912c1 Mon Sep 17 00:00:00 2001 From: jackpoz <giacomopoz@gmail.com> Date: Fri, 20 Jun 2014 23:15:04 +0200 Subject: [PATCH] Add custom trinitycore changes --- - Detour/Include/DetourNavMesh.h | 76 ++++++++------------------ - Detour/Source/DetourCommon.cpp | 4 +- - Detour/Source/DetourNavMesh.cpp | 32 ++++------- - Detour/Source/DetourNavMeshBuilder.cpp | 6 +- - Detour/Source/DetourNavMeshQuery.cpp | 9 +-- - Detour/Source/DetourNode.cpp | 29 +++------- - DetourCrowd/Source/DetourObstacleAvoidance.cpp | 6 +- - Recast/Include/Recast.h | 8 +-- - 8 files changed, 59 insertions(+), 111 deletions(-) + Detour/Include/DetourNavMesh.h | 76 ++++++++++++------------------------ + Detour/Source/DetourNavMesh.cpp | 30 +++++--------- + Detour/Source/DetourNavMeshQuery.cpp | 5 ++- + Detour/Source/DetourNode.cpp | 29 ++++---------- + Recast/Include/Recast.h | 8 ++-- + Recast/Source/RecastMeshDetail.cpp | 2 +- + Recast/Source/RecastRegion.cpp | 2 +- + 7 files changed, 50 insertions(+), 102 deletions(-) diff --git a/Detour/Include/DetourNavMesh.h b/Detour/Include/DetourNavMesh.h index 1060845..782ddbc 100644 @@ -177,46 +176,10 @@ index 1060845..782ddbc 100644 }; /// Allocates a navigation mesh object using the Detour allocator. -diff --git a/Detour/Source/DetourCommon.cpp b/Detour/Source/DetourCommon.cpp -index a98d8c8..b5700f5 100644 ---- a/Detour/Source/DetourCommon.cpp -+++ b/Detour/Source/DetourCommon.cpp -@@ -16,14 +16,14 @@ - // 3. This notice may not be removed or altered from any source distribution. - // - -+#include <math.h> - #include "DetourCommon.h" --#include "DetourMath.h" - - ////////////////////////////////////////////////////////////////////////////////////////// - - float dtSqrt(float x) - { -- return dtMathSqrtf(x); -+ return sqrtf(x); - } - - void dtClosestPtPointTriangle(float* closest, const float* p, diff --git a/Detour/Source/DetourNavMesh.cpp b/Detour/Source/DetourNavMesh.cpp -index 9d627be..5174050 100644 +index d353d08..e8a679b 100644 --- a/Detour/Source/DetourNavMesh.cpp +++ b/Detour/Source/DetourNavMesh.cpp -@@ -16,13 +16,13 @@ - // 3. This notice may not be removed or altered from any source distribution. - // - -+#include <math.h> - #include <float.h> - #include <string.h> - #include <stdio.h> - #include "DetourNavMesh.h" - #include "DetourNode.h" - #include "DetourCommon.h" --#include "DetourMath.h" - #include "DetourAlloc.h" - #include "DetourAssert.h" - #include <new> @@ -193,13 +193,11 @@ dtNavMesh::dtNavMesh() : m_tileLutMask(0), m_posLookup(0), @@ -270,68 +233,21 @@ index 9d627be..5174050 100644 if (tile->salt == 0) tile->salt++; -diff --git a/Detour/Source/DetourNavMeshBuilder.cpp b/Detour/Source/DetourNavMeshBuilder.cpp -index 1bf271b..9d8471b 100644 ---- a/Detour/Source/DetourNavMeshBuilder.cpp -+++ b/Detour/Source/DetourNavMeshBuilder.cpp -@@ -16,13 +16,13 @@ - // 3. This notice may not be removed or altered from any source distribution. - // - -+#include <math.h> - #include <stdio.h> - #include <stdlib.h> - #include <string.h> - #include <float.h> - #include "DetourNavMesh.h" - #include "DetourCommon.h" --#include "DetourMath.h" - #include "DetourNavMeshBuilder.h" - #include "DetourAlloc.h" - #include "DetourAssert.h" -@@ -202,8 +202,8 @@ static int createBVTree(const unsigned short* verts, const int /*nverts*/, - if (z > it.bmax[2]) it.bmax[2] = z; - } - // Remap y -- it.bmin[1] = (unsigned short)dtMathFloorf((float)it.bmin[1]*ch/cs); -- it.bmax[1] = (unsigned short)dtMathCeilf((float)it.bmax[1]*ch/cs); -+ it.bmin[1] = (unsigned short)floorf((float)it.bmin[1]*ch/cs); -+ it.bmax[1] = (unsigned short)ceilf((float)it.bmax[1]*ch/cs); - } - - int curNode = 0; diff --git a/Detour/Source/DetourNavMeshQuery.cpp b/Detour/Source/DetourNavMeshQuery.cpp -index 9debb4d..ec3a294 100644 +index 5fbc83e..fbf3724 100644 --- a/Detour/Source/DetourNavMeshQuery.cpp +++ b/Detour/Source/DetourNavMeshQuery.cpp -@@ -16,13 +16,13 @@ - // 3. This notice may not be removed or altered from any source distribution. - // - -+#include <math.h> - #include <float.h> - #include <string.h> - #include "DetourNavMeshQuery.h" - #include "DetourNavMesh.h" - #include "DetourNode.h" - #include "DetourCommon.h" --#include "DetourMath.h" - #include "DetourAlloc.h" - #include "DetourAssert.h" - #include <new> -@@ -99,8 +99,9 @@ inline float dtQueryFilter::getCost(const float* pa, const float* pb, - return dtVdist(pa, pb) * m_areaCost[curPoly->getArea()]; +@@ -100,7 +100,8 @@ inline float dtQueryFilter::getCost(const float* pa, const float* pb, } #endif -- + -static const float H_SCALE = 0.999f; // Search heuristic scale. -+ +// Edited by TC -+static const float H_SCALE = 2.0f; // Search heuristic scale. ++static const float H_SCALE = 2.0f; // Search heuristic scale. dtNavMeshQuery* dtAllocNavMeshQuery() -@@ -3504,7 +3505,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen +@@ -3501,7 +3502,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen dtVsub(hitNormal, centerPos, hitPos); dtVnormalize(hitNormal); @@ -383,42 +299,8 @@ index 5cf6548..1d18977 100644 ////////////////////////////////////////////////////////////////////////////////////////// dtNodePool::dtNodePool(int maxNodes, int hashSize) : -diff --git a/DetourCrowd/Source/DetourObstacleAvoidance.cpp b/DetourCrowd/Source/DetourObstacleAvoidance.cpp -index 0fad9ef..d3f90b7 100644 ---- a/DetourCrowd/Source/DetourObstacleAvoidance.cpp -+++ b/DetourCrowd/Source/DetourObstacleAvoidance.cpp -@@ -18,10 +18,10 @@ - - #include "DetourObstacleAvoidance.h" - #include "DetourCommon.h" --#include "DetourMath.h" - #include "DetourAlloc.h" - #include "DetourAssert.h" - #include <string.h> -+#include <math.h> - #include <float.h> - #include <new> - -@@ -58,7 +58,7 @@ static int isectRaySeg(const float* ap, const float* u, - dtVsub(v,bq,bp); - dtVsub(w,ap,bp); - float d = dtVperp2D(u,v); -- if (dtMathFabs(d) < 1e-6f) return 0; -+ if (fabsf(d) < 1e-6f) return 0; - d = 1.0f/d; - t = dtVperp2D(v,w) * d; - if (t < 0 || t > 1) return 0; -@@ -482,7 +482,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo - const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS); - const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS); - const float da = (1.0f/nd) * DT_PI*2; -- const float dang = dtMathAtan2f(dvel[2], dvel[0]); -+ const float dang = atan2f(dvel[2], dvel[0]); - - // Always add sample at zero - pat[npat*2+0] = 0; diff --git a/Recast/Include/Recast.h b/Recast/Include/Recast.h -index 83ca606..66974cd 100644 +index d8bdde2..d3e9219 100644 --- a/Recast/Include/Recast.h +++ b/Recast/Include/Recast.h @@ -243,7 +243,7 @@ struct rcConfig @@ -443,6 +325,32 @@ index 83ca606..66974cd 100644 rcSpan* next; ///< The next span higher up in column. }; +diff --git a/Recast/Source/RecastMeshDetail.cpp b/Recast/Source/RecastMeshDetail.cpp +index c0bba6f..56b059d 100644 +--- a/Recast/Source/RecastMeshDetail.cpp ++++ b/Recast/Source/RecastMeshDetail.cpp +@@ -511,7 +511,7 @@ static float polyMinExtent(const float* verts, const int nverts) + inline int prev(int i, int n) { return i-1 >= 0 ? i-1 : n-1; } + inline int next(int i, int n) { return i+1 < n ? i+1 : 0; } + +-static void triangulateHull(const int nverts, const float* verts, const int nhull, const int* hull, rcIntArray& tris) ++static void triangulateHull(const int /*nverts*/, const float* verts, const int nhull, const int* hull, rcIntArray& tris) + { + int start = 0, left = 1, right = nhull-1; + +diff --git a/Recast/Source/RecastRegion.cpp b/Recast/Source/RecastRegion.cpp +index 38bc4ff..352ba57 100644 +--- a/Recast/Source/RecastRegion.cpp ++++ b/Recast/Source/RecastRegion.cpp +@@ -1041,7 +1041,7 @@ static void addUniqueConnection(rcRegion& reg, int n) + static bool mergeAndFilterLayerRegions(rcContext* ctx, int minRegionArea, + unsigned short& maxRegionId, + rcCompactHeightfield& chf, +- unsigned short* srcReg, rcIntArray& overlaps) ++ unsigned short* srcReg, rcIntArray& /*overlaps*/) + { + const int w = chf.width; + const int h = chf.height; -- -1.9.0.msysgit.0 +1.9.5.msysgit.0 |
