diff --git a/fmt/CMakeLists.txt b/fmt/CMakeLists.txt index 5a96c412..9e491f93 100644 --- a/fmt/CMakeLists.txt +++ b/fmt/CMakeLists.txt @@ -1,6 +1,6 @@ # Define the fmt library, its includes and the needed defines. -# format.cc is added to FMT_HEADERS for the header-only configuration. -set(FMT_HEADERS format.h format.cc ostream.h ostream.cc printf.h +# *.cc are added to FMT_HEADERS for the header-only configuration. +set(FMT_HEADERS format.h format.cc ostream.h ostream.cc printf.h printf.cc string.h time.h) if (HAVE_OPEN) set(FMT_HEADERS ${FMT_HEADERS} posix.h) diff --git a/fmt/format.cc b/fmt/format.cc index 607314e9..ab460242 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -26,7 +26,6 @@ */ #include "format.h" -#include "printf.h" #include @@ -106,8 +105,6 @@ inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) { # define FMT_SWPRINTF swprintf #endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT) -const char RESET_COLOR[] = "\x1b[0m"; - typedef void (*FormatFunc)(Writer &, int, StringRef); // Portable thread-safe version of strerror. @@ -486,34 +483,6 @@ FMT_FUNC void report_windows_error( } #endif -FMT_FUNC void 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 print(CStringRef format_str, ArgList args) { - print(stdout, format_str, args); -} - -FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) { - char escape[] = "\x1b[30m"; - escape[3] = static_cast('0' + c); - std::fputs(escape, stdout); - print(format, args); - std::fputs(RESET_COLOR, stdout); -} - -template -void printf(BasicWriter &w, BasicCStringRef format, ArgList args); - -FMT_FUNC int fprintf(std::FILE *f, CStringRef format, ArgList args) { - MemoryWriter w; - printf(w, format, args); - std::size_t size = w.size(); - return std::fwrite(w.data(), 1, size, f) < size ? -1 : static_cast(size); -} - #ifndef FMT_HEADER_ONLY template struct internal::BasicData; @@ -524,8 +493,6 @@ template void internal::FixedBuffer::grow(std::size_t); template void internal::ArgMap::init(const ArgList &args); -template void PrintfFormatter::format(CStringRef format); - template int internal::CharTraits::format_float( char *buffer, std::size_t size, const char *format, unsigned width, int precision, double value); @@ -540,8 +507,6 @@ template void internal::FixedBuffer::grow(std::size_t); template void internal::ArgMap::init(const ArgList &args); -template void PrintfFormatter::format(WCStringRef format); - template int internal::CharTraits::format_float( wchar_t *buffer, std::size_t size, const wchar_t *format, unsigned width, int precision, double value); diff --git a/fmt/printf.cc b/fmt/printf.cc new file mode 100644 index 00000000..be523447 --- /dev/null +++ b/fmt/printf.cc @@ -0,0 +1,56 @@ +/* + Formatting library for C++ + + Copyright (c) 2012 - 2016, Victor Zverovich + All rights reserved. + + For the license information refer to format.h. + */ + +#include "format.h" +#include "printf.h" + +namespace fmt { + +namespace { + +const char RESET_COLOR[] = "\x1b[0m"; + +} // namespace + +FMT_FUNC void 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 print(CStringRef format_str, ArgList args) { + print(stdout, format_str, args); +} + +FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) { + char escape[] = "\x1b[30m"; + escape[3] = static_cast('0' + c); + std::fputs(escape, stdout); + print(format, args); + std::fputs(RESET_COLOR, stdout); +} + +template +void printf(BasicWriter &w, BasicCStringRef format, ArgList args); + +FMT_FUNC int fprintf(std::FILE *f, CStringRef format, ArgList args) { + MemoryWriter w; + printf(w, format, args); + std::size_t size = w.size(); + return std::fwrite(w.data(), 1, size, f) < size ? -1 : static_cast(size); +} + +#ifndef FMT_HEADER_ONLY + +template void PrintfFormatter::format(CStringRef format); +template void PrintfFormatter::format(WCStringRef format); + +#endif // FMT_HEADER_ONLY + +} // namespace fmt diff --git a/fmt/printf.h b/fmt/printf.h index 0e6af603..80d22441 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -555,4 +555,8 @@ inline int fprintf(std::ostream &os, CStringRef format_str, ArgList args) { FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef) } // namespace fmt +#ifdef FMT_HEADER_ONLY +# include "printf.cc" +#endif + #endif // FMT_PRINTF_H_ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 86e72b97..b805955e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -99,7 +99,7 @@ endif () if (HAVE_OPEN) add_fmt_executable(posix-mock-test - posix-mock-test.cc ../fmt/format.cc ${TEST_MAIN_SRC}) + posix-mock-test.cc ../fmt/format.cc ../fmt/printf.cc ${TEST_MAIN_SRC}) target_include_directories(posix-mock-test PRIVATE ${PROJECT_SOURCE_DIR}) target_compile_definitions(posix-mock-test PRIVATE FMT_USE_FILE_DESCRIPTORS=1) target_link_libraries(posix-mock-test gmock) diff --git a/test/add-subdirectory-test/main.cc b/test/add-subdirectory-test/main.cc index f39f377c..4585ea1b 100644 --- a/test/add-subdirectory-test/main.cc +++ b/test/add-subdirectory-test/main.cc @@ -1,4 +1,4 @@ -#include "fmt/format.h" +#include "fmt/printf.h" int main(int argc, char** argv) { for(int i = 0; i < argc; ++i) diff --git a/test/find-package-test/main.cc b/test/find-package-test/main.cc index f39f377c..4585ea1b 100644 --- a/test/find-package-test/main.cc +++ b/test/find-package-test/main.cc @@ -1,4 +1,4 @@ -#include "fmt/format.h" +#include "fmt/printf.h" int main(int argc, char** argv) { for(int i = 0; i < argc; ++i) diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index e29a6fe6..9fe2a7ec 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -28,8 +28,9 @@ #define FMT_NOEXCEPT #include "test-assert.h" -// Include format.cc instead of format.h to test implementation-specific stuff. +// Include *.cc instead of *.h to test implementation-specific stuff. #include "fmt/format.cc" +#include "fmt/printf.cc" #include #include