From eabaaf3a1a3a2edf3f7997e4347d9541b3235dac Mon Sep 17 00:00:00 2001 From: Mathieu Favreau Date: Mon, 29 Sep 2025 15:37:02 +0000 Subject: [PATCH] Don't use filesystem --- .../gnuradio_blocks/labsat23_source.cc | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc b/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc index e05c0b317..b5a04f729 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/labsat23_source.cc @@ -20,17 +20,7 @@ #include "labsat23_source.h" #include "INIReader.h" #include "command_event.h" -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include #if HAS_BOOST_ENDIAN #include @@ -102,6 +92,33 @@ void read_file_register_to_local_endian(std::ifstream &binary_input_file, uint64 #endif } +std::string get_extension(const std::string &path) +{ + size_t slash_pos = path.find_last_of("/\\"); // handle directories + size_t dot_pos = path.find_last_of('.'); + + // No dot or dot is in the directory part → no extension + if (dot_pos == std::string::npos || (slash_pos != std::string::npos && dot_pos < slash_pos)) + { + return ""; // no extension + } + + return path.substr(dot_pos); // includes the dot +} + +std::string replace_extension(const std::string &path, const std::string &new_ext) +{ + const auto dot_pos = path.find_last_of('.'); + if (dot_pos == std::string::npos) + { + return path + new_ext; // no extension just append + } + else + { + return path.substr(0, dot_pos) + new_ext; + } +} + } // namespace @@ -146,11 +163,10 @@ labsat23_source::labsat23_source(const char *signal_file_basename, std::cout << "LabSat file version 4 detected.\n"; } - std::filesystem::path file_path(signal_file); - file_path.replace_extension(".ini"); + const auto ini_file = replace_extension(signal_file, ".ini"); // Read ini file - if (read_ls3w_ini(file_path) != 0) + if (read_ls3w_ini(ini_file) != 0) { exit(1); } @@ -192,8 +208,7 @@ labsat23_source::~labsat23_source() std::string labsat23_source::generate_filename() { - std::filesystem::path file_path(d_signal_file_basename); - const auto extension = file_path.extension(); + const auto extension = get_extension(d_signal_file_basename); if (extension == ".ls2" or extension == ".LS2") {