1
1
mirror of https://github.com/tstack/lnav.git synced 2024-10-26 13:16:11 +03:00

[cleanup] prune some includes and some other cleaning

Defect Number:
    Reviewed By:
   Testing Done:
This commit is contained in:
Timothy Stack 2018-10-11 05:50:28 -07:00
parent c715807657
commit 5f5e2d5c4e
45 changed files with 654 additions and 733 deletions

View File

@ -137,7 +137,6 @@ set(diag_STAT_SRCS
sequence_sink.hh
shlex.hh
spectro_source.hh
status_controllers.hh
strong_int.hh
sysclip.hh
term_extra.hh

View File

@ -219,7 +219,6 @@ noinst_HEADERS = \
spectro_source.hh \
sql_util.hh \
sqlite-extension-func.hh \
status_controllers.hh \
statusview_curses.hh \
strnatcmp.h \
strong_int.hh \

View File

@ -30,7 +30,6 @@
#ifndef LNAV_ALL_LOGS_VTAB_HH
#define LNAV_ALL_LOGS_VTAB_HH
#include "byte_array.hh"
#include "log_vtab_impl.hh"
#include "data_parser.hh"
@ -44,16 +43,15 @@ public:
}
void get_columns(std::vector<vtab_column> &cols) const {
cols.push_back(vtab_column(this->alv_value_name.get()));
cols.push_back(vtab_column(this->alv_msg_name.get()));
cols.push_back(vtab_column(this->alv_schema_name.get(), SQLITE3_TEXT, NULL, true));
cols.emplace_back(this->alv_value_name.get());
cols.emplace_back(this->alv_msg_name.get());
cols.emplace_back(this->alv_schema_name.get(), SQLITE3_TEXT, nullptr, true);
};
void extract(std::shared_ptr<logfile> lf, shared_buffer_ref &line,
std::vector<logline_value> &values) {
log_format *format = lf->get_format();
values.push_back(logline_value(this->alv_value_name,
format->get_name(), 0));
values.emplace_back(this->alv_value_name, format->get_name(), 0);
std::vector<logline_value> sub_values;
struct line_range body;
@ -76,7 +74,7 @@ public:
tmp_shared_buffer tsb(str.c_str());
values.push_back(logline_value(this->alv_msg_name, tsb.tsb_ref, 1));
values.emplace_back(this->alv_msg_name, tsb.tsb_ref, 1);
this->alv_schema_manager.invalidate_refs();
dp.dp_schema_id.to_string(this->alv_schema_buffer);
@ -84,13 +82,13 @@ public:
schema_ref.share(this->alv_schema_manager,
this->alv_schema_buffer,
data_parser::schema_id_t::STRING_SIZE - 1);
values.push_back({this->alv_schema_name, schema_ref, 2});
values.emplace_back(this->alv_schema_name, schema_ref, 2);
}
bool is_valid(log_cursor &lc, logfile_sub_source &lss) {
content_line_t cl(lss.at(lc.lc_curr_line));
std::shared_ptr<logfile> lf = lss.find(cl);
logfile::iterator lf_iter = lf->begin() + cl;
auto lf_iter = lf->begin() + cl;
if (lf_iter->is_continued()) {
return false;
@ -109,7 +107,7 @@ public:
content_line_t cl(lss.at(lc.lc_curr_line));
std::shared_ptr<logfile> lf = lss.find(cl);
logfile::iterator lf_iter = lf->begin() + cl;
auto lf_iter = lf->begin() + cl;
if (lf_iter->is_continued()) {
return false;

View File

@ -99,7 +99,7 @@ void scrub_ansi_string(std::string &str, string_attrs_t &sa)
break;
}
}
lpc = str.find(";", lpc);
lpc = str.find(';', lpc);
if (lpc != string::npos) {
lpc += 1;
}

View File

@ -1,3 +1,5 @@
#include <utility>
/**
* Copyright (c) 2017, Timothy Stack
*
@ -288,7 +290,7 @@ rfind_string_attr_if(const string_attrs_t &sa, ssize_t near, T predicate)
inline struct line_range
find_string_attr_range(const string_attrs_t &sa, string_attr_type_t type)
{
string_attrs_t::const_iterator iter = find_string_attr(sa, type);
auto iter = find_string_attr(sa, type);
if (iter != sa.end()) {
return iter->sa_range;
@ -321,8 +323,8 @@ inline void remove_string_attr(string_attrs_t &sa, string_attr_type_t type)
inline void shift_string_attrs(string_attrs_t &sa, int32_t start, int32_t amount)
{
for (string_attrs_t::iterator iter = sa.begin(); iter != sa.end(); ++iter) {
iter->sa_range.shift(start, amount);
for (auto &iter : sa) {
iter.sa_range.shift(start, amount);
}
}
@ -352,7 +354,7 @@ public:
this->al_attrs.reserve(RESERVE_SIZE);
};
attr_line_t(const std::string &str) : al_string(str) {
attr_line_t(std::string str) : al_string(std::move(str)) {
this->al_attrs.reserve(RESERVE_SIZE);
};
@ -456,11 +458,9 @@ public:
long padding = width - this->length();
if (padding > 0) {
this->al_string.insert(0, padding, ' ');
for (std::vector<string_attr>::iterator iter = this->al_attrs.begin();
iter != this->al_attrs.end();
++iter) {
iter->sa_range.lr_start += padding;
iter->sa_range.lr_end += padding;
for (auto &al_attr : this->al_attrs) {
al_attr.sa_range.lr_start += padding;
al_attr.sa_range.lr_end += padding;
}
}
@ -470,12 +470,10 @@ public:
ssize_t length() const {
size_t retval = this->al_string.length();
for (std::vector<string_attr>::const_iterator iter = this->al_attrs.begin();
iter != this->al_attrs.end();
++iter) {
retval = std::max(retval, (size_t) iter->sa_range.lr_start);
if (iter->sa_range.lr_end != -1) {
retval = std::max(retval, (size_t) iter->sa_range.lr_end);
for (const auto &al_attr : this->al_attrs) {
retval = std::max(retval, (size_t) al_attr.sa_range.lr_start);
if (al_attr.sa_range.lr_end != -1) {
retval = std::max(retval, (size_t) al_attr.sa_range.lr_end);
}
}

View File

@ -36,40 +36,3 @@
using namespace std;
set<string> bookmark_metadata::KNOWN_TAGS;
template<typename LineType>
LineType bookmark_vector<LineType>::next(LineType start) const
{
LineType retval(-1);
require(start >= -1);
auto ub = upper_bound(this->cbegin(), this->cend(), start);
if (ub != this->cend()) {
retval = *ub;
}
ensure(retval == -1 || start < retval);
return retval;
}
template<typename LineType>
LineType bookmark_vector<LineType>::prev(LineType start) const
{
LineType retval(-1);
require(start >= 0);
auto lb = lower_bound(this->cbegin(), this->cend(), start);
if (lb != this->cbegin()) {
lb -= 1;
retval = *lb;
}
ensure(retval < start);
return retval;
}
template class bookmark_vector<vis_line_t>;

View File

@ -1,3 +1,5 @@
#include <utility>
/**
* Copyright (c) 2007-2012, Timothy Stack
*
@ -39,7 +41,6 @@
#include <algorithm>
#include "lnav_log.hh"
#include "listview_curses.hh"
struct bookmark_metadata {
static std::set<std::string> KNOWN_TAGS;
@ -190,7 +191,7 @@ public:
return all_types;
};
bookmark_type_t(const std::string &name) : bt_name(name) {
bookmark_type_t(std::string name) : bt_name(std::move(name)) {
get_all_types().push_back(this);
};
@ -212,6 +213,41 @@ private:
const std::string bt_name;
};
template<typename LineType>
LineType bookmark_vector<LineType>::next(LineType start) const
{
LineType retval(-1);
require(start >= -1);
auto ub = upper_bound(this->cbegin(), this->cend(), start);
if (ub != this->cend()) {
retval = *ub;
}
ensure(retval == -1 || start < retval);
return retval;
}
template<typename LineType>
LineType bookmark_vector<LineType>::prev(LineType start) const
{
LineType retval(-1);
require(start >= 0);
auto lb = lower_bound(this->cbegin(), this->cend(), start);
if (lb != this->cbegin()) {
lb -= 1;
retval = *lb;
}
ensure(retval < start);
return retval;
}
/**
* Map of bookmark types to bookmark vectors.
*/
@ -220,6 +256,4 @@ struct bookmarks {
typedef std::map<bookmark_type_t *, bookmark_vector<LineType> > type;
};
typedef bookmarks<vis_line_t>::type
vis_bookmarks;
#endif

View File

@ -35,7 +35,7 @@
#include "grep_proc.hh"
#include "textview_curses.hh"
#include "logfile_sub_source.hh"
#include "status_controllers.hh"
#include "statusview_curses.hh"
class bottom_status_source
: public status_data_source,

View File

@ -59,7 +59,7 @@ struct byte_array {
return memcmp(this->ba_data, other.ba_data, BYTE_COUNT) != 0;
};
void clear(void)
void clear()
{
memset(this->ba_data, 0, BYTE_COUNT);
};

View File

@ -40,6 +40,7 @@
#include "command_executor.hh"
#include "db_sub_source.hh"
#include "papertrail_proc.hh"
using namespace std;
@ -512,10 +513,8 @@ string execute_file(exec_context &ec, const string &path_and_args, bool multilin
}
if (!paths_to_exec.empty()) {
for (vector<script_metadata>::iterator path_iter = paths_to_exec.begin();
path_iter != paths_to_exec.end();
++path_iter) {
result = execute_file_contents(ec, path_iter->sm_path, multiline);
for (auto &path_iter : paths_to_exec) {
result = execute_file_contents(ec, path_iter.sm_path, multiline);
}
retval = result;
}
@ -644,7 +643,7 @@ void execute_init_commands(exec_context &ec, vector<pair<string, string> > &msgs
break;
}
msgs.push_back(make_pair(msg, alt_msg));
msgs.emplace_back(msg, alt_msg);
if (rescan_files()) {
rebuild_indexes(true);
@ -715,7 +714,7 @@ int sql_callback(exec_context &ec, sqlite3_stmt *stmt)
const char *value = (const char *)sqlite3_column_text(stmt, lpc);
dls.push_column(value);
if (value != NULL &&
if (value != nullptr &&
(dls.dls_headers[lpc].hm_name == "log_line" ||
strstr(dls.dls_headers[lpc].hm_name.c_str(), "log_line"))) {
int line_number = -1;
@ -745,7 +744,7 @@ future<string> pipe_callback(exec_context &ec, const string &cmdline, auto_fd &f
.with_fd(pp->get_fd())
.with_detect_format(false);
lnav_data.ld_files_to_front.emplace_back(desc, 0);
if (lnav_data.ld_rl_view != NULL) {
if (lnav_data.ld_rl_view != nullptr) {
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
X, "to close the file"));
}

View File

@ -29,6 +29,347 @@
#include "config.h"
#include "json_ptr.hh"
#include "db_sub_source.hh"
const char *db_label_source::NULL_STR = "<NULL>";
void db_label_source::text_value_for_line(textview_curses &tc, int row,
std::string &label_out,
text_sub_source::line_flags_t flags)
{
/*
* start_value is the result rowid, each bucket type is a column value
* label_out should be the raw text output.
*/
label_out.clear();
if (row >= (int)this->dls_rows.size()) {
return;
}
for (int lpc = 0; lpc < (int)this->dls_rows[row].size(); lpc++) {
int padding = (this->dls_headers[lpc].hm_column_size -
strlen(this->dls_rows[row][lpc]) -
1);
if (this->dls_headers[lpc].hm_column_type != SQLITE3_TEXT) {
label_out.append(padding, ' ');
}
label_out.append(this->dls_rows[row][lpc]);
if (this->dls_headers[lpc].hm_column_type == SQLITE3_TEXT) {
label_out.append(padding, ' ');
}
label_out.append(1, ' ');
}
}
void db_label_source::text_attrs_for_line(textview_curses &tc, int row,
string_attrs_t &sa)
{
struct line_range lr(0, 0);
struct line_range lr2(0, -1);
if (row >= (int)this->dls_rows.size()) {
return;
}
for (size_t lpc = 0; lpc < this->dls_headers.size() - 1; lpc++) {
if (row % 2 == 0) {
sa.push_back(string_attr(lr2, &view_curses::VC_STYLE, A_BOLD));
}
lr.lr_start += this->dls_headers[lpc].hm_column_size - 1;
lr.lr_end = lr.lr_start + 1;
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_VLINE));
lr.lr_start += 1;
}
int left = 0;
for (size_t lpc = 0; lpc < this->dls_headers.size(); lpc++) {
const char *row_value = this->dls_rows[row][lpc];
size_t row_len = strlen(row_value);
if (this->dls_headers[lpc].hm_graphable) {
double num_value;
if (sscanf(row_value, "%lf", &num_value) == 1) {
this->dls_chart.chart_attrs_for_value(tc, left, this->dls_headers[lpc].hm_name, num_value, sa);
}
}
if (row_len > 2 &&
((row_value[0] == '{' && row_value[row_len - 1] == '}') ||
(row_value[0] == '[' && row_value[row_len - 1] == ']'))) {
json_ptr_walk jpw;
if (jpw.parse(row_value, row_len) == yajl_status_ok &&
jpw.complete_parse() == yajl_status_ok) {
for (auto &jpw_value : jpw.jpw_values) {
double num_value;
if (jpw_value.wt_type == yajl_t_number &&
sscanf(jpw_value.wt_value.c_str(), "%lf", &num_value) == 1) {
this->dls_chart.chart_attrs_for_value(tc, left,
jpw_value.wt_ptr, num_value, sa);
}
}
}
}
}
}
void db_label_source::push_header(const std::string &colstr, int type,
bool graphable)
{
this->dls_headers.emplace_back(colstr);
header_meta &hm = this->dls_headers.back();
hm.hm_column_size = colstr.length() + 1;
hm.hm_column_type = type;
hm.hm_graphable = graphable;
if (colstr == "log_time") {
this->dls_time_column_index = this->dls_headers.size() - 1;
}
}
void db_label_source::push_column(const char *colstr)
{
view_colors &vc = view_colors::singleton();
int index = this->dls_rows.back().size();
double num_value = 0.0;
size_t value_len;
if (colstr == nullptr) {
value_len = 0;
}
else {
value_len = strlen(colstr);
}
if (colstr == nullptr) {
colstr = NULL_STR;
}
else {
colstr = strdup(colstr);
if (colstr == nullptr) {
throw "out of memory";
}
}
if (index == this->dls_time_column_index) {
date_time_scanner dts;
struct timeval tv;
if (!dts.convert_to_timeval(colstr, -1, nullptr, tv)) {
tv.tv_sec = -1;
tv.tv_usec = -1;
}
if (!this->dls_time_column.empty() && tv < this->dls_time_column.back()) {
this->dls_time_column_index = -1;
this->dls_time_column.clear();
}
else {
this->dls_time_column.push_back(tv);
}
}
this->dls_rows.back().push_back(colstr);
this->dls_headers[index].hm_column_size =
std::max(this->dls_headers[index].hm_column_size, strlen(colstr) + 1);
if (colstr != nullptr && this->dls_headers[index].hm_graphable) {
if (sscanf(colstr, "%lf", &num_value) != 1) {
num_value = 0.0;
}
this->dls_chart.add_value(this->dls_headers[index].hm_name, num_value);
}
else if (value_len > 2 &&
((colstr[0] == '{' && colstr[value_len - 1] == '}') ||
(colstr[0] == '[' && colstr[value_len - 1] == ']'))) {
json_ptr_walk jpw;
if (jpw.parse(colstr, value_len) == yajl_status_ok &&
jpw.complete_parse() == yajl_status_ok) {
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
iter != jpw.jpw_values.end();
++iter) {
if (iter->wt_type == yajl_t_number &&
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
this->dls_chart.add_value(iter->wt_ptr, num_value);
this->dls_chart.with_attrs_for_ident(
iter->wt_ptr, vc.attrs_for_ident(iter->wt_ptr));
}
}
}
}
}
void db_label_source::clear()
{
this->dls_chart.clear();
this->dls_headers.clear();
for (size_t row = 0; row < this->dls_rows.size(); row++) {
for (size_t col = 0; col < this->dls_rows[row].size(); col++) {
if (this->dls_rows[row][col] != NULL_STR) {
free((void *)this->dls_rows[row][col]);
}
}
}
this->dls_rows.clear();
this->dls_time_column.clear();
}
size_t db_overlay_source::list_overlay_count(const listview_curses &lv)
{
size_t retval = 1;
if (!this->dos_active || lv.get_inner_height() == 0) {
this->dos_lines.clear();
return retval;
}
view_colors &vc = view_colors::singleton();
vis_line_t top = lv.get_top();
const std::vector<const char *> &cols = this->dos_labels->dls_rows[top];
unsigned long width;
vis_line_t height;
lv.get_dimensions(height, width);
this->dos_lines.clear();
for (size_t col = 0; col < cols.size(); col++) {
const char *col_value = cols[col];
size_t col_len = strlen(col_value);
if (!(col_len >= 2 &&
((col_value[0] == '{' && col_value[col_len - 1] == '}') ||
(col_value[0] == '[' && col_value[col_len - 1] == ']')))) {
continue;
}
json_ptr_walk jpw;
if (jpw.parse(col_value, col_len) == yajl_status_ok &&
jpw.complete_parse() == yajl_status_ok) {
{
const std::string &header = this->dos_labels->dls_headers[col].hm_name;
this->dos_lines.emplace_back(" JSON Column: " + header);
retval += 1;
}
stacked_bar_chart<std::string> chart;
int start_line = this->dos_lines.size();
chart.with_stacking_enabled(false)
.with_margins(3, 0);
for (auto &jpw_value : jpw.jpw_values) {
this->dos_lines.push_back(" " + jpw_value.wt_ptr + " = " +
jpw_value.wt_value);
string_attrs_t &sa = this->dos_lines.back().get_attrs();
struct line_range lr(1, 2);
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_LTEE));
lr.lr_start = 3 + jpw_value.wt_ptr.size() + 3;
lr.lr_end = -1;
sa.push_back(string_attr(lr, &view_curses::VC_STYLE, A_BOLD));
double num_value = 0.0;
if (jpw_value.wt_type == yajl_t_number &&
sscanf(jpw_value.wt_value.c_str(), "%lf", &num_value) == 1) {
int attrs = vc.attrs_for_ident(jpw_value.wt_ptr);
chart.add_value(jpw_value.wt_ptr, num_value);
chart.with_attrs_for_ident(jpw_value.wt_ptr, attrs);
}
retval += 1;
}
int curr_line = start_line;
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
iter != jpw.jpw_values.end();
++iter, curr_line++) {
double num_value = 0.0;
if (iter->wt_type == yajl_t_number &&
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
string_attrs_t &sa = this->dos_lines[curr_line].get_attrs();
int left = 3;
chart.chart_attrs_for_value(lv, left, iter->wt_ptr, num_value, sa);
}
}
}
}
if (retval > 1) {
this->dos_lines.emplace_back("");
string_attrs_t &sa = this->dos_lines.back().get_attrs();
struct line_range lr(1, 2);
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_LLCORNER));
lr.lr_start = 2;
lr.lr_end = -1;
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_HLINE));
retval += 1;
}
return retval;
}
bool db_overlay_source::list_value_for_overlay(const listview_curses &lv, int y,
int bottom, vis_line_t row,
attr_line_t &value_out)
{
view_colors &vc = view_colors::singleton();
if (y == 0) {
this->list_overlay_count(lv);
std::string &line = value_out.get_string();
db_label_source *dls = this->dos_labels;
string_attrs_t &sa = value_out.get_attrs();
for (size_t lpc = 0;
lpc < this->dos_labels->dls_headers.size();
lpc++) {
int before, total_fill =
dls->dls_headers[lpc].hm_column_size -
dls->dls_headers[lpc].hm_name.length();
struct line_range header_range(line.length(),
line.length() +
dls->dls_headers[lpc].hm_column_size);
int attrs =
vc.attrs_for_ident(dls->dls_headers[lpc].hm_name) | A_REVERSE;
if (!this->dos_labels->dls_headers[lpc].hm_graphable) {
attrs = A_UNDERLINE;
}
sa.push_back(string_attr(header_range, &view_curses::VC_STYLE,
attrs));
before = total_fill / 2;
total_fill -= before;
line.append(before, ' ');
line.append(dls->dls_headers[lpc].hm_name);
line.append(total_fill, ' ');
}
struct line_range lr(0);
sa.push_back(string_attr(lr, &view_curses::VC_STYLE,
A_BOLD | A_UNDERLINE));
return true;
}
else if (this->dos_active && y >= 2 && ((size_t) y) < (this->dos_lines.size() + 2)) {
value_out = this->dos_lines[y - 2];
return true;
}
return false;
}

