Skip to content

Commit

Permalink
🚧 make clang-tidy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
vnepogodin committed Aug 15, 2024
1 parent e478074 commit 9bb3e77
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/conf-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <cstdio>
#include <cstdlib>

#include <algorithm> // for for_each
#include <algorithm> // for for_each, transform
#include <filesystem> // for permissions
#include <ranges> // for ranges::*
#include <string_view> // for string_view
Expand Down Expand Up @@ -156,7 +156,7 @@ inline auto set_combobox_val(QComboBox* combobox, ssize_t index) noexcept {
if (index < 0) {
return 1;
}
combobox->setCurrentIndex(index);
combobox->setCurrentIndex(static_cast<std::int32_t>(index));
return 0;
}

Expand Down Expand Up @@ -539,7 +539,7 @@ ConfWindow::ConfWindow(QWidget* parent)
/* clang-format on */

// Prepend 'file://' to each selected patch file.
std::transform(files.cbegin(), files.cend(),
std::ranges::transform(files,
files.begin(), // write to the same location
[](auto&& file_path) { return QString("file://") + std::forward<decltype(file_path)>(file_path); });

Expand Down
2 changes: 1 addition & 1 deletion src/km-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void init_kernels_tree_widget(QTreeWidget* tree_kernels, std::span<Kernel> kerne
widget_item->setCheckState(TreeCol::Check, Qt::Unchecked);
widget_item->setText(TreeCol::PkgName, kernel.get_raw());
widget_item->setText(TreeCol::Version, kernel.version().c_str());
widget_item->setText(TreeCol::Category, kernel.category().data());
widget_item->setText(TreeCol::Category, QLatin1StringView(kernel.category().data(), kernel.category().size()));
widget_item->setText(TreeCol::Displayed, QStringLiteral("true"));
if (kernel.is_installed()) {
const std::string_view kernel_installed_db = kernel.get_installed_db();
Expand Down
10 changes: 5 additions & 5 deletions src/schedext-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,28 @@ void SchedExtWindow::on_apply() noexcept {
return "restart"sv;
}();

const auto is_flags_commented = []() -> bool {
static constexpr auto is_flags_commented = []() -> bool {
using namespace std::string_view_literals;
static constexpr auto scx_conf_path = "/etc/default/scx"sv;
const auto& scx_conf_content = utils::read_whole_file(scx_conf_path);
return scx_conf_content.find("#SCX_FLAGS="sv) != std::string::npos;
};
const auto get_scx_flags_sed = [](std::string_view sched_flags_text, bool flags_commented) -> std::string {
static constexpr auto get_scx_flags_sed = [](std::string_view sched_flags_text, bool flags_commented) -> std::string {
using namespace std::string_literals;
if (sched_flags_text.empty() && !flags_commented) {
// comment out flags in scx
return "-e 's/SCX_FLAGS=/#SCX_FLAGS=/'"s;
} else if (!sched_flags_text.empty() && flags_commented) {
// set flags in scx
return fmt::format("-e \"s/.*SCX_FLAGS=.*/SCX_FLAGS=\'{}\'/\"", sched_flags_text);
return fmt::format(R"(-e "s/.*SCX_FLAGS=.*/SCX_FLAGS='{}'/")", sched_flags_text);
} else if (!sched_flags_text.empty() && !flags_commented) {
// set flags in scx
return fmt::format("-e \"s/SCX_FLAGS=.*/SCX_FLAGS=\'{}\'/\"", sched_flags_text);
return fmt::format(R"(-e "s/SCX_FLAGS=.*/SCX_FLAGS='{}'/")", sched_flags_text);
}
return ""s;
};

bool flags_commented = is_flags_commented();
const bool flags_commented = is_flags_commented();

// TODO(vnepogodin): refactor that
const auto& sched_flags_text = m_ui->schedext_flags_edit->text().trimmed().toStdString();
Expand Down
5 changes: 3 additions & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ auto read_whole_file(std::string_view filepath) noexcept -> std::string {
const std::size_t read = std::fread(buf.data(), sizeof(char), size, file);
if (read != size) {
fmt::print(stderr, "[READWHOLEFILE] '{}' read failed: {}\n", filepath, std::strerror(errno));
std::fclose(file);
return {};
}
std::fclose(file);
Expand Down Expand Up @@ -182,9 +183,9 @@ void restore_clean_environment(std::vector<std::string>& previously_set_options,
for (auto&& expr : set_values_list) {
auto expr_split = utils::make_multiline(std::move(expr), '=');
auto var_name = expr_split[0];
auto var_val = expr_split[1];

if (setenv(var_name.c_str(), var_val.c_str(), 1) != 0) {
const auto& var_val = expr_split[1];
if (::setenv(var_name.c_str(), var_val.c_str(), 1) != 0) {
fmt::print(stderr, "Cannot set environment variable!: {}\n", std::strerror(errno));
continue;
}
Expand Down

0 comments on commit 9bb3e77

Please sign in to comment.