[modernize] some more cleanups

This commit is contained in:
Timothy Stack 2022-03-31 08:59:19 -07:00
parent cfa6f35c44
commit 81e63784e7
97 changed files with 1729 additions and 1481 deletions

View File

@ -137,6 +137,8 @@ with the **lnav_view_filter_stats** table into a single view for ease of use.
all_logs all_logs
-------- --------
.. f0:sql.tables.all_logs
The **all_logs** table lets you query the format derived from the **lnav** The **all_logs** table lets you query the format derived from the **lnav**
log message parser that is used to automatically extract data, see log message parser that is used to automatically extract data, see
:ref:`data-ext` for more details. :ref:`data-ext` for more details.

View File

@ -47,6 +47,8 @@ by pressing :kbd:`t`.
Archive Support Archive Support
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
.. f0:archive
If **lnav** is compiled with `libarchive <https://www.libarchive.org>`_, If **lnav** is compiled with `libarchive <https://www.libarchive.org>`_,
any files to be opened will be examined to see if they are a supported archive 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 type. If so, the contents of the archive will be extracted to the

View File

@ -343,7 +343,6 @@ add_library(
archive_manager.hh archive_manager.hh
archive_manager.cfg.hh archive_manager.cfg.hh
attr_line.hh attr_line.hh
auto_fd.hh
auto_mem.hh auto_mem.hh
big_array.hh big_array.hh
bottom_status_source.hh bottom_status_source.hh

View File

@ -158,7 +158,6 @@ noinst_HEADERS = \
archive_manager.hh \ archive_manager.hh \
archive_manager.cfg.hh \ archive_manager.cfg.hh \
attr_line.hh \ attr_line.hh \
auto_fd.hh \
auto_mem.hh \ auto_mem.hh \
big_array.hh \ big_array.hh \
bin2c.hh \ bin2c.hh \

View File

@ -37,6 +37,8 @@
/** /**
* A virtual table that provides access to all log messages from all formats. * 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 { class all_logs_vtab : public log_vtab_impl {
public: public:

View File

@ -38,8 +38,6 @@
#include "pcrepp/pcrepp.hh" #include "pcrepp/pcrepp.hh"
#include "view_curses.hh" #include "view_curses.hh"
using namespace std;
static pcrepp& static pcrepp&
ansi_regex() ansi_regex()
{ {
@ -69,7 +67,7 @@ scrub_ansi_string(std::string& str, string_attrs_t& sa)
switch (pi.get_substr_start(&caps[2])[0]) { switch (pi.get_substr_start(&caps[2])[0]) {
case 'm': case 'm':
for (lpc = caps[1].c_begin; 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; int ansi_code = 0;
@ -103,7 +101,7 @@ scrub_ansi_string(std::string& str, string_attrs_t& sa)
} }
} }
lpc = str.find(';', lpc); lpc = str.find(';', lpc);
if (lpc != string::npos) { if (lpc != std::string::npos) {
lpc += 1; lpc += 1;
} }
} }

View File

@ -40,8 +40,8 @@
#include "archive_manager.cfg.hh" #include "archive_manager.cfg.hh"
#include "archive_manager.hh" #include "archive_manager.hh"
#include "auto_fd.hh"
#include "auto_mem.hh" #include "auto_mem.hh"
#include "base/auto_fd.hh"
#include "base/fs_util.hh" #include "base/fs_util.hh"
#include "base/humanize.hh" #include "base/humanize.hh"
#include "base/injector.hh" #include "base/injector.hh"
@ -87,9 +87,13 @@ public:
auto lock_path = archive_path; auto lock_path = archive_path;
lock_path += ".lck"; lock_path += ".lck";
this->lh_fd auto open_res
= lnav::filesystem::openp(lock_path, O_CREAT | O_RDWR, 0600); = lnav::filesystem::open_file(lock_path, O_CREAT | O_RDWR, 0600);
log_perror(fcntl(this->lh_fd, F_SETFD, FD_CLOEXEC)); 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; auto_fd lh_fd;
@ -103,6 +107,7 @@ public:
static void static void
enable_desired_archive_formats(archive* arc) enable_desired_archive_formats(archive* arc)
{ {
/** @feature f0:archive.formats */
archive_read_support_format_7zip(arc); archive_read_support_format_7zip(arc);
archive_read_support_format_cpio(arc); archive_read_support_format_cpio(arc);
archive_read_support_format_lha(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()); log_debug("read open %s", filename.c_str());
auto r = archive_read_open_filename(arc, filename.c_str(), 128 * 1024); auto r = archive_read_open_filename(arc, filename.c_str(), 128 * 1024);
if (r == ARCHIVE_OK) { 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()); log_debug("read next header %s %s", format_name, filename.c_str());
if (archive_read_next_header(arc, &entry) == ARCHIVE_OK) { if (archive_read_next_header(arc, &entry) == ARCHIVE_OK) {
@ -146,7 +151,7 @@ is_archive(const fs::path& filename)
return false; 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) { if (filter_count == 2 && GZ_FILTER_NAME == first_filter_name) {
return false; return false;
} }
@ -154,11 +159,11 @@ is_archive(const fs::path& filename)
log_info( log_info(
"detected archive: %s -- %s", filename.c_str(), format_name); "detected archive: %s -- %s", filename.c_str(), format_name);
return true; 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 { } else {
log_info("archive open failed: %s -- %s", log_info("archive open failed: %s -- %s",
filename.c_str(), filename.c_str(),
@ -214,7 +219,7 @@ copy_data(const std::string& filename,
for (;;) { for (;;) {
if (total >= next_space_check) { if (total >= next_space_check) {
auto& cfg = injector::get<const config&>(); const auto& cfg = injector::get<const config&>();
auto tmp_space = fs::space(entry_path); auto tmp_space = fs::space(entry_path);
if (tmp_space.available < cfg.amc_min_free_space) { if (tmp_space.available < cfg.amc_min_free_space) {
@ -256,10 +261,19 @@ copy_data(const std::string& filename,
static walk_result_t static walk_result_t
extract(const std::string& filename, const extract_cb& cb) 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; | ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_FFLAGS;
std::error_code ec;
auto tmp_path = filename_to_tmp_path(filename); 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 arc_lock = archive_lock(tmp_path);
auto lock_guard = archive_lock::guard(arc_lock); auto lock_guard = archive_lock::guard(arc_lock);
auto done_path = tmp_path; 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!", log_info("%s: archive has already been extracted!",
done_path.c_str()); done_path.c_str());
return Ok(); 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); 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()); log_info("extracting %s to %s", filename.c_str(), tmp_path.c_str());
while (true) { while (true) {
struct archive_entry* entry; struct archive_entry* entry = nullptr;
auto r = archive_read_next_header(arc, &entry); auto r = archive_read_next_header(arc, &entry);
if (r == ARCHIVE_EOF) { if (r == ARCHIVE_EOF) {
log_info("all done"); log_info("all done");
@ -319,7 +332,7 @@ extract(const std::string& filename, const extract_cb& cb)
archive_error_string(arc))); 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 filter_count = archive_filter_count(arc);
auto_mem<archive_entry> wentry(archive_entry_free); auto_mem<archive_entry> wentry(archive_entry_free);
@ -329,7 +342,7 @@ extract(const std::string& filename, const extract_cb& cb)
desired_pathname = fs::path(filename).filename(); desired_pathname = fs::path(filename).filename();
} }
auto entry_path = tmp_path / desired_pathname; auto entry_path = tmp_path / desired_pathname;
auto prog = cb( auto* prog = cb(
entry_path, entry_path,
archive_entry_size_is_set(entry) ? archive_entry_size(entry) : -1); archive_entry_size_is_set(entry) ? archive_entry_size(entry) : -1);
archive_entry_copy_pathname(wentry, entry_path.c_str()); 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: {} -- {}"), fmt::format(FMT_STRING("unable to write entry: {} -- {}"),
entry_path.string(), entry_path.string(),
archive_error_string(ext))); 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)); TRY(copy_data(filename, arc, entry, ext, entry_path, prog));
} }
r = archive_write_finish_entry(ext); r = archive_write_finish_entry(ext);
@ -358,7 +373,7 @@ extract(const std::string& filename, const extract_cb& cb)
archive_read_close(arc); archive_read_close(arc);
archive_write_close(ext); 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(); return Ok();
} }
@ -400,7 +415,7 @@ cleanup_cache()
(void) std::async(std::launch::async, []() { (void) std::async(std::launch::async, []() {
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
auto cache_path = archive_cache_path(); auto cache_path = archive_cache_path();
auto& cfg = injector::get<const config&>(); const auto& cfg = injector::get<const config&>();
std::vector<fs::path> to_remove; std::vector<fs::path> to_remove;
log_debug("cache-ttl %d", cfg.amc_cache_ttl.count()); log_debug("cache-ttl %d", cfg.amc_cache_ttl.count());

View File

@ -62,6 +62,14 @@ ghc::filesystem::path filename_to_tmp_path(const std::string& filename);
using walk_result_t = Result<void, std::string>; using walk_result_t = Result<void, std::string>;
/**
*
* @feature f0:archive
*
* @param filename
* @param cb
* @return
*/
walk_result_t walk_archive_files( walk_result_t walk_archive_files(
const std::string& filename, const std::string& filename,
const extract_cb& cb, const extract_cb& cb,

View File

@ -186,6 +186,12 @@ struct string_attr {
require(type); require(type);
}; };
string_attr(const struct line_range& lr,
std::pair<string_attr_type_base*, string_attr_value> value)
: sa_range(lr), sa_type2(value.first), sa_value2(value.second)
{
}
string_attr() : sa_type(nullptr){}; string_attr() : sa_type(nullptr){};
bool operator<(const struct string_attr& rhs) const bool operator<(const struct string_attr& rhs) const
@ -202,6 +208,8 @@ struct string_attr {
string_attr_type_t sa_type; string_attr_type_t sa_type;
string_attr_value_t sa_value; string_attr_value_t sa_value;
std::string sa_str_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. */ /** A map of line ranges to attributes for that range. */

View File

@ -1,58 +1,59 @@
add_library( add_library(
base STATIC base STATIC
../config.h.in ../config.h.in
auto_pid.cc auto_pid.cc
date_time_scanner.cc date_time_scanner.cc
fs_util.cc fs_util.cc
humanize.cc humanize.cc
humanize.network.cc humanize.network.cc
humanize.time.cc humanize.time.cc
intern_string.cc intern_string.cc
is_utf8.cc is_utf8.cc
isc.cc isc.cc
lnav.gzip.cc lnav.gzip.cc
lnav_log.cc lnav_log.cc
network.tcp.cc network.tcp.cc
paths.cc paths.cc
string_util.cc string_util.cc
strnatcmp.c strnatcmp.c
time_util.cc time_util.cc
auto_pid.hh auto_fd.hh
date_time_scanner.hh auto_pid.hh
enum_util.hh date_time_scanner.hh
fs_util.hh enum_util.hh
func_util.hh fs_util.hh
future_util.hh func_util.hh
humanize.hh future_util.hh
humanize.network.hh humanize.hh
humanize.time.hh humanize.network.hh
injector.hh humanize.time.hh
injector.bind.hh injector.hh
intern_string.hh injector.bind.hh
is_utf8.hh intern_string.hh
isc.hh is_utf8.hh
lrucache.hpp isc.hh
math_util.hh lrucache.hpp
network.tcp.hh math_util.hh
paths.hh network.tcp.hh
result.h paths.hh
strnatcmp.h result.h
time_util.hh) strnatcmp.h
time_util.hh)
target_include_directories(base PUBLIC . .. ../fmtlib ../third-party target_include_directories(base PUBLIC . .. ../fmtlib ../third-party
${CMAKE_CURRENT_BINARY_DIR}/..) ${CMAKE_CURRENT_BINARY_DIR}/..)
target_link_libraries(base cppfmt pcre::libpcre ncurses::libcurses pthread) target_link_libraries(base cppfmt pcre::libpcre ncurses::libcurses pthread)
add_executable( add_executable(
test_base test_base
humanize.file_size.tests.cc humanize.file_size.tests.cc
humanize.network.tests.cc humanize.network.tests.cc
humanize.time.tests.cc humanize.time.tests.cc
intern_string.tests.cc intern_string.tests.cc
lnav.gzip.tests.cc lnav.gzip.tests.cc
string_util.tests.cc string_util.tests.cc
network.tcp.tests.cc network.tcp.tests.cc
test_base.cc) test_base.cc)
target_include_directories(test_base PUBLIC ../third-party/doctest-root) target_include_directories(test_base PUBLIC ../third-party/doctest-root)
target_link_libraries(test_base base pcrepp ZLIB::ZLIB) target_link_libraries(test_base base pcrepp ZLIB::ZLIB)
add_test(NAME test_base COMMAND test_base) add_test(NAME test_base COMMAND test_base)

View File

@ -19,6 +19,7 @@ AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
noinst_LIBRARIES = libbase.a noinst_LIBRARIES = libbase.a
noinst_HEADERS = \ noinst_HEADERS = \
auto_fd.hh \
auto_pid.hh \ auto_pid.hh \
date_time_scanner.hh \ date_time_scanner.hh \
enum_util.hh \ enum_util.hh \

View File

@ -85,14 +85,14 @@ public:
return auto_fd{}; return auto_fd{};
} }
auto new_fd = dup(fd); auto new_fd = ::dup(fd);
if (new_fd == -1) { if (new_fd == -1) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
return auto_fd(new_fd); return auto_fd(new_fd);
}; }
/** /**
* Construct an auto_fd to manage the given file descriptor. * Construct an auto_fd to manage the given file descriptor.
@ -102,7 +102,7 @@ public:
explicit auto_fd(int fd = -1) : af_fd(fd) explicit auto_fd(int fd = -1) : af_fd(fd)
{ {
require(fd >= -1); require(fd >= -1);
}; }
/** /**
* Non-const copy constructor. Management of the file descriptor will be * Non-const copy constructor. Management of the file descriptor will be
@ -119,12 +119,18 @@ public:
* *
* @param af The source of the file descriptor. * @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(); throw std::bad_alloc();
} }
};
return auto_fd{new_fd};
}
/** /**
* Destructor that will close the file descriptor managed by this object. * 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 != fd) {
if (this->af_fd != -1) { 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; this->af_fd = fd;
} }
@ -240,7 +254,7 @@ public:
return Err(std::string(strerror(errno))); 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) explicit auto_pipe(int child_fd = -1, int child_flags = O_RDONLY)

View File

@ -36,7 +36,21 @@
namespace lnav { namespace lnav {
namespace filesystem { namespace filesystem {
Result<std::pair<ghc::filesystem::path, int>, std::string> Result<auto_fd, std::string>
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::pair<ghc::filesystem::path, auto_fd>, std::string>
open_temp_file(const ghc::filesystem::path& pattern) open_temp_file(const ghc::filesystem::path& pattern)
{ {
auto pattern_str = pattern.string(); auto pattern_str = pattern.string();
@ -51,7 +65,7 @@ open_temp_file(const ghc::filesystem::path& pattern)
strerror(errno))); 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<std::string, std::string> Result<std::string, std::string>

View File

@ -33,6 +33,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "auto_fd.hh"
#include "ghc/filesystem.hpp" #include "ghc/filesystem.hpp"
#include "result.h" #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); return open(path.c_str(), flags, mode);
} }
Result<std::pair<ghc::filesystem::path, int>, std::string> open_temp_file( Result<auto_fd, std::string> open_file(const ghc::filesystem::path& path,
int flags,
mode_t mode);
Result<std::pair<ghc::filesystem::path, auto_fd>, std::string> open_temp_file(
const ghc::filesystem::path& pattern); const ghc::filesystem::path& pattern);
Result<std::string, std::string> read_file(const ghc::filesystem::path& path); Result<std::string, std::string> read_file(const ghc::filesystem::path& path);

View File

@ -66,7 +66,7 @@ connect(const char* hostname, const char* servname)
strerror(rc))); strerror(rc)));
} }
return Ok(retval); return Ok(std::move(retval));
} }
} // namespace tcp } // namespace tcp

View File

@ -770,25 +770,29 @@ struct Result {
return !ok_; return !ok_;
} }
T expect(const char* str) const { T expect(const char* str)
{
if (!isOk()) { if (!isOk()) {
::fprintf(stderr, "%s\n", str); ::fprintf(stderr, "%s\n", str);
std::terminate(); std::terminate();
} }
return expect_impl(std::is_same<T, void>()); return expect_impl(std::is_same<T, void>());
} }
template<typename Func> template<typename Func>
auto map(Func func) const { auto map(Func func)
{
using return_type = decltype(func(T{})); using return_type = decltype(func(T{}));
if (this->isOk()) { if (this->isOk()) {
auto value = this->storage().template get<T>(); auto value = std::move(this->storage().template get<T>());
auto res = func(value); auto res = func(std::move(value));
return Result<return_type, E>(types::Ok<return_type>(std::move(res))); return Result<return_type, E>(
types::Ok<return_type>(std::move(res)));
} }
return Result<return_type, E>(types::Err<E>(this->storage().template get<E>())); return Result<return_type, E>(
types::Err<E>(this->storage().template get<E>()));
} }
template<typename Func, template<typename Func,
@ -901,11 +905,9 @@ struct Result {
} }
template<typename U = T> template<typename U = T>
typename std::enable_if< typename std::enable_if<std::is_same<U, void>::value, U>::type unwrap()
std::is_same<U, void>::value, const
U {
>::type
unwrap() const {
if (isOk()) { if (isOk()) {
return; return;
} }
@ -914,7 +916,8 @@ struct Result {
std::terminate(); std::terminate();
} }
E unwrapErr() const { E unwrapErr() const
{
if (isErr()) { if (isErr()) {
return storage().template get<E>(); return storage().template get<E>();
} }
@ -924,8 +927,11 @@ struct Result {
} }
private: private:
T expect_impl(std::true_type) const { } T expect_impl(std::true_type) const {}
T expect_impl(std::false_type) const { return storage_.template get<T>(); } T expect_impl(std::false_type)
{
return std::move(storage_.template get<T>());
}
bool ok_; bool ok_;
storage_type storage_; storage_type storage_;

View File

@ -33,6 +33,4 @@
#include "config.h" #include "config.h"
using namespace std; std::set<std::string> bookmark_metadata::KNOWN_TAGS;
set<string> bookmark_metadata::KNOWN_TAGS;

View File

@ -47,11 +47,9 @@
#include "sql_util.hh" #include "sql_util.hh"
#include "yajlpp/json_ptr.hh" #include "yajlpp/json_ptr.hh"
using namespace std;
exec_context INIT_EXEC_CONTEXT; 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 SELECT count(*) AS total, min(log_line) AS log_line, log_msg_format
FROM all_logs FROM all_logs
GROUP BY log_msg_format GROUP BY log_msg_format
@ -103,16 +101,17 @@ sql_progress_finished()
lnav_data.ld_views[LNV_DB].redo_search(); lnav_data.ld_views[LNV_DB].redo_search();
} }
Result<string, string> execute_from_file(exec_context& ec, Result<std::string, std::string> execute_from_file(
const ghc::filesystem::path& path, exec_context& ec,
int line_number, const ghc::filesystem::path& path,
char mode, int line_number,
const string& cmdline); char mode,
const std::string& cmdline);
Result<string, string> Result<std::string, std::string>
execute_command(exec_context& ec, const string& cmdline) execute_command(exec_context& ec, const std::string& cmdline)
{ {
vector<string> args; std::vector<std::string> args;
log_info("Executing: %s", cmdline.c_str()); 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"); return ec.make_error("no command to execute");
} }
Result<string, string> Result<std::string, std::string>
execute_sql(exec_context& ec, const string& sql, string& alt_msg) execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
{ {
db_label_source& dls = lnav_data.ld_db_row_source; db_label_source& dls = lnav_data.ld_db_row_source;
auto_mem<sqlite3_stmt> stmt(sqlite3_finalize); auto_mem<sqlite3_stmt> stmt(sqlite3_finalize);
struct timeval start_tv, end_tv; struct timeval start_tv, end_tv;
string stmt_str = trim(sql); std::string stmt_str = trim(sql);
string retval; std::string retval;
int retcode; int retcode;
log_info("Executing SQL: %s", sql.c_str()); 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(""); lnav_data.ld_bottom_source.grep_error("");
if (startswith(stmt_str, ".")) { if (startswith(stmt_str, ".")) {
vector<string> args; std::vector<std::string> args;
split_ws(stmt_str, args); split_ws(stmt_str, args);
auto sql_cmd_map = injector::get<readline_context::command_map_t*, auto sql_cmd_map = injector::get<readline_context::command_map_t*,
@ -164,7 +163,7 @@ execute_sql(exec_context& ec, const string& sql, string& alt_msg)
ec.ec_accumulator->clear(); ec.ec_accumulator->clear();
pair<string, int> source = ec.ec_source.top(); std::pair<std::string, int> source = ec.ec_source.top();
sql_progress_guard progress_guard( sql_progress_guard progress_guard(
sql_progress, sql_progress_finished, source.first, source.second); sql_progress, sql_progress_finished, source.first, source.second);
gettimeofday(&start_tv, nullptr); 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()); param_count = sqlite3_bind_parameter_count(stmt.in());
for (int lpc = 0; lpc < param_count; lpc++) { for (int lpc = 0; lpc < param_count; lpc++) {
map<string, string>::iterator ov_iter; std::map<std::string, std::string>::iterator ov_iter;
const char* name; const char* name;
name = sqlite3_bind_parameter_name(stmt.in(), lpc + 1); 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] == '$') { } else if (name[0] == '$') {
const auto& lvars = ec.ec_local_vars.top(); const auto& lvars = ec.ec_local_vars.top();
const auto& gvars = ec.ec_global_vars; const auto& gvars = ec.ec_global_vars;
map<string, string>::const_iterator local_var, global_var; std::map<std::string, std::string>::const_iterator local_var,
global_var;
const char* env_value; const char* env_value;
if (lnav_data.ld_window) { if (lnav_data.ld_window) {
@ -409,7 +409,7 @@ execute_sql(exec_context& ec, const string& sql, string& alt_msg)
return Ok(retval); return Ok(retval);
} }
static Result<string, string> static Result<std::string, std::string>
execute_file_contents(exec_context& ec, execute_file_contents(exec_context& ec,
const ghc::filesystem::path& path, const ghc::filesystem::path& path,
bool multiline) bool multiline)
@ -417,7 +417,7 @@ execute_file_contents(exec_context& ec,
static ghc::filesystem::path stdin_path("-"); static ghc::filesystem::path stdin_path("-");
static ghc::filesystem::path dev_stdin_path("/dev/stdin"); static ghc::filesystem::path dev_stdin_path("/dev/stdin");
string retval; std::string retval;
FILE* file; FILE* file;
if (path == stdin_path || path == dev_stdin_path) { if (path == stdin_path || path == dev_stdin_path) {
@ -433,7 +433,7 @@ execute_file_contents(exec_context& ec,
auto_mem<char> line; auto_mem<char> line;
size_t line_max_size; size_t line_max_size;
ssize_t line_size; ssize_t line_size;
string cmdline; std::string cmdline;
char mode = '\0'; char mode = '\0';
ec.ec_path_stack.emplace_back(path.parent_path()); ec.ec_path_stack.emplace_back(path.parent_path());
@ -460,7 +460,7 @@ execute_file_contents(exec_context& ec,
starting_line_number = line_number; starting_line_number = line_number;
mode = line[0]; mode = line[0];
cmdline = string(&line[1]); cmdline = std::string(&line[1]);
break; break;
default: default:
if (multiline) { if (multiline) {
@ -490,12 +490,12 @@ execute_file_contents(exec_context& ec,
return Ok(retval); return Ok(retval);
} }
Result<string, string> Result<std::string, std::string>
execute_file(exec_context& ec, const string& path_and_args, bool multiline) execute_file(exec_context& ec, const std::string& path_and_args, bool multiline)
{ {
available_scripts scripts; available_scripts scripts;
vector<string> split_args; std::vector<std::string> split_args;
string retval, msg; std::string retval, msg;
shlex lexer(path_and_args); shlex lexer(path_and_args);
log_info("Executing file: %s", path_and_args.c_str()); 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 script_name = split_args[0];
auto& vars = ec.ec_local_vars.top(); auto& vars = ec.ec_local_vars.top();
char env_arg_name[32]; char env_arg_name[32];
string star, open_error = "file not found"; std::string star, open_error = "file not found";
add_ansi_vars(vars); add_ansi_vars(vars);
@ -532,7 +532,7 @@ execute_file(exec_context& ec, const string& path_and_args, bool multiline)
} }
vars["__all__"] = star; vars["__all__"] = star;
vector<script_metadata> paths_to_exec; std::vector<script_metadata> paths_to_exec;
find_format_scripts(lnav_data.ld_config_paths, scripts); find_format_scripts(lnav_data.ld_config_paths, scripts);
auto iter = scripts.as_scripts.find(script_name); 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); return Ok(retval);
} }
Result<string, string> Result<std::string, std::string>
execute_from_file(exec_context& ec, execute_from_file(exec_context& ec,
const ghc::filesystem::path& path, const ghc::filesystem::path& path,
int line_number, int line_number,
char mode, 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); auto _sg = ec.enter_source(path.string(), line_number);
switch (mode) { switch (mode) {
@ -621,10 +621,10 @@ execute_from_file(exec_context& ec,
return Ok(retval); return Ok(retval);
} }
Result<string, string> Result<std::string, std::string>
execute_any(exec_context& ec, const string& cmdline_with_mode) 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] { auto _cleanup = finally([&ec] {
if (ec.is_read_write() && if (ec.is_read_write() &&
// only rebuild in a script or non-interactive mode so we don't // 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 void
execute_init_commands(exec_context& ec, execute_init_commands(
vector<pair<Result<string, string>, string> >& msgs) exec_context& ec,
std::vector<std::pair<Result<std::string, std::string>, std::string>>& msgs)
{ {
if (lnav_data.ld_cmd_init_done) { if (lnav_data.ld_cmd_init_done) {
return; return;
@ -673,7 +674,7 @@ execute_init_commands(exec_context& ec,
log_info("Executing initial commands"); log_info("Executing initial commands");
for (auto& cmd : lnav_data.ld_commands) { for (auto& cmd : lnav_data.ld_commands) {
string alt_msg; std::string alt_msg;
wait_for_children(); wait_for_children();
@ -705,9 +706,10 @@ execute_init_commands(exec_context& ec,
if (!lnav_data.ld_pt_search.empty()) { if (!lnav_data.ld_pt_search.empty()) {
#ifdef HAVE_LIBCURL #ifdef HAVE_LIBCURL
auto pt = make_shared<papertrail_proc>(lnav_data.ld_pt_search.substr(3), auto pt = std::make_shared<papertrail_proc>(
lnav_data.ld_pt_min_time, lnav_data.ld_pt_search.substr(3),
lnav_data.ld_pt_max_time); 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( lnav_data.ld_active_files.fc_file_names[lnav_data.ld_pt_search].with_fd(
pt->copy_fd()); pt->copy_fd());
isc::to<curl_looper&, services::curl_streamer_t>().send( isc::to<curl_looper&, services::curl_streamer_t>().send(
@ -744,7 +746,7 @@ sql_callback(exec_context& ec, sqlite3_stmt* stmt)
if (dls.dls_headers.empty()) { if (dls.dls_headers.empty()) {
for (lpc = 0; lpc < ncols; lpc++) { for (lpc = 0; lpc < ncols; lpc++) {
int type = sqlite3_column_type(stmt, 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; bool graphable;
graphable = ((type == SQLITE_INTEGER || type == SQLITE_FLOAT) graphable = ((type == SQLITE_INTEGER || type == SQLITE_FLOAT)
@ -782,8 +784,8 @@ sql_callback(exec_context& ec, sqlite3_stmt* stmt)
return retval; return retval;
} }
future<string> std::future<std::string>
pipe_callback(exec_context& ec, const string& cmdline, auto_fd& fd) pipe_callback(exec_context& ec, const std::string& cmdline, auto_fd& fd)
{ {
auto out = ec.get_output(); 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); fwrite(buffer, rc, 1, file);
} }
return string(); return std::string();
}); });
} else { } else {
auto pp = make_shared<piper_proc>( auto tmp_fd
fd, = lnav::filesystem::open_temp_file(
false, ghc::filesystem::temp_directory_path() / "lnav.out.XXXXXX")
lnav::filesystem::open_temp_file( .map([](auto pair) {
ghc::filesystem::temp_directory_path() / "lnav.out.XXXXXX") ghc::filesystem::remove(pair.first);
.map([](auto pair) {
ghc::filesystem::remove(pair.first);
return pair; return std::move(pair.second);
}) })
.expect("Cannot create temporary file for callback") .expect("Cannot create temporary file for callback");
.second); auto pp = std::make_shared<piper_proc>(
std::move(fd), false, std::move(tmp_fd));
static int exec_count = 0; static int exec_count = 0;
lnav_data.ld_pipers.push_back(pp); 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) { for (const auto& iter : lnav_config.lc_global_vars) {
shlex subber(iter.second); shlex subber(iter.second);
string str; std::string str;
if (!subber.eval(str, ec.ec_global_vars)) { if (!subber.eval(str, ec.ec_global_vars)) {
log_error("Unable to evaluate global variable value: %s", log_error("Unable to evaluate global variable value: %s",
@ -867,7 +868,9 @@ exec_context::get_error_prefix()
} }
void 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()); log_info("redirecting command output to: %s", name.c_str());
this->ec_output_stack.back().second | [](auto out) { this->ec_output_stack.back().second | [](auto out) {

View File

@ -36,7 +36,7 @@
#include <sqlite3.h> #include <sqlite3.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "bookmarks.hh" #include "bookmarks.hh"
#include "fmt/format.h" #include "fmt/format.h"
#include "ghc/filesystem.hpp" #include "ghc/filesystem.hpp"
@ -48,12 +48,11 @@ struct exec_context;
class attr_line_t; class attr_line_t;
class logline_value; 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); int sql_callback(exec_context& ec, sqlite3_stmt* stmt);
typedef std::future<std::string> (*pipe_callback_t)(exec_context& ec, using pipe_callback_t
const std::string& cmdline, = std::future<std::string> (*)(exec_context&, const std::string&, auto_fd&);
auto_fd& fd);
struct exec_context { struct exec_context {
enum class perm_t { enum class perm_t {

View File

@ -38,7 +38,7 @@
# include "curl_looper.hh" # include "curl_looper.hh"
using namespace std; using namespace std::chrono_literals;
struct curl_request_eq { struct curl_request_eq {
explicit curl_request_eq(const std::string& name) : cre_name(name){}; explicit curl_request_eq(const std::string& name) : cre_name(name){};
@ -49,7 +49,7 @@ struct curl_request_eq {
}; };
bool operator()( bool operator()(
const pair<mstime_t, std::shared_ptr<curl_request>>& pair) const const std::pair<mstime_t, std::shared_ptr<curl_request>>& pair) const
{ {
return this->cre_name == pair.second->get_name(); return this->cre_name == pair.second->get_name();
}; };

View File

@ -34,8 +34,6 @@
#include "config.h" #include "config.h"
#include "spookyhash/SpookyV2.h" #include "spookyhash/SpookyV2.h"
using namespace std;
data_format data_parser::FORMAT_SEMI("semi", DT_COMMA, DT_SEMI); 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_COMMA("comma", DT_INVALID, DT_COMMA);
data_format data_parser::FORMAT_PLAIN("plain", DT_INVALID, DT_INVALID); data_format data_parser::FORMAT_PLAIN("plain", DT_INVALID, DT_INVALID);

View File

@ -36,8 +36,6 @@
#include "config.h" #include "config.h"
#include "pcrepp/pcrepp.hh" #include "pcrepp/pcrepp.hh"
using namespace std;
static struct { static struct {
const char* name; const char* name;
pcrepp pcre; pcrepp pcre;

View File

@ -34,8 +34,6 @@
#include "config.h" #include "config.h"
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
using namespace std;
static void static void
element_to_json(yajl_gen gen, data_parser& dp, const data_parser::element& elem) 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: { case DNT_PAIR: {
const data_parser::element& pair_elem = elem.get_pair_elem(); 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()); = dp.get_element_string(pair_elem.e_sub_elements->front());
if (!key_str.empty()) { if (!key_str.empty()) {
@ -137,10 +135,10 @@ map_elements_to_json(yajl_gen gen,
data_parser::element_list_t* el) data_parser::element_list_t* el)
{ {
bool unique_names = el->size() > 1; bool unique_names = el->size() > 1;
vector<string> names; std::vector<std::string> names;
for (auto& iter : *el) { 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) { if (pvalue.value_token() == DT_INVALID) {
log_debug("invalid!!"); log_debug("invalid!!");

View File

@ -36,8 +36,6 @@
#include "base/lnav_log.hh" #include "base/lnav_log.hh"
#include "config.h" #include "config.h"
using namespace std;
extern char** environ; extern char** environ;
const char* const ENVIRON_CREATE_STMT = R"( const char* const ENVIRON_CREATE_STMT = R"(

View File

@ -40,8 +40,6 @@
#include "vtab_module.hh" #include "vtab_module.hh"
#include "vtab_module_json.hh" #include "vtab_module_json.hh"
using namespace std;
json_string extract(const char* str); json_string extract(const char* str);
void void
@ -65,7 +63,7 @@ field_overlay_source::build_summary_lines(const listview_curses& lv)
if (free_rows < 2 || !this->fos_show_status) { if (free_rows < 2 || !this->fos_show_status) {
this->fos_summary_lines.clear(); this->fos_summary_lines.clear();
} else { } else {
string time_span; std::string time_span;
double error_rate = 0.0; double error_rate = 0.0;
if (lv.get_inner_height() == 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 long computed_rate_len
= lrint(ceil((recent_error_rate * 40.0) = lrint(ceil((recent_error_rate * 40.0)
/ long_error_rate)); / 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, error_rate,
time_span.c_str()); time_span.c_str());
} }
string& sum_msg = sum_line.get_string(); const auto& sum_msg = sum_line.get_string();
sum_line sum_line
.with_attr(string_attr( .with_attr(string_attr(
line_range(sum_msg.find("Error rate"), 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]; char old_timestamp[64], curr_timestamp[64], orig_timestamp[64];
struct timeval curr_tv, offset_tv, orig_tv, diff_tv = {0, 0}; struct timeval curr_tv, offset_tv, orig_tv, diff_tv = {0, 0};
attr_line_t time_line; attr_line_t time_line;
string& time_str = time_line.get_string(); auto& time_str = time_line.get_string();
struct line_range time_lr; struct line_range time_lr;
sql_strftime(curr_timestamp, sql_strftime(curr_timestamp,
@ -368,7 +366,8 @@ field_overlay_source::build_field_lines(const listview_curses& lv)
if (!meta.lvm_struct_name.empty()) { if (!meta.lvm_struct_name.empty()) {
this_key_size += meta.lvm_struct_name.size() + 11; 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(); 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); colname = this->fos_log_helper.ldh_namer->add_column(colname);
this->fos_unknown_key_size 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(); 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_format = lv.lv_meta.lvm_format.value();
auto curr_elf = dynamic_cast<external_log_format*>(curr_format); auto curr_elf = dynamic_cast<external_log_format*>(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; attr_line_t al;
string str, value_str = lv.to_string(); std::string str, value_str = lv.to_string();
if (curr_format != last_format) { if (curr_format != last_format) {
this->fos_lines.emplace_back(" Known message fields for table " this->fos_lines.emplace_back(" Known message fields for table "

View File

@ -158,8 +158,9 @@ file_collection::merge(file_collection& other)
other.fc_synced_files.end()); other.fc_synced_files.end());
this->fc_name_to_errors.insert(other.fc_name_to_errors.begin(), this->fc_name_to_errors.insert(other.fc_name_to_errors.begin(),
other.fc_name_to_errors.end()); other.fc_name_to_errors.end());
this->fc_file_names.insert(other.fc_file_names.begin(), this->fc_file_names.insert(
other.fc_file_names.end()); std::make_move_iterator(other.fc_file_names.begin()),
std::make_move_iterator(other.fc_file_names.end()));
if (!other.fc_files.empty()) { if (!other.fc_files.empty()) {
for (const auto& lf : other.fc_files) { for (const auto& lf : other.fc_files) {
this->fc_name_to_errors.erase(lf->get_filename()); 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) { if (loo.loo_fd != -1) {
rc = fstat(loo.loo_fd, &st); 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 { } else {
rc = stat(filename.c_str(), &st); rc = stat(filename.c_str(), &st);
} }
@ -292,7 +302,7 @@ file_collection::watch_logfile(const std::string& filename,
auto func = [filename, auto func = [filename,
st, st,
loo, loo2 = std::move(loo),
prog = this->fc_progress, prog = this->fc_progress,
errs = this->fc_name_to_errors]() mutable { errs = this->fc_name_to_errors]() mutable {
file_collection retval; file_collection retval;
@ -304,7 +314,7 @@ file_collection::watch_logfile(const std::string& filename,
auto ff = detect_file_format(filename); auto ff = detect_file_format(filename);
loo.loo_file_format = ff; loo2.loo_file_format = ff;
switch (ff) { switch (ff) {
case file_format_t::SQLITE_DB: case file_format_t::SQLITE_DB:
retval.fc_other_files[filename].ofd_format = ff; retval.fc_other_files[filename].ofd_format = ff;
@ -316,7 +326,7 @@ file_collection::watch_logfile(const std::string& filename,
if (res.isOk()) { if (res.isOk()) {
auto convert_res = res.unwrap(); 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{ retval.fc_child_pollers.emplace_back(child_poller{
std::move(convert_res.cr_child), std::move(convert_res.cr_child),
[filename, [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()) { if (open_res.isOk()) {
retval.fc_files.push_back(open_res.unwrap()); retval.fc_files.push_back(open_res.unwrap());
} else { } else {
@ -368,7 +378,7 @@ file_collection::watch_logfile(const std::string& filename,
std::list<archive_manager::extract_progress>::iterator> std::list<archive_manager::extract_progress>::iterator>
prog_iter_opt; 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 // Don't try to open nested archives
return retval; return retval;
} }
@ -435,7 +445,7 @@ file_collection::watch_logfile(const std::string& filename,
default: default:
log_info("loading new file: filename=%s", filename.c_str()); 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()) { if (open_res.isOk()) {
retval.fc_files.push_back(open_res.unwrap()); retval.fc_files.push_back(open_res.unwrap());
} else { } else {
@ -452,16 +462,16 @@ file_collection::watch_logfile(const std::string& filename,
return retval; return retval;
}; };
return std::async(std::launch::async, func); return std::async(std::launch::async, std::move(func));
} else { }
auto lf = *file_iter;
if (lf->is_valid_filename() && lf->get_filename() != filename) { auto lf = *file_iter;
/* The file is already loaded, but has been found under a different
* name. We just need to update the stored file name. if (lf->is_valid_filename() && lf->get_filename() != filename) {
*/ /* The file is already loaded, but has been found under a different
retval.fc_renamed_files.emplace_back(lf, filename); * 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)); return lnav::futures::make_ready_future(std::move(retval));
@ -513,9 +523,12 @@ file_collection::expand_filename(
} }
file_collection retval; file_collection retval;
logfile_open_options_base loo_base{loo};
isc::to<tailer::looper&, services::remote_tailer_t>().send( isc::to<tailer::looper&, services::remote_tailer_t>().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; retval.fc_other_files[path] = file_format_t::REMOTE;
{ {
this->fc_progress->writeAccess() this->fc_progress->writeAccess()
@ -546,7 +559,7 @@ file_collection::expand_filename(
if ((abspath = realpath(gl->gl_pathv[lpc], nullptr)) == nullptr) if ((abspath = realpath(gl->gl_pathv[lpc], nullptr)) == nullptr)
{ {
auto errmsg = strerror(errno); auto* errmsg = strerror(errno);
if (required) { if (required) {
fprintf(stderr, fprintf(stderr,
@ -576,11 +589,11 @@ file_collection::expand_filename(
std::move(retval))); std::move(retval)));
} }
continue; 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) { 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); }); [&retval](auto& fc) { retval.merge(fc); });
for (auto& pair : this->fc_file_names) { 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); this->expand_filename(fq, pair.first, pair.second, required);
if (this->fc_rotated) { if (this->fc_rotated) {
std::string path = pair.first + ".*"; std::string path = pair.first + ".*";

View File

@ -34,7 +34,7 @@
#include "file_format.hh" #include "file_format.hh"
#include "archive_manager.hh" #include "archive_manager.hh"
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "base/fs_util.hh" #include "base/fs_util.hh"
#include "base/intern_string.hh" #include "base/intern_string.hh"
#include "base/lnav_log.hh" #include "base/lnav_log.hh"

View File

@ -41,10 +41,8 @@
#include "session_data.hh" #include "session_data.hh"
#include "vtab_module.hh" #include "vtab_module.hh"
using namespace std;
struct lnav_file : public tvt_iterator_cursor<lnav_file> { struct lnav_file : public tvt_iterator_cursor<lnav_file> {
using iterator = vector<shared_ptr<logfile>>::iterator; using iterator = std::vector<std::shared_ptr<logfile>>::iterator;
static constexpr const char* NAME = "lnav_file"; static constexpr const char* NAME = "lnav_file";
static constexpr const char* CREATE_STMT = R"( static constexpr const char* CREATE_STMT = R"(
@ -78,7 +76,7 @@ CREATE TABLE lnav_file (
{ {
auto lf = *vc.iter; auto lf = *vc.iter;
const struct stat& st = lf->get_stat(); const struct stat& st = lf->get_stat();
const string& name = lf->get_filename(); const auto& name = lf->get_filename();
auto format = lf->get_format(); auto format = lf->get_format();
const char* format_name = format != nullptr ? format->get_name().get() const char* format_name = format != nullptr ? format->get_name().get()
: nullptr; : nullptr;

View File

@ -37,8 +37,6 @@
#include "readline_highlighters.hh" #include "readline_highlighters.hh"
#include "readline_possibilities.hh" #include "readline_possibilities.hh"
using namespace std;
filter_sub_source::filter_sub_source() filter_sub_source::filter_sub_source()
{ {
this->fss_regex_context.set_highlighter(readline_regex_highlighter) 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; return true;
} }
shared_ptr<text_filter> tf = *(fs.begin() + lv.get_selection()); auto tf = *(fs.begin() + lv.get_selection());
fs.set_filter_enabled(tf, !tf->is_enabled()); fs.set_filter_enabled(tf, !tf->is_enabled());
tss->text_filters_changed(); tss->text_filters_changed();
@ -113,7 +111,7 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch)
return true; return true;
} }
shared_ptr<text_filter> tf = *(fs.begin() + lv.get_selection()); auto tf = *(fs.begin() + lv.get_selection());
if (tf->get_type() == text_filter::INCLUDE) { if (tf->get_type() == text_filter::INCLUDE) {
tf->set_type(text_filter::EXCLUDE); tf->set_type(text_filter::EXCLUDE);
@ -134,7 +132,7 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch)
return true; return true;
} }
shared_ptr<text_filter> tf = *(fs.begin() + lv.get_selection()); auto tf = *(fs.begin() + lv.get_selection());
fs.delete_filter(tf->get_id()); fs.delete_filter(tf->get_id());
lv.reload_data(); lv.reload_data();
@ -153,8 +151,8 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch)
return true; return true;
} }
auto ef = make_shared<empty_filter>(text_filter::type_t::INCLUDE, auto ef = std::make_shared<empty_filter>(
*filter_index); text_filter::type_t::INCLUDE, *filter_index);
fs.add_filter(ef); fs.add_filter(ef);
lv.set_selection(vis_line_t(fs.size() - 1)); lv.set_selection(vis_line_t(fs.size() - 1));
lv.reload_data(); lv.reload_data();
@ -190,8 +188,8 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch)
return true; return true;
} }
auto ef = make_shared<empty_filter>(text_filter::type_t::EXCLUDE, auto ef = std::make_shared<empty_filter>(
*filter_index); text_filter::type_t::EXCLUDE, *filter_index);
fs.add_filter(ef); fs.add_filter(ef);
lv.set_selection(vis_line_t(fs.size() - 1)); lv.set_selection(vis_line_t(fs.size() - 1));
lv.reload_data(); lv.reload_data();
@ -225,7 +223,7 @@ filter_sub_source::list_input_handle_key(listview_curses& lv, int ch)
return true; return true;
} }
shared_ptr<text_filter> tf = *(fs.begin() + lv.get_selection()); auto tf = *(fs.begin() + lv.get_selection());
this->fss_editing = true; 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(); textview_curses* top_view = *lnav_data.ld_view_stack.top();
text_sub_source* tss = top_view->get_sub_source(); text_sub_source* tss = top_view->get_sub_source();
filter_stack& fs = tss->get_filters(); filter_stack& fs = tss->get_filters();
shared_ptr<text_filter> tf = *(fs.begin() + line); auto tf = *(fs.begin() + line);
value_out = " "; value_out = " ";
switch (tf->get_type()) { 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(); textview_curses* top_view = *lnav_data.ld_view_stack.top();
text_sub_source* tss = top_view->get_sub_source(); text_sub_source* tss = top_view->get_sub_source();
filter_stack& fs = tss->get_filters(); filter_stack& fs = tss->get_filters();
shared_ptr<text_filter> tf = *(fs.begin() + line); auto tf = *(fs.begin() + line);
bool selected bool selected
= lnav_data.ld_mode == LNM_FILTER && line == tc.get_selection(); = 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(); textview_curses* top_view = *lnav_data.ld_view_stack.top();
text_sub_source* tss = top_view->get_sub_source(); text_sub_source* tss = top_view->get_sub_source();
filter_stack& fs = tss->get_filters(); filter_stack& fs = tss->get_filters();
shared_ptr<text_filter> tf = *(fs.begin() + line); auto tf = *(fs.begin() + line);
return 8 + tf->get_id().size(); 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(); auto iter = fs.begin() + this->tss_view->get_selection();
shared_ptr<text_filter> tf = *iter; auto tf = *iter;
string new_value = rc->get_line_buffer(); auto new_value = rc->get_line_buffer();
switch (tf->get_lang()) { switch (tf->get_lang()) {
case filter_lang_t::NONE: 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(); text_sub_source* tss = top_view->get_sub_source();
filter_stack& fs = tss->get_filters(); filter_stack& fs = tss->get_filters();
auto iter = fs.begin() + this->tss_view->get_selection(); auto iter = fs.begin() + this->tss_view->get_selection();
shared_ptr<text_filter> tf = *iter; auto tf = *iter;
string new_value = rc->get_value(); auto new_value = rc->get_value();
if (new_value.empty()) { if (new_value.empty()) {
this->rl_abort(rc); this->rl_abort(rc);
@ -534,10 +532,10 @@ filter_sub_source::rl_perform(readline_curses* rc)
tf->lf_deleted = true; tf->lf_deleted = true;
tss->text_filters_changed(); tss->text_filters_changed();
auto pf = make_shared<pcre_filter>(tf->get_type(), auto pf = std::make_shared<pcre_filter>(tf->get_type(),
new_value, new_value,
tf->get_index(), tf->get_index(),
code.release()); code.release());
*iter = pf; *iter = pf;
tss->text_filters_changed(); 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(); text_sub_source* tss = top_view->get_sub_source();
filter_stack& fs = tss->get_filters(); filter_stack& fs = tss->get_filters();
auto iter = fs.begin() + this->tss_view->get_selection(); auto iter = fs.begin() + this->tss_view->get_selection();
shared_ptr<text_filter> tf = *iter; auto tf = *iter;
lnav_data.ld_log_source.set_preview_sql_filter(nullptr); lnav_data.ld_log_source.set_preview_sql_filter(nullptr);
lnav_data.ld_filter_help_status_source.fss_prompt.clear(); 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->fss_match_view.set_height(0_vl);
this->tss_view->set_needs_update(); this->tss_view->set_needs_update();
} else { } else {
string current_match = rc->get_match_string(); auto current_match = rc->get_match_string();
attr_line_t al; attr_line_t al;
vis_line_t line, selected_line; vis_line_t line, selected_line;

View File

@ -15,6 +15,8 @@ def main(args):
value = format_dict[key] value = format_dict[key]
if not isinstance(value, dict): if not isinstance(value, dict):
continue continue
if 'title' not in value:
raise Exception("format '%s' is missing 'title'" % key)
out.writerow((value['title'], key, value['description'])) out.writerow((value['title'], key, value['description']))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -2,14 +2,17 @@
"$schema": "https://lnav.org/schemas/format-v1.schema.json", "$schema": "https://lnav.org/schemas/format-v1.schema.json",
"pcap_log": { "pcap_log": {
"json": true, "json": true,
"description": "pcap log format", "title": "Packet Capture",
"description": "Internal format for pcap files",
"mime-types": [ "mime-types": [
"application/vnd.tcpdump.pcap" "application/vnd.tcpdump.pcap"
], ],
"multiline": false, "multiline": false,
"convert-to-local-time": true, "convert-to-local-time": true,
"line-format": [ "line-format": [
{ "field": "time" }, {
"field": "time"
},
" ", " ",
{ {
"field": "source", "field": "source",
@ -35,7 +38,9 @@
"align": "right" "align": "right"
}, },
" ", " ",
{ "field": "info" } {
"field": "info"
}
], ],
"level": { "level": {
"warning": "^6291456$", "warning": "^6291456$",

View File

@ -44,7 +44,6 @@
#include "sqlite3.h" #include "sqlite3.h"
#include "vtab_module.hh" #include "vtab_module.hh"
using namespace std;
using namespace mapbox; using namespace mapbox;
static util::variant<const char*, string_fragment> static util::variant<const char*, string_fragment>
@ -95,8 +94,8 @@ sql_dirname(const char* path_in)
return path_in[0] == '/' ? "/" : "."; return path_in[0] == '/' ? "/" : ".";
} }
static nonstd::optional<string> static nonstd::optional<std::string>
sql_joinpath(const vector<const char*>& paths) sql_joinpath(const std::vector<const char*>& paths)
{ {
std::string full_path; std::string full_path;
@ -123,7 +122,7 @@ sql_joinpath(const vector<const char*>& paths)
return full_path; return full_path;
} }
static string static std::string
sql_readlink(const char* path) sql_readlink(const char* path)
{ {
struct stat st; struct stat st;
@ -145,10 +144,10 @@ sql_readlink(const char* path)
"unable to read link: {} -- {}", path, strerror(errno)); "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) sql_realpath(const char* path)
{ {
char resolved_path[PATH_MAX]; char resolved_path[PATH_MAX];

View File

@ -41,8 +41,6 @@
#include "sql_util.hh" #include "sql_util.hh"
#include "vtab_module.hh" #include "vtab_module.hh"
using namespace std;
enum { enum {
FSTAT_COL_PARENT, FSTAT_COL_PARENT,
FSTAT_COL_NAME, FSTAT_COL_NAME,
@ -65,6 +63,9 @@ enum {
FSTAT_COL_PATTERN, FSTAT_COL_PATTERN,
}; };
/**
* @feature f0:sql.tables.fstat
*/
struct fstat_table { struct fstat_table {
static constexpr const char* NAME = "fstat"; static constexpr const char* NAME = "fstat";
static constexpr const char* CREATE_STMT = R"( static constexpr const char* CREATE_STMT = R"(
@ -93,7 +94,7 @@ CREATE TABLE fstat (
struct cursor { struct cursor {
sqlite3_vtab_cursor base; sqlite3_vtab_cursor base;
string c_pattern; std::string c_pattern;
static_root_mem<glob_t, globfree> c_glob; static_root_mem<glob_t, globfree> c_glob;
size_t c_path_index{0}; size_t c_path_index{0};
struct stat c_stat; struct stat c_stat;

View File

@ -46,8 +46,6 @@
#include "lnav_util.hh" #include "lnav_util.hh"
#include "vis_line.hh" #include "vis_line.hh"
using namespace std;
template<typename LineType> template<typename LineType>
grep_proc<LineType>::grep_proc(pcre* code, grep_proc_source<LineType>& gps) grep_proc<LineType>::grep_proc(pcre* code, grep_proc_source<LineType>& gps)
: gp_pcre(code), gp_source(gps) : gp_pcre(code), gp_source(gps)
@ -66,7 +64,7 @@ grep_proc<LineType>::~grep_proc()
template<typename LineType> template<typename LineType>
void void
grep_proc<LineType>::handle_match( grep_proc<LineType>::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; int lpc;
@ -152,7 +150,7 @@ void
grep_proc<LineType>::child_loop() grep_proc<LineType>::child_loop()
{ {
char outbuf[BUFSIZ * 2]; char outbuf[BUFSIZ * 2];
string line_value; std::string line_value;
/* Make sure buffering is on, not sure of the state in the parent. */ /* Make sure buffering is on, not sure of the state in the parent. */
if (setvbuf(stdout, outbuf, _IOFBF, BUFSIZ * 2) < 0) { if (setvbuf(stdout, outbuf, _IOFBF, BUFSIZ * 2) < 0) {

View File

@ -42,7 +42,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "auto_mem.hh" #include "auto_mem.hh"
#include "base/lnav_log.hh" #include "base/lnav_log.hh"
#include "line_buffer.hh" #include "line_buffer.hh"

View File

@ -51,8 +51,6 @@
#include "termios_guard.hh" #include "termios_guard.hh"
#include "xterm_mouse.hh" #include "xterm_mouse.hh"
using namespace std;
class logline_helper { class logline_helper {
public: public:
logline_helper(logfile_sub_source& lss) logline_helper(logfile_sub_source& lss)
@ -101,14 +99,14 @@ public:
{ {
const char* start = this->lh_msg_buffer.get_data(); 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; logfile_sub_source& lh_sub_source;
vis_line_t lh_current_line; vis_line_t lh_current_line;
shared_buffer_ref lh_msg_buffer; shared_buffer_ref lh_msg_buffer;
string_attrs_t lh_string_attrs; string_attrs_t lh_string_attrs;
vector<logline_value> lh_line_values; std::vector<logline_value> lh_line_values;
}; };
static int static int
@ -133,7 +131,7 @@ key_sql_callback(exec_context& ec, sqlite3_stmt* stmt)
} }
vars[column_name] vars[column_name]
= string((const char*) sqlite3_column_text(stmt, lpc)); = std::string((const char*) sqlite3_column_text(stmt, lpc));
} }
return 0; return 0;
@ -149,12 +147,12 @@ handle_keyseq(const char* keyseq)
return false; return false;
} }
vector<logline_value> values; std::vector<logline_value> values;
exec_context ec(&values, key_sql_callback, pipe_callback); exec_context ec(&values, key_sql_callback, pipe_callback);
auto& var_stack = ec.ec_local_vars; auto& var_stack = ec.ec_local_vars;
ec.ec_global_vars = lnav_data.ld_exec_context.ec_global_vars; ec.ec_global_vars = lnav_data.ld_exec_context.ec_global_vars;
var_stack.push(map<string, string>()); var_stack.push(std::map<std::string, std::string>());
auto& vars = var_stack.top(); auto& vars = var_stack.top();
vars["keyseq"] = keyseq; vars["keyseq"] = keyseq;
const auto& kc = iter->second; const auto& kc = iter->second;
@ -166,7 +164,7 @@ handle_keyseq(const char* keyseq)
if (!kc.kc_alt_msg.empty()) { if (!kc.kc_alt_msg.empty()) {
shlex lexer(kc.kc_alt_msg); shlex lexer(kc.kc_alt_msg);
string expanded_msg; std::string expanded_msg;
if (lexer.eval(expanded_msg, if (lexer.eval(expanded_msg,
{ {
@ -339,7 +337,7 @@ handle_paging_key(int ch)
execute_command( execute_command(
ec, ec,
"zoom-to " "zoom-to "
+ string( + std::string(
lnav_zoom_strings[lnav_data.ld_zoom_level - 1])); lnav_zoom_strings[lnav_data.ld_zoom_level - 1]));
} }
break; break;
@ -351,7 +349,7 @@ handle_paging_key(int ch)
execute_command( execute_command(
ec, ec,
"zoom-to " "zoom-to "
+ string( + std::string(
lnav_zoom_strings[lnav_data.ld_zoom_level + 1])); lnav_zoom_strings[lnav_data.ld_zoom_level + 1]));
} }
break; break;
@ -424,10 +422,10 @@ handle_paging_key(int ch)
== lnav_data.ld_last_user_mark.end()) { == lnav_data.ld_last_user_mark.end()) {
alerter::singleton().chime(); alerter::singleton().chime();
} else { } else {
int start_line = min((int) tc->get_top(), int start_line = std::min((int) tc->get_top(),
lnav_data.ld_last_user_mark[tc] + 1); lnav_data.ld_last_user_mark[tc] + 1);
int end_line = max((int) tc->get_top(), int end_line = std::max((int) tc->get_top(),
lnav_data.ld_last_user_mark[tc] - 1); lnav_data.ld_last_user_mark[tc] - 1);
tc->toggle_user_mark(&textview_curses::BM_USER, tc->toggle_user_mark(&textview_curses::BM_USER,
vis_line_t(start_line), vis_line_t(start_line),
@ -636,7 +634,8 @@ handle_paging_key(int ch)
lnav_data.ld_rl_view->set_value(""); lnav_data.ld_rl_view->set_value("");
tc->set_top(next_helper.lh_current_line); tc->set_top(next_helper.lh_current_line);
} else { } 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( lnav_data.ld_rl_view->set_value(err_prefix(
"No more messages found with opid: " + opid_str)); "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"); lnav_data.ld_rl_view->set_value("Graphing all values");
}, },
[&](stacked_bar_chart_base::show_one) { [&](stacked_bar_chart_base::show_one) {
string colname; std::string colname;
chart.get_ident_to_show(colname); chart.get_ident_to_show(colname);
lnav_data.ld_rl_view->set_value( lnav_data.ld_rl_view->set_value(

View File

@ -52,8 +52,6 @@
#include "fmtlib/fmt/format.h" #include "fmtlib/fmt/format.h"
#include "line_buffer.hh" #include "line_buffer.hh"
using namespace std;
static const ssize_t DEFAULT_INCREMENT = 128 * 1024; static const ssize_t DEFAULT_INCREMENT = 128 * 1024;
static const ssize_t MAX_COMPRESSED_BUFFER_SIZE = 32 * 1024 * 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() line_buffer::gz_indexed::gz_indexed()
{ {
if ((this->inbuf = (Bytef*) malloc(Z_BUFSIZE)) == NULL) { 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) lb_last_line_offset(-1)
{ {
if ((this->lb_buffer = (char*) malloc(this->lb_buffer_max)) == nullptr) { if ((this->lb_buffer = (char*) malloc(this->lb_buffer_max)) == nullptr) {
throw bad_alloc(); throw std::bad_alloc();
} }
ensure(this->invariant()); 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) { if ((bz_file = BZ2_bzdopen(bzfd, "r")) == NULL) {
close(bzfd); close(bzfd);
if (errno == 0) { if (errno == 0) {
throw bad_alloc(); throw std::bad_alloc();
} else { } else {
throw error(errno); throw error(errno);
} }
@ -647,7 +645,7 @@ line_buffer::fill_range(file_off_t start, ssize_t max_length)
return retval; return retval;
} }
Result<line_info, string> Result<line_info, std::string>
line_buffer::load_next_line(file_range prev_line) line_buffer::load_next_line(file_range prev_line)
{ {
ssize_t request_size = DEFAULT_INCREMENT; 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 * Don't return anything past the last known line. The caller needs
* to try reading at the offset of the last line again. * 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)) { 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); line_start = this->get_range(fr.fr_offset, avail);

View File

@ -40,8 +40,8 @@
#include <unistd.h> #include <unistd.h>
#include <zlib.h> #include <zlib.h>
#include "auto_fd.hh"
#include "auto_mem.hh" #include "auto_mem.hh"
#include "base/auto_fd.hh"
#include "base/file_range.hh" #include "base/file_range.hh"
#include "base/lnav_log.hh" #include "base/lnav_log.hh"
#include "base/result.h" #include "base/result.h"

View File

@ -39,8 +39,6 @@
#include "base/lnav_log.hh" #include "base/lnav_log.hh"
#include "config.h" #include "config.h"
using namespace std;
list_gutter_source listview_curses::DEFAULT_GUTTER_SOURCE; list_gutter_source listview_curses::DEFAULT_GUTTER_SOURCE;
listview_curses::listview_curses() : lv_scroll(noop_func{}) {} listview_curses::listview_curses() : lv_scroll(noop_func{}) {}
@ -53,7 +51,8 @@ listview_curses::reload_data()
this->lv_left = 0; this->lv_left = 0;
} else { } else {
if (this->lv_top >= this->get_inner_height()) { 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) { if (this->get_inner_height() == 0) {
this->lv_selection = 0_vl; this->lv_selection = 0_vl;
@ -207,8 +206,8 @@ listview_curses::do_update()
row_count = this->get_inner_height(); row_count = this->get_inner_height();
row = this->lv_top; row = this->lv_top;
bottom = y + height; bottom = y + height;
vector<attr_line_t> rows( std::vector<attr_line_t> rows(
min((size_t) height, row_count - (int) this->lv_top)); std::min((size_t) height, row_count - (int) this->lv_top));
this->lv_source->listview_value_for_rows(*this, row, rows); this->lv_source->listview_value_for_rows(*this, row, rows);
while (y < bottom) { while (y < bottom) {
lr.lr_start = this->lv_left; lr.lr_start = this->lv_left;
@ -268,7 +267,7 @@ listview_curses::do_update()
y = this->lv_y + (int) (progress * (double) height); y = this->lv_y + (int) (progress * (double) height);
lines = vis_line_t( 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; for (unsigned int gutter_y = this->lv_y;
gutter_y < (this->lv_y + height); gutter_y < (this->lv_y + height);

View File

@ -154,11 +154,10 @@
# define SYSCONFDIR "/usr/etc" # define SYSCONFDIR "/usr/etc"
#endif #endif
using namespace std;
using namespace std::literals::chrono_literals; using namespace std::literals::chrono_literals;
static bool initial_build = false; static bool initial_build = false;
static multimap<lnav_flags_t, string> DEFAULT_FILES; static std::multimap<lnav_flags_t, std::string> DEFAULT_FILES;
static auto intern_lifetime = intern_string::get_table_lifetime(); static auto intern_lifetime = intern_string::get_table_lifetime();
struct lnav_data_t lnav_data; struct lnav_data_t lnav_data;
@ -377,7 +376,7 @@ setup_logline_table(exec_context& ec)
lnav_data.ld_rl_view->add_possibility( lnav_data.ld_rl_view->add_possibility(
LNM_SQL, 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++) { for (int lpc2 = 0; agg_funcs && agg_funcs[lpc2].zName; lpc2++) {
const FuncDefAgg& func_def = agg_funcs[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( lnav_data.ld_rl_view->add_possibility(
LNM_SQL, 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) { switch (pair.second->ht_context) {
case help_context_t::HC_SQL_FUNCTION: case help_context_t::HC_SQL_FUNCTION:
case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: { case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: {
string poss = pair.first std::string poss = pair.first
+ (pair.second->ht_parameters.empty() ? "()" : ("(")); + (pair.second->ht_parameters.empty() ? "()" : ("("));
lnav_data.ld_rl_view->add_possibility(LNM_SQL, "*", poss); lnav_data.ld_rl_view->add_possibility(LNM_SQL, "*", poss);
@ -423,7 +422,7 @@ class loading_observer : public logfile_observer {
public: public:
loading_observer() : lo_last_offset(0){}; loading_observer() : lo_last_offset(0){};
indexing_result logfile_indexing(const shared_ptr<logfile>& lf, indexing_result logfile_indexing(const std::shared_ptr<logfile>& lf,
file_off_t off, file_off_t off,
file_size_t total) override file_size_t total) override
{ {
@ -452,7 +451,7 @@ public:
return indexing_result::CONTINUE; return indexing_result::CONTINUE;
}; };
static void do_update(const shared_ptr<logfile>& lf) static void do_update(const std::shared_ptr<logfile>& lf)
{ {
if (isendwin()) { if (isendwin()) {
return; return;
@ -546,7 +545,7 @@ class textfile_callback {
public: public:
textfile_callback() : front_file(nullptr), front_top(-1){}; textfile_callback() : front_file(nullptr), front_top(-1){};
void closed_files(const std::vector<shared_ptr<logfile>>& files) void closed_files(const std::vector<std::shared_ptr<logfile>>& files)
{ {
for (const auto& lf : files) { for (const auto& lf : files) {
log_info("closed text files: %s", lf->get_filename().c_str()); log_info("closed text files: %s", lf->get_filename().c_str());
@ -554,7 +553,7 @@ public:
lnav_data.ld_active_files.close_files(files); lnav_data.ld_active_files.close_files(files);
}; };
void promote_file(const shared_ptr<logfile>& lf) void promote_file(const std::shared_ptr<logfile>& lf)
{ {
if (lnav_data.ld_log_source.insert_file(lf)) { if (lnav_data.ld_log_source.insert_file(lf)) {
this->did_promotion = true; this->did_promotion = true;
@ -584,7 +583,7 @@ public:
} }
}; };
void scanned_file(const shared_ptr<logfile>& lf) void scanned_file(const std::shared_ptr<logfile>& lf)
{ {
if (!lnav_data.ld_files_to_front.empty() if (!lnav_data.ld_files_to_front.empty()
&& lnav_data.ld_files_to_front.front().first == lf->get_filename()) && lnav_data.ld_files_to_front.front().first == lf->get_filename())
@ -596,7 +595,7 @@ public:
} }
}; };
shared_ptr<logfile> front_file; std::shared_ptr<logfile> front_file;
int front_top; int front_top;
bool did_promotion{false}; bool did_promotion{false};
}; };
@ -679,7 +678,8 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
log_view.reload_data(); log_view.reload_data();
{ {
unordered_map<string, list<shared_ptr<logfile>>> id_to_files; std::unordered_map<std::string, std::list<std::shared_ptr<logfile>>>
id_to_files;
bool reload = false; bool reload = false;
for (const auto& lf : lnav_data.ld_active_files.fc_files) { 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) { if (lnav_data.ld_flags & flag) {
auto cwd = ghc::filesystem::current_path(); auto cwd = ghc::filesystem::current_path();
pair<multimap<lnav_flags_t, string>::iterator, std::pair<std::multimap<lnav_flags_t, std::string>::iterator,
multimap<lnav_flags_t, string>::iterator> std::multimap<lnav_flags_t, std::string>::iterator>
range; range;
for (range = DEFAULT_FILES.equal_range(flag); for (range = DEFAULT_FILES.equal_range(flag);
range.first != range.second; range.first != range.second;
range.first++) range.first++)
{ {
string path = range.first->second; std::string path = range.first->second;
struct stat st; struct stat st;
if (access(path.c_str(), R_OK) == 0) { if (access(path.c_str(), R_OK) == 0) {
@ -1551,7 +1551,8 @@ looper()
id.id_escape_matcher = match_escape_seq; id.id_escape_matcher = match_escape_seq;
id.id_escape_handler = handle_keyseq; id.id_escape_handler = handle_keyseq;
id.id_key_handler = handle_key; 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) { id.id_unhandled_handler = [](const char* keyseq) {
auto enc_len = lnav_config.lc_ui_keymap.size() * 2; auto enc_len = lnav_config.lc_ui_keymap.size() * 2;
auto encoded_name = (char*) alloca(enc_len); auto encoded_name = (char*) alloca(enc_len);
@ -1589,7 +1590,7 @@ looper()
log_debug("rescan started %p", &active_copy); log_debug("rescan started %p", &active_copy);
active_copy.merge(lnav_data.ld_active_files); active_copy.merge(lnav_data.ld_active_files);
active_copy.fc_progress = lnav_data.ld_active_files.fc_progress; active_copy.fc_progress = lnav_data.ld_active_files.fc_progress;
future<file_collection> rescan_future std::future<file_collection> rescan_future
= std::async(std::launch::async, = std::async(std::launch::async,
&file_collection::rescan_files, &file_collection::rescan_files,
std::move(active_copy), std::move(active_copy),
@ -1607,7 +1608,7 @@ looper()
auto loop_deadline auto loop_deadline
= ui_clock::now() + (session_stage == 0 ? 3s : 50ms); = ui_clock::now() + (session_stage == 0 ? 3s : 50ms);
vector<struct pollfd> pollfds; std::vector<struct pollfd> pollfds;
size_t starting_view_stack_size = lnav_data.ld_view_stack.size(); size_t starting_view_stack_size = lnav_data.ld_view_stack.size();
size_t changes = 0; size_t changes = 0;
int rc; int rc;
@ -1932,7 +1933,9 @@ looper()
if (initial_build) { if (initial_build) {
static bool ran_cleanup = false; static bool ran_cleanup = false;
vector<pair<Result<string, string>, string>> cmd_results; std::vector<std::pair<Result<std::string, std::string>,
std::string>>
cmd_results;
execute_init_commands(ec, cmd_results); execute_init_commands(ec, cmd_results);
@ -2014,8 +2017,9 @@ looper()
int rc, child_stat; int rc, child_stat;
rc = waitpid(*iter, &child_stat, WNOHANG); rc = waitpid(*iter, &child_stat, WNOHANG);
if (rc == -1 || rc == 0) if (rc == -1 || rc == 0) {
continue; continue;
}
iter = lnav_data.ld_children.erase(iter); iter = lnav_data.ld_children.erase(iter);
} }
@ -2044,7 +2048,7 @@ looper()
void void
wait_for_children() wait_for_children()
{ {
vector<struct pollfd> pollfds; std::vector<struct pollfd> pollfds;
struct timeval to = {0, 333000}; struct timeval to = {0, 333000};
if (lnav_data.ld_meta_search) { if (lnav_data.ld_meta_search) {
@ -2103,7 +2107,7 @@ get_textview_for_mode(ln_mode_t mode)
} }
static void static void
print_errors(vector<string> error_list) print_errors(std::vector<std::string> error_list)
{ {
for (auto& iter : error_list) { for (auto& iter : error_list) {
fprintf(stderr, fprintf(stderr,
@ -2120,10 +2124,10 @@ main(int argc, char* argv[])
exec_context& ec = lnav_data.ld_exec_context; exec_context& ec = lnav_data.ld_exec_context;
int lpc, c, retval = EXIT_SUCCESS; int lpc, c, retval = EXIT_SUCCESS;
shared_ptr<piper_proc> stdin_reader; std::shared_ptr<piper_proc> stdin_reader;
const char* stdin_out = nullptr; ghc::filesystem::path stdin_out;
int stdin_out_fd = -1; auto_fd stdin_out_fd;
bool exec_stdin = false, load_stdin = false; bool exec_stdin = false, load_stdin = false, stdin_captured = false;
const char* LANG = getenv("LANG"); const char* LANG = getenv("LANG");
ghc::filesystem::path stdin_tmp_path; ghc::filesystem::path stdin_tmp_path;
@ -2216,7 +2220,7 @@ main(int argc, char* argv[])
|| strcmp("/dev/stdin", optarg) == 0) { || strcmp("/dev/stdin", optarg) == 0) {
exec_stdin = true; exec_stdin = true;
} }
lnav_data.ld_commands.push_back("|" + string(optarg)); lnav_data.ld_commands.push_back("|" + std::string(optarg));
break; break;
case 'I': case 'I':
@ -2359,11 +2363,11 @@ main(int argc, char* argv[])
} }
auto file_type = file_type_result.unwrap(); auto file_type = file_type_result.unwrap();
string dst_name; std::string dst_name;
if (file_type == config_file_type::CONFIG) { if (file_type == config_file_type::CONFIG) {
dst_name = basename(argv[lpc]); dst_name = basename(argv[lpc]);
} else { } else {
vector<intern_string_t> format_list std::vector<intern_string_t> format_list
= load_format_file(argv[lpc], loader_errors); = load_format_file(argv[lpc], loader_errors);
if (!loader_errors.empty()) { 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)) { if (!(lnav_data.ld_flags & LNF_CHECK_CONFIG)) {
DEFAULT_FILES.insert(make_pair(LNF_SYSLOG, string("var/log/messages")));
DEFAULT_FILES.insert( DEFAULT_FILES.insert(
make_pair(LNF_SYSLOG, string("var/log/system.log"))); make_pair(LNF_SYSLOG, std::string("var/log/messages")));
DEFAULT_FILES.insert(make_pair(LNF_SYSLOG, string("var/log/syslog")));
DEFAULT_FILES.insert( DEFAULT_FILES.insert(
make_pair(LNF_SYSLOG, string("var/log/syslog.log"))); make_pair(LNF_SYSLOG, std::string("var/log/system.log")));
DEFAULT_FILES.insert(
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); 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 auto cmd_ref_path
= ghc::filesystem::path(internals_dir) / "cmd-ref.rst"; = ghc::filesystem::path(internals_dir) / "cmd-ref.rst";
auto cmd_file = unique_ptr<FILE, decltype(&fclose)>( auto cmd_file = std::unique_ptr<FILE, decltype(&fclose)>(
fopen(cmd_ref_path.c_str(), "w+"), fclose); fopen(cmd_ref_path.c_str(), "w+"), fclose);
if (cmd_file.get()) { if (cmd_file.get()) {
set<readline_context::command_t*> unique_cmds; std::set<readline_context::command_t*> unique_cmds;
for (auto& cmd : lnav_commands) { for (auto& cmd : lnav_commands) {
if (unique_cmds.find(cmd.second) != unique_cmds.end()) { 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 auto sql_ref_path
= ghc::filesystem::path(internals_dir) / "sql-ref.rst"; = ghc::filesystem::path(internals_dir) / "sql-ref.rst";
auto sql_file = unique_ptr<FILE, decltype(&fclose)>( auto sql_file = std::unique_ptr<FILE, decltype(&fclose)>(
fopen(sql_ref_path.c_str(), "w+"), fclose); fopen(sql_ref_path.c_str(), "w+"), fclose);
set<help_text*> unique_sql_help; std::set<help_text*> unique_sql_help;
if (sql_file.get()) { if (sql_file.get()) {
for (auto& sql : sqlite_function_help) { for (auto& sql : sqlite_function_help) {
@ -2767,32 +2773,31 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
strerror(errno)); strerror(errno));
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
} else { } else {
auto fifo_piper = make_shared<piper_proc>( auto fifo_tmp_fd
fifo_fd.release(), = lnav::filesystem::open_temp_file(
false, ghc::filesystem::temp_directory_path()
lnav::filesystem::open_temp_file( / "lnav.fifo.XXXXXX")
ghc::filesystem::temp_directory_path() .map([](auto&& pair) {
/ "lnav.fifo.XXXXXX") ghc::filesystem::remove(pair.first);
.map([](auto pair) {
ghc::filesystem::remove(pair.first);
return pair; return std::move(pair.second);
}) })
.expect("Cannot create temporary file for FIFO") .expect("Cannot create temporary file for FIFO");
.second); auto fifo_piper = std::make_shared<piper_proc>(
std::move(fifo_fd), false, std::move(fifo_tmp_fd));
auto fifo_out_fd = fifo_piper->get_fd(); auto fifo_out_fd = fifo_piper->get_fd();
auto desc = fmt::format(FMT_STRING("FIFO [{}]"), auto desc = fmt::format(FMT_STRING("FIFO [{}]"),
lnav_data.ld_fifo_counter++); lnav_data.ld_fifo_counter++);
lnav_data.ld_active_files.fc_file_names[desc].with_fd( 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); lnav_data.ld_pipers.push_back(fifo_piper);
} }
} else if ((abspath = realpath(argv[lpc], nullptr)) == nullptr) { } else if ((abspath = realpath(argv[lpc], nullptr)) == nullptr) {
perror("Cannot find file"); perror("Cannot find file");
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
} else if (S_ISDIR(st.st_mode)) { } 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] == '/') { if (dir_wild[dir_wild.size() - 1] == '/') {
dir_wild.resize(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(); shared_buffer_ref sbr = read_result.unwrap();
if (fmt->scan_for_partial(sbr, partial_len)) { if (fmt->scan_for_partial(sbr, partial_len)) {
long line_number = distance(lf->begin(), line_iter); long line_number = distance(lf->begin(), line_iter);
string full_line(sbr.get_data(), sbr.length()); std::string full_line(sbr.get_data(), sbr.length());
string partial_line(sbr.get_data(), partial_len); std::string partial_line(sbr.get_data(), partial_len);
fprintf(stderr, fprintf(stderr,
"error:%s:%ld:line did not match format %s\n", "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) if (load_stdin && !isatty(STDIN_FILENO) && !is_dev_null(STDIN_FILENO)
&& !exec_stdin) && !exec_stdin)
{ {
if (stdin_out == nullptr) { if (stdin_out.empty()) {
auto pattern auto pattern
= lnav::paths::dotlnav() / "stdin-captures/stdin.XXXXXX"; = 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(); auto temp_pair = open_result.unwrap();
stdin_tmp_path = temp_pair.first; stdin_tmp_path = temp_pair.first;
stdin_out_fd = temp_pair.second; stdin_out_fd = std::move(temp_pair.second);
} else { } else {
if ((stdin_out_fd auto open_res = lnav::filesystem::open_file(
= open(stdin_out, O_RDWR | O_CREAT | O_TRUNC, 0600)) stdin_out, O_RDWR | O_CREAT | O_TRUNC, 0600);
== -1) { if (open_res.isErr()) {
perror("Unable to open output file for stdin"); fmt::print(stderr, "error: {}\n", open_res.unwrapErr());
return EXIT_FAILURE; return EXIT_FAILURE;
} }
stdin_out_fd = open_res.unwrap();
} }
stdin_reader = make_shared<piper_proc>( stdin_captured = true;
STDIN_FILENO, lnav_data.ld_flags & LNF_TIMESTAMP, stdin_out_fd); stdin_reader
= std::make_shared<piper_proc>(auto_fd(STDIN_FILENO),
lnav_data.ld_flags & LNF_TIMESTAMP,
std::move(stdin_out_fd));
lnav_data.ld_active_files.fc_file_names["stdin"] 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); .with_include_in_session(false);
lnav_data.ld_pipers.push_back(stdin_reader); 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) { if (lnav_data.ld_flags & LNF_HEADLESS) {
std::vector<pair<Result<string, string>, string>> cmd_results; std::vector<
std::pair<Result<std::string, std::string>, std::string>>
cmd_results;
textview_curses *log_tc, *text_tc, *tc; textview_curses *log_tc, *text_tc, *tc;
bool output_view = true; 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(); for (vl = tc->get_top(); vl < tc->get_inner_height();
++vl, ++y) { ++vl, ++y) {
attr_line_t al; attr_line_t al;
string& line = al.get_string(); auto& line = al.get_string();
while (los != nullptr while (los != nullptr
&& los->list_value_for_overlay( && los->list_value_for_overlay(
*tc, y, tc->get_inner_height(), vl, al)) *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; ++y;
} }
vector<attr_line_t> rows(1); std::vector<attr_line_t> rows(1);
tc->listview_value_for_rows(*tc, vl, rows); tc->listview_value_for_rows(*tc, vl, rows);
if (suppress_empty_lines && rows[0].empty()) { if (suppress_empty_lines && rows[0].empty()) {
continue; continue;
@ -3104,7 +3116,7 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
} }
{ {
attr_line_t al; attr_line_t al;
string& line = al.get_string(); auto& line = al.get_string();
while (los != nullptr while (los != nullptr
&& los->list_value_for_overlay( && 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 // When reading from stdin, tell the user where the capture file is
// stored so they can look at it later. // 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_QUIET)
&& !(lnav_data.ld_flags & LNF_HEADLESS)) && !(lnav_data.ld_flags & LNF_HEADLESS))
{ {

File diff suppressed because it is too large Load Diff

View File

@ -46,8 +46,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "auto_fd.hh"
#include "auto_mem.hh" #include "auto_mem.hh"
#include "base/auto_fd.hh"
#include "base/auto_pid.hh" #include "base/auto_pid.hh"
#include "base/fs_util.hh" #include "base/fs_util.hh"
#include "base/injector.bind.hh" #include "base/injector.bind.hh"
@ -62,7 +62,7 @@
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
#include "yajlpp/yajlpp_def.hh" #include "yajlpp/yajlpp_def.hh"
using namespace std; using namespace std::chrono_literals;
static const int MAX_CRASH_LOG_COUNT = 16; static const int MAX_CRASH_LOG_COUNT = 16;
static const auto STDIN_CAPTURE_RETENTION = 24h; static const auto STDIN_CAPTURE_RETENTION = 24h;
@ -159,7 +159,8 @@ ensure_dotlnav()
continue; 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; continue;
} }
@ -178,7 +179,7 @@ install_from_git(const char* repo)
auto formats_path = lnav::paths::dotlnav() / "formats"; auto formats_path = lnav::paths::dotlnav() / "formats";
auto configs_path = lnav::paths::dotlnav() / "configs"; auto configs_path = lnav::paths::dotlnav() / "configs";
auto staging_path = lnav::paths::dotlnav() / "staging"; 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_formats_path = formats_path / local_name;
auto local_configs_path = configs_path / local_name; auto local_configs_path = configs_path / local_name;
@ -307,7 +308,7 @@ update_installs_from_git()
static int static int
read_repo_path(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) 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()); install_from_git(path.c_str());
@ -367,9 +368,9 @@ install_extra_formats()
} }
struct userdata { struct userdata {
userdata(vector<string>& errors) : ud_errors(errors){}; userdata(std::vector<std::string>& errors) : ud_errors(errors){};
vector<string>& ud_errors; std::vector<std::string>& ud_errors;
}; };
static void static void
@ -418,30 +419,30 @@ static const struct json_path_container keymap_def_handlers
return &retval; return &retval;
}) })
.with_path_provider<key_map>( .with_path_provider<key_map>(
[](key_map* km, vector<string>& paths_out) { [](key_map* km, std::vector<std::string>& paths_out) {
for (const auto& iter : km->km_seq_to_cmd) { for (const auto& iter : km->km_seq_to_cmd) {
paths_out.emplace_back(iter.first); paths_out.emplace_back(iter.first);
} }
}) })
.with_children(key_command_handlers)}; .with_children(key_command_handlers)};
static const struct json_path_container keymap_defs_handlers static const struct json_path_container keymap_defs_handlers = {
= {yajlpp::pattern_property_handler("(?<keymap_name>[\\w\\-]+)") yajlpp::pattern_property_handler("(?<keymap_name>[\\w\\-]+)")
.with_description("The keymap definitions") .with_description("The keymap definitions")
.with_obj_provider<key_map, _lnav_config>( .with_obj_provider<key_map, _lnav_config>(
[](const yajlpp_provider_context& ypc, _lnav_config* root) { [](const yajlpp_provider_context& ypc, _lnav_config* root) {
key_map& retval key_map& retval
= root->lc_ui_keymaps[ypc.ypc_extractor.get_substr( = root->lc_ui_keymaps[ypc.ypc_extractor.get_substr(
"keymap_name")]; "keymap_name")];
return &retval; return &retval;
}) })
.with_path_provider<_lnav_config>( .with_path_provider<_lnav_config>(
[](struct _lnav_config* cfg, vector<string>& paths_out) { [](struct _lnav_config* cfg, std::vector<std::string>& paths_out) {
for (const auto& iter : cfg->lc_ui_keymaps) { for (const auto& iter : cfg->lc_ui_keymaps) {
paths_out.emplace_back(iter.first); paths_out.emplace_back(iter.first);
} }
}) })
.with_children(keymap_def_handlers)}; .with_children(keymap_def_handlers)};
static const struct json_path_container global_var_handlers = { static const struct json_path_container global_var_handlers = {
yajlpp::pattern_property_handler("(?<var_name>\\w+)") yajlpp::pattern_property_handler("(?<var_name>\\w+)")
@ -450,7 +451,7 @@ static const struct json_path_container global_var_handlers = {
"A global variable definition. Global variables can be referenced " "A global variable definition. Global variables can be referenced "
"in scripts, SQL statements, or commands.") "in scripts, SQL statements, or commands.")
.with_path_provider<_lnav_config>( .with_path_provider<_lnav_config>(
[](struct _lnav_config* cfg, vector<string>& paths_out) { [](struct _lnav_config* cfg, std::vector<std::string>& paths_out) {
for (const auto& iter : cfg->lc_global_vars) { for (const auto& iter : cfg->lc_global_vars) {
paths_out.emplace_back(iter.first); paths_out.emplace_back(iter.first);
} }
@ -783,7 +784,7 @@ static const struct json_path_container theme_log_level_styles_handlers
return &sc; return &sc;
}) })
.with_path_provider<lnav_theme>( .with_path_provider<lnav_theme>(
[](struct lnav_theme* cfg, vector<string>& paths_out) { [](struct lnav_theme* cfg, std::vector<std::string>& paths_out) {
for (int lpc = LEVEL_TRACE; lpc < LEVEL__MAX; lpc++) { for (int lpc = LEVEL_TRACE; lpc < LEVEL__MAX; lpc++) {
paths_out.emplace_back(level_names[lpc]); paths_out.emplace_back(level_names[lpc]);
} }
@ -818,7 +819,7 @@ static const struct json_path_container theme_highlights_handlers
return &hc; return &hc;
}) })
.with_path_provider<lnav_theme>( .with_path_provider<lnav_theme>(
[](struct lnav_theme* cfg, vector<string>& paths_out) { [](struct lnav_theme* cfg, std::vector<std::string>& paths_out) {
for (const auto& pair : cfg->lt_highlights) { for (const auto& pair : cfg->lt_highlights) {
paths_out.emplace_back(pair.first); paths_out.emplace_back(pair.first);
} }
@ -830,7 +831,7 @@ static const struct json_path_container theme_vars_handlers
.with_synopsis("name") .with_synopsis("name")
.with_description("A theme variable definition") .with_description("A theme variable definition")
.with_path_provider<lnav_theme>( .with_path_provider<lnav_theme>(
[](struct lnav_theme* lt, vector<string>& paths_out) { [](struct lnav_theme* lt, std::vector<std::string>& paths_out) {
for (const auto& iter : lt->lt_vars) { for (const auto& iter : lt->lt_vars) {
paths_out.emplace_back(iter.first); paths_out.emplace_back(iter.first);
} }
@ -863,24 +864,24 @@ static const struct json_path_container theme_def_handlers = {
.with_children(theme_highlights_handlers), .with_children(theme_highlights_handlers),
}; };
static const struct json_path_container theme_defs_handlers static const struct json_path_container theme_defs_handlers = {
= {yajlpp::pattern_property_handler("(?<theme_name>[\\w\\-]+)") yajlpp::pattern_property_handler("(?<theme_name>[\\w\\-]+)")
.with_description("Theme definitions") .with_description("Theme definitions")
.with_obj_provider<lnav_theme, _lnav_config>( .with_obj_provider<lnav_theme, _lnav_config>(
[](const yajlpp_provider_context& ypc, _lnav_config* root) { [](const yajlpp_provider_context& ypc, _lnav_config* root) {
lnav_theme& lt lnav_theme& lt
= root->lc_ui_theme_defs[ypc.ypc_extractor.get_substr( = root->lc_ui_theme_defs[ypc.ypc_extractor.get_substr(
"theme_name")]; "theme_name")];
return &lt; return &lt;
}) })
.with_path_provider<_lnav_config>( .with_path_provider<_lnav_config>(
[](struct _lnav_config* cfg, vector<string>& paths_out) { [](struct _lnav_config* cfg, std::vector<std::string>& paths_out) {
for (const auto& iter : cfg->lc_ui_theme_defs) { for (const auto& iter : cfg->lc_ui_theme_defs) {
paths_out.emplace_back(iter.first); paths_out.emplace_back(iter.first);
} }
}) })
.with_children(theme_def_handlers)}; .with_children(theme_def_handlers)};
static const struct json_path_container ui_handlers = { static const struct json_path_container ui_handlers = {
yajlpp::property_handler("clock-format") yajlpp::property_handler("clock-format")
@ -1072,7 +1073,7 @@ static const struct json_path_container sysclip_impls_handlers = {
return &retval; return &retval;
}) })
.with_path_provider<_lnav_config>( .with_path_provider<_lnav_config>(
[](struct _lnav_config* cfg, vector<string>& paths_out) { [](struct _lnav_config* cfg, std::vector<std::string>& paths_out) {
for (const auto& iter : cfg->lc_sysclip.c_clipboard_impls) { for (const auto& iter : cfg->lc_sysclip.c_clipboard_impls) {
paths_out.emplace_back(iter.first); paths_out.emplace_back(iter.first);
} }
@ -1104,21 +1105,21 @@ static const struct json_path_container tuning_handlers = {
.with_children(sysclip_handlers), .with_children(sysclip_handlers),
}; };
static const set<string> SUPPORTED_CONFIG_SCHEMAS = { static const std::set<std::string> SUPPORTED_CONFIG_SCHEMAS = {
"https://lnav.org/schemas/config-v1.schema.json", "https://lnav.org/schemas/config-v1.schema.json",
}; };
const char* DEFAULT_FORMAT_SCHEMA const char* DEFAULT_FORMAT_SCHEMA
= "https://lnav.org/schemas/format-v1.schema.json"; = "https://lnav.org/schemas/format-v1.schema.json";
const set<string> SUPPORTED_FORMAT_SCHEMAS = { const std::set<std::string> SUPPORTED_FORMAT_SCHEMAS = {
DEFAULT_FORMAT_SCHEMA, DEFAULT_FORMAT_SCHEMA,
}; };
static int static int
read_id(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) 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) { if (SUPPORTED_CONFIG_SCHEMAS.count(file_id) == 0) {
ypc->report_error( ypc->report_error(
@ -1176,7 +1177,7 @@ detect_config_file_type(const ghc::filesystem::path& path)
auto read_res = lnav::filesystem::read_file(path); auto read_res = lnav::filesystem::read_file(path);
if (read_res.isErr()) { 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(), path.string(),
read_res.unwrapErr())); read_res.unwrapErr()));
} }
@ -1187,7 +1188,7 @@ detect_config_file_type(const ghc::filesystem::path& path)
} }
char error_buffer[1024]; char error_buffer[1024];
auto content_tree = unique_ptr<yajl_val_s, decltype(&yajl_tree_free)>( auto content_tree = std::unique_ptr<yajl_val_s, decltype(&yajl_tree_free)>(
yajl_tree_parse(content.c_str(), error_buffer, sizeof(error_buffer)), yajl_tree_parse(content.c_str(), error_buffer, sizeof(error_buffer)),
yajl_tree_free); yajl_tree_free);
if (content_tree == nullptr) { if (content_tree == nullptr) {
@ -1216,7 +1217,7 @@ detect_config_file_type(const ghc::filesystem::path& path)
static void static void
load_config_from(_lnav_config& lconfig, load_config_from(_lnav_config& lconfig,
const ghc::filesystem::path& path, const ghc::filesystem::path& path,
vector<string>& errors) std::vector<std::string>& errors)
{ {
yajlpp_parse_context ypc(path.string(), &lnav_config_handlers); yajlpp_parse_context ypc(path.string(), &lnav_config_handlers);
struct userdata ud(errors); struct userdata ud(errors);
@ -1269,7 +1270,7 @@ static void
load_default_config(struct _lnav_config& config_obj, load_default_config(struct _lnav_config& config_obj,
const std::string& path, const std::string& path,
const bin_src_file& bsf, const bin_src_file& bsf,
vector<string>& errors) std::vector<std::string>& errors)
{ {
yajlpp_parse_context ypc_builtin(bsf.get_name(), &lnav_config_handlers); yajlpp_parse_context ypc_builtin(bsf.get_name(), &lnav_config_handlers);
auto_mem<yajl_handle_t> handle(yajl_free); auto_mem<yajl_handle_t> handle(yajl_free);
@ -1297,7 +1298,7 @@ load_default_config(struct _lnav_config& config_obj,
static void static void
load_default_configs(struct _lnav_config& config_obj, load_default_configs(struct _lnav_config& config_obj,
const std::string& path, const std::string& path,
vector<string>& errors) std::vector<std::string>& errors)
{ {
for (auto& bsf : lnav_config_json) { for (auto& bsf : lnav_config_json) {
load_default_config(config_obj, path, bsf, errors); load_default_config(config_obj, path, bsf, errors);
@ -1305,8 +1306,8 @@ load_default_configs(struct _lnav_config& config_obj,
} }
void void
load_config(const vector<ghc::filesystem::path>& extra_paths, load_config(const std::vector<ghc::filesystem::path>& extra_paths,
vector<string>& errors) std::vector<std::string>& errors)
{ {
auto user_config = lnav::paths::dotlnav() / "config.json"; auto user_config = lnav::paths::dotlnav() / "config.json";
@ -1369,7 +1370,7 @@ load_config(const vector<ghc::filesystem::path>& extra_paths,
void void
reset_config(const std::string& path) reset_config(const std::string& path)
{ {
vector<string> errors; std::vector<std::string> errors;
load_default_configs(lnav_config, path, errors); load_default_configs(lnav_config, path, errors);
@ -1380,7 +1381,7 @@ reset_config(const std::string& path)
} }
} }
string std::string
save_config() save_config()
{ {
yajlpp_gen gen; yajlpp_gen gen;
@ -1390,7 +1391,7 @@ save_config()
yajl_gen_config(gen, yajl_gen_beautify, true); yajl_gen_config(gen, yajl_gen_beautify, true);
yajlpp_gen_context ygc(gen, lnav_config_handlers); yajlpp_gen_context ygc(gen, lnav_config_handlers);
vector<string> errors; std::vector<std::string> errors;
ygc.with_default_obj(lnav_default_config).with_obj(lnav_config); ygc.with_default_obj(lnav_default_config).with_obj(lnav_config);
ygc.gen(); ygc.gen();
@ -1403,7 +1404,7 @@ save_config()
== -1) == -1)
{ {
return "error: unable to save configuration -- " return "error: unable to save configuration -- "
+ string(strerror(errno)); + std::string(strerror(errno));
} }
string_fragment bits = gen.to_string_fragment(); string_fragment bits = gen.to_string_fragment();
@ -1417,7 +1418,7 @@ save_config()
} }
void void
reload_config(vector<string>& errors) reload_config(std::vector<std::string>& errors)
{ {
lnav_config_listener* curr = lnav_config_listener::LISTENER_LIST; lnav_config_listener* curr = lnav_config_listener::LISTENER_LIST;
@ -1426,7 +1427,7 @@ reload_config(vector<string>& errors)
const std::string& errmsg) { const std::string& errmsg) {
auto cb = [&cfg_value, &errors, &errmsg]( auto cb = [&cfg_value, &errors, &errmsg](
const json_path_handler_base& jph, const json_path_handler_base& jph,
const string& path, const std::string& path,
void* mem) { void* mem) {
if (mem != cfg_value) { if (mem != cfg_value) {
return; return;

View File

@ -33,18 +33,16 @@
#include "config.h" #include "config.h"
#include "piper_proc.hh" #include "piper_proc.hh"
using namespace std; std::string
action_delegate::execute_action(const std::string& action_name)
string
action_delegate::execute_action(const string& action_name)
{ {
auto& ldh = this->ad_log_helper; auto& ldh = this->ad_log_helper;
auto value_index = this->ad_press_value; auto value_index = this->ad_press_value;
logline_value& lv = ldh.ldh_line_values[value_index]; logline_value& lv = ldh.ldh_line_values[value_index];
shared_ptr<logfile> lf = ldh.ldh_file; auto lf = ldh.ldh_file;
const auto format = lf->get_format(); const auto format = lf->get_format();
pid_t child_pid; pid_t child_pid;
string retval; std::string retval;
auto iter = format->lf_action_defs.find(action_name); auto iter = format->lf_action_defs.find(action_name);
@ -65,15 +63,16 @@ action_delegate::execute_action(const string& action_name)
switch (child_pid) { switch (child_pid) {
case -1: case -1:
retval = "error: unable to fork child process -- " retval = fmt::format(
+ string(strerror(errno)); FMT_STRING("error: unable to fork child process -- {}"),
strerror(errno));
break; break;
case 0: { case 0: {
const char* args[action.ad_cmdline.size() + 1]; const char* args[action.ad_cmdline.size() + 1];
set<std::string> path_set(format->get_source_path()); std::set<std::string> path_set(format->get_source_path());
char env_buffer[64]; char env_buffer[64];
int value_line; int value_line;
string path; std::string path;
dup2(STDOUT_FILENO, STDERR_FILENO); dup2(STDOUT_FILENO, STDERR_FILENO);
setenv("LNAV_ACTION_FILE", lf->get_filename().c_str(), 1); 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 += path_iter;
} }
path += ":" + string(getenv("PATH")); path += ":" + std::string(getenv("PATH"));
setenv("PATH", path.c_str(), 1); setenv("PATH", path.c_str(), 1);
for (size_t lpc = 0; lpc < action.ad_cmdline.size(); lpc++) { for (size_t lpc = 0; lpc < action.ad_cmdline.size(); lpc++) {
args[lpc] = action.ad_cmdline[lpc].c_str(); args[lpc] = action.ad_cmdline[lpc].c_str();
@ -112,7 +111,7 @@ action_delegate::execute_action(const string& action_name)
default: { default: {
static int exec_count = 0; static int exec_count = 0;
string value = lv.to_string(); const auto value = lv.to_string();
this->ad_child_cb(child_pid); this->ad_child_cb(child_pid);
@ -122,8 +121,8 @@ action_delegate::execute_action(const string& action_name)
in_pipe.close(); in_pipe.close();
if (out_pipe.read_end() != -1) { if (out_pipe.read_end() != -1) {
auto pp = make_shared<piper_proc>( auto pp = std::make_shared<piper_proc>(
out_pipe.read_end(), std::move(out_pipe.read_end()),
false, false,
lnav::filesystem::open_temp_file( lnav::filesystem::open_temp_file(
ghc::filesystem::temp_directory_path() 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; int x_offset = this->ad_line_index + mouse_left;
if (lv.lv_origin.contains(x_offset)) { if (lv.lv_origin.contains(x_offset)) {
shared_ptr<logfile> lf = this->ad_log_helper.ldh_file; auto lf = this->ad_log_helper.ldh_file;
const vector<string>* actions; const std::vector<std::string>* actions;
actions = lf->get_format()->get_actions(lv); actions = lf->get_format()->get_actions(lv);
if (actions != nullptr && !actions->empty()) { if (actions != nullptr && !actions->empty()) {

View File

@ -46,8 +46,6 @@
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
#include "yajlpp/yajlpp_def.hh" #include "yajlpp/yajlpp_def.hh"
using namespace std;
static auto intern_lifetime = intern_string::get_table_lifetime(); static auto intern_lifetime = intern_string::get_table_lifetime();
string_attr_type logline::L_PREFIX("prefix"); string_attr_type logline::L_PREFIX("prefix");
string_attr_type logline::L_TIMESTAMP("timestamp"); string_attr_type logline::L_TIMESTAMP("timestamp");
@ -232,9 +230,9 @@ logline_value::to_string() const
return {buffer}; return {buffer};
} }
vector<std::shared_ptr<log_format>> log_format::lf_root_formats; std::vector<std::shared_ptr<log_format>> log_format::lf_root_formats;
vector<std::shared_ptr<log_format>>& std::vector<std::shared_ptr<log_format>>&
log_format::get_root_formats() log_format::get_root_formats()
{ {
return lf_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_base_line->set_level(
jlu->jlu_format->convert_level(pi, &level_cap)); jlu->jlu_format->convert_level(pi, &level_cap));
} else { } else {
vector<pair<int64_t, log_level_t>>::iterator iter; std::vector<std::pair<int64_t, log_level_t>>::iterator iter;
for (iter = jlu->jlu_format->elf_level_pairs.begin(); for (iter = jlu->jlu_format->elf_level_pairs.begin();
iter != jlu->jlu_format->elf_level_pairs.end(); 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", log_debug("Unable to parse line at offset %d: %s",
li.li_file_range.fr_offset, li.li_file_range.fr_offset,
msg); 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); yajl_free_error(handle, msg);
} }
if (!this->lf_specialized) { if (!this->lf_specialized) {
@ -836,7 +835,7 @@ external_log_format::scan(logfile& lf,
} }
if (mod_index && level_cap && body_cap) { if (mod_index && level_cap && body_cap) {
auto mod_elf = dynamic_pointer_cast<external_log_format>( auto mod_elf = std::dynamic_pointer_cast<external_log_format>(
mod_iter->second.mf_mod_format); mod_iter->second.mf_mod_format);
if (mod_elf) { if (mod_elf) {
@ -1124,9 +1123,9 @@ void
external_log_format::rewrite(exec_context& ec, external_log_format::rewrite(exec_context& ec,
shared_buffer_ref& line, shared_buffer_ref& line,
string_attrs_t& sa, string_attrs_t& sa,
string& value_out) std::string& value_out)
{ {
vector<logline_value>::iterator shift_iter; std::vector<logline_value>::iterator shift_iter;
auto& values = *ec.ec_line_values; auto& values = *ec.ec_line_values;
value_out.assign(line.get_data(), line.length()); 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) || yajl_complete_parse(handle) != yajl_status_ok)
{ {
unsigned char* msg; unsigned char* msg;
string full_msg; std::string full_msg;
msg = yajl_get_error( msg = yajl_get_error(
handle, 1, (const unsigned char*) sbr.get_data(), sbr.length()); 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(), this->jlf_line_values.end(),
logline_value_cmp(&jfe.jfe_value)); logline_value_cmp(&jfe.jfe_value));
if (lv_iter != this->jlf_line_values.end()) { 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'); size_t nl_pos = str.find('\n');
lr.lr_start = this->jlf_cached_line.size(); 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()); 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(); lr.lr_end = this->jlf_cached_line.size();
} else { } else {
lr.lr_end = lr.lr_start + nl_pos; lr.lr_end = lr.lr_start + nl_pos;
@ -1628,7 +1627,7 @@ external_log_format::build(std::vector<std::string>& errors)
if (!this->lf_timestamp_field.empty()) { if (!this->lf_timestamp_field.empty()) {
auto& vd = this->elf_value_defs[this->lf_timestamp_field]; auto& vd = this->elf_value_defs[this->lf_timestamp_field];
if (vd.get() == nullptr) { if (vd.get() == nullptr) {
vd = make_shared<external_log_format::value_def>( vd = std::make_shared<external_log_format::value_def>(
this->lf_timestamp_field, value_kind_t::VALUE_TEXT, -1, this); this->lf_timestamp_field, value_kind_t::VALUE_TEXT, -1, this);
} }
vd->vd_meta.lvm_name = this->lf_timestamp_field; vd->vd_meta.lvm_name = this->lf_timestamp_field;
@ -1641,7 +1640,7 @@ external_log_format::build(std::vector<std::string>& errors)
{ {
auto& vd = this->elf_value_defs[this->elf_level_field]; auto& vd = this->elf_value_defs[this->elf_level_field];
if (vd.get() == nullptr) { if (vd.get() == nullptr) {
vd = make_shared<external_log_format::value_def>( vd = std::make_shared<external_log_format::value_def>(
this->elf_level_field, value_kind_t::VALUE_TEXT, -1, this); this->elf_level_field, value_kind_t::VALUE_TEXT, -1, this);
} }
vd->vd_meta.lvm_name = this->elf_level_field; vd->vd_meta.lvm_name = this->elf_level_field;
@ -1651,7 +1650,7 @@ external_log_format::build(std::vector<std::string>& errors)
if (!this->elf_body_field.empty()) { if (!this->elf_body_field.empty()) {
auto& vd = this->elf_value_defs[this->elf_body_field]; auto& vd = this->elf_value_defs[this->elf_body_field];
if (vd.get() == nullptr) { if (vd.get() == nullptr) {
vd = make_shared<external_log_format::value_def>( vd = std::make_shared<external_log_format::value_def>(
this->elf_body_field, value_kind_t::VALUE_TEXT, -1, this); this->elf_body_field, value_kind_t::VALUE_TEXT, -1, this);
} }
vd->vd_meta.lvm_name = this->elf_body_field; vd->vd_meta.lvm_name = this->elf_body_field;
@ -1687,8 +1686,8 @@ external_log_format::build(std::vector<std::string>& errors)
errors.push_back("error:" + this->elf_name.to_string() + ".regex[" errors.push_back("error:" + this->elf_name.to_string() + ".regex["
+ iter->first + "]" + ":" + pat.p_string); + iter->first + "]" + ":" + pat.p_string);
errors.push_back("error:" + this->elf_name.to_string() + ".regex[" errors.push_back("error:" + this->elf_name.to_string() + ".regex["
+ iter->first + "]" + ":" + string(e.e_offset, ' ') + iter->first + "]" + ":"
+ "^"); + std::string(e.e_offset, ' ') + "^");
continue; continue;
} }
for (pcre_named_capture::iterator name_iter = pat.p_pcre->named_begin(); for (pcre_named_capture::iterator name_iter = pat.p_pcre->named_begin();
@ -1903,8 +1902,8 @@ external_log_format::build(std::vector<std::string>& errors)
PTIMEC_FORMATS[lpc].pf_func(&tm, ts, off, ts_len); PTIMEC_FORMATS[lpc].pf_func(&tm, ts, off, ts_len);
errors.push_back( errors.push_back(
" format: " " format: "
+ string(PTIMEC_FORMATS[lpc].pf_fmt) + std::string(PTIMEC_FORMATS[lpc].pf_fmt)
+ "; matched: " + string(ts, off)); + "; matched: " + std::string(ts, off));
} }
} else { } else {
for (int lpc = 0; custom_formats[lpc] != nullptr; lpc++) for (int lpc = 0; custom_formats[lpc] != nullptr; lpc++)
@ -1913,9 +1912,9 @@ external_log_format::build(std::vector<std::string>& errors)
ptime_fmt( ptime_fmt(
custom_formats[lpc], &tm, ts, off, ts_len); custom_formats[lpc], &tm, ts, off, ts_len);
errors.push_back(" format: " errors.push_back(
+ string(custom_formats[lpc]) " format: " + std::string(custom_formats[lpc])
+ "; matched: " + string(ts, off)); + "; matched: " + std::string(ts, off));
} }
} }
} }
@ -2094,13 +2093,13 @@ external_log_format::build(std::vector<std::string>& errors)
if (code == nullptr) { if (code == nullptr) {
errors.push_back("error:" + this->elf_name.to_string() errors.push_back("error:" + this->elf_name.to_string()
+ ":highlighters/" + hd_pair.first.to_string() + ":highlighters/" + hd_pair.first.to_string()
+ ":" + string(errptr)); + ":" + std::string(errptr));
errors.push_back("error:" + this->elf_name.to_string() errors.push_back("error:" + this->elf_name.to_string()
+ ":highlighters/" + hd_pair.first.to_string() + ":highlighters/" + hd_pair.first.to_string()
+ ":" + pattern); + ":" + pattern);
errors.push_back("error:" + this->elf_name.to_string() errors.push_back("error:" + this->elf_name.to_string()
+ ":highlighters/" + hd_pair.first.to_string() + ":highlighters/" + hd_pair.first.to_string()
+ ":" + string(eoff, ' ') + "^"); + ":" + std::string(eoff, ' ') + "^");
} else { } else {
this->lf_highlighters.emplace_back(code); this->lf_highlighters.emplace_back(code);
this->lf_highlighters.back() this->lf_highlighters.back()
@ -2116,8 +2115,7 @@ void
external_log_format::register_vtabs(log_vtab_manager* vtab_manager, external_log_format::register_vtabs(log_vtab_manager* vtab_manager,
std::vector<std::string>& errors) std::vector<std::string>& errors)
{ {
vector<pair<intern_string_t, string>>::iterator search_iter; for (auto search_iter = this->elf_search_tables.begin();
for (search_iter = this->elf_search_tables.begin();
search_iter != this->elf_search_tables.end(); search_iter != this->elf_search_tables.end();
++search_iter) ++search_iter)
{ {
@ -2136,9 +2134,7 @@ external_log_format::register_vtabs(log_vtab_manager* vtab_manager,
auto lst = std::make_shared<log_search_table>(re_res.unwrap(), auto lst = std::make_shared<log_search_table>(re_res.unwrap(),
search_iter->first); search_iter->first);
string errmsg; auto errmsg = vtab_manager->register_vtab(lst);
errmsg = vtab_manager->register_vtab(lst);
if (!errmsg.empty()) { if (!errmsg.empty()) {
errors.push_back("error:" + this->elf_name.to_string() + ":" errors.push_back("error:" + this->elf_name.to_string() + ":"
+ search_iter->first.to_string() + search_iter->first.to_string()
@ -2148,7 +2144,7 @@ external_log_format::register_vtabs(log_vtab_manager* vtab_manager,
} }
bool bool
external_log_format::match_samples(const vector<sample>& samples) const external_log_format::match_samples(const std::vector<sample>& samples) const
{ {
for (const auto& sample_iter : samples) { for (const auto& sample_iter : samples) {
for (const auto& pat_iter : this->elf_pattern_order) { for (const auto& pat_iter : this->elf_pattern_order) {
@ -2175,7 +2171,7 @@ public:
external_log_table(const external_log_format& elf) external_log_table(const external_log_format& elf)
: log_format_vtab_impl(elf), elt_format(elf){}; : log_format_vtab_impl(elf), elt_format(elf){};
void get_columns(vector<vtab_column>& cols) const void get_columns(std::vector<vtab_column>& cols) const
{ {
const external_log_format& elf = this->elt_format; const external_log_format& elf = this->elt_format;
@ -2275,7 +2271,7 @@ public:
return false; return false;
}; };
virtual void extract(shared_ptr<logfile> lf, virtual void extract(std::shared_ptr<logfile> lf,
uint64_t line_number, uint64_t line_number,
shared_buffer_ref& line, shared_buffer_ref& line,
std::vector<logline_value>& values) std::vector<logline_value>& values)
@ -2339,7 +2335,7 @@ external_log_format::specialized(int fmt_lock)
} }
bool bool
external_log_format::match_name(const string& filename) external_log_format::match_name(const std::string& filename)
{ {
if (this->elf_file_pattern.empty()) { if (this->elf_file_pattern.empty()) {
return true; return true;

View File

@ -45,8 +45,6 @@
#include "sql_util.hh" #include "sql_util.hh"
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
using namespace std;
static const pcrepp RDNS_PATTERN( static const pcrepp RDNS_PATTERN(
"^(?:com|net|org|edu|[a-z][a-z])" "^(?:com|net|org|edu|[a-z][a-z])"
"(\\.\\w+)+(.+)"); "(\\.\\w+)+(.+)");
@ -60,12 +58,12 @@ static const pcrepp RDNS_PATTERN(
* @return The scrubbed version of the input string or the original string * @return The scrubbed version of the input string or the original string
* if it is not a reverse-DNS string. * if it is not a reverse-DNS string.
*/ */
static string static std::string
scrub_rdns(const string& str) scrub_rdns(const std::string& str)
{ {
pcre_context_static<30> context; pcre_context_static<30> context;
pcre_input input(str); pcre_input input(str);
string retval; std::string retval;
if (RDNS_PATTERN.match(context, input)) { if (RDNS_PATTERN.match(context, input)) {
pcre_context::capture_t* cap; pcre_context::capture_t* cap;
@ -142,11 +140,11 @@ class generic_log_format : public log_format {
return intern_string::lookup("generic_log"); return intern_string::lookup("generic_log");
}; };
void scrub(string& line) override void scrub(std::string& line) override
{ {
pcre_context_static<30> context; pcre_context_static<30> context;
pcre_input pi(line); pcre_input pi(line);
string new_line; std::string new_line;
if (scrub_pattern().match(context, pi)) { if (scrub_pattern().match(context, pi)) {
pcre_context::capture_t* cap; pcre_context::capture_t* cap;
@ -160,7 +158,7 @@ class generic_log_format : public log_format {
}; };
scan_result_t scan(logfile& lf, scan_result_t scan(logfile& lf,
vector<logline>& dst, std::vector<logline>& dst,
const line_info& li, const line_info& li,
shared_buffer_ref& sbr) override shared_buffer_ref& sbr) override
{ {
@ -236,16 +234,16 @@ class generic_log_format : public log_format {
sa.emplace_back(lr, &SA_BODY); sa.emplace_back(lr, &SA_BODY);
}; };
shared_ptr<log_format> specialized(int fmt_lock) override std::shared_ptr<log_format> specialized(int fmt_lock) override
{ {
return std::make_shared<generic_log_format>(*this); return std::make_shared<generic_log_format>(*this);
}; };
}; };
string std::string
from_escaped_string(const char* str, size_t len) from_escaped_string(const char* str, size_t len)
{ {
string retval; std::string retval;
for (size_t lpc = 0; lpc < len; lpc++) { for (size_t lpc = 0; lpc < len; lpc++) {
switch (str[lpc]) { switch (str[lpc]) {
@ -549,7 +547,7 @@ public:
this->clear(); this->clear();
string sep auto sep
= from_escaped_string(pi.get_substr_start(pc[0]), pc[0]->length()); = from_escaped_string(pi.get_substr_start(pc[0]), pc[0]->length());
this->blf_separator = intern_string::lookup(sep); this->blf_separator = intern_string::lookup(sep);
@ -624,14 +622,14 @@ public:
if (field_type == "time") { if (field_type == "time") {
fd.with_kind(value_kind_t::VALUE_TIMESTAMP); fd.with_kind(value_kind_t::VALUE_TIMESTAMP);
} else if (field_type == "string") { } else if (field_type == "string") {
bool ident = binary_search(begin(KNOWN_IDS), bool ident = std::binary_search(std::begin(KNOWN_IDS),
end(KNOWN_IDS), std::end(KNOWN_IDS),
fd.fd_meta.lvm_name); fd.fd_meta.lvm_name);
fd.with_kind(value_kind_t::VALUE_TEXT, ident); fd.with_kind(value_kind_t::VALUE_TEXT, ident);
} else if (field_type == "count") { } else if (field_type == "count") {
bool ident = binary_search(begin(KNOWN_IDS), bool ident = std::binary_search(std::begin(KNOWN_IDS),
end(KNOWN_IDS), std::end(KNOWN_IDS),
fd.fd_meta.lvm_name); fd.fd_meta.lvm_name);
fd.with_kind(value_kind_t::VALUE_INTEGER, ident) fd.with_kind(value_kind_t::VALUE_INTEGER, ident)
.with_numeric_index(numeric_count); .with_numeric_index(numeric_count);
numeric_count += 1; numeric_count += 1;
@ -731,7 +729,7 @@ public:
std::shared_ptr<log_format> specialized(int fmt_lock = -1) override std::shared_ptr<log_format> specialized(int fmt_lock = -1) override
{ {
return make_shared<bro_log_format>(*this); return std::make_shared<bro_log_format>(*this);
}; };
class bro_log_table : public log_format_vtab_impl { class bro_log_table : public log_format_vtab_impl {
@ -741,7 +739,7 @@ public:
{ {
} }
void get_columns(vector<vtab_column>& cols) const override void get_columns(std::vector<vtab_column>& cols) const override
{ {
for (const auto& fd : this->blt_format.blf_field_defs) { for (const auto& fd : this->blt_format.blf_field_defs) {
std::pair<int, unsigned int> type_pair std::pair<int, unsigned int> type_pair
@ -772,9 +770,10 @@ public:
const bro_log_format& blt_format; const bro_log_format& blt_format;
}; };
static map<intern_string_t, std::shared_ptr<bro_log_table>>& get_tables() static std::map<intern_string_t, std::shared_ptr<bro_log_table>>&
get_tables()
{ {
static map<intern_string_t, std::shared_ptr<bro_log_table>> retval; static std::map<intern_string_t, std::shared_ptr<bro_log_table>> retval;
return retval; return retval;
}; };
@ -808,7 +807,7 @@ public:
intern_string_t blf_set_separator; intern_string_t blf_set_separator;
intern_string_t blf_empty_field; intern_string_t blf_empty_field;
intern_string_t blf_unset_field; intern_string_t blf_unset_field;
vector<field_def> blf_field_defs; std::vector<field_def> blf_field_defs;
}; };
struct ws_separated_string { struct ws_separated_string {
@ -1321,7 +1320,7 @@ public:
std::shared_ptr<log_format> specialized(int fmt_lock = -1) override std::shared_ptr<log_format> specialized(int fmt_lock = -1) override
{ {
return make_shared<w3c_log_format>(*this); return std::make_shared<w3c_log_format>(*this);
}; };
class w3c_log_table : public log_format_vtab_impl { class w3c_log_table : public log_format_vtab_impl {
@ -1331,7 +1330,7 @@ public:
{ {
} }
void get_columns(vector<vtab_column>& cols) const override void get_columns(std::vector<vtab_column>& cols) const override
{ {
for (const auto& fd : KNOWN_FIELDS) { for (const auto& fd : KNOWN_FIELDS) {
auto type_pair = log_vtab_impl::logline_value_to_sqlite_type( auto type_pair = log_vtab_impl::logline_value_to_sqlite_type(
@ -1368,9 +1367,10 @@ public:
const w3c_log_format& wlt_format; const w3c_log_format& wlt_format;
}; };
static map<intern_string_t, std::shared_ptr<w3c_log_table>>& get_tables() static std::map<intern_string_t, std::shared_ptr<w3c_log_table>>&
get_tables()
{ {
static map<intern_string_t, std::shared_ptr<w3c_log_table>> retval; static std::map<intern_string_t, std::shared_ptr<w3c_log_table>> retval;
return retval; return retval;
}; };
@ -1401,7 +1401,7 @@ public:
date_time_scanner wlf_time_scanner; date_time_scanner wlf_time_scanner;
intern_string_t wlf_format_name; intern_string_t wlf_format_name;
vector<field_def> wlf_field_defs; std::vector<field_def> wlf_field_defs;
}; };
static int KNOWN_FIELD_INDEX = 0; static int KNOWN_FIELD_INDEX = 0;
@ -1566,7 +1566,7 @@ public:
{ {
} }
void get_columns(vector<vtab_column>& cols) const override void get_columns(std::vector<vtab_column>& cols) const override
{ {
static const auto FIELDS = std::string("fields"); static const auto FIELDS = std::string("fields");
@ -1574,7 +1574,7 @@ public:
}; };
}; };
shared_ptr<log_vtab_impl> get_vtab_impl() const override std::shared_ptr<log_vtab_impl> get_vtab_impl() const override
{ {
static auto retval = std::make_shared<logfmt_log_table>(*this); static auto retval = std::make_shared<logfmt_log_table>(*this);
@ -1582,7 +1582,7 @@ public:
} }
scan_result_t scan(logfile& lf, scan_result_t scan(logfile& lf,
vector<logline>& dst, std::vector<logline>& dst,
const line_info& li, const line_info& li,
shared_buffer_ref& sbr) override shared_buffer_ref& sbr) override
{ {
@ -1667,7 +1667,7 @@ public:
void annotate(uint64_t line_number, void annotate(uint64_t line_number,
shared_buffer_ref& sbr, shared_buffer_ref& sbr,
string_attrs_t& sa, string_attrs_t& sa,
vector<logline_value>& values, std::vector<logline_value>& values,
bool annotate_module) const override bool annotate_module) const override
{ {
static const auto FIELDS_NAME = intern_string::lookup("fields"); static const auto FIELDS_NAME = intern_string::lookup("fields");
@ -1767,7 +1767,7 @@ public:
} }
} }
shared_ptr<log_format> specialized(int fmt_lock) override std::shared_ptr<log_format> specialized(int fmt_lock) override
{ {
return std::make_shared<logfmt_format>(*this); return std::make_shared<logfmt_format>(*this);
}; };

View File

@ -40,7 +40,7 @@
#include <libgen.h> #include <libgen.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "base/fs_util.hh" #include "base/fs_util.hh"
#include "base/paths.hh" #include "base/paths.hh"
#include "base/string_util.hh" #include "base/string_util.hh"
@ -52,19 +52,16 @@
#include "file_format.hh" #include "file_format.hh"
#include "fmt/format.h" #include "fmt/format.h"
#include "lnav_config.hh" #include "lnav_config.hh"
#include "lnav_util.hh"
#include "log_format_ext.hh" #include "log_format_ext.hh"
#include "sql_util.hh" #include "sql_util.hh"
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
#include "yajlpp/yajlpp_def.hh" #include "yajlpp/yajlpp_def.hh"
using namespace std;
static void extract_metadata(const char* contents, static void extract_metadata(const char* contents,
size_t len, size_t len,
struct script_metadata& meta_out); struct script_metadata& meta_out);
typedef map<intern_string_t, std::shared_ptr<external_log_format>> typedef std::map<intern_string_t, std::shared_ptr<external_log_format>>
log_formats_map_t; log_formats_map_t;
static auto intern_lifetime = intern_string::get_table_lifetime(); static auto intern_lifetime = intern_string::get_table_lifetime();
@ -72,7 +69,7 @@ static log_formats_map_t LOG_FORMATS;
struct userdata { struct userdata {
ghc::filesystem::path ud_format_path; ghc::filesystem::path ud_format_path;
vector<intern_string_t>* ud_format_names{nullptr}; std::vector<intern_string_t>* ud_format_names{nullptr};
std::vector<std::string>* ud_errors{nullptr}; std::vector<std::string>* ud_errors{nullptr};
}; };
@ -80,7 +77,7 @@ static external_log_format*
ensure_format(const yajlpp_provider_context& ypc, userdata* ud) ensure_format(const yajlpp_provider_context& ypc, userdata* ud)
{ {
const intern_string_t name = ypc.get_substr_i(0); const intern_string_t name = ypc.get_substr_i(0);
vector<intern_string_t>* formats = ud->ud_format_names; std::vector<intern_string_t>* formats = ud->ud_format_names;
external_log_format* retval; external_log_format* retval;
retval = LOG_FORMATS[name].get(); retval = LOG_FORMATS[name].get();
@ -105,11 +102,11 @@ ensure_format(const yajlpp_provider_context& ypc, userdata* ud)
static external_log_format::pattern* static external_log_format::pattern*
pattern_provider(const yajlpp_provider_context& ypc, external_log_format* elf) 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]; auto& pat = elf->elf_patterns[regex_name];
if (pat.get() == nullptr) { if (pat.get() == nullptr) {
pat = make_shared<external_log_format::pattern>(); pat = std::make_shared<external_log_format::pattern>();
} }
if (pat->p_config_path.empty()) { 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); const intern_string_t value_name = ypc.get_substr_i(0);
auto iter = elf->elf_value_defs.find(value_name); auto iter = elf->elf_value_defs.find(value_name);
shared_ptr<external_log_format::value_def> retval; std::shared_ptr<external_log_format::value_def> retval;
if (iter == elf->elf_value_defs.end()) { if (iter == elf->elf_value_defs.end()) {
retval = make_shared<external_log_format::value_def>( retval = std::make_shared<external_log_format::value_def>(
value_name, value_kind_t::VALUE_TEXT, -1, elf); value_name, value_kind_t::VALUE_TEXT, -1, elf);
elf->elf_value_defs[value_name] = retval; elf->elf_value_defs[value_name] = retval;
elf->elf_value_def_order.emplace_back(retval); elf->elf_value_def_order.emplace_back(retval);
@ -173,7 +170,7 @@ static int
read_format_bool(yajlpp_parse_context* ypc, int val) read_format_bool(yajlpp_parse_context* ypc, int val)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); 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") if (field_name == "convert-to-local-time")
elf->lf_date_time.dts_local_time = val; elf->lf_date_time.dts_local_time = val;
@ -193,7 +190,7 @@ static int
read_format_double(yajlpp_parse_context* ypc, double val) read_format_double(yajlpp_parse_context* ypc, double val)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); 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 (field_name == "timestamp-divisor") {
if (val <= 0) { if (val <= 0) {
@ -213,7 +210,7 @@ static int
read_format_int(yajlpp_parse_context* ypc, long long val) read_format_int(yajlpp_parse_context* ypc, long long val)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); 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 (field_name == "timestamp-divisor") {
if (val <= 0) { 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 elf = (external_log_format*) ypc->ypc_obj_stack.top();
auto leading_slash = len > 0 && str[0] == '/'; auto leading_slash = len > 0 && str[0] == '/';
auto value = string((const char*) (leading_slash ? str + 1 : str), auto value = std::string((const char*) (leading_slash ? str + 1 : str),
leading_slash ? len - 1 : len); leading_slash ? len - 1 : len);
auto field_name = ypc->get_path_fragment(1); auto field_name = ypc->get_path_fragment(1);
if (field_name == "file-pattern") { if (field_name == "file-pattern") {
@ -286,8 +283,8 @@ static int
read_levels(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) read_levels(yajlpp_parse_context* ypc, const unsigned char* str, size_t len)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); auto elf = (external_log_format*) ypc->ypc_obj_stack.top();
string regex = string((const char*) str, len); auto regex = std::string((const char*) str, len);
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()); log_level_t level = string2level(level_name_or_number.c_str());
elf->elf_level_patterns[level].lp_regex = regex; elf->elf_level_patterns[level].lp_regex = regex;
@ -298,7 +295,7 @@ static int
read_level_int(yajlpp_parse_context* ypc, long long val) read_level_int(yajlpp_parse_context* ypc, long long val)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); 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()); log_level_t level = string2level(level_name_or_number.c_str());
elf->elf_level_pairs.emplace_back(val, level); 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) read_action_def(yajlpp_parse_context* ypc, const unsigned char* str, size_t len)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); auto elf = (external_log_format*) ypc->ypc_obj_stack.top();
string action_name = ypc->get_path_fragment(2); auto action_name = ypc->get_path_fragment(2);
string field_name = ypc->get_path_fragment(3); auto field_name = ypc->get_path_fragment(3);
string val = string((const char*) str, len); 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_name = action_name;
if (field_name == "label") if (field_name == "label")
@ -325,8 +322,8 @@ static int
read_action_bool(yajlpp_parse_context* ypc, int val) read_action_bool(yajlpp_parse_context* ypc, int val)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); auto elf = (external_log_format*) ypc->ypc_obj_stack.top();
string action_name = ypc->get_path_fragment(2); auto action_name = ypc->get_path_fragment(2);
string field_name = ypc->get_path_fragment(3); auto field_name = ypc->get_path_fragment(3);
elf->lf_action_defs[action_name].ad_capture_output = val; 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) read_action_cmd(yajlpp_parse_context* ypc, const unsigned char* str, size_t len)
{ {
auto elf = (external_log_format*) ypc->ypc_obj_stack.top(); auto elf = (external_log_format*) ypc->ypc_obj_stack.top();
string action_name = ypc->get_path_fragment(2); auto action_name = ypc->get_path_fragment(2);
string field_name = ypc->get_path_fragment(3); auto field_name = ypc->get_path_fragment(3);
string val = string((const char*) str, len); 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_name = action_name;
elf->lf_action_defs[action_name].ad_cmdline.push_back(val); 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, const unsigned char* str,
size_t len) 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(); auto elf = (external_log_format*) ypc->ypc_obj_stack.top();
ypc->ypc_array_index.back() += 1; 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(); auto elf = (external_log_format*) ypc->ypc_obj_stack.top();
const intern_string_t table_name = ypc->get_path_fragment_i(2); 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); elf->elf_search_tables.emplace_back(table_name, regex);
@ -810,7 +807,7 @@ struct json_path_container format_handlers = {
static int static int
read_id(yajlpp_parse_context* ypc, const unsigned char* str, size_t len) 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(), if (find(SUPPORTED_FORMAT_SCHEMAS.begin(),
SUPPORTED_FORMAT_SCHEMAS.end(), SUPPORTED_FORMAT_SCHEMAS.end(),
@ -927,7 +924,7 @@ format_error_reporter(const yajlpp_parse_context& ypc,
std::vector<intern_string_t> std::vector<intern_string_t>
load_format_file(const ghc::filesystem::path& filename, load_format_file(const ghc::filesystem::path& filename,
std::vector<string>& errors) std::vector<std::string>& errors)
{ {
std::vector<intern_string_t> retval; std::vector<intern_string_t> retval;
struct userdata ud; struct userdata ud;
@ -985,7 +982,8 @@ load_format_file(const ghc::filesystem::path& filename,
} }
static void static void
load_from_path(const ghc::filesystem::path& path, std::vector<string>& errors) load_from_path(const ghc::filesystem::path& path,
std::vector<std::string>& errors)
{ {
auto format_path = path / "formats/*/*.json"; auto format_path = path / "formats/*/*.json";
static_root_mem<glob_t, globfree> gl; static_root_mem<glob_t, globfree> gl;
@ -999,8 +997,8 @@ load_from_path(const ghc::filesystem::path& path, std::vector<string>& errors)
continue; continue;
} }
string filename(gl->gl_pathv[lpc]); std::string filename(gl->gl_pathv[lpc]);
vector<intern_string_t> format_list; std::vector<intern_string_t> format_list;
format_list = load_format_file(filename, errors); format_list = load_format_file(filename, errors);
if (format_list.empty()) { if (format_list.empty()) {
@ -1059,7 +1057,7 @@ load_formats(const std::vector<ghc::filesystem::path>& extra_paths,
uint8_t mod_counter = 0; uint8_t mod_counter = 0;
vector<std::shared_ptr<external_log_format>> alpha_ordered_formats; std::vector<std::shared_ptr<external_log_format>> alpha_ordered_formats;
for (auto iter = LOG_FORMATS.begin(); iter != LOG_FORMATS.end(); ++iter) { for (auto iter = LOG_FORMATS.begin(); iter != LOG_FORMATS.end(); ++iter) {
auto& elf = iter->second; auto& elf = iter->second;
elf->build(errors); elf->build(errors);
@ -1096,7 +1094,7 @@ load_formats(const std::vector<ghc::filesystem::path>& extra_paths,
auto& graph_ordered_formats = external_log_format::GRAPH_ORDERED_FORMATS; auto& graph_ordered_formats = external_log_format::GRAPH_ORDERED_FORMATS;
while (!alpha_ordered_formats.empty()) { while (!alpha_ordered_formats.empty()) {
vector<intern_string_t> popped_formats; std::vector<intern_string_t> popped_formats;
for (auto iter = alpha_ordered_formats.begin(); for (auto iter = alpha_ordered_formats.begin();
iter != alpha_ordered_formats.end();) iter != alpha_ordered_formats.end();)
@ -1156,7 +1154,7 @@ load_formats(const std::vector<ghc::filesystem::path>& extra_paths,
static void static void
exec_sql_in_path(sqlite3* db, exec_sql_in_path(sqlite3* db,
const ghc::filesystem::path& path, const ghc::filesystem::path& path,
std::vector<string>& errors) std::vector<std::string>& errors)
{ {
auto format_path = path / "formats/*/*.sql"; auto format_path = path / "formats/*/*.sql";
static_root_mem<glob_t, globfree> gl; static_root_mem<glob_t, globfree> gl;
@ -1216,7 +1214,7 @@ extract_metadata(const char* contents,
if (!meta_out.sm_synopsis.empty()) { if (!meta_out.sm_synopsis.empty()) {
size_t space = meta_out.sm_synopsis.find(' '); size_t space = meta_out.sm_synopsis.find(' ');
if (space == string::npos) { if (space == std::string::npos) {
space = meta_out.sm_synopsis.size(); space = meta_out.sm_synopsis.size();
} }
meta_out.sm_name = meta_out.sm_synopsis.substr(0, space); 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) { if (glob(format_path.c_str(), 0, nullptr, gl.inout()) == 0) {
for (int lpc = 0; lpc < (int) gl->gl_pathc; lpc++) { for (int lpc = 0; lpc < (int) gl->gl_pathc; lpc++) {
const char* filename = basename(gl->gl_pathv[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; struct script_metadata meta;
meta.sm_path = gl->gl_pathv[lpc]; meta.sm_path = gl->gl_pathv[lpc];
@ -1267,7 +1265,7 @@ find_format_in_path(const ghc::filesystem::path& path,
} }
void void
find_format_scripts(const vector<ghc::filesystem::path>& extra_paths, find_format_scripts(const std::vector<ghc::filesystem::path>& extra_paths,
available_scripts& scripts) available_scripts& scripts)
{ {
for (const auto& extra_path : extra_paths) { for (const auto& extra_path : extra_paths) {

View File

@ -38,8 +38,6 @@
#include "yajlpp/json_op.hh" #include "yajlpp/json_op.hh"
#include "yajlpp/yajlpp_def.hh" #include "yajlpp/yajlpp_def.hh"
using namespace std;
static auto intern_lifetime = intern_string::get_table_lifetime(); static auto intern_lifetime = intern_string::get_table_lifetime();
static struct log_cursor log_cursor_latest; 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++) { for (iter = cols.begin(); iter != cols.end(); iter++) {
auto_mem<char, sqlite3_free> coldecl; auto_mem<char, sqlite3_free> coldecl;
auto_mem<char, sqlite3_free> colname; auto_mem<char, sqlite3_free> colname;
string comment; std::string comment;
require(!iter->vc_name.empty()); require(!iter->vc_name.empty());
@ -132,7 +130,7 @@ log_vtab_impl::get_table_statement()
return oss.str(); return oss.str();
} }
pair<int, unsigned int> std::pair<int, unsigned int>
log_vtab_impl::logline_value_to_sqlite_type(value_kind_t kind) log_vtab_impl::logline_value_to_sqlite_type(value_kind_t kind)
{ {
int type = 0; int type = 0;
@ -164,7 +162,7 @@ log_vtab_impl::logline_value_to_sqlite_type(value_kind_t kind)
ensure(0); ensure(0);
break; break;
} }
return make_pair(type, subtype); return std::make_pair(type, subtype);
} }
struct vtab { 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)); content_line_t cl(vt->lss->at(vc->log_cursor.lc_curr_line));
uint64_t line_number; uint64_t line_number;
auto ld = vt->lss->find_data(cl, line_number); auto ld = vt->lss->find_data(cl, line_number);
shared_ptr<logfile> lf = (*ld)->get_file(); auto lf = (*ld)->get_file();
auto ll = lf->begin() + line_number; auto ll = lf->begin() + line_number;
require(col >= 0); require(col >= 0);
@ -419,8 +417,8 @@ vt_column(sqlite3_vtab_cursor* cur, sqlite3_context* ctx, int col)
} else { } else {
content_line_t prev_cl( content_line_t prev_cl(
vt->lss->at(vis_line_t(vc->log_cursor.lc_curr_line - 1))); vt->lss->at(vis_line_t(vc->log_cursor.lc_curr_line - 1)));
shared_ptr<logfile> prev_lf = vt->lss->find(prev_cl); auto prev_lf = vt->lss->find(prev_cl);
logfile::iterator prev_ll = prev_lf->begin() + prev_cl; auto prev_ll = prev_lf->begin() + prev_cl;
uint64_t prev_time, curr_line_time; uint64_t prev_time, curr_line_time;
prev_time = prev_ll->get_time() * 1000ULL; 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: { case VT_COL_LOG_TAGS: {
const map<content_line_t, bookmark_metadata>& bm const auto& bm = vt->lss->get_user_bookmark_metadata();
= vt->lss->get_user_bookmark_metadata();
auto bm_iter = bm.find(vt->lss->at(vc->log_cursor.lc_curr_line)); 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()) { 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; break;
} }
case 1: { case 1: {
const string& fn = lf->get_filename(); const auto& fn = lf->get_filename();
sqlite3_result_text( sqlite3_result_text(
ctx, fn.c_str(), fn.length(), SQLITE_STATIC); ctx, fn.c_str(), fn.length(), SQLITE_STATIC);
@ -984,7 +981,7 @@ vt_update(sqlite3_vtab* tab,
bookmark_metadata tmp_bm; bookmark_metadata tmp_bm;
if (log_tags) { if (log_tags) {
vector<string> errors; std::vector<std::string> errors;
yajlpp_parse_context ypc(log_vtab_data.lvd_source, &tags_handler); yajlpp_parse_context ypc(log_vtab_data.lvd_source, &tags_handler);
auto_mem<yajl_handle_t> handle(yajl_free); auto_mem<yajl_handle_t> handle(yajl_free);
@ -995,8 +992,8 @@ vt_update(sqlite3_vtab* tab,
.with_error_reporter([](const yajlpp_parse_context& ypc, .with_error_reporter([](const yajlpp_parse_context& ypc,
lnav_log_level_t level, lnav_log_level_t level,
const char* msg) { const char* msg) {
vector<string>& errors auto& errors
= *((vector<string>*) ypc.ypc_userdata); = *((std::vector<std::string>*) ypc.ypc_userdata);
errors.emplace_back(msg); errors.emplace_back(msg);
}) })
.with_obj(tmp_bm); .with_obj(tmp_bm);
@ -1026,12 +1023,12 @@ vt_update(sqlite3_vtab* tab,
vt->tc->set_user_mark(&textview_curses::BM_META, vrowid, true); vt->tc->set_user_mark(&textview_curses::BM_META, vrowid, true);
if (part_name) { if (part_name) {
line_meta.bm_name = string((const char*) part_name); line_meta.bm_name = std::string((const char*) part_name);
} else { } else {
line_meta.bm_name.clear(); line_meta.bm_name.clear();
} }
if (log_comment) { if (log_comment) {
line_meta.bm_comment = string((const char*) log_comment); line_meta.bm_comment = std::string((const char*) log_comment);
} else { } else {
line_meta.bm_comment.clear(); 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<log_vtab_impl> vi) log_vtab_manager::register_vtab(std::shared_ptr<log_vtab_impl> vi)
{ {
string retval; std::string retval;
if (this->vm_impls.find(vi->get_name()) == this->vm_impls.end()) { if (this->vm_impls.find(vi->get_name()) == this->vm_impls.end()) {
auto_mem<char, sqlite3_free> errmsg; auto_mem<char, sqlite3_free> errmsg;
@ -1153,10 +1150,10 @@ log_vtab_manager::register_vtab(std::shared_ptr<log_vtab_impl> vi)
return retval; return retval;
} }
string std::string
log_vtab_manager::unregister_vtab(intern_string_t name) log_vtab_manager::unregister_vtab(intern_string_t name)
{ {
string retval; std::string retval;
if (this->vm_impls.find(name) == this->vm_impls.end()) { if (this->vm_impls.find(name) == this->vm_impls.end()) {
retval = fmt::format(FMT_STRING("unknown log line table -- {}"), name); retval = fmt::format(FMT_STRING("unknown log line table -- {}"), name);

View File

@ -33,7 +33,6 @@
#include "logfile.hh" #include "logfile.hh"
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
@ -51,8 +50,6 @@
#include "log_format.hh" #include "log_format.hh"
#include "logfile.cfg.hh" #include "logfile.cfg.hh"
using namespace std;
static auto intern_lifetime = intern_string::get_table_lifetime(); static auto intern_lifetime = intern_string::get_table_lifetime();
static const size_t INDEX_RESERVE_INCREMENT = 1024; static const size_t INDEX_RESERVE_INCREMENT = 1024;
@ -126,7 +123,7 @@ logfile::open(std::string filename, logfile_open_options& loo)
return Ok(lf); 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)) : 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<const lnav::logfile::config&>() < injector::get<const lnav::logfile::config&>()
.lc_max_unrecognized_lines) .lc_max_unrecognized_lines)
{ {
auto& root_formats = log_format::get_root_formats(); const auto& root_formats = log_format::get_root_formats();
vector<std::shared_ptr<log_format>>::iterator iter;
/* /*
* Try each scanner until we get a match. Fortunately, all the formats * Try each scanner until we get a match. Fortunately, all the formats
* are sufficiently different that there are no ambiguities... * 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 != root_formats.end() && (found != log_format::SCAN_MATCH);
++iter) ++iter)
{ {
@ -647,7 +643,7 @@ logfile::read_line(logfile::iterator ll)
return sbr; return sbr;
}); });
} catch (line_buffer::error& e) { } 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 void
logfile::mark_as_duplicate(const string& name) logfile::mark_as_duplicate(const std::string& name)
{ {
this->lf_indexing = false; this->lf_indexing = false;
this->lf_options.loo_is_visible = false; this->lf_options.loo_is_visible = false;

View File

@ -1,3 +1,4 @@
/** /**
* Copyright (c) 2007-2012, Timothy Stack * Copyright (c) 2007-2012, Timothy Stack
* *

View File

@ -35,7 +35,7 @@
#include <chrono> #include <chrono>
#include <string> #include <string>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "file_format.hh" #include "file_format.hh"
using ui_clock = std::chrono::steady_clock; using ui_clock = std::chrono::steady_clock;
@ -52,20 +52,51 @@ enum class logfile_name_source {
REMOTE, 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) logfile_open_options& with_filename(const std::string& val)
{ {
this->loo_filename = val; this->loo_filename = val;
return *this; return *this;
}; }
logfile_open_options& with_fd(auto_fd fd) logfile_open_options& with_fd(auto_fd fd)
{ {
this->loo_fd = std::move(fd); this->loo_fd = std::move(fd);
this->loo_temp_file = true;
return *this; 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) logfile_open_options& with_source(logfile_name_source src)
{ {
@ -79,7 +110,7 @@ struct logfile_open_options {
this->loo_detect_format = val; this->loo_detect_format = val;
return *this; return *this;
}; }
logfile_open_options& with_include_in_session(bool val) logfile_open_options& with_include_in_session(bool val)
{ {
@ -123,16 +154,7 @@ struct logfile_open_options {
return *this; return *this;
} }
std::string loo_filename;
auto_fd loo_fd; 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 #endif

View File

@ -46,8 +46,6 @@
#include "sql_util.hh" #include "sql_util.hh"
#include "yajlpp/yajlpp.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_ERRORS("error");
const bookmark_type_t logfile_sub_source::BM_WARNINGS("warning"); const bookmark_type_t logfile_sub_source::BM_WARNINGS("warning");
const bookmark_type_t logfile_sub_source::BM_FILES(""); const bookmark_type_t logfile_sub_source::BM_FILES("");
@ -77,19 +75,19 @@ pretty_sql_callback(exec_context& ec, sqlite3_stmt* stmt)
return 0; return 0;
} }
static future<string> static std::future<std::string>
pretty_pipe_callback(exec_context& ec, const string& cmdline, auto_fd& fd) pretty_pipe_callback(exec_context& ec, const std::string& cmdline, auto_fd& fd)
{ {
auto retval = std::async(std::launch::async, [&]() { auto retval = std::async(std::launch::async, [&]() {
char buffer[1024]; char buffer[1024];
ostringstream ss; std::ostringstream ss;
ssize_t rc; ssize_t rc;
while ((rc = read(fd, buffer, sizeof(buffer))) > 0) { while ((rc = read(fd, buffer, sizeof(buffer))) > 0) {
ss.write(buffer, rc); ss.write(buffer, rc);
} }
string retval = ss.str(); auto retval = ss.str();
if (endswith(retval, "\n")) { if (endswith(retval, "\n")) {
retval.resize(retval.length() - 1); retval.resize(retval.length() - 1);
@ -109,11 +107,11 @@ logfile_sub_source::logfile_sub_source()
this->clear_min_max_log_times(); this->clear_min_max_log_times();
} }
shared_ptr<logfile> std::shared_ptr<logfile>
logfile_sub_source::find(const char* fn, content_line_t& line_base) logfile_sub_source::find(const char* fn, content_line_t& line_base)
{ {
iterator iter; iterator iter;
shared_ptr<logfile> retval = nullptr; std::shared_ptr<logfile> retval = nullptr;
line_base = content_line_t(0); line_base = content_line_t(0);
for (iter = this->lss_files.begin(); for (iter = this->lss_files.begin();
@ -153,7 +151,7 @@ logfile_sub_source::find_from_time(const struct timeval& start) const
void void
logfile_sub_source::text_value_for_line(textview_curses& tc, logfile_sub_source::text_value_for_line(textview_curses& tc,
int row, int row,
string& value_out, std::string& value_out,
line_flags_t flags) line_flags_t flags)
{ {
content_line_t line(0); 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)); line = this->at(vis_line_t(row));
if (flags & RF_RAW) { if (flags & RF_RAW) {
shared_ptr<logfile> lf = this->find(line); auto lf = this->find(line);
value_out = lf->read_line(lf->begin() + line) value_out = lf->read_line(lf->begin() + line)
.map([](auto sbr) { return to_string(sbr); }) .map([](auto sbr) { return to_string(sbr); })
.unwrapOr({}); .unwrapOr({});
@ -221,10 +219,10 @@ logfile_sub_source::text_value_for_line(textview_curses& tc,
if (flags & RF_REWRITE) { if (flags & RF_REWRITE) {
exec_context ec( exec_context ec(
&this->lss_token_values, pretty_sql_callback, pretty_pipe_callback); &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.with_perms(exec_context::perm_t::READ_ONLY);
ec.ec_local_vars.push(map<string, string>()); ec.ec_local_vars.push(std::map<std::string, std::string>());
ec.ec_top_line = vis_line_t(row); ec.ec_top_line = vis_line_t(row);
add_ansi_vars(ec.ec_global_vars); add_ansi_vars(ec.ec_global_vars);
add_global_vars(ec); add_global_vars(ec);
@ -438,8 +436,9 @@ logfile_sub_source::text_attrs_for_line(textview_curses& lv,
bookmark_vector<vis_line_t>& bv_search bookmark_vector<vis_line_t>& bv_search
= bm[&textview_curses::BM_SEARCH]; = bm[&textview_curses::BM_SEARCH];
if (binary_search( if (binary_search(std::begin(bv_search),
::begin(bv_search), ::end(bv_search), vis_line_t(row))) { std::end(bv_search),
vis_line_t(row))) {
lr.lr_start = 0; lr.lr_start = 0;
lr.lr_end = 1; lr.lr_end = 1;
value_out.emplace_back(lr, &view_curses::VC_STYLE, A_REVERSE); 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( value_out.emplace_back(
lr, &SA_FORMAT, this->lss_token_file->get_format()->get_name()); 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]; const auto& bv = lv.get_bookmarks()[&textview_curses::BM_META];
bookmark_vector<vis_line_t>::const_iterator bv_iter; bookmark_vector<vis_line_t>::const_iterator bv_iter;
@ -779,10 +781,10 @@ logfile_sub_source::rebuild_index(
remaining += lf->size() - ld.ld_lines_indexed; remaining += lf->size() - ld.ld_lines_indexed;
} }
auto row_iter = lower_bound(this->lss_index.begin(), auto row_iter = std::lower_bound(this->lss_index.begin(),
this->lss_index.end(), this->lss_index.end(),
*lowest_tv, *lowest_tv,
logline_cmp(*this)); logline_cmp(*this));
this->lss_index.shrink_to( this->lss_index.shrink_to(
std::distance(this->lss_index.begin(), row_iter)); std::distance(this->lss_index.begin(), row_iter));
log_debug("new index size %ld/%ld; remain %ld", log_debug("new index size %ld/%ld; remain %ld",
@ -862,7 +864,8 @@ logfile_sub_source::rebuild_index(
if (this->lss_sorting_observer) { if (this->lss_sorting_observer) {
this->lss_sorting_observer(*this, 0, this->lss_index.size()); 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) { if (this->lss_sorting_observer) {
this->lss_sorting_observer( this->lss_sorting_observer(
*this, this->lss_index.size(), this->lss_index.size()); *this, this->lss_index.size(), this->lss_index.size());
@ -1011,7 +1014,7 @@ logfile_sub_source::rebuild_index(
void void
logfile_sub_source::text_update_marks(vis_bookmarks& bm) logfile_sub_source::text_update_marks(vis_bookmarks& bm)
{ {
shared_ptr<logfile> last_file = nullptr; std::shared_ptr<logfile> last_file;
vis_line_t vl; vis_line_t vl;
bm[&BM_WARNINGS].clear(); 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) { for (; vl < (int) this->lss_filtered_index.size(); ++vl) {
const content_line_t orig_cl = this->at(vl); const content_line_t orig_cl = this->at(vl);
content_line_t cl = orig_cl; content_line_t cl = orig_cl;
shared_ptr<logfile> lf; auto lf = this->find(cl);
lf = this->find(cl);
for (auto& lss_user_mark : this->lss_user_marks) { for (auto& lss_user_mark : this->lss_user_marks) {
if (binary_search(lss_user_mark.second.begin(), 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< nonstd::optional<
pair<grep_proc_source<vis_line_t>*, grep_proc_sink<vis_line_t>*>> std::pair<grep_proc_source<vis_line_t>*, grep_proc_sink<vis_line_t>*>>
logfile_sub_source::get_grepper() logfile_sub_source::get_grepper()
{ {
return make_pair((grep_proc_source<vis_line_t>*) &this->lss_meta_grepper, return std::make_pair(
(grep_proc_sink<vis_line_t>*) &this->lss_meta_grepper); (grep_proc_source<vis_line_t>*) &this->lss_meta_grepper,
(grep_proc_sink<vis_line_t>*) &this->lss_meta_grepper);
} }
bool bool
logfile_sub_source::insert_file(const shared_ptr<logfile>& lf) logfile_sub_source::insert_file(const std::shared_ptr<logfile>& lf)
{ {
iterator existing; iterator existing;
@ -1368,7 +1370,7 @@ logfile_sub_source::eval_sql_filter(sqlite3_stmt* stmt,
lf->read_full_message(ll, sbr); lf->read_full_message(ll, sbr);
auto format = lf->get_format(); auto format = lf->get_format();
string_attrs_t sa; string_attrs_t sa;
vector<logline_value> values; std::vector<logline_value> values;
format->annotate(std::distance(lf->cbegin(), ll), sbr, sa, values); format->annotate(std::distance(lf->cbegin(), ll), sbr, sa, values);
sqlite3_reset(stmt); sqlite3_reset(stmt);
@ -1829,7 +1831,7 @@ sql_filter::to_command() const
bool bool
logfile_sub_source::meta_grepper::grep_value_for_line(vis_line_t line, 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)); content_line_t cl = this->lmg_source.at(vis_line_t(line));
std::map<content_line_t, bookmark_metadata>& user_mark_meta std::map<content_line_t, bookmark_metadata>& user_mark_meta

View File

@ -41,9 +41,7 @@
#include "sqlite3.h" #include "sqlite3.h"
#include "vtab_module.hh" #include "vtab_module.hh"
using namespace std; static std::string
static string
sql_gethostbyname(const char* name_in) sql_gethostbyname(const char* name_in)
{ {
char buffer[INET6_ADDRSTRLEN]; char buffer[INET6_ADDRSTRLEN];
@ -84,7 +82,7 @@ sql_gethostbyname(const char* name_in)
return buffer; return buffer;
} }
static string static std::string
sql_gethostbyaddr(const char* addr_str) sql_gethostbyaddr(const char* addr_str)
{ {
union { union {

View File

@ -45,8 +45,8 @@
# include <sys/wait.h> # include <sys/wait.h>
# include <unistd.h> # include <unistd.h>
# include "auto_fd.hh"
# include "auto_mem.hh" # include "auto_mem.hh"
# include "base/auto_fd.hh"
# include "curl_looper.hh" # include "curl_looper.hh"
# include "line_buffer.hh" # include "line_buffer.hh"
# include "yajlpp/yajlpp.hh" # include "yajlpp/yajlpp.hh"
@ -117,7 +117,7 @@ public:
auto_fd copy_fd() const auto_fd copy_fd() const
{ {
return this->ptp_fd; return this->ptp_fd.dup();
}; };
long complete(CURLcode result); long complete(CURLcode result);

View File

@ -59,7 +59,7 @@ convert(const std::string& filename)
auto dev_null = open("/dev/null", O_RDONLY); auto dev_null = open("/dev/null", O_RDONLY);
dup2(dev_null, STDIN_FILENO); dup2(dev_null, STDIN_FILENO);
dup2(outfile.second, STDOUT_FILENO); dup2(outfile.second.release(), STDOUT_FILENO);
setenv("TZ", "UTC", 1); setenv("TZ", "UTC", 1);
const char* args[] = { const char* args[] = {
@ -131,7 +131,7 @@ convert(const std::string& filename)
return Ok(convert_result{ return Ok(convert_result{
std::move(child), std::move(child),
auto_fd(outfile.second), std::move(outfile.second),
error_queue, error_queue,
}); });
} }

View File

@ -35,7 +35,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "base/auto_pid.hh" #include "base/auto_pid.hh"
#include "base/result.h" #include "base/result.h"

View File

@ -31,8 +31,6 @@
#include "pcrepp.hh" #include "pcrepp.hh"
using namespace std;
const int JIT_STACK_MIN_SIZE = 32 * 1024; const int JIT_STACK_MIN_SIZE = 32 * 1024;
const int JIT_STACK_MAX_SIZE = 512 * 1024; const int JIT_STACK_MAX_SIZE = 512 * 1024;
@ -87,7 +85,7 @@ void
pcrepp::find_captures(const char* pattern) pcrepp::find_captures(const char* pattern)
{ {
bool in_class = false, in_escape = false, in_literal = false; bool in_class = false, in_escape = false, in_literal = false;
vector<pcre_context::capture> cap_in_progress; std::vector<pcre_context::capture> cap_in_progress;
for (int lpc = 0; pattern[lpc]; lpc++) { for (int lpc = 0; pattern[lpc]; lpc++) {
if (in_escape) { if (in_escape) {

View File

@ -45,8 +45,6 @@
#include "config.h" #include "config.h"
#include "line_buffer.hh" #include "line_buffer.hh"
using namespace std;
static const char* STDIN_EOF_MSG = "---- END-OF-STDIN ----"; static const char* STDIN_EOF_MSG = "---- END-OF-STDIN ----";
static ssize_t static ssize_t
@ -64,10 +62,11 @@ write_timestamp(int fd, off_t woff)
return pwrite(fd, time_str, strlen(time_str), woff); return pwrite(fd, time_str, strlen(time_str), woff);
} }
piper_proc::piper_proc(int pipefd, bool timestamp, int filefd) piper_proc::piper_proc(auto_fd pipefd, bool timestamp, auto_fd filefd)
: pp_fd(filefd), pp_child(-1) : 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)); 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); throw error(errno);
case 0: { case 0: {
auto_fd infd(pipefd);
line_buffer lb; line_buffer lb;
off_t woff = 0, last_woff = 0; off_t woff = 0, last_woff = 0;
file_range last_range; file_range last_range;
@ -101,8 +99,8 @@ piper_proc::piper_proc(int pipefd, bool timestamp, int filefd)
close(fd_to_close); close(fd_to_close);
} }
} }
log_perror(fcntl(infd.get(), F_SETFL, O_NONBLOCK)); log_perror(fcntl(pipefd.get(), F_SETFL, O_NONBLOCK));
lb.set_fd(infd); lb.set_fd(pipefd);
do { do {
struct pollfd pfd = {lb.get_fd(), POLLIN, 0}; struct pollfd pfd = {lb.get_fd(), POLLIN, 0};

View File

@ -36,7 +36,7 @@
#include <sys/types.h> #include <sys/types.h>
#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 * 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. * the lines read from pipefd.
* @param filefd The descriptor for the backing file. * @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(); bool has_exited();
@ -74,7 +74,7 @@ public:
/** @return The file descriptor for the temporary file. */ /** @return The file descriptor for the temporary file. */
auto_fd get_fd() auto_fd get_fd()
{ {
return std::move(this->pp_fd); return this->pp_fd.dup();
}; };
pid_t get_child_pid() const pid_t get_child_pid() const

View File

@ -49,8 +49,6 @@
#include "vtab_module.hh" #include "vtab_module.hh"
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
using namespace std;
#define ABORT_MSG "(Press " ANSI_BOLD("CTRL+]") " to abort)" #define ABORT_MSG "(Press " ANSI_BOLD("CTRL+]") " to abort)"
#define STR_HELPER(x) #x #define STR_HELPER(x) #x
@ -179,10 +177,10 @@ rl_sql_help(readline_curses* rc)
for (const auto& ht : avail_help) { for (const auto& ht : avail_help) {
format_help_text_for_term( 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) { if (help_count == 1) {
format_example_text_for_term( 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 intern_ident = intern_string::lookup(ident);
auto vtab = lnav_data.ld_vtab_manager->lookup_impl(intern_ident); auto vtab = lnav_data.ld_vtab_manager->lookup_impl(intern_ident);
auto vtab_module_iter = vtab_module_ddls.find(intern_ident); auto vtab_module_iter = vtab_module_ddls.find(intern_ident);
string ddl; std::string ddl;
if (vtab != nullptr) { if (vtab != nullptr) {
ddl = trim(vtab->get_table_statement()); ddl = trim(vtab->get_table_statement());
@ -250,11 +248,11 @@ rl_change(readline_curses* rc)
switch (lnav_data.ld_mode) { switch (lnav_data.ld_mode) {
case LNM_COMMAND: { case LNM_COMMAND: {
static string last_command; static std::string last_command;
static int generation = 0; static int generation = 0;
string line = rc->get_line_buffer(); const auto line = rc->get_line_buffer();
vector<string> args; std::vector<std::string> args;
auto iter = lnav_commands.end(); auto iter = lnav_commands.end();
split_ws(line, args); split_ws(line, args);
@ -336,7 +334,7 @@ rl_change(readline_curses* rc)
attr_line_t al; attr_line_t al;
dtc.get_dimensions(height, width); 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); lnav_data.ld_doc_source.replace_with(al);
dtc.set_needs_update(); dtc.set_needs_update();
@ -349,7 +347,7 @@ rl_change(readline_curses* rc)
if (cmd.c_prompt != nullptr && generation == 0 if (cmd.c_prompt != nullptr && generation == 0
&& trim(line) == args[0]) { && trim(line) == args[0]) {
string new_prompt const auto new_prompt
= cmd.c_prompt(lnav_data.ld_exec_context, line); = cmd.c_prompt(lnav_data.ld_exec_context, line);
if (!new_prompt.empty()) { if (!new_prompt.empty()) {
@ -363,9 +361,9 @@ rl_change(readline_curses* rc)
break; break;
} }
case LNM_EXEC: { case LNM_EXEC: {
string line = rc->get_line_buffer(); const auto line = rc->get_line_buffer();
size_t name_end = line.find(' '); 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<available_scripts&>(); auto& scripts = injector::get<available_scripts&>();
auto iter = scripts.as_scripts.find(script_name); 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) rl_search_internal(readline_curses* rc, ln_mode_t mode, bool complete = false)
{ {
textview_curses* tc = get_textview_for_mode(mode); textview_curses* tc = get_textview_for_mode(mode);
string term_val; std::string term_val;
string name; std::string name;
tc->get_highlights().erase({highlight_source_t::PREVIEW, "preview"}); tc->get_highlights().erase({highlight_source_t::PREVIEW, "preview"});
tc->get_highlights().erase({highlight_source_t::PREVIEW, "bodypreview"}); 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"}); tc->get_highlights().erase({highlight_source_t::PREVIEW, "bodypreview"});
lnav_data.ld_log_source.set_preview_sql_filter(nullptr); lnav_data.ld_log_source.set_preview_sql_filter(nullptr);
vector<string> errors; std::vector<std::string> errors;
lnav_config = rollback_lnav_config; lnav_config = rollback_lnav_config;
reload_config(errors); 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); textview_curses* tc = get_textview_for_mode(lnav_data.ld_mode);
exec_context& ec = lnav_data.ld_exec_context; 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_bottom_source.set_prompt("");
lnav_data.ld_doc_source.clear(); lnav_data.ld_doc_source.clear();
@ -649,7 +647,7 @@ rl_callback_int(readline_curses* rc, bool is_alt)
case LNM_SQL: { case LNM_SQL: {
auto result = execute_sql(ec, rc->get_value(), alt_msg); auto result = execute_sql(ec, rc->get_value(), alt_msg);
db_label_source& dls = lnav_data.ld_db_row_source; db_label_source& dls = lnav_data.ld_db_row_source;
string prompt; std::string prompt;
if (result.isOk()) { if (result.isOk()) {
auto msg = result.unwrap(); auto msg = result.unwrap();
@ -675,24 +673,25 @@ rl_callback_int(readline_curses* rc, bool is_alt)
tmpout = std::tmpfile(); tmpout = std::tmpfile();
if (!tmpout) { if (!tmpout) {
rc->set_value("Unable to open temporary output file: " rc->set_value(fmt::format(
+ string(strerror(errno))); FMT_STRING("Unable to open temporary output file: {}"),
strerror(errno)));
} else { } else {
auto fd_copy = auto_fd::dup_of(fileno(tmpout)); auto fd_copy = auto_fd::dup_of(fileno(tmpout));
char desc[256], timestamp[32]; char desc[256], timestamp[32];
time_t current_time = time(nullptr); 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( exec_context::output_guard og(
ec, "tmp", std::make_pair(tmpout.release(), fclose)); ec, "tmp", std::make_pair(tmpout.release(), fclose));
string result = execute_file(ec, path_and_args) auto result = execute_file(ec, path_and_args)
.map(ok_prefix) .map(ok_prefix)
.orElse(err_to_ok) .orElse(err_to_ok)
.unwrap(); .unwrap();
string::size_type lf_index = result.find('\n'); auto lf_index = result.find('\n');
if (lf_index != string::npos) { if (lf_index != std::string::npos) {
result = result.substr(0, lf_index); result = result.substr(0, lf_index);
} }
rc->set_value(result); rc->set_value(result);
@ -711,7 +710,7 @@ rl_callback_int(readline_curses* rc, bool is_alt)
path_and_args.c_str(), path_and_args.c_str(),
timestamp); timestamp);
lnav_data.ld_active_files.fc_file_names[desc] 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_include_in_session(false)
.with_detect_format(false); .with_detect_format(false);
lnav_data.ld_files_to_front.emplace_back(desc, 0); 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); getmaxyx(lnav_data.ld_window, height, width);
max_len = rc->get_max_match_length() + 2; max_len = rc->get_max_match_length() + 2;
cols = max(1UL, width / max_len); cols = std::max(1UL, width / max_len);
if (matches.empty()) { if (matches.empty()) {
lnav_data.ld_match_source.clear(); lnav_data.ld_match_source.clear();
} else { } else {
string current_match = rc->get_match_string(); const auto current_match = rc->get_match_string();
int curr_col = 0; int curr_col = 0;
attr_line_t al; attr_line_t al;
bool add_nl = false; bool add_nl = false;

View File

@ -66,8 +66,6 @@
#include "shlex.hh" #include "shlex.hh"
#include "spookyhash/SpookyV2.h" #include "spookyhash/SpookyV2.h"
using namespace std;
static int got_line = 0; static int got_line = 0;
static bool alt_done = 0; static bool alt_done = 0;
static sig_atomic_t got_timeout = 0; static sig_atomic_t got_timeout = 0;
@ -93,8 +91,8 @@ static const char* RL_INIT[] = {
}; };
readline_context* readline_context::loaded_context; readline_context* readline_context::loaded_context;
set<string>* readline_context::arg_possibilities; std::set<std::string>* readline_context::arg_possibilities;
static string last_match_str; static std::string last_match_str;
static bool last_match_str_valid; static bool last_match_str_valid;
static bool arg_needs_shlex; static bool arg_needs_shlex;
static nonstd::optional<std::string> rewrite_line_start; static nonstd::optional<std::string> rewrite_line_start;
@ -226,9 +224,9 @@ recvstring(int sock, char* buf, size_t len)
char* char*
readline_context::completion_generator(const char* text_in, int state) readline_context::completion_generator(const char* text_in, int state)
{ {
static vector<string> matches; static std::vector<std::string> matches;
vector<string> long_matches; std::vector<std::string> long_matches;
char* retval = nullptr; char* retval = nullptr;
if (state == 0) { if (state == 0) {
@ -236,7 +234,7 @@ readline_context::completion_generator(const char* text_in, int state)
if (arg_needs_shlex) { if (arg_needs_shlex) {
shlex arg_lexer(text_str); shlex arg_lexer(text_str);
map<string, string> scope; std::map<std::string, std::string> scope;
std::string result; std::string result;
if (arg_lexer.eval(result, scope)) { if (arg_lexer.eval(result, scope)) {
@ -281,11 +279,11 @@ readline_context::completion_generator(const char* text_in, int state)
} }
if (matches.empty()) { if (matches.empty()) {
vector<pair<int, string>> fuzzy_matches; std::vector<std::pair<int, std::string>> fuzzy_matches;
vector<pair<int, string>> fuzzy_long_matches; std::vector<std::pair<int, std::string>> fuzzy_long_matches;
for (const auto& poss : (*arg_possibilities)) { for (const auto& poss : (*arg_possibilities)) {
string poss_str = tolower(poss); std::string poss_str = tolower(poss);
int score; int score;
if (fts::fuzzy_match( 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; rl_completion_append_character = loaded_context->rc_append_character;
} else { } else {
char* space; char* space;
string cmd; std::string cmd;
vector<string> prefix; std::vector<std::string> prefix;
int point = rl_point; int point = rl_point;
while (point > 0 && rl_line_buffer[point] != ' ') { while (point > 0 && rl_line_buffer[point] != ' ') {
point -= 1; point -= 1;
} }
shlex lexer(rl_line_buffer, point); shlex lexer(rl_line_buffer, point);
map<string, string> scope; std::map<std::string, std::string> scope;
arg_possibilities = nullptr; arg_possibilities = nullptr;
rl_completion_append_character = 0; rl_completion_append_character = 0;
@ -400,7 +398,7 @@ readline_context::attempted_completion(const char* text, int start, int end)
if (space == nullptr) { if (space == nullptr) {
space = rl_line_buffer + strlen(rl_line_buffer); 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); 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; = loaded_context->rc_append_character;
} }
} else { } else {
vector<string>& proto = loaded_context->rc_prototypes[cmd]; std::vector<std::string>& proto
= loaded_context->rc_prototypes[cmd];
if (proto.empty()) { if (proto.empty()) {
arg_possibilities = nullptr; 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 ? "" const auto& last_fn = fn_list.size() <= 1 ? ""
: fn_list.back(); : fn_list.back();
if (last_fn.find(':') != string::npos) { if (last_fn.find(':') != std::string::npos) {
auto rp_iter = loaded_context->rc_possibilities.find( auto rp_iter = loaded_context->rc_possibilities.find(
"remote-path"); "remote-path");
if (rp_iter != loaded_context->rc_possibilities.end()) { 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; max_len = 0;
for (int lpc = 0; lpc <= num_matches; lpc++) { 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) if (last_match_str_valid && strcmp(last_match_str.c_str(), matches[0]) == 0)
@ -742,7 +741,7 @@ readline_curses::start()
child_this = this; child_this = this;
} }
map<int, readline_context*>::iterator current_context; std::map<int, readline_context*>::iterator current_context;
int maxfd; int maxfd;
require(!this->rc_contexts.empty()); require(!this->rc_contexts.empty());
@ -751,7 +750,7 @@ readline_curses::start()
current_context = this->rc_contexts.end(); 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) { while (looping) {
fd_set ready_rfds; fd_set ready_rfds;
@ -928,8 +927,9 @@ readline_curses::start()
{ {
require(this->rc_contexts[context] != nullptr); require(this->rc_contexts[context] != nullptr);
this->rc_contexts[context]->rc_prefixes[string(type)] this->rc_contexts[context]
= string(&msg[prompt_start]); ->rc_prefixes[std::string(type)]
= std::string(&msg[prompt_start]);
} else if (sscanf(msg, } else if (sscanf(msg,
"ap:%d:%31[^:]:%n", "ap:%d:%31[^:]:%n",
&context, &context,
@ -939,7 +939,7 @@ readline_curses::start()
require(this->rc_contexts[context] != nullptr); require(this->rc_contexts[context] != nullptr);
this->rc_contexts[context]->add_possibility( 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 if (rl_last_func == rl_complete
|| rl_last_func == rl_menu_complete) { || rl_last_func == rl_menu_complete) {
rl_last_func = NULL; rl_last_func = NULL;
@ -953,7 +953,7 @@ readline_curses::start()
require(this->rc_contexts[context] != nullptr); require(this->rc_contexts[context] != nullptr);
this->rc_contexts[context]->rem_possibility( 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) { } else if (sscanf(msg, "cpre:%d", &context) == 1) {
this->rc_contexts[context]->rc_prefixes.clear(); this->rc_contexts[context]->rc_prefixes.clear();
} else if (sscanf(msg, "cp:%d:%s", &context, type)) { } else if (sscanf(msg, "cp:%d:%s", &context, type)) {
@ -1083,7 +1083,7 @@ readline_curses::line_ready(const char* line)
} }
void void
readline_curses::check_poll_set(const vector<struct pollfd>& pollfds) readline_curses::check_poll_set(const std::vector<struct pollfd>& pollfds)
{ {
int rc; int rc;
@ -1106,7 +1106,7 @@ readline_curses::check_poll_set(const vector<struct pollfd>& pollfds)
rc = recvstring( rc = recvstring(
this->rc_command_pipe[RCF_MASTER], msg, sizeof(msg) - 1); this->rc_command_pipe[RCF_MASTER], msg, sizeof(msg) - 1);
if (rc >= 0) { if (rc >= 0) {
string old_value = this->rc_value; std::string old_value = this->rc_value;
msg[rc] = '\0'; msg[rc] = '\0';
if (this->rc_matches_remaining > 0) { if (this->rc_matches_remaining > 0) {
@ -1148,7 +1148,7 @@ readline_curses::check_poll_set(const vector<struct pollfd>& pollfds)
case 't': case 't':
case 'd': case 'd':
case 'D': case 'D':
this->rc_value = string(&msg[2]); this->rc_value = std::string(&msg[2]);
break; break;
} }
switch (msg[0]) { switch (msg[0]) {
@ -1273,8 +1273,8 @@ readline_curses::abort()
void void
readline_curses::add_prefix(int context, readline_curses::add_prefix(int context,
const vector<string>& prefix, const std::vector<std::string>& prefix,
const string& value) const std::string& value)
{ {
char buffer[1024]; char buffer[1024];
auto prefix_wire = fmt::format(FMT_STRING("{}"), fmt::join(prefix, "\x1f")); auto prefix_wire = fmt::format(FMT_STRING("{}"), fmt::join(prefix, "\x1f"));
@ -1309,8 +1309,8 @@ readline_curses::clear_prefixes(int context)
void void
readline_curses::add_possibility(int context, readline_curses::add_possibility(int context,
const string& type, const std::string& type,
const string& value) const std::string& value)
{ {
char buffer[1024]; char buffer[1024];
@ -1334,8 +1334,8 @@ readline_curses::add_possibility(int context,
void void
readline_curses::rem_possibility(int context, readline_curses::rem_possibility(int context,
const string& type, const std::string& type,
const string& value) const std::string& value)
{ {
char buffer[1024]; char buffer[1024];
@ -1354,7 +1354,7 @@ readline_curses::rem_possibility(int context,
} }
void void
readline_curses::clear_possibilities(int context, string type) readline_curses::clear_possibilities(int context, std::string type)
{ {
char buffer[1024]; char buffer[1024];
@ -1432,9 +1432,9 @@ readline_curses::do_update()
std::string std::string
readline_curses::get_match_string() const 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; - this->rc_match_start;
auto context = this->get_active_context(); auto* context = this->get_active_context();
if (context->get_append_character() != 0) { if (context->get_append_character() != 0) {
if (this->rc_line_buffer.length() > (this->rc_match_start + len - 1) if (this->rc_line_buffer.length() > (this->rc_match_start + len - 1)

View File

@ -52,7 +52,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "base/func_util.hh" #include "base/func_util.hh"
#include "base/result.h" #include "base/result.h"
#include "help_text_formatter.hh" #include "help_text_formatter.hh"

View File

@ -38,12 +38,10 @@
#include "sql_help.hh" #include "sql_help.hh"
#include "sql_util.hh" #include "sql_util.hh"
using namespace std;
static void readline_sqlite_highlighter_int(attr_line_t& al, int x, int skip); static void readline_sqlite_highlighter_int(attr_line_t& al, int x, int skip);
static bool static bool
check_re_prev(const string& line, int x) check_re_prev(const std::string& line, int x)
{ {
bool retval = false; bool retval = false;
@ -58,7 +56,7 @@ check_re_prev(const string& line, int x)
} }
static bool 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] == '\\') { if (is_lit && str[index - 1] == '\\') {
return true; return true;
@ -78,7 +76,7 @@ find_matching_bracket(attr_line_t& al, int x, char left, char right)
int missing_bracket_attrs int missing_bracket_attrs
= A_BOLD | A_REVERSE | vc.attrs_for_role(view_colors::VCR_ERROR); = A_BOLD | A_REVERSE | vc.attrs_for_role(view_colors::VCR_ERROR);
bool is_lit = (left == 'Q'); bool is_lit = (left == 'Q');
const string& line = al.get_string(); const std::string& line = al.get_string();
int depth = 0; int depth = 0;
if (x < 0 || x > (int) line.length()) { 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 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()) { if (index < str.length()) {
return str.at(index); return str.at(index);
@ -178,7 +176,7 @@ readline_regex_highlighter_int(attr_line_t& al, int x, int skip)
nullptr}; nullptr};
string& line = al.get_string(); auto& line = al.get_string();
bool backslash_is_quoted = false; bool backslash_is_quoted = false;
for (size_t lpc = skip; lpc < line.length(); lpc++) { 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(); view_colors& vc = view_colors::singleton();
int keyword_attrs = (A_BOLD | vc.attrs_for_role(view_colors::VCR_KEYWORD)); 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_context_static<30> pc;
pcre_input pi(line); pcre_input pi(line);
size_t ws_index; size_t ws_index;
ws_index = line.find(' '); ws_index = line.find(' ');
string command = line.substr(0, ws_index); auto command = line.substr(0, ws_index);
if (ws_index != string::npos) { if (ws_index != std::string::npos) {
al.get_attrs().emplace_back( al.get_attrs().emplace_back(
line_range(1, ws_index), &view_curses::VC_STYLE, keyword_attrs); 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); pi.reset(line);
if (COLOR_RE.match(pc, pi)) { if (COLOR_RE.match(pc, pi)) {
pcre_context::capture_t* cap = pc[0]; 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) styling::color_unit::from_str(hash_color)
.then([&](const auto& rgb_fg) { .then([&](const auto& rgb_fg) {
@ -384,7 +382,7 @@ readline_command_highlighter(attr_line_t& al, int x)
} }
} }
pi.reset(line); 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; size_t start = ws_index, last;
do { 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)) { 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" if ((command == ":tag" || command == ":untag"
|| command == ":delete-tags") || command == ":delete-tags")
@ -418,7 +416,7 @@ readline_command_highlighter(attr_line_t& al, int x)
static void static void
readline_sqlite_highlighter_int(attr_line_t& al, int x, int skip) 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 keyword_pcre(keyword_re_str.c_str(), PCRE_CASELESS);
static pcrepp string_literal_pcre("'[^']*('(?:'[^']*')*|$)"); static pcrepp string_literal_pcre("'[^']*('(?:'[^']*')*|$)");
static pcrepp ident_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 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 error_attrs = vc.attrs_for_role(view_colors::VCR_ERROR) | A_REVERSE;
int string_attrs = vc.attrs_for_role(view_colors::VCR_STRING); 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; pcre_context::capture_t cap;
shlex_token_t token; shlex_token_t token;
int quote_start = -1; 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_VARIABLE_REF:
case shlex_token_t::ST_QUOTED_VARIABLE_REF: { case shlex_token_t::ST_QUOTED_VARIABLE_REF: {
int extra = token == shlex_token_t::ST_VARIABLE_REF ? 0 : 1; int extra = token == shlex_token_t::ST_VARIABLE_REF ? 0 : 1;
string ident = str.substr(cap.c_begin + 1 + extra, auto ident = str.substr(cap.c_begin + 1 + extra,
cap.length() - 1 - extra * 2); cap.length() - 1 - extra * 2);
int attrs = vc.attrs_for_ident(ident); int attrs = vc.attrs_for_ident(ident);
al.with_attr(string_attr( al.with_attr(string_attr(

View File

@ -47,8 +47,6 @@
#include "tailer/tailer.looper.hh" #include "tailer/tailer.looper.hh"
#include "yajlpp/yajlpp_def.hh" #include "yajlpp/yajlpp_def.hh"
using namespace std;
static int static int
handle_collation_list(void* ptr, int ncols, char** colvalues, char** colnames) 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) handle_table_list(void* ptr, int ncols, char** colvalues, char** colnames)
{ {
if (lnav_data.ld_rl_view != nullptr) { 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) { if (sqlite_function_help.count(table_name) == 0) {
lnav_data.ld_rl_view->add_possibility(LNM_SQL, "*", colvalues[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]); quoted_name = sql_quote_ident(colvalues[1]);
lnav_data.ld_rl_view->add_possibility( lnav_data.ld_rl_view->add_possibility(
LNM_SQL, "*", string(quoted_name)); LNM_SQL, "*", std::string(quoted_name));
} }
if (strcmp(colvalues[5], "1") == 0) { if (strcmp(colvalues[5], "1") == 0) {
lnav_data.ld_db_key_names.emplace_back(colvalues[1]); lnav_data.ld_db_key_names.emplace_back(colvalues[1]);
@ -120,7 +118,7 @@ struct sqlite_metadata_callbacks lnav_sql_meta_callbacks = {
static void static void
add_text_possibilities(readline_curses* rlc, add_text_possibilities(readline_curses* rlc,
int context, int context,
const string& type, const std::string& type,
const std::string& str) const std::string& str)
{ {
static const std::regex re_escape(R"(([.\^$*+?()\[\]{}\\|]))"); static const std::regex re_escape(R"(([.\^$*+?()\[\]{}\\|]))");
@ -146,7 +144,7 @@ add_text_possibilities(readline_curses* rlc,
switch (context) { switch (context) {
case LNM_SQL: { 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<char, sqlite3_free> quoted_token; auto_mem<char, sqlite3_free> quoted_token;
quoted_token = sqlite3_mprintf("%Q", token_value.c_str()); quoted_token = sqlite3_mprintf("%Q", token_value.c_str());
@ -154,7 +152,7 @@ add_text_possibilities(readline_curses* rlc,
break; break;
} }
default: { default: {
string token_value, token_value_no_dot; std::string token_value, token_value_no_dot;
token_value_no_dot = token_value token_value_no_dot = token_value
= ds.get_input().get_substr(pc.all()); = ds.get_input().get_substr(pc.all());
@ -184,7 +182,7 @@ add_text_possibilities(readline_curses* rlc,
void void
add_view_text_possibilities(readline_curses* rlc, add_view_text_possibilities(readline_curses* rlc,
int context, int context,
const string& type, const std::string& type,
textview_curses* tc) textview_curses* tc)
{ {
text_sub_source* tss = tc->get_sub_source(); 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(); for (vis_line_t curr_line = tc->get_top(); curr_line <= tc->get_bottom();
++curr_line) ++curr_line)
{ {
string line; std::string line;
tss->text_value_for_line(*tc, curr_line, line, text_sub_source::RF_RAW); 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(); auto format = lf->get_format();
shared_buffer_ref sbr; shared_buffer_ref sbr;
string_attrs_t sa; string_attrs_t sa;
vector<logline_value> values; std::vector<logline_value> values;
lf->read_full_message(ll, sbr); lf->read_full_message(ll, sbr);
format->annotate(cl, sbr, sa, values); format->annotate(cl, sbr, sa, values);
@ -269,7 +267,7 @@ add_filter_expr_possibilities(readline_curses* rlc,
str = sqlite3_mprintf( str = sqlite3_mprintf(
"%.*Q", lv.text_length(), lv.text_value()); "%.*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; break;
} }
} }
@ -289,7 +287,7 @@ add_filter_expr_possibilities(readline_curses* rlc,
rlc->add_possibility( rlc->add_possibility(
context, context,
type, 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++) { for (int lpc2 = 0; agg_funcs && agg_funcs[lpc2].zName; lpc2++) {
const FuncDefAgg& func_def = agg_funcs[lpc2]; const FuncDefAgg& func_def = agg_funcs[lpc2];
@ -297,7 +295,7 @@ add_filter_expr_possibilities(readline_curses* rlc,
rlc->add_possibility( rlc->add_possibility(
context, context,
type, 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++) { for (char** var = environ; *var != nullptr; var++) {
rlc->add_possibility( rlc->add_possibility(
context, "*", "$" + string(*var, strchr(*var, '='))); context, "*", "$" + std::string(*var, strchr(*var, '=')));
} }
exec_context& ec = lnav_data.ld_exec_context; exec_context& ec = lnav_data.ld_exec_context;
@ -400,9 +398,9 @@ void
add_config_possibilities() add_config_possibilities()
{ {
readline_curses* rc = lnav_data.ld_rl_view; readline_curses* rc = lnav_data.ld_rl_view;
set<string> visited; std::set<std::string> visited;
auto cb = [rc, &visited](const json_path_handler_base& jph, auto cb = [rc, &visited](const json_path_handler_base& jph,
const string& path, const std::string& path,
void* mem) { void* mem) {
if (jph.jph_children) { if (jph.jph_children) {
if (!jph.jph_regex.p_named_count) { if (!jph.jph_regex.p_named_count) {
@ -423,14 +421,14 @@ add_config_possibilities()
rc->add_possibility(LNM_COMMAND, "config-option", path); rc->add_possibility(LNM_COMMAND, "config-option", path);
if (jph.jph_synopsis) { if (jph.jph_synopsis) {
rc->add_prefix(LNM_COMMAND, rc->add_prefix(LNM_COMMAND,
vector<string>{"config", path}, std::vector<std::string>{"config", path},
jph.jph_synopsis); jph.jph_synopsis);
} }
} }
}; };
rc->clear_possibilities(LNM_COMMAND, "config-option"); 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); jph.walk(cb, &lnav_config);
} }
} }
@ -449,8 +447,7 @@ add_tag_possibilities()
logfile_sub_source& lss = lnav_data.ld_log_source; logfile_sub_source& lss = lnav_data.ld_log_source;
if (lss.text_line_count() > 0) { if (lss.text_line_count() > 0) {
content_line_t cl = lss.at(lnav_data.ld_views[LNV_LOG].get_top()); content_line_t cl = lss.at(lnav_data.ld_views[LNV_LOG].get_top());
const map<content_line_t, bookmark_metadata>& user_meta const auto& user_meta = lss.get_user_bookmark_metadata();
= lss.get_user_bookmark_metadata();
auto meta_iter = user_meta.find(cl); auto meta_iter = user_meta.find(cl);
if (meta_iter != user_meta.end()) { if (meta_iter != user_meta.end()) {

View File

@ -34,8 +34,6 @@
#include "sql_util.hh" #include "sql_util.hh"
#include "vtab_module.hh" #include "vtab_module.hh"
using namespace std;
enum { enum {
RC_COL_MATCH_INDEX, RC_COL_MATCH_INDEX,
RC_COL_INDEX, RC_COL_INDEX,
@ -70,8 +68,8 @@ CREATE TABLE regexp_capture (
sqlite3_vtab_cursor base; sqlite3_vtab_cursor base;
pcrepp c_pattern; pcrepp c_pattern;
pcre_context_static<30> c_context; pcre_context_static<30> c_context;
unique_ptr<pcre_input> c_input; std::unique_ptr<pcre_input> c_input;
string c_content; std::string c_content;
bool c_content_as_blob{false}; bool c_content_as_blob{false};
int c_index; int c_index;
int c_start_index; int c_start_index;
@ -247,7 +245,7 @@ rcFilter(sqlite3_vtab_cursor* pVtabCursor,
pCur->c_index = 0; pCur->c_index = 0;
pCur->c_context.set_count(0); pCur->c_context.set_count(0);
pCur->c_input = make_unique<pcre_input>(pCur->c_content); pCur->c_input = std::make_unique<pcre_input>(pCur->c_content);
pCur->c_matched = pCur->c_pattern.match(pCur->c_context, *(pCur->c_input)); pCur->c_matched = pCur->c_pattern.match(pCur->c_context, *(pCur->c_input));
log_debug("matched %d", pCur->c_matched); log_debug("matched %d", pCur->c_matched);
@ -272,10 +270,11 @@ register_regexp_vtab(sqlite3* db)
.with_parameter( .with_parameter(
{"string", "The string to match against the given pattern."}) {"string", "The string to match against the given pattern."})
.with_parameter({"pattern", "The regular expression to match."}) .with_parameter({"pattern", "The regular expression to match."})
.with_result( .with_result({
{"match_index", "match_index",
"The match iteration. This value will increase " "The match iteration. This value will increase "
"each time a new match is found in the input string."}) "each time a new match is found in the input string.",
})
.with_result( .with_result(
{"capture_index", "The index of the capture in the regex."}) {"capture_index", "The index of the capture in the regex."})
.with_result( .with_result(
@ -288,10 +287,12 @@ register_regexp_vtab(sqlite3* db)
"The stop of the capture in the input string."}) "The stop of the capture in the input string."})
.with_result({"content", "The captured value from the string."}) .with_result({"content", "The captured value from the string."})
.with_tags({"string"}) .with_tags({"string"})
.with_example({"To extract the key/value pairs 'a'/1 and 'b'/2 " .with_example({
"from the string 'a=1; b=2'", "To extract the key/value pairs 'a'/1 and 'b'/2 "
"SELECT * FROM regexp_capture('a=1; b=2', " "from the string 'a=1; b=2'",
"'(\\w+)=(\\d+)')"}); "SELECT * FROM regexp_capture('a=1; b=2', "
"'(\\w+)=(\\d+)')",
});
int rc; int rc;
@ -300,7 +301,7 @@ register_regexp_vtab(sqlite3* db)
rc = REGEXP_CAPTURE_MODULE.create(db, "regexp_capture"); rc = REGEXP_CAPTURE_MODULE.create(db, "regexp_capture");
sqlite_function_help.insert( sqlite_function_help.insert(
make_pair("regexp_capture", &regexp_capture_help)); std::make_pair("regexp_capture", &regexp_capture_help));
regexp_capture_help.index_tags(); regexp_capture_help.index_tags();
ensure(rc == SQLITE_OK); ensure(rc == SQLITE_OK);

View File

@ -35,7 +35,6 @@
#include "config.h" #include "config.h"
#include "pcrepp/pcrepp.hh" #include "pcrepp/pcrepp.hh"
using namespace std;
using namespace std::chrono_literals; using namespace std::chrono_literals;
static const struct { static const struct {
@ -333,15 +332,15 @@ relative_time::from_str(const char* str, size_t len)
case RTT_AT: case RTT_AT:
break; break;
case RTT_TIME: { case RTT_TIME: {
string hstr = pi.get_substr(pc[0]); const auto hstr = pi.get_substr(pc[0]);
string mstr = pi.get_substr(pc[1]); const auto mstr = pi.get_substr(pc[1]);
retval.rt_field[RTF_HOURS] = atoi(hstr.c_str()); retval.rt_field[RTF_HOURS] = atoi(hstr.c_str());
retval.rt_field[RTF_MINUTES] = atoi(mstr.c_str()); retval.rt_field[RTF_MINUTES] = atoi(mstr.c_str());
if (pc[2]->is_valid()) { 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()); retval.rt_field[RTF_SECONDS] = atoi(sstr.c_str());
if (pc[3]->is_valid()) { if (pc[3]->is_valid()) {
string substr = pi.get_substr(pc[3]); const auto substr = pi.get_substr(pc[3]);
switch (substr.length()) { switch (substr.length()) {
case 3: case 3:
@ -372,7 +371,7 @@ relative_time::from_str(const char* str, size_t len)
return Err(pe_out); 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) { if (sscanf(numstr.c_str(), "%" PRId64, &number) != 1) {
pe_out.pe_msg = "Invalid number: " + numstr; pe_out.pe_msg = "Invalid number: " + numstr;

View File

@ -32,8 +32,6 @@
#include "config.h" #include "config.h"
#include "spookyhash/SpookyV2.h" #include "spookyhash/SpookyV2.h"
using namespace std;
sequence_matcher::sequence_matcher(field_col_t& example) sequence_matcher::sequence_matcher(field_col_t& example)
{ {
for (field_col_t::iterator col_iter = example.begin(); for (field_col_t::iterator col_iter = example.begin();
@ -63,7 +61,7 @@ sequence_matcher::sequence_matcher(field_col_t& example)
} }
void void
sequence_matcher::identity(const std::vector<string>& values, id_t& id_out) sequence_matcher::identity(const std::vector<std::string>& values, id_t& id_out)
{ {
SpookyHash context; SpookyHash context;
int lpc = 0; int lpc = 0;

View File

@ -56,8 +56,6 @@
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
#include "yajlpp/yajlpp_def.hh" #include "yajlpp/yajlpp_def.hh"
using namespace std;
struct session_data_t session_data; struct session_data_t session_data;
static const char* LOG_METADATA_NAME = "log_metadata.db"; 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 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( return sqlite3_bind_text(
stmt, index, str.c_str(), str.size(), SQLITE_TRANSIENT); stmt, index, str.c_str(), str.size(), SQLITE_TRANSIENT);
@ -189,9 +187,7 @@ bind_line(sqlite3* db,
time_t session_time) time_t session_time)
{ {
logfile_sub_source& lss = lnav_data.ld_log_source; logfile_sub_source& lss = lnav_data.ld_log_source;
shared_ptr<logfile> lf; auto lf = lss.find(cl);
lf = lss.find(cl);
if (lf == nullptr) { if (lf == nullptr) {
return false; return false;
@ -224,7 +220,7 @@ bind_line(sqlite3* db,
} }
struct session_file_info { 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_timestamp(timestamp), sfi_id(std::move(id)),
sfi_path(std::move(path)){}; sfi_path(std::move(path)){};
@ -240,8 +236,8 @@ struct session_file_info {
}; };
int sfi_timestamp; int sfi_timestamp;
string sfi_id; std::string sfi_id;
string sfi_path; std::string sfi_path;
}; };
static void static void
@ -249,7 +245,7 @@ cleanup_session_data()
{ {
static_root_mem<glob_t, globfree> session_file_list; static_root_mem<glob_t, globfree> session_file_list;
std::list<struct session_file_info> session_info_list; std::list<struct session_file_info> session_info_list;
map<string, int> session_count; std::map<std::string, int> session_count;
auto session_file_pattern = lnav::paths::dotlnav() / "*-*.ts*.json"; auto session_file_pattern = lnav::paths::dotlnav() / "*-*.ts*.json";
if (glob( if (glob(
@ -492,7 +488,7 @@ load_time_bookmarks()
file_iter != lnav_data.ld_log_source.end(); file_iter != lnav_data.ld_log_source.end();
++file_iter) ++file_iter)
{ {
shared_ptr<logfile> lf = (*file_iter)->get_file(); auto lf = (*file_iter)->get_file();
content_line_t base_content_line; content_line_t base_content_line;
if (lf == nullptr) { if (lf == nullptr) {
@ -518,7 +514,7 @@ load_time_bookmarks()
date_time_scanner dts; date_time_scanner dts;
bool done = false; bool done = false;
string line; std::string line;
int64_t last_mark_time = -1; int64_t last_mark_time = -1;
while (!done) { while (!done) {
@ -582,7 +578,7 @@ load_time_bookmarks()
auto sbr = read_result.unwrap(); auto sbr = read_result.unwrap();
string line_hash auto line_hash
= hasher() = hasher()
.update(sbr.get_data(), sbr.length()) .update(sbr.get_data(), sbr.length())
.update(cl) .update(cl)
@ -681,7 +677,7 @@ load_time_bookmarks()
file_iter != lnav_data.ld_log_source.end(); file_iter != lnav_data.ld_log_source.end();
++file_iter) ++file_iter)
{ {
shared_ptr<logfile> lf = (*file_iter)->get_file(); auto lf = (*file_iter)->get_file();
content_line_t base_content_line; content_line_t base_content_line;
if (lf == nullptr) { if (lf == nullptr) {
@ -707,7 +703,7 @@ load_time_bookmarks()
date_time_scanner dts; date_time_scanner dts;
bool done = false; bool done = false;
string line; std::string line;
int64_t last_mark_time = -1; int64_t last_mark_time = -1;
while (!done) { while (!done) {
@ -807,7 +803,7 @@ read_current_search(yajlpp_parse_context* ypc,
const unsigned char* str, const unsigned char* str,
size_t len) size_t len)
{ {
string regex = std::string((const char*) str, len); const auto regex = std::string((const char*) str, len);
const char** view_name; const char** view_name;
int view_index; int view_index;
@ -1067,7 +1063,7 @@ save_user_bookmarks(sqlite3* db,
return; return;
} }
string tags; std::string tags;
if (!line_meta.bm_tags.empty()) { if (!line_meta.bm_tags.empty()) {
yajlpp_gen gen; yajlpp_gen gen;
@ -1226,7 +1222,7 @@ save_time_bookmarks()
file_iter != lnav_data.ld_log_source.end(); file_iter != lnav_data.ld_log_source.end();
++file_iter) ++file_iter)
{ {
shared_ptr<logfile> lf = (*file_iter)->get_file(); auto lf = (*file_iter)->get_file();
if (lf == nullptr) { if (lf == nullptr) {
continue; continue;
@ -1320,7 +1316,7 @@ save_time_bookmarks()
file_iter != lnav_data.ld_log_source.end(); file_iter != lnav_data.ld_log_source.end();
++file_iter) ++file_iter)
{ {
shared_ptr<logfile> lf = (*file_iter)->get_file(); auto lf = (*file_iter)->get_file();
content_line_t base_content_line; content_line_t base_content_line;
if (lf == nullptr) { if (lf == nullptr) {
@ -1366,7 +1362,7 @@ save_time_bookmarks()
if (ls->get_file() == nullptr) if (ls->get_file() == nullptr)
continue; continue;
shared_ptr<logfile> lf = ls->get_file(); auto lf = ls->get_file();
if (!lf->is_time_adjusted()) { if (!lf->is_time_adjusted()) {
continue; continue;
@ -1528,7 +1524,7 @@ save_session_with_id(const std::string& session_id)
yajlpp_array cmd_array(handle); yajlpp_array cmd_array(handle);
for (const auto& filter : fs) { for (const auto& filter : fs) {
string cmd = filter->to_command(); auto cmd = filter->to_command();
if (cmd.empty()) { if (cmd.empty()) {
continue; continue;
@ -1582,13 +1578,13 @@ save_session_with_id(const std::string& session_id)
min_time_str, sizeof(min_time_str), min_time); min_time_str, sizeof(min_time_str), min_time);
if (have_min_time) { if (have_min_time) {
cmd_array.gen("hide-lines-before " cmd_array.gen("hide-lines-before "
+ string(min_time_str)); + std::string(min_time_str));
} }
if (have_max_time) { if (have_max_time) {
sql_strftime( sql_strftime(
max_time_str, sizeof(max_time_str), max_time); max_time_str, sizeof(max_time_str), max_time);
cmd_array.gen("hide-lines-after " cmd_array.gen("hide-lines-after "
+ string(max_time_str)); + std::string(max_time_str));
} }
auto mark_expr = lss.get_sql_marker_text(); auto mark_expr = lss.get_sql_marker_text();

View File

@ -51,8 +51,6 @@
#include "sql_help.hh" #include "sql_help.hh"
#include "sqlite-extension-func.hh" #include "sqlite-extension-func.hh"
using namespace std;
/** /**
* Copied from -- http://www.sqlite.org/lang_keywords.html * Copied from -- http://www.sqlite.org/lang_keywords.html
*/ */
@ -259,7 +257,7 @@ const char* sql_function_names[] = {
nullptr}; nullptr};
multimap<std::string, help_text*> sqlite_function_help; std::multimap<std::string, help_text*> sqlite_function_help;
static int static int
handle_db_list(void* ptr, int ncols, char** colvalues, char** colnames) 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) schema_db_list(void* ptr, int ncols, char** colvalues, char** colnames)
{ {
struct sqlite_metadata_callbacks* smc = (sqlite_metadata_callbacks*) ptr; 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<char, sqlite3_free> attach_sql; auto_mem<char, sqlite3_free> attach_sql;
attach_sql = sqlite3_mprintf( attach_sql = sqlite3_mprintf(
@ -409,7 +407,7 @@ static int
schema_table_list(void* ptr, int ncols, char** colvalues, char** colnames) schema_table_list(void* ptr, int ncols, char** colvalues, char** colnames)
{ {
struct sqlite_metadata_callbacks* smc = (sqlite_metadata_callbacks*) ptr; 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<char, sqlite3_free> create_sql; auto_mem<char, sqlite3_free> create_sql;
create_sql = sqlite3_mprintf("%s;\n", colvalues[1]); 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("/\\"); 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; db_name = filename;
} else { } else {
db_name = filename.substr(base_start + 1); db_name = filename.substr(base_start + 1);
@ -634,10 +632,10 @@ sql_quote_ident(const char* ident)
return retval; return retval;
} }
string std::string
sql_safe_ident(const string_fragment& ident) 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++) { for (size_t lpc = 0; lpc < retval.size(); lpc++) {
char ch = retval[lpc]; char ch = retval[lpc];
@ -710,7 +708,7 @@ sql_execute_script(sqlite3* db,
const std::vector<sqlite3_stmt*>& stmts, const std::vector<sqlite3_stmt*>& stmts,
std::vector<std::string>& errors) std::vector<std::string>& errors)
{ {
map<string, string> lvars; std::map<std::string, std::string> lvars;
for (sqlite3_stmt* stmt : stmts) { for (sqlite3_stmt* stmt : stmts) {
bool done = false; bool done = false;
@ -724,7 +722,7 @@ sql_execute_script(sqlite3* db,
name = sqlite3_bind_parameter_name(stmt, lpc + 1); name = sqlite3_bind_parameter_name(stmt, lpc + 1);
if (name[0] == '$') { if (name[0] == '$') {
map<string, string>::iterator iter; std::map<std::string, std::string>::iterator iter;
const char* env_value; const char* env_value;
if ((iter = lvars.find(&name[1])) != lvars.end()) { if ((iter = lvars.find(&name[1])) != lvars.end()) {
@ -784,7 +782,7 @@ sql_execute_script(sqlite3* db,
const char* script, const char* script,
std::vector<std::string>& errors) std::vector<std::string>& errors)
{ {
vector<sqlite3_stmt*> stmts; std::vector<sqlite3_stmt*> stmts;
sql_compile_script(db, src_name, script, stmts, errors); sql_compile_script(db, src_name, script, stmts, errors);
if (errors.empty()) { if (errors.empty()) {
@ -808,11 +806,11 @@ static struct {
}; };
int int
guess_type_from_pcre(const string& pattern, std::string& collator) guess_type_from_pcre(const std::string& pattern, std::string& collator)
{ {
try { try {
pcrepp re(pattern); pcrepp re(pattern);
vector<int> matches; std::vector<int> matches;
int retval = SQLITE3_TEXT; int retval = SQLITE3_TEXT;
int index = 0; int index = 0;
@ -862,10 +860,10 @@ sqlite_authorizer(void* pUserData,
return SQLITE_OK; return SQLITE_OK;
} }
string std::string
sql_keyword_re() sql_keyword_re()
{ {
string retval = "(?:"; std::string retval = "(?:";
bool first = true; bool first = true;
for (const char* kw : sql_keywords) { for (const char* kw : sql_keywords) {
@ -896,7 +894,7 @@ string_attr_type SQL_GARBAGE_ATTR("sql_garbage");
void void
annotate_sql_statement(attr_line_t& al) 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 { static struct {
pcrepp re; pcrepp re;
@ -986,12 +984,12 @@ annotate_sql_statement(attr_line_t& al)
stable_sort(sa.begin(), sa.end()); stable_sort(sa.begin(), sa.end());
} }
vector<const help_text*> std::vector<const help_text*>
find_sql_help_for_line(const attr_line_t& al, size_t x) find_sql_help_for_line(const attr_line_t& al, size_t x)
{ {
vector<const help_text*> retval; std::vector<const help_text*> retval;
const auto& sa = al.get_attrs(); const auto& sa = al.get_attrs();
string name; std::string name;
x = al.nearest_text(x); 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); auto sa_opt = get_string_attr(al.get_attrs(), &SQL_COMMAND_ATTR);
if (sa_opt) { if (sa_opt) {
auto sql_cmd_map = injector::get<readline_context::command_map_t*, auto* sql_cmd_map = injector::get<readline_context::command_map_t*,
sql_cmd_map_tag>(); sql_cmd_map_tag>();
auto cmd_name = al.get_substring((*sa_opt)->sa_range); auto cmd_name = al.get_substring((*sa_opt)->sa_range);
auto cmd_iter = sql_cmd_map->find(cmd_name); 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<string> kw; std::vector<std::string> kw;
auto iter = rfind_string_attr_if(sa, x, [&al, &name, &kw, x](auto sa) { 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) if (sa.sa_type != &SQL_FUNCTION_ATTR && sa.sa_type != &SQL_KEYWORD_ATTR)
{ {
return false; return false;
} }
const string& str = al.get_string(); const std::string& str = al.get_string();
const line_range& lr = sa.sa_range; const line_range& lr = sa.sa_range;
int lpc; 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) { if (sa.sa_type == &SQL_KEYWORD_ATTR) {
tmp_name = toupper(tmp_name); 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()) { if (iter != sa.end()) {
auto func_pair = sqlite_function_help.equal_range(name); 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) { if (help_count > 1 && name != func_pair.first->second->ht_name) {
while (func_pair.first != func_pair.second) { while (func_pair.first != func_pair.second) {

View File

@ -37,8 +37,6 @@
#include "config.h" #include "config.h"
#include "sql_help.hh" #include "sql_help.hh"
using namespace std;
extern "C" { extern "C" {
struct sqlite3_api_routines; 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) { if (fd.fd_help.ht_context != help_context_t::HC_NONE) {
help_text& ht = fd.fd_help; 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(); 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) { if (fda.fda_help.ht_context != help_context_t::HC_NONE) {
help_text& ht = fda.fda_help; 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(); ht.index_tags();
} }
} }
@ -696,9 +694,11 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
.sql_function() .sql_function()
.with_parameter({"X", "The values to add."}) .with_parameter({"X", "The values to add."})
.with_tags({"math"}) .with_tags({"math"})
.with_example({"To sum all of the values in the column " .with_example({
"'ex_duration' from the table 'lnav_example_log'", "To sum all of the values in the column "
"SELECT sum(ex_duration) FROM lnav_example_log"}), "'ex_duration' from the table 'lnav_example_log'",
"SELECT sum(ex_duration) FROM lnav_example_log",
}),
help_text( help_text(
"total", "total",
@ -706,9 +706,11 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
.sql_function() .sql_function()
.with_parameter({"X", "The values to add."}) .with_parameter({"X", "The values to add."})
.with_tags({"math"}) .with_tags({"math"})
.with_example({"To total all of the values in the column " .with_example({
"'ex_duration' from the table 'lnav_example_log'", "To total all of the values in the column "
"SELECT total(ex_duration) FROM lnav_example_log"}), "'ex_duration' from the table 'lnav_example_log'",
"SELECT total(ex_duration) FROM lnav_example_log",
}),
help_text("generate_series", help_text("generate_series",
"A table-valued-function that returns the whole numbers " "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") help_text("step", "The increment between each value")
.optional()) .optional())
.with_result({"value", "The number in the series"}) .with_result({"value", "The number in the series"})
.with_example({"To generate the numbers in the range [10, 14]", .with_example({
"SELECT value FROM generate_series(10, 14)"}) "To generate the numbers in the range [10, 14]",
.with_example( "SELECT value FROM generate_series(10, 14)",
{"To generate every other number in the range [10, 14]", })
"SELECT value FROM generate_series(10, 14, 2)"}) .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", .with_example({"To count down from five to 1",
"SELECT value FROM generate_series(1, 5, -1)"})}; "SELECT value FROM generate_series(1, 5, -1)"})};
for (auto& ht : builtin_funcs) { 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(); ht.index_tags();
} }
@ -830,7 +835,7 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
}; };
for (auto& ht : builtin_win_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(); ht.index_tags();
} }
@ -995,9 +1000,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
"a row should be updated.") "a row should be updated.")
.with_flag_name("WHERE") .with_flag_name("WHERE")
.optional()) .optional())
.with_example( .with_example({
{"To mark the syslog message at line 40", "To mark the syslog message at line 40",
"UPDATE syslog_log SET log_mark = 1 WHERE log_line = 40"}), "UPDATE syslog_log SET log_mark = 1 WHERE log_line = 40",
}),
help_text("CASE", help_text("CASE",
"Evaluate a series of expressions in order until one " "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") .with_flag_name("ELSE")
.optional()) .optional())
.with_parameter(help_text("").with_flag_name("END")) .with_parameter(help_text("").with_flag_name("END"))
.with_example( .with_example({
{"To evaluate the number one and return the string 'one'", "To evaluate the number one and return the string 'one'",
"SELECT CASE 1 WHEN 0 THEN 'zero' WHEN 1 THEN 'one' END"}), "SELECT CASE 1 WHEN 0 THEN 'zero' WHEN 1 THEN 'one' END",
}),
help_text("CAST", help_text("CAST",
"Convert the value of the given expression to a different " "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( .with_parameter(
help_text("type-name", "The name of the type to convert to.") help_text("type-name", "The name of the type to convert to.")
.with_flag_name("AS")) .with_flag_name("AS"))
.with_example({"To cast the value 1.23 as an integer", .with_example({
"SELECT CAST(1.23 AS INTEGER)"}), "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.") help_text("expr", "Match an expression against a glob pattern.")
.sql_infix() .sql_infix()
@ -1044,8 +1053,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
.with_parameter( .with_parameter(
help_text("pattern", "The glob pattern to match against.") help_text("pattern", "The glob pattern to match against.")
.with_flag_name("GLOB")) .with_flag_name("GLOB"))
.with_example({"To check if a value matches the pattern '*.log'", .with_example({
"SELECT 'foobar.log' GLOB '*.log'"}), "To check if a value matches the pattern '*.log'",
"SELECT 'foobar.log' GLOB '*.log'",
}),
help_text("expr", "Match an expression against a text pattern.") help_text("expr", "Match an expression against a text pattern.")
.sql_infix() .sql_infix()
@ -1053,9 +1064,10 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
.with_parameter( .with_parameter(
help_text("pattern", "The pattern to match against.") help_text("pattern", "The pattern to match against.")
.with_flag_name("LIKE")) .with_flag_name("LIKE"))
.with_example( .with_example({
{"To check if a value matches the pattern 'Hello, %!'", "To check if a value matches the pattern 'Hello, %!'",
"SELECT 'Hello, World!' LIKE 'Hello, %!'"}), "SELECT 'Hello, World!' LIKE 'Hello, %!'",
}),
help_text("expr", "Match an expression against a regular expression.") help_text("expr", "Match an expression against a regular expression.")
.sql_infix() .sql_infix()
@ -1063,19 +1075,21 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
.with_parameter( .with_parameter(
help_text("pattern", "The regular expression to match against.") help_text("pattern", "The regular expression to match against.")
.with_flag_name("REGEXP")) .with_flag_name("REGEXP"))
.with_example( .with_example({
{"To check if a value matches the pattern 'file-\\d+'", "To check if a value matches the pattern 'file-\\d+'",
"SELECT 'file-23' REGEXP 'file-\\d+'"}), "SELECT 'file-23' REGEXP 'file-\\d+'",
}),
help_text("expr", "Assign a collating sequence to the expression.") help_text("expr", "Assign a collating sequence to the expression.")
.sql_infix() .sql_infix()
.with_parameter( .with_parameter(
help_text("collation-name", "The name of the collator.") help_text("collation-name", "The name of the collator.")
.with_flag_name("COLLATE")) .with_flag_name("COLLATE"))
.with_example( .with_example({
{"To change the collation method for string comparisons", "To change the collation method for string comparisons",
"SELECT ('a2' < 'a10'), ('a2' < 'a10' COLLATE " "SELECT ('a2' < 'a10'), ('a2' < 'a10' COLLATE "
"naturalnocase)"}), "naturalnocase)",
}),
help_text("expr", "Test if an expression is between two values.") help_text("expr", "Test if an expression is between two values.")
.sql_infix() .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")) help_text("low", "The low point").with_flag_name("BETWEEN"))
.with_parameter( .with_parameter(
help_text("hi", "The high point").with_flag_name("AND")) help_text("hi", "The high point").with_flag_name("AND"))
.with_example({"To check if 3 is between 5 and 10", .with_example({
"SELECT 3 BETWEEN 5 AND 10"}) "To check if 3 is between 5 and 10",
.with_example({"To check if 10 is between 5 and 10", "SELECT 3 BETWEEN 5 AND 10",
"SELECT 10 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") help_text("OVER", "Executes the preceding function over a window")
.sql_keyword() .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") help_text("OVER", "Executes the preceding function over a window")
.sql_function() .sql_function()
.with_parameter(help_text{"base-window-name", .with_parameter(help_text{
"The name of the window definition"} "base-window-name",
"The name of the window definition",
}
.optional()) .optional())
.with_parameter( .with_parameter(
help_text{"expr", "The values to use for partitioning"} 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"} "expr", "The values used to order the rows in the window"}
.with_flag_name("ORDER BY") .with_flag_name("ORDER BY")
.zero_or_more()) .zero_or_more())
.with_parameter(help_text{"frame-spec", .with_parameter(help_text{
"Determines which output rows are read " "frame-spec",
"by an aggregate window function"} "Determines which output rows are read "
"by an aggregate window function",
}
.optional()), .optional()),
}; };

View File

@ -36,8 +36,6 @@
#include "config.h" #include "config.h"
using namespace std;
void void
status_field::set_value(std::string value) status_field::set_value(std::string value)
{ {
@ -157,7 +155,7 @@ statusview_curses::do_update()
} }
if (val.length() > sf.get_width()) { 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) { if (sf.get_width() > 11) {
size_t half_width = sf.get_width() / 2 - 1; size_t half_width = sf.get_width() / 2 - 1;
@ -196,7 +194,7 @@ statusview_curses::window_change()
int total_shares = 0; int total_shares = 0;
unsigned long width, height; unsigned long width, height;
double remaining = 0; double remaining = 0;
vector<status_field*> resizable; std::vector<status_field*> resizable;
getmaxyx(this->sc_window, height, width); getmaxyx(this->sc_window, height, width);
// Silence the compiler. Remove this if height is used at a later stage. // 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); sf->set_width(actual_width);
} }
this->sc_last_width = width;
} }

View File

@ -248,7 +248,6 @@ private:
status_data_source* sc_source{nullptr}; status_data_source* sc_source{nullptr};
WINDOW* sc_window{nullptr}; WINDOW* sc_window{nullptr};
int sc_top{0}; int sc_top{0};
unsigned long sc_last_width{0};
bool sc_enabled{true}; bool sc_enabled{true};
}; };

View File

@ -38,27 +38,26 @@
#include "yajlpp/json_op.hh" #include "yajlpp/json_op.hh"
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
using namespace std;
using namespace mapbox; using namespace mapbox;
typedef struct { typedef struct {
shared_ptr<pcrepp> re2; std::shared_ptr<pcrepp> re2;
} cache_entry; } cache_entry;
static cache_entry* static cache_entry*
find_re(const char* re) find_re(const char* re)
{ {
using safe_cache = safe::Safe<unordered_map<string, cache_entry>>; using safe_cache = safe::Safe<std::unordered_map<std::string, cache_entry>>;
static safe_cache CACHE; static safe_cache CACHE;
safe::WriteAccess<safe_cache> wcache(CACHE); safe::WriteAccess<safe_cache> wcache(CACHE);
string re_str = re; std::string re_str = re;
auto iter = wcache->find(re_str); auto iter = wcache->find(re_str);
if (iter == wcache->end()) { if (iter == wcache->end()) {
cache_entry c; cache_entry c;
c.re2 = make_shared<pcrepp>(re_str); c.re2 = std::make_shared<pcrepp>(re_str);
auto pair = wcache->insert(std::make_pair(re_str, c)); auto pair = wcache->insert(std::make_pair(re_str, c));
iter = pair.first; iter = pair.first;
@ -102,33 +101,34 @@ regexp_match(const char* re, const char* str)
if (!cap->is_valid()) { if (!cap->is_valid()) {
return static_cast<const char*>(nullptr); return static_cast<const char*>(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 { } else {
yajlpp_map root_map(gen); yajlpp_map root_map(gen);
column_namer cn; column_namer cn;
for (int lpc = 0; lpc < extractor.get_capture_count(); lpc++) { 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]; pcre_context::capture_t* cap = pc[lpc];
yajl_gen_string(gen, colname); yajl_gen_string(gen, colname);
@ -225,7 +225,7 @@ logfmt2json(string_fragment line)
parse_handle.reset(yajl_alloc( parse_handle.reset(yajl_alloc(
&json_op::ptr_callbacks, nullptr, &jo)); &json_op::ptr_callbacks, nullptr, &jo));
auto json_in const auto* json_in
= (const unsigned char*) qv.qv_value.data(); = (const unsigned char*) qv.qv_value.data();
auto json_len = qv.qv_value.length(); auto json_len = qv.qv_value.length();
@ -252,7 +252,7 @@ logfmt2json(string_fragment line)
return json_string(gen); return json_string(gen);
} }
static string static std::string
regexp_replace(const char* str, const char* re, const char* repl) regexp_replace(const char* str, const char* re, const char* repl)
{ {
cache_entry* reobj = find_re(re); 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); return reobj->re2->replace(str, repl);
} }
static string static std::string
spooky_hash(const vector<const char*>& args) spooky_hash(const std::vector<const char*>& args)
{ {
byte_array<2, uint64> hash; byte_array<2, uint64> hash;
SpookyHash context; SpookyHash context;
context.Init(0, 0); context.Init(0, 0);
for (const auto arg : args) { for (const auto* const arg : args) {
int64_t len = arg != nullptr ? strlen(arg) : 0; int64_t len = arg != nullptr ? strlen(arg) : 0;
context.Update(&len, sizeof(len)); 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)); = (SpookyHash*) sqlite3_aggregate_context(context, sizeof(SpookyHash));
for (int lpc = 0; lpc < argc; lpc++) { 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; int64_t len = value != nullptr ? strlen((const char*) value) : 0;
hasher->Update(&len, sizeof(len)); hasher->Update(&len, sizeof(len));
@ -312,7 +312,7 @@ sql_spooky_hash_final(sqlite3_context* context)
hasher->Final(hash.out(0), hash.out(1)); hasher->Final(hash.out(0), hash.out(1));
string hex = hash.to_string(); auto hex = hash.to_string();
sqlite3_result_text( sqlite3_result_text(
context, hex.c_str(), hex.length(), SQLITE_TRANSIENT); context, hex.c_str(), hex.length(), SQLITE_TRANSIENT);
} }
@ -358,8 +358,8 @@ sparkline_final(sqlite3_context* context)
return; return;
} }
auto retval = (char*) malloc(sc->sc_values.size() * 3 + 1); auto* retval = (char*) malloc(sc->sc_values.size() * 3 + 1);
auto start = retval; auto* start = retval;
for (const auto& value : sc->sc_values) { for (const auto& value : sc->sc_values) {
auto bar = humanize::sparkline(value, sc->sc_max_value); auto bar = humanize::sparkline(value, sc->sc_max_value);
@ -380,7 +380,7 @@ sql_gunzip(sqlite3_value* val)
switch (sqlite3_value_type(val)) { switch (sqlite3_value_type(val)) {
case SQLITE3_TEXT: case SQLITE3_TEXT:
case SQLITE_BLOB: { case SQLITE_BLOB: {
auto buffer = sqlite3_value_blob(val); const auto* buffer = sqlite3_value_blob(val);
auto len = sqlite3_value_bytes(val); auto len = sqlite3_value_bytes(val);
if (!lnav::gzip::is_gzipped((const char*) buffer, len)) { if (!lnav::gzip::is_gzipped((const char*) buffer, len)) {
@ -414,7 +414,7 @@ sql_gzip(sqlite3_value* val)
switch (sqlite3_value_type(val)) { switch (sqlite3_value_type(val)) {
case SQLITE3_TEXT: case SQLITE3_TEXT:
case SQLITE_BLOB: { case SQLITE_BLOB: {
auto buffer = sqlite3_value_blob(val); const auto* buffer = sqlite3_value_blob(val);
auto len = sqlite3_value_bytes(val); auto len = sqlite3_value_bytes(val);
auto res = lnav::gzip::compress(buffer, len); auto res = lnav::gzip::compress(buffer, len);
@ -428,7 +428,6 @@ sql_gzip(sqlite3_value* val)
case SQLITE_INTEGER: case SQLITE_INTEGER:
case SQLITE_FLOAT: { case SQLITE_FLOAT: {
auto buffer = sqlite3_value_text(val); auto buffer = sqlite3_value_text(val);
log_debug("buf %s", buffer);
auto res auto res
= lnav::gzip::compress(buffer, strlen((const char*) buffer)); = lnav::gzip::compress(buffer, strlen((const char*) buffer));

View File

@ -35,6 +35,7 @@ string_attr_type SA_ORIGINAL_LINE("original_line");
string_attr_type SA_BODY("body"); string_attr_type SA_BODY("body");
string_attr_type SA_HIDDEN("hidden"); string_attr_type SA_HIDDEN("hidden");
string_attr_type SA_FORMAT("format"); string_attr_type SA_FORMAT("format");
string_attr_type2<const intern_string_t> SA_FORMAT2("format");
string_attr_type SA_REMOVED("removed"); string_attr_type SA_REMOVED("removed");
string_attr_type SA_INVALID("invalid"); string_attr_type SA_INVALID("invalid");
string_attr_type SA_ERROR("error"); string_attr_type SA_ERROR("error");

View File

@ -30,6 +30,13 @@
#ifndef lnav_string_attr_type_hh #ifndef lnav_string_attr_type_hh
#define lnav_string_attr_type_hh #define lnav_string_attr_type_hh
#include <utility>
#include <stdint.h>
#include "base/intern_string.hh"
#include "mapbox/variant.hpp"
class string_attr_type { class string_attr_type {
public: public:
explicit string_attr_type(const char* name = nullptr) noexcept explicit string_attr_type(const char* name = nullptr) noexcept
@ -37,12 +44,40 @@ public:
const char* sat_name; 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<int64_t, const intern_string_t, std::string>;
class string_attr_type_base {
public:
explicit string_attr_type_base(const char* name) noexcept : sat_name(name)
{
}
const char* const sat_name;
};
template<typename T>
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<string_attr_type_base*, string_attr_value> value(const T& val)
{
return std::make_pair(this, val);
}
};
extern string_attr_type SA_ORIGINAL_LINE; extern string_attr_type SA_ORIGINAL_LINE;
extern string_attr_type SA_BODY; extern string_attr_type SA_BODY;
extern string_attr_type SA_HIDDEN; extern string_attr_type SA_HIDDEN;
extern string_attr_type SA_FORMAT; extern string_attr_type SA_FORMAT;
class intern_string;
extern string_attr_type2<const intern_string_t> SA_FORMAT2;
extern string_attr_type SA_REMOVED; extern string_attr_type SA_REMOVED;
extern string_attr_type SA_INVALID; extern string_attr_type SA_INVALID;
extern string_attr_type SA_ERROR; extern string_attr_type SA_ERROR;

View File

@ -38,31 +38,32 @@
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
#include "yajlpp/yajlpp_def.hh" #include "yajlpp/yajlpp_def.hh"
using namespace std; 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 struct json_path_container term_color_rgb_handler static const struct json_path_container term_color_handler = {
= {yajlpp::property_handler("r").FOR_FIELD(rgb_color, rc_r), yajlpp::property_handler("colorId").FOR_FIELD(term_color, xc_id),
yajlpp::property_handler("g").FOR_FIELD(rgb_color, rc_g), yajlpp::property_handler("name").FOR_FIELD(term_color, xc_name),
yajlpp::property_handler("b").FOR_FIELD(rgb_color, rc_b)}; yajlpp::property_handler("hexString").FOR_FIELD(term_color, xc_hex),
yajlpp::property_handler("rgb")
.with_obj_provider<rgb_color, term_color>(
[](const auto& pc, term_color* xc) { return &xc->xc_color; })
.with_children(term_color_rgb_handler),
};
static struct json_path_container term_color_handler static const struct json_path_container root_color_handler = {
= {yajlpp::property_handler("colorId").FOR_FIELD(term_color, xc_id), yajlpp::property_handler("#")
yajlpp::property_handler("name").FOR_FIELD(term_color, xc_name), .with_obj_provider<term_color, std::vector<term_color>>(
yajlpp::property_handler("hexString").FOR_FIELD(term_color, xc_hex), [](const yajlpp_provider_context& ypc,
yajlpp::property_handler("rgb") std::vector<term_color>* palette) {
.with_obj_provider<rgb_color, term_color>( palette->resize(ypc.ypc_index + 1);
[](const auto& pc, term_color* xc) { return &xc->xc_color; }) return &((*palette)[ypc.ypc_index]);
.with_children(term_color_rgb_handler)}; })
.with_children(term_color_handler),
static struct json_path_container root_color_handler };
= {yajlpp::property_handler("#")
.with_obj_provider<term_color, vector<term_color>>(
[](const yajlpp_provider_context& ypc,
vector<term_color>* palette) {
palette->resize(ypc.ypc_index + 1);
return &((*palette)[ypc.ypc_index]);
})
.with_children(term_color_handler)};
term_color_palette* term_color_palette*
xterm_colors() xterm_colors()

View File

@ -130,7 +130,7 @@ public:
static color_unit make_empty() static color_unit make_empty()
{ {
return {rgb_color{}}; return color_unit{rgb_color{}};
} }
bool empty() const bool empty() const
@ -145,7 +145,7 @@ public:
variants_t cu_value; variants_t cu_value;
private: private:
color_unit(variants_t value) : cu_value(std::move(value)) {} explicit color_unit(variants_t value) : cu_value(std::move(value)) {}
}; };
} // namespace styling } // namespace styling

View File

@ -31,7 +31,7 @@
#include <unistd.h> #include <unistd.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "base/auto_pid.hh" #include "base/auto_pid.hh"
#include "config.h" #include "config.h"
#include "ghc/filesystem.hpp" #include "ghc/filesystem.hpp"

View File

@ -108,7 +108,7 @@ update_tailer_progress(const std::string& netloc, const std::string& msg)
static void static void
update_tailer_description( update_tailer_description(
const std::string& netloc, const std::string& netloc,
const std::map<std::string, logfile_open_options>& desired_paths, const std::map<std::string, logfile_open_options_base>& desired_paths,
const std::string& remote_uname) const std::string& remote_uname)
{ {
std::vector<std::string> paths; std::vector<std::string> paths;
@ -182,7 +182,7 @@ tailer::looper::loop_body()
for (const auto& pair : paths) { for (const auto& pair : paths) {
log_debug("adding path to tailer -- %s", log_debug("adding path to tailer -- %s",
pair.first.c_str()); 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 void
tailer::looper::add_remote(const network::path& path, 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()); auto netloc_str = fmt::to_string(path.home());
this->l_netlocs_to_paths[netloc_str].rpq_new_paths[path.p_path] 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 void
tailer::looper::host_tailer::open_remote_path(const std::string& path, tailer::looper::host_tailer::open_remote_path(const std::string& path,
logfile_open_options loo) logfile_open_options_base loo)
{ {
this->ht_state.match( this->ht_state.match(
[&](connected& conn) { [&](connected& conn) {
@ -660,7 +660,7 @@ tailer::looper::host_tailer::loop_body()
pob.pob_offset, pob.pob_offset,
pob.pob_length); pob.pob_length);
logfile_open_options loo; logfile_open_options_base loo;
if (pob.pob_path == pob.pob_root_path) { if (pob.pob_path == pob.pob_root_path) {
auto root_iter = conn.c_desired_paths.find(pob.pob_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); return std::move(this->ht_state);
} }
loo = std::move(root_iter->second); loo = root_iter->second;
} else { } else {
auto child_iter = conn.c_child_paths.find(pob.pob_path); auto child_iter = conn.c_child_paths.find(pob.pob_path);
if (child_iter == conn.c_child_paths.end()) { if (child_iter == conn.c_child_paths.end()) {

View File

@ -34,7 +34,7 @@
#include <logfile_fwd.hh> #include <logfile_fwd.hh>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "base/auto_pid.hh" #include "base/auto_pid.hh"
#include "base/isc.hh" #include "base/isc.hh"
#include "base/network.tcp.hh" #include "base/network.tcp.hh"
@ -45,7 +45,8 @@ namespace tailer {
class looper : public isc::service<looper> { class looper : public isc::service<looper> {
public: 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); void load_preview(int64_t id, const network::path& path);
@ -84,7 +85,7 @@ private:
auto_fd err_from_child); auto_fd err_from_child);
void open_remote_path(const std::string& path, 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); void load_preview(int64_t id, const std::string& path);
@ -114,8 +115,8 @@ private:
auto_pid<process_state::running> ht_child; auto_pid<process_state::running> ht_child;
auto_fd ht_to_child; auto_fd ht_to_child;
auto_fd ht_from_child; auto_fd ht_from_child;
std::map<std::string, logfile_open_options> c_desired_paths; std::map<std::string, logfile_open_options_base> c_desired_paths;
std::map<std::string, logfile_open_options> c_child_paths; std::map<std::string, logfile_open_options_base> c_child_paths;
auto_pid<process_state::finished> close() &&; auto_pid<process_state::finished> close() &&;
}; };
@ -145,8 +146,8 @@ private:
struct remote_path_queue { struct remote_path_queue {
attempt_time_point rpq_next_attempt_time{ attempt_time_point rpq_next_attempt_time{
std::chrono::steady_clock::now()}; std::chrono::steady_clock::now()};
std::map<std::string, logfile_open_options> rpq_new_paths; std::map<std::string, logfile_open_options_base> rpq_new_paths;
std::map<std::string, logfile_open_options> rpq_existing_paths; std::map<std::string, logfile_open_options_base> rpq_existing_paths;
void send_synced_to_main(const std::string& netloc); void send_synced_to_main(const std::string& netloc);
}; };

View File

@ -33,8 +33,6 @@
#include "config.h" #include "config.h"
using namespace std;
static pcre* static pcre*
xpcre_compile(const char* pattern, int options = 0) xpcre_compile(const char* pattern, int options = 0)
{ {

View File

@ -43,8 +43,6 @@
#include "shlex.hh" #include "shlex.hh"
#include "view_curses.hh" #include "view_curses.hh"
using namespace std;
const auto REVERSE_SEARCH_OFFSET = 2000_vl; const auto REVERSE_SEARCH_OFFSET = 2000_vl;
void void
@ -143,7 +141,7 @@ textview_curses::~textview_curses()
void void
textview_curses::reload_config(error_reporter& reporter) 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(); for (auto iter = this->tc_highlights.begin();
iter != this->tc_highlights.end();) iter != this->tc_highlights.end();)
@ -196,7 +194,7 @@ textview_curses::reload_config(error_reporter& reporter)
} }
const auto& sc = hl_pair.second.hc_style; 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; bool invalid = false;
int attrs = 0; int attrs = 0;
@ -334,7 +332,7 @@ textview_curses::grep_match(grep_proc<vis_line_t>& gp,
void void
textview_curses::listview_value_for_rows(const listview_curses& lv, textview_curses::listview_value_for_rows(const listview_curses& lv,
vis_line_t row, vis_line_t row,
vector<attr_line_t>& rows_out) std::vector<attr_line_t>& rows_out)
{ {
for (auto& al : rows_out) { for (auto& al : rows_out) {
this->textview_value_for_row(row, al); this->textview_value_for_row(row, al);
@ -428,9 +426,9 @@ textview_curses::handle_mouse(mouse_event& me)
void void
textview_curses::textview_value_for_row(vis_line_t row, attr_line_t& value_out) textview_curses::textview_value_for_row(vis_line_t row, attr_line_t& value_out)
{ {
string_attrs_t& sa = value_out.get_attrs(); auto& sa = value_out.get_attrs();
string& str = value_out.get_string(); auto& str = value_out.get_string();
text_format_t source_format = this->tc_sub_source->get_text_format(); auto source_format = this->tc_sub_source->get_text_format();
intern_string_t format_name; intern_string_t format_name;
this->tc_sub_source->text_value_for_line(*this, row, str); 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)) regex.c_str(), PCRE_CASELESS, &errptr, &eoff, nullptr))
== nullptr) == nullptr)
{ {
string errmsg = string(errptr); auto errmsg = std::string(errptr);
regex = pcrepp::quote(regex); regex = pcrepp::quote(regex);
@ -598,8 +596,7 @@ textview_curses::execute_search(const std::string& regex_orig)
highlight_map_t& hm = this->get_highlights(); highlight_map_t& hm = this->get_highlights();
hm[{highlight_source_t::PREVIEW, "search"}] = hl; hm[{highlight_source_t::PREVIEW, "search"}] = hl;
unique_ptr<grep_proc<vis_line_t>> gp auto gp = std::make_unique<grep_proc<vis_line_t>>(code, *this);
= make_unique<grep_proc<vis_line_t>>(code, *this);
gp->set_sink(this); gp->set_sink(this);
auto top = this->get_top(); auto top = this->get_top();
@ -619,8 +616,8 @@ textview_curses::execute_search(const std::string& regex_orig)
if (this->tc_sub_source != nullptr) { if (this->tc_sub_source != nullptr) {
this->tc_sub_source->get_grepper() | [this, code](auto pair) { this->tc_sub_source->get_grepper() | [this, code](auto pair) {
shared_ptr<grep_proc<vis_line_t>> sgp auto sgp = std::make_shared<grep_proc<vis_line_t>>(
= make_shared<grep_proc<vis_line_t>>(code, *pair.first); code, *pair.first);
sgp->set_sink(pair.second); sgp->set_sink(pair.second);
sgp->queue_request(0_vl); sgp->queue_request(0_vl);
@ -642,7 +639,7 @@ void
textview_curses::horiz_shift(vis_line_t start, textview_curses::horiz_shift(vis_line_t start,
vis_line_t end, vis_line_t end,
int off_start, int off_start,
pair<int, int>& range_out) std::pair<int, int>& range_out)
{ {
highlighter& hl highlighter& hl
= this->tc_highlights[{highlight_source_t::PREVIEW, "search"}]; = this->tc_highlights[{highlight_source_t::PREVIEW, "search"}];
@ -799,7 +796,7 @@ empty_filter::matches(const logfile& lf,
return false; return false;
} }
string std::string
empty_filter::to_command() const empty_filter::to_command() const
{ {
return ""; return "";

View File

@ -41,8 +41,6 @@
#include "sql_util.hh" #include "sql_util.hh"
#include "vtab_module.hh" #include "vtab_module.hh"
using namespace std;
static nonstd::optional<text_auto_buffer> static nonstd::optional<text_auto_buffer>
timeslice(sqlite3_value* time_in, nonstd::optional<const char*> slice_in_opt) timeslice(sqlite3_value* time_in, nonstd::optional<const char*> slice_in_opt)
{ {

View File

@ -51,7 +51,7 @@ public:
auto tmp_pair = tmp_res.unwrap(); auto tmp_pair = tmp_res.unwrap();
ghc::filesystem::remove(tmp_pair.first); 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_URL, this->cr_name.c_str());
curl_easy_setopt(this->cr_handle, CURLOPT_WRITEFUNCTION, write_cb); curl_easy_setopt(this->cr_handle, CURLOPT_WRITEFUNCTION, write_cb);
@ -66,7 +66,7 @@ public:
auto_fd copy_fd() const auto_fd copy_fd() const
{ {
return this->ul_fd; return this->ul_fd.dup();
}; };
long complete(CURLcode result) long complete(CURLcode result)

View File

@ -40,18 +40,18 @@
#include "view_helpers.examples.hh" #include "view_helpers.examples.hh"
#include "vtab_module.hh" #include "vtab_module.hh"
using namespace std; const char* lnav_view_strings[LNV__MAX + 1] = {
"log",
"text",
"help",
"histogram",
"db",
"schema",
"pretty",
"spectro",
const char* lnav_view_strings[LNV__MAX + 1] = {"log", nullptr,
"text", };
"help",
"histogram",
"db",
"schema",
"pretty",
"spectro",
nullptr};
nonstd::optional<lnav_view_t> nonstd::optional<lnav_view_t>
view_from_string(const char* name) view_from_string(const char* name)
@ -61,13 +61,13 @@ view_from_string(const char* name)
} }
auto view_name_iter auto view_name_iter
= find_if(::begin(lnav_view_strings), = std::find_if(std::begin(lnav_view_strings),
::end(lnav_view_strings), std::end(lnav_view_strings),
[&](const char* v) { [&](const char* v) {
return v != nullptr && strcasecmp(v, name) == 0; 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; return nonstd::nullopt;
} }
@ -78,7 +78,7 @@ static void
open_schema_view() open_schema_view()
{ {
textview_curses* schema_tc = &lnav_data.ld_views[LNV_SCHEMA]; textview_curses* schema_tc = &lnav_data.ld_views[LNV_SCHEMA];
string schema; std::string schema;
dump_sqlite_schema(lnav_data.ld_db, 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(); for (vis_line_t vl = log_tc->get_top(); vl <= log_tc->get_bottom();
++vl) { ++vl) {
content_line_t cl = lss.at(vl); content_line_t cl = lss.at(vl);
shared_ptr<logfile> lf = lss.find(cl); auto lf = lss.find(cl);
auto ll = lf->begin() + cl; auto ll = lf->begin() + cl;
shared_buffer_ref sbr; shared_buffer_ref sbr;
@ -153,7 +153,7 @@ open_pretty_view()
data_scanner ds(orig_al.get_string()); data_scanner ds(orig_al.get_string());
pretty_printer pp(&ds, orig_al.get_attrs()); pretty_printer pp(&ds, orig_al.get_attrs());
attr_line_t pretty_al; attr_line_t pretty_al;
vector<attr_line_t> pretty_lines; std::vector<attr_line_t> pretty_lines;
// TODO: dump more details of the line in the output. // TODO: dump more details of the line in the output.
pp.append_to(pretty_al); pp.append_to(pretty_al);
@ -176,7 +176,7 @@ open_pretty_view()
full_text.erase(full_text.length() - 1, 1); full_text.erase(full_text.length() - 1, 1);
} }
} else if (top_tc == text_tc) { } else if (top_tc == text_tc) {
shared_ptr<logfile> 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(); for (vis_line_t vl = text_tc->get_top(); vl <= text_tc->get_bottom();
++vl) { ++vl) {
@ -210,14 +210,14 @@ build_all_help_text()
attr_line_t all_help_text; attr_line_t all_help_text;
shlex lexer(help_txt.to_string_fragment()); shlex lexer(help_txt.to_string_fragment());
string sub_help_text; std::string sub_help_text;
lexer.with_ignore_quotes(true).eval( lexer.with_ignore_quotes(true).eval(
sub_help_text, lnav_data.ld_exec_context.ec_global_vars); sub_help_text, lnav_data.ld_exec_context.ec_global_vars);
all_help_text.with_ansi_string(sub_help_text); all_help_text.with_ansi_string(sub_help_text);
map<string, help_text*> sql_funcs; std::map<std::string, help_text*> sql_funcs;
map<string, help_text*> sql_keywords; std::map<std::string, help_text*> sql_keywords;
for (const auto& iter : sqlite_function_help) { for (const auto& iter : sqlite_function_help) {
switch (iter.second->ht_context) { switch (iter.second->ht_context) {
@ -293,7 +293,7 @@ layout_views()
? 0 ? 0
: lnav_data.ld_preview_source.text_line_count(); : lnav_data.ld_preview_source.text_line_count();
int match_rows = lnav_data.ld_match_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)); 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); lnav_data.ld_rl_view->set_width(width);
} }
static unordered_map<string, attr_line_t> EXAMPLE_RESULTS; static std::unordered_map<std::string, attr_line_t> EXAMPLE_RESULTS;
void void
execute_examples() execute_examples()
@ -389,7 +389,7 @@ execute_examples()
struct help_text& ht = *(help_iter.second); struct help_text& ht = *(help_iter.second);
for (auto& ex : ht.ht_example) { for (auto& ex : ht.ht_example) {
string alt_msg; std::string alt_msg;
attr_line_t result; attr_line_t result;
if (!ex.he_cmd) { 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); textview_curses* tc = lnav_data.ld_view_stack.top().value_or(nullptr);
bool retval = false; 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[0]);
require(toggle_tc < &lnav_data.ld_views[LNV__MAX]); require(toggle_tc < &lnav_data.ld_views[LNV__MAX]);
@ -536,9 +536,11 @@ next_cluster(vis_line_t (bookmark_vector<vis_line_t>::*f)(vis_line_t) const,
hit_count += 1; hit_count += 1;
if (!top_is_marked || diff > 1) { if (!top_is_marked || diff > 1) {
return new_top; 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); return vis_line_t(new_top - diff);
} else if (diff < -1) { }
if (diff < -1) {
last_top = new_top; last_top = new_top;
while ((new_top = (bv.*f)(new_top)) != -1) { while ((new_top = (bv.*f)(new_top)) != -1) {
if ((std::abs(last_top - new_top) > 1) if ((std::abs(last_top - new_top) > 1)

View File

@ -57,8 +57,6 @@
# error "SysV or X/Open-compatible Curses header file required" # error "SysV or X/Open-compatible Curses header file required"
#endif #endif
using namespace std;
/** /**
* Singleton used to hold the mapping of ncurses keycodes to VT52 escape * Singleton used to hold the mapping of ncurses keycodes to VT52 escape
* sequences. * sequences.
@ -79,10 +77,10 @@ public:
*/ */
const char* operator[](int ch) const const char* operator[](int ch) const
{ {
map<int, const char*>::const_iterator iter; auto iter = this->vem_map.find(ch);
const char* retval = nullptr; 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) { if (ch > KEY_MAX) {
auto name = keyname(ch); auto name = keyname(ch);
@ -104,7 +102,7 @@ public:
const char* operator[](const char* seq) const const char* operator[](const char* seq) const
{ {
map<string, const char*>::const_iterator iter; std::map<std::string, const char*>::const_iterator iter;
const char* retval = nullptr; const char* retval = nullptr;
require(seq != nullptr); require(seq != nullptr);
@ -162,8 +160,8 @@ private:
}; };
/** Map of ncurses keycodes to VT52 escape sequences. */ /** Map of ncurses keycodes to VT52 escape sequences. */
mutable map<int, const char*> vem_map; mutable std::map<int, const char*> vem_map;
map<string, const char*> vem_input_map; std::map<std::string, const char*> vem_input_map;
}; };
const char* const char*

View File

@ -39,8 +39,6 @@
#include "xml_util.hh" #include "xml_util.hh"
#include "yajlpp/yajlpp.hh" #include "yajlpp/yajlpp.hh"
using namespace std;
enum { enum {
XP_COL_RESULT, XP_COL_RESULT,
XP_COL_NODE_PATH, XP_COL_NODE_PATH,
@ -104,8 +102,8 @@ CREATE TABLE xpath (
struct cursor { struct cursor {
sqlite3_vtab_cursor base; sqlite3_vtab_cursor base;
sqlite3_int64 c_rowid{0}; sqlite3_int64 c_rowid{0};
string c_xpath; std::string c_xpath;
string c_value; std::string c_value;
bool c_value_as_blob{false}; bool c_value_as_blob{false};
pugi::xpath_query c_query; pugi::xpath_query c_query;
pugi::xml_document c_doc; pugi::xml_document c_doc;
@ -153,7 +151,7 @@ CREATE TABLE xpath (
auto& xpath_node = vc.c_results[vc.c_rowid]; auto& xpath_node = vc.c_results[vc.c_rowid];
if (xpath_node.node()) { if (xpath_node.node()) {
ostringstream oss; std::ostringstream oss;
// XXX avoid the extra allocs // XXX avoid the extra allocs
xpath_node.node().print(oss); xpath_node.node().print(oss);
@ -356,29 +354,35 @@ register_xpath_vtab(sqlite3* db)
"over an XML " "over an XML "
"string and returns the selected values.") "string and returns the selected values.")
.sql_table_valued_function() .sql_table_valued_function()
.with_parameter( .with_parameter({
{"xpath", "xpath",
"The XPATH expression to evaluate over the XML document."}) "The XPATH expression to evaluate over the XML document.",
})
.with_parameter({"xmldoc", "The XML document as a string."}) .with_parameter({"xmldoc", "The XML document as a string."})
.with_result({"result", "The result of the XPATH expression."}) .with_result({"result", "The result of the XPATH expression."})
.with_result( .with_result({
{"node_path", "node_path",
"The absolute path to the node containing the result."}) "The absolute path to the node containing the result.",
})
.with_result( .with_result(
{"node_attr", "The node's attributes stored in JSON object."}) {"node_attr", "The node's attributes stored in JSON object."})
.with_result({"node_text", "The node's text value."}) .with_result({"node_text", "The node's text value."})
.with_tags({"string", "xml"}) .with_tags({"string", "xml"})
.with_example({"To select the XML nodes on the path '/abc/def'", .with_example({
"SELECT * FROM xpath('/abc/def', '<abc><def " "To select the XML nodes on the path '/abc/def'",
"a=\"b\">Hello</def><def>Bye</def></abc>')"}) "SELECT * FROM xpath('/abc/def', '<abc><def "
.with_example( "a=\"b\">Hello</def><def>Bye</def></abc>')",
{"To select all 'a' attributes on the path '/abc/def'", })
"SELECT * FROM xpath('/abc/def/@a', '<abc><def " .with_example({
"a=\"b\">Hello</def><def>Bye</def></abc>')"}) "To select all 'a' attributes on the path '/abc/def'",
.with_example( "SELECT * FROM xpath('/abc/def/@a', '<abc><def "
{"To select the text nodes on the path '/abc/def'", "a=\"b\">Hello</def><def>Bye</def></abc>')",
"SELECT * FROM xpath('/abc/def/text()', '<abc><def " })
"a=\"b\">Hello &#x2605;</def></abc>')"}); .with_example({
"To select the text nodes on the path '/abc/def'",
"SELECT * FROM xpath('/abc/def/text()', '<abc><def "
"a=\"b\">Hello &#x2605;</def></abc>')",
});
int rc; int rc;
@ -386,7 +390,7 @@ register_xpath_vtab(sqlite3* db)
XPATH_MODULE.vm_module.xFilter = rcFilter; XPATH_MODULE.vm_module.xFilter = rcFilter;
rc = XPATH_MODULE.create(db, "xpath"); 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(); xpath_help.index_tags();
ensure(rc == SQLITE_OK); ensure(rc == SQLITE_OK);

View File

@ -40,8 +40,6 @@
#include "yajl/api/yajl_gen.h" #include "yajl/api/yajl_gen.h"
#include "yajlpp.hh" #include "yajlpp.hh"
using namespace std;
int int
main(int argc, char* argv[]) main(int argc, char* argv[])
{ {
@ -51,7 +49,7 @@ main(int argc, char* argv[])
log_argv(argc, argv); log_argv(argc, argv);
std::string json_input(std::istreambuf_iterator<char>(cin), {}); std::string json_input(std::istreambuf_iterator<char>(std::cin), {});
status = jpw.parse(json_input.c_str(), json_input.size()); status = jpw.parse(json_input.c_str(), json_input.size());
if (status == yajl_status_error) { if (status == yajl_status_error) {

View File

@ -38,8 +38,6 @@
#include "yajl/api/yajl_gen.h" #include "yajl/api/yajl_gen.h"
#include "yajlpp/json_ptr.hh" #include "yajlpp/json_ptr.hh"
using namespace std;
static int static int
handle_null(void* ctx) 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; json_ptr_walk* jpw = (json_ptr_walk*) ctx;
jpw->jpw_values.emplace_back( 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(); jpw->inc_array_index();
return 1; return 1;
@ -79,7 +77,7 @@ handle_number(void* ctx, const char* numberVal, size_t numberLen)
static void static void
appender(void* ctx, const char* strVal, size_t strLen) appender(void* ctx, const char* strVal, size_t strLen)
{ {
string& str = *(string*) ctx; std::string& str = *(std::string*) ctx;
str.append(strVal, strLen); 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; json_ptr_walk* jpw = (json_ptr_walk*) ctx;
auto_mem<yajl_gen_t> gen(yajl_gen_free); auto_mem<yajl_gen_t> gen(yajl_gen_free);
string str; std::string str;
gen = yajl_gen_alloc(nullptr); gen = yajl_gen_alloc(nullptr);
yajl_gen_config(gen.in(), yajl_gen_print_callback, appender, &str); yajl_gen_config(gen.in(), yajl_gen_print_callback, appender, &str);

View File

@ -39,12 +39,10 @@
#include "yajl/api/yajl_parse.h" #include "yajl/api/yajl_parse.h"
#include "yajlpp_def.hh" #include "yajlpp_def.hh"
using namespace std;
const json_path_handler_base::enum_value_t const json_path_handler_base::enum_value_t
json_path_handler_base::ENUM_TERMINATOR((const char*) nullptr, 0); 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() == '#' : jph_property(property.back() == '#'
? property.substr(0, property.size() - 1) ? property.substr(0, property.size() - 1)
: property), : 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)); 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) const pcrepp& property_re)
: jph_property(std::move(property)), jph_regex(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)); 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 yajl_gen_status
json_path_handler_base::gen(yajlpp_gen_context& ygc, yajl_gen handle) const json_path_handler_base::gen(yajlpp_gen_context& ygc, yajl_gen handle) const
{ {
vector<string> local_paths; std::vector<std::string> local_paths;
if (this->jph_path_provider) { if (this->jph_path_provider) {
this->jph_path_provider(ygc.ygc_obj_stack.top(), local_paths); 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) { if (this->jph_children) {
for (const auto& lpath : local_paths) { for (const auto& lpath : local_paths) {
string full_path = lpath; std::string full_path = lpath;
if (this->jph_path_provider) { if (this->jph_path_provider) {
full_path += "/"; full_path += "/";
} }
@ -180,7 +178,8 @@ json_path_handler_base::gen_schema(yajlpp_gen_context& ygc) const
fmt::join(ygc.ygc_path, "/"))); fmt::join(ygc.ygc_path, "/")));
schema.gen("type"); schema.gen("type");
if (this->jph_is_array) { 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"); schema.gen("array");
} else { } else {
yajlpp_array type_array(ygc.ygc_handle); 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"); schema.gen("type");
if (this->jph_is_array) { 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"); schema.gen("array");
} else { } else {
yajlpp_array type_array(ygc.ygc_handle); yajlpp_array type_array(ygc.ygc_handle);
@ -327,9 +326,9 @@ json_path_handler_base::walk(
const std::function< const std::function<
void(const json_path_handler_base&, const std::string&, void*)>& cb, void(const json_path_handler_base&, const std::string&, void*)>& cb,
void* root, void* root,
const string& base) const const std::string& base) const
{ {
vector<string> local_paths; std::vector<std::string> local_paths;
if (this->jph_path_provider) { if (this->jph_path_provider) {
this->jph_path_provider(root, local_paths); this->jph_path_provider(root, local_paths);
@ -340,7 +339,7 @@ json_path_handler_base::walk(
} else { } else {
local_paths.emplace_back(this->jph_property); 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) { if (this->jph_children) {
full_path += "/"; full_path += "/";
} }
@ -350,7 +349,7 @@ json_path_handler_base::walk(
if (this->jph_children) { if (this->jph_children) {
for (const auto& lpath : local_paths) { for (const auto& lpath : local_paths) {
for (auto& jph : this->jph_children->jpc_children) { for (auto& jph : this->jph_children->jpc_children) {
string full_path = base + lpath; std::string full_path = base + lpath;
if (this->jph_children) { if (this->jph_children) {
full_path += "/"; full_path += "/";
} }
@ -363,7 +362,7 @@ json_path_handler_base::walk(
ypc.set_path(full_path).with_obj(root).update_callbacks(); ypc.set_path(full_path).with_obj(root).update_callbacks();
if (this->jph_obj_provider) { if (this->jph_obj_provider) {
string full_path = lpath + "/"; std::string full_path = lpath + "/";
pcre_input pi(full_path); pcre_input pi(full_path);
if (!this->jph_regex.match(ypc.ypc_pcre_context, pi)) { 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; return nonstd::nullopt;
} }
vector<json_path_handler_base::schema_type_t> std::vector<json_path_handler_base::schema_type_t>
json_path_handler_base::get_types() const json_path_handler_base::get_types() const
{ {
std::vector<schema_type_t> retval; std::vector<schema_type_t> retval;
@ -537,7 +536,7 @@ yajlpp_parse_context::update_callbacks(const json_path_container* orig_handlers,
} }
if (!this->ypc_active_paths.empty()) { 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) if (this->ypc_active_paths.find(curr_path)
== this->ypc_active_paths.end()) { == 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.push_back('\0');
this->ypc_path_index_stack.clear(); this->ypc_path_index_stack.clear();
this->ypc_array_index.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; 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; 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; 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; 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; this->ypc_callbacks.yajl_string = jph.jph_callbacks.yajl_string;
}
} }
yajlpp_parse_context& 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); this->ypc_path.resize(path.size() + 1);
std::copy(path.begin(), path.end(), this->ypc_path.begin()); std::copy(path.begin(), path.end(), this->ypc_path.begin());
@ -950,7 +954,7 @@ yajlpp_parse_context::get_path_fragment(int offset,
int int
yajlpp_parse_context::get_line_number() const 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); size_t consumed = yajl_get_bytes_consumed(this->ypc_handle);
long current_count = std::count( long current_count = std::count(
&this->ypc_json_text[0], &this->ypc_json_text[consumed], '\n'); &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); 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); 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); 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) { if (!child_handler.jph_is_pattern_property) {
continue; continue;
} }
@ -1107,7 +1111,7 @@ dump_schema_to(const json_path_container& jpc,
yajlpp_gen genner; yajlpp_gen genner;
yajlpp_gen_context ygc(genner, jpc); yajlpp_gen_context ygc(genner, jpc);
auto schema_path = fmt::format(FMT_STRING("{}/{}"), internals_dir, name); auto schema_path = fmt::format(FMT_STRING("{}/{}"), internals_dir, name);
auto file = unique_ptr<FILE, decltype(&fclose)>( auto file = std::unique_ptr<FILE, decltype(&fclose)>(
fopen(schema_path.c_str(), "w+"), fclose); fopen(schema_path.c_str(), "w+"), fclose);
if (!file.get()) { if (!file.get()) {

View File

@ -31,7 +31,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
void void
foo(int* fd) foo(int* fd)

View File

@ -48,8 +48,6 @@
#include "pretty_printer.hh" #include "pretty_printer.hh"
#include "shared_buffer.hh" #include "shared_buffer.hh"
using namespace std;
const char* TMP_NAME = "scanned.tmp"; const char* TMP_NAME = "scanned.tmp";
int int
@ -71,7 +69,7 @@ main(int argc, char* argv[])
{ {
std::vector<ghc::filesystem::path> paths; std::vector<ghc::filesystem::path> paths;
vector<string> errors; std::vector<std::string> errors;
load_formats(paths, errors); load_formats(paths, errors);
} }
@ -105,14 +103,14 @@ main(int argc, char* argv[])
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
} else { } else {
for (int lpc = 0; lpc < argc; lpc++) { for (int lpc = 0; lpc < argc; lpc++) {
std::unique_ptr<ifstream> in_ptr; std::unique_ptr<std::ifstream> in_ptr;
istream* in; std::istream* in;
FILE* out; FILE* out;
if (strcmp(argv[lpc], "-") == 0) { if (strcmp(argv[lpc], "-") == 0) {
in = &cin; in = &std::cin;
} else { } else {
auto ifs = std::make_unique<ifstream>(argv[lpc]); auto ifs = std::make_unique<std::ifstream>(argv[lpc]);
if (!ifs->is_open()) { if (!ifs->is_open()) {
fprintf(stderr, "error: unable to open file\n"); 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"); "error: unable to temporary file for writing\n");
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
} else { } else {
shared_ptr<log_format> format; std::shared_ptr<log_format> format;
char* log_line; char* log_line;
bool found = false; bool found = false;
char cmd[2048]; char cmd[2048];
string line; std::string line;
int rc; int rc;
getline(*in, line); getline(*in, line);
@ -142,7 +140,7 @@ main(int argc, char* argv[])
log_line = (char*) alloca(line.length()); log_line = (char*) alloca(line.length());
strcpy(log_line, &line[13]); 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()); struct line_range body(0, sub_line.length());
shared_buffer share_manager; shared_buffer share_manager;
shared_buffer_ref sbr; shared_buffer_ref sbr;
@ -151,8 +149,8 @@ main(int argc, char* argv[])
share_manager, (char*) sub_line.c_str(), sub_line.size()); share_manager, (char*) sub_line.c_str(), sub_line.size());
auto& root_formats = log_format::get_root_formats(); auto& root_formats = log_format::get_root_formats();
vector<std::shared_ptr<log_format>>::iterator iter; std::vector<std::shared_ptr<log_format>>::iterator iter;
vector<logline> index; std::vector<logline> index;
if (is_log) { if (is_log) {
for (iter = root_formats.begin(); for (iter = root_formats.begin();
@ -175,7 +173,7 @@ main(int argc, char* argv[])
} }
} }
vector<logline_value> ll_values; std::vector<logline_value> ll_values;
string_attrs_t sa; string_attrs_t sa;
if (format.get() != nullptr) { 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_scanner ds(sub_line, body.lr_start, sub_line.length());
data_parser dp(&ds); data_parser dp(&ds);
string msg_format; std::string msg_format;
dp.dp_msg_format = &msg_format; dp.dp_msg_format = &msg_format;
dp.parse(); dp.parse();

View File

@ -41,7 +41,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "base/string_util.hh" #include "base/string_util.hh"
#include "config.h" #include "config.h"
#include "line_buffer.hh" #include "line_buffer.hh"

View File

@ -77,7 +77,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "auto_mem.hh" #include "auto_mem.hh"
#include "base/string_util.hh" #include "base/string_util.hh"
#include "fmt/format.h" #include "fmt/format.h"

View File

@ -33,7 +33,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "config.h" #include "config.h"
int int
@ -62,7 +62,7 @@ main(int argc, char* argv[])
assert(errno == EBADF); assert(errno == EBADF);
{ {
auto_fd fd_cp(const_cast<const auto_fd&>(fd1)); auto_fd fd_cp(fd1.dup());
assert(fd1 == STDOUT_FILENO); assert(fd1 == STDOUT_FILENO);
assert(fd_cp != STDOUT_FILENO); assert(fd_cp != STDOUT_FILENO);
@ -71,7 +71,7 @@ main(int argc, char* argv[])
tmp = (int) fd_cp; tmp = (int) fd_cp;
} }
{ {
auto_fd fd_cp(const_cast<const auto_fd&>(fd1)); auto_fd fd_cp(fd1.dup());
assert(fd_cp == tmp); assert(fd_cp == tmp);
} }

View File

@ -1,7 +1,7 @@
#! /bin/bash #! /bin/bash
export TZ="UTC" export TZ="UTC"
run_test ${lnav_test} -t -n <<EOF run_test ${lnav_test} -d /tmp/lnav.err -t -n <<EOF
Hello, World! Hello, World!
Goodbye, World! Goodbye, World!
EOF EOF

View File

@ -32,7 +32,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "auto_fd.hh" #include "base/auto_fd.hh"
#include "config.h" #include "config.h"
#include "line_buffer.hh" #include "line_buffer.hh"

View File

@ -3,6 +3,16 @@
echo ${top_srcdir} echo ${top_srcdir}
echo ${top_builddir} 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' <<EOF
2013-06-06T19:13:20.123 Hi
EOF
check_output "piping to stdin is not working?" <<EOF
2013-06-06T19:13:20.123 Hi
EOF
if test x"${TSHARK_CMD}" != x""; then if test x"${TSHARK_CMD}" != x""; then
run_test env TZ=UTC ${lnav_test} -n ${test_dir}/dhcp.pcapng run_test env TZ=UTC ${lnav_test} -n ${test_dir}/dhcp.pcapng
@ -20,15 +30,6 @@ error: unable to open file: {test_dir}/dhcp-trunc.pcapng -- tshark: The file "{t
EOF EOF
fi fi
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' <<EOF
2013-06-06T19:13:20.123 Hi
EOF
check_output "piping to stdin is not working?" <<EOF
2013-06-06T19:13:20.123 Hi
EOF
cp ${srcdir}/logfile_syslog.0 truncfile.0 cp ${srcdir}/logfile_syslog.0 truncfile.0
chmod u+w truncfile.0 chmod u+w truncfile.0
@ -171,7 +172,7 @@ EOF
> test_logfile.rotmp.out > test_logfile.rotmp.out
cp test_logfile.rotmp.out `test_err_filename` cp test_logfile.rotmp.out `test_err_filename`
check_error_output "archive not unpacked" <<EOF check_error_output "archive not unpacked" <<EOF
error: unable to open file: /test-logs.tgz -- unable to write entry: rotmp/lnav-user-NNN-work/archives/arc-NNN-test-logs.tgz/test/logfile_access_log.0 -- ... error: unable to open file: /test-logs.tgz -- Unable to create directory: rotmp/lnav-user-NNN-work/archives -- Permission denied
EOF EOF
fi fi