summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format121
-rw-r--r--.clangd11
-rw-r--r--CMakeLists.txt27
-rw-r--r--cabinet/magic.cpp19
-rw-r--r--cabinet/magic.hpp36
-rw-r--r--cabinet/main.cpp6
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
diff --git a/.clangd b/.clangd
new file mode 100644
index 0000000..7a48077
--- /dev/null
+++ b/.clangd
@@ -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};
}