[cleanup] uncrustify

pull/69/head
Timothy Stack 11 years ago
parent eee43efd5a
commit 5a7d6dab2c

@ -66,7 +66,7 @@ indent_sing_line_comments = 0 # number
indent_switch_case = 0 # number indent_switch_case = 0 # number
# Spaces to indent 'case' body from 'case' # Spaces to indent 'case' body from 'case'
indent_case_body = 0 # number indent_case_body = 4 # number
# Spaces to indent '{' from 'case' # Spaces to indent '{' from 'case'
indent_case_brace = 0 # number indent_case_brace = 0 # number

@ -48,10 +48,11 @@ static pcrepp &ansi_regex(void)
void scrub_ansi_string(std::string &str, string_attrs_t &sa) void scrub_ansi_string(std::string &str, string_attrs_t &sa)
{ {
view_colors &vc = view_colors::singleton(); view_colors &vc = view_colors::singleton();
vector<pair<string, string_attr_t> > attr_queue; vector<pair<string, string_attr_t> > attr_queue;
pcre_context_static<60> context; pcre_context_static<60> context;
vector<line_range> range_queue; vector<line_range> range_queue;
pcrepp &regex = ansi_regex(); pcrepp & regex = ansi_regex();
pcre_input pi(str); pcre_input pi(str);
while (regex.match(context, pi)) { while (regex.match(context, pi)) {

@ -49,5 +49,4 @@
* @param sa The container for any style attributes. * @param sa The container for any style attributes.
*/ */
void scrub_ansi_string(std::string &str, string_attrs_t &sa); void scrub_ansi_string(std::string &str, string_attrs_t &sa);
#endif #endif

@ -101,8 +101,9 @@ public:
void reset(T *ptr = NULL) void reset(T *ptr = NULL)
{ {
if (this->am_ptr != ptr) { if (this->am_ptr != ptr) {
if (this->am_ptr != NULL) if (this->am_ptr != NULL) {
this->am_free_func(this->am_ptr); this->am_free_func(this->am_ptr);
}
this->am_ptr = ptr; this->am_ptr = ptr;
} }
}; };
@ -112,10 +113,11 @@ private:
void (*am_free_func)(void *); void (*am_free_func)(void *);
}; };
template<typename T, void (*free_func)(T *)> template<typename T, void(*free_func) (T *)>
class static_root_mem { class static_root_mem {
public: public:
static_root_mem() { static_root_mem()
{
memset(&this->srm_value, 0, sizeof(T)); memset(&this->srm_value, 0, sizeof(T));
}; };

@ -96,7 +96,8 @@ public:
status_field &get_field(field_t id) { return this->bss_fields[id]; }; status_field &get_field(field_t id) { return this->bss_fields[id]; };
void set_prompt(const std::string &prompt) { void set_prompt(const std::string &prompt)
{
this->bss_prompt.set_value(prompt); this->bss_prompt.set_value(prompt);
}; };

@ -55,11 +55,13 @@ struct byte_array {
return memcmp(this->ba_data, other.ba_data, BYTE_COUNT) != 0; return memcmp(this->ba_data, other.ba_data, BYTE_COUNT) != 0;
}; };
void clear(void) { void clear(void)
{
memset(this->ba_data, 0, BYTE_COUNT); memset(this->ba_data, 0, BYTE_COUNT);
}; };
void to_string(char *buffer) const { void to_string(char *buffer) const
{
assert(buffer != NULL); assert(buffer != NULL);
for (size_t lpc = 0; lpc < BYTE_COUNT; lpc++) { for (size_t lpc = 0; lpc < BYTE_COUNT; lpc++) {
@ -67,7 +69,8 @@ struct byte_array {
} }
}; };
std::string to_string() const { std::string to_string() const
{
char buffer[BYTE_COUNT * 2 + 1]; char buffer[BYTE_COUNT * 2 + 1];
this->to_string(buffer); this->to_string(buffer);
@ -75,7 +78,7 @@ struct byte_array {
} }
const unsigned char *in() const { return this->ba_data; }; const unsigned char *in() const { return this->ba_data; };
unsigned char *out() { return this->ba_data; }; unsigned char * out() { return this->ba_data; };
unsigned char ba_data[BYTE_COUNT]; unsigned char ba_data[BYTE_COUNT];
}; };

@ -156,7 +156,8 @@ int sql_strnatcasecmp(void *ptr,
int register_collation_functions(sqlite3 *db) int register_collation_functions(sqlite3 *db)
{ {
sqlite3_create_collation(db, "ipaddress", SQLITE_UTF8, NULL, ipaddress); sqlite3_create_collation(db, "ipaddress", SQLITE_UTF8, NULL, ipaddress);
sqlite3_create_collation(db, "naturalcase", SQLITE_UTF8, NULL, sql_strnatcmp); sqlite3_create_collation(db, "naturalcase", SQLITE_UTF8, NULL,
sql_strnatcmp);
sqlite3_create_collation(db, "naturalnocase", SQLITE_UTF8, NULL, sqlite3_create_collation(db, "naturalnocase", SQLITE_UTF8, NULL,
sql_strnatcasecmp); sql_strnatcasecmp);

@ -62,15 +62,18 @@ data_format_state_t dfs_prefix_next(data_format_state_t state,
case DT_LANGLE: case DT_LANGLE:
case DT_RANGLE: case DT_RANGLE:
break; break;
default: default:
retval = DFS_ERROR; retval = DFS_ERROR;
break; break;
} }
break; break;
case DFS_EXPECTING_SEP: case DFS_EXPECTING_SEP:
case DFS_ERROR: case DFS_ERROR:
retval = DFS_ERROR; retval = DFS_ERROR;
break; break;
default: default:
break; break;
} }
@ -130,6 +133,7 @@ data_format_state_t dfs_comma_next(data_format_state_t state,
switch (next_token) { switch (next_token) {
case DT_COMMA: case DT_COMMA:
break; break;
case DT_SEMI: case DT_SEMI:
retval = DFS_ERROR; retval = DFS_ERROR;
break; break;
@ -161,15 +165,18 @@ data_format_state_t dfs_comma_next(data_format_state_t state,
default: break; default: break;
} }
break; break;
case DFS_EXPECTING_SEP: case DFS_EXPECTING_SEP:
switch (next_token) { switch (next_token) {
case DT_SEPARATOR: case DT_SEPARATOR:
retval = DFS_VALUE; retval = DFS_VALUE;
break; break;
case DT_COMMA: case DT_COMMA:
case DT_SEMI: case DT_SEMI:
retval = DFS_ERROR; retval = DFS_ERROR;
break; break;
default: break; default: break;
} }
break; break;

@ -114,7 +114,8 @@
#define PUSH_BACK(elem) push_back(elem, __FILE__, __LINE__) #define PUSH_BACK(elem) push_back(elem, __FILE__, __LINE__)
#define POP_FRONT(elem) pop_front(__FILE__, __LINE__) #define POP_FRONT(elem) pop_front(__FILE__, __LINE__)
#define POP_BACK(elem) pop_back(__FILE__, __LINE__) #define POP_BACK(elem) pop_back(__FILE__, __LINE__)
#define SPLICE(pos, other, first, last) splice(pos, other, first, last, __FILE__, __LINE__) #define SPLICE(pos, other, first, last) splice(pos, other, first, last, \
__FILE__, __LINE__)
template<class Container, class UnaryPredicate> template<class Container, class UnaryPredicate>
void strip(Container &container, UnaryPredicate p) void strip(Container &container, UnaryPredicate p)
@ -142,7 +143,7 @@ struct data_format {
: df_name(name), df_appender(appender), df_terminator(terminator) : df_name(name), df_appender(appender), df_terminator(terminator)
{}; {};
const char *df_name; const char * df_name;
const data_token_t df_appender; const data_token_t df_appender;
const data_token_t df_terminator; const data_token_t df_terminator;
}; };
@ -225,7 +226,7 @@ data_format_state_t dfs_comma_next(data_format_state_t state,
__FILE__, __LINE__, \ __FILE__, __LINE__, \
name); \ name); \
} \ } \
} while(false); } while (false);
class data_parser { class data_parser {
public: public:
@ -238,15 +239,17 @@ public:
typedef byte_array<SHA_DIGEST_LENGTH> schema_id_t; typedef byte_array<SHA_DIGEST_LENGTH> schema_id_t;
struct element; struct element;
// typedef std::list<element> element_list_t; /* typedef std::list<element> element_list_t; */
class element_list_t : public std::list<element> { class element_list_t : public std::list<element> {
public: public:
element_list_t(const char *varname, const char *fn, int line) { element_list_t(const char *varname, const char *fn, int line)
{
LIST_INIT_TRACE; LIST_INIT_TRACE;
} }
element_list_t() { element_list_t()
{
const char *varname = "_anon2_"; const char *varname = "_anon2_";
const char *fn = __FILE__; const char *fn = __FILE__;
int line = __LINE__; int line = __LINE__;
@ -254,26 +257,30 @@ public:
LIST_INIT_TRACE; LIST_INIT_TRACE;
}; };
~element_list_t() { ~element_list_t()
{
const char *fn = __FILE__; const char *fn = __FILE__;
int line = __LINE__; int line = __LINE__;
LIST_DEINIT_TRACE; LIST_DEINIT_TRACE;
}; };
void push_back(const element &elem, const char *fn, int line) { void push_back(const element &elem, const char *fn, int line)
{
ELEMENT_TRACE; ELEMENT_TRACE;
this->std::list<element>::push_back(elem); this->std::list<element>::push_back(elem);
}; };
void pop_front(const char *fn, int line) { void pop_front(const char *fn, int line)
{
LIST_TRACE; LIST_TRACE;
this->std::list<element>::pop_front(); this->std::list<element>::pop_front();
}; };
void pop_back(const char *fn, int line) { void pop_back(const char *fn, int line)
{
LIST_TRACE; LIST_TRACE;
this->std::list<element>::pop_back(); this->std::list<element>::pop_back();
@ -284,7 +291,8 @@ public:
iterator first, iterator first,
iterator last, iterator last,
const char *fn, const char *fn,
int line) { int line)
{
SPLICE_TRACE; SPLICE_TRACE;
this->std::list<element>::splice(pos, other, first, last); this->std::list<element>::splice(pos, other, first, last);
@ -340,7 +348,8 @@ public:
void assign_elements(element_list_t &subs) void assign_elements(element_list_t &subs)
{ {
if (this->e_sub_elements == NULL) { if (this->e_sub_elements == NULL) {
this->e_sub_elements = new element_list_t("_sub_", __FILE__, __LINE__); this->e_sub_elements = new element_list_t("_sub_", __FILE__,
__LINE__);
} }
this->e_sub_elements->swap(subs); this->e_sub_elements->swap(subs);
this->update_capture(); this->update_capture();
@ -356,7 +365,8 @@ public:
} }
}; };
const element &get_pair_value(void) const { const element & get_pair_value(void) const
{
assert(this->e_token == DNT_PAIR); assert(this->e_token == DNT_PAIR);
return this->e_sub_elements->back(); return this->e_sub_elements->back();
@ -452,7 +462,8 @@ private:
: dp_errors("dp_errors", __FILE__, __LINE__), : dp_errors("dp_errors", __FILE__, __LINE__),
dp_pairs("dp_pairs", __FILE__, __LINE__), dp_pairs("dp_pairs", __FILE__, __LINE__),
dp_format(NULL), dp_format(NULL),
dp_scanner(ds) { dp_scanner(ds)
{
if (TRACE_FILE != NULL) { if (TRACE_FILE != NULL) {
fprintf(TRACE_FILE, "input %s\n", ds->get_input().get_string()); fprintf(TRACE_FILE, "input %s\n", ds->get_input().get_string());
} }
@ -461,7 +472,9 @@ private:
void pairup(schema_id_t *schema, element_list_t &pairs_out, void pairup(schema_id_t *schema, element_list_t &pairs_out,
element_list_t &in_list) element_list_t &in_list)
{ {
element_list_t ELEMENT_LIST_T(el_stack), ELEMENT_LIST_T(free_row), ELEMENT_LIST_T(key_comps), ELEMENT_LIST_T(value), ELEMENT_LIST_T(prefix); element_list_t ELEMENT_LIST_T(el_stack), ELEMENT_LIST_T(free_row),
ELEMENT_LIST_T(key_comps), ELEMENT_LIST_T(value),
ELEMENT_LIST_T(prefix);
SHA_CTX context; SHA_CTX context;
POINT_TRACE("pairup_start"); POINT_TRACE("pairup_start");
@ -530,8 +543,8 @@ private:
if (el_stack.size() > 1 && if (el_stack.size() > 1 &&
this->dp_format->df_appender != DT_INVALID && this->dp_format->df_appender != DT_INVALID &&
this->dp_format->df_terminator != DT_INVALID) { this->dp_format->df_terminator != DT_INVALID) {
// If we're expecting a terminator and haven't found it /* If we're expecting a terminator and haven't found it */
// then this is part of the value. /* then this is part of the value. */
continue; continue;
} }
@ -601,7 +614,8 @@ private:
struct element blank; struct element blank;
blank.e_capture.c_begin = blank.e_capture.c_end = blank.e_capture.c_begin = blank.e_capture.c_end =
el_stack.front().e_capture.c_begin; el_stack.front().e_capture.
c_begin;
blank.e_token = DNT_KEY; blank.e_token = DNT_KEY;
free_pair_subs.PUSH_BACK(blank); free_pair_subs.PUSH_BACK(blank);
free_pair_subs.PUSH_BACK(el_stack.front()); free_pair_subs.PUSH_BACK(el_stack.front());
@ -637,7 +651,8 @@ private:
struct element blank; struct element blank;
blank.e_capture.c_begin = blank.e_capture.c_end = blank.e_capture.c_begin = blank.e_capture.c_end =
free_row.front().e_capture.c_begin; free_row.front().e_capture.
c_begin;
blank.e_token = DNT_KEY; blank.e_token = DNT_KEY;
free_pair_subs.PUSH_BACK(blank); free_pair_subs.PUSH_BACK(blank);
free_pair_subs.PUSH_BACK(free_row.front()); free_pair_subs.PUSH_BACK(free_row.front());
@ -771,11 +786,13 @@ private:
semi_state = dfs_semi_next(semi_state, elem.e_token); semi_state = dfs_semi_next(semi_state, elem.e_token);
comma_state = dfs_comma_next(comma_state, elem.e_token); comma_state = dfs_comma_next(comma_state, elem.e_token);
if (prefix_state != DFS_ERROR) { if (prefix_state != DFS_ERROR) {
if (semi_state == DFS_ERROR) if (semi_state == DFS_ERROR) {
semi_state = DFS_INIT; semi_state = DFS_INIT;
if (comma_state == DFS_ERROR) }
if (comma_state == DFS_ERROR) {
comma_state = DFS_INIT; comma_state = DFS_INIT;
} }
}
hist[elem.e_token] += 1; hist[elem.e_token] += 1;
switch (elem.e_token) { switch (elem.e_token) {
case DT_LPAREN: case DT_LPAREN:
@ -783,7 +800,9 @@ private:
case DT_LCURLY: case DT_LCURLY:
case DT_LSQUARE: case DT_LSQUARE:
this->dp_group_token.push_back(elem.e_token); this->dp_group_token.push_back(elem.e_token);
this->dp_group_stack.push_back(element_list_t("_anon_", __FILE__, __LINE__)); this->dp_group_stack.push_back(element_list_t("_anon_",
__FILE__,
__LINE__));
break; break;
case DT_RPAREN: case DT_RPAREN:

@ -46,7 +46,8 @@ static struct {
"(?:u|r)?'((?:\\\\.|[^'])+)')"), }, "(?:u|r)?'((?:\\\\.|[^'])+)')"), },
{ "url", pcrepp("\\A([\\w]+://[^\\s'\"\\[\\](){}]+[a-zA-Z0-9\\-=&])"), { "url", pcrepp("\\A([\\w]+://[^\\s'\"\\[\\](){}]+[a-zA-Z0-9\\-=&])"),
}, },
{ "path", pcrepp("\\A((?:/|\\./|\\.\\./)[\\w\\.\\-_\\~/]*)"), }, { "path", pcrepp("\\A((?:/|\\./|\\.\\./)[\\w\\.\\-_\\~/]*)"),
},
{ "mac", pcrepp( { "mac", pcrepp(
"\\A([0-9a-fA-F][0-9a-fA-F](?::[0-9a-fA-F][0-9a-fA-F]){5})"), }, "\\A([0-9a-fA-F][0-9a-fA-F](?::[0-9a-fA-F][0-9a-fA-F]){5})"), },
{ "time", pcrepp( { "time", pcrepp(
@ -94,16 +95,17 @@ static struct {
{ "pcnt", pcrepp("\\A(-?[0-9]+(\\.[0-9]+)?[ ]*%\\b)"), { "pcnt", pcrepp("\\A(-?[0-9]+(\\.[0-9]+)?[ ]*%\\b)"),
}, },
{ "num", pcrepp("\\A(-?[0-9]+(\\.[0-9]+)?([eE][-+][0-9]+)?)" { "num", pcrepp("\\A(-?[0-9]+(\\.[0-9]+)?([eE][-+][0-9]+)?)"
"\\b(?![\\._\\-][a-zA-Z])"), "\\b(?![\\._\\-][a-zA-Z])"), },
},
{ "hex", pcrepp("\\A(-?(?:0x|[0-9])[0-9a-fA-F]+)" { "hex", pcrepp("\\A(-?(?:0x|[0-9])[0-9a-fA-F]+)"
"\\b(?![\\._\\-][a-zA-Z])"), "\\b(?![\\._\\-][a-zA-Z])"), },
},
{ "mail", pcrepp("\\A([a-zA-Z0-9\\._%+-]+@[a-zA-Z0-9\\.-]+\\.[a-zA-Z]+)\\b"), }, { "mail", pcrepp(
{ "cnst", pcrepp("\\A(true|True|TRUE|false|False|FALSE|None|null)\\b") }, "\\A([a-zA-Z0-9\\._%+-]+@[a-zA-Z0-9\\.-]+\\.[a-zA-Z]+)\\b"), },
{ "cnst",
pcrepp("\\A(true|True|TRUE|false|False|FALSE|None|null)\\b") },
{ "word", pcrepp( { "word", pcrepp(
"\\A([a-zA-Z][a-z']+(?=[\\s\\(\\)!\\*:;'\\\"\\?,]|[\\.\\!,\\?]\\s|$))"), }, "\\A([a-zA-Z][a-z']+(?=[\\s\\(\\)!\\*:;'\\\"\\?,]|[\\.\\!,\\?]\\s|$))"),
},
{ "sym", pcrepp( { "sym", pcrepp(
"\\A([^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+" "\\A([^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+"
"(?:::[^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+)*)"), "(?:::[^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+)*)"),

@ -725,7 +725,8 @@ static bool append_default_files(lnav_flags_t flag)
perror("Unable to resolve path"); perror("Unable to resolve path");
} }
else { else {
lnav_data.ld_file_names.insert(make_pair(abspath.in(), -1)); lnav_data.ld_file_names.insert(make_pair(abspath.in(),
-1));
found = true; found = true;
} }
} }
@ -779,12 +780,14 @@ static void update_view_name(void)
status_field &sf = lnav_data.ld_top_source.statusview_value_for_field( status_field &sf = lnav_data.ld_top_source.statusview_value_for_field(
top_status_source::TSF_VIEW_NAME); top_status_source::TSF_VIEW_NAME);
textview_curses *tc = lnav_data.ld_view_stack.top(); textview_curses * tc = lnav_data.ld_view_stack.top();
struct line_range lr = { 0, -1 }; struct line_range lr = { 0, -1 };
sf.set_value("% 5s ", view_names[tc - lnav_data.ld_views]); sf.set_value("% 5s ", view_names[tc - lnav_data.ld_views]);
sf.get_value().get_attrs()[lr].insert(make_string_attr( sf.get_value().get_attrs()[lr].insert(make_string_attr(
"style", A_REVERSE|COLOR_PAIR(view_colors::VC_BLUE_ON_WHITE))); "style", A_REVERSE |
COLOR_PAIR(view_colors::
VC_BLUE_ON_WHITE)));
} }
bool toggle_view(textview_curses *toggle_tc) bool toggle_view(textview_curses *toggle_tc)
@ -1013,7 +1016,8 @@ static void handle_paging_key(int ch)
&logfile_sub_source::BM_ERRORS, &logfile_sub_source::BM_ERRORS,
tc->get_top()); tc->get_top());
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
w, W, "to move forward/backward through warning messages")); w, W,
"to move forward/backward through warning messages"));
break; break;
case 'E': case 'E':
@ -1021,7 +1025,8 @@ static void handle_paging_key(int ch)
&logfile_sub_source::BM_ERRORS, &logfile_sub_source::BM_ERRORS,
tc->get_top()); tc->get_top());
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
w, W, "to move forward/backward through warning messages")); w, W,
"to move forward/backward through warning messages"));
break; break;
case 'w': case 'w':
@ -1029,7 +1034,8 @@ static void handle_paging_key(int ch)
&logfile_sub_source::BM_WARNINGS, &logfile_sub_source::BM_WARNINGS,
tc->get_top()); tc->get_top());
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
o, O, "to move forward/backward an hour")); o, O,
"to move forward/backward an hour"));
break; break;
case 'W': case 'W':
@ -1037,7 +1043,8 @@ static void handle_paging_key(int ch)
&logfile_sub_source::BM_WARNINGS, &logfile_sub_source::BM_WARNINGS,
tc->get_top()); tc->get_top());
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
o, O, "to move forward/backward an hour")); o, O,
"to move forward/backward an hour"));
break; break;
case 'n': case 'n':
@ -1146,7 +1153,8 @@ static void handle_paging_key(int ch)
} }
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
I, "to switch to the log view at the top displayed time")); I,
"to switch to the log view at the top displayed time"));
} }
break; break;
@ -1161,7 +1169,8 @@ static void handle_paging_key(int ch)
} }
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
I, "to switch to the log view at the top displayed time")); I,
"to switch to the log view at the top displayed time"));
} }
break; break;
@ -1183,7 +1192,8 @@ static void handle_paging_key(int ch)
tc->reload_data(); tc->reload_data();
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
u, U, "to move forward/backward through user bookmarks")); u, U,
"to move forward/backward through user bookmarks"));
} }
break; break;
@ -1214,7 +1224,8 @@ static void handle_paging_key(int ch)
tc->reload_data(); tc->reload_data();
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
c, "to copy marked lines to the clipboard")); c,
"to copy marked lines to the clipboard"));
} }
break; break;
@ -1247,7 +1258,8 @@ static void handle_paging_key(int ch)
tc->reload_data(); tc->reload_data();
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
c, "to copy marked lines to the clipboard")); c,
"to copy marked lines to the clipboard"));
} }
break; break;
@ -1406,10 +1418,11 @@ static void handle_paging_key(int ch)
case ':': case ':':
if (lnav_data.ld_views[LNV_LOG].get_inner_height() > 0) { if (lnav_data.ld_views[LNV_LOG].get_inner_height() > 0) {
logfile_sub_source &lss = lnav_data.ld_log_source; logfile_sub_source &lss = lnav_data.ld_log_source;
textview_curses &log_view = lnav_data.ld_views[LNV_LOG]; textview_curses & log_view = lnav_data.ld_views[LNV_LOG];
content_line_t cl = lss.at(log_view.get_top()); content_line_t cl = lss.at(log_view.get_top());
logfile * lf = lss.find(cl); logfile * lf = lss.find(cl);
std::string line = lf->read_line(lf->begin() + cl); std::string line = lf->read_line(
lf->begin() + cl);
struct line_range body; struct line_range body;
string_attrs_t sa; string_attrs_t sa;
std::vector<logline_value> line_values; std::vector<logline_value> line_values;
@ -1428,13 +1441,16 @@ static void handle_paging_key(int ch)
column_namer namer; column_namer namer;
lnav_data.ld_rl_view->clear_possibilities(LNM_COMMAND, "colname"); lnav_data.ld_rl_view->clear_possibilities(LNM_COMMAND, "colname");
for (data_parser::element_list_t::iterator iter = dp.dp_pairs.begin(); for (data_parser::element_list_t::iterator iter =
dp.dp_pairs.begin();
iter != dp.dp_pairs.end(); iter != dp.dp_pairs.end();
++iter) { ++iter) {
std::string colname = dp.get_element_string(iter->e_sub_elements->front()); std::string colname = dp.get_element_string(
iter->e_sub_elements->front());
colname = namer.add_column(colname); colname = namer.add_column(colname);
lnav_data.ld_rl_view->add_possibility(LNM_COMMAND, "colname", colname); lnav_data.ld_rl_view->add_possibility(LNM_COMMAND, "colname",
colname);
} }
} }
lnav_data.ld_mode = LNM_COMMAND; lnav_data.ld_mode = LNM_COMMAND;
@ -1493,7 +1509,8 @@ static void handle_paging_key(int ch)
} }
else if (toggle_view(&lnav_data.ld_views[LNV_TEXT])) { else if (toggle_view(&lnav_data.ld_views[LNV_TEXT])) {
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
f, F, "to switch to the next/previous file")); f, F,
"to switch to the next/previous file"));
} }
break; break;
@ -1631,26 +1648,33 @@ static void handle_paging_key(int ch)
break; break;
case 'r': case 'r':
lnav_data.ld_session_file_index = (lnav_data.ld_session_file_index + 1) % lnav_data.ld_session_file_index =
(lnav_data.ld_session_file_index + 1) %
lnav_data.ld_session_file_names.size(); lnav_data.ld_session_file_names.size();
reset_session(); reset_session();
load_session(); load_session();
rebuild_indexes(true); rebuild_indexes(true);
break; break;
case 'R': case 'R':
if (lnav_data.ld_session_file_index == 0) if (lnav_data.ld_session_file_index == 0) {
lnav_data.ld_session_file_index = lnav_data.ld_session_file_names.size() - 1; lnav_data.ld_session_file_index =
else lnav_data.ld_session_file_names.size() - 1;
}
else{
lnav_data.ld_session_file_index -= 1; lnav_data.ld_session_file_index -= 1;
}
reset_session(); reset_session();
load_session(); load_session();
rebuild_indexes(true); rebuild_indexes(true);
break; break;
case KEY_CTRL_R: case KEY_CTRL_R:
reset_session(); reset_session();
rebuild_indexes(true); rebuild_indexes(true);
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2( lnav_data.ld_rl_view->set_alt_value(HELP_MSG_2(
r, R, "to restore the next/previous session")); r, R,
"to restore the next/previous session"));
break; break;
default: default:
@ -1794,7 +1818,7 @@ int sql_callback(sqlite3_stmt *stmt)
void execute_search(lnav_view_t view, const std::string &regex) void execute_search(lnav_view_t view, const std::string &regex)
{ {
auto_ptr<grep_highlighter> &gc = lnav_data.ld_search_child[view]; auto_ptr<grep_highlighter> &gc = lnav_data.ld_search_child[view];
textview_curses &tc = lnav_data.ld_views[view]; textview_curses & tc = lnav_data.ld_views[view];
if ((gc.get() == NULL) || (regex != lnav_data.ld_last_search[view])) { if ((gc.get() == NULL) || (regex != lnav_data.ld_last_search[view])) {
const char *errptr; const char *errptr;
@ -1846,9 +1870,9 @@ void execute_search(lnav_view_t view, const std::string &regex)
tc.set_follow_search(true); tc.set_follow_search(true);
auto_ptr<grep_highlighter> gh(new grep_highlighter(gp, "$search", hm)); auto_ptr<grep_highlighter> gh(new grep_highlighter(gp, "$search",
hm));
gc = gh; gc = gh;
} }
} }
@ -1893,8 +1917,7 @@ static void rl_search(void *dummy, readline_curses *rc)
grep_error(string("sql error: ") + string(errmsg)); grep_error(string("sql error: ") + string(errmsg));
} }
else { else {
lnav_data.ld_bottom_source. lnav_data.ld_bottom_source.grep_error("");
grep_error("");
} }
} }
return; return;
@ -1935,7 +1958,8 @@ static void rl_callback(void *dummy, readline_curses *rc)
add_possibility(LNM_COMMAND, "filter", rc->get_value()); add_possibility(LNM_COMMAND, "filter", rc->get_value());
rc->set_value("search: " + rc->get_value()); rc->set_value("search: " + rc->get_value());
rc->set_alt_value(HELP_MSG_2( rc->set_alt_value(HELP_MSG_2(
n, N, "to move forward/backward through search results")); n, N,
"to move forward/backward through search results"));
} }
lnav_data.ld_mode = LNM_PAGING; lnav_data.ld_mode = LNM_PAGING;
break; break;
@ -2011,7 +2035,8 @@ static void rl_callback(void *dummy, readline_curses *rc)
(int)dls.dls_rows.size()); (int)dls.dls_rows.size());
rc->set_value(row_count); rc->set_value(row_count);
rc->set_alt_value(HELP_MSG_2( rc->set_alt_value(HELP_MSG_2(
y, Y, "to move forward/backward through query results " y, Y,
"to move forward/backward through query results "
"in the log view")); "in the log view"));
} }
else { else {
@ -2539,7 +2564,8 @@ static void looper(void)
rlc.set_perform_action(readline_curses::action(rl_callback)); rlc.set_perform_action(readline_curses::action(rl_callback));
rlc.set_timeout_action(readline_curses::action(rl_search)); rlc.set_timeout_action(readline_curses::action(rl_search));
rlc.set_alt_value(HELP_MSG_2( rlc.set_alt_value(HELP_MSG_2(
e, E, "to move forward/backward through error messages")); e, E,
"to move forward/backward through error messages"));
(void)curs_set(0); (void)curs_set(0);
@ -2677,9 +2703,8 @@ static void looper(void)
toggle_view(&lnav_data.ld_views[LNV_TEXT]); toggle_view(&lnav_data.ld_views[LNV_TEXT]);
lnav_data.ld_views[LNV_TEXT].set_top(vis_line_t(0)); lnav_data.ld_views[LNV_TEXT].set_top(vis_line_t(0));
lnav_data.ld_rl_view->set_alt_value( lnav_data.ld_rl_view->set_alt_value(
HELP_MSG_2(f, F, "to switch to the next/previous file")); HELP_MSG_2(f, F,
"to switch to the next/previous file"));
} }
initial_build = true; initial_build = true;
@ -2802,7 +2827,8 @@ public:
cols.push_back(vtab_column("cs_user_agent", SQLITE3_TEXT)); cols.push_back(vtab_column("cs_user_agent", SQLITE3_TEXT));
}; };
void get_foreign_keys(vector<string> &keys_inout) { void get_foreign_keys(vector<string> &keys_inout)
{
this->log_vtab_impl::get_foreign_keys(keys_inout); this->log_vtab_impl::get_foreign_keys(keys_inout);
keys_inout.push_back("sc_status"); keys_inout.push_back("sc_status");
@ -2821,7 +2847,8 @@ public:
cols.push_back(vtab_column("log_pid", SQLITE_INTEGER)); cols.push_back(vtab_column("log_pid", SQLITE_INTEGER));
}; };
void get_foreign_keys(vector<string> &keys_inout) { void get_foreign_keys(vector<string> &keys_inout)
{
this->log_vtab_impl::get_foreign_keys(keys_inout); this->log_vtab_impl::get_foreign_keys(keys_inout);
keys_inout.push_back("log_pid"); keys_inout.push_back("log_pid");

@ -190,5 +190,4 @@ bool setup_logline_table();
int sql_callback(sqlite3_stmt *stmt); int sql_callback(sqlite3_stmt *stmt);
void execute_search(lnav_view_t view, const std::string &regex); void execute_search(lnav_view_t view, const std::string &regex);
#endif #endif

@ -168,17 +168,23 @@ static string com_save_to(string cmdline, vector<string> &args)
static_root_mem<wordexp_t, wordfree> wordmem; static_root_mem<wordexp_t, wordfree> wordmem;
switch (wordexp(args[1].c_str(), wordmem.inout(), WRDE_NOCMD|WRDE_UNDEF)) { switch (wordexp(args[1].c_str(), wordmem.inout(), WRDE_NOCMD |
WRDE_UNDEF)) {
case WRDE_BADCHAR: case WRDE_BADCHAR:
return "error: invalid filename character"; return "error: invalid filename character";
case WRDE_CMDSUB: case WRDE_CMDSUB:
return "error: command substitution is not allowed"; return "error: command substitution is not allowed";
case WRDE_BADVAL: case WRDE_BADVAL:
return "error: unknown environment variable in file name"; return "error: unknown environment variable in file name";
case WRDE_NOSPACE: case WRDE_NOSPACE:
return "error: out of memory"; return "error: out of memory";
case WRDE_SYNTAX: case WRDE_SYNTAX:
return "error: invalid syntax"; return "error: invalid syntax";
default: default:
break; break;
} }
@ -198,7 +204,7 @@ static string com_save_to(string cmdline, vector<string> &args)
return "error: unable to open file -- " + string(wordmem->we_wordv[0]); return "error: unable to open file -- " + string(wordmem->we_wordv[0]);
} }
textview_curses *tc = lnav_data.ld_view_stack.top(); textview_curses * tc = lnav_data.ld_view_stack.top();
bookmark_vector<vis_line_t> &bv = bookmark_vector<vis_line_t> &bv =
tc->get_bookmarks()[&textview_curses::BM_USER]; tc->get_bookmarks()[&textview_curses::BM_USER];
bookmark_vector<vis_line_t>::iterator iter; bookmark_vector<vis_line_t>::iterator iter;
@ -344,10 +350,11 @@ public:
return retval; return retval;
}; };
std::string to_command(void) { std::string to_command(void)
return ((this->lf_type == logfile_filter::INCLUDE ? {
return (this->lf_type == logfile_filter::INCLUDE ?
"filter-in " : "filter-out ") + "filter-in " : "filter-out ") +
this->lf_id); this->lf_id;
}; };
protected: protected:
@ -637,22 +644,25 @@ static string com_summarize(string cmdline, vector<string> &args)
for (std::vector<string>::iterator iter = other_columns.begin(); for (std::vector<string>::iterator iter = other_columns.begin();
iter != other_columns.end(); iter != other_columns.end();
++iter) { ++iter) {
if (iter != other_columns.begin()) if (iter != other_columns.begin()) {
query += ","; query += ",";
}
query_frag = sqlite3_mprintf(" \"%s\", count(*) as \"count_%s\"", query_frag = sqlite3_mprintf(" \"%s\", count(*) as \"count_%s\"",
iter->c_str(), iter->c_str(),
iter->c_str()); iter->c_str());
query += query_frag; query += query_frag;
} }
if (!other_columns.empty() && !num_columns.empty()) if (!other_columns.empty() && !num_columns.empty()) {
query += ", "; query += ", ";
}
for (std::vector<string>::iterator iter = num_columns.begin(); for (std::vector<string>::iterator iter = num_columns.begin();
iter != num_columns.end(); iter != num_columns.end();
++iter) { ++iter) {
if (iter != num_columns.begin()) if (iter != num_columns.begin()) {
query += ","; query += ",";
}
query_frag = sqlite3_mprintf(" sum(\"%s\"), " query_frag = sqlite3_mprintf(" sum(\"%s\"), "
" min(\"%s\"), " " min(\"%s\"), "
" avg(\"%s\"), " " avg(\"%s\"), "
@ -673,10 +683,12 @@ static string com_summarize(string cmdline, vector<string> &args)
for (std::vector<string>::iterator iter = other_columns.begin(); for (std::vector<string>::iterator iter = other_columns.begin();
iter != other_columns.end(); iter != other_columns.end();
++iter) { ++iter) {
if (iter == other_columns.begin()) if (iter == other_columns.begin()) {
query += " GROUP BY "; query += " GROUP BY ";
else }
else{
query += ","; query += ",";
}
query_frag = sqlite3_mprintf(" \"%s\"", iter->c_str()); query_frag = sqlite3_mprintf(" \"%s\"", iter->c_str());
query += query_frag; query += query_frag;
} }
@ -684,10 +696,12 @@ static string com_summarize(string cmdline, vector<string> &args)
for (std::vector<string>::iterator iter = other_columns.begin(); for (std::vector<string>::iterator iter = other_columns.begin();
iter != other_columns.end(); iter != other_columns.end();
++iter) { ++iter) {
if (iter == other_columns.begin()) if (iter == other_columns.begin()) {
query += " ORDER BY "; query += " ORDER BY ";
else }
else{
query += ","; query += ",";
}
query_frag = sqlite3_mprintf(" \"count_%s\" desc, \"%s\" asc", query_frag = sqlite3_mprintf(" \"count_%s\" desc, \"%s\" asc",
iter->c_str(), iter->c_str(),
iter->c_str()); iter->c_str());
@ -769,9 +783,7 @@ static string com_add_test(string cmdline, vector<string> &args)
{ {
string retval = ""; string retval = "";
if (args.size() == 0) { if (args.size() == 0) {}
}
else if (args.size() > 1) { else if (args.size() > 1) {
retval = "error: not expecting any arguments"; retval = "error: not expecting any arguments";
} }

@ -58,5 +58,4 @@ bool check_experimental(const char *feature_name);
* Ensure that the '.lnav' directory exists. * Ensure that the '.lnav' directory exists.
*/ */
void ensure_dotlnav(void); void ensure_dotlnav(void);
#endif #endif

@ -91,7 +91,8 @@ std::string time_ago(time_t last_time);
struct sha_updater { struct sha_updater {
sha_updater(SHA_CTX *context) : su_context(context) { }; sha_updater(SHA_CTX *context) : su_context(context) { };
void operator()(const std::string &str) { void operator()(const std::string &str)
{
SHA_Update(this->su_context, str.c_str(), str.length()); SHA_Update(this->su_context, str.c_str(), str.length());
} }
@ -102,14 +103,12 @@ std::string hash_string(const std::string &str);
template<typename UnaryFunction, typename Member> template<typename UnaryFunction, typename Member>
struct object_field_t { struct object_field_t {
object_field_t(UnaryFunction &func, Member &mem) object_field_t(UnaryFunction &func, Member &mem)
: of_func(func), of_mem(mem) { : of_func(func), of_mem(mem) {};
};
template<typename Object> template<typename Object>
void operator()(Object obj) { void operator()(Object obj)
{
this->of_func(obj.*(this->of_mem)); this->of_func(obj.*(this->of_mem));
}; };
@ -118,7 +117,9 @@ struct object_field_t {
}; };
template<typename UnaryFunction, typename Member> template<typename UnaryFunction, typename Member>
object_field_t<UnaryFunction, Member> object_field(UnaryFunction &func, Member mem) { object_field_t<UnaryFunction, Member> object_field(UnaryFunction &func,
Member mem)
{
return object_field_t<UnaryFunction, Member>(func, mem); return object_field_t<UnaryFunction, Member>(func, mem);
} }
@ -135,5 +136,4 @@ enum file_format_t {
}; };
file_format_t detect_file_format(const std::string &filename); file_format_t detect_file_format(const std::string &filename);
#endif #endif

@ -47,7 +47,8 @@
class log_data_table : public log_vtab_impl { class log_data_table : public log_vtab_impl {
public: public:
log_data_table(content_line_t template_line, std::string table_name="logline") log_data_table(content_line_t template_line,
std::string table_name = "logline")
: log_vtab_impl(table_name), : log_vtab_impl(table_name),
ldt_template_line(template_line) {}; ldt_template_line(template_line) {};
@ -148,8 +149,8 @@ public:
lf_iter->set_schema(dp.dp_schema_id); lf_iter->set_schema(dp.dp_schema_id);
// The cached schema ID in the log line is not complete, so we still /* The cached schema ID in the log line is not complete, so we still */
// need to check for a full match. /* need to check for a full match. */
if (dp.dp_schema_id != this->ldt_schema_id) { if (dp.dp_schema_id != this->ldt_schema_id) {
return false; return false;
} }
@ -172,7 +173,7 @@ public:
const std::string tmp = this->ldt_current_line.substr( const std::string tmp = this->ldt_current_line.substr(
pvalue.e_capture.c_begin, pvalue.e_capture.length()); pvalue.e_capture.c_begin, pvalue.e_capture.length());
switch(pvalue.value_token()) { switch (pvalue.value_token()) {
case DT_NUMBER: { case DT_NUMBER: {
double d = 0; double d = 0;
@ -180,6 +181,7 @@ public:
values.push_back(logline_value("", d)); values.push_back(logline_value("", d));
} }
break; break;
default: default:
values.push_back(logline_value("", tmp)); values.push_back(logline_value("", tmp));
break; break;

@ -111,12 +111,15 @@ static int strcasestr_i(const char *s1, const char *s2)
logline::level_t logline::string2level(const char *levelstr, bool exact) logline::level_t logline::string2level(const char *levelstr, bool exact)
{ {
logline::level_t retval = logline::LEVEL_UNKNOWN; logline::level_t retval = logline::LEVEL_UNKNOWN;
int (*cmpfunc)(const char *, const char *); int (*cmpfunc)(const char *, const char *);
if (exact) if (exact) {
cmpfunc = strcasecmp; cmpfunc = strcasecmp;
else }
else{
cmpfunc = strcasestr_i; cmpfunc = strcasestr_i;
}
if (cmpfunc(levelstr, "TRACE") == 0) { if (cmpfunc(levelstr, "TRACE") == 0) {
retval = logline::LEVEL_TRACE; retval = logline::LEVEL_TRACE;

@ -95,7 +95,8 @@ public:
ll_time(t), ll_time(t),
ll_millis(millis), ll_millis(millis),
ll_level(l), ll_level(l),
ll_module(m) { ll_module(m)
{
memset(this->ll_schema, 0, sizeof(this->ll_schema)); memset(this->ll_schema, 0, sizeof(this->ll_schema));
}; };
@ -130,11 +131,12 @@ public:
/** /**
* @return True if there is a schema value set for this log line. * @return True if there is a schema value set for this log line.
*/ */
bool has_schema(void) const { bool has_schema(void) const
return (this->ll_schema[0] != 0 || {
return this->ll_schema[0] != 0 ||
this->ll_schema[1] != 0 || this->ll_schema[1] != 0 ||
this->ll_schema[2] != 0 || this->ll_schema[2] != 0 ||
this->ll_schema[3] != 0); this->ll_schema[3] != 0;
}; };
/** /**
@ -144,7 +146,8 @@ public:
* *
* @param ba The SHA-1 hash of the constant parts of this log line. * @param ba The SHA-1 hash of the constant parts of this log line.
*/ */
void set_schema(const byte_array<20> &ba) { void set_schema(const byte_array<20> &ba)
{
memcpy(this->ll_schema, ba.in(), sizeof(this->ll_schema)); memcpy(this->ll_schema, ba.in(), sizeof(this->ll_schema));
}; };
@ -157,7 +160,8 @@ public:
* @return True if the first four bytes of the given schema match the * @return True if the first four bytes of the given schema match the
* schema stored in this log line. * schema stored in this log line.
*/ */
bool match_schema(const byte_array<20> &ba) const { bool match_schema(const byte_array<20> &ba) const
{
return memcmp(this->ll_schema, ba.in(), sizeof(this->ll_schema)) == 0; return memcmp(this->ll_schema, ba.in(), sizeof(this->ll_schema)) == 0;
} }

@ -156,8 +156,7 @@ class access_log_format : public log_format {
logline_value::VALUE_TEXT }, logline_value::VALUE_TEXT },
{ "cs_username", { "cs_username",
logline_value::VALUE_TEXT }, logline_value::VALUE_TEXT },
{ "", { "", },
},
{ "cs_method", { "cs_method",
logline_value::VALUE_TEXT }, logline_value::VALUE_TEXT },
{ "cs_uri_stem", { "cs_uri_stem",

@ -418,7 +418,7 @@ string log_vtab_manager::register_vtab(log_vtab_impl *vi)
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> errmsg(sqlite3_free); auto_mem<char> errmsg(sqlite3_free);
char *sql; char * sql;
int rc; int rc;
this->vm_impls[vi->get_name()] = vi; this->vm_impls[vi->get_name()] = vi;

@ -101,7 +101,8 @@ public:
virtual void get_columns(std::vector<vtab_column> &cols) { }; virtual void get_columns(std::vector<vtab_column> &cols) { };
virtual void get_foreign_keys(std::vector<std::string> &keys_inout) { virtual void get_foreign_keys(std::vector<std::string> &keys_inout)
{
keys_inout.push_back("log_line"); keys_inout.push_back("log_line");
}; };
@ -140,11 +141,13 @@ public:
return this->vm_impls[name]; return this->vm_impls[name];
}; };
iterator begin() const { iterator begin() const
{
return this->vm_impls.begin(); return this->vm_impls.begin();
}; };
iterator end() const { iterator end() const
{
return this->vm_impls.end(); return this->vm_impls.end();
}; };

@ -90,7 +90,7 @@ public:
class observer class observer
: public logfile_observer { : public logfile_observer {
public: public:
virtual void logfile_sub_source_filtering(logfile_sub_source &lss, virtual void logfile_sub_source_filtering(logfile_sub_source &lss,
content_line_t cl, content_line_t cl,
size_t total) = 0; size_t total) = 0;
@ -252,7 +252,8 @@ public:
} }
}; };
void set_user_mark(bookmark_type_t *bm, content_line_t cl) { void set_user_mark(bookmark_type_t *bm, content_line_t cl)
{
this->lss_user_marks[bm].insert_once(cl); this->lss_user_marks[bm].insert_once(cl);
}; };
@ -330,11 +331,13 @@ public:
typedef std::vector<logfile_data>::iterator iterator; typedef std::vector<logfile_data>::iterator iterator;
iterator begin() { iterator begin()
{
return this->lss_files.begin(); return this->lss_files.begin();
}; };
iterator end() { iterator end()
{
return this->lss_files.end(); return this->lss_files.end();
}; };

@ -47,6 +47,7 @@ pcre_jit_stack *pcrepp::jit_stack(void)
return retval; return retval;
} }
#else #else
#warning "pcrejit is not available, search performance will be degraded" #warning "pcrejit is not available, search performance will be degraded"

@ -191,7 +191,8 @@ public:
iter->length()); iter->length());
}; };
void reset(const char *str, size_t off = 0, size_t len = -1) { void reset(const char *str, size_t off = 0, size_t len = -1)
{
this->pi_string = str; this->pi_string = str;
this->pi_offset = off; this->pi_offset = off;
this->pi_next_offset = off; this->pi_next_offset = off;
@ -203,7 +204,8 @@ public:
} }
} }
void reset(const std::string &str, size_t off = 0) { void reset(const std::string &str, size_t off = 0)
{
this->reset(str.c_str(), off, str.length()); this->reset(str.c_str(), off, str.length());
} }
@ -237,7 +239,8 @@ public:
this->study(); this->study();
}; };
pcrepp(const char *pattern, int options = 0) : p_code_extra(pcre_free_study) pcrepp(const char *pattern, int options =
0) : p_code_extra(pcre_free_study)
{ {
const char *errptr; const char *errptr;
int eoff; int eoff;
@ -302,6 +305,7 @@ public:
switch (rc) { switch (rc) {
case PCRE_ERROR_NOMATCH: case PCRE_ERROR_NOMATCH:
break; break;
default: default:
fprintf(stderr, "pcre err %d\n", rc); fprintf(stderr, "pcre err %d\n", rc);
break; break;
@ -333,13 +337,15 @@ public:
#ifdef PCRE_STUDY_JIT_COMPILE #ifdef PCRE_STUDY_JIT_COMPILE
static pcre_jit_stack *jit_stack(void); static pcre_jit_stack *jit_stack(void);
#else #else
static void pcre_free_study(pcre_extra *); static void pcre_free_study(pcre_extra *);
#endif #endif
private: private:
void study(void) { void study(void)
{
const char *errptr; const char *errptr;
this->p_code_extra = pcre_study(this->p_code, this->p_code_extra = pcre_study(this->p_code,
@ -355,7 +361,7 @@ private:
if (this->p_code_extra != NULL) { if (this->p_code_extra != NULL) {
pcre_extra *extra = this->p_code_extra; pcre_extra *extra = this->p_code_extra;
extra->flags |= (PCRE_EXTRA_MATCH_LIMIT| extra->flags |= (PCRE_EXTRA_MATCH_LIMIT |
PCRE_EXTRA_MATCH_LIMIT_RECURSION); PCRE_EXTRA_MATCH_LIMIT_RECURSION);
extra->match_limit = 10000; extra->match_limit = 10000;
extra->match_limit_recursion = 500; extra->match_limit_recursion = 500;

@ -200,13 +200,17 @@ public:
void set_perform_action(action va) { this->rc_perform = va; }; void set_perform_action(action va) { this->rc_perform = va; };
void set_timeout_action(action va) { this->rc_timeout = va; }; void set_timeout_action(action va) { this->rc_timeout = va; };
void set_value(const std::string &value) { void set_value(const std::string &value)
{
this->rc_value = value; this->rc_value = value;
this->rc_value_expiration = time(NULL) + VALUE_EXPIRATION; this->rc_value_expiration = time(NULL) + VALUE_EXPIRATION;
}; };
std::string get_value() const { return this->rc_value; }; std::string get_value() const { return this->rc_value; };
void set_alt_value(const std::string &value) { this->rc_alt_value = value; }; void set_alt_value(const std::string &value)
{
this->rc_alt_value = value;
};
std::string get_alt_value() const { return this->rc_alt_value; }; std::string get_alt_value() const { return this->rc_alt_value; };
int update_fd_set(fd_set &readfds) int update_fd_set(fd_set &readfds)
@ -248,7 +252,8 @@ public:
void add_possibility(int context, void add_possibility(int context,
const std::string &type, const std::string &type,
const char *values[]) { const char *values[])
{
for (int lpc = 0; values[lpc]; lpc++) { for (int lpc = 0; values[lpc]; lpc++) {
this->add_possibility(context, type, values[lpc]); this->add_possibility(context, type, values[lpc]);
} }

@ -73,6 +73,7 @@ static string bookmark_file_name(const string &name)
static string latest_bookmark_file(const string &name) static string latest_bookmark_file(const string &name)
{ {
timestamped_list_t file_names; timestamped_list_t file_names;
static_root_mem<glob_t, globfree> file_list; static_root_mem<glob_t, globfree> file_list;
string mark_file_pattern; string mark_file_pattern;
char mark_base_name[256]; char mark_base_name[256];
@ -101,8 +102,9 @@ static string latest_bookmark_file(const string &name)
sort(file_names.begin(), file_names.end()); sort(file_names.begin(), file_names.end());
if (file_names.empty()) if (file_names.empty()) {
return ""; return "";
}
return file_names.back().second; return file_names.back().second;
} }
@ -111,14 +113,16 @@ struct session_file_info {
session_file_info(int timestamp, session_file_info(int timestamp,
const string &id, const string &id,
const string &path) const string &path)
: sfi_timestamp(timestamp), sfi_id(id), sfi_path(path) { : sfi_timestamp(timestamp), sfi_id(id), sfi_path(path) {};
};
bool operator<(const session_file_info &other) const { bool operator<(const session_file_info &other) const
if (this->sfi_timestamp < other.sfi_timestamp) {
if (this->sfi_timestamp < other.sfi_timestamp) {
return true; return true;
if (this->sfi_path < other.sfi_path) }
if (this->sfi_path < other.sfi_path) {
return true; return true;
}
return false; return false;
}; };
@ -221,7 +225,9 @@ void init_session(void)
void scan_sessions(void) void scan_sessions(void)
{ {
std::list<session_pair_t> &session_file_names = lnav_data.ld_session_file_names; std::list<session_pair_t> &session_file_names =
lnav_data.ld_session_file_names;
static_root_mem<glob_t, globfree> view_info_list; static_root_mem<glob_t, globfree> view_info_list;
std::list<session_pair_t>::iterator iter; std::list<session_pair_t>::iterator iter;
char view_info_pattern_base[128]; char view_info_pattern_base[128];
@ -245,7 +251,8 @@ void scan_sessions(void)
"view-info-%s.*.json", "view-info-%s.*.json",
lnav_data.ld_session_id.c_str()); lnav_data.ld_session_id.c_str());
view_info_pattern = dotlnav_path(view_info_pattern_base); view_info_pattern = dotlnav_path(view_info_pattern_base);
if (glob(view_info_pattern.c_str(), 0, NULL, view_info_list.inout()) == 0) { if (glob(view_info_pattern.c_str(), 0, NULL,
view_info_list.inout()) == 0) {
for (size_t lpc = 0; lpc < view_info_list->gl_pathc; lpc++) { for (size_t lpc = 0; lpc < view_info_list->gl_pathc; lpc++) {
const char *path = view_info_list->gl_pathv[lpc]; const char *path = view_info_list->gl_pathv[lpc];
int timestamp, ppid; int timestamp, ppid;
@ -299,6 +306,7 @@ static int read_path(void *ctx, const unsigned char *str, size_t len)
static int read_marks(void *ctx, long long num) static int read_marks(void *ctx, long long num)
{ {
yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx; yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx;
pair<logfile *, content_line_t> *pair; pair<logfile *, content_line_t> *pair;
fprintf(stderr, "read line %qd\n", num); fprintf(stderr, "read line %qd\n", num);
@ -341,8 +349,9 @@ void load_bookmarks(void)
} }
mark_file_name = latest_bookmark_file(log_name.c_str()); mark_file_name = latest_bookmark_file(log_name.c_str());
if (mark_file_name.empty()) if (mark_file_name.empty()) {
continue; continue;
}
fprintf(stderr, "loading %s\n", mark_file_name.c_str()); fprintf(stderr, "loading %s\n", mark_file_name.c_str());
handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc); handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc);
@ -399,7 +408,7 @@ static int read_last_search(void *ctx, const unsigned char *str, size_t len)
static int read_top_line(void *ctx, long long value) static int read_top_line(void *ctx, long long value)
{ {
yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx; yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx;
const char **view_name; const char ** view_name;
int view_index; int view_index;
view_name = find(lnav_view_strings, view_name = find(lnav_view_strings,
@ -409,9 +418,10 @@ static int read_top_line(void *ctx, long long value)
if (view_index < LNV__MAX) { if (view_index < LNV__MAX) {
textview_curses &tc = lnav_data.ld_views[view_index]; textview_curses &tc = lnav_data.ld_views[view_index];
if (value != -1 && value < tc.get_inner_height()) if (value != -1 && value < tc.get_inner_height()) {
tc.set_top(vis_line_t(value)); tc.set_top(vis_line_t(value));
} }
}
return 1; return 1;
} }
@ -479,13 +489,16 @@ static void yajl_writer(void *context, const char *str, size_t len)
void save_bookmarks(void) void save_bookmarks(void)
{ {
logfile_sub_source &lss = lnav_data.ld_log_source; logfile_sub_source &lss = lnav_data.ld_log_source;
bookmarks<content_line_t>::type &bm = lss.get_user_bookmarks();
bookmark_vector<content_line_t> &user_marks = bm[&textview_curses::BM_USER]; bookmarks<content_line_t>::type &bm =
lss.get_user_bookmarks();
bookmark_vector<content_line_t> &user_marks =
bm[&textview_curses::BM_USER];
logfile_sub_source::iterator file_iter; logfile_sub_source::iterator file_iter;
bookmark_vector<content_line_t>::iterator iter; bookmark_vector<content_line_t>::iterator iter;
string mark_file_name, mark_file_tmp_name; string mark_file_name, mark_file_tmp_name;
auto_mem<FILE> file(fclose); auto_mem<FILE> file(fclose);
logfile *curr_lf = NULL; logfile * curr_lf = NULL;
yajl_gen handle = NULL; yajl_gen handle = NULL;
for (file_iter = lnav_data.ld_log_source.begin(); for (file_iter = lnav_data.ld_log_source.begin();
@ -524,11 +537,10 @@ void save_bookmarks(void)
for (iter = user_marks.begin(); iter != user_marks.end(); ++iter) { for (iter = user_marks.begin(); iter != user_marks.end(); ++iter) {
content_line_t cl = *iter; content_line_t cl = *iter;
logfile *lf; logfile * lf;
lf = lss.find(cl); lf = lss.find(cl);
if (curr_lf != lf) { if (curr_lf != lf) {
if (handle) { if (handle) {
yajl_gen_array_close(handle); yajl_gen_array_close(handle);
yajl_gen_map_close(handle); yajl_gen_map_close(handle);
@ -571,6 +583,7 @@ void save_bookmarks(void)
void save_session(void) void save_session(void)
{ {
string view_file_name, view_file_tmp_name; string view_file_name, view_file_tmp_name;
auto_mem<FILE> file(fclose); auto_mem<FILE> file(fclose);
char view_base_name[256]; char view_base_name[256];
yajl_gen handle = NULL; yajl_gen handle = NULL;
@ -612,7 +625,8 @@ void save_session(void)
for_each(lnav_data.ld_file_names.begin(), for_each(lnav_data.ld_file_names.begin(),
lnav_data.ld_file_names.end(), lnav_data.ld_file_names.end(),
object_field(file_list.gen, &pair<string, int>::first)); object_field(file_list.gen,
&pair<string, int>::first));
} }
root_map.gen("views"); root_map.gen("views");
@ -632,10 +646,12 @@ void save_session(void)
view_map.gen("top_line"); view_map.gen("top_line");
tc.get_dimensions(height, width); tc.get_dimensions(height, width);
if ((tc.get_top() + height) > tc.get_inner_height()) if ((tc.get_top() + height) > tc.get_inner_height()) {
view_map.gen(-1); view_map.gen(-1);
else }
else{
view_map.gen((long long)tc.get_top()); view_map.gen((long long)tc.get_top());
}
view_map.gen("search"); view_map.gen("search");
view_map.gen(lnav_data.ld_last_search[lpc]); view_map.gen(lnav_data.ld_last_search[lpc]);
@ -654,20 +670,23 @@ void save_session(void)
for (filter_iter = fs.begin(); for (filter_iter = fs.begin();
filter_iter != fs.end(); filter_iter != fs.end();
++filter_iter) { ++filter_iter) {
if (!(*filter_iter)->is_enabled()) if (!(*filter_iter)->is_enabled()) {
continue; continue;
}
cmd_array.gen((*filter_iter)->to_command()); cmd_array.gen((*filter_iter)->to_command());
} }
textview_curses::highlight_map_t &hmap = lnav_data.ld_views[LNV_LOG].get_highlights(); textview_curses::highlight_map_t &hmap =
lnav_data.ld_views[LNV_LOG].get_highlights();
textview_curses::highlight_map_t::iterator hl_iter; textview_curses::highlight_map_t::iterator hl_iter;
for (hl_iter = hmap.begin(); for (hl_iter = hmap.begin();
hl_iter != hmap.end(); hl_iter != hmap.end();
++hl_iter) { ++hl_iter) {
if (hl_iter->first[0] == '$') if (hl_iter->first[0] == '$') {
continue; continue;
}
cmd_array.gen("highlight " + hl_iter->first); cmd_array.gen("highlight " + hl_iter->first);
} }
} }
@ -684,7 +703,8 @@ void save_session(void)
void reset_session(void) void reset_session(void)
{ {
textview_curses::highlight_map_t &hmap = lnav_data.ld_views[LNV_LOG].get_highlights(); textview_curses::highlight_map_t &hmap =
lnav_data.ld_views[LNV_LOG].get_highlights();
textview_curses::highlight_map_t::iterator hl_iter = hmap.begin(); textview_curses::highlight_map_t::iterator hl_iter = hmap.begin();
save_session(); save_session();

@ -37,5 +37,4 @@ void load_session(void);
void save_session(void); void save_session(void);
void reset_session(void); void reset_session(void);
void scan_sessions(void); void scan_sessions(void);
#endif #endif

@ -168,7 +168,7 @@ const char *sql_keywords[] = {
}; };
const char *sql_function_names[] = { const char *sql_function_names[] = {
// http://www.sqlite.org/lang_aggfunc.html /* http://www.sqlite.org/lang_aggfunc.html */
"avg", "avg",
"count", "count",
"group_concat", "group_concat",
@ -177,7 +177,7 @@ const char *sql_function_names[] = {
"sum", "sum",
"total", "total",
// http://www.sqlite.org/lang_corefunc.html /* http://www.sqlite.org/lang_corefunc.html */
"abs", "abs",
"changes", "changes",
"char", "char",
@ -231,7 +231,7 @@ static int handle_db_list(void *ptr,
struct table_list_data { struct table_list_data {
struct sqlite_metadata_callbacks *tld_callbacks; struct sqlite_metadata_callbacks *tld_callbacks;
db_table_map_t::iterator *tld_iter; db_table_map_t::iterator * tld_iter;
}; };
static int handle_table_list(void *ptr, static int handle_table_list(void *ptr,

@ -57,5 +57,4 @@ struct sqlite_metadata_callbacks {
int walk_sqlite_metadata(sqlite3 *db, struct sqlite_metadata_callbacks &smc); int walk_sqlite_metadata(sqlite3 *db, struct sqlite_metadata_callbacks &smc);
void attach_sqlite_db(sqlite3 *db, const std::string &filename); void attach_sqlite_db(sqlite3 *db, const std::string &filename);
#endif #endif

@ -128,13 +128,14 @@ public:
va_end(args); va_end(args);
}; };
void set_stitch_value(int color_pair) { void set_stitch_value(int color_pair)
string_attrs_t &sa = this->sf_value.get_attrs(); {
string_attrs_t & sa = this->sf_value.get_attrs();
struct line_range lr = { 0, 1 }; struct line_range lr = { 0, 1 };
this->sf_value.get_string() = "::"; this->sf_value.get_string() = "::";
sa[lr].insert(make_string_attr("style", sa[lr].insert(make_string_attr("style",
A_REVERSE|COLOR_PAIR(color_pair))); A_REVERSE | COLOR_PAIR(color_pair)));
lr.lr_start = 1; lr.lr_start = 1;
lr.lr_end = 2; lr.lr_end = 2;
sa[lr].insert(make_string_attr("style", COLOR_PAIR(color_pair))); sa[lr].insert(make_string_attr("style", COLOR_PAIR(color_pair)));

@ -19,8 +19,8 @@
#include "sqlite-extension-func.h" #include "sqlite-extension-func.h"
typedef struct { typedef struct {
char *s; char * s;
pcre *p; pcre * p;
pcre_extra *e; pcre_extra *e;
} cache_entry; } cache_entry;
@ -32,18 +32,18 @@ static
void regexp(sqlite3_context *ctx, int argc, sqlite3_value **argv) void regexp(sqlite3_context *ctx, int argc, sqlite3_value **argv)
{ {
const char *re, *str; const char *re, *str;
pcre *p; pcre * p;
pcre_extra *e; pcre_extra *e;
assert(argc == 2); assert(argc == 2);
re = (const char *) sqlite3_value_text(argv[0]); re = (const char *)sqlite3_value_text(argv[0]);
if (!re) { if (!re) {
sqlite3_result_error(ctx, "no regexp", -1); sqlite3_result_error(ctx, "no regexp", -1);
return; return;
} }
str = (const char *) sqlite3_value_text(argv[1]); str = (const char *)sqlite3_value_text(argv[1]);
if (!str) { if (!str) {
sqlite3_result_error(ctx, "no string", -1); sqlite3_result_error(ctx, "no string", -1);
return; return;

@ -1,4 +1,3 @@
#include "config.h" #include "config.h"
#include <time.h> #include <time.h>

@ -155,7 +155,7 @@ public:
if (this->h_code_extra != NULL) { if (this->h_code_extra != NULL) {
pcre_extra *extra = this->h_code_extra; pcre_extra *extra = this->h_code_extra;
extra->flags |= (PCRE_EXTRA_MATCH_LIMIT| extra->flags |= (PCRE_EXTRA_MATCH_LIMIT |
PCRE_EXTRA_MATCH_LIMIT_RECURSION); PCRE_EXTRA_MATCH_LIMIT_RECURSION);
extra->match_limit = 10000; extra->match_limit = 10000;
extra->match_limit_recursion = 500; extra->match_limit_recursion = 500;
@ -187,7 +187,7 @@ public:
}; };
pcre * h_code; pcre * h_code;
pcre_extra *h_code_extra; pcre_extra * h_code_extra;
bool h_multiple; bool h_multiple;
std::vector<view_colors::role_t> h_roles; std::vector<view_colors::role_t> h_roles;
}; };

@ -62,12 +62,14 @@ public:
this->tss_fields[TSF_VIEW_NAME].set_width(6); this->tss_fields[TSF_VIEW_NAME].set_width(6);
this->tss_fields[TSF_VIEW_NAME].right_justify(true); this->tss_fields[TSF_VIEW_NAME].right_justify(true);
this->tss_fields[TSF_STITCH_VIEW_FORMAT].set_width(2); this->tss_fields[TSF_STITCH_VIEW_FORMAT].set_width(2);
this->tss_fields[TSF_STITCH_VIEW_FORMAT].set_stitch_value(view_colors::VC_CYAN_ON_BLUE); this->tss_fields[TSF_STITCH_VIEW_FORMAT].set_stitch_value(
view_colors::VC_CYAN_ON_BLUE);
this->tss_fields[TSF_STITCH_VIEW_FORMAT].right_justify(true); this->tss_fields[TSF_STITCH_VIEW_FORMAT].right_justify(true);
this->tss_fields[TSF_FORMAT].set_width(13); this->tss_fields[TSF_FORMAT].set_width(13);
this->tss_fields[TSF_FORMAT].right_justify(true); this->tss_fields[TSF_FORMAT].right_justify(true);
this->tss_fields[TSF_STITCH_FORMAT_FILENAME].set_width(2); this->tss_fields[TSF_STITCH_FORMAT_FILENAME].set_width(2);
this->tss_fields[TSF_STITCH_FORMAT_FILENAME].set_stitch_value(view_colors::VC_WHITE_ON_CYAN); this->tss_fields[TSF_STITCH_FORMAT_FILENAME].set_stitch_value(
view_colors::VC_WHITE_ON_CYAN);
this->tss_fields[TSF_STITCH_FORMAT_FILENAME].right_justify(true); this->tss_fields[TSF_STITCH_FORMAT_FILENAME].right_justify(true);
this->tss_fields[TSF_FILENAME].set_min_width(35); /* XXX */ this->tss_fields[TSF_FILENAME].set_min_width(35); /* XXX */
this->tss_fields[TSF_FILENAME].set_share(1); this->tss_fields[TSF_FILENAME].set_share(1);
@ -97,8 +99,8 @@ public:
void update_filename(listview_curses *lc) void update_filename(listview_curses *lc)
{ {
status_field &sf_format = this->tss_fields[TSF_FORMAT]; status_field & sf_format = this->tss_fields[TSF_FORMAT];
status_field &sf_filename = this->tss_fields[TSF_FILENAME]; status_field & sf_filename = this->tss_fields[TSF_FILENAME];
struct line_range lr = { 0, -1 }; struct line_range lr = { 0, -1 };
if (lc->get_inner_height() > 0) { if (lc->get_inner_height() > 0) {
@ -136,7 +138,7 @@ public:
sf_filename.clear(); sf_filename.clear();
} }
sf_format.get_value().get_attrs()[lr].insert( sf_format.get_value().get_attrs()[lr].insert(
make_string_attr("style", A_REVERSE|COLOR_PAIR( make_string_attr("style", A_REVERSE | COLOR_PAIR(
view_colors::VC_CYAN_ON_BLACK))); view_colors::VC_CYAN_ON_BLACK)));
}; };

@ -288,7 +288,8 @@ void view_colors::init(void)
for (int lpc = 0; lpc < 8; lpc++) { for (int lpc = 0; lpc < 8; lpc++) {
short gradient_value = (1000 / 8) * lpc; short gradient_value = (1000 / 8) * lpc;
init_color(lpc + 16, gradient_value, gradient_value, gradient_value); init_color(lpc + 16, gradient_value, gradient_value,
gradient_value);
init_pair(VC_GRADIENT_START + lpc, lpc + 16, COLOR_BLACK); init_pair(VC_GRADIENT_START + lpc, lpc + 16, COLOR_BLACK);
} }
} }

@ -424,11 +424,13 @@ public:
VC_GRADIENT_START, VC_GRADIENT_START,
}; };
static inline int ansi_color_pair_index(int fg, int bg) { static inline int ansi_color_pair_index(int fg, int bg)
{
return VC_ANSI_START + ((fg * 8) + bg); return VC_ANSI_START + ((fg * 8) + bg);
}; };
int ansi_color_pair(int fg, int bg) { int ansi_color_pair(int fg, int bg)
{
return COLOR_PAIR(ansi_color_pair_index(fg, bg)); return COLOR_PAIR(ansi_color_pair_index(fg, bg));
}; };

@ -61,43 +61,49 @@ yajl_gen_status yajl_gen_string(yajl_gen hand, const std::string &str)
} }
struct json_path_handler_base { struct json_path_handler_base {
json_path_handler_base(const char *path) : jph_path(path), jph_regex(path) { json_path_handler_base(const char *path) : jph_path(path), jph_regex(path)
{
memset(&this->jph_callbacks, 0, sizeof(this->jph_callbacks)); memset(&this->jph_callbacks, 0, sizeof(this->jph_callbacks));
}; };
const char *jph_path; const char * jph_path;
pcrepp jph_regex; pcrepp jph_regex;
yajl_callbacks jph_callbacks; yajl_callbacks jph_callbacks;
}; };
struct json_path_handler : public json_path_handler_base { struct json_path_handler : public json_path_handler_base {
json_path_handler(const char *path, int (*null_func)(void *)) json_path_handler(const char *path, int(*null_func)(void *))
: json_path_handler_base(path) { : json_path_handler_base(path)
{
this->jph_callbacks.yajl_null = null_func; this->jph_callbacks.yajl_null = null_func;
}; };
json_path_handler(const char *path, int (*bool_func)(void *, int)) json_path_handler(const char *path, int(*bool_func)(void *, int))
: json_path_handler_base(path) { : json_path_handler_base(path)
{
this->jph_callbacks.yajl_boolean = bool_func; this->jph_callbacks.yajl_boolean = bool_func;
} }
json_path_handler(const char *path, int (*int_func)(void *, long long)) json_path_handler(const char *path, int(*int_func)(void *, long long))
: json_path_handler_base(path) { : json_path_handler_base(path)
{
this->jph_callbacks.yajl_integer = int_func; this->jph_callbacks.yajl_integer = int_func;
} }
json_path_handler(const char *path, int (*double_func)(void *, double)) json_path_handler(const char *path, int(*double_func)(void *, double))
: json_path_handler_base(path) { : json_path_handler_base(path)
{
this->jph_callbacks.yajl_double = double_func; this->jph_callbacks.yajl_double = double_func;
} }
json_path_handler(const char *path, int (*str_func)(void *, const unsigned char *, size_t)) json_path_handler(const char *path,
: json_path_handler_base(path) { int(*str_func)(void *, const unsigned char *, size_t))
: json_path_handler_base(path)
{
this->jph_callbacks.yajl_string = str_func; this->jph_callbacks.yajl_string = str_func;
} }
json_path_handler() : json_path_handler_base("") { json_path_handler() : json_path_handler_base("") {};
};
}; };
class yajlpp_parse_context { class yajlpp_parse_context {
@ -106,15 +112,12 @@ public:
struct json_path_element { struct json_path_element {
json_path_element(int index = 0) : jpe_index(index) { }; json_path_element(int index = 0) : jpe_index(index) { };
json_path_element(const std::string &name) json_path_element(const std::string &name)
: jpe_name(name), jpe_index(0) { : jpe_name(name), jpe_index(0) {};
};
json_path_element(const unsigned char *name) json_path_element(const unsigned char *name)
: jpe_name((const char *)name), jpe_index(0) { : jpe_name((const char *)name), jpe_index(0) {};
}; void set_name(const unsigned char *name, size_t len)
{
void set_name(const unsigned char *name, size_t len) {
this->jpe_name = std::string((const char *)name, len); this->jpe_name = std::string((const char *)name, len);
}; };
@ -122,26 +125,31 @@ public:
int jpe_index; int jpe_index;
}; };
yajlpp_parse_context(struct json_path_handler *handlers) : ypc_handlers(handlers) { yajlpp_parse_context(struct json_path_handler *handlers) : ypc_handlers(
handlers)
{
this->ypc_callbacks = DEFAULT_CALLBACKS; this->ypc_callbacks = DEFAULT_CALLBACKS;
}; };
std::string get_path_fragment(int offset) const { std::string get_path_fragment(int offset) const
{
size_t start, end; size_t start, end;
if (offset < 0) { if (offset < 0) {
offset = this->ypc_path_index_stack.size() + offset; offset = this->ypc_path_index_stack.size() + offset;
} }
start = this->ypc_path_index_stack[offset] + 1; start = this->ypc_path_index_stack[offset] + 1;
if ((offset + 1) < (int)this->ypc_path_index_stack.size()) if ((offset + 1) < (int)this->ypc_path_index_stack.size()) {
end = this->ypc_path_index_stack[offset + 1]; end = this->ypc_path_index_stack[offset + 1];
else }
else{
end = std::string::npos; end = std::string::npos;
}
return this->ypc_path.substr(start, end - start); return this->ypc_path.substr(start, end - start);
}; };
struct json_path_handler *ypc_handlers; struct json_path_handler *ypc_handlers;
void *ypc_userdata; void * ypc_userdata;
yajl_callbacks ypc_callbacks; yajl_callbacks ypc_callbacks;
std::string ypc_path; std::string ypc_path;
std::vector<size_t> ypc_path_index_stack; std::vector<size_t> ypc_path_index_stack;
@ -163,11 +171,13 @@ class yajlpp_generator {
public: public:
yajlpp_generator(yajl_gen handle) : yg_handle(handle) { }; yajlpp_generator(yajl_gen handle) : yg_handle(handle) { };
void operator()(const std::string &str) { void operator()(const std::string &str)
{
yajl_gen_string(this->yg_handle, str); yajl_gen_string(this->yg_handle, str);
}; };
void operator()(long long value) { void operator()(long long value)
{
yajl_gen_integer(this->yg_handle, value); yajl_gen_integer(this->yg_handle, value);
}; };
@ -178,15 +188,15 @@ private:
class yajlpp_container_base { class yajlpp_container_base {
public: public:
yajlpp_container_base(yajl_gen handle) yajlpp_container_base(yajl_gen handle)
: gen(handle), ycb_handle(handle) { : gen(handle), ycb_handle(handle) {};
}; void operator()(const std::string &str)
{
void operator()(const std::string &str) {
yajl_gen_string(this->ycb_handle, str); yajl_gen_string(this->ycb_handle, str);
}; };
void operator()(long long value) { void operator()(long long value)
{
yajl_gen_integer(this->ycb_handle, value); yajl_gen_integer(this->ycb_handle, value);
}; };
@ -197,24 +207,22 @@ protected:
}; };
class yajlpp_map : public yajlpp_container_base { class yajlpp_map : public yajlpp_container_base {
public: public:
yajlpp_map(yajl_gen handle) : yajlpp_container_base(handle) { yajlpp_map(yajl_gen handle) : yajlpp_container_base(handle)
{
yajl_gen_map_open(handle); yajl_gen_map_open(handle);
}; };
~yajlpp_map() { yajl_gen_map_close(this->ycb_handle); }; ~yajlpp_map() { yajl_gen_map_close(this->ycb_handle); };
}; };
class yajlpp_array : public yajlpp_container_base { class yajlpp_array : public yajlpp_container_base {
public: public:
yajlpp_array(yajl_gen handle) : yajlpp_container_base(handle) { yajlpp_array(yajl_gen handle) : yajlpp_container_base(handle)
{
yajl_gen_array_open(handle); yajl_gen_array_open(handle);
}; };
~yajlpp_array() { yajl_gen_array_close(this->ycb_handle); }; ~yajlpp_array() { yajl_gen_array_close(this->ycb_handle); };
}; };
#endif #endif

Loading…
Cancel
Save