diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-06-04 18:14:19 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-06-04 18:14:19 +0200 |
| commit | a95acc4d382cbb4937097e7fa2f6526974a26fcc (patch) | |
| tree | 71b922a413fad15d4796ee613a91240f4ae59df0 | |
| parent | 0ff3f826d9772d3695f481e0a3d0bc1517dd3ae4 (diff) | |
| download | cabinet-a95acc4d382cbb4937097e7fa2f6526974a26fcc.tar.xz cabinet-a95acc4d382cbb4937097e7fa2f6526974a26fcc.zip | |
core: add basic libmagic abstraction skeleton
| -rw-r--r-- | .clang-format | 121 | ||||
| -rw-r--r-- | .clangd | 11 | ||||
| -rw-r--r-- | CMakeLists.txt | 27 | ||||
| -rw-r--r-- | cabinet/magic.cpp | 19 | ||||
| -rw-r--r-- | cabinet/magic.hpp | 36 | ||||
| -rw-r--r-- | cabinet/main.cpp | 6 |
6 files changed, 219 insertions, 1 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d11db7d --- /dev/null +++ b/.clang-format @@ -0,0 +1,121 @@ +--- +AccessModifierOffset: "-2" +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignEscapedNewlines: LeftWithLastLine +AlignTrailingComments: "true" +AllowAllParametersOfDeclarationOnNextLine: "true" +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: "false" +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: "false" +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: "true" +BinPackArguments: "true" +BinPackParameters: "true" +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: "true" + AfterControlStatement: "true" + AfterEnum: "true" + AfterFunction: "true" + AfterNamespace: "true" + AfterStruct: "true" + AfterUnion: "true" + AfterExternBlock: "true" + BeforeCatch: "true" + BeforeElse: "true" + IndentBraces: "false" + AfterCaseLabel: true + SplitEmptyFunction: false + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeInheritanceComma: "false" +BreakConstructorInitializers: BeforeComma +BreakStringLiterals: "true" +ColumnLimit: "120" +CompactNamespaces: "false" +Cpp11BracedListStyle: "true" +DerivePointerAlignment: "false" +FixNamespaceComments: "true" +IncludeBlocks: Regroup +IncludeCategories: + # Library Headers + - Regex: 'cabinet/[[:alnum:]._\/]+\.hpp' + Priority: 200 + # Catch2 Headers + - Regex: 'catch2/[[:alnum:]._\/]+\.hpp' + Priority: 600 + # Standard Headers + - Regex: '<[[:alnum:]_]+>' + Priority: 900 + # Fallback + - Regex: '<.*>' + Priority: 800 +IndentCaseLabels: "true" +IndentPPDirectives: None +IndentWidth: "2" +KeepEmptyLinesAtTheStartOfBlocks: "false" +Language: Cpp +MainIncludeChar: "Any" +MaxEmptyLinesToKeep: "1" +NamespaceIndentation: All +PointerAlignment: Middle +ReflowComments: "true" +SortIncludes: "true" +SortUsingDeclarations: "true" +SpaceAfterCStyleCast: "false" +SpaceAfterTemplateKeyword: "false" +SpaceBeforeAssignmentOperators: "true" +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: "false" +SpacesBeforeTrailingComments: "2" +SpacesInAngles: "false" +SpacesInContainerLiterals: "false" +SpacesInCStyleCastParentheses: "false" +SpacesInParentheses: "false" +SpacesInSquareBrackets: "false" +Standard: Latest +TabWidth: "2" +UseTab: Never +AlignArrayOfStructures: Right +AlignConsecutiveBitFields: {} +AllowAllArgumentsOnNextLine: false +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortCaseExpressionOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: false +AllowShortLambdasOnASingleLine: Inline +BitFieldColonSpacing: Both +BracedInitializerIndentWidth: 2 +IntegerLiteralSeparator: + Binary: 4 + BinaryMinDigits: 8 + Decimal: 3 + DecimalMinDigits: 6 + Hex: 4 + HexMinDigits: 8 +QualifierAlignment: Custom +QualifierOrder: + - constexpr + - type + - static + - inline + - const +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false @@ -0,0 +1,11 @@ +Diagnostics: + UnusedIncludes: Strict + MissingIncludes: Strict +CompileFlags: + Remove: + - -fcondition-coverage + - -fmodules-ts + - -fmodule-mapper=* + - -fdeps-format=* +Documentation: + CommentFormat: Doxygen diff --git a/CMakeLists.txt b/CMakeLists.txt index 9647816..f2970ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,36 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_CXX_EXTENSIONS NO) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) +find_package("PkgConfig") + +pkg_check_modules("magic" REQUIRED + IMPORTED_TARGET + GLOBAL + "libmagic" +) + +add_library("core" STATIC) +add_library("cabinet::core" ALIAS "core") + +target_sources("core" PRIVATE + "cabinet/magic.cpp" +) + +target_include_directories("core" PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" +) + +target_link_libraries("core" PUBLIC + "PkgConfig::magic" +) + add_executable("cabinet") add_executable("cabinet::app" ALIAS "cabinet") target_sources("cabinet" PRIVATE "cabinet/main.cpp" ) + +target_link_libraries("cabinet" PRIVATE + "cabinet::core" +) diff --git a/cabinet/magic.cpp b/cabinet/magic.cpp new file mode 100644 index 0000000..f8d7337 --- /dev/null +++ b/cabinet/magic.cpp @@ -0,0 +1,19 @@ +#include <cabinet/magic.hpp> + +#include <magic.h> + +#include <utility> + +namespace cab +{ + + magic::magic(magic::flags flags) + : m_cookie{magic_open(std::to_underlying(flags))} + {} + + magic::~magic() + { + magic_close(m_cookie); + } + +} // namespace cab diff --git a/cabinet/magic.hpp b/cabinet/magic.hpp new file mode 100644 index 0000000..3ad6dfa --- /dev/null +++ b/cabinet/magic.hpp @@ -0,0 +1,36 @@ +#ifndef CABINET_MAGIC_HPP +#define CABINET_MAGIC_HPP + +#include <magic.h> + +#include <utility> + +namespace cab +{ + + struct magic + { + enum struct flags : decltype(MAGIC_NONE) + { + none = MAGIC_NONE, + print_debug = MAGIC_DEBUG, + follow_symlinks = MAGIC_SYMLINK, + inspect_compressed = MAGIC_COMPRESS, + inspect_devices = MAGIC_DEVICES, + }; + + magic(flags flags); + ~magic(); + + private: + magic_t m_cookie{}; + }; + + constexpr auto operator|(magic::flags lhs, magic::flags rhs) noexcept -> magic::flags + { + return static_cast<magic::flags>(std::to_underlying(lhs) | std::to_underlying(rhs)); + } + +} // namespace cab + +#endif diff --git a/cabinet/main.cpp b/cabinet/main.cpp index 09509dd..26dd690 100644 --- a/cabinet/main.cpp +++ b/cabinet/main.cpp @@ -1,2 +1,6 @@ -auto main() -> int { +#include <cabinet/magic.hpp> + +auto main() -> int +{ + [[maybe_unused]] auto magic = cab::magic{cab::magic::flags::print_debug | cab::magic::flags::follow_symlinks}; } |
