diff --git a/CMakeLists.txt b/CMakeLists.txt
index 88637695..f5e422c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -618,7 +618,6 @@ list(APPEND LIBDWARFS_COMMON_SRC
src/dwarfs/internal/string_table.cpp
src/dwarfs/internal/wcwidth.c
src/dwarfs/internal/worker_group.cpp
- src/dwarfs/iolayer.cpp
src/dwarfs/library_dependencies.cpp
src/dwarfs/logger.cpp
src/dwarfs/mmap.cpp
@@ -684,7 +683,10 @@ list(APPEND LIBDWARFS_EXTRACTOR_SRC
)
list(APPEND LIBDWARFS_TOOL_SRC
+ src/dwarfs/tool/call_sys_main_iolayer.cpp
+ src/dwarfs/tool/iolayer.cpp
src/dwarfs/tool/safe_main.cpp
+ src/dwarfs/tool/sys_char.cpp
src/dwarfs/tool/tool.cpp
)
diff --git a/include/dwarfs/tool/call_sys_main_iolayer.h b/include/dwarfs/tool/call_sys_main_iolayer.h
new file mode 100644
index 00000000..7d2d31f4
--- /dev/null
+++ b/include/dwarfs/tool/call_sys_main_iolayer.h
@@ -0,0 +1,38 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/**
+ * \author Marcus Holland-Moritz (github@mhxnet.de)
+ * \copyright Copyright (c) Marcus Holland-Moritz
+ *
+ * This file is part of dwarfs.
+ *
+ * dwarfs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dwarfs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dwarfs. If not, see .
+ */
+
+#pragma once
+
+#include
+
+#include
+
+namespace dwarfs::tool {
+
+struct iolayer;
+
+int call_sys_main_iolayer(std::span args, iolayer const& iol,
+ int (*main)(int, sys_char**, iolayer const&));
+
+int call_sys_main_iolayer(std::span args, iolayer const& iol,
+ int (*main)(int, sys_char**, iolayer const&));
+
+} // namespace dwarfs::tool
diff --git a/include/dwarfs/iolayer.h b/include/dwarfs/tool/iolayer.h
similarity index 96%
rename from include/dwarfs/iolayer.h
rename to include/dwarfs/tool/iolayer.h
index 2806ad99..19987d47 100644
--- a/include/dwarfs/iolayer.h
+++ b/include/dwarfs/tool/iolayer.h
@@ -30,6 +30,8 @@ class file_access;
class os_access;
class terminal;
+namespace tool {
+
struct iolayer {
static iolayer const& system_default();
@@ -41,4 +43,6 @@ struct iolayer {
std::ostream& err;
};
+} // namespace tool
+
} // namespace dwarfs
diff --git a/include/dwarfs/program_options_helpers.h b/include/dwarfs/tool/program_options_helpers.h
similarity index 95%
rename from include/dwarfs/program_options_helpers.h
rename to include/dwarfs/tool/program_options_helpers.h
index 5fffa1b1..dcd02924 100644
--- a/include/dwarfs/program_options_helpers.h
+++ b/include/dwarfs/tool/program_options_helpers.h
@@ -25,7 +25,7 @@
#include
-namespace dwarfs {
+namespace dwarfs::tool {
#ifdef _WIN32
template
@@ -39,4 +39,4 @@ auto po_sys_value(T* v) {
}
#endif
-} // namespace dwarfs
+} // namespace dwarfs::tool
diff --git a/include/dwarfs/tool/sys_char.h b/include/dwarfs/tool/sys_char.h
new file mode 100644
index 00000000..c3ccded3
--- /dev/null
+++ b/include/dwarfs/tool/sys_char.h
@@ -0,0 +1,41 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/**
+ * \author Marcus Holland-Moritz (github@mhxnet.de)
+ * \copyright Copyright (c) Marcus Holland-Moritz
+ *
+ * This file is part of dwarfs.
+ *
+ * dwarfs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dwarfs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dwarfs. If not, see .
+ */
+
+#pragma once
+
+#include
+
+namespace dwarfs::tool {
+
+#ifdef _WIN32
+#define SYS_MAIN wmain
+using sys_char = wchar_t;
+using sys_string = std::wstring;
+#else
+#define SYS_MAIN main
+using sys_char = char;
+using sys_string = std::string;
+#endif
+
+std::string sys_string_to_string(sys_string const& in);
+sys_string string_to_sys_string(std::string const& in);
+
+} // namespace dwarfs::tool
diff --git a/include/dwarfs/tool/tool.h b/include/dwarfs/tool/tool.h
index 84faa53a..2ddec7ec 100644
--- a/include/dwarfs/tool/tool.h
+++ b/include/dwarfs/tool/tool.h
@@ -26,6 +26,8 @@
#include
+#include
+
#ifdef DWARFS_BUILTIN_MANPAGE
#include
#endif
diff --git a/include/dwarfs/tool/tool_fwd.h b/include/dwarfs/tool/tool_fwd.h
new file mode 100644
index 00000000..c098a8c2
--- /dev/null
+++ b/include/dwarfs/tool/tool_fwd.h
@@ -0,0 +1,44 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/**
+ * \author Marcus Holland-Moritz (github@mhxnet.de)
+ * \copyright Copyright (c) Marcus Holland-Moritz
+ *
+ * This file is part of dwarfs.
+ *
+ * dwarfs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dwarfs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dwarfs. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+namespace dwarfs::tool {
+
+struct iolayer;
+
+}
+
+#define DWARFS_TOOL_MAIN_DECL(tool_name) \
+ namespace dwarfs::tool { \
+ int tool_name##_main(std::span args, iolayer const& iol); \
+ int tool_name##_main(std::span args, iolayer const& iol); \
+ int tool_name##_main(int argc, sys_char** argv, iolayer const& iol); \
+ int tool_name##_main(int argc, sys_char** argv); \
+ }
diff --git a/include/dwarfs/types.h b/include/dwarfs/types.h
index 0914000f..abc8953e 100644
--- a/include/dwarfs/types.h
+++ b/include/dwarfs/types.h
@@ -22,21 +22,9 @@
#pragma once
#include
-#include
-#include
namespace dwarfs {
using file_off_t = int64_t;
-#ifdef _WIN32
-#define SYS_MAIN wmain
-using sys_char = wchar_t;
-using sys_string = std::wstring;
-#else
-#define SYS_MAIN main
-using sys_char = char;
-using sys_string = std::string;
-#endif
-
} // namespace dwarfs
diff --git a/include/dwarfs/util.h b/include/dwarfs/util.h
index 1b830b04..ac8b9b53 100644
--- a/include/dwarfs/util.h
+++ b/include/dwarfs/util.h
@@ -34,8 +34,6 @@
namespace dwarfs {
-struct iolayer;
-
std::string time_with_unit(double sec);
std::string time_with_unit(std::chrono::nanoseconds ns);
std::string size_with_unit(size_t size);
@@ -53,15 +51,6 @@ inline std::string u8string_to_string(std::u8string const& in) {
return std::string(reinterpret_cast(in.data()), in.size());
}
-std::string sys_string_to_string(sys_string const& in);
-sys_string string_to_sys_string(std::string const& in);
-
-int call_sys_main_iolayer(std::span args, iolayer const& iol,
- int (*main)(int, sys_char**, iolayer const&));
-
-int call_sys_main_iolayer(std::span args, iolayer const& iol,
- int (*main)(int, sys_char**, iolayer const&));
-
size_t utf8_display_width(char const* p, size_t len);
size_t utf8_display_width(std::string const& str);
void utf8_truncate(std::string& str, size_t len);
diff --git a/include/dwarfs_tool_main.h b/include/dwarfs_tool_main.h
index e139e3e3..8ba8d4fc 100644
--- a/include/dwarfs_tool_main.h
+++ b/include/dwarfs_tool_main.h
@@ -21,40 +21,10 @@
#pragma once
-#include
-#include
-#include
-#include
+#include
-#include
-
-namespace dwarfs {
-
-struct iolayer;
-
-int mkdwarfs_main(std::span args, iolayer const& iol);
-int mkdwarfs_main(std::span args, iolayer const& iol);
-int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol);
-int mkdwarfs_main(int argc, sys_char** argv);
-
-int dwarfsck_main(std::span args, iolayer const& iol);
-int dwarfsck_main(std::span args, iolayer const& iol);
-int dwarfsck_main(int argc, sys_char** argv, iolayer const& iol);
-int dwarfsck_main(int argc, sys_char** argv);
-
-int dwarfsextract_main(std::span args, iolayer const& iol);
-int dwarfsextract_main(std::span args, iolayer const& iol);
-int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol);
-int dwarfsextract_main(int argc, sys_char** argv);
-
-int dwarfsbench_main(std::span args, iolayer const& iol);
-int dwarfsbench_main(std::span args, iolayer const& iol);
-int dwarfsbench_main(int argc, sys_char** argv, iolayer const& iol);
-int dwarfsbench_main(int argc, sys_char** argv);
-
-int dwarfs_main(std::span args, iolayer const& iol);
-int dwarfs_main(std::span args, iolayer const& iol);
-int dwarfs_main(int argc, sys_char** argv, iolayer const& iol);
-int dwarfs_main(int argc, sys_char** argv);
-
-} // namespace dwarfs
+DWARFS_TOOL_MAIN_DECL(mkdwarfs)
+DWARFS_TOOL_MAIN_DECL(dwarfsck)
+DWARFS_TOOL_MAIN_DECL(dwarfsextract)
+DWARFS_TOOL_MAIN_DECL(dwarfsbench)
+DWARFS_TOOL_MAIN_DECL(dwarfs)
diff --git a/src/dwarfs.cpp b/src/dwarfs.cpp
index c65c6f0b..ca84ec6f 100644
--- a/src/dwarfs.cpp
+++ b/src/dwarfs.cpp
@@ -22,7 +22,7 @@
#include
#include
-int SYS_MAIN(int argc, dwarfs::sys_char** argv) {
+int SYS_MAIN(int argc, dwarfs::tool::sys_char** argv) {
return dwarfs::tool::safe_main(
- [&] { return dwarfs::dwarfs_main(argc, argv); });
+ [&] { return dwarfs::tool::dwarfs_main(argc, argv); });
}
diff --git a/src/dwarfs/tool/call_sys_main_iolayer.cpp b/src/dwarfs/tool/call_sys_main_iolayer.cpp
new file mode 100644
index 00000000..098fd64e
--- /dev/null
+++ b/src/dwarfs/tool/call_sys_main_iolayer.cpp
@@ -0,0 +1,58 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/**
+ * \author Marcus Holland-Moritz (github@mhxnet.de)
+ * \copyright Copyright (c) Marcus Holland-Moritz
+ *
+ * This file is part of dwarfs.
+ *
+ * dwarfs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dwarfs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dwarfs. If not, see .
+ */
+
+#include
+
+#include
+
+extern "C" int dwarfs_wcwidth(int ucs);
+
+namespace dwarfs::tool {
+
+namespace {
+
+template
+int call_sys_main_iolayer_impl(std::span args, iolayer const& iol,
+ int (*main)(int, sys_char**, iolayer const&)) {
+ std::vector argv;
+ std::vector argv_ptrs;
+ argv.reserve(args.size());
+ argv_ptrs.reserve(args.size());
+ for (auto const& arg : args) {
+ argv.emplace_back(string_to_sys_string(std::string(arg)));
+ argv_ptrs.emplace_back(argv.back().data());
+ }
+ return main(argv_ptrs.size(), argv_ptrs.data(), iol);
+}
+
+} // namespace
+
+int call_sys_main_iolayer(std::span args, iolayer const& iol,
+ int (*main)(int, sys_char**, iolayer const&)) {
+ return call_sys_main_iolayer_impl(args, iol, main);
+}
+
+int call_sys_main_iolayer(std::span args, iolayer const& iol,
+ int (*main)(int, sys_char**, iolayer const&)) {
+ return call_sys_main_iolayer_impl(args, iol, main);
+}
+
+} // namespace dwarfs::tool
diff --git a/src/dwarfs/iolayer.cpp b/src/dwarfs/tool/iolayer.cpp
similarity index 93%
rename from src/dwarfs/iolayer.cpp
rename to src/dwarfs/tool/iolayer.cpp
index 229a9621..58a41871 100644
--- a/src/dwarfs/iolayer.cpp
+++ b/src/dwarfs/tool/iolayer.cpp
@@ -23,11 +23,11 @@
#include
#include
-#include
#include
#include
+#include
-namespace dwarfs {
+namespace dwarfs::tool {
iolayer const& iolayer::system_default() {
static iolayer const iol{
@@ -41,4 +41,4 @@ iolayer const& iolayer::system_default() {
return iol;
}
-} // namespace dwarfs
+} // namespace dwarfs::tool
diff --git a/src/dwarfs/tool/sys_char.cpp b/src/dwarfs/tool/sys_char.cpp
new file mode 100644
index 00000000..eb3e36a2
--- /dev/null
+++ b/src/dwarfs/tool/sys_char.cpp
@@ -0,0 +1,57 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/**
+ * \author Marcus Holland-Moritz (github@mhxnet.de)
+ * \copyright Copyright (c) Marcus Holland-Moritz
+ *
+ * This file is part of dwarfs.
+ *
+ * dwarfs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dwarfs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dwarfs. If not, see .
+ */
+
+#include
+
+#if __has_include()
+#include
+#else
+#include
+#endif
+
+#include
+
+namespace dwarfs::tool {
+
+std::string sys_string_to_string(sys_string const& in) {
+#ifdef _WIN32
+ std::u16string tmp(in.size(), 0);
+ std::transform(in.begin(), in.end(), tmp.begin(),
+ [](sys_char c) { return static_cast(c); });
+ return utf8::utf16to8(tmp);
+#else
+ return in;
+#endif
+}
+
+sys_string string_to_sys_string(std::string const& in) {
+#ifdef _WIN32
+ auto tmp = utf8::utf8to16(in);
+ sys_string rv(tmp.size(), 0);
+ std::transform(tmp.begin(), tmp.end(), rv.begin(),
+ [](char16_t c) { return static_cast(c); });
+ return rv;
+#else
+ return in;
+#endif
+}
+
+} // namespace dwarfs::tool
diff --git a/src/dwarfs/tool/tool.cpp b/src/dwarfs/tool/tool.cpp
index 6f3c9087..bd221aab 100644
--- a/src/dwarfs/tool/tool.cpp
+++ b/src/dwarfs/tool/tool.cpp
@@ -28,8 +28,8 @@
#include
#ifdef DWARFS_BUILTIN_MANPAGE
-#include
#include
+#include
#include
#include
#endif
diff --git a/src/dwarfs/util.cpp b/src/dwarfs/util.cpp
index f132fdb6..ae0c7dd5 100644
--- a/src/dwarfs/util.cpp
+++ b/src/dwarfs/util.cpp
@@ -60,20 +60,6 @@ inline std::string trimmed(std::string in) {
return in;
}
-template
-int call_sys_main_iolayer_impl(std::span args, iolayer const& iol,
- int (*main)(int, sys_char**, iolayer const&)) {
- std::vector argv;
- std::vector argv_ptrs;
- argv.reserve(args.size());
- argv_ptrs.reserve(args.size());
- for (auto const& arg : args) {
- argv.emplace_back(string_to_sys_string(std::string(arg)));
- argv_ptrs.emplace_back(argv.back().data());
- }
- return main(argv_ptrs.size(), argv_ptrs.data(), iol);
-}
-
} // namespace
std::string size_with_unit(size_t size) {
@@ -205,39 +191,6 @@ file_off_t parse_image_offset(std::string const& str) {
return off.value();
}
-std::string sys_string_to_string(sys_string const& in) {
-#ifdef _WIN32
- std::u16string tmp(in.size(), 0);
- std::transform(in.begin(), in.end(), tmp.begin(),
- [](sys_char c) { return static_cast(c); });
- return utf8::utf16to8(tmp);
-#else
- return in;
-#endif
-}
-
-sys_string string_to_sys_string(std::string const& in) {
-#ifdef _WIN32
- auto tmp = utf8::utf8to16(in);
- sys_string rv(tmp.size(), 0);
- std::transform(tmp.begin(), tmp.end(), rv.begin(),
- [](char16_t c) { return static_cast(c); });
- return rv;
-#else
- return in;
-#endif
-}
-
-int call_sys_main_iolayer(std::span args, iolayer const& iol,
- int (*main)(int, sys_char**, iolayer const&)) {
- return call_sys_main_iolayer_impl(args, iol, main);
-}
-
-int call_sys_main_iolayer(std::span args, iolayer const& iol,
- int (*main)(int, sys_char**, iolayer const&)) {
- return call_sys_main_iolayer_impl(args, iol, main);
-}
-
size_t utf8_display_width(char const* p, size_t len) {
char const* const e = p + len;
size_t rv = 0;
diff --git a/src/dwarfs_main.cpp b/src/dwarfs_main.cpp
index a99a5210..5565661d 100644
--- a/src/dwarfs_main.cpp
+++ b/src/dwarfs_main.cpp
@@ -87,7 +87,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -97,6 +96,8 @@
#include
#include
#include
+#include
+#include
#include
#include
#include
@@ -140,7 +141,7 @@ FARPROC WINAPI delay_hook(unsigned dliNotify, PDelayLoadInfo pdli) {
extern "C" const PfnDliHook __pfnDliFailureHook2 = delay_hook;
#endif
-namespace dwarfs {
+namespace dwarfs::tool {
namespace {
@@ -1664,4 +1665,4 @@ int dwarfs_main(std::span args, iolayer const& iol) {
return call_sys_main_iolayer(args, iol, dwarfs_main);
}
-} // namespace dwarfs
+} // namespace dwarfs::tool
diff --git a/src/dwarfsbench.cpp b/src/dwarfsbench.cpp
index 4f8ac162..a3cfe174 100644
--- a/src/dwarfsbench.cpp
+++ b/src/dwarfsbench.cpp
@@ -22,7 +22,7 @@
#include
#include
-int SYS_MAIN(int argc, dwarfs::sys_char** argv) {
+int SYS_MAIN(int argc, dwarfs::tool::sys_char** argv) {
return dwarfs::tool::safe_main(
- [&] { return dwarfs::dwarfsbench_main(argc, argv); });
+ [&] { return dwarfs::tool::dwarfsbench_main(argc, argv); });
}
diff --git a/src/dwarfsbench_main.cpp b/src/dwarfsbench_main.cpp
index e2720b28..1d7677d7 100644
--- a/src/dwarfsbench_main.cpp
+++ b/src/dwarfsbench_main.cpp
@@ -27,19 +27,20 @@
#include
#include
#include
-#include
#include
#include
#include
#include
#include
+#include
+#include
#include
#include
#include
namespace po = boost::program_options;
-namespace dwarfs {
+namespace dwarfs::tool {
int dwarfsbench_main(int argc, sys_char** argv, iolayer const& iol) {
std::string filesystem, cache_size_str, lock_mode_str, decompress_ratio_str;
@@ -145,4 +146,4 @@ int dwarfsbench_main(std::span args, iolayer const& iol) {
return call_sys_main_iolayer(args, iol, dwarfsbench_main);
}
-} // namespace dwarfs
+} // namespace dwarfs::tool
diff --git a/src/dwarfsck.cpp b/src/dwarfsck.cpp
index 740405d8..03cf4a55 100644
--- a/src/dwarfsck.cpp
+++ b/src/dwarfsck.cpp
@@ -22,7 +22,7 @@
#include
#include
-int SYS_MAIN(int argc, dwarfs::sys_char** argv) {
+int SYS_MAIN(int argc, dwarfs::tool::sys_char** argv) {
return dwarfs::tool::safe_main(
- [&] { return dwarfs::dwarfsck_main(argc, argv); });
+ [&] { return dwarfs::tool::dwarfsck_main(argc, argv); });
}
diff --git a/src/dwarfsck_main.cpp b/src/dwarfsck_main.cpp
index aaa13855..3b7b566f 100644
--- a/src/dwarfsck_main.cpp
+++ b/src/dwarfsck_main.cpp
@@ -39,19 +39,20 @@
#include
#include
#include
-#include
#include
#include
#include
#include
#include
-#include
#include
+#include
+#include
+#include
#include
#include
#include
-namespace dwarfs {
+namespace dwarfs::tool {
namespace po = boost::program_options;
@@ -376,4 +377,4 @@ int dwarfsck_main(std::span args, iolayer const& iol) {
return call_sys_main_iolayer(args, iol, dwarfsck_main);
}
-} // namespace dwarfs
+} // namespace dwarfs::tool
diff --git a/src/dwarfsextract.cpp b/src/dwarfsextract.cpp
index bec62cd5..ce40317e 100644
--- a/src/dwarfsextract.cpp
+++ b/src/dwarfsextract.cpp
@@ -22,7 +22,7 @@
#include
#include
-int SYS_MAIN(int argc, dwarfs::sys_char** argv) {
+int SYS_MAIN(int argc, dwarfs::tool::sys_char** argv) {
return dwarfs::tool::safe_main(
- [&] { return dwarfs::dwarfsextract_main(argc, argv); });
+ [&] { return dwarfs::tool::dwarfsextract_main(argc, argv); });
}
diff --git a/src/dwarfsextract_main.cpp b/src/dwarfsextract_main.cpp
index f1e9ce0d..4112d0ca 100644
--- a/src/dwarfsextract_main.cpp
+++ b/src/dwarfsextract_main.cpp
@@ -28,22 +28,23 @@
#include
#include
-#include
#include
#include
#include
#include
#include
#include
-#include
#include
+#include
+#include
+#include
#include
#include
#include
namespace po = boost::program_options;
-namespace dwarfs {
+namespace dwarfs::tool {
namespace {
@@ -241,4 +242,4 @@ int dwarfsextract_main(std::span args, iolayer const& iol) {
return call_sys_main_iolayer(args, iol, dwarfsextract_main);
}
-} // namespace dwarfs
+} // namespace dwarfs::tool
diff --git a/src/mkdwarfs.cpp b/src/mkdwarfs.cpp
index 0f68244a..b42640d8 100644
--- a/src/mkdwarfs.cpp
+++ b/src/mkdwarfs.cpp
@@ -22,7 +22,7 @@
#include
#include
-int SYS_MAIN(int argc, dwarfs::sys_char** argv) {
+int SYS_MAIN(int argc, dwarfs::tool::sys_char** argv) {
return dwarfs::tool::safe_main(
- [&] { return dwarfs::mkdwarfs_main(argc, argv); });
+ [&] { return dwarfs::tool::mkdwarfs_main(argc, argv); });
}
diff --git a/src/mkdwarfs_main.cpp b/src/mkdwarfs_main.cpp
index 4ca3b357..aed0bcf2 100644
--- a/src/mkdwarfs_main.cpp
+++ b/src/mkdwarfs_main.cpp
@@ -70,20 +70,21 @@
#include
#include
#include
-#include
#include
#include
#include
#include
#include
#include
-#include
#include
#include
#include
#include
#include
#include
+#include
+#include
+#include
#include
#include
#include
@@ -91,7 +92,7 @@
namespace po = boost::program_options;
-namespace dwarfs {
+namespace dwarfs::tool {
namespace {
@@ -1414,4 +1415,4 @@ int mkdwarfs_main(std::span args, iolayer const& iol) {
return call_sys_main_iolayer(args, iol, mkdwarfs_main);
}
-} // namespace dwarfs
+} // namespace dwarfs::tool
diff --git a/src/pxattr.cpp b/src/pxattr.cpp
index 622676b1..6153be12 100644
--- a/src/pxattr.cpp
+++ b/src/pxattr.cpp
@@ -23,11 +23,11 @@
#include
-#include
-#include
+#include
+#include
#include
-namespace dwarfs {
+namespace dwarfs::tool {
namespace po = boost::program_options;
namespace fs = std::filesystem;
@@ -124,8 +124,8 @@ int pxattr_main(int argc, sys_char** argv) {
return 0;
}
-} // namespace dwarfs
+} // namespace dwarfs::tool
-int SYS_MAIN(int argc, dwarfs::sys_char** argv) {
- return dwarfs::pxattr_main(argc, argv);
+int SYS_MAIN(int argc, dwarfs::tool::sys_char** argv) {
+ return dwarfs::tool::pxattr_main(argc, argv);
}
diff --git a/src/universal.cpp b/src/universal.cpp
index 59f04b6a..acc5fb07 100644
--- a/src/universal.cpp
+++ b/src/universal.cpp
@@ -20,6 +20,7 @@
*/
#include
+#include
#include
#include
#include
@@ -35,12 +36,11 @@
#include
#include
-#include
#include
namespace {
-using namespace dwarfs;
+using namespace dwarfs::tool;
#ifdef _WIN32
#define EXE_EXT ".exe"
@@ -66,7 +66,7 @@ int SYS_MAIN(int argc, sys_char** argv) {
if (auto ext = path.extension().string(); ext.empty() || ext == EXE_EXT) {
auto stem = path.stem().string();
if (auto it = functions.find(stem); it != functions.end()) {
- return tool::safe_main([&] { return it->second(argc, argv); });
+ return safe_main([&] { return it->second(argc, argv); });
}
}
@@ -80,7 +80,7 @@ int SYS_MAIN(int argc, sys_char** argv) {
argv_copy.reserve(argc - 1);
argv_copy.emplace_back(argv[0]);
std::copy(argv + 2, argv + argc, std::back_inserter(argv_copy));
- return tool::safe_main(
+ return safe_main(
[&] { return it->second(argc - 1, argv_copy.data()); });
}
}
@@ -92,7 +92,7 @@ int SYS_MAIN(int argc, sys_char** argv) {
ranges::to;
// clang-format off
- std::cout << tool::tool_header("dwarfs-universal")
+ std::cout << tool_header("dwarfs-universal")
<< "Command line options:\n"
<< " --tool= "
"which tool to run; available tools are:\n"
diff --git a/test/test_helpers.h b/test/test_helpers.h
index 9b569c28..aecc052f 100644
--- a/test/test_helpers.h
+++ b/test/test_helpers.h
@@ -41,10 +41,10 @@
#include
#include
#include
-#include
#include
#include
#include
+#include
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
@@ -302,7 +302,7 @@ class test_iolayer {
std::shared_ptr fa);
~test_iolayer();
- iolayer const& get();
+ tool::iolayer const& get();
std::string out() const;
std::string err() const;
@@ -327,7 +327,7 @@ class test_iolayer {
std::istringstream in_;
std::ostringstream out_;
std::ostringstream err_;
- std::unique_ptr iol_;
+ std::unique_ptr iol_;
std::shared_ptr real_term_;
};
diff --git a/test/test_iolayer.cpp b/test/test_iolayer.cpp
index 2cfc1e90..a1559e4c 100644
--- a/test/test_iolayer.cpp
+++ b/test/test_iolayer.cpp
@@ -315,10 +315,10 @@ test_iolayer::test_iolayer(std::shared_ptr os,
test_iolayer::~test_iolayer() = default;
-iolayer const& test_iolayer::get() {
+tool::iolayer const& test_iolayer::get() {
if (!iol_) {
if (real_term_) {
- iol_ = std::make_unique(iolayer{
+ iol_ = std::make_unique(tool::iolayer{
.os = os_,
.term = real_term_,
.file = fa_,
@@ -327,7 +327,7 @@ iolayer const& test_iolayer::get() {
.err = std::cerr,
});
} else {
- iol_ = std::make_unique(iolayer{
+ iol_ = std::make_unique(tool::iolayer{
.os = os_,
.term = term_,
.file = fa_,
diff --git a/test/tool_main_test.cpp b/test/tool_main_test.cpp
index f8c3631b..73dea123 100644
--- a/test/tool_main_test.cpp
+++ b/test/tool_main_test.cpp
@@ -58,6 +58,8 @@ using namespace dwarfs;
namespace fs = std::filesystem;
+using tool::iolayer;
+
namespace {
// TODO: this is a workaround for older Clang versions
@@ -167,7 +169,7 @@ auto constexpr default_fs_opts = filesystem_options{
class mkdwarfs_tester : public tester_common {
public:
mkdwarfs_tester(std::shared_ptr pos)
- : tester_common(mkdwarfs_main, "mkdwarfs", std::move(pos)) {}
+ : tester_common(tool::mkdwarfs_main, "mkdwarfs", std::move(pos)) {}
mkdwarfs_tester()
: mkdwarfs_tester(test::os_access_mock::create_test_instance()) {}
@@ -322,7 +324,7 @@ build_test_image(std::vector extra_args = {},
class dwarfsck_tester : public tester_common {
public:
dwarfsck_tester(std::shared_ptr pos)
- : tester_common(dwarfsck_main, "dwarfsck", std::move(pos)) {}
+ : tester_common(tool::dwarfsck_main, "dwarfsck", std::move(pos)) {}
dwarfsck_tester()
: dwarfsck_tester(std::make_shared()) {}
@@ -342,7 +344,8 @@ class dwarfsck_tester : public tester_common {
class dwarfsextract_tester : public tester_common {
public:
dwarfsextract_tester(std::shared_ptr pos)
- : tester_common(dwarfsextract_main, "dwarfsextract", std::move(pos)) {}
+ : tester_common(tool::dwarfsextract_main, "dwarfsextract",
+ std::move(pos)) {}
dwarfsextract_tester()
: dwarfsextract_tester(std::make_shared()) {}