View File

@ -1,3 +1,5 @@
#include <utility>
/**
* Copyright (c) 2007-2012, Timothy Stack
*
@ -35,10 +37,10 @@
#include <iterator>
#include <algorithm>
#include "json_ptr.hh"
#include "listview_curses.hh"
#include <sqlite3.h>
#include "textview_curses.hh"
#include "hist_source.hh"
#include "log_vtab_impl.hh"
class db_label_source : public text_sub_source, public text_time_translator {
public:
@ -63,10 +65,8 @@ public:
size_t text_line_width(textview_curses &curses) {
size_t retval = 0;
for (std::vector<header_meta>::iterator iter = this->dls_headers.begin();
iter != this->dls_headers.end();
++iter) {
retval += iter->hm_column_size;
for (auto &dls_header : this->dls_headers) {
retval += dls_header.hm_column_size;
}
return retval;
};
@ -74,186 +74,17 @@ public:
void text_value_for_line(textview_curses &tc,
int row,
std::string &label_out,
line_flags_t flags)
{
/*
* start_value is the result rowid, each bucket type is a column value
* label_out should be the raw text output.
*/
line_flags_t flags);
label_out.clear();
if (row >= (int)this->dls_rows.size()) {
return;
}
for (int lpc = 0; lpc < (int)this->dls_rows[row].size();
lpc++) {
int padding = (this->dls_headers[lpc].hm_column_size -
strlen(this->dls_rows[row][lpc]) -
1);
void text_attrs_for_line(textview_curses &tc, int row, string_attrs_t &sa);
if (this->dls_headers[lpc].hm_column_type != SQLITE3_TEXT) {
label_out.append(padding, ' ');
}
label_out.append(this->dls_rows[row][lpc]);
if (this->dls_headers[lpc].hm_column_type == SQLITE3_TEXT) {
label_out.append(padding, ' ');
}
label_out.append(1, ' ');
}
};
void text_attrs_for_line(textview_curses &tc, int row, string_attrs_t &sa)
{
struct line_range lr(0, 0);
struct line_range lr2(0, -1);
if (row >= (int)this->dls_rows.size()) {
return;
}
for (size_t lpc = 0; lpc < this->dls_headers.size() - 1; lpc++) {
if (row % 2 == 0) {
sa.push_back(string_attr(lr2, &view_curses::VC_STYLE, A_BOLD));
}
lr.lr_start += this->dls_headers[lpc].hm_column_size - 1;
lr.lr_end = lr.lr_start + 1;
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_VLINE));
lr.lr_start += 1;
}
int left = 0;
for (size_t lpc = 0; lpc < this->dls_headers.size(); lpc++) {
const char *row_value = this->dls_rows[row][lpc];
size_t row_len = strlen(row_value);
if (this->dls_headers[lpc].hm_graphable) {
double num_value;
if (sscanf(row_value, "%lf", &num_value) == 1) {
this->dls_chart.chart_attrs_for_value(tc, left, this->dls_headers[lpc].hm_name, num_value, sa);
}
}
if (row_len > 2 &&
((row_value[0] == '{' && row_value[row_len - 1] == '}') ||
(row_value[0] == '[' && row_value[row_len - 1] == ']'))) {
json_ptr_walk jpw;
if (jpw.parse(row_value, row_len) == yajl_status_ok &&
jpw.complete_parse() == yajl_status_ok) {
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
iter != jpw.jpw_values.end();
++iter) {
double num_value;
if (iter->wt_type == yajl_t_number &&
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
this->dls_chart.chart_attrs_for_value(tc, left, iter->wt_ptr, num_value, sa);
}
}
}
}
}
}
void push_header(const std::string &colstr, int type, bool graphable)
{
this->dls_headers.push_back(header_meta(colstr));
header_meta &hm = this->dls_headers.back();
hm.hm_column_size = colstr.length() + 1;
hm.hm_column_type = type;
hm.hm_graphable = graphable;
if (colstr == "log_time") {
this->dls_time_column_index = this->dls_headers.size() - 1;
}
}
void push_header(const std::string &colstr, int type, bool graphable);
/* TODO: add support for left and right justification... numbers should */
/* be right justified and strings should be left. */
void push_column(const char *colstr)
{
view_colors &vc = view_colors::singleton();
int index = this->dls_rows.back().size();
double num_value = 0.0;
size_t value_len;
void push_column(const char *colstr);
if (colstr == NULL) {
value_len = 0;
}
else {
value_len = strlen(colstr);
}
if (colstr == NULL) {
colstr = NULL_STR;
}
else {
colstr = strdup(colstr);
if (colstr == NULL) {
throw "out of memory";
}
}
if (index == this->dls_time_column_index) {
date_time_scanner dts;
struct timeval tv;
if (!dts.convert_to_timeval(colstr, -1, NULL, tv)) {
tv.tv_sec = -1;
tv.tv_usec = -1;
}
if (!this->dls_time_column.empty() && tv < this->dls_time_column.back()) {
this->dls_time_column_index = -1;
this->dls_time_column.clear();
}
else {
this->dls_time_column.push_back(tv);
}
}
this->dls_rows.back().push_back(colstr);
this->dls_headers[index].hm_column_size =
std::max(this->dls_headers[index].hm_column_size, strlen(colstr) + 1);
if (colstr != NULL && this->dls_headers[index].hm_graphable) {
if (sscanf(colstr, "%lf", &num_value) != 1) {
num_value = 0.0;
}
this->dls_chart.add_value(this->dls_headers[index].hm_name, num_value);
}
else if (value_len > 2 &&
((colstr[0] == '{' && colstr[value_len - 1] == '}') ||
(colstr[0] == '[' && colstr[value_len - 1] == ']'))) {
json_ptr_walk jpw;
if (jpw.parse(colstr, value_len) == yajl_status_ok &&
jpw.complete_parse() == yajl_status_ok) {
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
iter != jpw.jpw_values.end();
++iter) {
if (iter->wt_type == yajl_t_number &&
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
this->dls_chart.add_value(iter->wt_ptr, num_value);
this->dls_chart.with_attrs_for_ident(
iter->wt_ptr, vc.attrs_for_ident(iter->wt_ptr));
}
}
}
}
};
void clear(void) {
this->dls_chart.clear();
this->dls_headers.clear();
for (size_t row = 0; row < this->dls_rows.size(); row++) {
for (size_t col = 0; col < this->dls_rows[row].size(); col++) {
if (this->dls_rows[row][col] != NULL_STR) {
free((void *)this->dls_rows[row][col]);
}
}
}
this->dls_rows.clear();
this->dls_time_column.clear();
};
void clear();
long column_name_to_index(const std::string &name) const {
std::vector<header_meta>::const_iterator iter;
@ -289,8 +120,8 @@ public:
};
struct header_meta {
header_meta(const std::string &name)
: hm_name(name),
header_meta(std::string name)
: hm_name(std::move(name)),
hm_column_type(SQLITE3_TEXT),
hm_graphable(false),
hm_log_time(false),
@ -320,169 +151,16 @@ public:
class db_overlay_source : public list_overlay_source {
public:
db_overlay_source() : dos_active(false), dos_labels(NULL) {
db_overlay_source() : dos_active(false), dos_labels(nullptr) {
};
size_t list_overlay_count(const listview_curses &lv)
{
size_t retval = 1;
if (!this->dos_active || lv.get_inner_height() == 0) {
this->dos_lines.clear();
return retval;
}
view_colors &vc = view_colors::singleton();
vis_line_t top = lv.get_top();
const std::vector<const char *> &cols = this->dos_labels->dls_rows[top];
unsigned long width;
vis_line_t height;
lv.get_dimensions(height, width);
this->dos_lines.clear();
for (size_t col = 0; col < cols.size(); col++) {
const char *col_value = cols[col];
size_t col_len = strlen(col_value);
if (!(col_len >= 2 &&
((col_value[0] == '{' && col_value[col_len - 1] == '}') ||
(col_value[0] == '[' && col_value[col_len - 1] == ']')))) {
continue;
}
json_ptr_walk jpw;
if (jpw.parse(col_value, col_len) == yajl_status_ok &&
jpw.complete_parse() == yajl_status_ok) {
{
const std::string &header = this->dos_labels->dls_headers[col].hm_name;
this->dos_lines.push_back(" JSON Column: " + header);
retval += 1;
}
stacked_bar_chart<std::string> chart;
int start_line = this->dos_lines.size();
chart.with_stacking_enabled(false)
.with_margins(3, 0);
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
iter != jpw.jpw_values.end();
++iter) {
this->dos_lines.push_back(" " + iter->wt_ptr + " = " + iter->wt_value);
string_attrs_t &sa = this->dos_lines.back().get_attrs();
struct line_range lr(1, 2);
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_LTEE));
lr.lr_start = 3 + iter->wt_ptr.size() + 3;
lr.lr_end = -1;
sa.push_back(string_attr(lr, &view_curses::VC_STYLE, A_BOLD));
double num_value = 0.0;
if (iter->wt_type == yajl_t_number &&
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
int attrs = vc.attrs_for_ident(iter->wt_ptr);
chart.add_value(iter->wt_ptr, num_value);
chart.with_attrs_for_ident(iter->wt_ptr, attrs);
}
retval += 1;
}
int curr_line = start_line;
for (json_ptr_walk::walk_list_t::iterator iter = jpw.jpw_values.begin();
iter != jpw.jpw_values.end();
++iter, curr_line++) {
double num_value = 0.0;
if (iter->wt_type == yajl_t_number &&
sscanf(iter->wt_value.c_str(), "%lf", &num_value) == 1) {
string_attrs_t &sa = this->dos_lines[curr_line].get_attrs();
int left = 3;
chart.chart_attrs_for_value(lv, left, iter->wt_ptr, num_value, sa);
}
}
}
}
if (retval > 1) {
this->dos_lines.push_back("");
string_attrs_t &sa = this->dos_lines.back().get_attrs();
struct line_range lr(1, 2);
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_LLCORNER));
lr.lr_start = 2;
lr.lr_end = -1;
sa.push_back(string_attr(lr, &view_curses::VC_GRAPHIC, ACS_HLINE));
retval += 1;
}
return retval;
};
size_t list_overlay_count(const listview_curses &lv);
bool list_value_for_overlay(const listview_curses &lv,
int y, int bottom,
vis_line_t row,
attr_line_t &value_out)
{
view_colors &vc = view_colors::singleton();
if (y == 0) {
this->list_overlay_count(lv);
std::string &line = value_out.get_string();
db_label_source *dls = this->dos_labels;
string_attrs_t &sa = value_out.get_attrs();
for (size_t lpc = 0;
lpc < this->dos_labels->dls_headers.size();
lpc++) {
int before, total_fill =
dls->dls_headers[lpc].hm_column_size -
dls->dls_headers[lpc].hm_name.length();
struct line_range header_range(line.length(),
line.length() +
dls->dls_headers[lpc].hm_column_size);
int attrs =
vc.attrs_for_ident(dls->dls_headers[lpc].hm_name) | A_REVERSE;
if (!this->dos_labels->dls_headers[lpc].hm_graphable) {
attrs = A_UNDERLINE;
}
sa.push_back(string_attr(header_range, &view_curses::VC_STYLE,
attrs));
before = total_fill / 2;
total_fill -= before;
line.append(before, ' ');
line.append(dls->dls_headers[lpc].hm_name);
line.append(total_fill, ' ');
}
struct line_range lr(0);
sa.push_back(string_attr(lr, &view_curses::VC_STYLE,
A_BOLD | A_UNDERLINE));
return true;
}
else if (this->dos_active && y >= 2 && ((size_t) y) < (this->dos_lines.size() + 2)) {
value_out = this->dos_lines[y - 2];
return true;
}
return false;
};
attr_line_t &value_out);
bool dos_active;
db_label_source *dos_labels;

