mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 04:19:10 -04:00
refactor: move more code to tool namespace
This commit is contained in:
parent
b0575d6a0c
commit
db75114105
@ -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
|
||||
)
|
||||
|
||||
|
38
include/dwarfs/tool/call_sys_main_iolayer.h
Normal file
38
include/dwarfs/tool/call_sys_main_iolayer.h
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
|
||||
#include <dwarfs/tool/sys_char.h>
|
||||
|
||||
namespace dwarfs::tool {
|
||||
|
||||
struct iolayer;
|
||||
|
||||
int call_sys_main_iolayer(std::span<std::string_view> args, iolayer const& iol,
|
||||
int (*main)(int, sys_char**, iolayer const&));
|
||||
|
||||
int call_sys_main_iolayer(std::span<std::string> args, iolayer const& iol,
|
||||
int (*main)(int, sys_char**, iolayer const&));
|
||||
|
||||
} // namespace dwarfs::tool
|
@ -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
|
@ -25,7 +25,7 @@
|
||||
|
||||
#include <dwarfs/types.h>
|
||||
|
||||
namespace dwarfs {
|
||||
namespace dwarfs::tool {
|
||||
|
||||
#ifdef _WIN32
|
||||
template <typename T>
|
||||
@ -39,4 +39,4 @@ auto po_sys_value(T* v) {
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace dwarfs
|
||||
} // namespace dwarfs::tool
|
41
include/dwarfs/tool/sys_char.h
Normal file
41
include/dwarfs/tool/sys_char.h
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
@ -26,6 +26,8 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <dwarfs/tool/call_sys_main_iolayer.h>
|
||||
|
||||
#ifdef DWARFS_BUILTIN_MANPAGE
|
||||
#include <dwarfs/tool/manpage.h>
|
||||
#endif
|
||||
|
44
include/dwarfs/tool/tool_fwd.h
Normal file
44
include/dwarfs/tool/tool_fwd.h
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iosfwd>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <dwarfs/tool/sys_char.h>
|
||||
#include <dwarfs/tool/tool_fwd.h>
|
||||
|
||||
namespace dwarfs::tool {
|
||||
|
||||
struct iolayer;
|
||||
|
||||
}
|
||||
|
||||
#define DWARFS_TOOL_MAIN_DECL(tool_name) \
|
||||
namespace dwarfs::tool { \
|
||||
int tool_name##_main(std::span<std::string> args, iolayer const& iol); \
|
||||
int tool_name##_main(std::span<std::string_view> 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); \
|
||||
}
|
@ -22,21 +22,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
@ -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<char const*>(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<std::string_view> args, iolayer const& iol,
|
||||
int (*main)(int, sys_char**, iolayer const&));
|
||||
|
||||
int call_sys_main_iolayer(std::span<std::string> 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);
|
||||
|
@ -21,40 +21,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iosfwd>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <dwarfs/tool/tool_fwd.h>
|
||||
|
||||
#include <dwarfs/types.h>
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
struct iolayer;
|
||||
|
||||
int mkdwarfs_main(std::span<std::string> args, iolayer const& iol);
|
||||
int mkdwarfs_main(std::span<std::string_view> 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<std::string> args, iolayer const& iol);
|
||||
int dwarfsck_main(std::span<std::string_view> 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<std::string> args, iolayer const& iol);
|
||||
int dwarfsextract_main(std::span<std::string_view> 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<std::string> args, iolayer const& iol);
|
||||
int dwarfsbench_main(std::span<std::string_view> 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<std::string> args, iolayer const& iol);
|
||||
int dwarfs_main(std::span<std::string_view> 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)
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <dwarfs/tool/safe_main.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
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); });
|
||||
}
|
||||
|
58
src/dwarfs/tool/call_sys_main_iolayer.cpp
Normal file
58
src/dwarfs/tool/call_sys_main_iolayer.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <dwarfs/tool/call_sys_main_iolayer.h>
|
||||
|
||||
extern "C" int dwarfs_wcwidth(int ucs);
|
||||
|
||||
namespace dwarfs::tool {
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
int call_sys_main_iolayer_impl(std::span<T> args, iolayer const& iol,
|
||||
int (*main)(int, sys_char**, iolayer const&)) {
|
||||
std::vector<sys_string> argv;
|
||||
std::vector<sys_char*> 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<std::string_view> 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<std::string> args, iolayer const& iol,
|
||||
int (*main)(int, sys_char**, iolayer const&)) {
|
||||
return call_sys_main_iolayer_impl(args, iol, main);
|
||||
}
|
||||
|
||||
} // namespace dwarfs::tool
|
@ -23,11 +23,11 @@
|
||||
|
||||
#include <dwarfs/file_access.h>
|
||||
#include <dwarfs/file_access_generic.h>
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/os_access_generic.h>
|
||||
#include <dwarfs/terminal.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
|
||||
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
|
57
src/dwarfs/tool/sys_char.cpp
Normal file
57
src/dwarfs/tool/sys_char.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#if __has_include(<utf8cpp/utf8.h>)
|
||||
#include <utf8cpp/utf8.h>
|
||||
#else
|
||||
#include <utf8.h>
|
||||
#endif
|
||||
|
||||
#include <dwarfs/tool/sys_char.h>
|
||||
|
||||
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<char16_t>(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<sys_char>(c); });
|
||||
return rv;
|
||||
#else
|
||||
return in;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace dwarfs::tool
|
@ -28,8 +28,8 @@
|
||||
#include <dwarfs/version.h>
|
||||
|
||||
#ifdef DWARFS_BUILTIN_MANPAGE
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/terminal.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
#include <dwarfs/tool/pager.h>
|
||||
#include <dwarfs/tool/render_manpage.h>
|
||||
#endif
|
||||
|
@ -60,20 +60,6 @@ inline std::string trimmed(std::string in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int call_sys_main_iolayer_impl(std::span<T> args, iolayer const& iol,
|
||||
int (*main)(int, sys_char**, iolayer const&)) {
|
||||
std::vector<sys_string> argv;
|
||||
std::vector<sys_char*> 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<char16_t>(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<sys_char>(c); });
|
||||
return rv;
|
||||
#else
|
||||
return in;
|
||||
#endif
|
||||
}
|
||||
|
||||
int call_sys_main_iolayer(std::span<std::string_view> 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<std::string> 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;
|
||||
|
@ -87,7 +87,6 @@
|
||||
#include <dwarfs/file_stat.h>
|
||||
#include <dwarfs/filesystem_v2.h>
|
||||
#include <dwarfs/fstypes.h>
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/iovec_read_buf.h>
|
||||
#include <dwarfs/library_dependencies.h>
|
||||
#include <dwarfs/logger.h>
|
||||
@ -97,6 +96,8 @@
|
||||
#include <dwarfs/performance_monitor.h>
|
||||
#include <dwarfs/scope_exit.h>
|
||||
#include <dwarfs/string.h>
|
||||
#include <dwarfs/tool/call_sys_main_iolayer.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
#include <dwarfs/tool/tool.h>
|
||||
#include <dwarfs/util.h>
|
||||
#include <dwarfs/version.h>
|
||||
@ -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<std::string_view> args, iolayer const& iol) {
|
||||
return call_sys_main_iolayer(args, iol, dwarfs_main);
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
} // namespace dwarfs::tool
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <dwarfs/tool/safe_main.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
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); });
|
||||
}
|
||||
|
@ -27,19 +27,20 @@
|
||||
#include <dwarfs/file_stat.h>
|
||||
#include <dwarfs/filesystem_v2.h>
|
||||
#include <dwarfs/fstypes.h>
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/library_dependencies.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/mmap.h>
|
||||
#include <dwarfs/options.h>
|
||||
#include <dwarfs/thread_pool.h>
|
||||
#include <dwarfs/tool/call_sys_main_iolayer.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
#include <dwarfs/tool/tool.h>
|
||||
#include <dwarfs/util.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
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<std::string_view> args, iolayer const& iol) {
|
||||
return call_sys_main_iolayer(args, iol, dwarfsbench_main);
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
} // namespace dwarfs::tool
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <dwarfs/tool/safe_main.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
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); });
|
||||
}
|
||||
|
@ -39,19 +39,20 @@
|
||||
#include <dwarfs/error.h>
|
||||
#include <dwarfs/file_access.h>
|
||||
#include <dwarfs/filesystem_v2.h>
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/library_dependencies.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/mmap.h>
|
||||
#include <dwarfs/options.h>
|
||||
#include <dwarfs/os_access.h>
|
||||
#include <dwarfs/program_options_helpers.h>
|
||||
#include <dwarfs/thread_pool.h>
|
||||
#include <dwarfs/tool/call_sys_main_iolayer.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
#include <dwarfs/tool/program_options_helpers.h>
|
||||
#include <dwarfs/tool/tool.h>
|
||||
#include <dwarfs/util.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
namespace dwarfs {
|
||||
namespace dwarfs::tool {
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
@ -376,4 +377,4 @@ int dwarfsck_main(std::span<std::string_view> args, iolayer const& iol) {
|
||||
return call_sys_main_iolayer(args, iol, dwarfsck_main);
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
} // namespace dwarfs::tool
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <dwarfs/tool/safe_main.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
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); });
|
||||
}
|
||||
|
@ -28,22 +28,23 @@
|
||||
|
||||
#include <dwarfs/filesystem_extractor.h>
|
||||
#include <dwarfs/filesystem_v2.h>
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/library_dependencies.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/mmap.h>
|
||||
#include <dwarfs/options.h>
|
||||
#include <dwarfs/os_access.h>
|
||||
#include <dwarfs/performance_monitor.h>
|
||||
#include <dwarfs/program_options_helpers.h>
|
||||
#include <dwarfs/string.h>
|
||||
#include <dwarfs/tool/call_sys_main_iolayer.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
#include <dwarfs/tool/program_options_helpers.h>
|
||||
#include <dwarfs/tool/tool.h>
|
||||
#include <dwarfs/util.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace dwarfs {
|
||||
namespace dwarfs::tool {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -241,4 +242,4 @@ int dwarfsextract_main(std::span<std::string_view> args, iolayer const& iol) {
|
||||
return call_sys_main_iolayer(args, iol, dwarfsextract_main);
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
} // namespace dwarfs::tool
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <dwarfs/tool/safe_main.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
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); });
|
||||
}
|
||||
|
@ -70,20 +70,21 @@
|
||||
#include <dwarfs/filter_debug.h>
|
||||
#include <dwarfs/fragment_order_parser.h>
|
||||
#include <dwarfs/integral_value_parser.h>
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/library_dependencies.h>
|
||||
#include <dwarfs/logger.h>
|
||||
#include <dwarfs/match.h>
|
||||
#include <dwarfs/mmap.h>
|
||||
#include <dwarfs/options.h>
|
||||
#include <dwarfs/os_access.h>
|
||||
#include <dwarfs/program_options_helpers.h>
|
||||
#include <dwarfs/scanner.h>
|
||||
#include <dwarfs/script.h>
|
||||
#include <dwarfs/segmenter_factory.h>
|
||||
#include <dwarfs/string.h>
|
||||
#include <dwarfs/terminal.h>
|
||||
#include <dwarfs/thread_pool.h>
|
||||
#include <dwarfs/tool/call_sys_main_iolayer.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
#include <dwarfs/tool/program_options_helpers.h>
|
||||
#include <dwarfs/tool/tool.h>
|
||||
#include <dwarfs/util.h>
|
||||
#include <dwarfs/writer_progress.h>
|
||||
@ -91,7 +92,7 @@
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace dwarfs {
|
||||
namespace dwarfs::tool {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -1414,4 +1415,4 @@ int mkdwarfs_main(std::span<std::string_view> args, iolayer const& iol) {
|
||||
return call_sys_main_iolayer(args, iol, mkdwarfs_main);
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
} // namespace dwarfs::tool
|
||||
|
@ -23,11 +23,11 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <dwarfs/program_options_helpers.h>
|
||||
#include <dwarfs/types.h>
|
||||
#include <dwarfs/tool/program_options_helpers.h>
|
||||
#include <dwarfs/tool/sys_char.h>
|
||||
#include <dwarfs/xattr.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
@ -35,12 +36,11 @@
|
||||
|
||||
#include <dwarfs/tool/safe_main.h>
|
||||
#include <dwarfs/tool/tool.h>
|
||||
#include <dwarfs/util.h>
|
||||
#include <dwarfs_tool_main.h>
|
||||
|
||||
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<std::string>;
|
||||
|
||||
// clang-format off
|
||||
std::cout << tool::tool_header("dwarfs-universal")
|
||||
std::cout << tool_header("dwarfs-universal")
|
||||
<< "Command line options:\n"
|
||||
<< " --tool=<name> "
|
||||
"which tool to run; available tools are:\n"
|
||||
|
@ -41,10 +41,10 @@
|
||||
#include <dwarfs/entry_interface.h>
|
||||
#include <dwarfs/file_access.h>
|
||||
#include <dwarfs/file_stat.h>
|
||||
#include <dwarfs/iolayer.h>
|
||||
#include <dwarfs/os_access.h>
|
||||
#include <dwarfs/script.h>
|
||||
#include <dwarfs/terminal.h>
|
||||
#include <dwarfs/tool/iolayer.h>
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(address_sanitizer)
|
||||
@ -302,7 +302,7 @@ class test_iolayer {
|
||||
std::shared_ptr<file_access const> 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<iolayer> iol_;
|
||||
std::unique_ptr<tool::iolayer> iol_;
|
||||
std::shared_ptr<terminal const> real_term_;
|
||||
};
|
||||
|
||||
|
@ -315,10 +315,10 @@ test_iolayer::test_iolayer(std::shared_ptr<os_access const> 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>(iolayer{
|
||||
iol_ = std::make_unique<tool::iolayer>(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>(iolayer{
|
||||
iol_ = std::make_unique<tool::iolayer>(tool::iolayer{
|
||||
.os = os_,
|
||||
.term = term_,
|
||||
.file = fa_,
|
||||
|
@ -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<test::os_access_mock> 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<std::string> extra_args = {},
|
||||
class dwarfsck_tester : public tester_common {
|
||||
public:
|
||||
dwarfsck_tester(std::shared_ptr<test::os_access_mock> 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<test::os_access_mock>()) {}
|
||||
@ -342,7 +344,8 @@ class dwarfsck_tester : public tester_common {
|
||||
class dwarfsextract_tester : public tester_common {
|
||||
public:
|
||||
dwarfsextract_tester(std::shared_ptr<test::os_access_mock> 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<test::os_access_mock>()) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user