From d4fb82992c4f77368a541c138c6f6423b251b065 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 31 Jul 2025 21:36:43 -0400 Subject: [PATCH] Format files --- .clang-format | 4 ++ src/include/oslog_extension.hpp | 9 +++- src/include/oslog_table.hpp | 14 +++++ src/oslog_extension.cpp | 13 +++-- src/oslog_table.hpp | 9 ---- src/oslog_table.mm | 94 +++++++++++++++++++-------------- 6 files changed, 89 insertions(+), 54 deletions(-) create mode 100644 src/include/oslog_table.hpp delete mode 100644 src/oslog_table.hpp diff --git a/.clang-format b/.clang-format index 7eb8d98..93cbb2d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,7 @@ BasedOnStyle: Chromium InsertBraces: true InsertNewlineAtEOF: true +ColumnLimit: 100 +AllowShortCaseLabelsOnASingleLine: true +AlignConsecutiveShortCaseStatements: + Enabled: true diff --git a/src/include/oslog_extension.hpp b/src/include/oslog_extension.hpp index 5e85adf..691cbcc 100644 --- a/src/include/oslog_extension.hpp +++ b/src/include/oslog_extension.hpp @@ -1,6 +1,11 @@ +// Copyright 2025 Blue Static +// This program is free software licensed under the GNU General Public License, +// version 3.0. The full text of the license can be found in LICENSE.txt. +// SPDX-License-Identifier: GPL-3.0-only + #pragma once -#include "duckdb.hpp" +#include namespace duckdb { @@ -11,4 +16,4 @@ class OslogExtension : public Extension { std::string Version() const override; }; -} // namespace duckdb +} // namespace duckdb diff --git a/src/include/oslog_table.hpp b/src/include/oslog_table.hpp new file mode 100644 index 0000000..4b1b19e --- /dev/null +++ b/src/include/oslog_table.hpp @@ -0,0 +1,14 @@ +// Copyright 2025 Blue Static +// This program is free software licensed under the GNU General Public License, +// version 3.0. The full text of the license can be found in LICENSE.txt. +// SPDX-License-Identifier: GPL-3.0-only + +#include + +namespace duckdb { +namespace oslog { + +duckdb::TableFunction GetTableFunction(); + +} // namespace oslog +} // namespace duckdb diff --git a/src/oslog_extension.cpp b/src/oslog_extension.cpp index d4d6aef..02143e2 100644 --- a/src/oslog_extension.cpp +++ b/src/oslog_extension.cpp @@ -1,10 +1,15 @@ +// Copyright 2025 Blue Static +// This program is free software licensed under the GNU General Public License, +// version 3.0. The full text of the license can be found in LICENSE.txt. +// SPDX-License-Identifier: GPL-3.0-only + #define DUCKDB_EXTENSION_MAIN #include "oslog_extension.hpp" -#include "duckdb.hpp" -#include "duckdb/common/exception.hpp" -#include "duckdb/main/extension_util.hpp" +#include +#include +#include #include "oslog_table.hpp" @@ -26,7 +31,7 @@ std::string OslogExtension::Version() const { #endif } -} // namespace duckdb +} // namespace duckdb extern "C" { diff --git a/src/oslog_table.hpp b/src/oslog_table.hpp deleted file mode 100644 index 0971bca..0000000 --- a/src/oslog_table.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -namespace duckdb { -namespace oslog { - -duckdb::TableFunction GetTableFunction(); - -} // namespace oslog -} // namespace duckdb diff --git a/src/oslog_table.mm b/src/oslog_table.mm index ef3a851..09a3606 100644 --- a/src/oslog_table.mm +++ b/src/oslog_table.mm @@ -1,9 +1,14 @@ +// Copyright 2025 Blue Static +// This program is free software licensed under the GNU General Public License, +// version 3.0. The full text of the license can be found in LICENSE.txt. +// SPDX-License-Identifier: GPL-3.0-only + #import #import #include -#include #include +#include namespace duckdb { namespace oslog { @@ -50,11 +55,11 @@ class LevelColumn : public Column { OSLogEntryLogLevel level = [static_cast(log) level]; switch (level) { case OSLogEntryLogLevelUndefined: return Value("undefined"); - case OSLogEntryLogLevelDebug: return Value("debug"); - case OSLogEntryLogLevelInfo: return Value("info"); - case OSLogEntryLogLevelNotice: return Value("notice"); - case OSLogEntryLogLevelError: return Value("error"); - case OSLogEntryLogLevelFault: return Value("fault"); + case OSLogEntryLogLevelDebug: return Value("debug"); + case OSLogEntryLogLevelInfo: return Value("info"); + case OSLogEntryLogLevelNotice: return Value("notice"); + case OSLogEntryLogLevelError: return Value("error"); + case OSLogEntryLogLevelFault: return Value("fault"); } } }; @@ -63,78 +68,87 @@ class SubsystemColumn : public Column { public: SubsystemColumn(idx_t i) : Column(i, "subsystem") {} LogicalType type() const override { return LogicalType::VARCHAR; } - Value Produce(OSLogEntry* log) const override { return Value([static_cast(log) subsystem].UTF8String); } + Value Produce(OSLogEntry* log) const override { + return Value([static_cast(log) subsystem].UTF8String); + } }; class CategoryColumn : public Column { public: CategoryColumn(idx_t i) : Column(i, "category") {} LogicalType type() const override { return LogicalType::VARCHAR; } - Value Produce(OSLogEntry* log) const override { return Value([static_cast(log) category].UTF8String); } + Value Produce(OSLogEntry* log) const override { + return Value([static_cast(log) category].UTF8String); + } }; class ProcessColumn : public Column { public: ProcessColumn(idx_t i) : Column(i, "process") {} LogicalType type() const override { return LogicalType::VARCHAR; } - Value Produce(OSLogEntry* log) const override { return Value([static_cast(log) process].UTF8String); } + Value Produce(OSLogEntry* log) const override { + return Value([static_cast(log) process].UTF8String); + } }; class ProcessIdColumn : public Column { public: ProcessIdColumn(idx_t i) : Column(i, "processId") {} LogicalType type() const override { return LogicalType::BIGINT; } - Value Produce(OSLogEntry* log) const override { return Value([static_cast(log) processIdentifier]); } + Value Produce(OSLogEntry* log) const override { + return Value([static_cast(log) processIdentifier]); + } }; class SenderColumn : public Column { public: SenderColumn(idx_t i) : Column(i, "sender") {} LogicalType type() const override { return LogicalType::VARCHAR; } - Value Produce(OSLogEntry* log) const override { return Value([static_cast(log) sender].UTF8String); } + Value Produce(OSLogEntry* log) const override { + return Value([static_cast(log) sender].UTF8String); + } }; class ThreadIdColumn : public Column { public: ThreadIdColumn(idx_t i) : Column(i, "threadId") {} LogicalType type() const override { return LogicalType::UBIGINT; } - Value Produce(OSLogEntry* log) const override { return Value::UBIGINT([static_cast(log) threadIdentifier]); } + Value Produce(OSLogEntry* log) const override { + return Value::UBIGINT([static_cast(log) threadIdentifier]); + } }; class MessageColumn : public Column { public: MessageColumn(idx_t i) : Column(i, "message") {} LogicalType type() const override { return LogicalType::VARCHAR; } - Value Produce(OSLogEntry* log) const override { return Value([static_cast(log) composedMessage].UTF8String); } + Value Produce(OSLogEntry* log) const override { + return Value([static_cast(log) composedMessage].UTF8String); + } }; class FormatStringColumn : public Column { public: FormatStringColumn(idx_t i) : Column(i, "formatString") {} LogicalType type() const override { return LogicalType::VARCHAR; } - Value Produce(OSLogEntry* log) const override { return Value([static_cast(log) formatString].UTF8String); } + Value Produce(OSLogEntry* log) const override { + return Value([static_cast(log) formatString].UTF8String); + } }; const vector& GetColumns() { idx_t i = 0; // XXX - don't leak this static const vector kColumns = { - new DateColumn(i++), - new LevelColumn(i++), - new SubsystemColumn(i++), - new CategoryColumn(i++), - new ProcessColumn(i++), - new ProcessIdColumn(i++), - new SenderColumn(i++), - new ThreadIdColumn(i++), - new MessageColumn(i++), - new FormatStringColumn(i++), + new DateColumn(i++), new LevelColumn(i++), new SubsystemColumn(i++), + new CategoryColumn(i++), new ProcessColumn(i++), new ProcessIdColumn(i++), + new SenderColumn(i++), new ThreadIdColumn(i++), new MessageColumn(i++), + new FormatStringColumn(i++), }; return kColumns; } -struct OSLogLocalState : public LocalTableFunctionState { -}; +struct OSLogLocalState : public LocalTableFunctionState {}; struct OSLogTableFunctionData : public TableFunctionData { OSLogStore* store = nil; @@ -142,13 +156,15 @@ struct OSLogTableFunctionData : public TableFunctionData { }; NSString* NSStringFromString(const string& str) { - return [[NSString alloc] initWithBytes:str.data() length:str.length() encoding:NSUTF8StringEncoding]; + return [[NSString alloc] initWithBytes:str.data() + length:str.length() + encoding:NSUTF8StringEncoding]; } unique_ptr OSLogBind(ClientContext& context, TableFunctionBindInput& input, vector& return_types, - vector &names) { + vector& names) { const auto& archive = input.named_parameters["archive"]; if (archive.IsNull()) { throw InvalidInputException("Missing 'archive' parameter"); @@ -171,21 +187,21 @@ unique_ptr OSLogBind(ClientContext& context, return data; } -unique_ptr OSLogLocalInit( - ExecutionContext& context, - TableFunctionInitInput& input, - GlobalTableFunctionState* global_state) { +unique_ptr OSLogLocalInit(ExecutionContext& context, + TableFunctionInitInput& input, + GlobalTableFunctionState* global_state) { return make_uniq(); } -void OSLogTableFunction(ClientContext& context, - TableFunctionInput& data, - DataChunk& output) { +void OSLogTableFunction(ClientContext& context, TableFunctionInput& data, DataChunk& output) { auto& oslog = const_cast(data.bind_data->Cast()); if (!oslog.enumerator) { NSError* error = nil; - oslog.enumerator = [oslog.store entriesEnumeratorWithOptions:0 position:nil predicate:nil error:&error]; + oslog.enumerator = [oslog.store entriesEnumeratorWithOptions:0 + position:nil + predicate:nil + error:&error]; if (error) { throw IOException(error.description.UTF8String); } @@ -195,8 +211,7 @@ void OSLogTableFunction(ClientContext& context, idx_t count = 0; OSLogEntry* entry = nil; - while (count < output.GetCapacity() && - (entry = [oslog.enumerator nextObject])) { + while (count < output.GetCapacity() && (entry = [oslog.enumerator nextObject])) { if (![entry isKindOfClass:[OSLogEntryLog class]]) { continue; } @@ -214,7 +229,8 @@ void OSLogTableFunction(ClientContext& context, } // namespace TableFunction GetTableFunction() { - TableFunction table_fn("oslog", /*args=*/ {}, &OSLogTableFunction, &OSLogBind, /*global_init=*/ nullptr, &OSLogLocalInit); + TableFunction table_fn("oslog", /*args=*/{}, &OSLogTableFunction, &OSLogBind, + /*global_init=*/nullptr, &OSLogLocalInit); table_fn.named_parameters["archive"] = LogicalType::VARCHAR; table_fn.named_parameters["start"] = LogicalType::TIMESTAMP; table_fn.named_parameters["end"] = LogicalType::TIMESTAMP; -- 2.43.5