View File

@ -32,7 +32,6 @@
#include <string>
#include "lnav_config.hh"
#include "statusview_curses.hh"
class doc_status_source

View File

@ -88,10 +88,8 @@ void map_elements_to_json2(yajl_gen gen, data_parser &dp, data_parser::element_l
yajlpp_map root_map(gen);
int col = 0;
for (data_parser::element_list_t::iterator iter = el->begin();
iter != el->end();
++iter) {
const data_parser::element &pvalue = iter->get_pair_value();
for (auto &iter : *el) {
const data_parser::element &pvalue = iter.get_pair_value();
if (pvalue.value_token() == DT_INVALID) {
log_debug("invalid!!");
@ -99,7 +97,7 @@ void map_elements_to_json2(yajl_gen gen, data_parser &dp, data_parser::element_l
}
std::string key_str = dp.get_element_string(
iter->e_sub_elements->front());
iter.e_sub_elements->front());
if (key_str.empty()) {
char buffer[32];
@ -116,10 +114,8 @@ void map_elements_to_json2(yajl_gen gen, data_parser &dp, data_parser::element_l
static
void list_body_elements_to_json(yajl_gen gen, data_parser &dp, data_parser::element_list_t *el)
{
for (data_parser::element_list_t::iterator iter = el->begin();
iter != el->end();
++iter) {
element_to_json(gen, dp, *iter);
for (auto &iter : *el) {
element_to_json(gen, dp, iter);
}
}
@ -137,10 +133,8 @@ void map_elements_to_json(yajl_gen gen, data_parser &dp, data_parser::element_li
bool unique_names = el->size() > 1;
vector<string> names;
for (data_parser::element_list_t::iterator iter = el->begin();
iter != el->end();
++iter) {
const data_parser::element &pvalue = iter->get_pair_value();
for (auto &iter : *el) {
const data_parser::element &pvalue = iter.get_pair_value();
if (pvalue.value_token() == DT_INVALID) {
log_debug("invalid!!");
@ -148,7 +142,7 @@ void map_elements_to_json(yajl_gen gen, data_parser &dp, data_parser::element_li
}
std::string key_str = dp.get_element_string(
iter->e_sub_elements->front());
iter.e_sub_elements->front());
if (key_str.empty()) {
continue;
}

View File

@ -32,7 +32,6 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <glob.h>
#include <grp.h>

View File

@ -262,7 +262,7 @@ public:
void check_poll_set(const std::vector<struct pollfd> &pollfds);
/** Check the invariants for this object. */
bool invariant(void)
bool invariant()
{
require(this->gp_code != NULL);
if (this->gp_child_started) {

View File

@ -35,3 +35,75 @@
using namespace std;
const char *hist_source2::LINE_FORMAT = " %8d normal %8d errors %8d warnings %8d marks";
int hist_source2::row_for_time(struct timeval tv_bucket)
{
std::map<int64_t, struct bucket_block>::iterator iter;
int retval = 0;
time_t time_bucket = rounddown(tv_bucket.tv_sec, this->hs_time_slice);
for (iter = this->hs_blocks.begin();
iter != this->hs_blocks.end();
++iter) {
struct bucket_block &bb = iter->second;
if (time_bucket < bb.bb_buckets[0].b_time) {
break;
}
if (time_bucket > bb.bb_buckets[bb.bb_used].b_time) {
retval += bb.bb_used + 1;
continue;
}
for (unsigned int lpc = 0; lpc <= bb.bb_used; lpc++, retval++) {
if (time_bucket <= bb.bb_buckets[lpc].b_time) {
return retval;
}
}
}
return retval;
}
void hist_source2::text_value_for_line(textview_curses &tc, int row,
std::string &value_out,
text_sub_source::line_flags_t flags)
{
bucket_t &bucket = this->find_bucket(row);
struct tm bucket_tm;
char tm_buffer[128];
char line[256];
if (gmtime_r(&bucket.b_time, &bucket_tm) != NULL) {
strftime(tm_buffer, sizeof(tm_buffer),
" %a %b %d %H:%M:%S ",
&bucket_tm);
}
else {
log_error("no time?");
tm_buffer[0] = '\0';
}
snprintf(line, sizeof(line),
LINE_FORMAT,
(int) rint(bucket.b_values[HT_NORMAL].hv_value),
(int) rint(bucket.b_values[HT_ERROR].hv_value),
(int) rint(bucket.b_values[HT_WARNING].hv_value),
(int) rint(bucket.b_values[HT_MARK].hv_value));
value_out.clear();
value_out.append(tm_buffer);
value_out.append(line);
}
void hist_source2::text_attrs_for_line(textview_curses &tc, int row,
string_attrs_t &value_out)
{
bucket_t &bucket = this->find_bucket(row);
int left = 0;
for (int lpc = 0; lpc < HT__MAX; lpc++) {
this->hs_chart.chart_attrs_for_value(
tc, left, (const hist_type_t) lpc,
bucket.b_values[lpc].hv_value,
value_out);
}
}

View File

@ -44,8 +44,6 @@
#include "strong_int.hh"
#include "textview_curses.hh"
typedef float bucket_count_t;
/** Type for indexes into a group of buckets. */
STRONG_INT_TYPE(int, bucket_group);
@ -233,9 +231,8 @@ public:
lr.lr_end = left = lr.lr_start + amount;
if (ci.ci_attrs != 0) {
value_out.push_back(string_attr(lr,
&view_curses::VC_STYLE,
ci.ci_attrs | A_REVERSE));
value_out.emplace_back(
lr, &view_curses::VC_STYLE, ci.ci_attrs | A_REVERSE);
}
};
@ -403,46 +400,11 @@ public:
void text_value_for_line(textview_curses &tc,
int row,
std::string &value_out,
line_flags_t flags) {
bucket_t &bucket = this->find_bucket(row);
struct tm bucket_tm;
char tm_buffer[128];
char line[256];
if (gmtime_r(&bucket.b_time, &bucket_tm) != NULL) {
strftime(tm_buffer, sizeof(tm_buffer),
" %a %b %d %H:%M:%S ",
&bucket_tm);
}
else {
log_error("no time?");
tm_buffer[0] = '\0';
}
snprintf(line, sizeof(line),
LINE_FORMAT,
(int) rint(bucket.b_values[HT_NORMAL].hv_value),
(int) rint(bucket.b_values[HT_ERROR].hv_value),
(int) rint(bucket.b_values[HT_WARNING].hv_value),
(int) rint(bucket.b_values[HT_MARK].hv_value));
value_out.clear();
value_out.append(tm_buffer);
value_out.append(line);
};
line_flags_t flags);;
void text_attrs_for_line(textview_curses &tc,
int row,
string_attrs_t &value_out) {
bucket_t &bucket = this->find_bucket(row);
int left = 0;
for (int lpc = 0; lpc < HT__MAX; lpc++) {
this->hs_chart.chart_attrs_for_value(
tc, left, (const hist_type_t) lpc,
bucket.b_values[lpc].hv_value,
value_out);
}
};
string_attrs_t &value_out);;
size_t text_size_for_line(textview_curses &tc, int row, line_flags_t flags) {
return 0;
@ -457,32 +419,7 @@ public:
return { bucket.b_time, 0 };
};
int row_for_time(struct timeval tv_bucket) {
std::map<int64_t, struct bucket_block>::iterator iter;
int retval = 0;
time_t time_bucket = rounddown(tv_bucket.tv_sec, this->hs_time_slice);
for (iter = this->hs_blocks.begin();
iter != this->hs_blocks.end();
++iter) {
struct bucket_block &bb = iter->second;
if (time_bucket < bb.bb_buckets[0].b_time) {
break;
}
if (time_bucket > bb.bb_buckets[bb.bb_used].b_time) {
retval += bb.bb_used + 1;
continue;
}
for (unsigned int lpc = 0; lpc <= bb.bb_used; lpc++, retval++) {
if (time_bucket <= bb.bb_buckets[lpc].b_time) {
return retval;
}
}
}
return retval;
};
int row_for_time(struct timeval tv_bucket);;
private:
static const char *LINE_FORMAT;

View File

@ -31,6 +31,8 @@
#include "config.h"
#include "yajl/api/yajl_gen.h"
#include "json_op.hh"
#include "lnav_log.hh"

View File

@ -31,6 +31,8 @@
#include "config.h"
#include "yajl/api/yajl_gen.h"
#include "json_ptr.hh"
using namespace std;
@ -39,8 +41,7 @@ static int handle_null(void *ctx)
{
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
jpw->jpw_values.push_back(
json_ptr_walk::walk_triple(jpw->current_ptr(), yajl_t_null, "null"));
jpw->jpw_values.emplace_back(jpw->current_ptr(), yajl_t_null, "null");
jpw->inc_array_index();
return 1;
@ -50,10 +51,9 @@ static int handle_boolean(void *ctx, int boolVal)
{
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
jpw->jpw_values.push_back(
json_ptr_walk::walk_triple(jpw->current_ptr(),
boolVal ? yajl_t_true : yajl_t_false,
boolVal ? "true" : "false"));
jpw->jpw_values.emplace_back(jpw->current_ptr(),
boolVal ? yajl_t_true : yajl_t_false,
boolVal ? "true" : "false");
jpw->inc_array_index();
return 1;
@ -63,10 +63,9 @@ static int handle_number(void *ctx, const char *numberVal, size_t numberLen)
{
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
jpw->jpw_values.push_back(
json_ptr_walk::walk_triple(jpw->current_ptr(),
yajl_t_number,
string(numberVal, numberLen)));
jpw->jpw_values.emplace_back(jpw->current_ptr(),
yajl_t_number,
string(numberVal, numberLen));
jpw->inc_array_index();
return 1;
@ -85,11 +84,10 @@ static int handle_string(void *ctx, const unsigned char * stringVal, size_t len)
auto_mem<yajl_gen_t> gen(yajl_gen_free);
string str;
gen = yajl_gen_alloc(NULL);
gen = yajl_gen_alloc(nullptr);
yajl_gen_config(gen.in(), yajl_gen_print_callback, appender, &str);
yajl_gen_string(gen.in(), stringVal, len);
jpw->jpw_values.push_back(
json_ptr_walk::walk_triple(jpw->current_ptr(), yajl_t_string, str));
jpw->jpw_values.emplace_back(jpw->current_ptr(), yajl_t_string, str);
jpw->inc_array_index();
return 1;
@ -99,7 +97,7 @@ static int handle_start_map(void *ctx)
{
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
jpw->jpw_keys.push_back("");
jpw->jpw_keys.emplace_back("");
jpw->jpw_array_indexes.push_back(-1);
return 1;
@ -145,7 +143,7 @@ static int handle_start_array(void *ctx)
{
json_ptr_walk *jpw = (json_ptr_walk *)ctx;
jpw->jpw_keys.push_back("");
jpw->jpw_keys.emplace_back("");
jpw->jpw_array_indexes.push_back(0);
return 1;

View File

@ -1,3 +1,5 @@
#include <utility>
/**
* Copyright (c) 2014, Timothy Stack
*
@ -43,8 +45,6 @@
#include "auto_mem.hh"
#include "yajl/api/yajl_parse.h"
#include "yajl/api/yajl_tree.h"
#include "yajl/api/yajl_gen.h"
#include "lnav_log.hh"
class json_ptr_walk {
public:
@ -118,7 +118,8 @@ public:
struct walk_triple {
walk_triple(std::string ptr, yajl_type type, std::string value)
: wt_ptr(ptr), wt_type(type), wt_value(value) {
: wt_ptr(std::move(ptr)), wt_type(type), wt_value(
std::move(value)) {
};

View File

@ -67,7 +67,6 @@
#include <set>
#include <stack>
#include <vector>
#include <memory>
#include <fstream>
#include <sstream>
#include <iostream>
@ -296,7 +295,11 @@ bool setup_logline_table(exec_context &ec)
content_line_t cl = lnav_data.ld_log_source.at_base(vl);
lnav_data.ld_vtab_manager->unregister_vtab(logline);
lnav_data.ld_vtab_manager->register_vtab(new log_data_table(cl, logline));
lnav_data.ld_vtab_manager->register_vtab(
new log_data_table(lnav_data.ld_log_source,
*lnav_data.ld_vtab_manager,
cl,
logline));
if (update_possibilities) {
log_data_helper ldh(lnav_data.ld_log_source);

View File

@ -43,7 +43,6 @@
#include <stack>
#include <memory>
#include "byte_array.hh"
#include "logfile.hh"
#include "hist_source.hh"
#include "statusview_curses.hh"
@ -59,9 +58,7 @@
#include "xterm_mouse.hh"
#include "piper_proc.hh"
#include "term_extra.hh"
#include "ansi_scrubber.hh"
#include "curl_looper.hh"
#include "papertrail_proc.hh"
#include "relative_time.hh"
#include "log_format_loader.hh"
#include "spectro_source.hh"

View File

@ -56,6 +56,7 @@
#include "sysclip.hh"
#include "yajl/api/yajl_parse.h"
#include "db_sub_source.hh"
#include "papertrail_proc.hh"
using namespace std;
@ -1065,7 +1066,7 @@ public:
return this->pf_pcre.match(pc, pi);
};
std::string to_command(void) override {
std::string to_command() override {
return (this->lf_type == text_filter::INCLUDE ?
"filter-in " : "filter-out ") +
this->lf_id;
@ -1235,7 +1236,7 @@ static string com_disable_filter(exec_context &ec, string cmdline, vector<string
args[1] = remaining_args(cmdline, args);
lf = fs.get_filter(args[1]);
if (lf == NULL) {
if (lf == nullptr) {
retval = "error: no such filter -- " + args[1];
}
else if (!lf->is_enabled()) {
@ -1303,7 +1304,11 @@ static string com_create_logline_table(exec_context &ec, string cmdline, vector<
else {
vis_line_t vl = log_view.get_top();
content_line_t cl = lnav_data.ld_log_source.at_base(vl);
log_data_table *ldt = new log_data_table(cl, intern_string::lookup(args[1]));
log_data_table *ldt = new log_data_table(
lnav_data.ld_log_source,
*lnav_data.ld_vtab_manager,
cl,
intern_string::lookup(args[1]));
if (ec.ec_dry_run) {
attr_line_t al(ldt->get_table_statement());
@ -1648,7 +1653,7 @@ static string com_open(exec_context &ec, string cmdline, vector<string> &args)
lnav_data.ld_file_names[fn]
.with_fd(ul->copy_fd());
lnav_data.ld_curl_looper.add_request(ul.release());
lnav_data.ld_files_to_front.push_back(make_pair(fn, top));
lnav_data.ld_files_to_front.emplace_back(fn, top);
retval = "info: opened URL";
} else {
retval = "";
@ -1708,7 +1713,7 @@ static string com_open(exec_context &ec, string cmdline, vector<string> &args)
fn = abspath.in();
file_names[fn] = default_loo;
retval = "info: opened -- " + fn;
files_to_front.push_back(make_pair(fn, top));
files_to_front.emplace_back(fn, top);
closed_files.push_back(fn);
if (lnav_data.ld_rl_view != NULL) {
@ -2277,7 +2282,7 @@ static string com_summarize(exec_context &ec, string cmdline, vector<string> &ar
}
query = "SELECT";
for (std::vector<string>::iterator iter = other_columns.begin();
for (auto iter = other_columns.begin();
iter != other_columns.end();
++iter) {
if (iter != other_columns.begin()) {
@ -2294,7 +2299,7 @@ static string com_summarize(exec_context &ec, string cmdline, vector<string> &ar
query += ", ";
}
for (std::vector<string>::iterator iter = num_columns.begin();
for (auto iter = num_columns.begin();
iter != num_columns.end();
++iter) {
if (iter != num_columns.begin()) {
@ -2320,7 +2325,7 @@ static string com_summarize(exec_context &ec, string cmdline, vector<string> &ar
"WHERE (logline.log_part is null or "
"startswith(logline.log_part, '.') = 0) ");
for (std::vector<string>::iterator iter = other_columns.begin();
for (auto iter = other_columns.begin();
iter != other_columns.end();
++iter) {
if (iter == other_columns.begin()) {
@ -2333,7 +2338,7 @@ static string com_summarize(exec_context &ec, string cmdline, vector<string> &ar
query += query_frag;
}
for (std::vector<string>::iterator iter = other_columns.begin();
for (auto iter = other_columns.begin();
iter != other_columns.end();
++iter) {
if (iter == other_columns.begin()) {
@ -3190,7 +3195,7 @@ public:
continue;
}
logfile::iterator ll = lf->begin();
auto ll = lf->begin();
if (this->lsvs_begin_time == 0 || ll->get_time() < this->lsvs_begin_time) {
this->lsvs_begin_time = ll->get_time();
@ -3250,7 +3255,7 @@ public:
for (vis_line_t curr_line = begin_line; curr_line < end_line; ++curr_line) {
content_line_t cl = lss.at(curr_line);
std::shared_ptr<logfile> lf = lss.find(cl);
logfile::iterator ll = lf->begin() + cl;
auto ll = lf->begin() + cl;
log_format *format = lf->get_format();
shared_buffer_ref sbr;

View File

@ -35,8 +35,8 @@
#include <string>
#include <vector>
#include "lnav.hh"
#include "logfile.hh"
#include "logfile_sub_source.hh"
#include "data_parser.hh"
#include "column_namer.hh"
#include "log_vtab_impl.hh"
@ -44,23 +44,27 @@
class log_data_table : public log_vtab_impl {
public:
log_data_table(content_line_t template_line, intern_string_t table_name)
log_data_table(logfile_sub_source &lss,
log_vtab_manager &lvm,
content_line_t template_line,
intern_string_t table_name)
: log_vtab_impl(table_name),
ldt_log_source(lss),
ldt_template_line(template_line),
ldt_parent_column_count(0),
ldt_instance(-1) {
std::shared_ptr<logfile> lf = lnav_data.ld_log_source.find(template_line);
std::shared_ptr<logfile> lf = lss.find(template_line);
log_format *format = lf->get_format();
this->vi_supports_indexes = false;
this->ldt_format_impl = lnav_data.ld_vtab_manager->lookup_impl(format->get_name());
this->ldt_format_impl = lvm.lookup_impl(format->get_name());
this->get_columns_int(this->ldt_cols);
};
void get_columns_int(std::vector<vtab_column> &cols)
{
content_line_t cl_copy = this->ldt_template_line;
std::shared_ptr<logfile> lf = lnav_data.ld_log_source.find(cl_copy);
std::shared_ptr<logfile> lf = this->ldt_log_source.find(cl_copy);
struct line_range body;
string_attrs_t sa;
std::vector<logline_value> line_values;
@ -85,9 +89,8 @@ public:
dp.parse();
cols.push_back(vtab_column("log_msg_instance", SQLITE_INTEGER, NULL));
for (data_parser::element_list_t::iterator pair_iter =
dp.dp_pairs.begin();
cols.emplace_back("log_msg_instance", SQLITE_INTEGER, nullptr);
for (auto pair_iter = dp.dp_pairs.begin();
pair_iter != dp.dp_pairs.end();
++pair_iter) {
std::string key_str = dp.get_element_string(
@ -122,7 +125,7 @@ public:
void get_foreign_keys(std::vector<std::string> &keys_inout) const
{
log_vtab_impl::get_foreign_keys(keys_inout);
keys_inout.push_back("log_msg_instance");
keys_inout.emplace_back("log_msg_instance");
};
bool next(log_cursor &lc, logfile_sub_source &lss)
@ -192,14 +195,11 @@ public:
int next_column = this->ldt_parent_column_count;
this->ldt_format_impl->extract(lf, line, values);
values.push_back(logline_value(instance_name, this->ldt_instance));
values.emplace_back(instance_name, this->ldt_instance);
logline_value &lv = values.back();
lv.lv_column = next_column++;
for (data_parser::element_list_t::iterator pair_iter =
this->ldt_pairs.begin();
pair_iter != this->ldt_pairs.end();
++pair_iter) {
const data_parser::element &pvalue = pair_iter->get_pair_value();
for (auto &ldt_pair : this->ldt_pairs) {
const data_parser::element &pvalue = ldt_pair.get_pair_value();
switch (pvalue.value_token()) {
case DT_NUMBER: {
@ -213,7 +213,7 @@ public:
if (sscanf(scan_value, "%lf", &d) != 1) {
d = 0.0;
}
values.push_back(logline_value(intern_string::lookup("", 0), d));
values.emplace_back(intern_string::lookup("", 0), d);
}
break;
@ -222,8 +222,8 @@ public:
value_sbr.subset(line,
pvalue.e_capture.c_begin, pvalue.e_capture.length());
values.push_back(logline_value(intern_string::lookup("", 0),
logline_value::VALUE_TEXT, value_sbr));
values.emplace_back(intern_string::lookup("", 0),
logline_value::VALUE_TEXT, value_sbr);
break;
}
@ -233,6 +233,7 @@ public:
};
private:
logfile_sub_source &ldt_log_source;
const content_line_t ldt_template_line;
data_parser::schema_id_t ldt_schema_id;
shared_buffer_ref ldt_current_line;
@ -242,4 +243,5 @@ private:
int64_t ldt_instance;
std::vector<vtab_column> ldt_cols;
};
#endif

View File

@ -35,7 +35,6 @@
#include <string>
#include <vector>
#include "lnav.hh"
#include "logfile.hh"
#include "sql_util.hh"
#include "data_parser.hh"

View File

@ -29,7 +29,6 @@
#include "config.h"
#include "lnav.hh"
#include "lnav_log.hh"
#include "sql_util.hh"
#include "log_vtab_impl.hh"

View File

@ -34,6 +34,7 @@
#include <vector>
#include "attr_line.hh"
#include "textview_curses.hh"
class plain_text_source
: public text_sub_source {
@ -42,16 +43,16 @@ public:
: tds_text_format(TF_UNKNOWN), tds_longest_line(0) {
};
plain_text_source(std::string text) : tds_text_format(TF_UNKNOWN) {
plain_text_source(const std::string &text) : tds_text_format(TF_UNKNOWN) {
size_t start = 0, end;
while ((end = text.find('\n', start)) != std::string::npos) {
size_t len = (end - start);
this->tds_lines.push_back(text.substr(start, len));
this->tds_lines.emplace_back(text.substr(start, len));
start = end + 1;
}
if (start < text.length()) {
this->tds_lines.push_back(text.substr(start));
this->tds_lines.emplace_back(text.substr(start));
}
this->tds_longest_line = this->compute_longest_line();
};

View File

@ -32,17 +32,8 @@
#include "view_curses.hh"
#include "pretty_printer.hh"
sig_atomic_t reverse_lookup_enabled = 1;
void sigalrm_handler(int sig)
void pretty_printer::append_to(attr_line_t &al)
{
if (sig == SIGALRM)
{
reverse_lookup_enabled = 0;
}
}
void pretty_printer::append_to(attr_line_t &al) {
pcre_context_static<30> pc;
data_token_t dt;
@ -127,65 +118,8 @@ void pretty_printer::append_to(attr_line_t &al) {
al.append(combined);
}
void pretty_printer::convert_ip_address(const pretty_printer::element &el) {
union {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} sa;
pcre_input &pi = this->pp_scanner->get_input();
std::string ipstr = pi.get_substr(&el.e_capture);
std::string result = "unknown";
char buffer[NI_MAXHOST];
int socklen, rc;
if (ipstr == "::") {
return;
}
switch (el.e_token) {
case DT_IPV4_ADDRESS:
sa.sin.sin_family = AF_INET;
rc = inet_pton(AF_INET, ipstr.c_str(), &sa.sin.sin_addr);
socklen = sizeof(struct sockaddr_in);
break;
case DT_IPV6_ADDRESS:
sa.sin6.sin6_family = AF_INET6;
rc = inet_pton(AF_INET6, ipstr.c_str(), &sa.sin6.sin6_addr);
socklen = sizeof(struct sockaddr_in6);
break;
default:
require(0);
break;
}
if (rc == 1 && reverse_lookup_enabled) {
const struct timeval timeout = {0, 500 * 1000};
{
timer::interrupt_timer t(timeout, sigalrm_handler);
if (t.arm_timer() == 0) {
rc = getnameinfo((struct sockaddr *)&sa, socklen,
buffer, sizeof(buffer), NULL, 0,
NI_NAMEREQD);
if (rc == 0) {
result = buffer;
}
}
else {
log_error("Unable to set timer, disabling reverse lookup");
reverse_lookup_enabled = 0;
}
}
if (!reverse_lookup_enabled) {
log_info("Reverse lookup in pretty-print view disabled");
}
}
ssize_t start_size = this->pp_stream.tellp();
this->pp_stream << " (" << result << ")";
struct line_range lr{(int) start_size + 1, (int) this->pp_stream.tellp()};
this->pp_attrs.emplace_back(lr, &view_curses::VC_STYLE, A_UNDERLINE);
}
void pretty_printer::write_element(const pretty_printer::element &el) {
void pretty_printer::write_element(const pretty_printer::element &el)
{
if (this->pp_leading_indent == 0 &&
this->pp_line_length == 0 &&
el.e_token == DT_WHITE) {
@ -249,7 +183,8 @@ void pretty_printer::write_element(const pretty_printer::element &el) {
}
}
void pretty_printer::append_indent() {
void pretty_printer::append_indent()
{
this->pp_stream << std::string(this->pp_leading_indent + this->pp_soft_indent, ' ');
this->pp_soft_indent = 0;
if (this->pp_stream.tellp() == this->pp_leading_indent) {
@ -260,7 +195,8 @@ void pretty_printer::append_indent() {
}
}
bool pretty_printer::flush_values(bool start_on_depth) {
bool pretty_printer::flush_values(bool start_on_depth)
{
bool retval = false;
while (!this->pp_values.empty()) {
@ -282,7 +218,8 @@ bool pretty_printer::flush_values(bool start_on_depth) {
return retval;
}
void pretty_printer::start_new_line() {
void pretty_printer::start_new_line()
{
bool has_output;
if (this->pp_line_length > 0) {
@ -297,7 +234,8 @@ void pretty_printer::start_new_line() {
this->pp_body_lines.top() += 1;
}
void pretty_printer::ascend() {
void pretty_printer::ascend()
{
if (this->pp_depth > 0) {
int lines = this->pp_body_lines.top();
this->pp_depth -= 1;
@ -309,7 +247,8 @@ void pretty_printer::ascend() {
}
}
void pretty_printer::descend() {
void pretty_printer::descend()
{
this->pp_depth += 1;
this->pp_body_lines.push(0);
}

View File

@ -32,10 +32,6 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <signal.h>
#include <stack>
@ -44,15 +40,10 @@
#include <iomanip>
#include <utility>
#include "timer.hh"
#include "ansi_scrubber.hh"
#include "attr_line.hh"
#include "data_scanner.hh"
#include "lnav_util.hh"
extern sig_atomic_t reverse_lookup_enabled;
void sigalrm_handler(int sig);
class pretty_printer {
public:
@ -88,8 +79,6 @@ public:
private:
void convert_ip_address(const element &el);
void descend();
void ascend();

View File

@ -32,7 +32,6 @@
#include <string>
#include "lnav_config.hh"
#include "statusview_curses.hh"
class preview_status_source

View File

@ -475,23 +475,23 @@ void rl_callback(void *dummy, readline_curses *rc)
tmpout = std::tmpfile();
if (!tmpout) {
rc->set_value("Unable to open temporary output file: " + string(strerror(errno)));
}
else {
rc->set_value("Unable to open temporary output file: " +
string(strerror(errno)));
} else {
auto_fd fd(fileno(tmpout));
auto_fd fd_copy((const auto_fd &) fd);
char desc[256], timestamp[32];
time_t current_time = time(NULL);
string path_and_args = rc->get_value();
lnav_data.ld_output_stack.push(tmpout);
string result = execute_file(ec, path_and_args);
string::size_type lf_index = result.find('\n');
if (lf_index != string::npos) {
result = result.substr(0, lf_index);
}
rc->set_value(result);
lnav_data.ld_output_stack.pop();
lnav_data.ld_output_stack.push(tmpout);
string result = execute_file(ec, path_and_args);
string::size_type lf_index = result.find('\n');
if (lf_index != string::npos) {
result = result.substr(0, lf_index);
}
rc->set_value(result);
lnav_data.ld_output_stack.pop();
struct stat st;
@ -509,8 +509,8 @@ void rl_callback(void *dummy, readline_curses *rc)
lnav_data.ld_files_to_front.push_back(make_pair(desc, 0));
if (lnav_data.ld_rl_view != NULL) {
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
X, "to close the file"));
lnav_data.ld_rl_view->set_alt_value(
HELP_MSG_1(X, "to close the file"));
}
}
}

View File

@ -86,10 +86,10 @@ static void find_matching_bracket(attr_line_t &al, int x, char left, char right)
}
else if (line[lpc] == left && is_bracket(line, lpc, is_lit)) {
if (depth == 0) {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc, lpc + 1),
&view_curses::VC_STYLE,
matching_bracket_attrs));
matching_bracket_attrs);
break;
}
else {
@ -106,10 +106,10 @@ static void find_matching_bracket(attr_line_t &al, int x, char left, char right)
}
else if (line[lpc] == right && is_bracket(line, lpc, is_lit)) {
if (depth == 0) {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc, lpc + 1),
&view_curses::VC_STYLE,
matching_bracket_attrs));
matching_bracket_attrs);
break;
}
else {
@ -135,19 +135,19 @@ static void find_matching_bracket(attr_line_t &al, int x, char left, char right)
depth -= 1;
}
else {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(is_lit ? lpc - 1 : lpc, lpc + 1),
&view_curses::VC_STYLE,
missing_bracket_attrs));
missing_bracket_attrs);
}
}
}
if (depth > 0) {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(is_lit ? first_left - 1 : first_left, first_left + 1),
&view_curses::VC_STYLE,
missing_bracket_attrs));
missing_bracket_attrs);
}
}
@ -193,17 +193,17 @@ static void readline_regex_highlighter_int(attr_line_t &al, int x, int skip)
case '+':
case '|':
case '.':
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc, lpc + 1),
&view_curses::VC_STYLE,
special_char));
special_char);
if ((line[lpc] == '*' || line[lpc] == '+') &&
check_re_prev(line, lpc)) {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc - 1, lpc),
&view_curses::VC_STYLE,
repeated_char_attrs));
repeated_char_attrs);
}
break;
case '?': {
@ -219,22 +219,22 @@ static void readline_regex_highlighter_int(attr_line_t &al, int x, int skip)
lr.lr_end += 1;
break;
}
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
lr,
&view_curses::VC_STYLE,
bracket_attrs));
bracket_attrs);
}
else {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
lr,
&view_curses::VC_STYLE,
special_char));
special_char);
if (check_re_prev(line, lpc)) {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc - 1, lpc),
&view_curses::VC_STYLE,
repeated_char_attrs));
repeated_char_attrs);
}
}
break;
@ -246,10 +246,10 @@ static void readline_regex_highlighter_int(attr_line_t &al, int x, int skip)
case '}':
case '[':
case ']':
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc, lpc + 1),
&view_curses::VC_STYLE,
bracket_attrs));
bracket_attrs);
break;
}
@ -287,16 +287,16 @@ static void readline_regex_highlighter_int(attr_line_t &al, int x, int skip)
case 'G':
case 'Z':
case 'z':
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc - 1, lpc + 1),
&view_curses::VC_STYLE,
class_attrs));
class_attrs);
break;
case ' ':
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc - 1, lpc + 1),
&view_curses::VC_STYLE,
error_attrs));
error_attrs);
break;
case '0':
case 'x':
@ -368,10 +368,10 @@ void readline_command_highlighter(attr_line_t &al, int x)
ws_index = line.find(' ');
string command = line.substr(0, ws_index);
if (ws_index != string::npos) {
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(1, ws_index),
&view_curses::VC_STYLE,
keyword_attrs));
keyword_attrs);
}
if (RE_PREFIXES.match(pc, pi)) {
readline_regex_highlighter_int(al, x, 1 + pc[0]->length());
@ -442,8 +442,8 @@ void readline_sqlite_highlighter(attr_line_t &al, int x)
}
else if (!lr.contains(x) && !lr.contains(x - 1)) {
al.get_attrs().push_back(string_attr(
lr, &view_curses::VC_STYLE, attrs));
al.get_attrs().emplace_back(
lr, &view_curses::VC_STYLE, attrs);
}
}
@ -452,10 +452,10 @@ void readline_sqlite_highlighter(attr_line_t &al, int x)
while (keyword_pcre.match(pc, pi)) {
pcre_context::capture_t *cap = pc.all();
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(cap->c_begin, cap->c_end),
&view_curses::VC_STYLE,
keyword_attrs));
keyword_attrs);
}
for (size_t lpc = 0; lpc < line.length(); lpc++) {
@ -467,10 +467,10 @@ void readline_sqlite_highlighter(attr_line_t &al, int x)
case '!':
case '-':
case '+':
al.get_attrs().push_back(string_attr(
al.get_attrs().emplace_back(
line_range(lpc, lpc + 1),
&view_curses::VC_STYLE,
symbol_attrs));
symbol_attrs);
break;
}
}
@ -485,16 +485,13 @@ void readline_sqlite_highlighter(attr_line_t &al, int x)
remove_string_attr(sa, lr);
if (line[cap->c_end - 1] != '\'') {
sa.push_back(string_attr(
sa.emplace_back(
line_range(cap->c_begin, cap->c_begin + 1),
&view_curses::VC_STYLE,
error_attrs));
error_attrs);
lr.lr_start += 1;
}
sa.push_back(string_attr(
lr,
&view_curses::VC_STYLE,
string_attrs));
sa.emplace_back(lr, &view_curses::VC_STYLE, string_attrs);
}
for (int lpc = 0; brackets[lpc]; lpc++) {

View File

@ -33,7 +33,7 @@
#include <unistd.h>
#include <string.h>
#include "lnav.hh"
#include "logfile.hh"
#include "auto_mem.hh"
#include "lnav_log.hh"
#include "sql_util.hh"

View File

@ -35,6 +35,7 @@
#include "bookmarks.hh"
#include "grep_proc.hh"
#include "sequence_matcher.hh"
#include "listview_curses.hh"
class sequence_sink : public grep_proc_sink<vis_line_t> {
public:

View File

@ -1,35 +0,0 @@
/**
* Copyright (c) 2007-2012, Timothy Stack
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Timothy Stack nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __status_controllers_hh
#define __status_controllers_hh
#include "listview_curses.hh"
#include "statusview_curses.hh"
#endif

View File

@ -32,6 +32,8 @@
#ifndef __sysclip_hh
#define __sysclip_hh
#include <stdio.h>
enum clip_type_t {
CT_GENERAL,
CT_FIND,

View File

@ -33,6 +33,7 @@
#define __termios_guard_hh
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>

View File

@ -389,3 +389,5 @@ void text_time_translator::data_reloaded(textview_curses *tc)
}
}
}
template class bookmark_vector<vis_line_t>;

View File

@ -46,6 +46,8 @@
class logline;
class textview_curses;
using vis_bookmarks = bookmarks<vis_line_t>::type;
class logfile_filter_state {
public:
logfile_filter_state(std::shared_ptr<logfile> lf = nullptr) : tfs_logfile(

View File

@ -31,6 +31,7 @@
#define url_loader_hh
#ifdef HAVE_LIBCURL
#include <paths.h>
#include <curl/curl.h>
class url_loader : public curl_request {

View File

@ -33,7 +33,10 @@
#include <stdlib.h>
#include "yajl/api/yajl_gen.h"
#include "json_op.hh"
#include "lnav_log.hh"
static void printer(void *ctx, const char *numberVal, size_t numberLen)
{

View File

@ -34,6 +34,7 @@
#include <stdlib.h>
#include "json_ptr.hh"
#include "lnav_log.hh"
int main(int argc, char *argv[])
{

View File

@ -47,6 +47,7 @@
#include "logfile.hh"
#include "sequence_sink.hh"
#include "sequence_matcher.hh"
#include "textview_curses.hh"
using namespace std;

View File

@ -34,6 +34,7 @@
#include <assert.h>
#include "bookmarks.hh"
#include "textview_curses.hh"
int main(int argc, char *argv[])
{