From 81e63784e7990b85e5538ea1d2412d88aa83869c Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Thu, 31 Mar 2022 08:59:19 -0700 Subject: [PATCH] [modernize] some more cleanups --- docs/source/sqltab.rst | 2 + docs/source/usage.rst | 2 + src/CMakeLists.txt | 1 - src/Makefile.am | 1 - src/all_logs_vtab.hh | 2 + src/ansi_scrubber.cc | 6 +- src/archive_manager.cc | 61 +- src/archive_manager.hh | 8 + src/attr_line.hh | 8 + src/base/CMakeLists.txt | 97 ++-- src/base/Makefile.am | 1 + src/{ => base}/auto_fd.hh | 30 +- src/base/fs_util.cc | 18 +- src/base/fs_util.hh | 7 +- src/base/network.tcp.cc | 2 +- src/base/result.h | 36 +- src/bookmarks.cc | 4 +- src/command_executor.cc | 121 ++-- src/command_executor.hh | 9 +- src/curl_looper.cc | 4 +- src/data_parser.cc | 2 - src/data_scanner.cc | 2 - src/elem_to_json.cc | 8 +- src/environ_vtab.cc | 2 - src/field_overlay_source.cc | 19 +- src/file_collection.cc | 61 +- src/file_format.cc | 2 +- src/file_vtab.cc | 6 +- src/filter_sub_source.cc | 44 +- src/format2csv.py | 2 + src/formats/pcap_log.json | 11 +- src/fs-extension-functions.cc | 11 +- src/fstat_vtab.cc | 7 +- src/grep_proc.cc | 6 +- src/grep_proc.hh | 2 +- src/hotkeys.cc | 31 +- src/line_buffer.cc | 14 +- src/line_buffer.hh | 2 +- src/listview_curses.cc | 11 +- src/lnav.cc | 148 ++--- src/lnav_commands.cc | 897 ++++++++++++++++------------- src/lnav_config.cc | 127 ++-- src/log_actions.cc | 31 +- src/log_format.cc | 62 +- src/log_format_impls.cc | 66 +-- src/log_format_loader.cc | 78 ++- src/log_vtab_impl.cc | 37 +- src/logfile.cc | 14 +- src/logfile.hh | 1 + src/logfile_fwd.hh | 50 +- src/logfile_sub_source.cc | 60 +- src/network-extension-functions.cc | 6 +- src/papertrail_proc.hh | 4 +- src/pcap_manager.cc | 4 +- src/pcap_manager.hh | 2 +- src/pcrepp/pcrepp.cc | 4 +- src/piper_proc.cc | 14 +- src/piper_proc.hh | 6 +- src/readline_callbacks.cc | 57 +- src/readline_curses.cc | 70 +-- src/readline_curses.hh | 2 +- src/readline_highlighters.cc | 32 +- src/readline_possibilities.cc | 37 +- src/regexp_vtab.cc | 29 +- src/relative_time.cc | 11 +- src/sequence_matcher.cc | 4 +- src/session_data.cc | 42 +- src/sql_util.cc | 50 +- src/sqlite-extension-func.cc | 114 ++-- src/statusview_curses.cc | 8 +- src/statusview_curses.hh | 1 - src/string-extension-functions.cc | 75 ++- src/string_attr_type.cc | 1 + src/string_attr_type.hh | 37 +- src/styling.cc | 51 +- src/styling.hh | 4 +- src/tailer/drive_tailer.cc | 2 +- src/tailer/tailer.looper.cc | 12 +- src/tailer/tailer.looper.hh | 15 +- src/textfile_highlighters.cc | 2 - src/textview_curses.cc | 27 +- src/time-extension-functions.cc | 2 - src/url_loader.hh | 4 +- src/view_helpers.cc | 64 +- src/vt52_curses.cc | 12 +- src/xpath_vtab.cc | 50 +- src/yajlpp/drive_json_ptr_walk.cc | 4 +- src/yajlpp/json_ptr.cc | 8 +- src/yajlpp/yajlpp.cc | 56 +- test/aftest.cc | 2 +- test/drive_data_scanner.cc | 26 +- test/drive_line_buffer.cc | 2 +- test/scripty.cc | 2 +- test/test_auto_fd.cc | 6 +- test/test_cli.sh | 2 +- test/test_line_buffer2.cc | 2 +- test/test_logfile.sh | 21 +- 97 files changed, 1734 insertions(+), 1486 deletions(-) rename src/{ => base}/auto_fd.hh (93%) diff --git a/docs/source/sqltab.rst b/docs/source/sqltab.rst index 6c5db54c..82f14de2 100644 --- a/docs/source/sqltab.rst +++ b/docs/source/sqltab.rst @@ -137,6 +137,8 @@ with the **lnav_view_filter_stats** table into a single view for ease of use. all_logs -------- +.. f0:sql.tables.all_logs + The **all_logs** table lets you query the format derived from the **lnav** log message parser that is used to automatically extract data, see :ref:`data-ext` for more details. diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 3103d0a3..2b614cb0 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -47,6 +47,8 @@ by pressing :kbd:`t`. Archive Support ^^^^^^^^^^^^^^^ +.. f0:archive + If **lnav** is compiled with `libarchive `_, any files to be opened will be examined to see if they are a supported archive type. If so, the contents of the archive will be extracted to the diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 91e5ba13..75cdfe87 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -343,7 +343,6 @@ add_library( archive_manager.hh archive_manager.cfg.hh attr_line.hh - auto_fd.hh auto_mem.hh big_array.hh bottom_status_source.hh diff --git a/src/Makefile.am b/src/Makefile.am index c70d1838..bdf2ff08 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -158,7 +158,6 @@ noinst_HEADERS = \ archive_manager.hh \ archive_manager.cfg.hh \ attr_line.hh \ - auto_fd.hh \ auto_mem.hh \ big_array.hh \ bin2c.hh \ diff --git a/src/all_logs_vtab.hh b/src/all_logs_vtab.hh index d3e445fe..48b534cf 100644 --- a/src/all_logs_vtab.hh +++ b/src/all_logs_vtab.hh @@ -37,6 +37,8 @@ /** * A virtual table that provides access to all log messages from all formats. + * + * @feature f0:sql.tables.all_logs */ class all_logs_vtab : public log_vtab_impl { public: diff --git a/src/ansi_scrubber.cc b/src/ansi_scrubber.cc index 7e668caa..d20110e7 100644 --- a/src/ansi_scrubber.cc +++ b/src/ansi_scrubber.cc @@ -38,8 +38,6 @@ #include "pcrepp/pcrepp.hh" #include "view_curses.hh" -using namespace std; - static pcrepp& ansi_regex() { @@ -69,7 +67,7 @@ scrub_ansi_string(std::string& str, string_attrs_t& sa) switch (pi.get_substr_start(&caps[2])[0]) { case 'm': for (lpc = caps[1].c_begin; - lpc != string::npos && lpc < (size_t) caps[1].c_end;) + lpc != std::string::npos && lpc < (size_t) caps[1].c_end;) { int ansi_code = 0; @@ -103,7 +101,7 @@ scrub_ansi_string(std::string& str, string_attrs_t& sa) } } lpc = str.find(';', lpc); - if (lpc != string::npos) { + if (lpc != std::string::npos) { lpc += 1; } } diff --git a/src/archive_manager.cc b/src/archive_manager.cc index a80df201..5e1fc191 100644 --- a/src/archive_manager.cc +++ b/src/archive_manager.cc @@ -40,8 +40,8 @@ #include "archive_manager.cfg.hh" #include "archive_manager.hh" -#include "auto_fd.hh" #include "auto_mem.hh" +#include "base/auto_fd.hh" #include "base/fs_util.hh" #include "base/humanize.hh" #include "base/injector.hh" @@ -87,9 +87,13 @@ public: auto lock_path = archive_path; lock_path += ".lck"; - this->lh_fd - = lnav::filesystem::openp(lock_path, O_CREAT | O_RDWR, 0600); - log_perror(fcntl(this->lh_fd, F_SETFD, FD_CLOEXEC)); + auto open_res + = lnav::filesystem::open_file(lock_path, O_CREAT | O_RDWR, 0600); + if (open_res.isErr()) { + throw std::runtime_error(open_res.unwrapErr()); + } + this->lh_fd = open_res.unwrap(); + this->lh_fd.close_on_exec(); }; auto_fd lh_fd; @@ -103,6 +107,7 @@ public: static void enable_desired_archive_formats(archive* arc) { + /** @feature f0:archive.formats */ archive_read_support_format_7zip(arc); archive_read_support_format_cpio(arc); archive_read_support_format_lha(arc); @@ -126,9 +131,9 @@ is_archive(const fs::path& filename) log_debug("read open %s", filename.c_str()); auto r = archive_read_open_filename(arc, filename.c_str(), 128 * 1024); if (r == ARCHIVE_OK) { - struct archive_entry* entry; + struct archive_entry* entry = nullptr; - auto format_name = archive_format_name(arc); + const auto* format_name = archive_format_name(arc); log_debug("read next header %s %s", format_name, filename.c_str()); if (archive_read_next_header(arc, &entry) == ARCHIVE_OK) { @@ -146,7 +151,7 @@ is_archive(const fs::path& filename) return false; } - auto first_filter_name = archive_filter_name(arc, 0); + const auto* first_filter_name = archive_filter_name(arc, 0); if (filter_count == 2 && GZ_FILTER_NAME == first_filter_name) { return false; } @@ -154,11 +159,11 @@ is_archive(const fs::path& filename) log_info( "detected archive: %s -- %s", filename.c_str(), format_name); return true; - } else { - log_info("archive read header failed: %s -- %s", - filename.c_str(), - archive_error_string(arc)); } + + log_info("archive read header failed: %s -- %s", + filename.c_str(), + archive_error_string(arc)); } else { log_info("archive open failed: %s -- %s", filename.c_str(), @@ -214,7 +219,7 @@ copy_data(const std::string& filename, for (;;) { if (total >= next_space_check) { - auto& cfg = injector::get(); + const auto& cfg = injector::get(); auto tmp_space = fs::space(entry_path); if (tmp_space.available < cfg.amc_min_free_space) { @@ -256,10 +261,19 @@ copy_data(const std::string& filename, static walk_result_t extract(const std::string& filename, const extract_cb& cb) { - static int FLAGS = ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM + static const int FLAGS = ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_FFLAGS; + std::error_code ec; auto tmp_path = filename_to_tmp_path(filename); + + fs::create_directories(tmp_path.parent_path(), ec); + if (ec) { + return Err(fmt::format("Unable to create directory: {} -- {}", + tmp_path.parent_path().string(), + ec.message())); + } + auto arc_lock = archive_lock(tmp_path); auto lock_guard = archive_lock::guard(arc_lock); auto done_path = tmp_path; @@ -279,10 +293,9 @@ extract(const std::string& filename, const extract_cb& cb) log_info("%s: archive has already been extracted!", done_path.c_str()); return Ok(); - } else { - log_warning("%s: archive cache has been damaged, re-extracting", - done_path.c_str()); } + log_warning("%s: archive cache has been damaged, re-extracting", + done_path.c_str()); fs::remove(done_path); } @@ -306,7 +319,7 @@ extract(const std::string& filename, const extract_cb& cb) log_info("extracting %s to %s", filename.c_str(), tmp_path.c_str()); while (true) { - struct archive_entry* entry; + struct archive_entry* entry = nullptr; auto r = archive_read_next_header(arc, &entry); if (r == ARCHIVE_EOF) { log_info("all done"); @@ -319,7 +332,7 @@ extract(const std::string& filename, const extract_cb& cb) archive_error_string(arc))); } - auto format_name = archive_format_name(arc); + const auto* format_name = archive_format_name(arc); auto filter_count = archive_filter_count(arc); auto_mem wentry(archive_entry_free); @@ -329,7 +342,7 @@ extract(const std::string& filename, const extract_cb& cb) desired_pathname = fs::path(filename).filename(); } auto entry_path = tmp_path / desired_pathname; - auto prog = cb( + auto* prog = cb( entry_path, archive_entry_size_is_set(entry) ? archive_entry_size(entry) : -1); archive_entry_copy_pathname(wentry, entry_path.c_str()); @@ -343,8 +356,10 @@ extract(const std::string& filename, const extract_cb& cb) fmt::format(FMT_STRING("unable to write entry: {} -- {}"), entry_path.string(), archive_error_string(ext))); - } else if (!archive_entry_size_is_set(entry) - || archive_entry_size(entry) > 0) { + } + + if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0) + { TRY(copy_data(filename, arc, entry, ext, entry_path, prog)); } r = archive_write_finish_entry(ext); @@ -358,7 +373,7 @@ extract(const std::string& filename, const extract_cb& cb) archive_read_close(arc); archive_write_close(ext); - auto_fd(open(done_path.c_str(), O_CREAT | O_WRONLY, 0600)); + lnav::filesystem::open_file(done_path, O_CREAT | O_WRONLY, 0600); return Ok(); } @@ -400,7 +415,7 @@ cleanup_cache() (void) std::async(std::launch::async, []() { auto now = std::chrono::system_clock::now(); auto cache_path = archive_cache_path(); - auto& cfg = injector::get(); + const auto& cfg = injector::get(); std::vector to_remove; log_debug("cache-ttl %d", cfg.amc_cache_ttl.count()); diff --git a/src/archive_manager.hh b/src/archive_manager.hh index 894fedc2..777ae87b 100644 --- a/src/archive_manager.hh +++ b/src/archive_manager.hh @@ -62,6 +62,14 @@ ghc::filesystem::path filename_to_tmp_path(const std::string& filename); using walk_result_t = Result; +/** + * + * @feature f0:archive + * + * @param filename + * @param cb + * @return + */ walk_result_t walk_archive_files( const std::string& filename, const extract_cb& cb, diff --git a/src/attr_line.hh b/src/attr_line.hh index 34d226d6..84e21f21 100644 --- a/src/attr_line.hh +++ b/src/attr_line.hh @@ -186,6 +186,12 @@ struct string_attr { require(type); }; + string_attr(const struct line_range& lr, + std::pair value) + : sa_range(lr), sa_type2(value.first), sa_value2(value.second) + { + } + string_attr() : sa_type(nullptr){}; bool operator<(const struct string_attr& rhs) const @@ -202,6 +208,8 @@ struct string_attr { string_attr_type_t sa_type; string_attr_value_t sa_value; std::string sa_str_value; + string_attr_type_base* sa_type2; + string_attr_value sa_value2; }; /** A map of line ranges to attributes for that range. */ diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index ae631131..ac7e5791 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -1,58 +1,59 @@ add_library( - base STATIC - ../config.h.in - auto_pid.cc - date_time_scanner.cc - fs_util.cc - humanize.cc - humanize.network.cc - humanize.time.cc - intern_string.cc - is_utf8.cc - isc.cc - lnav.gzip.cc - lnav_log.cc - network.tcp.cc - paths.cc - string_util.cc - strnatcmp.c - time_util.cc - auto_pid.hh - date_time_scanner.hh - enum_util.hh - fs_util.hh - func_util.hh - future_util.hh - humanize.hh - humanize.network.hh - humanize.time.hh - injector.hh - injector.bind.hh - intern_string.hh - is_utf8.hh - isc.hh - lrucache.hpp - math_util.hh - network.tcp.hh - paths.hh - result.h - strnatcmp.h - time_util.hh) + base STATIC + ../config.h.in + auto_pid.cc + date_time_scanner.cc + fs_util.cc + humanize.cc + humanize.network.cc + humanize.time.cc + intern_string.cc + is_utf8.cc + isc.cc + lnav.gzip.cc + lnav_log.cc + network.tcp.cc + paths.cc + string_util.cc + strnatcmp.c + time_util.cc + auto_fd.hh + auto_pid.hh + date_time_scanner.hh + enum_util.hh + fs_util.hh + func_util.hh + future_util.hh + humanize.hh + humanize.network.hh + humanize.time.hh + injector.hh + injector.bind.hh + intern_string.hh + is_utf8.hh + isc.hh + lrucache.hpp + math_util.hh + network.tcp.hh + paths.hh + result.h + strnatcmp.h + time_util.hh) target_include_directories(base PUBLIC . .. ../fmtlib ../third-party ${CMAKE_CURRENT_BINARY_DIR}/..) target_link_libraries(base cppfmt pcre::libpcre ncurses::libcurses pthread) add_executable( - test_base - humanize.file_size.tests.cc - humanize.network.tests.cc - humanize.time.tests.cc - intern_string.tests.cc - lnav.gzip.tests.cc - string_util.tests.cc - network.tcp.tests.cc - test_base.cc) + test_base + humanize.file_size.tests.cc + humanize.network.tests.cc + humanize.time.tests.cc + intern_string.tests.cc + lnav.gzip.tests.cc + string_util.tests.cc + network.tcp.tests.cc + test_base.cc) target_include_directories(test_base PUBLIC ../third-party/doctest-root) target_link_libraries(test_base base pcrepp ZLIB::ZLIB) add_test(NAME test_base COMMAND test_base) diff --git a/src/base/Makefile.am b/src/base/Makefile.am index ca513b17..7de7aa24 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -19,6 +19,7 @@ AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS) noinst_LIBRARIES = libbase.a noinst_HEADERS = \ + auto_fd.hh \ auto_pid.hh \ date_time_scanner.hh \ enum_util.hh \ diff --git a/src/auto_fd.hh b/src/base/auto_fd.hh similarity index 93% rename from src/auto_fd.hh rename to src/base/auto_fd.hh index 3df93663..d8276bd7 100644 --- a/src/auto_fd.hh +++ b/src/base/auto_fd.hh @@ -85,14 +85,14 @@ public: return auto_fd{}; } - auto new_fd = dup(fd); + auto new_fd = ::dup(fd); if (new_fd == -1) { throw std::bad_alloc(); } return auto_fd(new_fd); - }; + } /** * Construct an auto_fd to manage the given file descriptor. @@ -102,7 +102,7 @@ public: explicit auto_fd(int fd = -1) : af_fd(fd) { require(fd >= -1); - }; + } /** * Non-const copy constructor. Management of the file descriptor will be @@ -119,12 +119,18 @@ public: * * @param af The source of the file descriptor. */ - auto_fd(const auto_fd& af) : af_fd(-1) + auto_fd(const auto_fd& af) = delete; + + auto_fd dup() const { - if (af.af_fd != -1 && (this->af_fd = dup(af.af_fd)) == -1) { + int new_fd; + + if (this->af_fd == -1 || (new_fd = ::dup(this->af_fd)) == -1) { throw std::bad_alloc(); } - }; + + return auto_fd{new_fd}; + } /** * Destructor that will close the file descriptor managed by this object. @@ -212,7 +218,15 @@ public: if (this->af_fd != fd) { if (this->af_fd != -1) { - close(this->af_fd); + switch (this->af_fd) { + case STDIN_FILENO: + case STDOUT_FILENO: + case STDERR_FILENO: + break; + default: + close(this->af_fd); + break; + } } this->af_fd = fd; } @@ -240,7 +254,7 @@ public: return Err(std::string(strerror(errno))); } - return Ok(retval); + return Ok(std::move(retval)); } explicit auto_pipe(int child_fd = -1, int child_flags = O_RDONLY) diff --git a/src/base/fs_util.cc b/src/base/fs_util.cc index d12d24ae..1a7e307a 100644 --- a/src/base/fs_util.cc +++ b/src/base/fs_util.cc @@ -36,7 +36,21 @@ namespace lnav { namespace filesystem { -Result, std::string> +Result +open_file(const ghc::filesystem::path& path, int flags, mode_t mode) +{ + auto fd = openp(path, flags, mode); + + if (fd == -1) { + return Err(fmt::format(FMT_STRING("Failed to open: {} -- {}"), + path.string(), + strerror(errno))); + } + + return Ok(auto_fd(fd)); +} + +Result, std::string> open_temp_file(const ghc::filesystem::path& pattern) { auto pattern_str = pattern.string(); @@ -51,7 +65,7 @@ open_temp_file(const ghc::filesystem::path& pattern) strerror(errno))); } - return Ok(std::make_pair(ghc::filesystem::path(pattern_copy), fd)); + return Ok(std::make_pair(ghc::filesystem::path(pattern_copy), auto_fd(fd))); } Result diff --git a/src/base/fs_util.hh b/src/base/fs_util.hh index a9c35d14..1fd28d68 100644 --- a/src/base/fs_util.hh +++ b/src/base/fs_util.hh @@ -33,6 +33,7 @@ #include #include +#include "auto_fd.hh" #include "ghc/filesystem.hpp" #include "result.h" @@ -57,7 +58,11 @@ openp(const ghc::filesystem::path& path, int flags, mode_t mode) return open(path.c_str(), flags, mode); } -Result, std::string> open_temp_file( +Result open_file(const ghc::filesystem::path& path, + int flags, + mode_t mode); + +Result, std::string> open_temp_file( const ghc::filesystem::path& pattern); Result read_file(const ghc::filesystem::path& path); diff --git a/src/base/network.tcp.cc b/src/base/network.tcp.cc index 5eede974..62760626 100644 --- a/src/base/network.tcp.cc +++ b/src/base/network.tcp.cc @@ -66,7 +66,7 @@ connect(const char* hostname, const char* servname) strerror(rc))); } - return Ok(retval); + return Ok(std::move(retval)); } } // namespace tcp diff --git a/src/base/result.h b/src/base/result.h index 6162d01b..1eaa2a29 100644 --- a/src/base/result.h +++ b/src/base/result.h @@ -770,25 +770,29 @@ struct Result { return !ok_; } - T expect(const char* str) const { + T expect(const char* str) + { if (!isOk()) { ::fprintf(stderr, "%s\n", str); - std::terminate(); + std::terminate(); } return expect_impl(std::is_same()); } template - auto map(Func func) const { + auto map(Func func) + { using return_type = decltype(func(T{})); if (this->isOk()) { - auto value = this->storage().template get(); - auto res = func(value); - return Result(types::Ok(std::move(res))); + auto value = std::move(this->storage().template get()); + auto res = func(std::move(value)); + return Result( + types::Ok(std::move(res))); } - return Result(types::Err(this->storage().template get())); + return Result( + types::Err(this->storage().template get())); } template - typename std::enable_if< - std::is_same::value, - U - >::type - unwrap() const { + typename std::enable_if::value, U>::type unwrap() + const + { if (isOk()) { return; } @@ -914,7 +916,8 @@ struct Result { std::terminate(); } - E unwrapErr() const { + E unwrapErr() const + { if (isErr()) { return storage().template get(); } @@ -924,8 +927,11 @@ struct Result { } private: - T expect_impl(std::true_type) const { } - T expect_impl(std::false_type) const { return storage_.template get(); } + T expect_impl(std::true_type) const {} + T expect_impl(std::false_type) + { + return std::move(storage_.template get()); + } bool ok_; storage_type storage_; diff --git a/src/bookmarks.cc b/src/bookmarks.cc index 8570ff2f..f26f7dcb 100644 --- a/src/bookmarks.cc +++ b/src/bookmarks.cc @@ -33,6 +33,4 @@ #include "config.h" -using namespace std; - -set bookmark_metadata::KNOWN_TAGS; +std::set bookmark_metadata::KNOWN_TAGS; diff --git a/src/command_executor.cc b/src/command_executor.cc index 0282601a..3384ec1c 100644 --- a/src/command_executor.cc +++ b/src/command_executor.cc @@ -47,11 +47,9 @@ #include "sql_util.hh" #include "yajlpp/json_ptr.hh" -using namespace std; - exec_context INIT_EXEC_CONTEXT; -static const string MSG_FORMAT_STMT = R"( +static const std::string MSG_FORMAT_STMT = R"( SELECT count(*) AS total, min(log_line) AS log_line, log_msg_format FROM all_logs GROUP BY log_msg_format @@ -103,16 +101,17 @@ sql_progress_finished() lnav_data.ld_views[LNV_DB].redo_search(); } -Result execute_from_file(exec_context& ec, - const ghc::filesystem::path& path, - int line_number, - char mode, - const string& cmdline); +Result execute_from_file( + exec_context& ec, + const ghc::filesystem::path& path, + int line_number, + char mode, + const std::string& cmdline); -Result -execute_command(exec_context& ec, const string& cmdline) +Result +execute_command(exec_context& ec, const std::string& cmdline) { - vector args; + std::vector args; log_info("Executing: %s", cmdline.c_str()); @@ -131,14 +130,14 @@ execute_command(exec_context& ec, const string& cmdline) return ec.make_error("no command to execute"); } -Result -execute_sql(exec_context& ec, const string& sql, string& alt_msg) +Result +execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg) { db_label_source& dls = lnav_data.ld_db_row_source; auto_mem stmt(sqlite3_finalize); struct timeval start_tv, end_tv; - string stmt_str = trim(sql); - string retval; + std::string stmt_str = trim(sql); + std::string retval; int retcode; log_info("Executing SQL: %s", sql.c_str()); @@ -146,7 +145,7 @@ execute_sql(exec_context& ec, const string& sql, string& alt_msg) lnav_data.ld_bottom_source.grep_error(""); if (startswith(stmt_str, ".")) { - vector args; + std::vector args; split_ws(stmt_str, args); auto sql_cmd_map = injector::getclear(); - pair source = ec.ec_source.top(); + std::pair source = ec.ec_source.top(); sql_progress_guard progress_guard( sql_progress, sql_progress_finished, source.first, source.second); gettimeofday(&start_tv, nullptr); @@ -193,7 +192,7 @@ execute_sql(exec_context& ec, const string& sql, string& alt_msg) param_count = sqlite3_bind_parameter_count(stmt.in()); for (int lpc = 0; lpc < param_count; lpc++) { - map::iterator ov_iter; + std::map::iterator ov_iter; const char* name; name = sqlite3_bind_parameter_name(stmt.in(), lpc + 1); @@ -207,7 +206,8 @@ execute_sql(exec_context& ec, const string& sql, string& alt_msg) } else if (name[0] == '$') { const auto& lvars = ec.ec_local_vars.top(); const auto& gvars = ec.ec_global_vars; - map::const_iterator local_var, global_var; + std::map::const_iterator local_var, + global_var; const char* env_value; if (lnav_data.ld_window) { @@ -409,7 +409,7 @@ execute_sql(exec_context& ec, const string& sql, string& alt_msg) return Ok(retval); } -static Result +static Result execute_file_contents(exec_context& ec, const ghc::filesystem::path& path, bool multiline) @@ -417,7 +417,7 @@ execute_file_contents(exec_context& ec, static ghc::filesystem::path stdin_path("-"); static ghc::filesystem::path dev_stdin_path("/dev/stdin"); - string retval; + std::string retval; FILE* file; if (path == stdin_path || path == dev_stdin_path) { @@ -433,7 +433,7 @@ execute_file_contents(exec_context& ec, auto_mem line; size_t line_max_size; ssize_t line_size; - string cmdline; + std::string cmdline; char mode = '\0'; ec.ec_path_stack.emplace_back(path.parent_path()); @@ -460,7 +460,7 @@ execute_file_contents(exec_context& ec, starting_line_number = line_number; mode = line[0]; - cmdline = string(&line[1]); + cmdline = std::string(&line[1]); break; default: if (multiline) { @@ -490,12 +490,12 @@ execute_file_contents(exec_context& ec, return Ok(retval); } -Result -execute_file(exec_context& ec, const string& path_and_args, bool multiline) +Result +execute_file(exec_context& ec, const std::string& path_and_args, bool multiline) { available_scripts scripts; - vector split_args; - string retval, msg; + std::vector split_args; + std::string retval, msg; shlex lexer(path_and_args); log_info("Executing file: %s", path_and_args.c_str()); @@ -512,7 +512,7 @@ execute_file(exec_context& ec, const string& path_and_args, bool multiline) auto script_name = split_args[0]; auto& vars = ec.ec_local_vars.top(); char env_arg_name[32]; - string star, open_error = "file not found"; + std::string star, open_error = "file not found"; add_ansi_vars(vars); @@ -532,7 +532,7 @@ execute_file(exec_context& ec, const string& path_and_args, bool multiline) } vars["__all__"] = star; - vector paths_to_exec; + std::vector paths_to_exec; find_format_scripts(lnav_data.ld_config_paths, scripts); auto iter = scripts.as_scripts.find(script_name); @@ -583,14 +583,14 @@ execute_file(exec_context& ec, const string& path_and_args, bool multiline) return Ok(retval); } -Result +Result execute_from_file(exec_context& ec, const ghc::filesystem::path& path, int line_number, char mode, - const string& cmdline) + const std::string& cmdline) { - string retval, alt_msg; + std::string retval, alt_msg; auto _sg = ec.enter_source(path.string(), line_number); switch (mode) { @@ -621,10 +621,10 @@ execute_from_file(exec_context& ec, return Ok(retval); } -Result -execute_any(exec_context& ec, const string& cmdline_with_mode) +Result +execute_any(exec_context& ec, const std::string& cmdline_with_mode) { - string retval, alt_msg, cmdline = cmdline_with_mode.substr(1); + std::string retval, alt_msg, cmdline = cmdline_with_mode.substr(1); auto _cleanup = finally([&ec] { if (ec.is_read_write() && // only rebuild in a script or non-interactive mode so we don't @@ -661,8 +661,9 @@ execute_any(exec_context& ec, const string& cmdline_with_mode) } void -execute_init_commands(exec_context& ec, - vector, string> >& msgs) +execute_init_commands( + exec_context& ec, + std::vector, std::string>>& msgs) { if (lnav_data.ld_cmd_init_done) { return; @@ -673,7 +674,7 @@ execute_init_commands(exec_context& ec, log_info("Executing initial commands"); for (auto& cmd : lnav_data.ld_commands) { - string alt_msg; + std::string alt_msg; wait_for_children(); @@ -705,9 +706,10 @@ execute_init_commands(exec_context& ec, if (!lnav_data.ld_pt_search.empty()) { #ifdef HAVE_LIBCURL - auto pt = make_shared(lnav_data.ld_pt_search.substr(3), - lnav_data.ld_pt_min_time, - lnav_data.ld_pt_max_time); + auto pt = std::make_shared( + lnav_data.ld_pt_search.substr(3), + lnav_data.ld_pt_min_time, + lnav_data.ld_pt_max_time); lnav_data.ld_active_files.fc_file_names[lnav_data.ld_pt_search].with_fd( pt->copy_fd()); isc::to().send( @@ -744,7 +746,7 @@ sql_callback(exec_context& ec, sqlite3_stmt* stmt) if (dls.dls_headers.empty()) { for (lpc = 0; lpc < ncols; lpc++) { int type = sqlite3_column_type(stmt, lpc); - string colname = sqlite3_column_name(stmt, lpc); + std::string colname = sqlite3_column_name(stmt, lpc); bool graphable; graphable = ((type == SQLITE_INTEGER || type == SQLITE_FLOAT) @@ -782,8 +784,8 @@ sql_callback(exec_context& ec, sqlite3_stmt* stmt) return retval; } -future -pipe_callback(exec_context& ec, const string& cmdline, auto_fd& fd) +std::future +pipe_callback(exec_context& ec, const std::string& cmdline, auto_fd& fd) { auto out = ec.get_output(); @@ -802,21 +804,20 @@ pipe_callback(exec_context& ec, const string& cmdline, auto_fd& fd) fwrite(buffer, rc, 1, file); } - return string(); + return std::string(); }); } else { - auto pp = make_shared( - fd, - false, - lnav::filesystem::open_temp_file( - ghc::filesystem::temp_directory_path() / "lnav.out.XXXXXX") - .map([](auto pair) { - ghc::filesystem::remove(pair.first); - - return pair; - }) - .expect("Cannot create temporary file for callback") - .second); + auto tmp_fd + = lnav::filesystem::open_temp_file( + ghc::filesystem::temp_directory_path() / "lnav.out.XXXXXX") + .map([](auto pair) { + ghc::filesystem::remove(pair.first); + + return std::move(pair.second); + }) + .expect("Cannot create temporary file for callback"); + auto pp = std::make_shared( + std::move(fd), false, std::move(tmp_fd)); static int exec_count = 0; lnav_data.ld_pipers.push_back(pp); @@ -841,7 +842,7 @@ add_global_vars(exec_context& ec) { for (const auto& iter : lnav_config.lc_global_vars) { shlex subber(iter.second); - string str; + std::string str; if (!subber.eval(str, ec.ec_global_vars)) { log_error("Unable to evaluate global variable value: %s", @@ -867,7 +868,9 @@ exec_context::get_error_prefix() } void -exec_context::set_output(const string& name, FILE* file, int (*closer)(FILE*)) +exec_context::set_output(const std::string& name, + FILE* file, + int (*closer)(FILE*)) { log_info("redirecting command output to: %s", name.c_str()); this->ec_output_stack.back().second | [](auto out) { diff --git a/src/command_executor.hh b/src/command_executor.hh index f022db74..b8969777 100644 --- a/src/command_executor.hh +++ b/src/command_executor.hh @@ -36,7 +36,7 @@ #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "bookmarks.hh" #include "fmt/format.h" #include "ghc/filesystem.hpp" @@ -48,12 +48,11 @@ struct exec_context; class attr_line_t; class logline_value; -typedef int (*sql_callback_t)(exec_context& ec, sqlite3_stmt* stmt); +using sql_callback_t = int (*)(exec_context&, sqlite3_stmt*); int sql_callback(exec_context& ec, sqlite3_stmt* stmt); -typedef std::future (*pipe_callback_t)(exec_context& ec, - const std::string& cmdline, - auto_fd& fd); +using pipe_callback_t + = std::future (*)(exec_context&, const std::string&, auto_fd&); struct exec_context { enum class perm_t { diff --git a/src/curl_looper.cc b/src/curl_looper.cc index 9bbd2183..63f68e73 100644 --- a/src/curl_looper.cc +++ b/src/curl_looper.cc @@ -38,7 +38,7 @@ # include "curl_looper.hh" -using namespace std; +using namespace std::chrono_literals; struct curl_request_eq { explicit curl_request_eq(const std::string& name) : cre_name(name){}; @@ -49,7 +49,7 @@ struct curl_request_eq { }; bool operator()( - const pair>& pair) const + const std::pair>& pair) const { return this->cre_name == pair.second->get_name(); }; diff --git a/src/data_parser.cc b/src/data_parser.cc index 3755f7ef..7db577c0 100644 --- a/src/data_parser.cc +++ b/src/data_parser.cc @@ -34,8 +34,6 @@ #include "config.h" #include "spookyhash/SpookyV2.h" -using namespace std; - data_format data_parser::FORMAT_SEMI("semi", DT_COMMA, DT_SEMI); data_format data_parser::FORMAT_COMMA("comma", DT_INVALID, DT_COMMA); data_format data_parser::FORMAT_PLAIN("plain", DT_INVALID, DT_INVALID); diff --git a/src/data_scanner.cc b/src/data_scanner.cc index 20e43271..8d466e2e 100644 --- a/src/data_scanner.cc +++ b/src/data_scanner.cc @@ -36,8 +36,6 @@ #include "config.h" #include "pcrepp/pcrepp.hh" -using namespace std; - static struct { const char* name; pcrepp pcre; diff --git a/src/elem_to_json.cc b/src/elem_to_json.cc index 50dceb70..10ed6fa6 100644 --- a/src/elem_to_json.cc +++ b/src/elem_to_json.cc @@ -34,8 +34,6 @@ #include "config.h" #include "yajlpp/yajlpp.hh" -using namespace std; - static void element_to_json(yajl_gen gen, data_parser& dp, const data_parser::element& elem) { @@ -54,7 +52,7 @@ element_to_json(yajl_gen gen, data_parser& dp, const data_parser::element& elem) } case DNT_PAIR: { const data_parser::element& pair_elem = elem.get_pair_elem(); - string key_str + const auto key_str = dp.get_element_string(pair_elem.e_sub_elements->front()); if (!key_str.empty()) { @@ -137,10 +135,10 @@ map_elements_to_json(yajl_gen gen, data_parser::element_list_t* el) { bool unique_names = el->size() > 1; - vector names; + std::vector names; for (auto& iter : *el) { - const data_parser::element& pvalue = iter.get_pair_value(); + const auto& pvalue = iter.get_pair_value(); if (pvalue.value_token() == DT_INVALID) { log_debug("invalid!!"); diff --git a/src/environ_vtab.cc b/src/environ_vtab.cc index 302ac92c..d8b77928 100644 --- a/src/environ_vtab.cc +++ b/src/environ_vtab.cc @@ -36,8 +36,6 @@ #include "base/lnav_log.hh" #include "config.h" -using namespace std; - extern char** environ; const char* const ENVIRON_CREATE_STMT = R"( diff --git a/src/field_overlay_source.cc b/src/field_overlay_source.cc index 7084f92c..d799cf78 100644 --- a/src/field_overlay_source.cc +++ b/src/field_overlay_source.cc @@ -40,8 +40,6 @@ #include "vtab_module.hh" #include "vtab_module_json.hh" -using namespace std; - json_string extract(const char* str); void @@ -65,7 +63,7 @@ field_overlay_source::build_summary_lines(const listview_curses& lv) if (free_rows < 2 || !this->fos_show_status) { this->fos_summary_lines.clear(); } else { - string time_span; + std::string time_span; double error_rate = 0.0; if (lv.get_inner_height() == 0) { @@ -130,7 +128,7 @@ field_overlay_source::build_summary_lines(const listview_curses& lv) long computed_rate_len = lrint(ceil((recent_error_rate * 40.0) / long_error_rate)); - rate_len = min(10L, computed_rate_len); + rate_len = std::min(10L, computed_rate_len); } } } @@ -164,7 +162,7 @@ field_overlay_source::build_summary_lines(const listview_curses& lv) error_rate, time_span.c_str()); } - string& sum_msg = sum_line.get_string(); + const auto& sum_msg = sum_line.get_string(); sum_line .with_attr(string_attr( line_range(sum_msg.find("Error rate"), @@ -248,7 +246,7 @@ field_overlay_source::build_field_lines(const listview_curses& lv) char old_timestamp[64], curr_timestamp[64], orig_timestamp[64]; struct timeval curr_tv, offset_tv, orig_tv, diff_tv = {0, 0}; attr_line_t time_line; - string& time_str = time_line.get_string(); + auto& time_str = time_line.get_string(); struct line_range time_lr; sql_strftime(curr_timestamp, @@ -368,7 +366,8 @@ field_overlay_source::build_field_lines(const listview_curses& lv) if (!meta.lvm_struct_name.empty()) { this_key_size += meta.lvm_struct_name.size() + 11; } - this->fos_known_key_size = max(this->fos_known_key_size, this_key_size); + this->fos_known_key_size + = std::max(this->fos_known_key_size, this_key_size); } for (auto iter = this->fos_log_helper.ldh_parser->dp_pairs.begin(); @@ -381,7 +380,7 @@ field_overlay_source::build_field_lines(const listview_curses& lv) colname = this->fos_log_helper.ldh_namer->add_column(colname); this->fos_unknown_key_size - = max(this->fos_unknown_key_size, (int) colname.length()); + = std::max(this->fos_unknown_key_size, (int) colname.length()); } auto lf = this->fos_log_helper.ldh_file->get_format(); @@ -408,9 +407,9 @@ field_overlay_source::build_field_lines(const listview_curses& lv) auto curr_format = lv.lv_meta.lvm_format.value(); auto curr_elf = dynamic_cast(curr_format); - string format_name = curr_format->get_name().to_string(); + const auto format_name = curr_format->get_name().to_string(); attr_line_t al; - string str, value_str = lv.to_string(); + std::string str, value_str = lv.to_string(); if (curr_format != last_format) { this->fos_lines.emplace_back(" Known message fields for table " diff --git a/src/file_collection.cc b/src/file_collection.cc index c33c1b01..60007b37 100644 --- a/src/file_collection.cc +++ b/src/file_collection.cc @@ -158,8 +158,9 @@ file_collection::merge(file_collection& other) other.fc_synced_files.end()); this->fc_name_to_errors.insert(other.fc_name_to_errors.begin(), other.fc_name_to_errors.end()); - this->fc_file_names.insert(other.fc_file_names.begin(), - other.fc_file_names.end()); + this->fc_file_names.insert( + std::make_move_iterator(other.fc_file_names.begin()), + std::make_move_iterator(other.fc_file_names.end())); if (!other.fc_files.empty()) { for (const auto& lf : other.fc_files) { this->fc_name_to_errors.erase(lf->get_filename()); @@ -229,6 +230,15 @@ file_collection::watch_logfile(const std::string& filename, if (loo.loo_fd != -1) { rc = fstat(loo.loo_fd, &st); + if (rc == 0) { + loo.with_stat_for_temp(st); + } + } else if (loo.loo_temp_file) { + memset(&st, 0, sizeof(st)); + st.st_dev = loo.loo_temp_dev; + st.st_ino = loo.loo_temp_ino; + st.st_mode = S_IFREG; + rc = 0; } else { rc = stat(filename.c_str(), &st); } @@ -292,7 +302,7 @@ file_collection::watch_logfile(const std::string& filename, auto func = [filename, st, - loo, + loo2 = std::move(loo), prog = this->fc_progress, errs = this->fc_name_to_errors]() mutable { file_collection retval; @@ -304,7 +314,7 @@ file_collection::watch_logfile(const std::string& filename, auto ff = detect_file_format(filename); - loo.loo_file_format = ff; + loo2.loo_file_format = ff; switch (ff) { case file_format_t::SQLITE_DB: retval.fc_other_files[filename].ofd_format = ff; @@ -316,7 +326,7 @@ file_collection::watch_logfile(const std::string& filename, if (res.isOk()) { auto convert_res = res.unwrap(); - loo.loo_fd = std::move(convert_res.cr_destination); + loo2.with_fd(std::move(convert_res.cr_destination)); retval.fc_child_pollers.emplace_back(child_poller{ std::move(convert_res.cr_child), [filename, @@ -342,7 +352,7 @@ file_collection::watch_logfile(const std::string& filename, }); }, }); - auto open_res = logfile::open(filename, loo); + auto open_res = logfile::open(filename, loo2); if (open_res.isOk()) { retval.fc_files.push_back(open_res.unwrap()); } else { @@ -368,7 +378,7 @@ file_collection::watch_logfile(const std::string& filename, std::list::iterator> prog_iter_opt; - if (loo.loo_source == logfile_name_source::ARCHIVE) { + if (loo2.loo_source == logfile_name_source::ARCHIVE) { // Don't try to open nested archives return retval; } @@ -435,7 +445,7 @@ file_collection::watch_logfile(const std::string& filename, default: log_info("loading new file: filename=%s", filename.c_str()); - auto open_res = logfile::open(filename, loo); + auto open_res = logfile::open(filename, loo2); if (open_res.isOk()) { retval.fc_files.push_back(open_res.unwrap()); } else { @@ -452,16 +462,16 @@ file_collection::watch_logfile(const std::string& filename, return retval; }; - return std::async(std::launch::async, func); - } else { - auto lf = *file_iter; + return std::async(std::launch::async, std::move(func)); + } - if (lf->is_valid_filename() && lf->get_filename() != filename) { - /* The file is already loaded, but has been found under a different - * name. We just need to update the stored file name. - */ - retval.fc_renamed_files.emplace_back(lf, filename); - } + auto lf = *file_iter; + + if (lf->is_valid_filename() && lf->get_filename() != filename) { + /* The file is already loaded, but has been found under a different + * name. We just need to update the stored file name. + */ + retval.fc_renamed_files.emplace_back(lf, filename); } return lnav::futures::make_ready_future(std::move(retval)); @@ -513,9 +523,12 @@ file_collection::expand_filename( } file_collection retval; + logfile_open_options_base loo_base{loo}; isc::to().send( - [=](auto& tlooper) { tlooper.add_remote(rp, loo); }); + [rp, loo_base](auto& tlooper) { + tlooper.add_remote(rp, loo_base); + }); retval.fc_other_files[path] = file_format_t::REMOTE; { this->fc_progress->writeAccess() @@ -546,7 +559,7 @@ file_collection::expand_filename( if ((abspath = realpath(gl->gl_pathv[lpc], nullptr)) == nullptr) { - auto errmsg = strerror(errno); + auto* errmsg = strerror(errno); if (required) { fprintf(stderr, @@ -576,11 +589,11 @@ file_collection::expand_filename( std::move(retval))); } continue; - } else { - auto p = REALPATH_CACHE.emplace(path_str, abspath.in()); - - iter = p.first; } + + auto p = REALPATH_CACHE.emplace(path_str, abspath.in()); + + iter = p.first; } if (required || access(iter->second.c_str(), R_OK) == 0) { @@ -598,7 +611,7 @@ file_collection::rescan_files(bool required) [&retval](auto& fc) { retval.merge(fc); }); for (auto& pair : this->fc_file_names) { - if (pair.second.loo_fd == -1) { + if (!pair.second.loo_temp_file) { this->expand_filename(fq, pair.first, pair.second, required); if (this->fc_rotated) { std::string path = pair.first + ".*"; diff --git a/src/file_format.cc b/src/file_format.cc index 4062ac20..d82b78cd 100644 --- a/src/file_format.cc +++ b/src/file_format.cc @@ -34,7 +34,7 @@ #include "file_format.hh" #include "archive_manager.hh" -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "base/fs_util.hh" #include "base/intern_string.hh" #include "base/lnav_log.hh" diff --git a/src/file_vtab.cc b/src/file_vtab.cc index c71051eb..968a6369 100644 --- a/src/file_vtab.cc +++ b/src/file_vtab.cc @@ -41,10 +41,8 @@ #include "session_data.hh" #include "vtab_module.hh" -using namespace std; - struct lnav_file : public tvt_iterator_cursor { - using iterator = vector>::iterator; + using iterator = std::vector>::iterator; static constexpr const char* NAME = "lnav_file"; static constexpr const char* CREATE_STMT = R"( @@ -78,7 +76,7 @@ CREATE TABLE lnav_file ( { auto lf = *vc.iter; const struct stat& st = lf->get_stat(); - const string& name = lf->get_filename(); + const auto& name = lf->get_filename(); auto format = lf->get_format(); const char* format_name = format != nullptr ? format->get_name().get() : nullptr; diff --git a/src/filter_sub_source.cc b/src/filter_sub_source.cc index 7503af89..889d9393 100644 --- a/src/filter_sub_source.cc +++ b/src/filter_sub_source.cc @@ -37,8 +37,6 @@ #include "readline_highlighters.hh" #include "readline_possibilities.hh" -using namespace std; - filter_sub_source::filter_sub_source() { this->fss_regex_context.set_highlighter(readline_regex_highlighter) @@ -97,7 +95,7 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch) return true; } - shared_ptr tf = *(fs.begin() + lv.get_selection()); + auto tf = *(fs.begin() + lv.get_selection()); fs.set_filter_enabled(tf, !tf->is_enabled()); tss->text_filters_changed(); @@ -113,7 +111,7 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch) return true; } - shared_ptr tf = *(fs.begin() + lv.get_selection()); + auto tf = *(fs.begin() + lv.get_selection()); if (tf->get_type() == text_filter::INCLUDE) { tf->set_type(text_filter::EXCLUDE); @@ -134,7 +132,7 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch) return true; } - shared_ptr tf = *(fs.begin() + lv.get_selection()); + auto tf = *(fs.begin() + lv.get_selection()); fs.delete_filter(tf->get_id()); lv.reload_data(); @@ -153,8 +151,8 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch) return true; } - auto ef = make_shared(text_filter::type_t::INCLUDE, - *filter_index); + auto ef = std::make_shared( + text_filter::type_t::INCLUDE, *filter_index); fs.add_filter(ef); lv.set_selection(vis_line_t(fs.size() - 1)); lv.reload_data(); @@ -190,8 +188,8 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch) return true; } - auto ef = make_shared(text_filter::type_t::EXCLUDE, - *filter_index); + auto ef = std::make_shared( + text_filter::type_t::EXCLUDE, *filter_index); fs.add_filter(ef); lv.set_selection(vis_line_t(fs.size() - 1)); lv.reload_data(); @@ -225,7 +223,7 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch) return true; } - shared_ptr tf = *(fs.begin() + lv.get_selection()); + auto tf = *(fs.begin() + lv.get_selection()); this->fss_editing = true; @@ -309,7 +307,7 @@ filter_sub_source::text_value_for_line(textview_curses& tc, textview_curses* top_view = *lnav_data.ld_view_stack.top(); text_sub_source* tss = top_view->get_sub_source(); filter_stack& fs = tss->get_filters(); - shared_ptr tf = *(fs.begin() + line); + auto tf = *(fs.begin() + line); value_out = " "; switch (tf->get_type()) { @@ -349,7 +347,7 @@ filter_sub_source::text_attrs_for_line(textview_curses& tc, textview_curses* top_view = *lnav_data.ld_view_stack.top(); text_sub_source* tss = top_view->get_sub_source(); filter_stack& fs = tss->get_filters(); - shared_ptr tf = *(fs.begin() + line); + auto tf = *(fs.begin() + line); bool selected = lnav_data.ld_mode == LNM_FILTER && line == tc.get_selection(); @@ -410,7 +408,7 @@ filter_sub_source::text_size_for_line(textview_curses& tc, textview_curses* top_view = *lnav_data.ld_view_stack.top(); text_sub_source* tss = top_view->get_sub_source(); filter_stack& fs = tss->get_filters(); - shared_ptr tf = *(fs.begin() + line); + auto tf = *(fs.begin() + line); return 8 + tf->get_id().size(); } @@ -426,8 +424,8 @@ filter_sub_source::rl_change(readline_curses* rc) } auto iter = fs.begin() + this->tss_view->get_selection(); - shared_ptr tf = *iter; - string new_value = rc->get_line_buffer(); + auto tf = *iter; + auto new_value = rc->get_line_buffer(); switch (tf->get_lang()) { case filter_lang_t::NONE: @@ -507,8 +505,8 @@ filter_sub_source::rl_perform(readline_curses* rc) text_sub_source* tss = top_view->get_sub_source(); filter_stack& fs = tss->get_filters(); auto iter = fs.begin() + this->tss_view->get_selection(); - shared_ptr tf = *iter; - string new_value = rc->get_value(); + auto tf = *iter; + auto new_value = rc->get_value(); if (new_value.empty()) { this->rl_abort(rc); @@ -534,10 +532,10 @@ filter_sub_source::rl_perform(readline_curses* rc) tf->lf_deleted = true; tss->text_filters_changed(); - auto pf = make_shared(tf->get_type(), - new_value, - tf->get_index(), - code.release()); + auto pf = std::make_shared(tf->get_type(), + new_value, + tf->get_index(), + code.release()); *iter = pf; tss->text_filters_changed(); @@ -588,7 +586,7 @@ filter_sub_source::rl_abort(readline_curses* rc) text_sub_source* tss = top_view->get_sub_source(); filter_stack& fs = tss->get_filters(); auto iter = fs.begin() + this->tss_view->get_selection(); - shared_ptr tf = *iter; + auto tf = *iter; lnav_data.ld_log_source.set_preview_sql_filter(nullptr); lnav_data.ld_filter_help_status_source.fss_prompt.clear(); @@ -616,7 +614,7 @@ filter_sub_source::rl_display_matches(readline_curses* rc) this->fss_match_view.set_height(0_vl); this->tss_view->set_needs_update(); } else { - string current_match = rc->get_match_string(); + auto current_match = rc->get_match_string(); attr_line_t al; vis_line_t line, selected_line; diff --git a/src/format2csv.py b/src/format2csv.py index 17b3ce45..a4d4d6d2 100644 --- a/src/format2csv.py +++ b/src/format2csv.py @@ -15,6 +15,8 @@ def main(args): value = format_dict[key] if not isinstance(value, dict): continue + if 'title' not in value: + raise Exception("format '%s' is missing 'title'" % key) out.writerow((value['title'], key, value['description'])) if __name__ == "__main__": diff --git a/src/formats/pcap_log.json b/src/formats/pcap_log.json index 0c213bbf..a3192e15 100644 --- a/src/formats/pcap_log.json +++ b/src/formats/pcap_log.json @@ -2,14 +2,17 @@ "$schema": "https://lnav.org/schemas/format-v1.schema.json", "pcap_log": { "json": true, - "description": "pcap log format", + "title": "Packet Capture", + "description": "Internal format for pcap files", "mime-types": [ "application/vnd.tcpdump.pcap" ], "multiline": false, "convert-to-local-time": true, "line-format": [ - { "field": "time" }, + { + "field": "time" + }, " ", { "field": "source", @@ -35,7 +38,9 @@ "align": "right" }, " ", - { "field": "info" } + { + "field": "info" + } ], "level": { "warning": "^6291456$", diff --git a/src/fs-extension-functions.cc b/src/fs-extension-functions.cc index 4015f6e4..5f14c903 100644 --- a/src/fs-extension-functions.cc +++ b/src/fs-extension-functions.cc @@ -44,7 +44,6 @@ #include "sqlite3.h" #include "vtab_module.hh" -using namespace std; using namespace mapbox; static util::variant @@ -95,8 +94,8 @@ sql_dirname(const char* path_in) return path_in[0] == '/' ? "/" : "."; } -static nonstd::optional -sql_joinpath(const vector& paths) +static nonstd::optional +sql_joinpath(const std::vector& paths) { std::string full_path; @@ -123,7 +122,7 @@ sql_joinpath(const vector& paths) return full_path; } -static string +static std::string sql_readlink(const char* path) { struct stat st; @@ -145,10 +144,10 @@ sql_readlink(const char* path) "unable to read link: {} -- {}", path, strerror(errno)); } - return string(buf, rc); + return std::string(buf, rc); } -static string +static std::string sql_realpath(const char* path) { char resolved_path[PATH_MAX]; diff --git a/src/fstat_vtab.cc b/src/fstat_vtab.cc index 2dc52fd5..a5de4f41 100644 --- a/src/fstat_vtab.cc +++ b/src/fstat_vtab.cc @@ -41,8 +41,6 @@ #include "sql_util.hh" #include "vtab_module.hh" -using namespace std; - enum { FSTAT_COL_PARENT, FSTAT_COL_NAME, @@ -65,6 +63,9 @@ enum { FSTAT_COL_PATTERN, }; +/** + * @feature f0:sql.tables.fstat + */ struct fstat_table { static constexpr const char* NAME = "fstat"; static constexpr const char* CREATE_STMT = R"( @@ -93,7 +94,7 @@ CREATE TABLE fstat ( struct cursor { sqlite3_vtab_cursor base; - string c_pattern; + std::string c_pattern; static_root_mem c_glob; size_t c_path_index{0}; struct stat c_stat; diff --git a/src/grep_proc.cc b/src/grep_proc.cc index 8d04e6e5..e55f350d 100644 --- a/src/grep_proc.cc +++ b/src/grep_proc.cc @@ -46,8 +46,6 @@ #include "lnav_util.hh" #include "vis_line.hh" -using namespace std; - template grep_proc::grep_proc(pcre* code, grep_proc_source& gps) : gp_pcre(code), gp_source(gps) @@ -66,7 +64,7 @@ grep_proc::~grep_proc() template void grep_proc::handle_match( - int line, string& line_value, int off, int* matches, int count) + int line, std::string& line_value, int off, int* matches, int count) { int lpc; @@ -152,7 +150,7 @@ void grep_proc::child_loop() { char outbuf[BUFSIZ * 2]; - string line_value; + std::string line_value; /* Make sure buffering is on, not sure of the state in the parent. */ if (setvbuf(stdout, outbuf, _IOFBF, BUFSIZ * 2) < 0) { diff --git a/src/grep_proc.hh b/src/grep_proc.hh index 1cb46b1c..ff9a7322 100644 --- a/src/grep_proc.hh +++ b/src/grep_proc.hh @@ -42,7 +42,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "auto_mem.hh" #include "base/lnav_log.hh" #include "line_buffer.hh" diff --git a/src/hotkeys.cc b/src/hotkeys.cc index 22a2d9f5..2f506463 100644 --- a/src/hotkeys.cc +++ b/src/hotkeys.cc @@ -51,8 +51,6 @@ #include "termios_guard.hh" #include "xterm_mouse.hh" -using namespace std; - class logline_helper { public: logline_helper(logfile_sub_source& lss) @@ -101,14 +99,14 @@ public: { const char* start = this->lh_msg_buffer.get_data(); - return string(&start[lr.lr_start], lr.length()); + return std::string(&start[lr.lr_start], lr.length()); } logfile_sub_source& lh_sub_source; vis_line_t lh_current_line; shared_buffer_ref lh_msg_buffer; string_attrs_t lh_string_attrs; - vector lh_line_values; + std::vector lh_line_values; }; static int @@ -133,7 +131,7 @@ key_sql_callback(exec_context& ec, sqlite3_stmt* stmt) } vars[column_name] - = string((const char*) sqlite3_column_text(stmt, lpc)); + = std::string((const char*) sqlite3_column_text(stmt, lpc)); } return 0; @@ -149,12 +147,12 @@ handle_keyseq(const char* keyseq) return false; } - vector values; + std::vector values; exec_context ec(&values, key_sql_callback, pipe_callback); auto& var_stack = ec.ec_local_vars; ec.ec_global_vars = lnav_data.ld_exec_context.ec_global_vars; - var_stack.push(map()); + var_stack.push(std::map()); auto& vars = var_stack.top(); vars["keyseq"] = keyseq; const auto& kc = iter->second; @@ -166,7 +164,7 @@ handle_keyseq(const char* keyseq) if (!kc.kc_alt_msg.empty()) { shlex lexer(kc.kc_alt_msg); - string expanded_msg; + std::string expanded_msg; if (lexer.eval(expanded_msg, { @@ -339,7 +337,7 @@ handle_paging_key(int ch) execute_command( ec, "zoom-to " - + string( + + std::string( lnav_zoom_strings[lnav_data.ld_zoom_level - 1])); } break; @@ -351,7 +349,7 @@ handle_paging_key(int ch) execute_command( ec, "zoom-to " - + string( + + std::string( lnav_zoom_strings[lnav_data.ld_zoom_level + 1])); } break; @@ -424,10 +422,10 @@ handle_paging_key(int ch) == lnav_data.ld_last_user_mark.end()) { alerter::singleton().chime(); } else { - int start_line = min((int) tc->get_top(), - lnav_data.ld_last_user_mark[tc] + 1); - int end_line = max((int) tc->get_top(), - lnav_data.ld_last_user_mark[tc] - 1); + int start_line = std::min((int) tc->get_top(), + lnav_data.ld_last_user_mark[tc] + 1); + int end_line = std::max((int) tc->get_top(), + lnav_data.ld_last_user_mark[tc] - 1); tc->toggle_user_mark(&textview_curses::BM_USER, vis_line_t(start_line), @@ -636,7 +634,8 @@ handle_paging_key(int ch) lnav_data.ld_rl_view->set_value(""); tc->set_top(next_helper.lh_current_line); } else { - string opid_str = start_helper.to_string(opid_range); + const auto opid_str + = start_helper.to_string(opid_range); lnav_data.ld_rl_view->set_value(err_prefix( "No more messages found with opid: " + opid_str)); @@ -814,7 +813,7 @@ handle_paging_key(int ch) lnav_data.ld_rl_view->set_value("Graphing all values"); }, [&](stacked_bar_chart_base::show_one) { - string colname; + std::string colname; chart.get_ident_to_show(colname); lnav_data.ld_rl_view->set_value( diff --git a/src/line_buffer.cc b/src/line_buffer.cc index bb087a0b..35aebe22 100644 --- a/src/line_buffer.cc +++ b/src/line_buffer.cc @@ -52,8 +52,6 @@ #include "fmtlib/fmt/format.h" #include "line_buffer.hh" -using namespace std; - static const ssize_t DEFAULT_INCREMENT = 128 * 1024; static const ssize_t MAX_COMPRESSED_BUFFER_SIZE = 32 * 1024 * 1024; @@ -126,7 +124,7 @@ read_le32(const unsigned char* data) line_buffer::gz_indexed::gz_indexed() { if ((this->inbuf = (Bytef*) malloc(Z_BUFSIZE)) == NULL) { - throw bad_alloc(); + throw std::bad_alloc(); } } @@ -300,7 +298,7 @@ line_buffer::line_buffer() lb_last_line_offset(-1) { if ((this->lb_buffer = (char*) malloc(this->lb_buffer_max)) == nullptr) { - throw bad_alloc(); + throw std::bad_alloc(); } ensure(this->invariant()); @@ -548,7 +546,7 @@ line_buffer::fill_range(file_off_t start, ssize_t max_length) if ((bz_file = BZ2_bzdopen(bzfd, "r")) == NULL) { close(bzfd); if (errno == 0) { - throw bad_alloc(); + throw std::bad_alloc(); } else { throw error(errno); } @@ -647,7 +645,7 @@ line_buffer::fill_range(file_off_t start, ssize_t max_length) return retval; } -Result +Result line_buffer::load_next_line(file_range prev_line) { ssize_t request_size = DEFAULT_INCREMENT; @@ -780,11 +778,11 @@ line_buffer::read_range(const file_range fr) * Don't return anything past the last known line. The caller needs * to try reading at the offset of the last line again. */ - return Err(string("out-of-bounds")); + return Err(std::string("out-of-bounds")); } if (!this->fill_range(fr.fr_offset, fr.fr_size)) { - return Err(string("unable to read file")); + return Err(std::string("unable to read file")); } line_start = this->get_range(fr.fr_offset, avail); diff --git a/src/line_buffer.hh b/src/line_buffer.hh index 89228863..72d17109 100644 --- a/src/line_buffer.hh +++ b/src/line_buffer.hh @@ -40,8 +40,8 @@ #include #include -#include "auto_fd.hh" #include "auto_mem.hh" +#include "base/auto_fd.hh" #include "base/file_range.hh" #include "base/lnav_log.hh" #include "base/result.h" diff --git a/src/listview_curses.cc b/src/listview_curses.cc index 2838f9e0..5d65a7f9 100644 --- a/src/listview_curses.cc +++ b/src/listview_curses.cc @@ -39,8 +39,6 @@ #include "base/lnav_log.hh" #include "config.h" -using namespace std; - list_gutter_source listview_curses::DEFAULT_GUTTER_SOURCE; listview_curses::listview_curses() : lv_scroll(noop_func{}) {} @@ -53,7 +51,8 @@ listview_curses::reload_data() this->lv_left = 0; } else { if (this->lv_top >= this->get_inner_height()) { - this->lv_top = max(0_vl, vis_line_t(this->get_inner_height() - 1)); + this->lv_top + = std::max(0_vl, vis_line_t(this->get_inner_height() - 1)); } if (this->get_inner_height() == 0) { this->lv_selection = 0_vl; @@ -207,8 +206,8 @@ listview_curses::do_update() row_count = this->get_inner_height(); row = this->lv_top; bottom = y + height; - vector rows( - min((size_t) height, row_count - (int) this->lv_top)); + std::vector rows( + std::min((size_t) height, row_count - (int) this->lv_top)); this->lv_source->listview_value_for_rows(*this, row, rows); while (y < bottom) { lr.lr_start = this->lv_left; @@ -268,7 +267,7 @@ listview_curses::do_update() y = this->lv_y + (int) (progress * (double) height); lines = vis_line_t( - y + min((int) height, (int) (coverage * (double) height))); + y + std::min((int) height, (int) (coverage * (double) height))); for (unsigned int gutter_y = this->lv_y; gutter_y < (this->lv_y + height); diff --git a/src/lnav.cc b/src/lnav.cc index 628c39df..298a3913 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -154,11 +154,10 @@ # define SYSCONFDIR "/usr/etc" #endif -using namespace std; using namespace std::literals::chrono_literals; static bool initial_build = false; -static multimap DEFAULT_FILES; +static std::multimap DEFAULT_FILES; static auto intern_lifetime = intern_string::get_table_lifetime(); struct lnav_data_t lnav_data; @@ -377,7 +376,7 @@ setup_logline_table(exec_context& ec) lnav_data.ld_rl_view->add_possibility( LNM_SQL, "*", - string(func_def.zName) + (func_def.nArg ? "(" : "()")); + std::string(func_def.zName) + (func_def.nArg ? "(" : "()")); } for (int lpc2 = 0; agg_funcs && agg_funcs[lpc2].zName; lpc2++) { const FuncDefAgg& func_def = agg_funcs[lpc2]; @@ -385,7 +384,7 @@ setup_logline_table(exec_context& ec) lnav_data.ld_rl_view->add_possibility( LNM_SQL, "*", - string(func_def.zName) + (func_def.nArg ? "(" : "()")); + std::string(func_def.zName) + (func_def.nArg ? "(" : "()")); } } @@ -393,7 +392,7 @@ setup_logline_table(exec_context& ec) switch (pair.second->ht_context) { case help_context_t::HC_SQL_FUNCTION: case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: { - string poss = pair.first + std::string poss = pair.first + (pair.second->ht_parameters.empty() ? "()" : ("(")); lnav_data.ld_rl_view->add_possibility(LNM_SQL, "*", poss); @@ -423,7 +422,7 @@ class loading_observer : public logfile_observer { public: loading_observer() : lo_last_offset(0){}; - indexing_result logfile_indexing(const shared_ptr& lf, + indexing_result logfile_indexing(const std::shared_ptr& lf, file_off_t off, file_size_t total) override { @@ -452,7 +451,7 @@ public: return indexing_result::CONTINUE; }; - static void do_update(const shared_ptr& lf) + static void do_update(const std::shared_ptr& lf) { if (isendwin()) { return; @@ -546,7 +545,7 @@ class textfile_callback { public: textfile_callback() : front_file(nullptr), front_top(-1){}; - void closed_files(const std::vector>& files) + void closed_files(const std::vector>& files) { for (const auto& lf : files) { log_info("closed text files: %s", lf->get_filename().c_str()); @@ -554,7 +553,7 @@ public: lnav_data.ld_active_files.close_files(files); }; - void promote_file(const shared_ptr& lf) + void promote_file(const std::shared_ptr& lf) { if (lnav_data.ld_log_source.insert_file(lf)) { this->did_promotion = true; @@ -584,7 +583,7 @@ public: } }; - void scanned_file(const shared_ptr& lf) + void scanned_file(const std::shared_ptr& lf) { if (!lnav_data.ld_files_to_front.empty() && lnav_data.ld_files_to_front.front().first == lf->get_filename()) @@ -596,7 +595,7 @@ public: } }; - shared_ptr front_file; + std::shared_ptr front_file; int front_top; bool did_promotion{false}; }; @@ -679,7 +678,8 @@ rebuild_indexes(nonstd::optional deadline) log_view.reload_data(); { - unordered_map>> id_to_files; + std::unordered_map>> + id_to_files; bool reload = false; for (const auto& lf : lnav_data.ld_active_files.fc_files) { @@ -751,14 +751,14 @@ append_default_files(lnav_flags_t flag) if (lnav_data.ld_flags & flag) { auto cwd = ghc::filesystem::current_path(); - pair::iterator, - multimap::iterator> + std::pair::iterator, + std::multimap::iterator> range; for (range = DEFAULT_FILES.equal_range(flag); range.first != range.second; range.first++) { - string path = range.first->second; + std::string path = range.first->second; struct stat st; if (access(path.c_str(), R_OK) == 0) { @@ -1551,7 +1551,8 @@ looper() id.id_escape_matcher = match_escape_seq; id.id_escape_handler = handle_keyseq; id.id_key_handler = handle_key; - id.id_mouse_handler = bind(&xterm_mouse::handle_mouse, &mouse_i); + id.id_mouse_handler + = std::bind(&xterm_mouse::handle_mouse, &mouse_i); id.id_unhandled_handler = [](const char* keyseq) { auto enc_len = lnav_config.lc_ui_keymap.size() * 2; auto encoded_name = (char*) alloca(enc_len); @@ -1589,7 +1590,7 @@ looper() log_debug("rescan started %p", &active_copy); active_copy.merge(lnav_data.ld_active_files); active_copy.fc_progress = lnav_data.ld_active_files.fc_progress; - future rescan_future + std::future rescan_future = std::async(std::launch::async, &file_collection::rescan_files, std::move(active_copy), @@ -1607,7 +1608,7 @@ looper() auto loop_deadline = ui_clock::now() + (session_stage == 0 ? 3s : 50ms); - vector pollfds; + std::vector pollfds; size_t starting_view_stack_size = lnav_data.ld_view_stack.size(); size_t changes = 0; int rc; @@ -1932,7 +1933,9 @@ looper() if (initial_build) { static bool ran_cleanup = false; - vector, string>> cmd_results; + std::vector, + std::string>> + cmd_results; execute_init_commands(ec, cmd_results); @@ -2014,8 +2017,9 @@ looper() int rc, child_stat; rc = waitpid(*iter, &child_stat, WNOHANG); - if (rc == -1 || rc == 0) + if (rc == -1 || rc == 0) { continue; + } iter = lnav_data.ld_children.erase(iter); } @@ -2044,7 +2048,7 @@ looper() void wait_for_children() { - vector pollfds; + std::vector pollfds; struct timeval to = {0, 333000}; if (lnav_data.ld_meta_search) { @@ -2103,7 +2107,7 @@ get_textview_for_mode(ln_mode_t mode) } static void -print_errors(vector error_list) +print_errors(std::vector error_list) { for (auto& iter : error_list) { fprintf(stderr, @@ -2120,10 +2124,10 @@ main(int argc, char* argv[]) exec_context& ec = lnav_data.ld_exec_context; int lpc, c, retval = EXIT_SUCCESS; - shared_ptr stdin_reader; - const char* stdin_out = nullptr; - int stdin_out_fd = -1; - bool exec_stdin = false, load_stdin = false; + std::shared_ptr stdin_reader; + ghc::filesystem::path stdin_out; + auto_fd stdin_out_fd; + bool exec_stdin = false, load_stdin = false, stdin_captured = false; const char* LANG = getenv("LANG"); ghc::filesystem::path stdin_tmp_path; @@ -2216,7 +2220,7 @@ main(int argc, char* argv[]) || strcmp("/dev/stdin", optarg) == 0) { exec_stdin = true; } - lnav_data.ld_commands.push_back("|" + string(optarg)); + lnav_data.ld_commands.push_back("|" + std::string(optarg)); break; case 'I': @@ -2359,11 +2363,11 @@ main(int argc, char* argv[]) } auto file_type = file_type_result.unwrap(); - string dst_name; + std::string dst_name; if (file_type == config_file_type::CONFIG) { dst_name = basename(argv[lpc]); } else { - vector format_list + std::vector format_list = load_format_file(argv[lpc], loader_errors); if (!loader_errors.empty()) { @@ -2616,12 +2620,14 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' } if (!(lnav_data.ld_flags & LNF_CHECK_CONFIG)) { - DEFAULT_FILES.insert(make_pair(LNF_SYSLOG, string("var/log/messages"))); DEFAULT_FILES.insert( - make_pair(LNF_SYSLOG, string("var/log/system.log"))); - DEFAULT_FILES.insert(make_pair(LNF_SYSLOG, string("var/log/syslog"))); + make_pair(LNF_SYSLOG, std::string("var/log/messages"))); + DEFAULT_FILES.insert( + make_pair(LNF_SYSLOG, std::string("var/log/system.log"))); DEFAULT_FILES.insert( - make_pair(LNF_SYSLOG, string("var/log/syslog.log"))); + make_pair(LNF_SYSLOG, std::string("var/log/syslog"))); + DEFAULT_FILES.insert( + make_pair(LNF_SYSLOG, std::string("var/log/syslog.log"))); } init_lnav_commands(lnav_commands); @@ -2669,11 +2675,11 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' auto cmd_ref_path = ghc::filesystem::path(internals_dir) / "cmd-ref.rst"; - auto cmd_file = unique_ptr( + auto cmd_file = std::unique_ptr( fopen(cmd_ref_path.c_str(), "w+"), fclose); if (cmd_file.get()) { - set unique_cmds; + std::set unique_cmds; for (auto& cmd : lnav_commands) { if (unique_cmds.find(cmd.second) != unique_cmds.end()) { @@ -2687,9 +2693,9 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' auto sql_ref_path = ghc::filesystem::path(internals_dir) / "sql-ref.rst"; - auto sql_file = unique_ptr( + auto sql_file = std::unique_ptr( fopen(sql_ref_path.c_str(), "w+"), fclose); - set unique_sql_help; + std::set unique_sql_help; if (sql_file.get()) { for (auto& sql : sqlite_function_help) { @@ -2767,32 +2773,31 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' strerror(errno)); retval = EXIT_FAILURE; } else { - auto fifo_piper = make_shared( - fifo_fd.release(), - false, - lnav::filesystem::open_temp_file( - ghc::filesystem::temp_directory_path() - / "lnav.fifo.XXXXXX") - .map([](auto pair) { - ghc::filesystem::remove(pair.first); - - return pair; - }) - .expect("Cannot create temporary file for FIFO") - .second); + auto fifo_tmp_fd + = lnav::filesystem::open_temp_file( + ghc::filesystem::temp_directory_path() + / "lnav.fifo.XXXXXX") + .map([](auto&& pair) { + ghc::filesystem::remove(pair.first); + + return std::move(pair.second); + }) + .expect("Cannot create temporary file for FIFO"); + auto fifo_piper = std::make_shared( + std::move(fifo_fd), false, std::move(fifo_tmp_fd)); auto fifo_out_fd = fifo_piper->get_fd(); auto desc = fmt::format(FMT_STRING("FIFO [{}]"), lnav_data.ld_fifo_counter++); lnav_data.ld_active_files.fc_file_names[desc].with_fd( - fifo_out_fd); + std::move(fifo_out_fd)); lnav_data.ld_pipers.push_back(fifo_piper); } } else if ((abspath = realpath(argv[lpc], nullptr)) == nullptr) { perror("Cannot find file"); retval = EXIT_FAILURE; } else if (S_ISDIR(st.st_mode)) { - string dir_wild(abspath.in()); + std::string dir_wild(abspath.in()); if (dir_wild[dir_wild.size() - 1] == '/') { dir_wild.resize(dir_wild.size() - 1); @@ -2837,8 +2842,8 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' shared_buffer_ref sbr = read_result.unwrap(); if (fmt->scan_for_partial(sbr, partial_len)) { long line_number = distance(lf->begin(), line_iter); - string full_line(sbr.get_data(), sbr.length()); - string partial_line(sbr.get_data(), partial_len); + std::string full_line(sbr.get_data(), sbr.length()); + std::string partial_line(sbr.get_data(), partial_len); fprintf(stderr, "error:%s:%ld:line did not match format %s\n", @@ -2879,7 +2884,7 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' if (load_stdin && !isatty(STDIN_FILENO) && !is_dev_null(STDIN_FILENO) && !exec_stdin) { - if (stdin_out == nullptr) { + if (stdin_out.empty()) { auto pattern = lnav::paths::dotlnav() / "stdin-captures/stdin.XXXXXX"; @@ -2893,20 +2898,25 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' auto temp_pair = open_result.unwrap(); stdin_tmp_path = temp_pair.first; - stdin_out_fd = temp_pair.second; + stdin_out_fd = std::move(temp_pair.second); } else { - if ((stdin_out_fd - = open(stdin_out, O_RDWR | O_CREAT | O_TRUNC, 0600)) - == -1) { - perror("Unable to open output file for stdin"); + auto open_res = lnav::filesystem::open_file( + stdin_out, O_RDWR | O_CREAT | O_TRUNC, 0600); + if (open_res.isErr()) { + fmt::print(stderr, "error: {}\n", open_res.unwrapErr()); return EXIT_FAILURE; } + + stdin_out_fd = open_res.unwrap(); } - stdin_reader = make_shared( - STDIN_FILENO, lnav_data.ld_flags & LNF_TIMESTAMP, stdin_out_fd); + stdin_captured = true; + stdin_reader + = std::make_shared(auto_fd(STDIN_FILENO), + lnav_data.ld_flags & LNF_TIMESTAMP, + std::move(stdin_out_fd)); lnav_data.ld_active_files.fc_file_names["stdin"] - .with_fd(auto_fd(stdin_out_fd)) + .with_fd(stdin_reader->get_fd()) .with_include_in_session(false); lnav_data.ld_pipers.push_back(stdin_reader); } @@ -2967,7 +2977,9 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' } if (lnav_data.ld_flags & LNF_HEADLESS) { - std::vector, string>> cmd_results; + std::vector< + std::pair, std::string>> + cmd_results; textview_curses *log_tc, *text_tc, *tc; bool output_view = true; @@ -3070,7 +3082,7 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' for (vl = tc->get_top(); vl < tc->get_inner_height(); ++vl, ++y) { attr_line_t al; - string& line = al.get_string(); + auto& line = al.get_string(); while (los != nullptr && los->list_value_for_overlay( *tc, y, tc->get_inner_height(), vl, al)) @@ -3085,7 +3097,7 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' ++y; } - vector rows(1); + std::vector rows(1); tc->listview_value_for_rows(*tc, vl, rows); if (suppress_empty_lines && rows[0].empty()) { continue; @@ -3104,7 +3116,7 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' } { attr_line_t al; - string& line = al.get_string(); + auto& line = al.get_string(); while (los != nullptr && los->list_value_for_overlay( @@ -3142,7 +3154,7 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%' // When reading from stdin, tell the user where the capture file is // stored so they can look at it later. - if (stdin_out_fd != -1 && stdin_out == nullptr + if (stdin_captured && stdin_out.empty() && !(lnav_data.ld_flags & LNF_QUIET) && !(lnav_data.ld_flags & LNF_HEADLESS)) { diff --git a/src/lnav_commands.cc b/src/lnav_commands.cc index c87f5577..da222e65 100644 --- a/src/lnav_commands.cc +++ b/src/lnav_commands.cc @@ -78,11 +78,9 @@ #include "yajlpp/json_op.hh" #include "yajlpp/yajlpp.hh" -using namespace std; - -static string -remaining_args(const string& cmdline, - const vector& args, +static std::string +remaining_args(const std::string& cmdline, + const std::vector& args, size_t index = 1) { size_t start_pos = 0; @@ -98,13 +96,13 @@ remaining_args(const string& cmdline, size_t index_in_cmdline = cmdline.find(args[index], start_pos); - require(index_in_cmdline != string::npos); + require(index_in_cmdline != std::string::npos); return cmdline.substr(index_in_cmdline); } -static nonstd::optional -find_arg(vector& args, const string& flag) +static nonstd::optional +find_arg(std::vector& args, const std::string& flag) { auto iter = find_if(args.begin(), args.end(), [&flag](const auto elem) { return startswith(elem, flag); @@ -115,7 +113,7 @@ find_arg(vector& args, const string& flag) } auto index = iter->find('='); - if (index == string::npos) { + if (index == std::string::npos) { return ""; } @@ -142,10 +140,10 @@ combined_user_marks(vis_bookmarks& vb) return retval; } -static string +static std::string refresh_pt_search() { - string retval; + std::string retval; if (!lnav_data.ld_cmd_init_done) { return ""; @@ -183,10 +181,12 @@ refresh_pt_search() return retval; } -static Result -com_adjust_log_time(exec_context& ec, string cmdline, vector& args) +static Result +com_adjust_log_time(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("line-time"); @@ -251,10 +251,12 @@ com_adjust_log_time(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_unix_time(exec_context& ec, string cmdline, vector& args) +static Result +com_unix_time(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (args.size() >= 2) { @@ -270,8 +272,8 @@ com_unix_time(exec_context& ec, string cmdline, vector& args) log_time.tm_isdst = -1; args[1] = remaining_args(cmdline, args); - if ((millis = args[1].find('.')) != string::npos - || (millis = args[1].find(',')) != string::npos) + if ((millis = args[1].find('.')) != std::string::npos + || (millis = args[1].find(',')) != std::string::npos) { args[1] = args[1].erase(millis, 4); } @@ -300,7 +302,7 @@ com_unix_time(exec_context& ec, string cmdline, vector& args) localtime(&u_time)); len = strlen(ftime); snprintf(ftime + len, sizeof(ftime) - len, " -- %ld", u_time); - retval = string(ftime); + retval = std::string(ftime); } else { return ec.make_error("invalid unix time -- {}", args[1]); } @@ -311,12 +313,14 @@ com_unix_time(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_current_time(exec_context& ec, string cmdline, vector& args) +static Result +com_current_time(exec_context& ec, + std::string cmdline, + std::vector& args) { char ftime[128]; struct tm localtm; - string retval; + std::string retval; time_t u_time; size_t len; @@ -328,20 +332,20 @@ com_current_time(exec_context& ec, string cmdline, vector& args) localtime_r(&u_time, &localtm)); len = strlen(ftime); snprintf(ftime + len, sizeof(ftime) - len, " -- %ld", u_time); - retval = string(ftime); + retval = std::string(ftime); return Ok(retval); } -static Result -com_goto(exec_context& ec, string cmdline, vector& args) +static Result +com_goto(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("move-time"); } else if (args.size() > 1) { - string all_args = remaining_args(cmdline, args); + std::string all_args = remaining_args(cmdline, args); textview_curses* tc = *lnav_data.ld_view_stack.top(); auto ttt = dynamic_cast(tc->get_sub_source()); int line_number, consumed; @@ -426,7 +430,8 @@ com_goto(exec_context& ec, string cmdline, vector& args) dst_vl | [&ec, tc, &retval](auto new_top) { if (ec.ec_dry_run) { - retval = "info: will move to line " + to_string((int) new_top); + retval = "info: will move to line " + + std::to_string((int) new_top); } else { tc->get_sub_source()->get_location_history() | [new_top](auto lh) { lh->loc_history_append(new_top); }; @@ -440,10 +445,12 @@ com_goto(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_relative_goto(exec_context& ec, string cmdline, vector& args) +static Result +com_relative_goto(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval = "error: "; + std::string retval = "error: "; if (args.empty()) { } else if (args.size() > 1) { @@ -460,7 +467,7 @@ com_relative_goto(exec_context& ec, string cmdline, vector& args) } if (ec.ec_dry_run) { - retval = "info: shifting top by " + to_string(line_offset) + retval = "info: shifting top by " + std::to_string(line_offset) + " lines"; } else { tc->shift_top(vis_line_t(line_offset), true); @@ -477,10 +484,10 @@ com_relative_goto(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_mark(exec_context& ec, string cmdline, vector& args) +static Result +com_mark(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty() || lnav_data.ld_view_stack.empty()) { } else if (!ec.ec_dry_run) { @@ -494,10 +501,12 @@ com_mark(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_mark_expr(exec_context& ec, string cmdline, vector& args) +static Result +com_mark_expr(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty() || lnav_data.ld_view_stack.empty()) { args.emplace_back("filter-expr-syms"); @@ -553,8 +562,8 @@ com_mark_expr(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static string -com_mark_expr_prompt(exec_context& ec, const string& cmdline) +static std::string +com_mark_expr_prompt(exec_context& ec, const std::string& cmdline) { textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -567,10 +576,12 @@ com_mark_expr_prompt(exec_context& ec, const string& cmdline) trim(lnav_data.ld_log_source.get_sql_marker_text())); } -static Result -com_clear_mark_expr(exec_context& ec, string cmdline, vector& args) +static Result +com_clear_mark_expr(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else { @@ -582,10 +593,12 @@ com_clear_mark_expr(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_goto_mark(exec_context& ec, string cmdline, vector& args) +static Result +com_goto_mark(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("mark-type"); @@ -660,10 +673,12 @@ com_goto_mark(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_goto_location(exec_context& ec, string cmdline, vector& args) +static Result +com_goto_location(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -682,17 +697,17 @@ com_goto_location(exec_context& ec, string cmdline, vector& args) } static bool -csv_needs_quoting(const string& str) +csv_needs_quoting(const std::string& str) { - return (str.find_first_of(",\"\r\n") != string::npos); + return (str.find_first_of(",\"\r\n") != std::string::npos); } -static string -csv_quote_string(const string& str) +static std::string +csv_quote_string(const std::string& str) { static const std::regex csv_column_quoter("\""); - string retval = std::regex_replace(str, csv_column_quoter, "\"\""); + std::string retval = std::regex_replace(str, csv_column_quoter, "\"\""); retval.insert(0, 1, '\"'); retval.append(1, '\"'); @@ -701,10 +716,10 @@ csv_quote_string(const string& str) } static void -csv_write_string(FILE* outfile, const string& str) +csv_write_string(FILE* outfile, const std::string& str) { if (csv_needs_quoting(str)) { - string quoted_str = csv_quote_string(str); + std::string quoted_str = csv_quote_string(str); fmt::fprintf(outfile, "%s", quoted_str); } else { @@ -841,18 +856,20 @@ write_line_to(FILE* outfile, const attr_line_t& al) } } -static Result -com_save_to(exec_context& ec, string cmdline, vector& args) +static Result +com_save_to(exec_context& ec, + std::string cmdline, + std::vector& args) { FILE *outfile = nullptr, *toclose = nullptr; const char* mode = ""; - string fn, retval; + std::string fn, retval; bool to_term = false; int (*closer)(FILE*) = fclose; if (args.empty()) { args.emplace_back("filename"); - return Ok(string()); + return Ok(std::string()); } if (lnav_data.ld_flags & LNF_SECURE_MODE) { @@ -861,7 +878,7 @@ com_save_to(exec_context& ec, string cmdline, vector& args) fn = trim(remaining_args(cmdline, args)); - vector split_args; + std::vector split_args; shlex lexer(fn); if (!lexer.split(split_args, ec.create_resolver())) { @@ -1114,7 +1131,7 @@ com_save_to(exec_context& ec, string cmdline, vector& args) vis_line_t top = tc->get_top(); vis_line_t bottom = tc->get_bottom(); - vector rows(bottom - top + 1); + std::vector rows(bottom - top + 1); tc->listview_value_for_rows(*tc, top, rows); for (auto& al : rows) { @@ -1151,9 +1168,9 @@ com_save_to(exec_context& ec, string cmdline, vector& args) nonstd::optional> last_line; bookmark_vector visited; auto& lss = lnav_data.ld_log_source; - vector rows(1); + std::vector rows(1); size_t count = 0; - string line; + std::string line; for (auto iter = all_user_marks.begin(); iter != all_user_marks.end(); @@ -1200,7 +1217,7 @@ com_save_to(exec_context& ec, string cmdline, vector& args) break; } - string line; + std::string line; tss->text_value_for_line(*tc, lpc, line, text_sub_source::RF_RAW); fprintf(outfile, "%s\n", line.c_str()); @@ -1210,9 +1227,9 @@ com_save_to(exec_context& ec, string cmdline, vector& args) tc->set_word_wrap(wrapped); } else { - vector rows(1); + std::vector rows(1); size_t count = 0; - string line; + std::string line; for (auto iter = all_user_marks.begin(); iter != all_user_marks.end(); iter++, count++) @@ -1241,7 +1258,7 @@ com_save_to(exec_context& ec, string cmdline, vector& args) char buffer[32 * 1024]; size_t rc = fread(buffer, 1, sizeof(buffer), outfile); - attr_line_t al(string(buffer, rc)); + attr_line_t al(std::string(buffer, rc)); lnav_data.ld_preview_source.replace_with(al) .set_text_format(detect_text_format(al.get_string())) @@ -1249,7 +1266,7 @@ com_save_to(exec_context& ec, string cmdline, vector& args) lnav_data.ld_preview_status_source.get_description().set_value( "First lines of file: %s", split_args[0].c_str()); } else { - retval = "info: Wrote " + to_string(line_count) + " rows to " + retval = "info: Wrote " + std::to_string(line_count) + " rows to " + split_args[0]; } if (toclose != nullptr) { @@ -1260,14 +1277,16 @@ com_save_to(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_pipe_to(exec_context& ec, string cmdline, vector& args) +static Result +com_pipe_to(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("filename"); - return Ok(string()); + return Ok(std::string()); } if (lnav_data.ld_flags & LNF_SECURE_MODE) { @@ -1279,14 +1298,14 @@ com_pipe_to(exec_context& ec, string cmdline, vector& args) } if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } auto* tc = *lnav_data.ld_view_stack.top(); auto bv = combined_user_marks(tc->get_bookmarks()); bool pipe_line_to = (args[0] == "pipe-line-to"); - string cmd = trim(remaining_args(cmdline, args)); + std::string cmd = trim(remaining_args(cmdline, args)); auto_pipe in_pipe(STDIN_FILENO); auto_pipe out_pipe(STDOUT_FILENO); @@ -1311,7 +1330,7 @@ com_pipe_to(exec_context& ec, string cmdline, vector& args) nullptr, }; auto path_v = ec.ec_path_stack; - string path; + std::string path; dup2(STDOUT_FILENO, STDERR_FILENO); path_v.emplace_back(lnav::paths::dotlnav() / "formats/default"); @@ -1323,7 +1342,7 @@ com_pipe_to(exec_context& ec, string cmdline, vector& args) ldh.parse_line(ec.ec_top_line, true); auto format = ldh.ldh_file->get_format(); - set source_path = format->get_source_path(); + auto source_path = format->get_source_path(); path_v.insert( path_v.end(), source_path.begin(), source_path.end()); @@ -1344,7 +1363,7 @@ com_pipe_to(exec_context& ec, string cmdline, vector& args) std::string colname = ldh.ldh_parser->get_element_string( iter->e_sub_elements->front()); colname = ldh.ldh_namer->add_column(colname); - string val = ldh.ldh_parser->get_element_string( + std::string val = ldh.ldh_parser->get_element_string( iter->e_sub_elements->back()); setenv(colname.c_str(), val.c_str(), 1); } @@ -1358,14 +1377,14 @@ com_pipe_to(exec_context& ec, string cmdline, vector& args) default: bookmark_vector::iterator iter; - string line; + std::string line; in_pipe.read_end().close_on_exec(); in_pipe.write_end().close_on_exec(); lnav_data.ld_children.push_back(child_pid); - future reader; + std::future reader; if (out_pipe.read_end() != -1) { reader = ec.ec_pipe_callback(ec, cmdline, out_pipe.read_end()); @@ -1421,25 +1440,27 @@ com_pipe_to(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_redirect_to(exec_context& ec, string cmdline, vector& args) +static Result +com_redirect_to(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { args.emplace_back("filename"); - return Ok(string()); + return Ok(std::string()); } if (args.size() == 1) { if (ec.ec_dry_run) { - return Ok(string("info: redirect will be cleared")); + return Ok(std::string("info: redirect will be cleared")); } ec.clear_output(); - return Ok(string("info: cleared redirect")); + return Ok(std::string("info: cleared redirect")); } - string fn = trim(remaining_args(cmdline, args)); - vector split_args; + std::string fn = trim(remaining_args(cmdline, args)); + std::vector split_args; shlex lexer(fn); scoped_resolver scopes = { &ec.ec_local_vars.top(), @@ -1483,10 +1504,12 @@ com_redirect_to(exec_context& ec, string cmdline, vector& args) return Ok("info: redirecting output to file -- " + split_args[0]); } -static Result -com_highlight(exec_context& ec, string cmdline, vector& args) +static Result +com_highlight(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("filter"); @@ -1544,10 +1567,12 @@ com_highlight(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_clear_highlight(exec_context& ec, string cmdline, vector& args) +static Result +com_clear_highlight(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("highlight"); @@ -1578,10 +1603,10 @@ com_clear_highlight(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_help(exec_context& ec, string cmdline, vector& args) +static Result +com_help(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -1591,19 +1616,20 @@ com_help(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result com_enable_filter(exec_context& ec, - string cmdline, - vector& args); +static Result com_enable_filter( + exec_context& ec, std::string cmdline, std::vector& args); -static Result -com_filter(exec_context& ec, string cmdline, vector& args) +static Result +com_filter(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("filter"); - return Ok(string()); + return Ok(std::string()); } auto tc = *lnav_data.ld_view_stack.top(); @@ -1670,7 +1696,7 @@ com_filter(exec_context& ec, string cmdline, vector& args) if (!filter_index) { return ec.make_error("too many filters"); } - auto pf = make_shared( + auto pf = std::make_shared( lt, args[1], *filter_index, code.release()); log_debug("%s [%d] %s", @@ -1690,10 +1716,12 @@ com_filter(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_delete_filter(exec_context& ec, string cmdline, vector& args) +static Result +com_delete_filter(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("all-filters"); @@ -1718,10 +1746,12 @@ com_delete_filter(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_enable_filter(exec_context& ec, string cmdline, vector& args) +static Result +com_enable_filter(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("disabled-filter"); @@ -1729,11 +1759,11 @@ com_enable_filter(exec_context& ec, string cmdline, vector& args) textview_curses* tc = *lnav_data.ld_view_stack.top(); text_sub_source* tss = tc->get_sub_source(); filter_stack& fs = tss->get_filters(); - shared_ptr lf; + std::shared_ptr lf; args[1] = remaining_args(cmdline, args); lf = fs.get_filter(args[1]); - if (lf == NULL) { + if (lf == nullptr) { return ec.make_error("no such filter -- {}", args[1]); } else if (lf->is_enabled()) { retval = "info: filter already enabled"; @@ -1751,10 +1781,12 @@ com_enable_filter(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_disable_filter(exec_context& ec, string cmdline, vector& args) +static Result +com_disable_filter(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("enabled-filter"); @@ -1762,7 +1794,7 @@ com_disable_filter(exec_context& ec, string cmdline, vector& args) textview_curses* tc = *lnav_data.ld_view_stack.top(); text_sub_source* tss = tc->get_sub_source(); filter_stack& fs = tss->get_filters(); - shared_ptr lf; + std::shared_ptr lf; args[1] = remaining_args(cmdline, args); lf = fs.get_filter(args[1]); @@ -1784,10 +1816,12 @@ com_disable_filter(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_filter_expr(exec_context& ec, string cmdline, vector& args) +static Result +com_filter_expr(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("filter-expr-syms"); @@ -1852,8 +1886,8 @@ com_filter_expr(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static string -com_filter_expr_prompt(exec_context& ec, const string& cmdline) +static std::string +com_filter_expr_prompt(exec_context& ec, const std::string& cmdline) { textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -1866,10 +1900,12 @@ com_filter_expr_prompt(exec_context& ec, const string& cmdline) trim(lnav_data.ld_log_source.get_sql_filter_text())); } -static Result -com_clear_filter_expr(exec_context& ec, string cmdline, vector& args) +static Result +com_clear_filter_expr(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else { @@ -1882,10 +1918,12 @@ com_clear_filter_expr(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_enable_word_wrap(exec_context& ec, string cmdline, vector& args) +static Result +com_enable_word_wrap(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -1897,10 +1935,12 @@ com_enable_word_wrap(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_disable_word_wrap(exec_context& ec, string cmdline, vector& args) +static Result +com_disable_word_wrap(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -1912,12 +1952,14 @@ com_disable_word_wrap(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static std::set custom_logline_tables; +static std::set custom_logline_tables; -static Result -com_create_logline_table(exec_context& ec, string cmdline, vector& args) +static Result +com_create_logline_table(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (args.size() == 2) { @@ -1942,9 +1984,9 @@ com_create_logline_table(exec_context& ec, string cmdline, vector& args) lnav_data.ld_preview_source.replace_with(al).set_text_format( text_format_t::TF_SQL); - return Ok(string()); + return Ok(std::string()); } else { - string errmsg; + std::string errmsg; errmsg = lnav_data.ld_vtab_manager->register_vtab(ldt); if (errmsg.empty()) { @@ -1967,10 +2009,12 @@ com_create_logline_table(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_delete_logline_table(exec_context& ec, string cmdline, vector& args) +static Result +com_delete_logline_table(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("custom-table"); @@ -1981,10 +2025,10 @@ com_delete_logline_table(exec_context& ec, string cmdline, vector& args) } if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } - string rc = lnav_data.ld_vtab_manager->unregister_vtab( + std::string rc = lnav_data.ld_vtab_manager->unregister_vtab( intern_string::lookup(args[1])); if (rc.empty()) { @@ -2003,16 +2047,18 @@ com_delete_logline_table(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static std::set custom_search_tables; +static std::set custom_search_tables; -static Result -com_create_search_table(exec_context& ec, string cmdline, vector& args) +static Result +com_create_search_table(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (args.size() >= 2) { - string regex; + std::string regex; if (args.size() >= 3) { regex = remaining_args(cmdline, args, 2); @@ -2049,10 +2095,10 @@ com_create_search_table(exec_context& ec, string cmdline, vector& args) lnav_data.ld_preview_source.replace_with(al).set_text_format( text_format_t::TF_SQL); - return Ok(string()); + return Ok(std::string()); } - string errmsg; + std::string errmsg; errmsg = lnav_data.ld_vtab_manager->register_vtab(lst); if (errmsg.empty()) { @@ -2072,10 +2118,12 @@ com_create_search_table(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_delete_search_table(exec_context& ec, string cmdline, vector& args) +static Result +com_delete_search_table(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("search-table"); @@ -2085,10 +2133,10 @@ com_delete_search_table(exec_context& ec, string cmdline, vector& args) } if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } - string rc = lnav_data.ld_vtab_manager->unregister_vtab( + std::string rc = lnav_data.ld_vtab_manager->unregister_vtab( intern_string::lookup(args[1])); if (rc.empty()) { @@ -2107,10 +2155,12 @@ com_delete_search_table(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_session(exec_context& ec, string cmdline, vector& args) +static Result +com_session(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (ec.ec_dry_run) { @@ -2132,14 +2182,14 @@ com_session(exec_context& ec, string cmdline, vector& args) auto old_file_name = lnav::paths::dotlnav() / "session"; auto new_file_name = lnav::paths::dotlnav() / "session.tmp"; - ifstream session_file(old_file_name.string()); - ofstream new_session_file(new_file_name.string()); + std::ifstream session_file(old_file_name.string()); + std::ofstream new_session_file(new_file_name.string()); if (!new_session_file) { return ec.make_error("cannot write to session file"); } else { bool added = false; - string line; + std::string line; if (session_file.is_open()) { while (getline(session_file, line)) { @@ -2147,11 +2197,11 @@ com_session(exec_context& ec, string cmdline, vector& args) added = true; break; } - new_session_file << line << endl; + new_session_file << line << std::endl; } } if (!added) { - new_session_file << saved_cmd << endl; + new_session_file << saved_cmd << std::endl; log_perror( rename(new_file_name.c_str(), old_file_name.c_str())); @@ -2169,27 +2219,27 @@ com_session(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_open(exec_context& ec, string cmdline, vector& args) +static Result +com_open(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("filename"); - return Ok(string()); + return Ok(std::string()); } else if (lnav_data.ld_flags & LNF_SECURE_MODE) { return ec.make_error("{} -- unavailable in secure mode", args[0]); } else if (args.size() < 2) { return ec.make_error("expecting file name to open"); } - vector word_exp; + std::vector word_exp; size_t colon_index; - string pat; + std::string pat; pat = trim(remaining_args(cmdline, args)); - vector split_args; + std::vector split_args; shlex lexer(pat); scoped_resolver scopes = { &ec.ec_local_vars.top(), @@ -2200,12 +2250,12 @@ com_open(exec_context& ec, string cmdline, vector& args) return ec.make_error("unable to parse arguments"); } - map file_names; - vector> files_to_front; - vector closed_files; + std::map file_names; + std::vector> files_to_front; + std::vector closed_files; for (size_t lpc = 0; lpc < split_args.size(); lpc++) { - string fn = split_args[lpc]; + std::string fn = split_args[lpc]; int top = 0; if (startswith(fn, "pt:")) { @@ -2218,7 +2268,7 @@ com_open(exec_context& ec, string cmdline, vector& args) } if (access(fn.c_str(), R_OK) != 0 - && (colon_index = fn.rfind(':')) != string::npos) + && (colon_index = fn.rfind(':')) != std::string::npos) { if (sscanf(&fn.c_str()[colon_index + 1], "%d", &top) == 1) { fn = fn.substr(0, colon_index); @@ -2250,7 +2300,7 @@ com_open(exec_context& ec, string cmdline, vector& args) retval = "error: lnav was not compiled with libcurl"; #else if (!ec.ec_dry_run) { - auto ul = make_shared(fn); + auto ul = std::make_shared(fn); lnav_data.ld_active_files.fc_file_names[fn].with_fd( ul->copy_fd()); @@ -2266,7 +2316,7 @@ com_open(exec_context& ec, string cmdline, vector& args) file_names.emplace(fn, logfile_open_options()); retval = "info: watching -- " + fn; } else if (stat(fn.c_str(), &st) == -1) { - if (fn.find(':') != string::npos) { + if (fn.find(':') != std::string::npos) { file_names.emplace(fn, logfile_open_options()); retval = "info: watching -- " + fn; } else { @@ -2284,8 +2334,8 @@ com_open(exec_context& ec, string cmdline, vector& args) } else if (ec.ec_dry_run) { retval = ""; } else { - auto fifo_piper = make_shared( - fifo_fd.release(), + auto fifo_piper = std::make_shared( + std::move(fifo_fd), false, lnav::filesystem::open_temp_file( ghc::filesystem::temp_directory_path() @@ -2298,20 +2348,16 @@ com_open(exec_context& ec, string cmdline, vector& args) .expect("Cannot create temporary file for FIFO") .second); auto fifo_out_fd = fifo_piper->get_fd(); - char desc[128]; - - snprintf(desc, - sizeof(desc), - "FIFO [%d]", - lnav_data.ld_fifo_counter++); + auto desc = fmt::format(FMT_STRING("FIFO [{}]"), + lnav_data.ld_fifo_counter++); lnav_data.ld_active_files.fc_file_names[desc].with_fd( - fifo_out_fd); + std::move(fifo_out_fd)); lnav_data.ld_pipers.push_back(fifo_piper); } } else if ((abspath = realpath(fn.c_str(), nullptr)) == nullptr) { return ec.make_error("cannot find file -- {}", fn); } else if (S_ISDIR(st.st_mode)) { - string dir_wild(abspath.in()); + std::string dir_wild(abspath.in()); if (dir_wild[dir_wild.size() - 1] == '/') { dir_wild.resize(dir_wild.size() - 1); @@ -2343,10 +2389,10 @@ com_open(exec_context& ec, string cmdline, vector& args) lnav_data.ld_preview_source.clear(); if (!file_names.empty()) { auto iter = file_names.begin(); - string fn = iter->first; + std::string fn = iter->first; auto_fd preview_fd; - if (fn.find(':') != string::npos) { + if (fn.find(':') != std::string::npos) { auto id = lnav_data.ld_preview_generation; lnav_data.ld_preview_status_source.get_description() .set_cylon(true) @@ -2373,7 +2419,7 @@ com_open(exec_context& ec, string cmdline, vector& args) } if (gl->gl_pathc > 10) { al.append(" ... ") - .append(to_string(gl->gl_pathc - 10), + .append(std::to_string(gl->gl_pathc - 10), &view_curses::VC_STYLE, A_BOLD) .append(" files not shown ..."); @@ -2386,12 +2432,12 @@ com_open(exec_context& ec, string cmdline, vector& args) } } else if ((preview_fd = open(fn.c_str(), O_RDONLY)) == -1) { return ec.make_error( - "unable to open file: {} -- {}", fn, strerror(errno)); + "unable to open file3: {} -- {}", fn, strerror(errno)); } else { line_buffer lb; attr_line_t al; file_range range; - string lines; + std::string lines; lb.set_fd(preview_fd); for (int lpc = 0; lpc < 10; lpc++) { @@ -2423,8 +2469,9 @@ com_open(exec_context& ec, string cmdline, vector& args) lnav_data.ld_files_to_front.insert(lnav_data.ld_files_to_front.end(), files_to_front.begin(), files_to_front.end()); - lnav_data.ld_active_files.fc_file_names.insert(file_names.begin(), - file_names.end()); + lnav_data.ld_active_files.fc_file_names.insert( + std::make_move_iterator(file_names.begin()), + std::make_move_iterator(file_names.end())); for (const auto& fn : closed_files) { lnav_data.ld_active_files.fc_closed_files.erase(fn); } @@ -2433,16 +2480,16 @@ com_open(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_close(exec_context& ec, string cmdline, vector& args) +static Result +com_close(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else { textview_curses* tc = *lnav_data.ld_view_stack.top(); nonstd::optional actual_path; - string fn; + std::string fn; if (tc == &lnav_data.ld_views[LNV_TEXT]) { textfile_sub_source& tss = lnav_data.ld_text_source; @@ -2497,12 +2544,14 @@ com_close(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_file_visibility(exec_context& ec, string cmdline, vector& args) +static Result +com_file_visibility(exec_context& ec, + std::string cmdline, + std::vector& args) { bool only_this_file = false; bool make_visible; - string retval; + std::string retval; if (args[0] == "show-file") { make_visible = true; @@ -2515,7 +2564,7 @@ com_file_visibility(exec_context& ec, string cmdline, vector& args) if (args.size() == 1 || only_this_file) { textview_curses* tc = *lnav_data.ld_view_stack.top(); - shared_ptr lf; + std::shared_ptr lf; if (tc == &lnav_data.ld_views[LNV_TEXT]) { textfile_sub_source& tss = lnav_data.ld_text_source; @@ -2611,10 +2660,12 @@ com_file_visibility(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_hide_file(exec_context& ec, string cmdline, vector& args) +static Result +com_hide_file(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("visible-files"); @@ -2625,10 +2676,12 @@ com_hide_file(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_show_file(exec_context& ec, string cmdline, vector& args) +static Result +com_show_file(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("hidden-files"); @@ -2639,10 +2692,12 @@ com_show_file(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_show_only_this_file(exec_context& ec, string cmdline, vector& args) +static Result +com_show_only_this_file(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else { @@ -2652,16 +2707,18 @@ com_show_only_this_file(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_comment(exec_context& ec, string cmdline, vector& args) +static Result +com_comment(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { - return Ok(string()); + return Ok(std::string()); } else if (args.size() > 1) { if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -2692,8 +2749,8 @@ com_comment(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static string -com_comment_prompt(exec_context& ec, const string& cmdline) +static std::string +com_comment_prompt(exec_context& ec, const std::string& cmdline) { textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -2713,15 +2770,17 @@ com_comment_prompt(exec_context& ec, const string& cmdline) return ""; } -static Result -com_clear_comment(exec_context& ec, string cmdline, vector& args) +static Result +com_clear_comment(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { - return Ok(string()); + return Ok(std::string()); } else if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } else { textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -2756,17 +2815,17 @@ com_clear_comment(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_tag(exec_context& ec, string cmdline, vector& args) +static Result +com_tag(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("tag"); - return Ok(string()); + return Ok(std::string()); } else if (args.size() > 1) { if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -2780,7 +2839,7 @@ com_tag(exec_context& ec, string cmdline, vector& args) tc->set_user_mark(&textview_curses::BM_META, tc->get_top(), true); bookmark_metadata& line_meta = bm[lss.at(tc->get_top())]; for (size_t lpc = 1; lpc < args.size(); lpc++) { - string tag = args[lpc]; + std::string tag = args[lpc]; if (!startswith(tag, "#")) { tag = "#" + tag; @@ -2801,17 +2860,17 @@ com_tag(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_untag(exec_context& ec, string cmdline, vector& args) +static Result +com_untag(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("line-tags"); - return Ok(string()); + return Ok(std::string()); } else if (args.size() > 1) { if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -2828,7 +2887,7 @@ com_untag(exec_context& ec, string cmdline, vector& args) bookmark_metadata& line_meta = iter->second; for (size_t lpc = 1; lpc < args.size(); lpc++) { - string tag = args[lpc]; + std::string tag = args[lpc]; if (!startswith(tag, "#")) { tag = "#" + tag; @@ -2853,17 +2912,19 @@ com_untag(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_delete_tags(exec_context& ec, string cmdline, vector& args) +static Result +com_delete_tags(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("tag"); - return Ok(string()); + return Ok(std::string()); } else if (args.size() > 1) { if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -2872,11 +2933,11 @@ com_delete_tags(exec_context& ec, string cmdline, vector& args) "The :delete-tag command only works in the log view"); } - set& known_tags = bookmark_metadata::KNOWN_TAGS; - vector tags; + std::set& known_tags = bookmark_metadata::KNOWN_TAGS; + std::vector tags; for (size_t lpc = 1; lpc < args.size(); lpc++) { - string tag = args[lpc]; + std::string tag = args[lpc]; if (!startswith(tag, "#")) { tag = "#" + tag; @@ -2926,13 +2987,15 @@ com_delete_tags(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_partition_name(exec_context& ec, string cmdline, vector& args) +static Result +com_partition_name(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { - return Ok(string()); + return Ok(std::string()); } else if (args.size() > 1) { if (ec.ec_dry_run) { retval = ""; @@ -2958,13 +3021,15 @@ com_partition_name(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_clear_partition(exec_context& ec, string cmdline, vector& args) +static Result +com_clear_partition(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { - return Ok(string()); + return Ok(std::string()); } else if (args.size() == 1) { textview_curses& tc = lnav_data.ld_views[LNV_LOG]; logfile_sub_source& lss = lnav_data.ld_log_source; @@ -2997,10 +3062,12 @@ com_clear_partition(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_pt_time(exec_context& ec, string cmdline, vector& args) +static Result +com_pt_time(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("move-time"); @@ -3015,7 +3082,8 @@ com_pt_time(exec_context& ec, string cmdline, vector& args) "this command to set it"; } else { ctime_r(&lnav_data.ld_pt_min_time, ftime); - retval = "info: papertrail minimum time is " + string(ftime); + retval + = "info: papertrail minimum time is " + std::string(ftime); } } if (args[0] == "pt-max-time") { @@ -3025,11 +3093,12 @@ com_pt_time(exec_context& ec, string cmdline, vector& args) "this command to set it"; } else { ctime_r(&lnav_data.ld_pt_max_time, ftime); - retval = "info: papertrail maximum time is " + string(ftime); + retval + = "info: papertrail maximum time is " + std::string(ftime); } } } else if (args.size() >= 2) { - string all_args = remaining_args(cmdline, args); + std::string all_args = remaining_args(cmdline, args); struct timeval new_time = {0, 0}; date_time_scanner dts; struct exttm tm; @@ -3065,10 +3134,12 @@ com_pt_time(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_summarize(exec_context& ec, string cmdline, vector& args) +static Result +com_summarize(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("colname"); @@ -3079,15 +3150,15 @@ com_summarize(exec_context& ec, string cmdline, vector& args) return ec.make_error("no columns specified"); } else { auto_mem query_frag; - std::vector other_columns; - std::vector num_columns; + std::vector other_columns; + std::vector num_columns; sql_progress_guard progress_guard(sql_progress, sql_progress_finished, ec.ec_source.top().first, ec.ec_source.top().second); auto_mem stmt(sqlite3_finalize); int retcode; - string query; + std::string query; query = "SELECT "; for (size_t lpc = 1; lpc < args.size(); lpc++) { @@ -3121,7 +3192,7 @@ com_summarize(exec_context& ec, string cmdline, vector& args) } if (ec.ec_dry_run) { - return Ok(string()); + return Ok(std::string()); } for (int lpc = 0; lpc < sqlite3_column_count(stmt.in()); lpc++) { @@ -3261,10 +3332,12 @@ com_summarize(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_add_test(exec_context& ec, string cmdline, vector& args) +static Result +com_add_test(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (args.size() > 1) { @@ -3280,7 +3353,7 @@ com_add_test(exec_context& ec, string cmdline, vector& args) for (iter = bv.begin(); iter != bv.end(); ++iter) { auto_mem file(fclose); char path[PATH_MAX]; - string line; + std::string line; tc->grep_value_for_line(*iter, line); @@ -3303,10 +3376,12 @@ com_add_test(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_switch_to_view(exec_context& ec, string cmdline, vector& args) +static Result +com_switch_to_view(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("viewname"); @@ -3334,10 +3409,12 @@ com_switch_to_view(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_toggle_filtering(exec_context& ec, string cmdline, vector& args) +static Result +com_toggle_filtering(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -3350,10 +3427,12 @@ com_toggle_filtering(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_zoom_to(exec_context& ec, string cmdline, vector& args) +static Result +com_zoom_to(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("zoomlevel"); @@ -3416,8 +3495,10 @@ com_zoom_to(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_reset_session(exec_context& ec, string cmdline, vector& args) +static Result +com_reset_session(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -3425,11 +3506,13 @@ com_reset_session(exec_context& ec, string cmdline, vector& args) lnav_data.ld_views[LNV_LOG].reload_data(); } - return Ok(string()); + return Ok(std::string()); } -static Result -com_load_session(exec_context& ec, string cmdline, vector& args) +static Result +com_load_session(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -3437,24 +3520,28 @@ com_load_session(exec_context& ec, string cmdline, vector& args) lnav_data.ld_views[LNV_LOG].reload_data(); } - return Ok(string()); + return Ok(std::string()); } -static Result -com_save_session(exec_context& ec, string cmdline, vector& args) +static Result +com_save_session(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { } else if (!ec.ec_dry_run) { save_session(); } - return Ok(string()); + return Ok(std::string()); } -static Result -com_set_min_log_level(exec_context& ec, string cmdline, vector& args) +static Result +com_set_min_log_level(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("levelname"); @@ -3468,7 +3555,7 @@ com_set_min_log_level(exec_context& ec, string cmdline, vector& args) lss.set_min_log_level(new_level); retval = ("info: minimum log level is now -- " - + string(level_names[new_level])); + + std::string(level_names[new_level])); } else { return ec.make_error("expecting a log level name"); } @@ -3476,10 +3563,12 @@ com_set_min_log_level(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_toggle_field(exec_context& ec, string cmdline, vector& args) +static Result +com_toggle_field(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("colname"); @@ -3496,14 +3585,14 @@ com_toggle_field(exec_context& ec, string cmdline, vector& args) } else { logfile_sub_source& lss = lnav_data.ld_log_source; bool hide = args[0] == "hide-fields"; - vector found_fields, missing_fields; + std::vector found_fields, missing_fields; for (int lpc = 1; lpc < (int) args.size(); lpc++) { intern_string_t name; std::shared_ptr format; size_t dot; - if ((dot = args[lpc].find('.')) != string::npos) { + if ((dot = args[lpc].find('.')) != std::string::npos) { const intern_string_t format_name = intern_string::lookup(args[lpc].c_str(), dot); @@ -3552,10 +3641,12 @@ com_toggle_field(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_hide_line(exec_context& ec, string cmdline, vector& args) +static Result +com_hide_line(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("move-time"); @@ -3576,12 +3667,15 @@ com_hide_line(exec_context& ec, string cmdline, vector& args) sql_strftime(max_time_str, sizeof(max_time_str), max_time); } if (have_min_time && have_max_time) { - retval = "info: hiding lines before " + string(min_time_str) - + " and after " + string(max_time_str); + retval = "info: hiding lines before " + + std::string(min_time_str) + " and after " + + std::string(max_time_str); } else if (have_min_time) { - retval = "info: hiding lines before " + string(min_time_str); + retval + = "info: hiding lines before " + std::string(min_time_str); } else if (have_max_time) { - retval = "info: hiding lines after " + string(max_time_str); + retval + = "info: hiding lines after " + std::string(max_time_str); } else { retval = "info: no lines hidden by time, pass an absolute or " @@ -3592,7 +3686,7 @@ com_hide_line(exec_context& ec, string cmdline, vector& args) "hiding lines by time only works in the log view"); } } else if (args.size() >= 2) { - string all_args = remaining_args(cmdline, args); + std::string all_args = remaining_args(cmdline, args); textview_curses* tc = *lnav_data.ld_view_stack.top(); logfile_sub_source& lss = lnav_data.ld_log_source; date_time_scanner dts; @@ -3630,7 +3724,7 @@ com_hide_line(exec_context& ec, string cmdline, vector& args) if (tv_set && !ec.ec_dry_run) { char time_text[256]; - string relation; + std::string relation; sql_strftime(time_text, sizeof(time_text), tv); if (args[0] == "hide-lines-before") { @@ -3648,10 +3742,12 @@ com_hide_line(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_show_lines(exec_context& ec, string cmdline, vector& args) +static Result +com_show_lines(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval = "info: showing lines"; + std::string retval = "info: showing lines"; if (ec.ec_dry_run) { retval = ""; @@ -3667,10 +3763,12 @@ com_show_lines(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_hide_unmarked(exec_context& ec, string cmdline, vector& args) +static Result +com_hide_unmarked(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval = "info: hid unmarked lines"; + std::string retval = "info: hid unmarked lines"; if (args.empty()) { } else if (ec.ec_dry_run) { @@ -3691,10 +3789,12 @@ com_hide_unmarked(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_show_unmarked(exec_context& ec, string cmdline, vector& args) +static Result +com_show_unmarked(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval = "info: showing unmarked lines"; + std::string retval = "info: showing unmarked lines"; if (ec.ec_dry_run) { retval = ""; @@ -3705,30 +3805,36 @@ com_show_unmarked(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_rebuild(exec_context& ec, string cmdline, vector& args) +static Result +com_rebuild(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { } else if (!ec.ec_dry_run) { rebuild_indexes_repeatedly(); } - return Ok(string()); + return Ok(std::string()); } -static Result -com_shexec(exec_context& ec, string cmdline, vector& args) +static Result +com_shexec(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { } else if (!ec.ec_dry_run) { log_perror(system(cmdline.substr(args[0].size()).c_str())); } - return Ok(string()); + return Ok(std::string()); } -static Result -com_poll_now(exec_context& ec, string cmdline, vector& args) +static Result +com_poll_now(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -3736,11 +3842,13 @@ com_poll_now(exec_context& ec, string cmdline, vector& args) [](auto& clooper) { clooper.process_all(); }); } - return Ok(string()); + return Ok(std::string()); } -static Result -com_redraw(exec_context& ec, string cmdline, vector& args) +static Result +com_redraw(exec_context& ec, + std::string cmdline, + std::vector& args) { if (args.empty()) { } else if (ec.ec_dry_run) { @@ -3748,21 +3856,21 @@ com_redraw(exec_context& ec, string cmdline, vector& args) redrawwin(lnav_data.ld_window); } - return Ok(string()); + return Ok(std::string()); } -static Result -com_echo(exec_context& ec, string cmdline, vector& args) +static Result +com_echo(exec_context& ec, std::string cmdline, std::vector& args) { - string retval = "error: expecting a message"; + std::string retval = "error: expecting a message"; if (args.empty()) { } else if (args.size() >= 1) { bool lf = true; - string src; + std::string src; if (args.size() > 2 && args[1] == "-n") { - string::size_type index_in_cmdline = cmdline.find(args[1]); + std::string::size_type index_in_cmdline = cmdline.find(args[1]); lf = false; src = cmdline.substr(index_in_cmdline + args[1].length() + 1); @@ -3801,10 +3909,12 @@ com_echo(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_alt_msg(exec_context& ec, string cmdline, vector& args) +static Result +com_alt_msg(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { } else if (ec.ec_dry_run) { @@ -3815,7 +3925,7 @@ com_alt_msg(exec_context& ec, string cmdline, vector& args) } retval = ""; } else { - string msg = remaining_args(cmdline, args); + std::string msg = remaining_args(cmdline, args); if (lnav_data.ld_rl_view != nullptr) { lnav_data.ld_rl_view->set_alt_value(msg); @@ -3827,16 +3937,16 @@ com_alt_msg(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_eval(exec_context& ec, string cmdline, vector& args) +static Result +com_eval(exec_context& ec, std::string cmdline, std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("*"); } else if (args.size() > 1) { - string all_args = remaining_args(cmdline, args); - string expanded_cmd; + std::string all_args = remaining_args(cmdline, args); + std::string expanded_cmd; shlex lexer(all_args.c_str(), all_args.size()); log_debug("Evaluating: %s", all_args.c_str()); @@ -3862,10 +3972,10 @@ com_eval(exec_context& ec, string cmdline, vector& args) lnav_data.ld_preview_source.replace_with(al); - return Ok(string()); + return Ok(std::string()); } - string alt_msg; + std::string alt_msg; switch (expanded_cmd[0]) { case ':': return execute_command(ec, expanded_cmd.substr(1)); @@ -3891,17 +4001,19 @@ com_eval(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_config(exec_context& ec, string cmdline, vector& args) +static Result +com_config(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("config-option"); } else if (args.size() > 1) { yajlpp_parse_context ypc("input", &lnav_config_handlers); - vector errors; - string option = args[1]; + std::vector errors; + std::string option = args[1]; lnav_config = rollback_lnav_config; ypc.set_path(option) @@ -3931,7 +4043,7 @@ com_config(exec_context& ec, string cmdline, vector& args) jph->gen(ygc, gen); } - string old_value = gen.to_string_fragment().to_string(); + std::string old_value = gen.to_string_fragment().to_string(); if (args.size() == 2 || ypc.ypc_current_handler == nullptr) { lnav_config = rollback_lnav_config; @@ -3961,7 +4073,7 @@ com_config(exec_context& ec, string cmdline, vector& args) FMT_STRING("{} = {}"), option, trim(old_value)); } } else { - string value = remaining_args(cmdline, args, 2); + std::string value = remaining_args(cmdline, args, 2); bool changed = false; if (ec.ec_dry_run) { @@ -4043,10 +4155,12 @@ com_config(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_reset_config(exec_context& ec, string cmdline, vector& args) +static Result +com_reset_config(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("config-option"); @@ -4054,7 +4168,7 @@ com_reset_config(exec_context& ec, string cmdline, vector& args) return ec.make_error("expecting a configuration option to reset"); } else { yajlpp_parse_context ypc("input", &lnav_config_handlers); - string option = args[1]; + std::string option = args[1]; lnav_config = rollback_lnav_config; ypc.set_path(option).with_obj(lnav_config); @@ -4170,7 +4284,7 @@ public: = lss.find_from_time(sr.sr_begin_time).value_or(0_vl); vis_line_t end_line = lss.find_from_time(sr.sr_end_time) .value_or(lss.text_line_count()); - vector values; + std::vector values; string_attrs_t sa; for (vis_line_t curr_line = begin_line; curr_line < end_line; @@ -4190,7 +4304,7 @@ public: values.clear(); format->annotate(cl, sbr, sa, values, false); - vector::iterator lv_iter; + std::vector::iterator lv_iter; lv_iter = find_if(values.begin(), values.end(), @@ -4225,7 +4339,7 @@ public: vis_line_t begin_line = lss.find_from_time(begin_time).value_or(0_vl); vis_line_t end_line = lss.find_from_time(end_time).value_or(lss.text_line_count()); - vector values; + std::vector values; string_attrs_t sa; for (vis_line_t curr_line = begin_line; curr_line < end_line; @@ -4245,7 +4359,7 @@ public: values.clear(); format->annotate(cl, sbr, sa, values, false); - vector::iterator lv_iter; + std::vector::iterator lv_iter; lv_iter = find_if(values.begin(), values.end(), @@ -4283,7 +4397,7 @@ public: class db_spectro_value_source : public spectrogram_value_source { public: - db_spectro_value_source(string colname) + db_spectro_value_source(std::string colname) : dsvs_colname(std::move(colname)), dsvs_begin_time(0), dsvs_end_time(0) { this->update_stats(); @@ -4296,7 +4410,7 @@ public: this->dsvs_stats.clear(); db_label_source& dls = lnav_data.ld_db_row_source; - stacked_bar_chart& chart = dls.dls_chart; + stacked_bar_chart& chart = dls.dls_chart; date_time_scanner dts; this->dsvs_column_index = dls.column_name_to_index(this->dsvs_colname); @@ -4324,7 +4438,7 @@ public: return; } - stacked_bar_chart::bucket_stats_t bs + stacked_bar_chart::bucket_stats_t bs = chart.get_stats_for(this->dsvs_colname); this->dsvs_begin_time = dls.dls_time_column.front().tv_sec; @@ -4373,25 +4487,27 @@ public: double range_min, double range_max){}; - string dsvs_colname; + std::string dsvs_colname; logline_value_stats dsvs_stats; time_t dsvs_begin_time; time_t dsvs_end_time; int dsvs_column_index; - string dsvs_error_msg; + std::string dsvs_error_msg; }; -static Result -com_spectrogram(exec_context& ec, string cmdline, vector& args) +static Result +com_spectrogram(exec_context& ec, + std::string cmdline, + std::vector& args) { - string retval; + std::string retval; if (args.empty()) { args.emplace_back("numeric-colname"); } else if (ec.ec_dry_run) { retval = ""; } else if (args.size() == 2) { - string colname = remaining_args(cmdline, args); + std::string colname = remaining_args(cmdline, args); spectrogram_source& ss = lnav_data.ld_spectro_source; bool found = false; @@ -4403,7 +4519,7 @@ com_spectrogram(exec_context& ec, string cmdline, vector& args) ss.invalidate(); if (*lnav_data.ld_view_stack.top() == &lnav_data.ld_views[LNV_DB]) { - unique_ptr dsvs( + std::unique_ptr dsvs( new db_spectro_value_source(colname)); if (!dsvs->dsvs_error_msg.empty()) { @@ -4413,7 +4529,7 @@ com_spectrogram(exec_context& ec, string cmdline, vector& args) found = true; } } else { - unique_ptr lsvs( + std::unique_ptr lsvs( new log_spectro_value_source(intern_string::lookup(colname))); if (!lsvs->lsvs_found) { @@ -4442,18 +4558,18 @@ com_spectrogram(exec_context& ec, string cmdline, vector& args) return Ok(retval); } -static Result -com_quit(exec_context& ec, string cmdline, vector& args) +static Result +com_quit(exec_context& ec, std::string cmdline, std::vector& args) { if (args.empty()) { } else if (!ec.ec_dry_run) { lnav_data.ld_looping = false; } - return Ok(string()); + return Ok(std::string()); } static void -command_prompt(vector& args) +command_prompt(std::vector& args) { textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -4567,7 +4683,7 @@ command_prompt(vector& args) } static void -script_prompt(vector& args) +script_prompt(std::vector& args) { textview_curses* tc = *lnav_data.ld_view_stack.top(); auto& scripts = injector::get(); @@ -4590,7 +4706,7 @@ script_prompt(vector& args) } static void -search_prompt(vector& args) +search_prompt(std::vector& args) { textview_curses* tc = *lnav_data.ld_view_stack.top(); @@ -4608,7 +4724,7 @@ search_prompt(vector& args) } static void -search_filters_prompt(vector& args) +search_filters_prompt(std::vector& args) { lnav_data.ld_mode = LNM_SEARCH_FILTERS; lnav_data.ld_filter_view.reload_data(); @@ -4626,7 +4742,7 @@ search_filters_prompt(vector& args) } static void -search_files_prompt(vector& args) +search_files_prompt(std::vector& args) { static const std::regex re_escape(R"(([.\^$*+?()\[\]{}\\|]))"); @@ -4645,7 +4761,7 @@ search_files_prompt(vector& args) } static void -sql_prompt(vector& args) +sql_prompt(std::vector& args) { textview_curses* tc = *lnav_data.ld_view_stack.top(); textview_curses& log_view = lnav_data.ld_views[LNV_LOG]; @@ -4670,7 +4786,7 @@ sql_prompt(vector& args) } static void -user_prompt(vector& args) +user_prompt(std::vector& args) { textview_curses* tc = *lnav_data.ld_view_stack.top(); lnav_data.ld_exec_context.ec_top_line = tc->get_top(); @@ -4684,18 +4800,21 @@ user_prompt(vector& args) lnav_data.ld_status[LNS_BOTTOM].do_update(); } -static Result -com_prompt(exec_context& ec, string cmdline, vector& args) +static Result +com_prompt(exec_context& ec, + std::string cmdline, + std::vector& args) { - static map&)>> PROMPT_TYPES = { - {"command", command_prompt}, - {"script", script_prompt}, - {"search", search_prompt}, - {"search-filters", search_filters_prompt}, - {"search-files", search_files_prompt}, - {"sql", sql_prompt}, - {"user", user_prompt}, - }; + static std::map&)>> + PROMPT_TYPES = { + {"command", command_prompt}, + {"script", script_prompt}, + {"search", search_prompt}, + {"search-filters", search_filters_prompt}, + {"search-files", search_files_prompt}, + {"sql", sql_prompt}, + {"user", user_prompt}, + }; if (args.empty()) { } else if (!ec.ec_dry_run) { @@ -4720,7 +4839,7 @@ com_prompt(exec_context& ec, string cmdline, vector& args) prompter->second(args); lnav_data.ld_rl_view->set_alt_focus(is_alt); } - return Ok(string()); + return Ok(std::string()); } readline_context::command_t STD_COMMANDS[] = { @@ -5549,7 +5668,7 @@ readline_context::command_t STD_COMMANDS[] = { help_text(":quit").with_summary("Quit lnav")}}; -static unordered_map> aliases +static std::unordered_map> aliases = {{"quit", {"q", "q!"}}, {"write-table-to", { diff --git a/src/lnav_config.cc b/src/lnav_config.cc index 99ad0783..5bd51a74 100644 --- a/src/lnav_config.cc +++ b/src/lnav_config.cc @@ -46,8 +46,8 @@ #include #include -#include "auto_fd.hh" #include "auto_mem.hh" +#include "base/auto_fd.hh" #include "base/auto_pid.hh" #include "base/fs_util.hh" #include "base/injector.bind.hh" @@ -62,7 +62,7 @@ #include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp_def.hh" -using namespace std; +using namespace std::chrono_literals; static const int MAX_CRASH_LOG_COUNT = 16; static const auto STDIN_CAPTURE_RETENTION = 24h; @@ -159,7 +159,8 @@ ensure_dotlnav() continue; } - if (chrono::system_clock::from_time_t(st.st_mtime) > old_time) { + if (std::chrono::system_clock::from_time_t(st.st_mtime) + > old_time) { continue; } @@ -178,7 +179,7 @@ install_from_git(const char* repo) auto formats_path = lnav::paths::dotlnav() / "formats"; auto configs_path = lnav::paths::dotlnav() / "configs"; auto staging_path = lnav::paths::dotlnav() / "staging"; - string local_name = std::regex_replace(repo, repo_name_converter, "_"); + auto local_name = std::regex_replace(repo, repo_name_converter, "_"); auto local_formats_path = formats_path / local_name; auto local_configs_path = configs_path / local_name; @@ -307,7 +308,7 @@ update_installs_from_git() static int read_repo_path(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { - string path = string((const char*) str, len); + auto path = std::string((const char*) str, len); install_from_git(path.c_str()); @@ -367,9 +368,9 @@ install_extra_formats() } struct userdata { - userdata(vector& errors) : ud_errors(errors){}; + userdata(std::vector& errors) : ud_errors(errors){}; - vector& ud_errors; + std::vector& ud_errors; }; static void @@ -418,30 +419,30 @@ static const struct json_path_container keymap_def_handlers return &retval; }) .with_path_provider( - [](key_map* km, vector& paths_out) { + [](key_map* km, std::vector& paths_out) { for (const auto& iter : km->km_seq_to_cmd) { paths_out.emplace_back(iter.first); } }) .with_children(key_command_handlers)}; -static const struct json_path_container keymap_defs_handlers - = {yajlpp::pattern_property_handler("(?[\\w\\-]+)") - .with_description("The keymap definitions") - .with_obj_provider( - [](const yajlpp_provider_context& ypc, _lnav_config* root) { - key_map& retval - = root->lc_ui_keymaps[ypc.ypc_extractor.get_substr( - "keymap_name")]; - return &retval; - }) - .with_path_provider<_lnav_config>( - [](struct _lnav_config* cfg, vector& paths_out) { - for (const auto& iter : cfg->lc_ui_keymaps) { - paths_out.emplace_back(iter.first); - } - }) - .with_children(keymap_def_handlers)}; +static const struct json_path_container keymap_defs_handlers = { + yajlpp::pattern_property_handler("(?[\\w\\-]+)") + .with_description("The keymap definitions") + .with_obj_provider( + [](const yajlpp_provider_context& ypc, _lnav_config* root) { + key_map& retval + = root->lc_ui_keymaps[ypc.ypc_extractor.get_substr( + "keymap_name")]; + return &retval; + }) + .with_path_provider<_lnav_config>( + [](struct _lnav_config* cfg, std::vector& paths_out) { + for (const auto& iter : cfg->lc_ui_keymaps) { + paths_out.emplace_back(iter.first); + } + }) + .with_children(keymap_def_handlers)}; static const struct json_path_container global_var_handlers = { yajlpp::pattern_property_handler("(?\\w+)") @@ -450,7 +451,7 @@ static const struct json_path_container global_var_handlers = { "A global variable definition. Global variables can be referenced " "in scripts, SQL statements, or commands.") .with_path_provider<_lnav_config>( - [](struct _lnav_config* cfg, vector& paths_out) { + [](struct _lnav_config* cfg, std::vector& paths_out) { for (const auto& iter : cfg->lc_global_vars) { paths_out.emplace_back(iter.first); } @@ -783,7 +784,7 @@ static const struct json_path_container theme_log_level_styles_handlers return ≻ }) .with_path_provider( - [](struct lnav_theme* cfg, vector& paths_out) { + [](struct lnav_theme* cfg, std::vector& paths_out) { for (int lpc = LEVEL_TRACE; lpc < LEVEL__MAX; lpc++) { paths_out.emplace_back(level_names[lpc]); } @@ -818,7 +819,7 @@ static const struct json_path_container theme_highlights_handlers return &hc; }) .with_path_provider( - [](struct lnav_theme* cfg, vector& paths_out) { + [](struct lnav_theme* cfg, std::vector& paths_out) { for (const auto& pair : cfg->lt_highlights) { paths_out.emplace_back(pair.first); } @@ -830,7 +831,7 @@ static const struct json_path_container theme_vars_handlers .with_synopsis("name") .with_description("A theme variable definition") .with_path_provider( - [](struct lnav_theme* lt, vector& paths_out) { + [](struct lnav_theme* lt, std::vector& paths_out) { for (const auto& iter : lt->lt_vars) { paths_out.emplace_back(iter.first); } @@ -863,24 +864,24 @@ static const struct json_path_container theme_def_handlers = { .with_children(theme_highlights_handlers), }; -static const struct json_path_container theme_defs_handlers - = {yajlpp::pattern_property_handler("(?[\\w\\-]+)") - .with_description("Theme definitions") - .with_obj_provider( - [](const yajlpp_provider_context& ypc, _lnav_config* root) { - lnav_theme& lt - = root->lc_ui_theme_defs[ypc.ypc_extractor.get_substr( - "theme_name")]; +static const struct json_path_container theme_defs_handlers = { + yajlpp::pattern_property_handler("(?[\\w\\-]+)") + .with_description("Theme definitions") + .with_obj_provider( + [](const yajlpp_provider_context& ypc, _lnav_config* root) { + lnav_theme& lt + = root->lc_ui_theme_defs[ypc.ypc_extractor.get_substr( + "theme_name")]; - return < - }) - .with_path_provider<_lnav_config>( - [](struct _lnav_config* cfg, vector& paths_out) { - for (const auto& iter : cfg->lc_ui_theme_defs) { - paths_out.emplace_back(iter.first); - } - }) - .with_children(theme_def_handlers)}; + return < + }) + .with_path_provider<_lnav_config>( + [](struct _lnav_config* cfg, std::vector& paths_out) { + for (const auto& iter : cfg->lc_ui_theme_defs) { + paths_out.emplace_back(iter.first); + } + }) + .with_children(theme_def_handlers)}; static const struct json_path_container ui_handlers = { yajlpp::property_handler("clock-format") @@ -1072,7 +1073,7 @@ static const struct json_path_container sysclip_impls_handlers = { return &retval; }) .with_path_provider<_lnav_config>( - [](struct _lnav_config* cfg, vector& paths_out) { + [](struct _lnav_config* cfg, std::vector& paths_out) { for (const auto& iter : cfg->lc_sysclip.c_clipboard_impls) { paths_out.emplace_back(iter.first); } @@ -1104,21 +1105,21 @@ static const struct json_path_container tuning_handlers = { .with_children(sysclip_handlers), }; -static const set SUPPORTED_CONFIG_SCHEMAS = { +static const std::set SUPPORTED_CONFIG_SCHEMAS = { "https://lnav.org/schemas/config-v1.schema.json", }; const char* DEFAULT_FORMAT_SCHEMA = "https://lnav.org/schemas/format-v1.schema.json"; -const set SUPPORTED_FORMAT_SCHEMAS = { +const std::set SUPPORTED_FORMAT_SCHEMAS = { DEFAULT_FORMAT_SCHEMA, }; static int read_id(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { - auto file_id = string((const char*) str, len); + auto file_id = std::string((const char*) str, len); if (SUPPORTED_CONFIG_SCHEMAS.count(file_id) == 0) { ypc->report_error( @@ -1176,7 +1177,7 @@ detect_config_file_type(const ghc::filesystem::path& path) auto read_res = lnav::filesystem::read_file(path); if (read_res.isErr()) { - return Err(fmt::format(FMT_STRING("unable to open file: {} -- {}"), + return Err(fmt::format(FMT_STRING("unable to open file4: {} -- {}"), path.string(), read_res.unwrapErr())); } @@ -1187,7 +1188,7 @@ detect_config_file_type(const ghc::filesystem::path& path) } char error_buffer[1024]; - auto content_tree = unique_ptr( + auto content_tree = std::unique_ptr( yajl_tree_parse(content.c_str(), error_buffer, sizeof(error_buffer)), yajl_tree_free); if (content_tree == nullptr) { @@ -1216,7 +1217,7 @@ detect_config_file_type(const ghc::filesystem::path& path) static void load_config_from(_lnav_config& lconfig, const ghc::filesystem::path& path, - vector& errors) + std::vector& errors) { yajlpp_parse_context ypc(path.string(), &lnav_config_handlers); struct userdata ud(errors); @@ -1269,7 +1270,7 @@ static void load_default_config(struct _lnav_config& config_obj, const std::string& path, const bin_src_file& bsf, - vector& errors) + std::vector& errors) { yajlpp_parse_context ypc_builtin(bsf.get_name(), &lnav_config_handlers); auto_mem handle(yajl_free); @@ -1297,7 +1298,7 @@ load_default_config(struct _lnav_config& config_obj, static void load_default_configs(struct _lnav_config& config_obj, const std::string& path, - vector& errors) + std::vector& errors) { for (auto& bsf : lnav_config_json) { load_default_config(config_obj, path, bsf, errors); @@ -1305,8 +1306,8 @@ load_default_configs(struct _lnav_config& config_obj, } void -load_config(const vector& extra_paths, - vector& errors) +load_config(const std::vector& extra_paths, + std::vector& errors) { auto user_config = lnav::paths::dotlnav() / "config.json"; @@ -1369,7 +1370,7 @@ load_config(const vector& extra_paths, void reset_config(const std::string& path) { - vector errors; + std::vector errors; load_default_configs(lnav_config, path, errors); @@ -1380,7 +1381,7 @@ reset_config(const std::string& path) } } -string +std::string save_config() { yajlpp_gen gen; @@ -1390,7 +1391,7 @@ save_config() yajl_gen_config(gen, yajl_gen_beautify, true); yajlpp_gen_context ygc(gen, lnav_config_handlers); - vector errors; + std::vector errors; ygc.with_default_obj(lnav_default_config).with_obj(lnav_config); ygc.gen(); @@ -1403,7 +1404,7 @@ save_config() == -1) { return "error: unable to save configuration -- " - + string(strerror(errno)); + + std::string(strerror(errno)); } string_fragment bits = gen.to_string_fragment(); @@ -1417,7 +1418,7 @@ save_config() } void -reload_config(vector& errors) +reload_config(std::vector& errors) { lnav_config_listener* curr = lnav_config_listener::LISTENER_LIST; @@ -1426,7 +1427,7 @@ reload_config(vector& errors) const std::string& errmsg) { auto cb = [&cfg_value, &errors, &errmsg]( const json_path_handler_base& jph, - const string& path, + const std::string& path, void* mem) { if (mem != cfg_value) { return; diff --git a/src/log_actions.cc b/src/log_actions.cc index fc55f9e6..235abe96 100644 --- a/src/log_actions.cc +++ b/src/log_actions.cc @@ -33,18 +33,16 @@ #include "config.h" #include "piper_proc.hh" -using namespace std; - -string -action_delegate::execute_action(const string& action_name) +std::string +action_delegate::execute_action(const std::string& action_name) { auto& ldh = this->ad_log_helper; auto value_index = this->ad_press_value; logline_value& lv = ldh.ldh_line_values[value_index]; - shared_ptr lf = ldh.ldh_file; + auto lf = ldh.ldh_file; const auto format = lf->get_format(); pid_t child_pid; - string retval; + std::string retval; auto iter = format->lf_action_defs.find(action_name); @@ -65,15 +63,16 @@ action_delegate::execute_action(const string& action_name) switch (child_pid) { case -1: - retval = "error: unable to fork child process -- " - + string(strerror(errno)); + retval = fmt::format( + FMT_STRING("error: unable to fork child process -- {}"), + strerror(errno)); break; case 0: { const char* args[action.ad_cmdline.size() + 1]; - set path_set(format->get_source_path()); + std::set path_set(format->get_source_path()); char env_buffer[64]; int value_line; - string path; + std::string path; dup2(STDOUT_FILENO, STDERR_FILENO); setenv("LNAV_ACTION_FILE", lf->get_filename().c_str(), 1); @@ -96,7 +95,7 @@ action_delegate::execute_action(const string& action_name) } path += path_iter; } - path += ":" + string(getenv("PATH")); + path += ":" + std::string(getenv("PATH")); setenv("PATH", path.c_str(), 1); for (size_t lpc = 0; lpc < action.ad_cmdline.size(); lpc++) { args[lpc] = action.ad_cmdline[lpc].c_str(); @@ -112,7 +111,7 @@ action_delegate::execute_action(const string& action_name) default: { static int exec_count = 0; - string value = lv.to_string(); + const auto value = lv.to_string(); this->ad_child_cb(child_pid); @@ -122,8 +121,8 @@ action_delegate::execute_action(const string& action_name) in_pipe.close(); if (out_pipe.read_end() != -1) { - auto pp = make_shared( - out_pipe.read_end(), + auto pp = std::make_shared( + std::move(out_pipe.read_end()), false, lnav::filesystem::open_temp_file( ghc::filesystem::temp_directory_path() @@ -209,8 +208,8 @@ action_delegate::text_handle_mouse(textview_curses& tc, mouse_event& me) int x_offset = this->ad_line_index + mouse_left; if (lv.lv_origin.contains(x_offset)) { - shared_ptr lf = this->ad_log_helper.ldh_file; - const vector* actions; + auto lf = this->ad_log_helper.ldh_file; + const std::vector* actions; actions = lf->get_format()->get_actions(lv); if (actions != nullptr && !actions->empty()) { diff --git a/src/log_format.cc b/src/log_format.cc index eeb4eb30..0c75c032 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -46,8 +46,6 @@ #include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp_def.hh" -using namespace std; - static auto intern_lifetime = intern_string::get_table_lifetime(); string_attr_type logline::L_PREFIX("prefix"); string_attr_type logline::L_TIMESTAMP("timestamp"); @@ -232,9 +230,9 @@ logline_value::to_string() const return {buffer}; } -vector> log_format::lf_root_formats; +std::vector> log_format::lf_root_formats; -vector>& +std::vector>& log_format::get_root_formats() { return lf_root_formats; @@ -471,7 +469,7 @@ read_json_int(yajlpp_parse_context* ypc, long long val) jlu->jlu_base_line->set_level( jlu->jlu_format->convert_level(pi, &level_cap)); } else { - vector>::iterator iter; + std::vector>::iterator iter; for (iter = jlu->jlu_format->elf_level_pairs.begin(); iter != jlu->jlu_format->elf_level_pairs.end(); @@ -735,7 +733,8 @@ external_log_format::scan(logfile& lf, log_debug("Unable to parse line at offset %d: %s", li.li_file_range.fr_offset, msg); - line_count = count(msg, msg + strlen((char*) msg), '\n') + 1; + line_count + = std::count(msg, msg + strlen((char*) msg), '\n') + 1; yajl_free_error(handle, msg); } if (!this->lf_specialized) { @@ -836,7 +835,7 @@ external_log_format::scan(logfile& lf, } if (mod_index && level_cap && body_cap) { - auto mod_elf = dynamic_pointer_cast( + auto mod_elf = std::dynamic_pointer_cast( mod_iter->second.mf_mod_format); if (mod_elf) { @@ -1124,9 +1123,9 @@ void external_log_format::rewrite(exec_context& ec, shared_buffer_ref& line, string_attrs_t& sa, - string& value_out) + std::string& value_out) { - vector::iterator shift_iter; + std::vector::iterator shift_iter; auto& values = *ec.ec_line_values; value_out.assign(line.get_data(), line.length()); @@ -1333,7 +1332,7 @@ external_log_format::get_subline(const logline& ll, || yajl_complete_parse(handle) != yajl_status_ok) { unsigned char* msg; - string full_msg; + std::string full_msg; msg = yajl_get_error( handle, 1, (const unsigned char*) sbr.get_data(), sbr.length()); @@ -1387,7 +1386,7 @@ external_log_format::get_subline(const logline& ll, this->jlf_line_values.end(), logline_value_cmp(&jfe.jfe_value)); if (lv_iter != this->jlf_line_values.end()) { - string str = lv_iter->to_string(); + auto str = lv_iter->to_string(); size_t nl_pos = str.find('\n'); lr.lr_start = this->jlf_cached_line.size(); @@ -1436,7 +1435,7 @@ external_log_format::get_subline(const logline& ll, this->json_append(jfe, str.c_str(), str.size()); } - if (nl_pos == string::npos || full_message) { + if (nl_pos == std::string::npos || full_message) { lr.lr_end = this->jlf_cached_line.size(); } else { lr.lr_end = lr.lr_start + nl_pos; @@ -1628,7 +1627,7 @@ external_log_format::build(std::vector& errors) if (!this->lf_timestamp_field.empty()) { auto& vd = this->elf_value_defs[this->lf_timestamp_field]; if (vd.get() == nullptr) { - vd = make_shared( + vd = std::make_shared( this->lf_timestamp_field, value_kind_t::VALUE_TEXT, -1, this); } vd->vd_meta.lvm_name = this->lf_timestamp_field; @@ -1641,7 +1640,7 @@ external_log_format::build(std::vector& errors) { auto& vd = this->elf_value_defs[this->elf_level_field]; if (vd.get() == nullptr) { - vd = make_shared( + vd = std::make_shared( this->elf_level_field, value_kind_t::VALUE_TEXT, -1, this); } vd->vd_meta.lvm_name = this->elf_level_field; @@ -1651,7 +1650,7 @@ external_log_format::build(std::vector& errors) if (!this->elf_body_field.empty()) { auto& vd = this->elf_value_defs[this->elf_body_field]; if (vd.get() == nullptr) { - vd = make_shared( + vd = std::make_shared( this->elf_body_field, value_kind_t::VALUE_TEXT, -1, this); } vd->vd_meta.lvm_name = this->elf_body_field; @@ -1687,8 +1686,8 @@ external_log_format::build(std::vector& errors) errors.push_back("error:" + this->elf_name.to_string() + ".regex[" + iter->first + "]" + ":" + pat.p_string); errors.push_back("error:" + this->elf_name.to_string() + ".regex[" - + iter->first + "]" + ":" + string(e.e_offset, ' ') - + "^"); + + iter->first + "]" + ":" + + std::string(e.e_offset, ' ') + "^"); continue; } for (pcre_named_capture::iterator name_iter = pat.p_pcre->named_begin(); @@ -1903,8 +1902,8 @@ external_log_format::build(std::vector& errors) PTIMEC_FORMATS[lpc].pf_func(&tm, ts, off, ts_len); errors.push_back( " format: " - + string(PTIMEC_FORMATS[lpc].pf_fmt) - + "; matched: " + string(ts, off)); + + std::string(PTIMEC_FORMATS[lpc].pf_fmt) + + "; matched: " + std::string(ts, off)); } } else { for (int lpc = 0; custom_formats[lpc] != nullptr; lpc++) @@ -1913,9 +1912,9 @@ external_log_format::build(std::vector& errors) ptime_fmt( custom_formats[lpc], &tm, ts, off, ts_len); - errors.push_back(" format: " - + string(custom_formats[lpc]) - + "; matched: " + string(ts, off)); + errors.push_back( + " format: " + std::string(custom_formats[lpc]) + + "; matched: " + std::string(ts, off)); } } } @@ -2094,13 +2093,13 @@ external_log_format::build(std::vector& errors) if (code == nullptr) { errors.push_back("error:" + this->elf_name.to_string() + ":highlighters/" + hd_pair.first.to_string() - + ":" + string(errptr)); + + ":" + std::string(errptr)); errors.push_back("error:" + this->elf_name.to_string() + ":highlighters/" + hd_pair.first.to_string() + ":" + pattern); errors.push_back("error:" + this->elf_name.to_string() + ":highlighters/" + hd_pair.first.to_string() - + ":" + string(eoff, ' ') + "^"); + + ":" + std::string(eoff, ' ') + "^"); } else { this->lf_highlighters.emplace_back(code); this->lf_highlighters.back() @@ -2116,8 +2115,7 @@ void external_log_format::register_vtabs(log_vtab_manager* vtab_manager, std::vector& errors) { - vector>::iterator search_iter; - for (search_iter = this->elf_search_tables.begin(); + for (auto search_iter = this->elf_search_tables.begin(); search_iter != this->elf_search_tables.end(); ++search_iter) { @@ -2136,9 +2134,7 @@ external_log_format::register_vtabs(log_vtab_manager* vtab_manager, auto lst = std::make_shared(re_res.unwrap(), search_iter->first); - string errmsg; - - errmsg = vtab_manager->register_vtab(lst); + auto errmsg = vtab_manager->register_vtab(lst); if (!errmsg.empty()) { errors.push_back("error:" + this->elf_name.to_string() + ":" + search_iter->first.to_string() @@ -2148,7 +2144,7 @@ external_log_format::register_vtabs(log_vtab_manager* vtab_manager, } bool -external_log_format::match_samples(const vector& samples) const +external_log_format::match_samples(const std::vector& samples) const { for (const auto& sample_iter : samples) { for (const auto& pat_iter : this->elf_pattern_order) { @@ -2175,7 +2171,7 @@ public: external_log_table(const external_log_format& elf) : log_format_vtab_impl(elf), elt_format(elf){}; - void get_columns(vector& cols) const + void get_columns(std::vector& cols) const { const external_log_format& elf = this->elt_format; @@ -2275,7 +2271,7 @@ public: return false; }; - virtual void extract(shared_ptr lf, + virtual void extract(std::shared_ptr lf, uint64_t line_number, shared_buffer_ref& line, std::vector& values) @@ -2339,7 +2335,7 @@ external_log_format::specialized(int fmt_lock) } bool -external_log_format::match_name(const string& filename) +external_log_format::match_name(const std::string& filename) { if (this->elf_file_pattern.empty()) { return true; diff --git a/src/log_format_impls.cc b/src/log_format_impls.cc index ec7e0597..a729308c 100644 --- a/src/log_format_impls.cc +++ b/src/log_format_impls.cc @@ -45,8 +45,6 @@ #include "sql_util.hh" #include "yajlpp/yajlpp.hh" -using namespace std; - static const pcrepp RDNS_PATTERN( "^(?:com|net|org|edu|[a-z][a-z])" "(\\.\\w+)+(.+)"); @@ -60,12 +58,12 @@ static const pcrepp RDNS_PATTERN( * @return The scrubbed version of the input string or the original string * if it is not a reverse-DNS string. */ -static string -scrub_rdns(const string& str) +static std::string +scrub_rdns(const std::string& str) { pcre_context_static<30> context; pcre_input input(str); - string retval; + std::string retval; if (RDNS_PATTERN.match(context, input)) { pcre_context::capture_t* cap; @@ -142,11 +140,11 @@ class generic_log_format : public log_format { return intern_string::lookup("generic_log"); }; - void scrub(string& line) override + void scrub(std::string& line) override { pcre_context_static<30> context; pcre_input pi(line); - string new_line; + std::string new_line; if (scrub_pattern().match(context, pi)) { pcre_context::capture_t* cap; @@ -160,7 +158,7 @@ class generic_log_format : public log_format { }; scan_result_t scan(logfile& lf, - vector& dst, + std::vector& dst, const line_info& li, shared_buffer_ref& sbr) override { @@ -236,16 +234,16 @@ class generic_log_format : public log_format { sa.emplace_back(lr, &SA_BODY); }; - shared_ptr specialized(int fmt_lock) override + std::shared_ptr specialized(int fmt_lock) override { return std::make_shared(*this); }; }; -string +std::string from_escaped_string(const char* str, size_t len) { - string retval; + std::string retval; for (size_t lpc = 0; lpc < len; lpc++) { switch (str[lpc]) { @@ -549,7 +547,7 @@ public: this->clear(); - string sep + auto sep = from_escaped_string(pi.get_substr_start(pc[0]), pc[0]->length()); this->blf_separator = intern_string::lookup(sep); @@ -624,14 +622,14 @@ public: if (field_type == "time") { fd.with_kind(value_kind_t::VALUE_TIMESTAMP); } else if (field_type == "string") { - bool ident = binary_search(begin(KNOWN_IDS), - end(KNOWN_IDS), - fd.fd_meta.lvm_name); + bool ident = std::binary_search(std::begin(KNOWN_IDS), + std::end(KNOWN_IDS), + fd.fd_meta.lvm_name); fd.with_kind(value_kind_t::VALUE_TEXT, ident); } else if (field_type == "count") { - bool ident = binary_search(begin(KNOWN_IDS), - end(KNOWN_IDS), - fd.fd_meta.lvm_name); + bool ident = std::binary_search(std::begin(KNOWN_IDS), + std::end(KNOWN_IDS), + fd.fd_meta.lvm_name); fd.with_kind(value_kind_t::VALUE_INTEGER, ident) .with_numeric_index(numeric_count); numeric_count += 1; @@ -731,7 +729,7 @@ public: std::shared_ptr specialized(int fmt_lock = -1) override { - return make_shared(*this); + return std::make_shared(*this); }; class bro_log_table : public log_format_vtab_impl { @@ -741,7 +739,7 @@ public: { } - void get_columns(vector& cols) const override + void get_columns(std::vector& cols) const override { for (const auto& fd : this->blt_format.blf_field_defs) { std::pair type_pair @@ -772,9 +770,10 @@ public: const bro_log_format& blt_format; }; - static map>& get_tables() + static std::map>& + get_tables() { - static map> retval; + static std::map> retval; return retval; }; @@ -808,7 +807,7 @@ public: intern_string_t blf_set_separator; intern_string_t blf_empty_field; intern_string_t blf_unset_field; - vector blf_field_defs; + std::vector blf_field_defs; }; struct ws_separated_string { @@ -1321,7 +1320,7 @@ public: std::shared_ptr specialized(int fmt_lock = -1) override { - return make_shared(*this); + return std::make_shared(*this); }; class w3c_log_table : public log_format_vtab_impl { @@ -1331,7 +1330,7 @@ public: { } - void get_columns(vector& cols) const override + void get_columns(std::vector& cols) const override { for (const auto& fd : KNOWN_FIELDS) { auto type_pair = log_vtab_impl::logline_value_to_sqlite_type( @@ -1368,9 +1367,10 @@ public: const w3c_log_format& wlt_format; }; - static map>& get_tables() + static std::map>& + get_tables() { - static map> retval; + static std::map> retval; return retval; }; @@ -1401,7 +1401,7 @@ public: date_time_scanner wlf_time_scanner; intern_string_t wlf_format_name; - vector wlf_field_defs; + std::vector wlf_field_defs; }; static int KNOWN_FIELD_INDEX = 0; @@ -1566,7 +1566,7 @@ public: { } - void get_columns(vector& cols) const override + void get_columns(std::vector& cols) const override { static const auto FIELDS = std::string("fields"); @@ -1574,7 +1574,7 @@ public: }; }; - shared_ptr get_vtab_impl() const override + std::shared_ptr get_vtab_impl() const override { static auto retval = std::make_shared(*this); @@ -1582,7 +1582,7 @@ public: } scan_result_t scan(logfile& lf, - vector& dst, + std::vector& dst, const line_info& li, shared_buffer_ref& sbr) override { @@ -1667,7 +1667,7 @@ public: void annotate(uint64_t line_number, shared_buffer_ref& sbr, string_attrs_t& sa, - vector& values, + std::vector& values, bool annotate_module) const override { static const auto FIELDS_NAME = intern_string::lookup("fields"); @@ -1767,7 +1767,7 @@ public: } } - shared_ptr specialized(int fmt_lock) override + std::shared_ptr specialized(int fmt_lock) override { return std::make_shared(*this); }; diff --git a/src/log_format_loader.cc b/src/log_format_loader.cc index baaeb50b..7edcd909 100644 --- a/src/log_format_loader.cc +++ b/src/log_format_loader.cc @@ -40,7 +40,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "base/fs_util.hh" #include "base/paths.hh" #include "base/string_util.hh" @@ -52,19 +52,16 @@ #include "file_format.hh" #include "fmt/format.h" #include "lnav_config.hh" -#include "lnav_util.hh" #include "log_format_ext.hh" #include "sql_util.hh" #include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp_def.hh" -using namespace std; - static void extract_metadata(const char* contents, size_t len, struct script_metadata& meta_out); -typedef map> +typedef std::map> log_formats_map_t; static auto intern_lifetime = intern_string::get_table_lifetime(); @@ -72,7 +69,7 @@ static log_formats_map_t LOG_FORMATS; struct userdata { ghc::filesystem::path ud_format_path; - vector* ud_format_names{nullptr}; + std::vector* ud_format_names{nullptr}; std::vector* ud_errors{nullptr}; }; @@ -80,7 +77,7 @@ static external_log_format* ensure_format(const yajlpp_provider_context& ypc, userdata* ud) { const intern_string_t name = ypc.get_substr_i(0); - vector* formats = ud->ud_format_names; + std::vector* formats = ud->ud_format_names; external_log_format* retval; retval = LOG_FORMATS[name].get(); @@ -105,11 +102,11 @@ ensure_format(const yajlpp_provider_context& ypc, userdata* ud) static external_log_format::pattern* pattern_provider(const yajlpp_provider_context& ypc, external_log_format* elf) { - string regex_name = ypc.get_substr(0); + auto regex_name = ypc.get_substr(0); auto& pat = elf->elf_patterns[regex_name]; if (pat.get() == nullptr) { - pat = make_shared(); + pat = std::make_shared(); } if (pat->p_config_path.empty()) { @@ -126,10 +123,10 @@ value_def_provider(const yajlpp_provider_context& ypc, external_log_format* elf) const intern_string_t value_name = ypc.get_substr_i(0); auto iter = elf->elf_value_defs.find(value_name); - shared_ptr retval; + std::shared_ptr retval; if (iter == elf->elf_value_defs.end()) { - retval = make_shared( + retval = std::make_shared( value_name, value_kind_t::VALUE_TEXT, -1, elf); elf->elf_value_defs[value_name] = retval; elf->elf_value_def_order.emplace_back(retval); @@ -173,7 +170,7 @@ static int read_format_bool(yajlpp_parse_context* ypc, int val) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string field_name = ypc->get_path_fragment(1); + auto field_name = ypc->get_path_fragment(1); if (field_name == "convert-to-local-time") elf->lf_date_time.dts_local_time = val; @@ -193,7 +190,7 @@ static int read_format_double(yajlpp_parse_context* ypc, double val) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string field_name = ypc->get_path_fragment(1); + auto field_name = ypc->get_path_fragment(1); if (field_name == "timestamp-divisor") { if (val <= 0) { @@ -213,7 +210,7 @@ static int read_format_int(yajlpp_parse_context* ypc, long long val) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string field_name = ypc->get_path_fragment(1); + auto field_name = ypc->get_path_fragment(1); if (field_name == "timestamp-divisor") { if (val <= 0) { @@ -236,8 +233,8 @@ read_format_field(yajlpp_parse_context* ypc, { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); auto leading_slash = len > 0 && str[0] == '/'; - auto value = string((const char*) (leading_slash ? str + 1 : str), - leading_slash ? len - 1 : len); + auto value = std::string((const char*) (leading_slash ? str + 1 : str), + leading_slash ? len - 1 : len); auto field_name = ypc->get_path_fragment(1); if (field_name == "file-pattern") { @@ -286,8 +283,8 @@ static int read_levels(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string regex = string((const char*) str, len); - string level_name_or_number = ypc->get_path_fragment(2); + auto regex = std::string((const char*) str, len); + auto level_name_or_number = ypc->get_path_fragment(2); log_level_t level = string2level(level_name_or_number.c_str()); elf->elf_level_patterns[level].lp_regex = regex; @@ -298,7 +295,7 @@ static int read_level_int(yajlpp_parse_context* ypc, long long val) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string level_name_or_number = ypc->get_path_fragment(2); + auto level_name_or_number = ypc->get_path_fragment(2); log_level_t level = string2level(level_name_or_number.c_str()); elf->elf_level_pairs.emplace_back(val, level); @@ -310,9 +307,9 @@ static int read_action_def(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string action_name = ypc->get_path_fragment(2); - string field_name = ypc->get_path_fragment(3); - string val = string((const char*) str, len); + auto action_name = ypc->get_path_fragment(2); + auto field_name = ypc->get_path_fragment(3); + auto val = std::string((const char*) str, len); elf->lf_action_defs[action_name].ad_name = action_name; if (field_name == "label") @@ -325,8 +322,8 @@ static int read_action_bool(yajlpp_parse_context* ypc, int val) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string action_name = ypc->get_path_fragment(2); - string field_name = ypc->get_path_fragment(3); + auto action_name = ypc->get_path_fragment(2); + auto field_name = ypc->get_path_fragment(3); elf->lf_action_defs[action_name].ad_capture_output = val; @@ -337,9 +334,9 @@ static int read_action_cmd(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); - string action_name = ypc->get_path_fragment(2); - string field_name = ypc->get_path_fragment(3); - string val = string((const char*) str, len); + auto action_name = ypc->get_path_fragment(2); + auto field_name = ypc->get_path_fragment(3); + auto val = std::string((const char*) str, len); elf->lf_action_defs[action_name].ad_name = action_name; elf->lf_action_defs[action_name].ad_cmdline.push_back(val); @@ -368,7 +365,7 @@ read_json_constant(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { - auto val = string((const char*) str, len); + auto val = std::string((const char*) str, len); auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); ypc->ypc_array_index.back() += 1; @@ -386,7 +383,7 @@ create_search_table(yajlpp_parse_context* ypc, { auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); const intern_string_t table_name = ypc->get_path_fragment_i(2); - string regex = string((const char*) str, len); + auto regex = std::string((const char*) str, len); elf->elf_search_tables.emplace_back(table_name, regex); @@ -810,7 +807,7 @@ struct json_path_container format_handlers = { static int read_id(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { - auto file_id = string((const char*) str, len); + auto file_id = std::string((const char*) str, len); if (find(SUPPORTED_FORMAT_SCHEMAS.begin(), SUPPORTED_FORMAT_SCHEMAS.end(), @@ -927,7 +924,7 @@ format_error_reporter(const yajlpp_parse_context& ypc, std::vector load_format_file(const ghc::filesystem::path& filename, - std::vector& errors) + std::vector& errors) { std::vector retval; struct userdata ud; @@ -985,7 +982,8 @@ load_format_file(const ghc::filesystem::path& filename, } static void -load_from_path(const ghc::filesystem::path& path, std::vector& errors) +load_from_path(const ghc::filesystem::path& path, + std::vector& errors) { auto format_path = path / "formats/*/*.json"; static_root_mem gl; @@ -999,8 +997,8 @@ load_from_path(const ghc::filesystem::path& path, std::vector& errors) continue; } - string filename(gl->gl_pathv[lpc]); - vector format_list; + std::string filename(gl->gl_pathv[lpc]); + std::vector format_list; format_list = load_format_file(filename, errors); if (format_list.empty()) { @@ -1059,7 +1057,7 @@ load_formats(const std::vector& extra_paths, uint8_t mod_counter = 0; - vector> alpha_ordered_formats; + std::vector> alpha_ordered_formats; for (auto iter = LOG_FORMATS.begin(); iter != LOG_FORMATS.end(); ++iter) { auto& elf = iter->second; elf->build(errors); @@ -1096,7 +1094,7 @@ load_formats(const std::vector& extra_paths, auto& graph_ordered_formats = external_log_format::GRAPH_ORDERED_FORMATS; while (!alpha_ordered_formats.empty()) { - vector popped_formats; + std::vector popped_formats; for (auto iter = alpha_ordered_formats.begin(); iter != alpha_ordered_formats.end();) @@ -1156,7 +1154,7 @@ load_formats(const std::vector& extra_paths, static void exec_sql_in_path(sqlite3* db, const ghc::filesystem::path& path, - std::vector& errors) + std::vector& errors) { auto format_path = path / "formats/*/*.sql"; static_root_mem gl; @@ -1216,7 +1214,7 @@ extract_metadata(const char* contents, if (!meta_out.sm_synopsis.empty()) { size_t space = meta_out.sm_synopsis.find(' '); - if (space == string::npos) { + if (space == std::string::npos) { space = meta_out.sm_synopsis.size(); } meta_out.sm_name = meta_out.sm_synopsis.substr(0, space); @@ -1253,7 +1251,7 @@ find_format_in_path(const ghc::filesystem::path& path, if (glob(format_path.c_str(), 0, nullptr, gl.inout()) == 0) { for (int lpc = 0; lpc < (int) gl->gl_pathc; lpc++) { const char* filename = basename(gl->gl_pathv[lpc]); - string script_name = string(filename, strlen(filename) - 5); + auto script_name = std::string(filename, strlen(filename) - 5); struct script_metadata meta; meta.sm_path = gl->gl_pathv[lpc]; @@ -1267,7 +1265,7 @@ find_format_in_path(const ghc::filesystem::path& path, } void -find_format_scripts(const vector& extra_paths, +find_format_scripts(const std::vector& extra_paths, available_scripts& scripts) { for (const auto& extra_path : extra_paths) { diff --git a/src/log_vtab_impl.cc b/src/log_vtab_impl.cc index 05e3b3b4..1239dc4d 100644 --- a/src/log_vtab_impl.cc +++ b/src/log_vtab_impl.cc @@ -38,8 +38,6 @@ #include "yajlpp/json_op.hh" #include "yajlpp/yajlpp_def.hh" -using namespace std; - static auto intern_lifetime = intern_string::get_table_lifetime(); static struct log_cursor log_cursor_latest; @@ -106,7 +104,7 @@ log_vtab_impl::get_table_statement() for (iter = cols.begin(); iter != cols.end(); iter++) { auto_mem coldecl; auto_mem colname; - string comment; + std::string comment; require(!iter->vc_name.empty()); @@ -132,7 +130,7 @@ log_vtab_impl::get_table_statement() return oss.str(); } -pair +std::pair log_vtab_impl::logline_value_to_sqlite_type(value_kind_t kind) { int type = 0; @@ -164,7 +162,7 @@ log_vtab_impl::logline_value_to_sqlite_type(value_kind_t kind) ensure(0); break; } - return make_pair(type, subtype); + return std::make_pair(type, subtype); } struct vtab { @@ -322,7 +320,7 @@ vt_column(sqlite3_vtab_cursor* cur, sqlite3_context* ctx, int col) content_line_t cl(vt->lss->at(vc->log_cursor.lc_curr_line)); uint64_t line_number; auto ld = vt->lss->find_data(cl, line_number); - shared_ptr lf = (*ld)->get_file(); + auto lf = (*ld)->get_file(); auto ll = lf->begin() + line_number; require(col >= 0); @@ -419,8 +417,8 @@ vt_column(sqlite3_vtab_cursor* cur, sqlite3_context* ctx, int col) } else { content_line_t prev_cl( vt->lss->at(vis_line_t(vc->log_cursor.lc_curr_line - 1))); - shared_ptr prev_lf = vt->lss->find(prev_cl); - logfile::iterator prev_ll = prev_lf->begin() + prev_cl; + auto prev_lf = vt->lss->find(prev_cl); + auto prev_ll = prev_lf->begin() + prev_cl; uint64_t prev_time, curr_line_time; prev_time = prev_ll->get_time() * 1000ULL; @@ -460,8 +458,7 @@ vt_column(sqlite3_vtab_cursor* cur, sqlite3_context* ctx, int col) } case VT_COL_LOG_TAGS: { - const map& bm - = vt->lss->get_user_bookmark_metadata(); + const auto& bm = vt->lss->get_user_bookmark_metadata(); auto bm_iter = bm.find(vt->lss->at(vc->log_cursor.lc_curr_line)); if (bm_iter == bm.end() || bm_iter->second.bm_tags.empty()) { @@ -535,7 +532,7 @@ vt_column(sqlite3_vtab_cursor* cur, sqlite3_context* ctx, int col) break; } case 1: { - const string& fn = lf->get_filename(); + const auto& fn = lf->get_filename(); sqlite3_result_text( ctx, fn.c_str(), fn.length(), SQLITE_STATIC); @@ -984,7 +981,7 @@ vt_update(sqlite3_vtab* tab, bookmark_metadata tmp_bm; if (log_tags) { - vector errors; + std::vector errors; yajlpp_parse_context ypc(log_vtab_data.lvd_source, &tags_handler); auto_mem handle(yajl_free); @@ -995,8 +992,8 @@ vt_update(sqlite3_vtab* tab, .with_error_reporter([](const yajlpp_parse_context& ypc, lnav_log_level_t level, const char* msg) { - vector& errors - = *((vector*) ypc.ypc_userdata); + auto& errors + = *((std::vector*) ypc.ypc_userdata); errors.emplace_back(msg); }) .with_obj(tmp_bm); @@ -1026,12 +1023,12 @@ vt_update(sqlite3_vtab* tab, vt->tc->set_user_mark(&textview_curses::BM_META, vrowid, true); if (part_name) { - line_meta.bm_name = string((const char*) part_name); + line_meta.bm_name = std::string((const char*) part_name); } else { line_meta.bm_name.clear(); } if (log_comment) { - line_meta.bm_comment = string((const char*) log_comment); + line_meta.bm_comment = std::string((const char*) log_comment); } else { line_meta.bm_comment.clear(); } @@ -1125,10 +1122,10 @@ log_vtab_manager::~log_vtab_manager() } } -string +std::string log_vtab_manager::register_vtab(std::shared_ptr vi) { - string retval; + std::string retval; if (this->vm_impls.find(vi->get_name()) == this->vm_impls.end()) { auto_mem errmsg; @@ -1153,10 +1150,10 @@ log_vtab_manager::register_vtab(std::shared_ptr vi) return retval; } -string +std::string log_vtab_manager::unregister_vtab(intern_string_t name) { - string retval; + std::string retval; if (this->vm_impls.find(name) == this->vm_impls.end()) { retval = fmt::format(FMT_STRING("unknown log line table -- {}"), name); diff --git a/src/logfile.cc b/src/logfile.cc index f5fa6035..90b1b34a 100644 --- a/src/logfile.cc +++ b/src/logfile.cc @@ -33,7 +33,6 @@ #include "logfile.hh" -#include #include #include #include @@ -51,8 +50,6 @@ #include "log_format.hh" #include "logfile.cfg.hh" -using namespace std; - static auto intern_lifetime = intern_string::get_table_lifetime(); static const size_t INDEX_RESERVE_INCREMENT = 1024; @@ -126,7 +123,7 @@ logfile::open(std::string filename, logfile_open_options& loo) return Ok(lf); } -logfile::logfile(string filename, logfile_open_options& loo) +logfile::logfile(std::string filename, logfile_open_options& loo) : lf_filename(std::move(filename)), lf_options(std::move(loo)) { } @@ -195,14 +192,13 @@ logfile::process_prefix(shared_buffer_ref& sbr, const line_info& li) < injector::get() .lc_max_unrecognized_lines) { - auto& root_formats = log_format::get_root_formats(); - vector>::iterator iter; + const auto& root_formats = log_format::get_root_formats(); /* * Try each scanner until we get a match. Fortunately, all the formats * are sufficiently different that there are no ambiguities... */ - for (iter = root_formats.begin(); + for (auto iter = root_formats.begin(); iter != root_formats.end() && (found != log_format::SCAN_MATCH); ++iter) { @@ -647,7 +643,7 @@ logfile::read_line(logfile::iterator ll) return sbr; }); } catch (line_buffer::error& e) { - return Err(string(strerror(e.e_err))); + return Err(std::string(strerror(e.e_err))); } } @@ -792,7 +788,7 @@ logfile::find_from_time(const timeval& tv) const } void -logfile::mark_as_duplicate(const string& name) +logfile::mark_as_duplicate(const std::string& name) { this->lf_indexing = false; this->lf_options.loo_is_visible = false; diff --git a/src/logfile.hh b/src/logfile.hh index 0648333c..b76ae9d3 100644 --- a/src/logfile.hh +++ b/src/logfile.hh @@ -1,3 +1,4 @@ + /** * Copyright (c) 2007-2012, Timothy Stack * diff --git a/src/logfile_fwd.hh b/src/logfile_fwd.hh index 8bd01413..4ea8fea0 100644 --- a/src/logfile_fwd.hh +++ b/src/logfile_fwd.hh @@ -35,7 +35,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "file_format.hh" using ui_clock = std::chrono::steady_clock; @@ -52,20 +52,51 @@ enum class logfile_name_source { REMOTE, }; -struct logfile_open_options { +struct logfile_open_options_base { + std::string loo_filename; + logfile_name_source loo_source{logfile_name_source::USER}; + bool loo_temp_file{false}; + dev_t loo_temp_dev{0}; + ino_t loo_temp_ino{0}; + bool loo_detect_format{true}; + bool loo_include_in_session{true}; + bool loo_is_visible{true}; + bool loo_non_utf_is_visible{true}; + ssize_t loo_visible_size_limit{-1}; + bool loo_tail{true}; + file_format_t loo_file_format{file_format_t::UNKNOWN}; +}; + +struct logfile_open_options : public logfile_open_options_base { + logfile_open_options() = default; + + explicit logfile_open_options(const logfile_open_options_base& base) + : logfile_open_options_base(base) + { + } + logfile_open_options& with_filename(const std::string& val) { this->loo_filename = val; return *this; - }; + } logfile_open_options& with_fd(auto_fd fd) { this->loo_fd = std::move(fd); + this->loo_temp_file = true; return *this; - }; + } + + logfile_open_options& with_stat_for_temp(const struct stat& st) + { + this->loo_temp_dev = st.st_dev; + this->loo_temp_ino = st.st_ino; + + return *this; + } logfile_open_options& with_source(logfile_name_source src) { @@ -79,7 +110,7 @@ struct logfile_open_options { this->loo_detect_format = val; return *this; - }; + } logfile_open_options& with_include_in_session(bool val) { @@ -123,16 +154,7 @@ struct logfile_open_options { return *this; } - std::string loo_filename; auto_fd loo_fd; - logfile_name_source loo_source{logfile_name_source::USER}; - bool loo_detect_format{true}; - bool loo_include_in_session{true}; - bool loo_is_visible{true}; - bool loo_non_utf_is_visible{true}; - ssize_t loo_visible_size_limit{-1}; - bool loo_tail{true}; - file_format_t loo_file_format{file_format_t::UNKNOWN}; }; #endif diff --git a/src/logfile_sub_source.cc b/src/logfile_sub_source.cc index 0b6573a2..2b17db4a 100644 --- a/src/logfile_sub_source.cc +++ b/src/logfile_sub_source.cc @@ -46,8 +46,6 @@ #include "sql_util.hh" #include "yajlpp/yajlpp.hh" -using namespace std; - const bookmark_type_t logfile_sub_source::BM_ERRORS("error"); const bookmark_type_t logfile_sub_source::BM_WARNINGS("warning"); const bookmark_type_t logfile_sub_source::BM_FILES(""); @@ -77,19 +75,19 @@ pretty_sql_callback(exec_context& ec, sqlite3_stmt* stmt) return 0; } -static future -pretty_pipe_callback(exec_context& ec, const string& cmdline, auto_fd& fd) +static std::future +pretty_pipe_callback(exec_context& ec, const std::string& cmdline, auto_fd& fd) { auto retval = std::async(std::launch::async, [&]() { char buffer[1024]; - ostringstream ss; + std::ostringstream ss; ssize_t rc; while ((rc = read(fd, buffer, sizeof(buffer))) > 0) { ss.write(buffer, rc); } - string retval = ss.str(); + auto retval = ss.str(); if (endswith(retval, "\n")) { retval.resize(retval.length() - 1); @@ -109,11 +107,11 @@ logfile_sub_source::logfile_sub_source() this->clear_min_max_log_times(); } -shared_ptr +std::shared_ptr logfile_sub_source::find(const char* fn, content_line_t& line_base) { iterator iter; - shared_ptr retval = nullptr; + std::shared_ptr retval = nullptr; line_base = content_line_t(0); for (iter = this->lss_files.begin(); @@ -153,7 +151,7 @@ logfile_sub_source::find_from_time(const struct timeval& start) const void logfile_sub_source::text_value_for_line(textview_curses& tc, int row, - string& value_out, + std::string& value_out, line_flags_t flags) { content_line_t line(0); @@ -164,7 +162,7 @@ logfile_sub_source::text_value_for_line(textview_curses& tc, line = this->at(vis_line_t(row)); if (flags & RF_RAW) { - shared_ptr lf = this->find(line); + auto lf = this->find(line); value_out = lf->read_line(lf->begin() + line) .map([](auto sbr) { return to_string(sbr); }) .unwrapOr({}); @@ -221,10 +219,10 @@ logfile_sub_source::text_value_for_line(textview_curses& tc, if (flags & RF_REWRITE) { exec_context ec( &this->lss_token_values, pretty_sql_callback, pretty_pipe_callback); - string rewritten_line; + std::string rewritten_line; ec.with_perms(exec_context::perm_t::READ_ONLY); - ec.ec_local_vars.push(map()); + ec.ec_local_vars.push(std::map()); ec.ec_top_line = vis_line_t(row); add_ansi_vars(ec.ec_global_vars); add_global_vars(ec); @@ -438,8 +436,9 @@ logfile_sub_source::text_attrs_for_line(textview_curses& lv, bookmark_vector& bv_search = bm[&textview_curses::BM_SEARCH]; - if (binary_search( - ::begin(bv_search), ::end(bv_search), vis_line_t(row))) { + if (binary_search(std::begin(bv_search), + std::end(bv_search), + vis_line_t(row))) { lr.lr_start = 0; lr.lr_end = 1; value_out.emplace_back(lr, &view_curses::VC_STYLE, A_REVERSE); @@ -503,6 +502,9 @@ logfile_sub_source::text_attrs_for_line(textview_curses& lv, value_out.emplace_back( lr, &SA_FORMAT, this->lss_token_file->get_format()->get_name()); + value_out.emplace_back( + lr, SA_FORMAT2.value(this->lss_token_file->get_format()->get_name())); + { const auto& bv = lv.get_bookmarks()[&textview_curses::BM_META]; bookmark_vector::const_iterator bv_iter; @@ -779,10 +781,10 @@ logfile_sub_source::rebuild_index( remaining += lf->size() - ld.ld_lines_indexed; } - auto row_iter = lower_bound(this->lss_index.begin(), - this->lss_index.end(), - *lowest_tv, - logline_cmp(*this)); + auto row_iter = std::lower_bound(this->lss_index.begin(), + this->lss_index.end(), + *lowest_tv, + logline_cmp(*this)); this->lss_index.shrink_to( std::distance(this->lss_index.begin(), row_iter)); log_debug("new index size %ld/%ld; remain %ld", @@ -862,7 +864,8 @@ logfile_sub_source::rebuild_index( if (this->lss_sorting_observer) { this->lss_sorting_observer(*this, 0, this->lss_index.size()); } - sort(this->lss_index.begin(), this->lss_index.end(), line_cmper); + std::sort( + this->lss_index.begin(), this->lss_index.end(), line_cmper); if (this->lss_sorting_observer) { this->lss_sorting_observer( *this, this->lss_index.size(), this->lss_index.size()); @@ -1011,7 +1014,7 @@ logfile_sub_source::rebuild_index( void logfile_sub_source::text_update_marks(vis_bookmarks& bm) { - shared_ptr last_file = nullptr; + std::shared_ptr last_file; vis_line_t vl; bm[&BM_WARNINGS].clear(); @@ -1025,9 +1028,7 @@ logfile_sub_source::text_update_marks(vis_bookmarks& bm) for (; vl < (int) this->lss_filtered_index.size(); ++vl) { const content_line_t orig_cl = this->at(vl); content_line_t cl = orig_cl; - shared_ptr lf; - - lf = this->find(cl); + auto lf = this->find(cl); for (auto& lss_user_mark : this->lss_user_marks) { if (binary_search(lss_user_mark.second.begin(), @@ -1201,15 +1202,16 @@ logfile_sub_source::list_input_handle_key(listview_curses& lv, int ch) } nonstd::optional< - pair*, grep_proc_sink*>> + std::pair*, grep_proc_sink*>> logfile_sub_source::get_grepper() { - return make_pair((grep_proc_source*) &this->lss_meta_grepper, - (grep_proc_sink*) &this->lss_meta_grepper); + return std::make_pair( + (grep_proc_source*) &this->lss_meta_grepper, + (grep_proc_sink*) &this->lss_meta_grepper); } bool -logfile_sub_source::insert_file(const shared_ptr& lf) +logfile_sub_source::insert_file(const std::shared_ptr& lf) { iterator existing; @@ -1368,7 +1370,7 @@ logfile_sub_source::eval_sql_filter(sqlite3_stmt* stmt, lf->read_full_message(ll, sbr); auto format = lf->get_format(); string_attrs_t sa; - vector values; + std::vector values; format->annotate(std::distance(lf->cbegin(), ll), sbr, sa, values); sqlite3_reset(stmt); @@ -1829,7 +1831,7 @@ sql_filter::to_command() const bool logfile_sub_source::meta_grepper::grep_value_for_line(vis_line_t line, - string& value_out) + std::string& value_out) { content_line_t cl = this->lmg_source.at(vis_line_t(line)); std::map& user_mark_meta diff --git a/src/network-extension-functions.cc b/src/network-extension-functions.cc index cd5f1225..fe8ada3a 100644 --- a/src/network-extension-functions.cc +++ b/src/network-extension-functions.cc @@ -41,9 +41,7 @@ #include "sqlite3.h" #include "vtab_module.hh" -using namespace std; - -static string +static std::string sql_gethostbyname(const char* name_in) { char buffer[INET6_ADDRSTRLEN]; @@ -84,7 +82,7 @@ sql_gethostbyname(const char* name_in) return buffer; } -static string +static std::string sql_gethostbyaddr(const char* addr_str) { union { diff --git a/src/papertrail_proc.hh b/src/papertrail_proc.hh index 3e3bc79b..78e68b08 100644 --- a/src/papertrail_proc.hh +++ b/src/papertrail_proc.hh @@ -45,8 +45,8 @@ # include # include -# include "auto_fd.hh" # include "auto_mem.hh" +# include "base/auto_fd.hh" # include "curl_looper.hh" # include "line_buffer.hh" # include "yajlpp/yajlpp.hh" @@ -117,7 +117,7 @@ public: auto_fd copy_fd() const { - return this->ptp_fd; + return this->ptp_fd.dup(); }; long complete(CURLcode result); diff --git a/src/pcap_manager.cc b/src/pcap_manager.cc index 750cf049..54449319 100644 --- a/src/pcap_manager.cc +++ b/src/pcap_manager.cc @@ -59,7 +59,7 @@ convert(const std::string& filename) auto dev_null = open("/dev/null", O_RDONLY); dup2(dev_null, STDIN_FILENO); - dup2(outfile.second, STDOUT_FILENO); + dup2(outfile.second.release(), STDOUT_FILENO); setenv("TZ", "UTC", 1); const char* args[] = { @@ -131,7 +131,7 @@ convert(const std::string& filename) return Ok(convert_result{ std::move(child), - auto_fd(outfile.second), + std::move(outfile.second), error_queue, }); } diff --git a/src/pcap_manager.hh b/src/pcap_manager.hh index f59937a9..319dfdc1 100644 --- a/src/pcap_manager.hh +++ b/src/pcap_manager.hh @@ -35,7 +35,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "base/auto_pid.hh" #include "base/result.h" diff --git a/src/pcrepp/pcrepp.cc b/src/pcrepp/pcrepp.cc index 795d3cec..5e8f8bc1 100644 --- a/src/pcrepp/pcrepp.cc +++ b/src/pcrepp/pcrepp.cc @@ -31,8 +31,6 @@ #include "pcrepp.hh" -using namespace std; - const int JIT_STACK_MIN_SIZE = 32 * 1024; const int JIT_STACK_MAX_SIZE = 512 * 1024; @@ -87,7 +85,7 @@ void pcrepp::find_captures(const char* pattern) { bool in_class = false, in_escape = false, in_literal = false; - vector cap_in_progress; + std::vector cap_in_progress; for (int lpc = 0; pattern[lpc]; lpc++) { if (in_escape) { diff --git a/src/piper_proc.cc b/src/piper_proc.cc index 1610021c..3b14f6c6 100644 --- a/src/piper_proc.cc +++ b/src/piper_proc.cc @@ -45,8 +45,6 @@ #include "config.h" #include "line_buffer.hh" -using namespace std; - static const char* STDIN_EOF_MSG = "---- END-OF-STDIN ----"; static ssize_t @@ -64,10 +62,11 @@ write_timestamp(int fd, off_t woff) return pwrite(fd, time_str, strlen(time_str), woff); } -piper_proc::piper_proc(int pipefd, bool timestamp, int filefd) - : pp_fd(filefd), pp_child(-1) +piper_proc::piper_proc(auto_fd pipefd, bool timestamp, auto_fd filefd) + : pp_fd(std::move(filefd)), pp_child(-1) { - require(pipefd >= 0); + require(pipefd.get() >= 0); + require(this->pp_fd.get() >= 0); log_perror(fcntl(this->pp_fd.get(), F_SETFD, FD_CLOEXEC)); @@ -77,7 +76,6 @@ piper_proc::piper_proc(int pipefd, bool timestamp, int filefd) throw error(errno); case 0: { - auto_fd infd(pipefd); line_buffer lb; off_t woff = 0, last_woff = 0; file_range last_range; @@ -101,8 +99,8 @@ piper_proc::piper_proc(int pipefd, bool timestamp, int filefd) close(fd_to_close); } } - log_perror(fcntl(infd.get(), F_SETFL, O_NONBLOCK)); - lb.set_fd(infd); + log_perror(fcntl(pipefd.get(), F_SETFL, O_NONBLOCK)); + lb.set_fd(pipefd); do { struct pollfd pfd = {lb.get_fd(), POLLIN, 0}; diff --git a/src/piper_proc.hh b/src/piper_proc.hh index 093bddac..4c352fea 100644 --- a/src/piper_proc.hh +++ b/src/piper_proc.hh @@ -36,7 +36,7 @@ #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" /** * Creates a subprocess that reads data from a pipe and writes it to a file so @@ -62,7 +62,7 @@ public: * the lines read from pipefd. * @param filefd The descriptor for the backing file. */ - piper_proc(int pipefd, bool timestamp, int filefd); + piper_proc(auto_fd pipefd, bool timestamp, auto_fd filefd); bool has_exited(); @@ -74,7 +74,7 @@ public: /** @return The file descriptor for the temporary file. */ auto_fd get_fd() { - return std::move(this->pp_fd); + return this->pp_fd.dup(); }; pid_t get_child_pid() const diff --git a/src/readline_callbacks.cc b/src/readline_callbacks.cc index f1353f45..3cb9b951 100644 --- a/src/readline_callbacks.cc +++ b/src/readline_callbacks.cc @@ -49,8 +49,6 @@ #include "vtab_module.hh" #include "yajlpp/yajlpp.hh" -using namespace std; - #define ABORT_MSG "(Press " ANSI_BOLD("CTRL+]") " to abort)" #define STR_HELPER(x) #x @@ -179,10 +177,10 @@ rl_sql_help(readline_curses* rc) for (const auto& ht : avail_help) { format_help_text_for_term( - *ht, min(70UL, doc_width), doc_al, help_count > 1); + *ht, std::min(70UL, doc_width), doc_al, help_count > 1); if (help_count == 1) { format_example_text_for_term( - *ht, eval_example, min(70UL, ex_width), ex_al); + *ht, eval_example, std::min(70UL, ex_width), ex_al); } } @@ -204,7 +202,7 @@ rl_sql_help(readline_curses* rc) auto intern_ident = intern_string::lookup(ident); auto vtab = lnav_data.ld_vtab_manager->lookup_impl(intern_ident); auto vtab_module_iter = vtab_module_ddls.find(intern_ident); - string ddl; + std::string ddl; if (vtab != nullptr) { ddl = trim(vtab->get_table_statement()); @@ -250,11 +248,11 @@ rl_change(readline_curses* rc) switch (lnav_data.ld_mode) { case LNM_COMMAND: { - static string last_command; + static std::string last_command; static int generation = 0; - string line = rc->get_line_buffer(); - vector args; + const auto line = rc->get_line_buffer(); + std::vector args; auto iter = lnav_commands.end(); split_ws(line, args); @@ -336,7 +334,7 @@ rl_change(readline_curses* rc) attr_line_t al; dtc.get_dimensions(height, width); - format_help_text_for_term(ht, min(70UL, width), al); + format_help_text_for_term(ht, std::min(70UL, width), al); lnav_data.ld_doc_source.replace_with(al); dtc.set_needs_update(); @@ -349,7 +347,7 @@ rl_change(readline_curses* rc) if (cmd.c_prompt != nullptr && generation == 0 && trim(line) == args[0]) { - string new_prompt + const auto new_prompt = cmd.c_prompt(lnav_data.ld_exec_context, line); if (!new_prompt.empty()) { @@ -363,9 +361,9 @@ rl_change(readline_curses* rc) break; } case LNM_EXEC: { - string line = rc->get_line_buffer(); + const auto line = rc->get_line_buffer(); size_t name_end = line.find(' '); - string script_name = line.substr(0, name_end); + const auto script_name = line.substr(0, name_end); auto& scripts = injector::get(); auto iter = scripts.as_scripts.find(script_name); @@ -395,8 +393,8 @@ static void rl_search_internal(readline_curses* rc, ln_mode_t mode, bool complete = false) { textview_curses* tc = get_textview_for_mode(mode); - string term_val; - string name; + std::string term_val; + std::string name; tc->get_highlights().erase({highlight_source_t::PREVIEW, "preview"}); tc->get_highlights().erase({highlight_source_t::PREVIEW, "bodypreview"}); @@ -520,7 +518,7 @@ lnav_rl_abort(readline_curses* rc) tc->get_highlights().erase({highlight_source_t::PREVIEW, "bodypreview"}); lnav_data.ld_log_source.set_preview_sql_filter(nullptr); - vector errors; + std::vector errors; lnav_config = rollback_lnav_config; reload_config(errors); @@ -545,7 +543,7 @@ rl_callback_int(readline_curses* rc, bool is_alt) { textview_curses* tc = get_textview_for_mode(lnav_data.ld_mode); exec_context& ec = lnav_data.ld_exec_context; - string alt_msg; + std::string alt_msg; lnav_data.ld_bottom_source.set_prompt(""); lnav_data.ld_doc_source.clear(); @@ -649,7 +647,7 @@ rl_callback_int(readline_curses* rc, bool is_alt) case LNM_SQL: { auto result = execute_sql(ec, rc->get_value(), alt_msg); db_label_source& dls = lnav_data.ld_db_row_source; - string prompt; + std::string prompt; if (result.isOk()) { auto msg = result.unwrap(); @@ -675,24 +673,25 @@ rl_callback_int(readline_curses* rc, bool is_alt) tmpout = std::tmpfile(); if (!tmpout) { - rc->set_value("Unable to open temporary output file: " - + string(strerror(errno))); + rc->set_value(fmt::format( + FMT_STRING("Unable to open temporary output file: {}"), + strerror(errno))); } else { auto fd_copy = auto_fd::dup_of(fileno(tmpout)); char desc[256], timestamp[32]; time_t current_time = time(nullptr); - string path_and_args = rc->get_value(); + const auto path_and_args = rc->get_value(); { exec_context::output_guard og( ec, "tmp", std::make_pair(tmpout.release(), fclose)); - string result = execute_file(ec, path_and_args) - .map(ok_prefix) - .orElse(err_to_ok) - .unwrap(); - string::size_type lf_index = result.find('\n'); - if (lf_index != string::npos) { + auto result = execute_file(ec, path_and_args) + .map(ok_prefix) + .orElse(err_to_ok) + .unwrap(); + auto lf_index = result.find('\n'); + if (lf_index != std::string::npos) { result = result.substr(0, lf_index); } rc->set_value(result); @@ -711,7 +710,7 @@ rl_callback_int(readline_curses* rc, bool is_alt) path_and_args.c_str(), timestamp); lnav_data.ld_active_files.fc_file_names[desc] - .with_fd(fd_copy) + .with_fd(std::move(fd_copy)) .with_include_in_session(false) .with_detect_format(false); lnav_data.ld_files_to_front.emplace_back(desc, 0); @@ -751,12 +750,12 @@ rl_display_matches(readline_curses* rc) getmaxyx(lnav_data.ld_window, height, width); max_len = rc->get_max_match_length() + 2; - cols = max(1UL, width / max_len); + cols = std::max(1UL, width / max_len); if (matches.empty()) { lnav_data.ld_match_source.clear(); } else { - string current_match = rc->get_match_string(); + const auto current_match = rc->get_match_string(); int curr_col = 0; attr_line_t al; bool add_nl = false; diff --git a/src/readline_curses.cc b/src/readline_curses.cc index cfd38d19..b4d4f7e2 100644 --- a/src/readline_curses.cc +++ b/src/readline_curses.cc @@ -66,8 +66,6 @@ #include "shlex.hh" #include "spookyhash/SpookyV2.h" -using namespace std; - static int got_line = 0; static bool alt_done = 0; static sig_atomic_t got_timeout = 0; @@ -93,8 +91,8 @@ static const char* RL_INIT[] = { }; readline_context* readline_context::loaded_context; -set* readline_context::arg_possibilities; -static string last_match_str; +std::set* readline_context::arg_possibilities; +static std::string last_match_str; static bool last_match_str_valid; static bool arg_needs_shlex; static nonstd::optional rewrite_line_start; @@ -226,9 +224,9 @@ recvstring(int sock, char* buf, size_t len) char* readline_context::completion_generator(const char* text_in, int state) { - static vector matches; + static std::vector matches; - vector long_matches; + std::vector long_matches; char* retval = nullptr; if (state == 0) { @@ -236,7 +234,7 @@ readline_context::completion_generator(const char* text_in, int state) if (arg_needs_shlex) { shlex arg_lexer(text_str); - map scope; + std::map scope; std::string result; if (arg_lexer.eval(result, scope)) { @@ -281,11 +279,11 @@ readline_context::completion_generator(const char* text_in, int state) } if (matches.empty()) { - vector> fuzzy_matches; - vector> fuzzy_long_matches; + std::vector> fuzzy_matches; + std::vector> fuzzy_long_matches; for (const auto& poss : (*arg_possibilities)) { - string poss_str = tolower(poss); + std::string poss_str = tolower(poss); int score; if (fts::fuzzy_match( @@ -372,14 +370,14 @@ readline_context::attempted_completion(const char* text, int start, int end) rl_completion_append_character = loaded_context->rc_append_character; } else { char* space; - string cmd; - vector prefix; + std::string cmd; + std::vector prefix; int point = rl_point; while (point > 0 && rl_line_buffer[point] != ' ') { point -= 1; } shlex lexer(rl_line_buffer, point); - map scope; + std::map scope; arg_possibilities = nullptr; rl_completion_append_character = 0; @@ -400,7 +398,7 @@ readline_context::attempted_completion(const char* text, int start, int end) if (space == nullptr) { space = rl_line_buffer + strlen(rl_line_buffer); } - cmd = string(rl_line_buffer, space - rl_line_buffer); + cmd = std::string(rl_line_buffer, space - rl_line_buffer); auto iter = loaded_context->rc_prototypes.find(cmd); @@ -414,7 +412,8 @@ readline_context::attempted_completion(const char* text, int start, int end) = loaded_context->rc_append_character; } } else { - vector& proto = loaded_context->rc_prototypes[cmd]; + std::vector& proto + = loaded_context->rc_prototypes[cmd]; if (proto.empty()) { arg_possibilities = nullptr; @@ -428,7 +427,7 @@ readline_context::attempted_completion(const char* text, int start, int end) const auto& last_fn = fn_list.size() <= 1 ? "" : fn_list.back(); - if (last_fn.find(':') != string::npos) { + if (last_fn.find(':') != std::string::npos) { auto rp_iter = loaded_context->rc_possibilities.find( "remote-path"); if (rp_iter != loaded_context->rc_possibilities.end()) { @@ -630,7 +629,7 @@ readline_curses::store_matches(char** matches, int num_matches, int max_len) max_len = 0; for (int lpc = 0; lpc <= num_matches; lpc++) { - max_len = max(max_len, (int) strlen(matches[lpc])); + max_len = std::max(max_len, (int) strlen(matches[lpc])); } if (last_match_str_valid && strcmp(last_match_str.c_str(), matches[0]) == 0) @@ -742,7 +741,7 @@ readline_curses::start() child_this = this; } - map::iterator current_context; + std::map::iterator current_context; int maxfd; require(!this->rc_contexts.empty()); @@ -751,7 +750,7 @@ readline_curses::start() current_context = this->rc_contexts.end(); - maxfd = max(STDIN_FILENO, this->rc_command_pipe[RCF_SLAVE].get()); + maxfd = std::max(STDIN_FILENO, this->rc_command_pipe[RCF_SLAVE].get()); while (looping) { fd_set ready_rfds; @@ -928,8 +927,9 @@ readline_curses::start() { require(this->rc_contexts[context] != nullptr); - this->rc_contexts[context]->rc_prefixes[string(type)] - = string(&msg[prompt_start]); + this->rc_contexts[context] + ->rc_prefixes[std::string(type)] + = std::string(&msg[prompt_start]); } else if (sscanf(msg, "ap:%d:%31[^:]:%n", &context, @@ -939,7 +939,7 @@ readline_curses::start() require(this->rc_contexts[context] != nullptr); this->rc_contexts[context]->add_possibility( - string(type), string(&msg[prompt_start])); + std::string(type), std::string(&msg[prompt_start])); if (rl_last_func == rl_complete || rl_last_func == rl_menu_complete) { rl_last_func = NULL; @@ -953,7 +953,7 @@ readline_curses::start() require(this->rc_contexts[context] != nullptr); this->rc_contexts[context]->rem_possibility( - string(type), string(&msg[prompt_start])); + std::string(type), std::string(&msg[prompt_start])); } else if (sscanf(msg, "cpre:%d", &context) == 1) { this->rc_contexts[context]->rc_prefixes.clear(); } else if (sscanf(msg, "cp:%d:%s", &context, type)) { @@ -1083,7 +1083,7 @@ readline_curses::line_ready(const char* line) } void -readline_curses::check_poll_set(const vector& pollfds) +readline_curses::check_poll_set(const std::vector& pollfds) { int rc; @@ -1106,7 +1106,7 @@ readline_curses::check_poll_set(const vector& pollfds) rc = recvstring( this->rc_command_pipe[RCF_MASTER], msg, sizeof(msg) - 1); if (rc >= 0) { - string old_value = this->rc_value; + std::string old_value = this->rc_value; msg[rc] = '\0'; if (this->rc_matches_remaining > 0) { @@ -1148,7 +1148,7 @@ readline_curses::check_poll_set(const vector& pollfds) case 't': case 'd': case 'D': - this->rc_value = string(&msg[2]); + this->rc_value = std::string(&msg[2]); break; } switch (msg[0]) { @@ -1273,8 +1273,8 @@ readline_curses::abort() void readline_curses::add_prefix(int context, - const vector& prefix, - const string& value) + const std::vector& prefix, + const std::string& value) { char buffer[1024]; auto prefix_wire = fmt::format(FMT_STRING("{}"), fmt::join(prefix, "\x1f")); @@ -1309,8 +1309,8 @@ readline_curses::clear_prefixes(int context) void readline_curses::add_possibility(int context, - const string& type, - const string& value) + const std::string& type, + const std::string& value) { char buffer[1024]; @@ -1334,8 +1334,8 @@ readline_curses::add_possibility(int context, void readline_curses::rem_possibility(int context, - const string& type, - const string& value) + const std::string& type, + const std::string& value) { char buffer[1024]; @@ -1354,7 +1354,7 @@ readline_curses::rem_possibility(int context, } void -readline_curses::clear_possibilities(int context, string type) +readline_curses::clear_possibilities(int context, std::string type) { char buffer[1024]; @@ -1432,9 +1432,9 @@ readline_curses::do_update() std::string readline_curses::get_match_string() const { - auto len = ::min((size_t) this->vc_x, this->rc_line_buffer.size()) + auto len = std::min((size_t) this->vc_x, this->rc_line_buffer.size()) - this->rc_match_start; - auto context = this->get_active_context(); + auto* context = this->get_active_context(); if (context->get_append_character() != 0) { if (this->rc_line_buffer.length() > (this->rc_match_start + len - 1) diff --git a/src/readline_curses.hh b/src/readline_curses.hh index 2a1974d7..bc29303d 100644 --- a/src/readline_curses.hh +++ b/src/readline_curses.hh @@ -52,7 +52,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "base/func_util.hh" #include "base/result.h" #include "help_text_formatter.hh" diff --git a/src/readline_highlighters.cc b/src/readline_highlighters.cc index 105d8a56..944da6ef 100644 --- a/src/readline_highlighters.cc +++ b/src/readline_highlighters.cc @@ -38,12 +38,10 @@ #include "sql_help.hh" #include "sql_util.hh" -using namespace std; - static void readline_sqlite_highlighter_int(attr_line_t& al, int x, int skip); static bool -check_re_prev(const string& line, int x) +check_re_prev(const std::string& line, int x) { bool retval = false; @@ -58,7 +56,7 @@ check_re_prev(const string& line, int x) } static bool -is_bracket(const string& str, int index, bool is_lit) +is_bracket(const std::string& str, int index, bool is_lit) { if (is_lit && str[index - 1] == '\\') { return true; @@ -78,7 +76,7 @@ find_matching_bracket(attr_line_t& al, int x, char left, char right) int missing_bracket_attrs = A_BOLD | A_REVERSE | vc.attrs_for_role(view_colors::VCR_ERROR); bool is_lit = (left == 'Q'); - const string& line = al.get_string(); + const std::string& line = al.get_string(); int depth = 0; if (x < 0 || x > (int) line.length()) { @@ -150,7 +148,7 @@ find_matching_bracket(attr_line_t& al, int x, char left, char right) } static char -safe_read(const string& str, string::size_type index) +safe_read(const std::string& str, std::string::size_type index) { if (index < str.length()) { return str.at(index); @@ -178,7 +176,7 @@ readline_regex_highlighter_int(attr_line_t& al, int x, int skip) nullptr}; - string& line = al.get_string(); + auto& line = al.get_string(); bool backslash_is_quoted = false; for (size_t lpc = skip; lpc < line.length(); lpc++) { @@ -345,14 +343,14 @@ readline_command_highlighter(attr_line_t& al, int x) view_colors& vc = view_colors::singleton(); int keyword_attrs = (A_BOLD | vc.attrs_for_role(view_colors::VCR_KEYWORD)); - const string& line = al.get_string(); + const auto& line = al.get_string(); pcre_context_static<30> pc; pcre_input pi(line); size_t ws_index; ws_index = line.find(' '); - string command = line.substr(0, ws_index); - if (ws_index != string::npos) { + auto command = line.substr(0, ws_index); + if (ws_index != std::string::npos) { al.get_attrs().emplace_back( line_range(1, ws_index), &view_curses::VC_STYLE, keyword_attrs); } @@ -372,7 +370,7 @@ readline_command_highlighter(attr_line_t& al, int x) pi.reset(line); if (COLOR_RE.match(pc, pi)) { pcre_context::capture_t* cap = pc[0]; - string hash_color = pi.get_substr(cap); + auto hash_color = pi.get_substr(cap); styling::color_unit::from_str(hash_color) .then([&](const auto& rgb_fg) { @@ -384,7 +382,7 @@ readline_command_highlighter(attr_line_t& al, int x) } } pi.reset(line); - if (IDENT_PREFIXES.match(pc, pi) && ws_index != string::npos) { + if (IDENT_PREFIXES.match(pc, pi) && ws_index != std::string::npos) { size_t start = ws_index, last; do { @@ -398,7 +396,7 @@ readline_command_highlighter(attr_line_t& al, int x) }; if (lr.length() > 0 && !lr.contains(x) && !lr.contains(x - 1)) { - string value(lr.substr(line), lr.sublen(line)); + std::string value(lr.substr(line), lr.sublen(line)); if ((command == ":tag" || command == ":untag" || command == ":delete-tags") @@ -418,7 +416,7 @@ readline_command_highlighter(attr_line_t& al, int x) static void readline_sqlite_highlighter_int(attr_line_t& al, int x, int skip) { - static string keyword_re_str = sql_keyword_re(); + static const auto keyword_re_str = sql_keyword_re(); static pcrepp keyword_pcre(keyword_re_str.c_str(), PCRE_CASELESS); static pcrepp string_literal_pcre("'[^']*('(?:'[^']*')*|$)"); static pcrepp ident_pcre( @@ -526,7 +524,7 @@ readline_shlex_highlighter(attr_line_t& al, int x) int special_char = (A_BOLD | vc.attrs_for_role(view_colors::VCR_SYMBOL)); int error_attrs = vc.attrs_for_role(view_colors::VCR_ERROR) | A_REVERSE; int string_attrs = vc.attrs_for_role(view_colors::VCR_STRING); - const string& str = al.get_string(); + const auto& str = al.get_string(); pcre_context::capture_t cap; shlex_token_t token; int quote_start = -1; @@ -559,8 +557,8 @@ readline_shlex_highlighter(attr_line_t& al, int x) case shlex_token_t::ST_VARIABLE_REF: case shlex_token_t::ST_QUOTED_VARIABLE_REF: { int extra = token == shlex_token_t::ST_VARIABLE_REF ? 0 : 1; - string ident = str.substr(cap.c_begin + 1 + extra, - cap.length() - 1 - extra * 2); + auto ident = str.substr(cap.c_begin + 1 + extra, + cap.length() - 1 - extra * 2); int attrs = vc.attrs_for_ident(ident); al.with_attr(string_attr( diff --git a/src/readline_possibilities.cc b/src/readline_possibilities.cc index b142ea1d..e20889eb 100644 --- a/src/readline_possibilities.cc +++ b/src/readline_possibilities.cc @@ -47,8 +47,6 @@ #include "tailer/tailer.looper.hh" #include "yajlpp/yajlpp_def.hh" -using namespace std; - static int handle_collation_list(void* ptr, int ncols, char** colvalues, char** colnames) { @@ -73,7 +71,7 @@ static int handle_table_list(void* ptr, int ncols, char** colvalues, char** colnames) { if (lnav_data.ld_rl_view != nullptr) { - string table_name = colvalues[0]; + std::string table_name = colvalues[0]; if (sqlite_function_help.count(table_name) == 0) { lnav_data.ld_rl_view->add_possibility(LNM_SQL, "*", colvalues[0]); @@ -93,7 +91,7 @@ handle_table_info(void* ptr, int ncols, char** colvalues, char** colnames) quoted_name = sql_quote_ident(colvalues[1]); lnav_data.ld_rl_view->add_possibility( - LNM_SQL, "*", string(quoted_name)); + LNM_SQL, "*", std::string(quoted_name)); } if (strcmp(colvalues[5], "1") == 0) { lnav_data.ld_db_key_names.emplace_back(colvalues[1]); @@ -120,7 +118,7 @@ struct sqlite_metadata_callbacks lnav_sql_meta_callbacks = { static void add_text_possibilities(readline_curses* rlc, int context, - const string& type, + const std::string& type, const std::string& str) { static const std::regex re_escape(R"(([.\^$*+?()\[\]{}\\|]))"); @@ -146,7 +144,7 @@ add_text_possibilities(readline_curses* rlc, switch (context) { case LNM_SQL: { - string token_value = ds.get_input().get_substr(pc.all()); + auto token_value = ds.get_input().get_substr(pc.all()); auto_mem quoted_token; quoted_token = sqlite3_mprintf("%Q", token_value.c_str()); @@ -154,7 +152,7 @@ add_text_possibilities(readline_curses* rlc, break; } default: { - string token_value, token_value_no_dot; + std::string token_value, token_value_no_dot; token_value_no_dot = token_value = ds.get_input().get_substr(pc.all()); @@ -184,7 +182,7 @@ add_text_possibilities(readline_curses* rlc, void add_view_text_possibilities(readline_curses* rlc, int context, - const string& type, + const std::string& type, textview_curses* tc) { text_sub_source* tss = tc->get_sub_source(); @@ -194,7 +192,7 @@ add_view_text_possibilities(readline_curses* rlc, for (vis_line_t curr_line = tc->get_top(); curr_line <= tc->get_bottom(); ++curr_line) { - string line; + std::string line; tss->text_value_for_line(*tc, curr_line, line, text_sub_source::RF_RAW); @@ -241,7 +239,7 @@ add_filter_expr_possibilities(readline_curses* rlc, auto format = lf->get_format(); shared_buffer_ref sbr; string_attrs_t sa; - vector values; + std::vector values; lf->read_full_message(ll, sbr); format->annotate(cl, sbr, sa, values); @@ -269,7 +267,7 @@ add_filter_expr_possibilities(readline_curses* rlc, str = sqlite3_mprintf( "%.*Q", lv.text_length(), lv.text_value()); - rlc->add_possibility(context, type, string(str.in())); + rlc->add_possibility(context, type, std::string(str.in())); break; } } @@ -289,7 +287,7 @@ add_filter_expr_possibilities(readline_curses* rlc, rlc->add_possibility( context, type, - string(func_def.zName) + (func_def.nArg ? "(" : "()")); + std::string(func_def.zName) + (func_def.nArg ? "(" : "()")); } for (int lpc2 = 0; agg_funcs && agg_funcs[lpc2].zName; lpc2++) { const FuncDefAgg& func_def = agg_funcs[lpc2]; @@ -297,7 +295,7 @@ add_filter_expr_possibilities(readline_curses* rlc, rlc->add_possibility( context, type, - string(func_def.zName) + (func_def.nArg ? "(" : "()")); + std::string(func_def.zName) + (func_def.nArg ? "(" : "()")); } } } @@ -310,7 +308,7 @@ add_env_possibilities(int context) for (char** var = environ; *var != nullptr; var++) { rlc->add_possibility( - context, "*", "$" + string(*var, strchr(*var, '='))); + context, "*", "$" + std::string(*var, strchr(*var, '='))); } exec_context& ec = lnav_data.ld_exec_context; @@ -400,9 +398,9 @@ void add_config_possibilities() { readline_curses* rc = lnav_data.ld_rl_view; - set visited; + std::set visited; auto cb = [rc, &visited](const json_path_handler_base& jph, - const string& path, + const std::string& path, void* mem) { if (jph.jph_children) { if (!jph.jph_regex.p_named_count) { @@ -423,14 +421,14 @@ add_config_possibilities() rc->add_possibility(LNM_COMMAND, "config-option", path); if (jph.jph_synopsis) { rc->add_prefix(LNM_COMMAND, - vector{"config", path}, + std::vector{"config", path}, jph.jph_synopsis); } } }; rc->clear_possibilities(LNM_COMMAND, "config-option"); - for (auto& jph : lnav_config_handlers.jpc_children) { + for (const auto& jph : lnav_config_handlers.jpc_children) { jph.walk(cb, &lnav_config); } } @@ -449,8 +447,7 @@ add_tag_possibilities() logfile_sub_source& lss = lnav_data.ld_log_source; if (lss.text_line_count() > 0) { content_line_t cl = lss.at(lnav_data.ld_views[LNV_LOG].get_top()); - const map& user_meta - = lss.get_user_bookmark_metadata(); + const auto& user_meta = lss.get_user_bookmark_metadata(); auto meta_iter = user_meta.find(cl); if (meta_iter != user_meta.end()) { diff --git a/src/regexp_vtab.cc b/src/regexp_vtab.cc index 45160d92..530727b0 100644 --- a/src/regexp_vtab.cc +++ b/src/regexp_vtab.cc @@ -34,8 +34,6 @@ #include "sql_util.hh" #include "vtab_module.hh" -using namespace std; - enum { RC_COL_MATCH_INDEX, RC_COL_INDEX, @@ -70,8 +68,8 @@ CREATE TABLE regexp_capture ( sqlite3_vtab_cursor base; pcrepp c_pattern; pcre_context_static<30> c_context; - unique_ptr c_input; - string c_content; + std::unique_ptr c_input; + std::string c_content; bool c_content_as_blob{false}; int c_index; int c_start_index; @@ -247,7 +245,7 @@ rcFilter(sqlite3_vtab_cursor* pVtabCursor, pCur->c_index = 0; pCur->c_context.set_count(0); - pCur->c_input = make_unique(pCur->c_content); + pCur->c_input = std::make_unique(pCur->c_content); pCur->c_matched = pCur->c_pattern.match(pCur->c_context, *(pCur->c_input)); log_debug("matched %d", pCur->c_matched); @@ -272,10 +270,11 @@ register_regexp_vtab(sqlite3* db) .with_parameter( {"string", "The string to match against the given pattern."}) .with_parameter({"pattern", "The regular expression to match."}) - .with_result( - {"match_index", - "The match iteration. This value will increase " - "each time a new match is found in the input string."}) + .with_result({ + "match_index", + "The match iteration. This value will increase " + "each time a new match is found in the input string.", + }) .with_result( {"capture_index", "The index of the capture in the regex."}) .with_result( @@ -288,10 +287,12 @@ register_regexp_vtab(sqlite3* db) "The stop of the capture in the input string."}) .with_result({"content", "The captured value from the string."}) .with_tags({"string"}) - .with_example({"To extract the key/value pairs 'a'/1 and 'b'/2 " - "from the string 'a=1; b=2'", - "SELECT * FROM regexp_capture('a=1; b=2', " - "'(\\w+)=(\\d+)')"}); + .with_example({ + "To extract the key/value pairs 'a'/1 and 'b'/2 " + "from the string 'a=1; b=2'", + "SELECT * FROM regexp_capture('a=1; b=2', " + "'(\\w+)=(\\d+)')", + }); int rc; @@ -300,7 +301,7 @@ register_regexp_vtab(sqlite3* db) rc = REGEXP_CAPTURE_MODULE.create(db, "regexp_capture"); sqlite_function_help.insert( - make_pair("regexp_capture", ®exp_capture_help)); + std::make_pair("regexp_capture", ®exp_capture_help)); regexp_capture_help.index_tags(); ensure(rc == SQLITE_OK); diff --git a/src/relative_time.cc b/src/relative_time.cc index 8436f241..e184fb8d 100644 --- a/src/relative_time.cc +++ b/src/relative_time.cc @@ -35,7 +35,6 @@ #include "config.h" #include "pcrepp/pcrepp.hh" -using namespace std; using namespace std::chrono_literals; static const struct { @@ -333,15 +332,15 @@ relative_time::from_str(const char* str, size_t len) case RTT_AT: break; case RTT_TIME: { - string hstr = pi.get_substr(pc[0]); - string mstr = pi.get_substr(pc[1]); + const auto hstr = pi.get_substr(pc[0]); + const auto mstr = pi.get_substr(pc[1]); retval.rt_field[RTF_HOURS] = atoi(hstr.c_str()); retval.rt_field[RTF_MINUTES] = atoi(mstr.c_str()); if (pc[2]->is_valid()) { - string sstr = pi.get_substr(pc[2]); + const auto sstr = pi.get_substr(pc[2]); retval.rt_field[RTF_SECONDS] = atoi(sstr.c_str()); if (pc[3]->is_valid()) { - string substr = pi.get_substr(pc[3]); + const auto substr = pi.get_substr(pc[3]); switch (substr.length()) { case 3: @@ -372,7 +371,7 @@ relative_time::from_str(const char* str, size_t len) return Err(pe_out); } - string numstr = pi.get_substr(pc[0]); + const auto numstr = pi.get_substr(pc[0]); if (sscanf(numstr.c_str(), "%" PRId64, &number) != 1) { pe_out.pe_msg = "Invalid number: " + numstr; diff --git a/src/sequence_matcher.cc b/src/sequence_matcher.cc index e3e95b12..9af0add6 100644 --- a/src/sequence_matcher.cc +++ b/src/sequence_matcher.cc @@ -32,8 +32,6 @@ #include "config.h" #include "spookyhash/SpookyV2.h" -using namespace std; - sequence_matcher::sequence_matcher(field_col_t& example) { for (field_col_t::iterator col_iter = example.begin(); @@ -63,7 +61,7 @@ sequence_matcher::sequence_matcher(field_col_t& example) } void -sequence_matcher::identity(const std::vector& values, id_t& id_out) +sequence_matcher::identity(const std::vector& values, id_t& id_out) { SpookyHash context; int lpc = 0; diff --git a/src/session_data.cc b/src/session_data.cc index 4a068ee5..4a4946d1 100644 --- a/src/session_data.cc +++ b/src/session_data.cc @@ -56,8 +56,6 @@ #include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp_def.hh" -using namespace std; - struct session_data_t session_data; static const char* LOG_METADATA_NAME = "log_metadata.db"; @@ -142,7 +140,7 @@ bind_to_sqlite(sqlite3_stmt* stmt, int index, intern_string_t ist) } int -bind_to_sqlite(sqlite3_stmt* stmt, int index, const string& str) +bind_to_sqlite(sqlite3_stmt* stmt, int index, const std::string& str) { return sqlite3_bind_text( stmt, index, str.c_str(), str.size(), SQLITE_TRANSIENT); @@ -189,9 +187,7 @@ bind_line(sqlite3* db, time_t session_time) { logfile_sub_source& lss = lnav_data.ld_log_source; - shared_ptr lf; - - lf = lss.find(cl); + auto lf = lss.find(cl); if (lf == nullptr) { return false; @@ -224,7 +220,7 @@ bind_line(sqlite3* db, } struct session_file_info { - session_file_info(int timestamp, string id, string path) + session_file_info(int timestamp, std::string id, std::string path) : sfi_timestamp(timestamp), sfi_id(std::move(id)), sfi_path(std::move(path)){}; @@ -240,8 +236,8 @@ struct session_file_info { }; int sfi_timestamp; - string sfi_id; - string sfi_path; + std::string sfi_id; + std::string sfi_path; }; static void @@ -249,7 +245,7 @@ cleanup_session_data() { static_root_mem session_file_list; std::list session_info_list; - map session_count; + std::map session_count; auto session_file_pattern = lnav::paths::dotlnav() / "*-*.ts*.json"; if (glob( @@ -492,7 +488,7 @@ load_time_bookmarks() file_iter != lnav_data.ld_log_source.end(); ++file_iter) { - shared_ptr lf = (*file_iter)->get_file(); + auto lf = (*file_iter)->get_file(); content_line_t base_content_line; if (lf == nullptr) { @@ -518,7 +514,7 @@ load_time_bookmarks() date_time_scanner dts; bool done = false; - string line; + std::string line; int64_t last_mark_time = -1; while (!done) { @@ -582,7 +578,7 @@ load_time_bookmarks() auto sbr = read_result.unwrap(); - string line_hash + auto line_hash = hasher() .update(sbr.get_data(), sbr.length()) .update(cl) @@ -681,7 +677,7 @@ load_time_bookmarks() file_iter != lnav_data.ld_log_source.end(); ++file_iter) { - shared_ptr lf = (*file_iter)->get_file(); + auto lf = (*file_iter)->get_file(); content_line_t base_content_line; if (lf == nullptr) { @@ -707,7 +703,7 @@ load_time_bookmarks() date_time_scanner dts; bool done = false; - string line; + std::string line; int64_t last_mark_time = -1; while (!done) { @@ -807,7 +803,7 @@ read_current_search(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) { - string regex = std::string((const char*) str, len); + const auto regex = std::string((const char*) str, len); const char** view_name; int view_index; @@ -1067,7 +1063,7 @@ save_user_bookmarks(sqlite3* db, return; } - string tags; + std::string tags; if (!line_meta.bm_tags.empty()) { yajlpp_gen gen; @@ -1226,7 +1222,7 @@ save_time_bookmarks() file_iter != lnav_data.ld_log_source.end(); ++file_iter) { - shared_ptr lf = (*file_iter)->get_file(); + auto lf = (*file_iter)->get_file(); if (lf == nullptr) { continue; @@ -1320,7 +1316,7 @@ save_time_bookmarks() file_iter != lnav_data.ld_log_source.end(); ++file_iter) { - shared_ptr lf = (*file_iter)->get_file(); + auto lf = (*file_iter)->get_file(); content_line_t base_content_line; if (lf == nullptr) { @@ -1366,7 +1362,7 @@ save_time_bookmarks() if (ls->get_file() == nullptr) continue; - shared_ptr lf = ls->get_file(); + auto lf = ls->get_file(); if (!lf->is_time_adjusted()) { continue; @@ -1528,7 +1524,7 @@ save_session_with_id(const std::string& session_id) yajlpp_array cmd_array(handle); for (const auto& filter : fs) { - string cmd = filter->to_command(); + auto cmd = filter->to_command(); if (cmd.empty()) { continue; @@ -1582,13 +1578,13 @@ save_session_with_id(const std::string& session_id) min_time_str, sizeof(min_time_str), min_time); if (have_min_time) { cmd_array.gen("hide-lines-before " - + string(min_time_str)); + + std::string(min_time_str)); } if (have_max_time) { sql_strftime( max_time_str, sizeof(max_time_str), max_time); cmd_array.gen("hide-lines-after " - + string(max_time_str)); + + std::string(max_time_str)); } auto mark_expr = lss.get_sql_marker_text(); diff --git a/src/sql_util.cc b/src/sql_util.cc index 495270c2..d98810af 100644 --- a/src/sql_util.cc +++ b/src/sql_util.cc @@ -51,8 +51,6 @@ #include "sql_help.hh" #include "sqlite-extension-func.hh" -using namespace std; - /** * Copied from -- http://www.sqlite.org/lang_keywords.html */ @@ -259,7 +257,7 @@ const char* sql_function_names[] = { nullptr}; -multimap sqlite_function_help; +std::multimap sqlite_function_help; static int handle_db_list(void* ptr, int ncols, char** colvalues, char** colnames) @@ -394,7 +392,7 @@ static int schema_db_list(void* ptr, int ncols, char** colvalues, char** colnames) { struct sqlite_metadata_callbacks* smc = (sqlite_metadata_callbacks*) ptr; - string& schema_out = *((string*) smc->smc_userdata); + std::string& schema_out = *((std::string*) smc->smc_userdata); auto_mem attach_sql; attach_sql = sqlite3_mprintf( @@ -409,7 +407,7 @@ static int schema_table_list(void* ptr, int ncols, char** colvalues, char** colnames) { struct sqlite_metadata_callbacks* smc = (sqlite_metadata_callbacks*) ptr; - string& schema_out = *((string*) smc->smc_userdata); + std::string& schema_out = *((std::string*) smc->smc_userdata); auto_mem create_sql; create_sql = sqlite3_mprintf("%s;\n", colvalues[1]); @@ -471,9 +469,9 @@ attach_sqlite_db(sqlite3* db, const std::string& filename) } size_t base_start = filename.find_last_of("/\\"); - string db_name; + std::string db_name; - if (base_start == string::npos) { + if (base_start == std::string::npos) { db_name = filename; } else { db_name = filename.substr(base_start + 1); @@ -634,10 +632,10 @@ sql_quote_ident(const char* ident) return retval; } -string +std::string sql_safe_ident(const string_fragment& ident) { - string retval = to_string(ident); + std::string retval = std::to_string(ident); for (size_t lpc = 0; lpc < retval.size(); lpc++) { char ch = retval[lpc]; @@ -710,7 +708,7 @@ sql_execute_script(sqlite3* db, const std::vector& stmts, std::vector& errors) { - map lvars; + std::map lvars; for (sqlite3_stmt* stmt : stmts) { bool done = false; @@ -724,7 +722,7 @@ sql_execute_script(sqlite3* db, name = sqlite3_bind_parameter_name(stmt, lpc + 1); if (name[0] == '$') { - map::iterator iter; + std::map::iterator iter; const char* env_value; if ((iter = lvars.find(&name[1])) != lvars.end()) { @@ -784,7 +782,7 @@ sql_execute_script(sqlite3* db, const char* script, std::vector& errors) { - vector stmts; + std::vector stmts; sql_compile_script(db, src_name, script, stmts, errors); if (errors.empty()) { @@ -808,11 +806,11 @@ static struct { }; int -guess_type_from_pcre(const string& pattern, std::string& collator) +guess_type_from_pcre(const std::string& pattern, std::string& collator) { try { pcrepp re(pattern); - vector matches; + std::vector matches; int retval = SQLITE3_TEXT; int index = 0; @@ -862,10 +860,10 @@ sqlite_authorizer(void* pUserData, return SQLITE_OK; } -string +std::string sql_keyword_re() { - string retval = "(?:"; + std::string retval = "(?:"; bool first = true; for (const char* kw : sql_keywords) { @@ -896,7 +894,7 @@ string_attr_type SQL_GARBAGE_ATTR("sql_garbage"); void annotate_sql_statement(attr_line_t& al) { - static string keyword_re_str = R"(\A)" + sql_keyword_re(); + static const std::string keyword_re_str = R"(\A)" + sql_keyword_re(); static struct { pcrepp re; @@ -986,12 +984,12 @@ annotate_sql_statement(attr_line_t& al) stable_sort(sa.begin(), sa.end()); } -vector +std::vector find_sql_help_for_line(const attr_line_t& al, size_t x) { - vector retval; + std::vector retval; const auto& sa = al.get_attrs(); - string name; + std::string name; x = al.nearest_text(x); @@ -999,8 +997,8 @@ find_sql_help_for_line(const attr_line_t& al, size_t x) auto sa_opt = get_string_attr(al.get_attrs(), &SQL_COMMAND_ATTR); if (sa_opt) { - auto sql_cmd_map = injector::get(); + auto* sql_cmd_map = injector::get(); auto cmd_name = al.get_substring((*sa_opt)->sa_range); auto cmd_iter = sql_cmd_map->find(cmd_name); @@ -1010,14 +1008,14 @@ find_sql_help_for_line(const attr_line_t& al, size_t x) } } - vector kw; + std::vector kw; auto iter = rfind_string_attr_if(sa, x, [&al, &name, &kw, x](auto sa) { if (sa.sa_type != &SQL_FUNCTION_ATTR && sa.sa_type != &SQL_KEYWORD_ATTR) { return false; } - const string& str = al.get_string(); + const std::string& str = al.get_string(); const line_range& lr = sa.sa_range; int lpc; @@ -1033,7 +1031,7 @@ find_sql_help_for_line(const attr_line_t& al, size_t x) } } - string tmp_name = str.substr(lr.lr_start, lpc - lr.lr_start); + auto tmp_name = str.substr(lr.lr_start, lpc - lr.lr_start); if (sa.sa_type == &SQL_KEYWORD_ATTR) { tmp_name = toupper(tmp_name); } @@ -1048,7 +1046,7 @@ find_sql_help_for_line(const attr_line_t& al, size_t x) if (iter != sa.end()) { auto func_pair = sqlite_function_help.equal_range(name); - size_t help_count = distance(func_pair.first, func_pair.second); + size_t help_count = std::distance(func_pair.first, func_pair.second); if (help_count > 1 && name != func_pair.first->second->ht_name) { while (func_pair.first != func_pair.second) { diff --git a/src/sqlite-extension-func.cc b/src/sqlite-extension-func.cc index b0bbe8ab..08dfbc54 100644 --- a/src/sqlite-extension-func.cc +++ b/src/sqlite-extension-func.cc @@ -37,8 +37,6 @@ #include "config.h" #include "sql_help.hh" -using namespace std; - extern "C" { struct sqlite3_api_routines; @@ -96,7 +94,7 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) if (fd.fd_help.ht_context != help_context_t::HC_NONE) { help_text& ht = fd.fd_help; - sqlite_function_help.insert(make_pair(ht.ht_name, &ht)); + sqlite_function_help.insert(std::make_pair(ht.ht_name, &ht)); ht.index_tags(); } } @@ -117,7 +115,7 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) if (fda.fda_help.ht_context != help_context_t::HC_NONE) { help_text& ht = fda.fda_help; - sqlite_function_help.insert(make_pair(ht.ht_name, &ht)); + sqlite_function_help.insert(std::make_pair(ht.ht_name, &ht)); ht.index_tags(); } } @@ -696,9 +694,11 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) .sql_function() .with_parameter({"X", "The values to add."}) .with_tags({"math"}) - .with_example({"To sum all of the values in the column " - "'ex_duration' from the table 'lnav_example_log'", - "SELECT sum(ex_duration) FROM lnav_example_log"}), + .with_example({ + "To sum all of the values in the column " + "'ex_duration' from the table 'lnav_example_log'", + "SELECT sum(ex_duration) FROM lnav_example_log", + }), help_text( "total", @@ -706,9 +706,11 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) .sql_function() .with_parameter({"X", "The values to add."}) .with_tags({"math"}) - .with_example({"To total all of the values in the column " - "'ex_duration' from the table 'lnav_example_log'", - "SELECT total(ex_duration) FROM lnav_example_log"}), + .with_example({ + "To total all of the values in the column " + "'ex_duration' from the table 'lnav_example_log'", + "SELECT total(ex_duration) FROM lnav_example_log", + }), help_text("generate_series", "A table-valued-function that returns the whole numbers " @@ -720,16 +722,19 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) help_text("step", "The increment between each value") .optional()) .with_result({"value", "The number in the series"}) - .with_example({"To generate the numbers in the range [10, 14]", - "SELECT value FROM generate_series(10, 14)"}) - .with_example( - {"To generate every other number in the range [10, 14]", - "SELECT value FROM generate_series(10, 14, 2)"}) + .with_example({ + "To generate the numbers in the range [10, 14]", + "SELECT value FROM generate_series(10, 14)", + }) + .with_example({ + "To generate every other number in the range [10, 14]", + "SELECT value FROM generate_series(10, 14, 2)", + }) .with_example({"To count down from five to 1", "SELECT value FROM generate_series(1, 5, -1)"})}; for (auto& ht : builtin_funcs) { - sqlite_function_help.insert(make_pair(ht.ht_name, &ht)); + sqlite_function_help.insert(std::make_pair(ht.ht_name, &ht)); ht.index_tags(); } @@ -830,7 +835,7 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) }; for (auto& ht : builtin_win_funcs) { - sqlite_function_help.insert(make_pair(ht.ht_name, &ht)); + sqlite_function_help.insert(std::make_pair(ht.ht_name, &ht)); ht.index_tags(); } @@ -995,9 +1000,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) "a row should be updated.") .with_flag_name("WHERE") .optional()) - .with_example( - {"To mark the syslog message at line 40", - "UPDATE syslog_log SET log_mark = 1 WHERE log_line = 40"}), + .with_example({ + "To mark the syslog message at line 40", + "UPDATE syslog_log SET log_mark = 1 WHERE log_line = 40", + }), help_text("CASE", "Evaluate a series of expressions in order until one " @@ -1023,9 +1029,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) .with_flag_name("ELSE") .optional()) .with_parameter(help_text("").with_flag_name("END")) - .with_example( - {"To evaluate the number one and return the string 'one'", - "SELECT CASE 1 WHEN 0 THEN 'zero' WHEN 1 THEN 'one' END"}), + .with_example({ + "To evaluate the number one and return the string 'one'", + "SELECT CASE 1 WHEN 0 THEN 'zero' WHEN 1 THEN 'one' END", + }), help_text("CAST", "Convert the value of the given expression to a different " @@ -1035,8 +1042,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) .with_parameter( help_text("type-name", "The name of the type to convert to.") .with_flag_name("AS")) - .with_example({"To cast the value 1.23 as an integer", - "SELECT CAST(1.23 AS INTEGER)"}), + .with_example({ + "To cast the value 1.23 as an integer", + "SELECT CAST(1.23 AS INTEGER)", + }), help_text("expr", "Match an expression against a glob pattern.") .sql_infix() @@ -1044,8 +1053,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) .with_parameter( help_text("pattern", "The glob pattern to match against.") .with_flag_name("GLOB")) - .with_example({"To check if a value matches the pattern '*.log'", - "SELECT 'foobar.log' GLOB '*.log'"}), + .with_example({ + "To check if a value matches the pattern '*.log'", + "SELECT 'foobar.log' GLOB '*.log'", + }), help_text("expr", "Match an expression against a text pattern.") .sql_infix() @@ -1053,9 +1064,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) .with_parameter( help_text("pattern", "The pattern to match against.") .with_flag_name("LIKE")) - .with_example( - {"To check if a value matches the pattern 'Hello, %!'", - "SELECT 'Hello, World!' LIKE 'Hello, %!'"}), + .with_example({ + "To check if a value matches the pattern 'Hello, %!'", + "SELECT 'Hello, World!' LIKE 'Hello, %!'", + }), help_text("expr", "Match an expression against a regular expression.") .sql_infix() @@ -1063,19 +1075,21 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) .with_parameter( help_text("pattern", "The regular expression to match against.") .with_flag_name("REGEXP")) - .with_example( - {"To check if a value matches the pattern 'file-\\d+'", - "SELECT 'file-23' REGEXP 'file-\\d+'"}), + .with_example({ + "To check if a value matches the pattern 'file-\\d+'", + "SELECT 'file-23' REGEXP 'file-\\d+'", + }), help_text("expr", "Assign a collating sequence to the expression.") .sql_infix() .with_parameter( help_text("collation-name", "The name of the collator.") .with_flag_name("COLLATE")) - .with_example( - {"To change the collation method for string comparisons", - "SELECT ('a2' < 'a10'), ('a2' < 'a10' COLLATE " - "naturalnocase)"}), + .with_example({ + "To change the collation method for string comparisons", + "SELECT ('a2' < 'a10'), ('a2' < 'a10' COLLATE " + "naturalnocase)", + }), help_text("expr", "Test if an expression is between two values.") .sql_infix() @@ -1084,10 +1098,14 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) help_text("low", "The low point").with_flag_name("BETWEEN")) .with_parameter( help_text("hi", "The high point").with_flag_name("AND")) - .with_example({"To check if 3 is between 5 and 10", - "SELECT 3 BETWEEN 5 AND 10"}) - .with_example({"To check if 10 is between 5 and 10", - "SELECT 10 BETWEEN 5 AND 10"}), + .with_example({ + "To check if 3 is between 5 and 10", + "SELECT 3 BETWEEN 5 AND 10", + }) + .with_example({ + "To check if 10 is between 5 and 10", + "SELECT 10 BETWEEN 5 AND 10", + }), help_text("OVER", "Executes the preceding function over a window") .sql_keyword() @@ -1096,8 +1114,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) help_text("OVER", "Executes the preceding function over a window") .sql_function() - .with_parameter(help_text{"base-window-name", - "The name of the window definition"} + .with_parameter(help_text{ + "base-window-name", + "The name of the window definition", + } .optional()) .with_parameter( help_text{"expr", "The values to use for partitioning"} @@ -1107,9 +1127,11 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs) "expr", "The values used to order the rows in the window"} .with_flag_name("ORDER BY") .zero_or_more()) - .with_parameter(help_text{"frame-spec", - "Determines which output rows are read " - "by an aggregate window function"} + .with_parameter(help_text{ + "frame-spec", + "Determines which output rows are read " + "by an aggregate window function", + } .optional()), }; diff --git a/src/statusview_curses.cc b/src/statusview_curses.cc index fb9da4b6..2e0fb466 100644 --- a/src/statusview_curses.cc +++ b/src/statusview_curses.cc @@ -36,8 +36,6 @@ #include "config.h" -using namespace std; - void status_field::set_value(std::string value) { @@ -157,7 +155,7 @@ statusview_curses::do_update() } if (val.length() > sf.get_width()) { - static const string ELLIPSIS = "\xE2\x8B\xAF"; + static const std::string ELLIPSIS = "\xE2\x8B\xAF"; if (sf.get_width() > 11) { size_t half_width = sf.get_width() / 2 - 1; @@ -196,7 +194,7 @@ statusview_curses::window_change() int total_shares = 0; unsigned long width, height; double remaining = 0; - vector resizable; + std::vector resizable; getmaxyx(this->sc_window, height, width); // Silence the compiler. Remove this if height is used at a later stage. @@ -239,6 +237,4 @@ statusview_curses::window_change() sf->set_width(actual_width); } - - this->sc_last_width = width; } diff --git a/src/statusview_curses.hh b/src/statusview_curses.hh index 235a566c..88c2355c 100644 --- a/src/statusview_curses.hh +++ b/src/statusview_curses.hh @@ -248,7 +248,6 @@ private: status_data_source* sc_source{nullptr}; WINDOW* sc_window{nullptr}; int sc_top{0}; - unsigned long sc_last_width{0}; bool sc_enabled{true}; }; diff --git a/src/string-extension-functions.cc b/src/string-extension-functions.cc index 386f9047..4c8f25ff 100644 --- a/src/string-extension-functions.cc +++ b/src/string-extension-functions.cc @@ -38,27 +38,26 @@ #include "yajlpp/json_op.hh" #include "yajlpp/yajlpp.hh" -using namespace std; using namespace mapbox; typedef struct { - shared_ptr re2; + std::shared_ptr re2; } cache_entry; static cache_entry* find_re(const char* re) { - using safe_cache = safe::Safe>; + using safe_cache = safe::Safe>; static safe_cache CACHE; safe::WriteAccess wcache(CACHE); - string re_str = re; + std::string re_str = re; auto iter = wcache->find(re_str); if (iter == wcache->end()) { cache_entry c; - c.re2 = make_shared(re_str); + c.re2 = std::make_shared(re_str); auto pair = wcache->insert(std::make_pair(re_str, c)); iter = pair.first; @@ -102,33 +101,34 @@ regexp_match(const char* re, const char* str) if (!cap->is_valid()) { return static_cast(nullptr); - } else { - char* cap_copy = (char*) alloca(cap->length() + 1); - long long int i_value; - double d_value; - int end_index; - - memcpy(cap_copy, cap_start, cap->length()); - cap_copy[cap->length()] = '\0'; - - if (sscanf(cap_copy, "%lld%n", &i_value, &end_index) == 1 - && (end_index == cap->length())) - { - return (int64_t) i_value; - } else if (sscanf(cap_copy, "%lf%n", &d_value, &end_index) == 1 - && (end_index == cap->length())) - { - return d_value; - } else { - return string_fragment(str, cap->c_begin, cap->c_end); - } } + + char* cap_copy = (char*) alloca(cap->length() + 1); + long long int i_value; + double d_value; + int end_index; + + memcpy(cap_copy, cap_start, cap->length()); + cap_copy[cap->length()] = '\0'; + + if (sscanf(cap_copy, "%lld%n", &i_value, &end_index) == 1 + && (end_index == cap->length())) + { + return (int64_t) i_value; + } + if (sscanf(cap_copy, "%lf%n", &d_value, &end_index) == 1 + && (end_index == cap->length())) + { + return d_value; + } + return string_fragment(str, cap->c_begin, cap->c_end); } else { yajlpp_map root_map(gen); column_namer cn; for (int lpc = 0; lpc < extractor.get_capture_count(); lpc++) { - string colname = cn.add_column(extractor.name_for_capture(lpc)); + std::string colname + = cn.add_column(extractor.name_for_capture(lpc)); pcre_context::capture_t* cap = pc[lpc]; yajl_gen_string(gen, colname); @@ -225,7 +225,7 @@ logfmt2json(string_fragment line) parse_handle.reset(yajl_alloc( &json_op::ptr_callbacks, nullptr, &jo)); - auto json_in + const auto* json_in = (const unsigned char*) qv.qv_value.data(); auto json_len = qv.qv_value.length(); @@ -252,7 +252,7 @@ logfmt2json(string_fragment line) return json_string(gen); } -static string +static std::string regexp_replace(const char* str, const char* re, const char* repl) { cache_entry* reobj = find_re(re); @@ -260,14 +260,14 @@ regexp_replace(const char* str, const char* re, const char* repl) return reobj->re2->replace(str, repl); } -static string -spooky_hash(const vector& args) +static std::string +spooky_hash(const std::vector& args) { byte_array<2, uint64> hash; SpookyHash context; context.Init(0, 0); - for (const auto arg : args) { + for (const auto* const arg : args) { int64_t len = arg != nullptr ? strlen(arg) : 0; context.Update(&len, sizeof(len)); @@ -288,7 +288,7 @@ sql_spooky_hash_step(sqlite3_context* context, int argc, sqlite3_value** argv) = (SpookyHash*) sqlite3_aggregate_context(context, sizeof(SpookyHash)); for (int lpc = 0; lpc < argc; lpc++) { - auto value = sqlite3_value_text(argv[lpc]); + const auto* value = sqlite3_value_text(argv[lpc]); int64_t len = value != nullptr ? strlen((const char*) value) : 0; hasher->Update(&len, sizeof(len)); @@ -312,7 +312,7 @@ sql_spooky_hash_final(sqlite3_context* context) hasher->Final(hash.out(0), hash.out(1)); - string hex = hash.to_string(); + auto hex = hash.to_string(); sqlite3_result_text( context, hex.c_str(), hex.length(), SQLITE_TRANSIENT); } @@ -358,8 +358,8 @@ sparkline_final(sqlite3_context* context) return; } - auto retval = (char*) malloc(sc->sc_values.size() * 3 + 1); - auto start = retval; + auto* retval = (char*) malloc(sc->sc_values.size() * 3 + 1); + auto* start = retval; for (const auto& value : sc->sc_values) { auto bar = humanize::sparkline(value, sc->sc_max_value); @@ -380,7 +380,7 @@ sql_gunzip(sqlite3_value* val) switch (sqlite3_value_type(val)) { case SQLITE3_TEXT: case SQLITE_BLOB: { - auto buffer = sqlite3_value_blob(val); + const auto* buffer = sqlite3_value_blob(val); auto len = sqlite3_value_bytes(val); if (!lnav::gzip::is_gzipped((const char*) buffer, len)) { @@ -414,7 +414,7 @@ sql_gzip(sqlite3_value* val) switch (sqlite3_value_type(val)) { case SQLITE3_TEXT: case SQLITE_BLOB: { - auto buffer = sqlite3_value_blob(val); + const auto* buffer = sqlite3_value_blob(val); auto len = sqlite3_value_bytes(val); auto res = lnav::gzip::compress(buffer, len); @@ -428,7 +428,6 @@ sql_gzip(sqlite3_value* val) case SQLITE_INTEGER: case SQLITE_FLOAT: { auto buffer = sqlite3_value_text(val); - log_debug("buf %s", buffer); auto res = lnav::gzip::compress(buffer, strlen((const char*) buffer)); diff --git a/src/string_attr_type.cc b/src/string_attr_type.cc index 9854d060..0c75e889 100644 --- a/src/string_attr_type.cc +++ b/src/string_attr_type.cc @@ -35,6 +35,7 @@ string_attr_type SA_ORIGINAL_LINE("original_line"); string_attr_type SA_BODY("body"); string_attr_type SA_HIDDEN("hidden"); string_attr_type SA_FORMAT("format"); +string_attr_type2 SA_FORMAT2("format"); string_attr_type SA_REMOVED("removed"); string_attr_type SA_INVALID("invalid"); string_attr_type SA_ERROR("error"); diff --git a/src/string_attr_type.hh b/src/string_attr_type.hh index 8e1c1876..99a730f3 100644 --- a/src/string_attr_type.hh +++ b/src/string_attr_type.hh @@ -30,6 +30,13 @@ #ifndef lnav_string_attr_type_hh #define lnav_string_attr_type_hh +#include + +#include + +#include "base/intern_string.hh" +#include "mapbox/variant.hpp" + class string_attr_type { public: explicit string_attr_type(const char* name = nullptr) noexcept @@ -37,12 +44,40 @@ public: const char* sat_name; }; -typedef string_attr_type* string_attr_type_t; +using string_attr_type_t = string_attr_type*; + +using string_attr_value + = mapbox::util::variant; + +class string_attr_type_base { +public: + explicit string_attr_type_base(const char* name) noexcept : sat_name(name) + { + } + + const char* const sat_name; +}; + +template +class string_attr_type2 : public string_attr_type_base { +public: + explicit string_attr_type2(const char* name) noexcept + : string_attr_type_base(name) + { + } + + std::pair value(const T& val) + { + return std::make_pair(this, val); + } +}; extern string_attr_type SA_ORIGINAL_LINE; extern string_attr_type SA_BODY; extern string_attr_type SA_HIDDEN; extern string_attr_type SA_FORMAT; +class intern_string; +extern string_attr_type2 SA_FORMAT2; extern string_attr_type SA_REMOVED; extern string_attr_type SA_INVALID; extern string_attr_type SA_ERROR; diff --git a/src/styling.cc b/src/styling.cc index e782b33c..71dc6974 100644 --- a/src/styling.cc +++ b/src/styling.cc @@ -38,31 +38,32 @@ #include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp_def.hh" -using namespace std; - -static struct json_path_container term_color_rgb_handler - = {yajlpp::property_handler("r").FOR_FIELD(rgb_color, rc_r), - yajlpp::property_handler("g").FOR_FIELD(rgb_color, rc_g), - yajlpp::property_handler("b").FOR_FIELD(rgb_color, rc_b)}; - -static struct json_path_container term_color_handler - = {yajlpp::property_handler("colorId").FOR_FIELD(term_color, xc_id), - yajlpp::property_handler("name").FOR_FIELD(term_color, xc_name), - yajlpp::property_handler("hexString").FOR_FIELD(term_color, xc_hex), - yajlpp::property_handler("rgb") - .with_obj_provider( - [](const auto& pc, term_color* xc) { return &xc->xc_color; }) - .with_children(term_color_rgb_handler)}; - -static struct json_path_container root_color_handler - = {yajlpp::property_handler("#") - .with_obj_provider>( - [](const yajlpp_provider_context& ypc, - vector* palette) { - palette->resize(ypc.ypc_index + 1); - return &((*palette)[ypc.ypc_index]); - }) - .with_children(term_color_handler)}; +static const struct json_path_container term_color_rgb_handler = { + yajlpp::property_handler("r").FOR_FIELD(rgb_color, rc_r), + yajlpp::property_handler("g").FOR_FIELD(rgb_color, rc_g), + yajlpp::property_handler("b").FOR_FIELD(rgb_color, rc_b), +}; + +static const struct json_path_container term_color_handler = { + yajlpp::property_handler("colorId").FOR_FIELD(term_color, xc_id), + yajlpp::property_handler("name").FOR_FIELD(term_color, xc_name), + yajlpp::property_handler("hexString").FOR_FIELD(term_color, xc_hex), + yajlpp::property_handler("rgb") + .with_obj_provider( + [](const auto& pc, term_color* xc) { return &xc->xc_color; }) + .with_children(term_color_rgb_handler), +}; + +static const struct json_path_container root_color_handler = { + yajlpp::property_handler("#") + .with_obj_provider>( + [](const yajlpp_provider_context& ypc, + std::vector* palette) { + palette->resize(ypc.ypc_index + 1); + return &((*palette)[ypc.ypc_index]); + }) + .with_children(term_color_handler), +}; term_color_palette* xterm_colors() diff --git a/src/styling.hh b/src/styling.hh index e404f7d2..5362eae6 100644 --- a/src/styling.hh +++ b/src/styling.hh @@ -130,7 +130,7 @@ public: static color_unit make_empty() { - return {rgb_color{}}; + return color_unit{rgb_color{}}; } bool empty() const @@ -145,7 +145,7 @@ public: variants_t cu_value; private: - color_unit(variants_t value) : cu_value(std::move(value)) {} + explicit color_unit(variants_t value) : cu_value(std::move(value)) {} }; } // namespace styling diff --git a/src/tailer/drive_tailer.cc b/src/tailer/drive_tailer.cc index 0434f00b..18ead430 100644 --- a/src/tailer/drive_tailer.cc +++ b/src/tailer/drive_tailer.cc @@ -31,7 +31,7 @@ #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "base/auto_pid.hh" #include "config.h" #include "ghc/filesystem.hpp" diff --git a/src/tailer/tailer.looper.cc b/src/tailer/tailer.looper.cc index 71862ace..f8865b68 100644 --- a/src/tailer/tailer.looper.cc +++ b/src/tailer/tailer.looper.cc @@ -108,7 +108,7 @@ update_tailer_progress(const std::string& netloc, const std::string& msg) static void update_tailer_description( const std::string& netloc, - const std::map& desired_paths, + const std::map& desired_paths, const std::string& remote_uname) { std::vector paths; @@ -182,7 +182,7 @@ tailer::looper::loop_body() for (const auto& pair : paths) { log_debug("adding path to tailer -- %s", pair.first.c_str()); - ht.open_remote_path(pair.first, pair.second); + ht.open_remote_path(pair.first, std::move(pair.second)); } }); @@ -199,7 +199,7 @@ tailer::looper::loop_body() void tailer::looper::add_remote(const network::path& path, - logfile_open_options options) + logfile_open_options_base options) { auto netloc_str = fmt::to_string(path.home()); this->l_netlocs_to_paths[netloc_str].rpq_new_paths[path.p_path] @@ -488,7 +488,7 @@ tailer::looper::host_tailer::host_tailer(const std::string& netloc, void tailer::looper::host_tailer::open_remote_path(const std::string& path, - logfile_open_options loo) + logfile_open_options_base loo) { this->ht_state.match( [&](connected& conn) { @@ -660,7 +660,7 @@ tailer::looper::host_tailer::loop_body() pob.pob_offset, pob.pob_length); - logfile_open_options loo; + logfile_open_options_base loo; if (pob.pob_path == pob.pob_root_path) { auto root_iter = conn.c_desired_paths.find(pob.pob_path); @@ -670,7 +670,7 @@ tailer::looper::host_tailer::loop_body() return std::move(this->ht_state); } - loo = std::move(root_iter->second); + loo = root_iter->second; } else { auto child_iter = conn.c_child_paths.find(pob.pob_path); if (child_iter == conn.c_child_paths.end()) { diff --git a/src/tailer/tailer.looper.hh b/src/tailer/tailer.looper.hh index 9b2b073d..9fab57ea 100644 --- a/src/tailer/tailer.looper.hh +++ b/src/tailer/tailer.looper.hh @@ -34,7 +34,7 @@ #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "base/auto_pid.hh" #include "base/isc.hh" #include "base/network.tcp.hh" @@ -45,7 +45,8 @@ namespace tailer { class looper : public isc::service { public: - void add_remote(const network::path& path, logfile_open_options options); + void add_remote(const network::path& path, + logfile_open_options_base options); void load_preview(int64_t id, const network::path& path); @@ -84,7 +85,7 @@ private: auto_fd err_from_child); void open_remote_path(const std::string& path, - logfile_open_options loo); + logfile_open_options_base loo); void load_preview(int64_t id, const std::string& path); @@ -114,8 +115,8 @@ private: auto_pid ht_child; auto_fd ht_to_child; auto_fd ht_from_child; - std::map c_desired_paths; - std::map c_child_paths; + std::map c_desired_paths; + std::map c_child_paths; auto_pid close() &&; }; @@ -145,8 +146,8 @@ private: struct remote_path_queue { attempt_time_point rpq_next_attempt_time{ std::chrono::steady_clock::now()}; - std::map rpq_new_paths; - std::map rpq_existing_paths; + std::map rpq_new_paths; + std::map rpq_existing_paths; void send_synced_to_main(const std::string& netloc); }; diff --git a/src/textfile_highlighters.cc b/src/textfile_highlighters.cc index 27b3805f..3ff3cab4 100644 --- a/src/textfile_highlighters.cc +++ b/src/textfile_highlighters.cc @@ -33,8 +33,6 @@ #include "config.h" -using namespace std; - static pcre* xpcre_compile(const char* pattern, int options = 0) { diff --git a/src/textview_curses.cc b/src/textview_curses.cc index ccbb8fa1..1b44e75b 100644 --- a/src/textview_curses.cc +++ b/src/textview_curses.cc @@ -43,8 +43,6 @@ #include "shlex.hh" #include "view_curses.hh" -using namespace std; - const auto REVERSE_SEARCH_OFFSET = 2000_vl; void @@ -143,7 +141,7 @@ textview_curses::~textview_curses() void textview_curses::reload_config(error_reporter& reporter) { - const static auto DEFAULT_THEME_NAME = string("default"); + const static auto DEFAULT_THEME_NAME = std::string("default"); for (auto iter = this->tc_highlights.begin(); iter != this->tc_highlights.end();) @@ -196,7 +194,7 @@ textview_curses::reload_config(error_reporter& reporter) } const auto& sc = hl_pair.second.hc_style; - string fg1, bg1, fg_color, bg_color, errmsg; + std::string fg1, bg1, fg_color, bg_color, errmsg; bool invalid = false; int attrs = 0; @@ -334,7 +332,7 @@ textview_curses::grep_match(grep_proc& gp, void textview_curses::listview_value_for_rows(const listview_curses& lv, vis_line_t row, - vector& rows_out) + std::vector& rows_out) { for (auto& al : rows_out) { this->textview_value_for_row(row, al); @@ -428,9 +426,9 @@ textview_curses::handle_mouse(mouse_event& me) void textview_curses::textview_value_for_row(vis_line_t row, attr_line_t& value_out) { - string_attrs_t& sa = value_out.get_attrs(); - string& str = value_out.get_string(); - text_format_t source_format = this->tc_sub_source->get_text_format(); + auto& sa = value_out.get_attrs(); + auto& str = value_out.get_string(); + auto source_format = this->tc_sub_source->get_text_format(); intern_string_t format_name; this->tc_sub_source->text_value_for_line(*this, row, str); @@ -577,7 +575,7 @@ textview_curses::execute_search(const std::string& regex_orig) regex.c_str(), PCRE_CASELESS, &errptr, &eoff, nullptr)) == nullptr) { - string errmsg = string(errptr); + auto errmsg = std::string(errptr); regex = pcrepp::quote(regex); @@ -598,8 +596,7 @@ textview_curses::execute_search(const std::string& regex_orig) highlight_map_t& hm = this->get_highlights(); hm[{highlight_source_t::PREVIEW, "search"}] = hl; - unique_ptr> gp - = make_unique>(code, *this); + auto gp = std::make_unique>(code, *this); gp->set_sink(this); auto top = this->get_top(); @@ -619,8 +616,8 @@ textview_curses::execute_search(const std::string& regex_orig) if (this->tc_sub_source != nullptr) { this->tc_sub_source->get_grepper() | [this, code](auto pair) { - shared_ptr> sgp - = make_shared>(code, *pair.first); + auto sgp = std::make_shared>( + code, *pair.first); sgp->set_sink(pair.second); sgp->queue_request(0_vl); @@ -642,7 +639,7 @@ void textview_curses::horiz_shift(vis_line_t start, vis_line_t end, int off_start, - pair& range_out) + std::pair& range_out) { highlighter& hl = this->tc_highlights[{highlight_source_t::PREVIEW, "search"}]; @@ -799,7 +796,7 @@ empty_filter::matches(const logfile& lf, return false; } -string +std::string empty_filter::to_command() const { return ""; diff --git a/src/time-extension-functions.cc b/src/time-extension-functions.cc index f7915112..618778f7 100644 --- a/src/time-extension-functions.cc +++ b/src/time-extension-functions.cc @@ -41,8 +41,6 @@ #include "sql_util.hh" #include "vtab_module.hh" -using namespace std; - static nonstd::optional timeslice(sqlite3_value* time_in, nonstd::optional slice_in_opt) { diff --git a/src/url_loader.hh b/src/url_loader.hh index 831b5a77..1d08bd5f 100644 --- a/src/url_loader.hh +++ b/src/url_loader.hh @@ -51,7 +51,7 @@ public: auto tmp_pair = tmp_res.unwrap(); ghc::filesystem::remove(tmp_pair.first); - this->ul_fd = tmp_pair.second; + this->ul_fd = std::move(tmp_pair.second); curl_easy_setopt(this->cr_handle, CURLOPT_URL, this->cr_name.c_str()); curl_easy_setopt(this->cr_handle, CURLOPT_WRITEFUNCTION, write_cb); @@ -66,7 +66,7 @@ public: auto_fd copy_fd() const { - return this->ul_fd; + return this->ul_fd.dup(); }; long complete(CURLcode result) diff --git a/src/view_helpers.cc b/src/view_helpers.cc index ed3a7e8b..8dd2b12e 100644 --- a/src/view_helpers.cc +++ b/src/view_helpers.cc @@ -40,18 +40,18 @@ #include "view_helpers.examples.hh" #include "vtab_module.hh" -using namespace std; - -const char* lnav_view_strings[LNV__MAX + 1] = {"log", - "text", - "help", - "histogram", - "db", - "schema", - "pretty", - "spectro", - - nullptr}; +const char* lnav_view_strings[LNV__MAX + 1] = { + "log", + "text", + "help", + "histogram", + "db", + "schema", + "pretty", + "spectro", + + nullptr, +}; nonstd::optional view_from_string(const char* name) @@ -61,13 +61,13 @@ view_from_string(const char* name) } auto view_name_iter - = find_if(::begin(lnav_view_strings), - ::end(lnav_view_strings), - [&](const char* v) { - return v != nullptr && strcasecmp(v, name) == 0; - }); + = std::find_if(std::begin(lnav_view_strings), + std::end(lnav_view_strings), + [&](const char* v) { + return v != nullptr && strcasecmp(v, name) == 0; + }); - if (view_name_iter == ::end(lnav_view_strings)) { + if (view_name_iter == std::end(lnav_view_strings)) { return nonstd::nullopt; } @@ -78,7 +78,7 @@ static void open_schema_view() { textview_curses* schema_tc = &lnav_data.ld_views[LNV_SCHEMA]; - string schema; + std::string schema; dump_sqlite_schema(lnav_data.ld_db, schema); @@ -123,7 +123,7 @@ open_pretty_view() for (vis_line_t vl = log_tc->get_top(); vl <= log_tc->get_bottom(); ++vl) { content_line_t cl = lss.at(vl); - shared_ptr lf = lss.find(cl); + auto lf = lss.find(cl); auto ll = lf->begin() + cl; shared_buffer_ref sbr; @@ -153,7 +153,7 @@ open_pretty_view() data_scanner ds(orig_al.get_string()); pretty_printer pp(&ds, orig_al.get_attrs()); attr_line_t pretty_al; - vector pretty_lines; + std::vector pretty_lines; // TODO: dump more details of the line in the output. pp.append_to(pretty_al); @@ -176,7 +176,7 @@ open_pretty_view() full_text.erase(full_text.length() - 1, 1); } } else if (top_tc == text_tc) { - shared_ptr lf = lnav_data.ld_text_source.current_file(); + auto lf = lnav_data.ld_text_source.current_file(); for (vis_line_t vl = text_tc->get_top(); vl <= text_tc->get_bottom(); ++vl) { @@ -210,14 +210,14 @@ build_all_help_text() attr_line_t all_help_text; shlex lexer(help_txt.to_string_fragment()); - string sub_help_text; + std::string sub_help_text; lexer.with_ignore_quotes(true).eval( sub_help_text, lnav_data.ld_exec_context.ec_global_vars); all_help_text.with_ansi_string(sub_help_text); - map sql_funcs; - map sql_keywords; + std::map sql_funcs; + std::map sql_keywords; for (const auto& iter : sqlite_function_help) { switch (iter.second->ht_context) { @@ -293,7 +293,7 @@ layout_views() ? 0 : lnav_data.ld_preview_source.text_line_count(); int match_rows = lnav_data.ld_match_source.text_line_count(); - int match_height = min((unsigned long) match_rows, (height - 4) / 2); + int match_height = std::min((unsigned long) match_rows, (height - 4) / 2); lnav_data.ld_match_view.set_height(vis_line_t(match_height)); @@ -376,7 +376,7 @@ layout_views() lnav_data.ld_rl_view->set_width(width); } -static unordered_map EXAMPLE_RESULTS; +static std::unordered_map EXAMPLE_RESULTS; void execute_examples() @@ -389,7 +389,7 @@ execute_examples() struct help_text& ht = *(help_iter.second); for (auto& ex : ht.ht_example) { - string alt_msg; + std::string alt_msg; attr_line_t result; if (!ex.he_cmd) { @@ -461,7 +461,7 @@ toggle_view(textview_curses* toggle_tc) textview_curses* tc = lnav_data.ld_view_stack.top().value_or(nullptr); bool retval = false; - require(toggle_tc != NULL); + require(toggle_tc != nullptr); require(toggle_tc >= &lnav_data.ld_views[0]); require(toggle_tc < &lnav_data.ld_views[LNV__MAX]); @@ -536,9 +536,11 @@ next_cluster(vis_line_t (bookmark_vector::*f)(vis_line_t) const, hit_count += 1; if (!top_is_marked || diff > 1) { return new_top; - } else if (hit_count > 1 && std::abs(new_top - top) >= tc_height) { + } + if (hit_count > 1 && std::abs(new_top - top) >= tc_height) { return vis_line_t(new_top - diff); - } else if (diff < -1) { + } + if (diff < -1) { last_top = new_top; while ((new_top = (bv.*f)(new_top)) != -1) { if ((std::abs(last_top - new_top) > 1) diff --git a/src/vt52_curses.cc b/src/vt52_curses.cc index bef01ecf..a258d6e8 100644 --- a/src/vt52_curses.cc +++ b/src/vt52_curses.cc @@ -57,8 +57,6 @@ # error "SysV or X/Open-compatible Curses header file required" #endif -using namespace std; - /** * Singleton used to hold the mapping of ncurses keycodes to VT52 escape * sequences. @@ -79,10 +77,10 @@ public: */ const char* operator[](int ch) const { - map::const_iterator iter; + auto iter = this->vem_map.find(ch); const char* retval = nullptr; - if ((iter = this->vem_map.find(ch)) == this->vem_map.end()) { + if (iter == this->vem_map.end()) { if (ch > KEY_MAX) { auto name = keyname(ch); @@ -104,7 +102,7 @@ public: const char* operator[](const char* seq) const { - map::const_iterator iter; + std::map::const_iterator iter; const char* retval = nullptr; require(seq != nullptr); @@ -162,8 +160,8 @@ private: }; /** Map of ncurses keycodes to VT52 escape sequences. */ - mutable map vem_map; - map vem_input_map; + mutable std::map vem_map; + std::map vem_input_map; }; const char* diff --git a/src/xpath_vtab.cc b/src/xpath_vtab.cc index 4695a8c0..9c15cb26 100644 --- a/src/xpath_vtab.cc +++ b/src/xpath_vtab.cc @@ -39,8 +39,6 @@ #include "xml_util.hh" #include "yajlpp/yajlpp.hh" -using namespace std; - enum { XP_COL_RESULT, XP_COL_NODE_PATH, @@ -104,8 +102,8 @@ CREATE TABLE xpath ( struct cursor { sqlite3_vtab_cursor base; sqlite3_int64 c_rowid{0}; - string c_xpath; - string c_value; + std::string c_xpath; + std::string c_value; bool c_value_as_blob{false}; pugi::xpath_query c_query; pugi::xml_document c_doc; @@ -153,7 +151,7 @@ CREATE TABLE xpath ( auto& xpath_node = vc.c_results[vc.c_rowid]; if (xpath_node.node()) { - ostringstream oss; + std::ostringstream oss; // XXX avoid the extra allocs xpath_node.node().print(oss); @@ -356,29 +354,35 @@ register_xpath_vtab(sqlite3* db) "over an XML " "string and returns the selected values.") .sql_table_valued_function() - .with_parameter( - {"xpath", - "The XPATH expression to evaluate over the XML document."}) + .with_parameter({ + "xpath", + "The XPATH expression to evaluate over the XML document.", + }) .with_parameter({"xmldoc", "The XML document as a string."}) .with_result({"result", "The result of the XPATH expression."}) - .with_result( - {"node_path", - "The absolute path to the node containing the result."}) + .with_result({ + "node_path", + "The absolute path to the node containing the result.", + }) .with_result( {"node_attr", "The node's attributes stored in JSON object."}) .with_result({"node_text", "The node's text value."}) .with_tags({"string", "xml"}) - .with_example({"To select the XML nodes on the path '/abc/def'", - "SELECT * FROM xpath('/abc/def', 'HelloBye')"}) - .with_example( - {"To select all 'a' attributes on the path '/abc/def'", - "SELECT * FROM xpath('/abc/def/@a', 'HelloBye')"}) - .with_example( - {"To select the text nodes on the path '/abc/def'", - "SELECT * FROM xpath('/abc/def/text()', 'Hello ★')"}); + .with_example({ + "To select the XML nodes on the path '/abc/def'", + "SELECT * FROM xpath('/abc/def', 'HelloBye')", + }) + .with_example({ + "To select all 'a' attributes on the path '/abc/def'", + "SELECT * FROM xpath('/abc/def/@a', 'HelloBye')", + }) + .with_example({ + "To select the text nodes on the path '/abc/def'", + "SELECT * FROM xpath('/abc/def/text()', 'Hello ★')", + }); int rc; @@ -386,7 +390,7 @@ register_xpath_vtab(sqlite3* db) XPATH_MODULE.vm_module.xFilter = rcFilter; rc = XPATH_MODULE.create(db, "xpath"); - sqlite_function_help.insert(make_pair("xpath", &xpath_help)); + sqlite_function_help.insert(std::make_pair("xpath", &xpath_help)); xpath_help.index_tags(); ensure(rc == SQLITE_OK); diff --git a/src/yajlpp/drive_json_ptr_walk.cc b/src/yajlpp/drive_json_ptr_walk.cc index 5b76e07b..c6a8f72b 100644 --- a/src/yajlpp/drive_json_ptr_walk.cc +++ b/src/yajlpp/drive_json_ptr_walk.cc @@ -40,8 +40,6 @@ #include "yajl/api/yajl_gen.h" #include "yajlpp.hh" -using namespace std; - int main(int argc, char* argv[]) { @@ -51,7 +49,7 @@ main(int argc, char* argv[]) log_argv(argc, argv); - std::string json_input(std::istreambuf_iterator(cin), {}); + std::string json_input(std::istreambuf_iterator(std::cin), {}); status = jpw.parse(json_input.c_str(), json_input.size()); if (status == yajl_status_error) { diff --git a/src/yajlpp/json_ptr.cc b/src/yajlpp/json_ptr.cc index 4e872df1..a1451d4f 100644 --- a/src/yajlpp/json_ptr.cc +++ b/src/yajlpp/json_ptr.cc @@ -38,8 +38,6 @@ #include "yajl/api/yajl_gen.h" #include "yajlpp/json_ptr.hh" -using namespace std; - static int handle_null(void* ctx) { @@ -70,7 +68,7 @@ handle_number(void* ctx, const char* numberVal, size_t numberLen) json_ptr_walk* jpw = (json_ptr_walk*) ctx; jpw->jpw_values.emplace_back( - jpw->current_ptr(), yajl_t_number, string(numberVal, numberLen)); + jpw->current_ptr(), yajl_t_number, std::string(numberVal, numberLen)); jpw->inc_array_index(); return 1; @@ -79,7 +77,7 @@ handle_number(void* ctx, const char* numberVal, size_t numberLen) static void appender(void* ctx, const char* strVal, size_t strLen) { - string& str = *(string*) ctx; + std::string& str = *(std::string*) ctx; str.append(strVal, strLen); } @@ -89,7 +87,7 @@ handle_string(void* ctx, const unsigned char* stringVal, size_t len) { json_ptr_walk* jpw = (json_ptr_walk*) ctx; auto_mem gen(yajl_gen_free); - string str; + std::string str; gen = yajl_gen_alloc(nullptr); yajl_gen_config(gen.in(), yajl_gen_print_callback, appender, &str); diff --git a/src/yajlpp/yajlpp.cc b/src/yajlpp/yajlpp.cc index ce0e1628..eb60b880 100644 --- a/src/yajlpp/yajlpp.cc +++ b/src/yajlpp/yajlpp.cc @@ -39,12 +39,10 @@ #include "yajl/api/yajl_parse.h" #include "yajlpp_def.hh" -using namespace std; - const json_path_handler_base::enum_value_t json_path_handler_base::ENUM_TERMINATOR((const char*) nullptr, 0); -json_path_handler_base::json_path_handler_base(const string& property) +json_path_handler_base::json_path_handler_base(const std::string& property) : jph_property(property.back() == '#' ? property.substr(0, property.size() - 1) : property), @@ -70,10 +68,10 @@ json_path_handler_base::json_path_handler_base(const pcrepp& property) memset(&this->jph_callbacks, 0, sizeof(this->jph_callbacks)); } -json_path_handler_base::json_path_handler_base(string property, +json_path_handler_base::json_path_handler_base(std::string property, const pcrepp& property_re) : jph_property(std::move(property)), jph_regex(property_re), - jph_is_array(property_re.p_pattern.find('#') != string::npos) + jph_is_array(property_re.p_pattern.find('#') != std::string::npos) { memset(&this->jph_callbacks, 0, sizeof(this->jph_callbacks)); } @@ -81,7 +79,7 @@ json_path_handler_base::json_path_handler_base(string property, yajl_gen_status json_path_handler_base::gen(yajlpp_gen_context& ygc, yajl_gen handle) const { - vector local_paths; + std::vector local_paths; if (this->jph_path_provider) { this->jph_path_provider(ygc.ygc_obj_stack.top(), local_paths); @@ -91,7 +89,7 @@ json_path_handler_base::gen(yajlpp_gen_context& ygc, yajl_gen handle) const if (this->jph_children) { for (const auto& lpath : local_paths) { - string full_path = lpath; + std::string full_path = lpath; if (this->jph_path_provider) { full_path += "/"; } @@ -180,7 +178,8 @@ json_path_handler_base::gen_schema(yajlpp_gen_context& ygc) const fmt::join(ygc.ygc_path, "/"))); schema.gen("type"); if (this->jph_is_array) { - if (this->jph_regex.p_pattern.find("#?") == string::npos) { + if (this->jph_regex.p_pattern.find("#?") + == std::string::npos) { schema.gen("array"); } else { yajlpp_array type_array(ygc.ygc_handle); @@ -231,7 +230,7 @@ json_path_handler_base::gen_schema(yajlpp_gen_context& ygc) const schema.gen("type"); if (this->jph_is_array) { - if (this->jph_regex.p_pattern.find("#?") == string::npos) { + if (this->jph_regex.p_pattern.find("#?") == std::string::npos) { schema.gen("array"); } else { yajlpp_array type_array(ygc.ygc_handle); @@ -327,9 +326,9 @@ json_path_handler_base::walk( const std::function< void(const json_path_handler_base&, const std::string&, void*)>& cb, void* root, - const string& base) const + const std::string& base) const { - vector local_paths; + std::vector local_paths; if (this->jph_path_provider) { this->jph_path_provider(root, local_paths); @@ -340,7 +339,7 @@ json_path_handler_base::walk( } else { local_paths.emplace_back(this->jph_property); - string full_path = base + this->jph_property; + std::string full_path = base + this->jph_property; if (this->jph_children) { full_path += "/"; } @@ -350,7 +349,7 @@ json_path_handler_base::walk( if (this->jph_children) { for (const auto& lpath : local_paths) { for (auto& jph : this->jph_children->jpc_children) { - string full_path = base + lpath; + std::string full_path = base + lpath; if (this->jph_children) { full_path += "/"; } @@ -363,7 +362,7 @@ json_path_handler_base::walk( ypc.set_path(full_path).with_obj(root).update_callbacks(); if (this->jph_obj_provider) { - string full_path = lpath + "/"; + std::string full_path = lpath + "/"; pcre_input pi(full_path); if (!this->jph_regex.match(ypc.ypc_pcre_context, pi)) { @@ -402,7 +401,7 @@ json_path_handler_base::to_enum_value(const string_fragment& sf) const return nonstd::nullopt; } -vector +std::vector json_path_handler_base::get_types() const { std::vector retval; @@ -537,7 +536,7 @@ yajlpp_parse_context::update_callbacks(const json_path_container* orig_handlers, } if (!this->ypc_active_paths.empty()) { - string curr_path(&this->ypc_path[0], this->ypc_path.size() - 1); + std::string curr_path(&this->ypc_path[0], this->ypc_path.size() - 1); if (this->ypc_active_paths.find(curr_path) == this->ypc_active_paths.end()) { @@ -889,20 +888,25 @@ yajlpp_parse_context::set_static_handler(json_path_handler_base& jph) this->ypc_path.push_back('\0'); this->ypc_path_index_stack.clear(); this->ypc_array_index.clear(); - if (jph.jph_callbacks.yajl_null != nullptr) + if (jph.jph_callbacks.yajl_null != nullptr) { this->ypc_callbacks.yajl_null = jph.jph_callbacks.yajl_null; - if (jph.jph_callbacks.yajl_boolean != nullptr) + } + if (jph.jph_callbacks.yajl_boolean != nullptr) { this->ypc_callbacks.yajl_boolean = jph.jph_callbacks.yajl_boolean; - if (jph.jph_callbacks.yajl_integer != nullptr) + } + if (jph.jph_callbacks.yajl_integer != nullptr) { this->ypc_callbacks.yajl_integer = jph.jph_callbacks.yajl_integer; - if (jph.jph_callbacks.yajl_double != nullptr) + } + if (jph.jph_callbacks.yajl_double != nullptr) { this->ypc_callbacks.yajl_double = jph.jph_callbacks.yajl_double; - if (jph.jph_callbacks.yajl_string != nullptr) + } + if (jph.jph_callbacks.yajl_string != nullptr) { this->ypc_callbacks.yajl_string = jph.jph_callbacks.yajl_string; + } } yajlpp_parse_context& -yajlpp_parse_context::set_path(const string& path) +yajlpp_parse_context::set_path(const std::string& path) { this->ypc_path.resize(path.size() + 1); std::copy(path.begin(), path.end(), this->ypc_path.begin()); @@ -950,7 +954,7 @@ yajlpp_parse_context::get_path_fragment(int offset, int yajlpp_parse_context::get_line_number() const { - if (this->ypc_handle != NULL && this->ypc_json_text) { + if (this->ypc_handle != nullptr && this->ypc_json_text) { size_t consumed = yajl_get_bytes_consumed(this->ypc_handle); long current_count = std::count( &this->ypc_json_text[0], &this->ypc_json_text[consumed], '\n'); @@ -966,7 +970,7 @@ yajlpp_gen_context::gen() { yajlpp_map root(this->ygc_handle); - for (auto& jph : this->ygc_handlers->jpc_children) { + for (const auto& jph : this->ygc_handlers->jpc_children) { jph.gen(*this, this->ygc_handle); } } @@ -1079,7 +1083,7 @@ json_path_container::gen_properties(yajlpp_gen_context& ygc) const { yajlpp_map properties(ygc.ygc_handle); - for (auto& child_handler : this->jpc_children) { + for (const auto& child_handler : this->jpc_children) { if (!child_handler.jph_is_pattern_property) { continue; } @@ -1107,7 +1111,7 @@ dump_schema_to(const json_path_container& jpc, yajlpp_gen genner; yajlpp_gen_context ygc(genner, jpc); auto schema_path = fmt::format(FMT_STRING("{}/{}"), internals_dir, name); - auto file = unique_ptr( + auto file = std::unique_ptr( fopen(schema_path.c_str(), "w+"), fclose); if (!file.get()) { diff --git a/test/aftest.cc b/test/aftest.cc index 225b2301..5707c793 100644 --- a/test/aftest.cc +++ b/test/aftest.cc @@ -31,7 +31,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" void foo(int* fd) diff --git a/test/drive_data_scanner.cc b/test/drive_data_scanner.cc index 7869bfac..1de28d74 100644 --- a/test/drive_data_scanner.cc +++ b/test/drive_data_scanner.cc @@ -48,8 +48,6 @@ #include "pretty_printer.hh" #include "shared_buffer.hh" -using namespace std; - const char* TMP_NAME = "scanned.tmp"; int @@ -71,7 +69,7 @@ main(int argc, char* argv[]) { std::vector paths; - vector errors; + std::vector errors; load_formats(paths, errors); } @@ -105,14 +103,14 @@ main(int argc, char* argv[]) retval = EXIT_FAILURE; } else { for (int lpc = 0; lpc < argc; lpc++) { - std::unique_ptr in_ptr; - istream* in; + std::unique_ptr in_ptr; + std::istream* in; FILE* out; if (strcmp(argv[lpc], "-") == 0) { - in = &cin; + in = &std::cin; } else { - auto ifs = std::make_unique(argv[lpc]); + auto ifs = std::make_unique(argv[lpc]); if (!ifs->is_open()) { fprintf(stderr, "error: unable to open file\n"); @@ -128,11 +126,11 @@ main(int argc, char* argv[]) "error: unable to temporary file for writing\n"); retval = EXIT_FAILURE; } else { - shared_ptr format; + std::shared_ptr format; char* log_line; bool found = false; char cmd[2048]; - string line; + std::string line; int rc; getline(*in, line); @@ -142,7 +140,7 @@ main(int argc, char* argv[]) log_line = (char*) alloca(line.length()); strcpy(log_line, &line[13]); - string sub_line = line.substr(13); + auto sub_line = line.substr(13); struct line_range body(0, sub_line.length()); shared_buffer share_manager; shared_buffer_ref sbr; @@ -151,8 +149,8 @@ main(int argc, char* argv[]) share_manager, (char*) sub_line.c_str(), sub_line.size()); auto& root_formats = log_format::get_root_formats(); - vector>::iterator iter; - vector index; + std::vector>::iterator iter; + std::vector index; if (is_log) { for (iter = root_formats.begin(); @@ -175,7 +173,7 @@ main(int argc, char* argv[]) } } - vector ll_values; + std::vector ll_values; string_attrs_t sa; if (format.get() != nullptr) { @@ -187,7 +185,7 @@ main(int argc, char* argv[]) data_scanner ds(sub_line, body.lr_start, sub_line.length()); data_parser dp(&ds); - string msg_format; + std::string msg_format; dp.dp_msg_format = &msg_format; dp.parse(); diff --git a/test/drive_line_buffer.cc b/test/drive_line_buffer.cc index 22bddfb0..75acba36 100644 --- a/test/drive_line_buffer.cc +++ b/test/drive_line_buffer.cc @@ -41,7 +41,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "base/string_util.hh" #include "config.h" #include "line_buffer.hh" diff --git a/test/scripty.cc b/test/scripty.cc index 476da055..07623b69 100644 --- a/test/scripty.cc +++ b/test/scripty.cc @@ -77,7 +77,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "auto_mem.hh" #include "base/string_util.hh" #include "fmt/format.h" diff --git a/test/test_auto_fd.cc b/test/test_auto_fd.cc index 1a4686c4..ab454902 100644 --- a/test/test_auto_fd.cc +++ b/test/test_auto_fd.cc @@ -33,7 +33,7 @@ #include #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "config.h" int @@ -62,7 +62,7 @@ main(int argc, char* argv[]) assert(errno == EBADF); { - auto_fd fd_cp(const_cast(fd1)); + auto_fd fd_cp(fd1.dup()); assert(fd1 == STDOUT_FILENO); assert(fd_cp != STDOUT_FILENO); @@ -71,7 +71,7 @@ main(int argc, char* argv[]) tmp = (int) fd_cp; } { - auto_fd fd_cp(const_cast(fd1)); + auto_fd fd_cp(fd1.dup()); assert(fd_cp == tmp); } diff --git a/test/test_cli.sh b/test/test_cli.sh index b689ffb1..ca3c4f35 100644 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -1,7 +1,7 @@ #! /bin/bash export TZ="UTC" -run_test ${lnav_test} -t -n < #include -#include "auto_fd.hh" +#include "base/auto_fd.hh" #include "config.h" #include "line_buffer.hh" diff --git a/test/test_logfile.sh b/test/test_logfile.sh index 2c969e25..465f64d2 100644 --- a/test/test_logfile.sh +++ b/test/test_logfile.sh @@ -3,6 +3,16 @@ echo ${top_srcdir} echo ${top_builddir} + +run_test ${lnav_test} -d /tmp/lnav.err -n -w logfile_stdin.0.log \ + -c ':shexec sleep 1 && touch -t 200711030923 logfile_stdin.0.log' < test_logfile.rotmp.out cp test_logfile.rotmp.out `test_err_filename` check_error_output "archive not unpacked" <