From 535b6cbf8ea11bc59fd1f27f17617ed8c17cc8ee Mon Sep 17 00:00:00 2001 From: heinezen Date: Thu, 31 Oct 2024 17:44:53 +0100 Subject: [PATCH 1/2] etc: clang-format rule for preprocessor indentation. --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 9264f3bc0f..4191b164f7 100644 --- a/.clang-format +++ b/.clang-format @@ -81,7 +81,7 @@ IndentCaseBlocks: false IndentCaseLabels: false IndentExternBlock: NoIndent IndentGotoLabels: false -IndentPPDirectives: None +IndentPPDirectives: BeforeHash IndentWidth: 4 IndentWrappedFunctionNames: false # clang-format-16 InsertNewlineAtEOF: true From 3c47b65f5a8afdb69b01239993842c439ca3c08a Mon Sep 17 00:00:00 2001 From: heinezen Date: Thu, 31 Oct 2024 18:05:49 +0100 Subject: [PATCH 2/2] refactor: Format cpp files with preprocessor code. --- libopenage/console/tests.cpp | 18 ++--- libopenage/engine/engine.h | 6 +- libopenage/error/handlers.cpp | 6 +- libopenage/error/stackanalyzer.cpp | 20 +++--- libopenage/event/demo/gui.cpp | 32 ++++----- libopenage/event/demo/gui.h | 18 ++--- libopenage/event/demo/main.cpp | 12 ++-- libopenage/event/demo/physics.cpp | 24 +++---- libopenage/log/level.h | 10 +-- libopenage/log/message.h | 6 +- libopenage/log/stdout_logsink.cpp | 6 +- libopenage/renderer/color.cpp | 13 ++-- .../guisys/private/opengl_debug_logger.cpp | 12 ++-- libopenage/renderer/vulkan/loader.cpp | 24 +++---- libopenage/util/compiler.cpp | 40 ++++++----- libopenage/util/fds.cpp | 47 ++++++------ libopenage/util/fds.h | 2 +- libopenage/util/fslike/directory.cpp | 72 ++++++++----------- libopenage/util/macro/concat.h | 22 +++--- libopenage/util/macro/loop.h | 22 +++--- libopenage/util/os.cpp | 45 ++++++------ libopenage/util/pty.h | 12 ++-- libopenage/util/strings.h | 4 +- libopenage/util/subprocess.cpp | 22 +++--- libopenage/util/thread_id.cpp | 20 +++--- libopenage/versions/versions.cpp | 4 +- 26 files changed, 253 insertions(+), 266 deletions(-) diff --git a/libopenage/console/tests.cpp b/libopenage/console/tests.cpp index 445fb71b30..7da8dd02f4 100644 --- a/libopenage/console/tests.cpp +++ b/libopenage/console/tests.cpp @@ -1,12 +1,12 @@ -// Copyright 2014-2019 the openage authors. See copying.md for legal info. +// Copyright 2014-2024 the openage authors. See copying.md for legal info. -#include #include +#include #ifdef _MSC_VER -#define STDOUT_FILENO 1 + #define STDOUT_FILENO 1 #else -#include + #include #endif #include "../util/fds.h" #include "../util/pty.h" @@ -15,8 +15,8 @@ #include #include -#include "../log/log.h" #include "../error/error.h" +#include "../log/log.h" #include "buf.h" #include "console.h" @@ -51,7 +51,7 @@ void render() { void interactive() { - #ifndef _WIN32 +#ifndef _WIN32 console::Buf buf{{80, 25}, 1337, 80}; struct winsize ws; @@ -75,7 +75,7 @@ void interactive() { throw Error(MSG(err) << "execl(\"" << shell << "\", \"" << shell << "\", nullptr) failed: " << strerror(errno)); } default: - //we are the parent + // we are the parent break; } @@ -143,7 +143,7 @@ void interactive() { ssize_t retval = read(ptyin.fd, rdbuf, rdbuf_size); switch (retval) { case -1: - switch(errno) { + switch (errno) { case EIO: loop = false; break; @@ -175,7 +175,7 @@ void interactive() { // show cursor termout.puts("\x1b[?25h"); - #endif /* _WIN32 */ +#endif /* _WIN32 */ } diff --git a/libopenage/engine/engine.h b/libopenage/engine/engine.h index 4f96ae74bf..1fe4298061 100644 --- a/libopenage/engine/engine.h +++ b/libopenage/engine/engine.h @@ -11,7 +11,7 @@ // TODO: Remove custom jthread definition when clang/libc++ finally supports it #if __llvm__ -#if !__cpp_lib_jthread + #if !__cpp_lib_jthread namespace std { class jthread : public thread { public: @@ -27,9 +27,9 @@ class jthread : public thread { } }; } // namespace std -#endif + #endif #else -#include + #include #endif diff --git a/libopenage/error/handlers.cpp b/libopenage/error/handlers.cpp index f608b0e78f..b3e61450b2 100644 --- a/libopenage/error/handlers.cpp +++ b/libopenage/error/handlers.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. /* * This file holds handlers for std::terminate and SIGSEGV. @@ -17,9 +17,9 @@ #include #ifdef _MSC_VER -#include + #include #else -#include + #include #endif #include "util/init.h" diff --git a/libopenage/error/stackanalyzer.cpp b/libopenage/error/stackanalyzer.cpp index 878cb01025..cc04dae05d 100644 --- a/libopenage/error/stackanalyzer.cpp +++ b/libopenage/error/stackanalyzer.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #include "stackanalyzer.h" @@ -30,8 +30,8 @@ constexpr uint64_t base_skip_frames = 1; #if WITH_BACKTRACE -// use modern -#include + // use modern + #include namespace openage { namespace error { @@ -59,7 +59,7 @@ struct backtrace_state *bt_state; util::OnInit init_backtrace_state([]() { bt_state = backtrace_create_state( nullptr, // auto-determine filename - 1, // threaded + 1, // threaded backtrace_error_callback, nullptr // passed to the callback ); @@ -189,8 +189,8 @@ void StackAnalyzer::get_symbols(std::function cb #else // WITHOUT_BACKTRACE -#ifdef _WIN32 -#include + #ifdef _WIN32 + #include namespace openage { namespace error { @@ -208,10 +208,10 @@ void StackAnalyzer::analyze() { } // namespace error } // namespace openage -#else // not _MSC_VER + #else // not _MSC_VER -// use GNU's -#include + // use GNU's + #include namespace openage::error { @@ -256,7 +256,7 @@ void StackAnalyzer::analyze() { } // namespace openage::error -#endif // for _MSC_VER or GNU execinfo + #endif // for _MSC_VER or GNU execinfo namespace openage::error { diff --git a/libopenage/event/demo/gui.cpp b/libopenage/event/demo/gui.cpp index 100509c0f4..66d0bbf79d 100644 --- a/libopenage/event/demo/gui.cpp +++ b/libopenage/event/demo/gui.cpp @@ -1,25 +1,25 @@ -// Copyright 2016-2023 the openage authors. See copying.md for legal info. +// Copyright 2016-2024 the openage authors. See copying.md for legal info. #include "gui.h" // the gui requires ncurses. #if WITH_NCURSES -#include -#include -#include -#include -#ifdef __MINGW32__ -#include -#else -#include -#endif // __MINGW32__ -#include - -#include "curve/continuous.h" -#include "curve/discrete.h" -#include "event/demo/gamestate.h" -#include "util/fixed_point.h" + #include + #include + #include + #include + #ifdef __MINGW32__ + #include + #else + #include + #endif // __MINGW32__ + #include + + #include "curve/continuous.h" + #include "curve/discrete.h" + #include "event/demo/gamestate.h" + #include "util/fixed_point.h" namespace openage::event::demo { diff --git a/libopenage/event/demo/gui.h b/libopenage/event/demo/gui.h index de21a99d02..8e447d808f 100644 --- a/libopenage/event/demo/gui.h +++ b/libopenage/event/demo/gui.h @@ -1,18 +1,18 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #pragma once #include "config.h" #if WITH_NCURSES -#include -#include -#include -#include - -#include "event/demo/gamestate.h" -#include "time/time.h" -#include "util/vector.h" + #include + #include + #include + #include + + #include "event/demo/gamestate.h" + #include "time/time.h" + #include "util/vector.h" namespace openage::event::demo { diff --git a/libopenage/event/demo/main.cpp b/libopenage/event/demo/main.cpp index 3ccbed5ac6..f5100b2e82 100644 --- a/libopenage/event/demo/main.cpp +++ b/libopenage/event/demo/main.cpp @@ -1,4 +1,4 @@ -// Copyright 2016-2023 the openage authors. See copying.md for legal info. +// Copyright 2016-2024 the openage authors. See copying.md for legal info. #include "main.h" @@ -16,11 +16,11 @@ #include "renderer/gui/integration/public/gui_application_with_logger.h" #if WITH_NCURSES -#ifdef __MINGW32__ -#include -#else -#include -#endif // __MINGW32__ + #ifdef __MINGW32__ + #include + #else + #include + #endif // __MINGW32__ #endif diff --git a/libopenage/event/demo/physics.cpp b/libopenage/event/demo/physics.cpp index e27a51d962..e7e969a533 100644 --- a/libopenage/event/demo/physics.cpp +++ b/libopenage/event/demo/physics.cpp @@ -1,4 +1,4 @@ -// Copyright 2017-2023 the openage authors. See copying.md for legal info. +// Copyright 2017-2024 the openage authors. See copying.md for legal info. #include "physics.h" @@ -9,13 +9,13 @@ #include #if WITH_NCURSES -#ifdef __MINGW32__ -#include -#else -#include -#endif // __MINGW32__ + #ifdef __MINGW32__ + #include + #else + #include + #endif // __MINGW32__ -#include "gui.h" + #include "gui.h" #endif #include "error/error.h" @@ -377,7 +377,7 @@ void Physics::init(const std::shared_ptr &gstate, loop->create_event("demo.ball.reflect_panel", state->ball->position, state, now); // FIXME once "reset": deregister - //reset(state, mgr, now); + // reset(state, mgr, now); } void Physics::process_input(const std::shared_ptr &state, @@ -466,11 +466,11 @@ void Physics::process_input(const std::shared_ptr &state, Physics::reset(state, *mgr, now); break; - //if (player->state->get(now).state == PongEvent::LOST) { + // if (player->state->get(now).state == PongEvent::LOST) { // state->ball.position->set_last(now, state.display_boundary * 0.5); - //} - //update_ball(state, now, init_recursion_limit); - //break; + // } + // update_ball(state, now, init_recursion_limit); + // break; default: break; diff --git a/libopenage/log/level.h b/libopenage/log/level.h index ef7322ec63..0d35f163c5 100644 --- a/libopenage/log/level.h +++ b/libopenage/log/level.h @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #pragma once @@ -50,11 +50,11 @@ struct OAAPI level : util::Enum { level(); #ifdef __MINGW32__ -// Do not try to optimize these out even if it seems they are not used. -// Namely MIN that is not used within the library. -#define NOOPTIMIZE __attribute__((__used__)) + // Do not try to optimize these out even if it seems they are not used. + // Namely MIN that is not used within the library. + #define NOOPTIMIZE __attribute__((__used__)) #else -#define NOOPTIMIZE + #define NOOPTIMIZE #endif // _win32 static constexpr level_value MIN NOOPTIMIZE{{"min loglevel", -1000}, "5"}; diff --git a/libopenage/log/message.h b/libopenage/log/message.h index d46ed18c7d..ca534e2efe 100644 --- a/libopenage/log/message.h +++ b/libopenage/log/message.h @@ -21,11 +21,11 @@ #if defined(__GNUC__) -#define OPENAGE_FUNC_NAME __PRETTY_FUNCTION__ + #define OPENAGE_FUNC_NAME __PRETTY_FUNCTION__ #elif defined(_MSC_VER) -#define OPENAGE_FUNC_NAME __FUNCSIG__ + #define OPENAGE_FUNC_NAME __FUNCSIG__ #else -#define OPENAGE_FUNC_NAME __FUNCTION__ + #define OPENAGE_FUNC_NAME __FUNCTION__ #endif namespace openage { diff --git a/libopenage/log/stdout_logsink.cpp b/libopenage/log/stdout_logsink.cpp index 647af51c49..99daecf5cd 100644 --- a/libopenage/log/stdout_logsink.cpp +++ b/libopenage/log/stdout_logsink.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #include "stdout_logsink.h" @@ -7,8 +7,8 @@ #include #ifdef _MSC_VER -#define WIN32_LEAN_AND_MEAN -#include + #define WIN32_LEAN_AND_MEAN + #include #endif #include "log/level.h" diff --git a/libopenage/renderer/color.cpp b/libopenage/renderer/color.cpp index 7333dfb073..f03f883a0a 100644 --- a/libopenage/renderer/color.cpp +++ b/libopenage/renderer/color.cpp @@ -1,12 +1,11 @@ -// Copyright 2015-2019 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #include "color.h" namespace openage { namespace renderer { -Color::Color() - : +Color::Color() : r{0}, g{0}, b{0}, @@ -14,8 +13,7 @@ Color::Color() // Empty } -Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) - : +Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : r{r}, g{g}, b{b}, @@ -32,6 +30,7 @@ bool Color::operator!=(const Color &other) const { } Color Colors::WHITE = {255, 255, 255, 255}; -Color Colors::BLACK = { 0, 0, 0, 255}; +Color Colors::BLACK = {0, 0, 0, 255}; -}} // openage::renderer +} // namespace renderer +} // namespace openage diff --git a/libopenage/renderer/gui/guisys/private/opengl_debug_logger.cpp b/libopenage/renderer/gui/guisys/private/opengl_debug_logger.cpp index 61025528a6..0f565efaae 100644 --- a/libopenage/renderer/gui/guisys/private/opengl_debug_logger.cpp +++ b/libopenage/renderer/gui/guisys/private/opengl_debug_logger.cpp @@ -1,4 +1,4 @@ -// Copyright 2017-2023 the openage authors. See copying.md for legal info. +// Copyright 2017-2024 the openage authors. See copying.md for legal info. #include "opengl_debug_logger.h" @@ -7,11 +7,11 @@ #include #ifdef __APPLE__ -// from https://www.khronos.org/registry/OpenGL/api/GL/glext.h -#define GL_DEBUG_CALLBACK_FUNCTION 0x8244 -#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 -#define GL_DEBUG_TYPE_ERROR 0x824C -#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E + // from https://www.khronos.org/registry/OpenGL/api/GL/glext.h + #define GL_DEBUG_CALLBACK_FUNCTION 0x8244 + #define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 + #define GL_DEBUG_TYPE_ERROR 0x824C + #define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E #endif namespace qtgui { diff --git a/libopenage/renderer/vulkan/loader.cpp b/libopenage/renderer/vulkan/loader.cpp index fdeb6f8c94..2dcf6bd2fc 100644 --- a/libopenage/renderer/vulkan/loader.cpp +++ b/libopenage/renderer/vulkan/loader.cpp @@ -1,4 +1,4 @@ -// Copyright 2017-2018 the openage authors. See copying.md for legal info. +// Copyright 2017-2024 the openage authors. See copying.md for legal info. #include "loader.h" @@ -9,14 +9,14 @@ namespace openage { namespace renderer { namespace vulkan { -VlkLoader::VlkLoader() - : inited(false) {} +VlkLoader::VlkLoader() : + inited(false) {} void VlkLoader::init(VkInstance instance) { - #ifndef NDEBUG +#ifndef NDEBUG this->pCreateDebugReportCallbackEXT = PFN_vkCreateDebugReportCallbackEXT(vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT")); this->pDestroyDebugReportCallbackEXT = PFN_vkDestroyDebugReportCallbackEXT(vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT")); - #endif +#endif this->inited = true; } @@ -24,10 +24,9 @@ void VlkLoader::init(VkInstance instance) { #ifndef NDEBUG VkResult VlkLoader::vkCreateDebugReportCallbackEXT( VkInstance instance, - const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkDebugReportCallbackEXT* pCallback -) { + const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkDebugReportCallbackEXT *pCallback) { if (!this->inited) { throw Error(MSG(err) << "Tried to request function from Vulkan extension loader before initializing it."); } @@ -42,8 +41,7 @@ VkResult VlkLoader::vkCreateDebugReportCallbackEXT( void VlkLoader::vkDestroyDebugReportCallbackEXT( VkInstance instance, VkDebugReportCallbackEXT callback, - const VkAllocationCallbacks* pAllocator -) { + const VkAllocationCallbacks *pAllocator) { if (!this->inited) { throw Error(MSG(err) << "Tried to request function from Vulkan extension loader before initializing it."); } @@ -54,4 +52,6 @@ void VlkLoader::vkDestroyDebugReportCallbackEXT( } #endif -}}} // openage::renderer::vulkan +} // namespace vulkan +} // namespace renderer +} // namespace openage diff --git a/libopenage/util/compiler.cpp b/libopenage/util/compiler.cpp index b854d91278..082240a704 100644 --- a/libopenage/util/compiler.cpp +++ b/libopenage/util/compiler.cpp @@ -1,22 +1,22 @@ -// Copyright 2015-2019 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #include "compiler.h" #ifndef _WIN32 -#include -#include + #include + #include #else -#define WIN32_LEAN_AND_MEAN -#include -#include + #define WIN32_LEAN_AND_MEAN + #include + #include #endif #include "strings.h" #include #include -#include #include +#include namespace openage { namespace util { @@ -34,7 +34,8 @@ std::string demangle(const char *symbol) { if (status != 0) { return symbol; - } else { + } + else { std::string result{buf}; free(buf); return result; @@ -78,12 +79,12 @@ std::optional symbol_name_win(const void *addr) { constexpr int buffer_size = sizeof(SYMBOL_INFO) + name_buffer_size * sizeof(char); std::array buffer; - SYMBOL_INFO *symbol_info = reinterpret_cast(buffer.data()); + SYMBOL_INFO *symbol_info = reinterpret_cast(buffer.data()); symbol_info->SizeOfStruct = sizeof(SYMBOL_INFO); symbol_info->MaxNameLen = name_buffer_size; - if (SymFromAddr(process_handle, reinterpret_cast(addr), nullptr, symbol_info)) { + if (SymFromAddr(process_handle, reinterpret_cast(addr), nullptr, symbol_info)) { return std::string(symbol_info->Name); } } @@ -92,7 +93,7 @@ std::optional symbol_name_win(const void *addr) { } -} +} // namespace #endif std::string symbol_name(const void *addr, bool require_exact_addr, bool no_pure_addrs) { @@ -100,8 +101,7 @@ std::string symbol_name(const void *addr, bool require_exact_addr, bool no_pure_ auto symbol_name_result = symbol_name_win(addr); - if (!initialized_symbol_handler_successfully || - !symbol_name_result.has_value()) { + if (!initialized_symbol_handler_successfully || !symbol_name_result.has_value()) { return no_pure_addrs ? "" : addr_to_string(addr); } @@ -113,8 +113,9 @@ std::string symbol_name(const void *addr, bool require_exact_addr, bool no_pure_ if (dladdr(addr, &addr_info) == 0) { // dladdr has... failed. return no_pure_addrs ? "" : addr_to_string(addr); - } else { - size_t symbol_offset = (size_t) addr - (size_t) addr_info.dli_saddr; + } + else { + size_t symbol_offset = (size_t)addr - (size_t)addr_info.dli_saddr; if (addr_info.dli_sname == nullptr or (symbol_offset != 0 and require_exact_addr)) { return no_pure_addrs ? "" : addr_to_string(addr); @@ -123,7 +124,8 @@ std::string symbol_name(const void *addr, bool require_exact_addr, bool no_pure_ if (symbol_offset == 0) { // this is our symbol name. return demangle(addr_info.dli_sname); - } else { + } + else { return util::sformat("%s+0x%lx", demangle(addr_info.dli_sname).c_str(), symbol_offset); @@ -138,7 +140,8 @@ bool is_symbol(const void *addr) { if (!initialized_symbol_handler_successfully) { return true; - } else { + } + else { return symbol_name_win(addr).has_value(); } @@ -154,4 +157,5 @@ bool is_symbol(const void *addr) { } -}} // openage::util +} // namespace util +} // namespace openage diff --git a/libopenage/util/fds.cpp b/libopenage/util/fds.cpp index 468d3354bc..8d5188c10d 100644 --- a/libopenage/util/fds.cpp +++ b/libopenage/util/fds.cpp @@ -1,4 +1,4 @@ -// Copyright 2014-2019 the openage authors. See copying.md for legal info. +// Copyright 2014-2024 the openage authors. See copying.md for legal info. #include "fds.h" @@ -7,12 +7,12 @@ #include #include -#include #include "pty.h" +#include #ifdef _WIN32 -#include + #include #else -#include + #include #endif #include "unicode.h" @@ -28,10 +28,10 @@ FD::FD(int fd, bool set_nonblocking) { this->close_on_destroy = true; if (set_nonblocking) { - #ifndef _WIN32 +#ifndef _WIN32 int flags = ::fcntl(this->fd, F_GETFL, 0); ::fcntl(this->fd, F_SETFL, flags | O_NONBLOCK); - #endif +#endif } } @@ -64,31 +64,32 @@ int FD::putbyte(char c) { int FD::putcp(int cp) { char utf8buf[5]; if (util::utf8_encode(cp, utf8buf) == 0) { - //unrepresentable character (question mark in black rhombus) + // unrepresentable character (question mark in black rhombus) return this->puts("\uFFFD"); - } else { + } + else { return this->puts(utf8buf); } } int FD::printf(const char *format, ...) { const unsigned buf_size = 16; - char *buf = static_cast(malloc(sizeof(char) * buf_size)); + char *buf = static_cast(malloc(sizeof(char) * buf_size)); if (!buf) { return -1; } va_list vl; - //first, try to vsnprintf to a buffer of length 16 + // first, try to vsnprintf to a buffer of length 16 va_start(vl, format); unsigned len = vsnprintf(buf, buf_size, format, vl); va_end(vl); - //if that wasn't enough, allocate more memory and try again + // if that wasn't enough, allocate more memory and try again if (len >= buf_size) { char *oldbuf = buf; - buf = static_cast(realloc(oldbuf, sizeof(char) * (len + 1))); + buf = static_cast(realloc(oldbuf, sizeof(char) * (len + 1))); if (!buf) { free(oldbuf); return -1; @@ -99,42 +100,42 @@ int FD::printf(const char *format, ...) { va_end(vl); } - //output buf to the socket + // output buf to the socket int result = this->puts(buf); - //free the buffer + // free the buffer free(buf); return result; } void FD::setinputmodecanon() { - #ifndef _WIN32 +#ifndef _WIN32 if (::isatty(this->fd)) { - //get the terminal settings for stdin + // get the terminal settings for stdin ::tcgetattr(this->fd, &this->old_tio); - //backup old settings + // backup old settings struct termios new_tio = this->old_tio; - //disable buffered i/o (canonical mode) and local echo + // disable buffered i/o (canonical mode) and local echo new_tio.c_lflag &= (~ICANON & ~ECHO & ~ISIG); - //set the settings + // set the settings ::tcsetattr(this->fd, TCSANOW, &new_tio); this->restore_input_mode_on_destroy = true; } - #endif /* _WIN32 */ +#endif /* _WIN32 */ } void FD::restoreinputmode() { - #ifndef _WIN32 +#ifndef _WIN32 if (::isatty(this->fd)) { ::tcsetattr(this->fd, TCSANOW, &this->old_tio); this->restore_input_mode_on_destroy = false; } - #endif /* _WIN32 */ +#endif /* _WIN32 */ } -} // openage::util +} // namespace openage::util diff --git a/libopenage/util/fds.h b/libopenage/util/fds.h index 251ad0aec7..309384e1ad 100644 --- a/libopenage/util/fds.h +++ b/libopenage/util/fds.h @@ -5,7 +5,7 @@ #include #ifndef _WIN32 -#include + #include #endif namespace openage { diff --git a/libopenage/util/fslike/directory.cpp b/libopenage/util/fslike/directory.cpp index 22055e2c32..420757f3a6 100644 --- a/libopenage/util/fslike/directory.cpp +++ b/libopenage/util/fslike/directory.cpp @@ -1,11 +1,11 @@ -// Copyright 2017-2019 the openage authors. See copying.md for legal info. +// Copyright 2017-2024 the openage authors. See copying.md for legal info. #include "directory.h" // HACK: windows.h defines max and min as macros. This results in compile errors. #ifdef _WIN32 -// defining `NOMINMAX` disables the definition of those macros. -#define NOMINMAX + // defining `NOMINMAX` disables the definition of those macros. + #define NOMINMAX #endif #include @@ -17,34 +17,32 @@ #include #ifdef __APPLE__ -#include + #include #endif #ifdef _WIN32 -#include -#include -#include -// HACK: What the heck? I want the std::filesystem library! -#define O_NOCTTY 0 -#define O_NONBLOCK 0 -#define W_OK 2 + #include + #include + #include + // HACK: What the heck? I want the std::filesystem library! + #define O_NOCTTY 0 + #define O_NONBLOCK 0 + #define W_OK 2 #else // ! _MSC_VER -#include + #include #endif -#include "./native.h" #include "../file.h" #include "../filelike/native.h" #include "../misc.h" #include "../path.h" +#include "./native.h" namespace openage::util::fslike { -Directory::Directory(std::string basepath, bool create_if_missing) - : +Directory::Directory(std::string basepath, bool create_if_missing) : basepath{std::move(basepath)} { - if (create_if_missing) { this->mkdirs({}); } @@ -78,8 +76,7 @@ bool Directory::is_file(const Path::parts_t &parts) { auto stat_result = this->do_stat(parts); // test for regular file - if (std::get<1>(stat_result) == 0 and - S_ISREG(std::get<0>(stat_result).st_mode)) { + if (std::get<1>(stat_result) == 0 and S_ISREG(std::get<0>(stat_result).st_mode)) { return true; } @@ -91,8 +88,7 @@ bool Directory::is_dir(const Path::parts_t &parts) { auto stat_result = this->do_stat(parts); // test for regular file - if (std::get<1>(stat_result) == 0 and - S_ISDIR(std::get<0>(stat_result).st_mode)) { + if (std::get<1>(stat_result) == 0 and S_ISDIR(std::get<0>(stat_result).st_mode)) { return true; } @@ -104,9 +100,7 @@ bool Directory::writable(const Path::parts_t &parts) { Path::parts_t parts_test = parts; // try to find the first existing path-part - while (not (this->is_dir(parts_test) or - this->is_file(parts_test))) { - + while (not(this->is_dir(parts_test) or this->is_file(parts_test))) { if (parts_test.size() == 0) { throw Error{ERR << "file not found"}; } @@ -120,7 +114,6 @@ bool Directory::writable(const Path::parts_t &parts) { std::vector Directory::list(const Path::parts_t &parts) { - const std::string path = this->resolve(parts); std::vector ret; @@ -145,7 +138,6 @@ std::vector Directory::list(const Path::parts_t &parts) { bool Directory::mkdirs(const Path::parts_t &parts) { - Path::parts_t all_parts = util::split(this->basepath, PATHSEP); vector_extend(all_parts, parts); @@ -158,9 +150,7 @@ bool Directory::mkdirs(const Path::parts_t &parts) { struct stat buf; // it it exists already, try creating the next one - if (stat(dirpath.c_str(), &buf) == 0 and - S_ISDIR(buf.st_mode)) { - + if (stat(dirpath.c_str(), &buf) == 0 and S_ISDIR(buf.st_mode)) { continue; } @@ -184,40 +174,35 @@ bool Directory::mkdirs(const Path::parts_t &parts) { File Directory::open_r(const Path::parts_t &parts) { return File{ std::make_shared(this->resolve(parts), - filelike::Native::mode_t::R) - }; + filelike::Native::mode_t::R)}; } File Directory::open_w(const Path::parts_t &parts) { return File{ std::make_shared(this->resolve(parts), - filelike::Native::mode_t::W) - }; + filelike::Native::mode_t::W)}; } File Directory::open_rw(const Path::parts_t &parts) { return File{ std::make_shared(this->resolve(parts), - filelike::Native::mode_t::RW) - }; + filelike::Native::mode_t::RW)}; } File Directory::open_a(const Path::parts_t &parts) { return File{ std::make_shared(this->resolve(parts), - filelike::Native::mode_t::A) - }; + filelike::Native::mode_t::A)}; } File Directory::open_ar(const Path::parts_t &parts) { return File{ std::make_shared(this->resolve(parts), - filelike::Native::mode_t::AR) - }; + filelike::Native::mode_t::AR)}; } @@ -228,9 +213,9 @@ std::string Directory::get_native_path(const Path::parts_t &parts) { bool Directory::rename(const Path::parts_t &parts, const Path::parts_t &target_parts) { - return std::rename(this->resolve(parts).c_str(), - this->resolve(target_parts).c_str()) == 0; + this->resolve(target_parts).c_str()) + == 0; } @@ -245,9 +230,8 @@ bool Directory::touch(const Path::parts_t &parts) { // create the file if missing int fd = open( path.c_str(), - O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, - 0666 - ); + O_WRONLY | O_CREAT | O_NOCTTY | O_NONBLOCK, + 0666); if (fd < 0) { return false; @@ -308,4 +292,4 @@ std::ostream &Directory::repr(std::ostream &stream) { return stream; } -} // openage::util::fslike +} // namespace openage::util::fslike diff --git a/libopenage/util/macro/concat.h b/libopenage/util/macro/concat.h index b8f7b746ca..dd057ccd9f 100644 --- a/libopenage/util/macro/concat.h +++ b/libopenage/util/macro/concat.h @@ -9,16 +9,16 @@ #define CONCAT_N(_1, _2, _3, NAME, ...) NAME #ifdef _MSC_VER -#define CONCAT_COUNT_ARGS_IMPL(args) CONCAT_N args -#define CONCAT_COUNT_ARGS(...) CONCAT_COUNT_ARGS_IMPL((__VA_ARGS__, 3, 2, 1)) -#define CONCAT_HELPER2(count) CONCAT_##count -#define CONCAT_HELPER1(count) CONCAT_HELPER2(count) -#define CONCAT_HELPER(count) CONCAT_HELPER1(count) -#define CONCAT_GLUE(x, y) x y -#define CONCAT(OP, ...) CONCAT_GLUE(CONCAT_HELPER(CONCAT_COUNT_ARGS(__VA_ARGS__)), (OP, __VA_ARGS__)) + #define CONCAT_COUNT_ARGS_IMPL(args) CONCAT_N args + #define CONCAT_COUNT_ARGS(...) CONCAT_COUNT_ARGS_IMPL((__VA_ARGS__, 3, 2, 1)) + #define CONCAT_HELPER2(count) CONCAT_##count + #define CONCAT_HELPER1(count) CONCAT_HELPER2(count) + #define CONCAT_HELPER(count) CONCAT_HELPER1(count) + #define CONCAT_GLUE(x, y) x y + #define CONCAT(OP, ...) CONCAT_GLUE(CONCAT_HELPER(CONCAT_COUNT_ARGS(__VA_ARGS__)), (OP, __VA_ARGS__)) #else -#define CONCAT(OP, ...) CONCAT_N(__VA_ARGS__, \ - CONCAT_3, \ - CONCAT_2, \ - CONCAT_1)(OP, __VA_ARGS__) + #define CONCAT(OP, ...) CONCAT_N(__VA_ARGS__, \ + CONCAT_3, \ + CONCAT_2, \ + CONCAT_1)(OP, __VA_ARGS__) #endif diff --git a/libopenage/util/macro/loop.h b/libopenage/util/macro/loop.h index 5b8dc59e8e..c868a12694 100644 --- a/libopenage/util/macro/loop.h +++ b/libopenage/util/macro/loop.h @@ -9,16 +9,16 @@ #define LOOP_N(_1, _2, _3, NAME, ...) NAME #ifdef _MSC_VER -#define LOOP_COUNT_ARGS_IMPL(args) LOOP_N args -#define LOOP_COUNT_ARGS(...) LOOP_COUNT_ARGS_IMPL((__VA_ARGS__, 3, 2, 1)) -#define LOOP_HELPER2(count) LOOP_##count -#define LOOP_HELPER1(count) LOOP_HELPER2(count) -#define LOOP_HELPER(count) LOOP_HELPER1(count) -#define LOOP_GLUE(x, y) x y -#define LOOP(MACRO, ...) LOOP_GLUE(LOOP_HELPER(LOOP_COUNT_ARGS(__VA_ARGS__)), (MACRO, __VA_ARGS__)) + #define LOOP_COUNT_ARGS_IMPL(args) LOOP_N args + #define LOOP_COUNT_ARGS(...) LOOP_COUNT_ARGS_IMPL((__VA_ARGS__, 3, 2, 1)) + #define LOOP_HELPER2(count) LOOP_##count + #define LOOP_HELPER1(count) LOOP_HELPER2(count) + #define LOOP_HELPER(count) LOOP_HELPER1(count) + #define LOOP_GLUE(x, y) x y + #define LOOP(MACRO, ...) LOOP_GLUE(LOOP_HELPER(LOOP_COUNT_ARGS(__VA_ARGS__)), (MACRO, __VA_ARGS__)) #else -#define LOOP(MACRO, ...) LOOP_N(__VA_ARGS__, \ - LOOP_3, \ - LOOP_2, \ - LOOP_1)(MACRO, __VA_ARGS__) + #define LOOP(MACRO, ...) LOOP_N(__VA_ARGS__, \ + LOOP_3, \ + LOOP_2, \ + LOOP_1)(MACRO, __VA_ARGS__) #endif diff --git a/libopenage/util/os.cpp b/libopenage/util/os.cpp index c3bbea2da6..ccc68d86c6 100644 --- a/libopenage/util/os.cpp +++ b/libopenage/util/os.cpp @@ -1,4 +1,4 @@ -// Copyright 2014-2019 the openage authors. See copying.md for legal info. +// Copyright 2014-2024 the openage authors. See copying.md for legal info. #include "os.h" @@ -7,16 +7,16 @@ #ifdef _WIN32 // TODO not yet implemented #else -#include + #include #endif #ifdef __APPLE__ -#include + #include #endif #ifdef __FreeBSD__ -#include -#include + #include + #include #endif #include "../log/log.h" @@ -77,8 +77,7 @@ std::string self_exec_filename() { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, - -1 - }; + -1}; while (true) { std::unique_ptr buf{new char[bufsize]}; @@ -103,23 +102,23 @@ int execute_file(const char *path, bool background) { // TODO some sort of shell-open, not yet implemented return -1; // failure #else - std::string runner = ""; -#ifdef __APPLE__ - runner = subprocess::which("open"); -#else - runner = subprocess::which("xdg-open"); - // fallback - if (runner.size() == 0) { - runner = subprocess::which("gnome-open"); - } -#endif - if (runner.size() == 0) { - log::log(MSG(err) << "could not locate file-opener"); - return -1; - } + std::string runner = ""; + #ifdef __APPLE__ + runner = subprocess::which("open"); + #else + runner = subprocess::which("xdg-open"); + // fallback + if (runner.size() == 0) { + runner = subprocess::which("gnome-open"); + } + #endif + if (runner.size() == 0) { + log::log(MSG(err) << "could not locate file-opener"); + return -1; + } - return subprocess::call({runner.c_str(), path, nullptr}, not background); + return subprocess::call({runner.c_str(), path, nullptr}, not background); #endif } -} // namespace openage +} // namespace openage::os diff --git a/libopenage/util/pty.h b/libopenage/util/pty.h index 0ae9e72d23..cb85f38865 100644 --- a/libopenage/util/pty.h +++ b/libopenage/util/pty.h @@ -3,14 +3,14 @@ #pragma once #ifdef __APPLE__ -#include + #include #elif defined(__FreeBSD__) -#include -#include -#include -#include + #include + #include + #include + #include #elif _WIN32 // TODO not yet implemented #else -#include + #include #endif diff --git a/libopenage/util/strings.h b/libopenage/util/strings.h index ad04e5267c..69f2759fb4 100644 --- a/libopenage/util/strings.h +++ b/libopenage/util/strings.h @@ -11,9 +11,9 @@ #include #if defined(__GNUC__) -#define ATTRIBUTE_FORMAT(i, j) __attribute__((format(printf, i, j))) + #define ATTRIBUTE_FORMAT(i, j) __attribute__((format(printf, i, j))) #else -#define ATTRIBUTE_FORMAT(i, j) + #define ATTRIBUTE_FORMAT(i, j) #endif namespace openage { diff --git a/libopenage/util/subprocess.cpp b/libopenage/util/subprocess.cpp index 98ae6720eb..c9a7670159 100644 --- a/libopenage/util/subprocess.cpp +++ b/libopenage/util/subprocess.cpp @@ -1,19 +1,19 @@ -// Copyright 2014-2019 the openage authors. See copying.md for legal info. +// Copyright 2014-2024 the openage authors. See copying.md for legal info. #include "subprocess.h" +#include #include #include -#include #ifdef _WIN32 // TODO not yet implemented #else -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include #endif #include "../log/log.h" @@ -90,7 +90,7 @@ int call(const std::vector &argv, bool wait, const char *redirect_ if (redirect_stdout_to != nullptr) { replacement_stdout_fd = open( redirect_stdout_to, - O_WRONLY | O_CREAT|O_TRUNC|O_CLOEXEC, + O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (replacement_stdout_fd < 0) { @@ -215,8 +215,8 @@ int call(const std::vector &argv, bool wait, const char *redirect_ } if (child_errno > 0) { - log::log(MSG(err) << "execv has failed: " << strerror(child_errno)); - return -1; + log::log(MSG(err) << "execv has failed: " << strerror(child_errno)); + return -1; } } @@ -235,7 +235,7 @@ int call(const std::vector &argv, bool wait, const char *redirect_ // everything went well. return status; - #endif +#endif } } // namespace openage::subprocess diff --git a/libopenage/util/thread_id.cpp b/libopenage/util/thread_id.cpp index 0bcfc0abc9..3a178c441d 100644 --- a/libopenage/util/thread_id.cpp +++ b/libopenage/util/thread_id.cpp @@ -1,13 +1,13 @@ -// Copyright 2015-2018 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #include "thread_id.h" #include "config.h" #if HAVE_THREAD_LOCAL_STORAGE -#include + #include #else -#include + #include #endif namespace openage { @@ -23,9 +23,8 @@ namespace util { */ class ThreadIdSupplier { public: - ThreadIdSupplier() - : - val{ThreadIdSupplier::counting_id++} {} + ThreadIdSupplier() : + val{ThreadIdSupplier::counting_id++} {} const size_t val; @@ -42,12 +41,13 @@ std::atomic ThreadIdSupplier::counting_id{0}; #endif size_t get_current_thread_id() { - #if HAVE_THREAD_LOCAL_STORAGE +#if HAVE_THREAD_LOCAL_STORAGE static thread_local ThreadIdSupplier current_thread_id; return current_thread_id.val; - #else +#else return std::hash()(std::this_thread::get_id()); - #endif +#endif } -}} // namespace openage::util +} // namespace util +} // namespace openage diff --git a/libopenage/versions/versions.cpp b/libopenage/versions/versions.cpp index d2e1fd251a..29655b6db9 100644 --- a/libopenage/versions/versions.cpp +++ b/libopenage/versions/versions.cpp @@ -1,9 +1,9 @@ -// Copyright 2020-2023 the openage authors. See copying.md for legal info. +// Copyright 2020-2024 the openage authors. See copying.md for legal info. #include "versions.h" #ifdef __linux__ -#include + #include #endif #include