diff --git a/lnav.cfg b/lnav.cfg index a589ddbb..216b4099 100644 --- a/lnav.cfg +++ b/lnav.cfg @@ -66,7 +66,7 @@ indent_sing_line_comments = 0 # number indent_switch_case = 0 # number # Spaces to indent 'case' body from 'case' -indent_case_body = 0 # number +indent_case_body = 4 # number # Spaces to indent '{' from 'case' indent_case_brace = 0 # number diff --git a/src/ansi_scrubber.cc b/src/ansi_scrubber.cc index 63f795f5..7cb69840 100644 --- a/src/ansi_scrubber.cc +++ b/src/ansi_scrubber.cc @@ -48,19 +48,20 @@ static pcrepp &ansi_regex(void) void scrub_ansi_string(std::string &str, string_attrs_t &sa) { view_colors &vc = view_colors::singleton(); + vector > attr_queue; pcre_context_static<60> context; - vector range_queue; - pcrepp ®ex = ansi_regex(); + vector range_queue; + pcrepp & regex = ansi_regex(); pcre_input pi(str); while (regex.match(context, pi)) { pcre_context::capture_t *caps = context.all(); - struct line_range lr; + struct line_range lr; bool has_attrs = false; int attrs = 0; - int bg = 0; - int fg = 0; + int bg = 0; + int fg = 0; int lpc; switch (pi.get_substr_start(&caps[2])[0]) { @@ -72,7 +73,7 @@ void scrub_ansi_string(std::string &str, string_attrs_t &sa) if (sscanf(&(str[lpc]), "%d", &ansi_code) == 1) { if (90 <= ansi_code && ansi_code <= 97) { ansi_code -= 60; - attrs |= A_STANDOUT; + attrs |= A_STANDOUT; } if (30 <= ansi_code && ansi_code <= 37) { fg = ansi_code - 30; @@ -110,15 +111,15 @@ void scrub_ansi_string(std::string &str, string_attrs_t &sa) break; case 'C': - { - int spaces = 0; + { + int spaces = 0; - if (sscanf(&(str[caps[1].c_begin]), "%d", &spaces) == 1 && - spaces > 0) { - str.insert(caps[0].c_end, spaces, ' '); - } + if (sscanf(&(str[caps[1].c_begin]), "%d", &spaces) == 1 && + spaces > 0) { + str.insert(caps[0].c_end, spaces, ' '); } - break; + } + break; } str.erase(str.begin() + caps[0].c_begin, str.begin() + caps[0].c_end); diff --git a/src/ansi_scrubber.hh b/src/ansi_scrubber.hh index 93b5cb42..63960cec 100644 --- a/src/ansi_scrubber.hh +++ b/src/ansi_scrubber.hh @@ -36,18 +36,17 @@ #include "view_curses.hh" -#define ANSI_BOLD_START "\x1b[1m" -#define ANSI_NORM "\x1b[0m" +#define ANSI_BOLD_START "\x1b[1m" +#define ANSI_NORM "\x1b[0m" -#define ANSI_BOLD(msg) ANSI_BOLD_START msg ANSI_NORM +#define ANSI_BOLD(msg) ANSI_BOLD_START msg ANSI_NORM /** * Check a string for ANSI escape sequences, process them, remove them, and add * any style attributes to the given attribute container. - * + * * @param str The string to check for ANSI escape sequences. * @param sa The container for any style attributes. */ void scrub_ansi_string(std::string &str, string_attrs_t &sa); - #endif diff --git a/src/auto_mem.hh b/src/auto_mem.hh index 464ace9e..f16baf7e 100644 --- a/src/auto_mem.hh +++ b/src/auto_mem.hh @@ -101,8 +101,9 @@ public: void reset(T *ptr = NULL) { if (this->am_ptr != ptr) { - if (this->am_ptr != NULL) + if (this->am_ptr != NULL) { this->am_free_func(this->am_ptr); + } this->am_ptr = ptr; } }; @@ -112,10 +113,11 @@ private: void (*am_free_func)(void *); }; -template +template class static_root_mem { public: - static_root_mem() { + static_root_mem() + { memset(&this->srm_value, 0, sizeof(T)); }; diff --git a/src/bottom_status_source.hh b/src/bottom_status_source.hh index 527b7ef9..10d23a18 100644 --- a/src/bottom_status_source.hh +++ b/src/bottom_status_source.hh @@ -96,7 +96,8 @@ public: 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); }; diff --git a/src/byte_array.hh b/src/byte_array.hh index e6f26cdf..1956a72f 100644 --- a/src/byte_array.hh +++ b/src/byte_array.hh @@ -55,11 +55,13 @@ struct byte_array { return memcmp(this->ba_data, other.ba_data, BYTE_COUNT) != 0; }; - void clear(void) { + void clear(void) + { memset(this->ba_data, 0, BYTE_COUNT); }; - void to_string(char *buffer) const { + void to_string(char *buffer) const + { assert(buffer != NULL); 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]; this->to_string(buffer); @@ -75,8 +78,8 @@ struct byte_array { } 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]; }; #endif diff --git a/src/collation-functions.cc b/src/collation-functions.cc index 53900a7d..df3134d2 100644 --- a/src/collation-functions.cc +++ b/src/collation-functions.cc @@ -156,7 +156,8 @@ int sql_strnatcasecmp(void *ptr, int register_collation_functions(sqlite3 *db) { 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, sql_strnatcasecmp); diff --git a/src/data_parser.cc b/src/data_parser.cc index e420a3f0..bbc3a7b6 100644 --- a/src/data_parser.cc +++ b/src/data_parser.cc @@ -62,15 +62,18 @@ data_format_state_t dfs_prefix_next(data_format_state_t state, case DT_LANGLE: case DT_RANGLE: break; + default: retval = DFS_ERROR; break; } break; + case DFS_EXPECTING_SEP: case DFS_ERROR: retval = DFS_ERROR; break; + default: break; } @@ -130,6 +133,7 @@ data_format_state_t dfs_comma_next(data_format_state_t state, switch (next_token) { case DT_COMMA: break; + case DT_SEMI: retval = DFS_ERROR; break; @@ -161,15 +165,18 @@ data_format_state_t dfs_comma_next(data_format_state_t state, default: break; } break; + case DFS_EXPECTING_SEP: switch (next_token) { case DT_SEPARATOR: retval = DFS_VALUE; break; + case DT_COMMA: case DT_SEMI: retval = DFS_ERROR; break; + default: break; } break; diff --git a/src/data_parser.hh b/src/data_parser.hh index e5261ce1..28986068 100644 --- a/src/data_parser.hh +++ b/src/data_parser.hh @@ -110,11 +110,12 @@ * into the 'bookmarks' table to create new user bookmarks. */ -#define ELEMENT_LIST_T(var) var("" #var, __FILE__, __LINE__) -#define PUSH_BACK(elem) push_back(elem, __FILE__, __LINE__) -#define POP_FRONT(elem) pop_front(__FILE__, __LINE__) -#define POP_BACK(elem) pop_back(__FILE__, __LINE__) -#define SPLICE(pos, other, first, last) splice(pos, other, first, last, __FILE__, __LINE__) +#define ELEMENT_LIST_T(var) var("" #var, __FILE__, __LINE__) +#define PUSH_BACK(elem) push_back(elem, __FILE__, __LINE__) +#define POP_FRONT(elem) pop_front(__FILE__, __LINE__) +#define POP_BACK(elem) pop_back(__FILE__, __LINE__) +#define SPLICE(pos, other, first, last) splice(pos, other, first, last, \ + __FILE__, __LINE__) template void strip(Container &container, UnaryPredicate p) @@ -142,7 +143,7 @@ struct data_format { : 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_terminator; }; @@ -154,78 +155,78 @@ data_format_state_t dfs_semi_next(data_format_state_t state, data_format_state_t dfs_comma_next(data_format_state_t state, data_token_t next_token); -#define LIST_INIT_TRACE \ - do { \ - if (TRACE_FILE != NULL) { \ - fprintf(TRACE_FILE, \ +#define LIST_INIT_TRACE \ + do { \ + if (TRACE_FILE != NULL) { \ + fprintf(TRACE_FILE, \ "%p %s:%d %s %s\n", \ - this, \ - fn, line, \ - __func__, \ - varname); \ - } \ + this, \ + fn, line, \ + __func__, \ + varname); \ + } \ } while (false) -#define LIST_DEINIT_TRACE \ - do { \ - if (TRACE_FILE != NULL) { \ - fprintf(TRACE_FILE, \ +#define LIST_DEINIT_TRACE \ + do { \ + if (TRACE_FILE != NULL) { \ + fprintf(TRACE_FILE, \ "%p %s:%d %s\n", \ - this, \ - fn, line, \ - __func__); \ - } \ + this, \ + fn, line, \ + __func__); \ + } \ } while (false) -#define ELEMENT_TRACE \ - do { \ - if (TRACE_FILE != NULL) { \ - fprintf(TRACE_FILE, \ - "%p %s:%d %s %s %d:%d\n", \ - this, \ - fn, line, \ - __func__, \ +#define ELEMENT_TRACE \ + do { \ + if (TRACE_FILE != NULL) { \ + fprintf(TRACE_FILE, \ + "%p %s:%d %s %s %d:%d\n", \ + this, \ + fn, line, \ + __func__, \ data_scanner::token2name(elem.e_token), \ - elem.e_capture.c_begin, \ - elem.e_capture.c_end); \ - } \ + elem.e_capture.c_begin, \ + elem.e_capture.c_end); \ + } \ } while (false) -#define LIST_TRACE \ - do { \ - if (TRACE_FILE != NULL) { \ - fprintf(TRACE_FILE, \ +#define LIST_TRACE \ + do { \ + if (TRACE_FILE != NULL) { \ + fprintf(TRACE_FILE, \ "%p %s:%d %s\n", \ - this, \ - fn, line, \ - __func__); \ - } \ + this, \ + fn, line, \ + __func__); \ + } \ } while (false) -#define SPLICE_TRACE \ - do { \ - if (TRACE_FILE != NULL) { \ - fprintf(TRACE_FILE, \ - "%p %s:%d %s %d %p %d:%d\n", \ - this, \ - fn, line, \ - __func__, \ - (int)std::distance(this->begin(), pos), \ - &other, \ +#define SPLICE_TRACE \ + do { \ + if (TRACE_FILE != NULL) { \ + fprintf(TRACE_FILE, \ + "%p %s:%d %s %d %p %d:%d\n", \ + this, \ + fn, line, \ + __func__, \ + (int)std::distance(this->begin(), pos), \ + &other, \ (int)std::distance(other.begin(), first), \ - (int)std::distance(last, other.end())); \ - } \ + (int)std::distance(last, other.end())); \ + } \ } while (false); -#define POINT_TRACE(name) \ - do { \ - if (TRACE_FILE) { \ - fprintf(TRACE_FILE, \ +#define POINT_TRACE(name) \ + do { \ + if (TRACE_FILE) { \ + fprintf(TRACE_FILE, \ "0x0 %s:%d point %s\n", \ - __FILE__, __LINE__, \ - name); \ - } \ - } while(false); + __FILE__, __LINE__, \ + name); \ + } \ + } while (false); class data_parser { public: @@ -235,45 +236,51 @@ public: static FILE *TRACE_FILE; - typedef byte_array schema_id_t; + typedef byte_array schema_id_t; struct element; - // typedef std::list element_list_t; + /* typedef std::list element_list_t; */ class element_list_t : public std::list { - public: - element_list_t(const char *varname, const char *fn, int line) { +public: + element_list_t(const char *varname, const char *fn, int line) + { LIST_INIT_TRACE; } - element_list_t() { + element_list_t() + { const char *varname = "_anon2_"; - const char *fn = __FILE__; - int line = __LINE__; + const char *fn = __FILE__; + int line = __LINE__; LIST_INIT_TRACE; }; - ~element_list_t() { - const char *fn = __FILE__; - int line = __LINE__; + ~element_list_t() + { + const char *fn = __FILE__; + int line = __LINE__; 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; this->std::list::push_back(elem); }; - void pop_front(const char *fn, int line) { + void pop_front(const char *fn, int line) + { LIST_TRACE; this->std::list::pop_front(); }; - void pop_back(const char *fn, int line) { + void pop_back(const char *fn, int line) + { LIST_TRACE; this->std::list::pop_back(); @@ -284,7 +291,8 @@ public: iterator first, iterator last, const char *fn, - int line) { + int line) + { SPLICE_TRACE; this->std::list::splice(pos, other, first, last); @@ -340,7 +348,8 @@ public: void assign_elements(element_list_t &subs) { 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->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); return this->e_sub_elements->back(); @@ -452,7 +462,8 @@ private: : dp_errors("dp_errors", __FILE__, __LINE__), dp_pairs("dp_pairs", __FILE__, __LINE__), dp_format(NULL), - dp_scanner(ds) { + dp_scanner(ds) + { if (TRACE_FILE != NULL) { fprintf(TRACE_FILE, "input %s\n", ds->get_input().get_string()); } @@ -461,8 +472,10 @@ private: void pairup(schema_id_t *schema, element_list_t &pairs_out, 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); - SHA_CTX context; + 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; POINT_TRACE("pairup_start"); @@ -530,8 +543,8 @@ private: if (el_stack.size() > 1 && this->dp_format->df_appender != DT_INVALID && this->dp_format->df_terminator != DT_INVALID) { - // If we're expecting a terminator and haven't found it - // then this is part of the value. + /* If we're expecting a terminator and haven't found it */ + /* then this is part of the value. */ continue; } @@ -601,7 +614,8 @@ private: struct element blank; 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; free_pair_subs.PUSH_BACK(blank); free_pair_subs.PUSH_BACK(el_stack.front()); @@ -637,7 +651,8 @@ private: struct element blank; 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; free_pair_subs.PUSH_BACK(blank); free_pair_subs.PUSH_BACK(free_row.front()); @@ -751,9 +766,9 @@ private: this->dp_group_token.push_back(DT_INVALID); this->dp_group_stack.resize(1); - data_format_state_t prefix_state = DFS_INIT; - data_format_state_t semi_state = DFS_INIT; - data_format_state_t comma_state = DFS_INIT; + data_format_state_t prefix_state = DFS_INIT; + data_format_state_t semi_state = DFS_INIT; + data_format_state_t comma_state = DFS_INIT; memset(hist, 0, sizeof(hist)); while (this->dp_scanner->tokenize(pc, elem.e_token)) { @@ -767,14 +782,16 @@ private: assert(elem.e_capture.c_begin != -1); assert(elem.e_capture.c_end != -1); - prefix_state = dfs_prefix_next(prefix_state, elem.e_token); - semi_state = dfs_semi_next(semi_state, elem.e_token); - comma_state = dfs_comma_next(comma_state, elem.e_token); + prefix_state = dfs_prefix_next(prefix_state, elem.e_token); + semi_state = dfs_semi_next(semi_state, elem.e_token); + comma_state = dfs_comma_next(comma_state, elem.e_token); if (prefix_state != DFS_ERROR) { - if (semi_state == DFS_ERROR) + if (semi_state == DFS_ERROR) { semi_state = DFS_INIT; - if (comma_state == DFS_ERROR) + } + if (comma_state == DFS_ERROR) { comma_state = DFS_INIT; + } } hist[elem.e_token] += 1; switch (elem.e_token) { @@ -783,7 +800,9 @@ private: case DT_LCURLY: case DT_LSQUARE: 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; case DT_RPAREN: diff --git a/src/data_scanner.cc b/src/data_scanner.cc index 337c6d61..7a6fb56f 100644 --- a/src/data_scanner.cc +++ b/src/data_scanner.cc @@ -46,11 +46,12 @@ static struct { "(?:u|r)?'((?:\\\\.|[^'])+)')"), }, { "url", pcrepp("\\A([\\w]+://[^\\s'\"\\[\\](){}]+[a-zA-Z0-9\\-=&])"), }, - { "path", pcrepp("\\A((?:/|\\./|\\.\\./)[\\w\\.\\-_\\~/]*)"), }, + { "path", pcrepp("\\A((?:/|\\./|\\.\\./)[\\w\\.\\-_\\~/]*)"), + }, { "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( - "\\A(\\d?\\d:\\d\\d(:\\d\\d)?(:\\d\\d)?([,.]\\d{3})?)\\b"), }, /* XXX be more specific */ + "\\A(\\d?\\d:\\d\\d(:\\d\\d)?(:\\d\\d)?([,.]\\d{3})?)\\b"), }, /* XXX be more specific */ /* { "qual", pcrepp("\\A([^\\s:=]+:[^\\s:=,]+(?!,)(?::[^\\s:=,]+)*)"), }, */ { "ipv6", pcrepp("\\A(::|[:\\da-fA-f\\.]+[a-fA-f\\d])"), }, @@ -85,7 +86,7 @@ static struct { { "ipv4", pcrepp("\\A(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})"), }, { "uuid", pcrepp( - "\\A([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})"), }, + "\\A([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})"), }, { "vers", pcrepp("\\A([0-9]+(?:\\.[0-9]+){2,}\\b)"), }, @@ -94,19 +95,20 @@ static struct { { "pcnt", pcrepp("\\A(-?[0-9]+(\\.[0-9]+)?[ ]*%\\b)"), }, { "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]+)" - "\\b(?![\\._\\-][a-zA-Z])"), - }, + "\\b(?![\\._\\-][a-zA-Z])"), }, - { "mail", pcrepp("\\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") }, + { "mail", pcrepp( + "\\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( - "\\A([a-zA-Z][a-z']+(?=[\\s\\(\\)!\\*:;'\\\"\\?,]|[\\.\\!,\\?]\\s|$))"), }, + "\\A([a-zA-Z][a-z']+(?=[\\s\\(\\)!\\*:;'\\\"\\?,]|[\\.\\!,\\?]\\s|$))"), + }, { "sym", pcrepp( - "\\A([^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+" - "(?:::[^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+)*)"), + "\\A([^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+" + "(?:::[^\";\\s:=,\\(\\)\\{\\}\\[\\]\\+#!@%\\^&\\*'\\?<>\\~`\\|\\\\]+)*)"), }, { "line", pcrepp("\\A(\r?\n|\r|;)"), }, @@ -170,8 +172,8 @@ static void single_char_capture(pcre_context &pc, pcre_input &pi) { pc.all()[0].c_begin = pi.pi_offset; - pc.all()[0].c_end = pi.pi_offset + 1; - pc.all()[1] = pc.all()[0]; + pc.all()[0].c_end = pi.pi_offset + 1; + pc.all()[1] = pc.all()[0]; pc.set_count(2); pi.pi_next_offset = pi.pi_offset + 1; } @@ -179,8 +181,8 @@ void single_char_capture(pcre_context &pc, pcre_input &pi) bool data_scanner::tokenize(pcre_context &pc, data_token_t &token_out) { const char *str = this->ds_pcre_input.get_string(); - pcre_input &pi = this->ds_pcre_input; - int lpc; + pcre_input &pi = this->ds_pcre_input; + int lpc; token_out = data_token_t(-1); @@ -246,7 +248,7 @@ bool data_scanner::tokenize(pcre_context &pc, data_token_t &token_out) if (str[pi.pi_offset] == ':' || str[pi.pi_offset] == '=') { - token_out = data_token_t(DT_SEPARATOR); + token_out = data_token_t(DT_SEPARATOR); single_char_capture(pc, pi); return true; } @@ -257,7 +259,7 @@ bool data_scanner::tokenize(pcre_context &pc, data_token_t &token_out) pi.pi_offset = pi.pi_next_offset; if (str[pi.pi_offset] == ',') { - token_out = data_token_t(DT_COMMA); + token_out = data_token_t(DT_COMMA); single_char_capture(pc, pi); return true; } @@ -268,7 +270,7 @@ bool data_scanner::tokenize(pcre_context &pc, data_token_t &token_out) pi.pi_offset = pi.pi_next_offset; if (str[pi.pi_offset] == ';') { - token_out = data_token_t(DT_SEMI); + token_out = data_token_t(DT_SEMI); single_char_capture(pc, pi); return true; } diff --git a/src/fs-extension-functions.cc b/src/fs-extension-functions.cc index 213038ea..1ba7ad5e 100644 --- a/src/fs-extension-functions.cc +++ b/src/fs-extension-functions.cc @@ -44,7 +44,7 @@ static void sql_basename(sqlite3_context *context, int argc, sqlite3_value **argv) { const char *path_in; - int text_end = -1; + int text_end = -1; if (sqlite3_value_type(argv[0]) == SQLITE_NULL) { sqlite3_result_null(context); @@ -86,7 +86,7 @@ static void sql_dirname(sqlite3_context *context, int argc, sqlite3_value **argv) { const char *path_in; - int text_end; + int text_end; if (sqlite3_value_type(argv[0]) == SQLITE_NULL) { sqlite3_result_null(context); @@ -124,7 +124,7 @@ static void sql_joinpath(sqlite3_context *context, int argc, sqlite3_value **argv) { std::string full_path; - int lpc; + int lpc; if (argc == 0) { sqlite3_result_null(context); @@ -161,15 +161,15 @@ int fs_extension_functions(const struct FuncDef **basic_funcs, const struct FuncDefAgg **agg_funcs) { static const struct FuncDef fs_funcs[] = { - { "basename", 1, 0, SQLITE_UTF8, 0, sql_basename }, - { "dirname", 1, 0, SQLITE_UTF8, 0, sql_dirname }, + { "basename", 1, 0, SQLITE_UTF8, 0, sql_basename }, + { "dirname", 1, 0, SQLITE_UTF8, 0, sql_dirname }, { "joinpath", -1, 0, SQLITE_UTF8, 0, sql_joinpath }, { NULL } }; *basic_funcs = fs_funcs; - *agg_funcs = NULL; + *agg_funcs = NULL; return SQLITE_OK; } diff --git a/src/lnav.cc b/src/lnav.cc index b745a206..392d8c0d 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -382,7 +382,7 @@ struct sqlite_metadata_callbacks lnav_sql_meta_callbacks = { bool setup_logline_table() { textview_curses &log_view = lnav_data.ld_views[LNV_LOG]; - bool retval = false; + bool retval = false; if (log_view.get_inner_height()) { vis_line_t vl = log_view.get_top(); @@ -479,9 +479,9 @@ private: static void rebuild_hist(size_t old_count, bool force) { - textview_curses & hist_view = lnav_data.ld_views[LNV_HISTOGRAM]; - logfile_sub_source &lss = lnav_data.ld_log_source; - size_t new_count = lss.text_line_count(); + textview_curses & hist_view = lnav_data.ld_views[LNV_HISTOGRAM]; + logfile_sub_source &lss = lnav_data.ld_log_source; + size_t new_count = lss.text_line_count(); hist_source &hs = lnav_data.ld_hist_source; int zoom_level = lnav_data.ld_hist_zoom; time_t old_time; @@ -725,7 +725,8 @@ static bool append_default_files(lnav_flags_t flag) perror("Unable to resolve path"); } 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; } } @@ -779,12 +780,14 @@ static void update_view_name(void) status_field &sf = lnav_data.ld_top_source.statusview_value_for_field( 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 }; sf.set_value("% 5s ", view_names[tc - lnav_data.ld_views]); 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) @@ -912,8 +915,8 @@ static void copy_to_xclip(void) bookmark_vector &bv = tc->get_bookmarks()[&textview_curses::BM_USER]; bookmark_vector::iterator iter; - FILE * pfile = NULL; - int line_count = 0; + FILE * pfile = NULL; + int line_count = 0; string line; /* XXX : Check if this is linux or MAC. Probably not the best solution but */ @@ -963,24 +966,24 @@ static void handle_paging_key(int ch) switch (ch) { case 'q': case 'Q': - { - string msg = ""; - - if (tc == &lnav_data.ld_views[LNV_DB]) { - msg = HELP_MSG_2(v, V, "to switch to the SQL result view"); - } - else if (tc == &lnav_data.ld_views[LNV_HISTOGRAM]) { - msg = HELP_MSG_2(i, I, "to switch to the histogram view"); - } - else if (tc == &lnav_data.ld_views[LNV_TEXT]) { - msg = HELP_MSG_1(t, "to switch to the text file view"); - } - else if (tc == &lnav_data.ld_views[LNV_GRAPH]) { - msg = HELP_MSG_1(g, "to switch to the graph view"); - } + { + string msg = ""; - lnav_data.ld_rl_view->set_alt_value(msg); + if (tc == &lnav_data.ld_views[LNV_DB]) { + msg = HELP_MSG_2(v, V, "to switch to the SQL result view"); + } + else if (tc == &lnav_data.ld_views[LNV_HISTOGRAM]) { + msg = HELP_MSG_2(i, I, "to switch to the histogram view"); + } + else if (tc == &lnav_data.ld_views[LNV_TEXT]) { + msg = HELP_MSG_1(t, "to switch to the text file view"); + } + else if (tc == &lnav_data.ld_views[LNV_GRAPH]) { + msg = HELP_MSG_1(g, "to switch to the graph view"); } + + lnav_data.ld_rl_view->set_alt_value(msg); + } lnav_data.ld_view_stack.pop(); if (lnav_data.ld_view_stack.empty() || (lnav_data.ld_view_stack.size() == 1 && @@ -1013,7 +1016,8 @@ static void handle_paging_key(int ch) &logfile_sub_source::BM_ERRORS, tc->get_top()); 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; case 'E': @@ -1021,7 +1025,8 @@ static void handle_paging_key(int ch) &logfile_sub_source::BM_ERRORS, tc->get_top()); 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; case 'w': @@ -1029,7 +1034,8 @@ static void handle_paging_key(int ch) &logfile_sub_source::BM_WARNINGS, tc->get_top()); 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; case 'W': @@ -1037,7 +1043,8 @@ static void handle_paging_key(int ch) &logfile_sub_source::BM_WARNINGS, tc->get_top()); 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; case 'n': @@ -1146,7 +1153,8 @@ static void handle_paging_key(int ch) } 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; @@ -1161,7 +1169,8 @@ static void handle_paging_key(int ch) } 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; @@ -1183,7 +1192,8 @@ static void handle_paging_key(int ch) tc->reload_data(); 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; @@ -1214,7 +1224,8 @@ static void handle_paging_key(int ch) tc->reload_data(); 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; @@ -1247,7 +1258,8 @@ static void handle_paging_key(int ch) tc->reload_data(); 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; @@ -1260,7 +1272,7 @@ static void handle_paging_key(int ch) else { int start_line = min( (int)tc->get_top(), lnav_data.ld_last_user_mark[tc] + 1); - int end_line = max( + int end_line = max( (int)tc->get_top(), lnav_data.ld_last_user_mark[tc] - 1); lss->toggle_user_mark(&textview_curses::BM_USER, @@ -1405,13 +1417,14 @@ static void handle_paging_key(int ch) case ':': if (lnav_data.ld_views[LNV_LOG].get_inner_height() > 0) { - logfile_sub_source &lss = lnav_data.ld_log_source; - textview_curses &log_view = lnav_data.ld_views[LNV_LOG]; - content_line_t cl = lss.at(log_view.get_top()); - logfile * lf = lss.find(cl); - std::string line = lf->read_line(lf->begin() + cl); - struct line_range body; - string_attrs_t sa; + logfile_sub_source &lss = lnav_data.ld_log_source; + textview_curses & log_view = lnav_data.ld_views[LNV_LOG]; + content_line_t cl = lss.at(log_view.get_top()); + logfile * lf = lss.find(cl); + std::string line = lf->read_line( + lf->begin() + cl); + struct line_range body; + string_attrs_t sa; std::vector line_values; lf->get_format()->annotate(line, sa, line_values); @@ -1422,19 +1435,22 @@ static void handle_paging_key(int ch) } data_scanner ds(line); - data_parser dp(&ds); + data_parser dp(&ds); dp.parse(); column_namer namer; 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) { - 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); - lnav_data.ld_rl_view->add_possibility(LNM_COMMAND, "colname", colname); + colname = namer.add_column(colname); + lnav_data.ld_rl_view->add_possibility(LNM_COMMAND, "colname", + colname); } } 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])) { 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; @@ -1631,26 +1648,33 @@ static void handle_paging_key(int ch) break; 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(); reset_session(); load_session(); rebuild_indexes(true); break; + case 'R': - if (lnav_data.ld_session_file_index == 0) - lnav_data.ld_session_file_index = lnav_data.ld_session_file_names.size() - 1; - else + if (lnav_data.ld_session_file_index == 0) { + lnav_data.ld_session_file_index = + lnav_data.ld_session_file_names.size() - 1; + } + else{ lnav_data.ld_session_file_index -= 1; + } reset_session(); load_session(); rebuild_indexes(true); break; + case KEY_CTRL_R: reset_session(); rebuild_indexes(true); 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; default: @@ -1794,7 +1818,7 @@ int sql_callback(sqlite3_stmt *stmt) void execute_search(lnav_view_t view, const std::string ®ex) { auto_ptr &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])) { const char *errptr; @@ -1846,12 +1870,12 @@ void execute_search(lnav_view_t view, const std::string ®ex) tc.set_follow_search(true); - auto_ptr gh(new grep_highlighter(gp, "$search", hm)); + auto_ptr gh(new grep_highlighter(gp, "$search", + hm)); gc = gh; - } } - + lnav_data.ld_last_search[view] = regex; } @@ -1893,8 +1917,7 @@ static void rl_search(void *dummy, readline_curses *rc) grep_error(string("sql error: ") + string(errmsg)); } else { - lnav_data.ld_bottom_source. - grep_error(""); + lnav_data.ld_bottom_source.grep_error(""); } } return; @@ -1904,8 +1927,8 @@ static void rl_search(void *dummy, readline_curses *rc) break; } - textview_curses *tc = lnav_data.ld_view_stack.top(); - lnav_view_t index = (lnav_view_t)(tc - lnav_data.ld_views); + textview_curses *tc = lnav_data.ld_view_stack.top(); + lnav_view_t index = (lnav_view_t)(tc - lnav_data.ld_views); tc->set_top(lnav_data.ld_search_start_line); execute_search(index, rc->get_value()); @@ -1914,7 +1937,7 @@ static void rl_search(void *dummy, readline_curses *rc) static void rl_callback(void *dummy, readline_curses *rc) { lnav_data.ld_bottom_source.set_prompt(""); - + switch (lnav_data.ld_mode) { case LNM_PAGING: assert(0); @@ -1935,7 +1958,8 @@ static void rl_callback(void *dummy, readline_curses *rc) add_possibility(LNM_COMMAND, "filter", rc->get_value()); rc->set_value("search: " + rc->get_value()); 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; break; @@ -2011,8 +2035,9 @@ static void rl_callback(void *dummy, readline_curses *rc) (int)dls.dls_rows.size()); rc->set_value(row_count); rc->set_alt_value(HELP_MSG_2( - y, Y, "to move forward/backward through query results " - "in the log view")); + y, Y, + "to move forward/backward through query results " + "in the log view")); } else { rc->set_value("No rows matched"); @@ -2539,7 +2564,8 @@ static void looper(void) rlc.set_perform_action(readline_curses::action(rl_callback)); rlc.set_timeout_action(readline_curses::action(rl_search)); 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); @@ -2677,9 +2703,8 @@ static void looper(void) toggle_view(&lnav_data.ld_views[LNV_TEXT]); lnav_data.ld_views[LNV_TEXT].set_top(vis_line_t(0)); 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; @@ -2802,7 +2827,8 @@ public: cols.push_back(vtab_column("cs_user_agent", SQLITE3_TEXT)); }; - void get_foreign_keys(vector &keys_inout) { + void get_foreign_keys(vector &keys_inout) + { this->log_vtab_impl::get_foreign_keys(keys_inout); keys_inout.push_back("sc_status"); @@ -2821,7 +2847,8 @@ public: cols.push_back(vtab_column("log_pid", SQLITE_INTEGER)); }; - void get_foreign_keys(vector &keys_inout) { + void get_foreign_keys(vector &keys_inout) + { this->log_vtab_impl::get_foreign_keys(keys_inout); keys_inout.push_back("log_pid"); @@ -3215,7 +3242,7 @@ int main(int argc, char *argv[]) for (lpc = 0; lpc < argc; lpc++) { auto_mem abspath; - struct stat st; + struct stat st; if (stat(argv[lpc], &st) == -1) { fprintf(stderr, @@ -3269,7 +3296,7 @@ int main(int argc, char *argv[]) else { try { rescan_files(true); - + init_session(); scan_sessions(); diff --git a/src/lnav.hh b/src/lnav.hh index 03b9d005..74530ebb 100644 --- a/src/lnav.hh +++ b/src/lnav.hh @@ -117,15 +117,15 @@ typedef enum { void sqlite_close_wrapper(void *mem); -typedef std::pair ppid_time_pair_t; +typedef std::pair ppid_time_pair_t; typedef std::pair session_pair_t; struct _lnav_data { - std::string ld_session_id; - time_t ld_session_time; - time_t ld_session_save_time; - std::list ld_session_file_names; - int ld_session_file_index; + std::string ld_session_id; + time_t ld_session_time; + time_t ld_session_save_time; + std::list ld_session_file_names; + int ld_session_file_index; const char * ld_program_name; const char * ld_debug_log_name; @@ -171,7 +171,7 @@ struct _lnav_data { fd_set ld_read_fds; std::auto_ptr ld_grep_child[LG__MAX]; - std::string ld_last_search[LNV__MAX]; + std::string ld_last_search[LNV__MAX]; log_vtab_manager * ld_vtab_manager; auto_mem ld_db; @@ -190,5 +190,4 @@ bool setup_logline_table(); int sql_callback(sqlite3_stmt *stmt); void execute_search(lnav_view_t view, const std::string ®ex); - #endif diff --git a/src/lnav_commands.cc b/src/lnav_commands.cc index 8251f262..3c4f1819 100644 --- a/src/lnav_commands.cc +++ b/src/lnav_commands.cc @@ -155,7 +155,7 @@ static string com_goto(string cmdline, vector &args) static string com_save_to(string cmdline, vector &args) { FILE * outfile = NULL; - const char *mode = ""; + const char *mode = ""; if (args.size() == 0) { args.push_back("filename"); @@ -168,17 +168,23 @@ static string com_save_to(string cmdline, vector &args) static_root_mem 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: return "error: invalid filename character"; + case WRDE_CMDSUB: return "error: command substitution is not allowed"; + case WRDE_BADVAL: return "error: unknown environment variable in file name"; + case WRDE_NOSPACE: return "error: out of memory"; + case WRDE_SYNTAX: return "error: invalid syntax"; + default: break; } @@ -198,7 +204,7 @@ static string com_save_to(string cmdline, vector &args) 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 &bv = tc->get_bookmarks()[&textview_curses::BM_USER]; bookmark_vector::iterator iter; @@ -344,10 +350,11 @@ public: return retval; }; - std::string to_command(void) { - return ((this->lf_type == logfile_filter::INCLUDE ? - "filter-in " : "filter-out ") + - this->lf_id); + std::string to_command(void) + { + return (this->lf_type == logfile_filter::INCLUDE ? + "filter-in " : "filter-out ") + + this->lf_id; }; protected: @@ -463,7 +470,7 @@ static string com_create_logline_table(string cmdline, vector &args) { string retval = "error: expecting a table name"; - if (args.size() == 0) {} + if (args.size() == 0) {} else if (args.size() == 2) { textview_curses &log_view = lnav_data.ld_views[LNV_LOG]; @@ -471,10 +478,10 @@ static string com_create_logline_table(string cmdline, vector &args) retval = "error: no log data available"; } else { - vis_line_t vl = log_view.get_top(); - content_line_t cl = lnav_data.ld_log_source.at(vl); + vis_line_t vl = log_view.get_top(); + content_line_t cl = lnav_data.ld_log_source.at(vl); log_data_table *ldt = new log_data_table(cl, args[1]); - string errmsg; + string errmsg; errmsg = lnav_data.ld_vtab_manager->register_vtab(ldt); if (errmsg.empty()) { @@ -599,14 +606,14 @@ static string com_summarize(string cmdline, vector &args) } else { auto_mem query_frag; - std::vector other_columns; - std::vector num_columns; + std::vector other_columns; + std::vector num_columns; string query; for (size_t lpc = 1; lpc < args.size(); lpc++) { - string quoted_name = args[lpc]; + string quoted_name = args[lpc]; const char *datatype; - int rc; + int rc; rc = sqlite3_table_column_metadata( lnav_data.ld_db.in(), @@ -637,22 +644,25 @@ static string com_summarize(string cmdline, vector &args) for (std::vector::iterator iter = other_columns.begin(); iter != other_columns.end(); ++iter) { - if (iter != other_columns.begin()) + if (iter != other_columns.begin()) { query += ","; + } query_frag = sqlite3_mprintf(" \"%s\", count(*) as \"count_%s\"", iter->c_str(), iter->c_str()); query += query_frag; } - if (!other_columns.empty() && !num_columns.empty()) + if (!other_columns.empty() && !num_columns.empty()) { query += ", "; + } for (std::vector::iterator iter = num_columns.begin(); iter != num_columns.end(); ++iter) { - if (iter != num_columns.begin()) + if (iter != num_columns.begin()) { query += ","; + } query_frag = sqlite3_mprintf(" sum(\"%s\"), " " min(\"%s\"), " " avg(\"%s\"), " @@ -673,21 +683,25 @@ static string com_summarize(string cmdline, vector &args) for (std::vector::iterator iter = other_columns.begin(); iter != other_columns.end(); ++iter) { - if (iter == other_columns.begin()) + if (iter == other_columns.begin()) { query += " GROUP BY "; - else + } + else{ query += ","; + } query_frag = sqlite3_mprintf(" \"%s\"", iter->c_str()); - query += query_frag; + query += query_frag; } for (std::vector::iterator iter = other_columns.begin(); iter != other_columns.end(); ++iter) { - if (iter == other_columns.begin()) + if (iter == other_columns.begin()) { query += " ORDER BY "; - else + } + else{ query += ","; + } query_frag = sqlite3_mprintf(" \"count_%s\" desc, \"%s\" asc", iter->c_str(), iter->c_str()); @@ -740,7 +754,7 @@ static string com_summarize(string cmdline, vector &args) fprintf(stderr, "code %d\n", retcode); errmsg = sqlite3_errmsg(lnav_data.ld_db); retval = "error: " + string(errmsg); - done = true; + done = true; } break; } @@ -769,9 +783,7 @@ static string com_add_test(string cmdline, vector &args) { string retval = ""; - if (args.size() == 0) { - - } + if (args.size() == 0) {} else if (args.size() > 1) { retval = "error: not expecting any arguments"; } @@ -784,8 +796,8 @@ static string com_add_test(string cmdline, vector &args) for (iter = bv.begin(); iter != bv.end(); ++iter) { auto_mem file(fclose); - char path[PATH_MAX]; - string line; + char path[PATH_MAX]; + string line; tc->grep_value_for_line(*iter, line); @@ -810,22 +822,22 @@ static string com_add_test(string cmdline, vector &args) void init_lnav_commands(readline_context::command_map_t &cmd_map) { - cmd_map["unix-time"] = com_unix_time; - cmd_map["current-time"] = com_current_time; - cmd_map["goto"] = com_goto; - cmd_map["graph"] = com_graph; - cmd_map["help"] = com_help; - cmd_map["highlight"] = com_highlight; - cmd_map["filter-in"] = com_filter; - cmd_map["filter-out"] = com_filter; - cmd_map["append-to"] = com_save_to; - cmd_map["write-to"] = com_save_to; - cmd_map["enable-filter"] = com_enable_filter; - cmd_map["disable-filter"] = com_disable_filter; + cmd_map["unix-time"] = com_unix_time; + cmd_map["current-time"] = com_current_time; + cmd_map["goto"] = com_goto; + cmd_map["graph"] = com_graph; + cmd_map["help"] = com_help; + cmd_map["highlight"] = com_highlight; + cmd_map["filter-in"] = com_filter; + cmd_map["filter-out"] = com_filter; + cmd_map["append-to"] = com_save_to; + cmd_map["write-to"] = com_save_to; + cmd_map["enable-filter"] = com_enable_filter; + cmd_map["disable-filter"] = com_disable_filter; cmd_map["create-logline-table"] = com_create_logline_table; cmd_map["delete-logline-table"] = com_delete_logline_table; - cmd_map["session"] = com_session; - cmd_map["summarize"] = com_summarize; + cmd_map["session"] = com_session; + cmd_map["summarize"] = com_summarize; if (getenv("LNAV_SRC") != NULL) { cmd_map["add-test"] = com_add_test; diff --git a/src/lnav_config.hh b/src/lnav_config.hh index d2e05f99..b2126898 100644 --- a/src/lnav_config.hh +++ b/src/lnav_config.hh @@ -58,5 +58,4 @@ bool check_experimental(const char *feature_name); * Ensure that the '.lnav' directory exists. */ void ensure_dotlnav(void); - #endif diff --git a/src/lnav_util.cc b/src/lnav_util.cc index 5c0dac43..43f5ba9e 100644 --- a/src/lnav_util.cc +++ b/src/lnav_util.cc @@ -54,10 +54,10 @@ std::string hash_string(const std::string &str) std::string time_ago(time_t last_time) { - time_t delta, current_time = time(NULL); + time_t delta, current_time = time(NULL); const char *fmt; - char buffer[64]; - int amount; + char buffer[64]; + int amount; delta = current_time - last_time; if (delta < 0) { @@ -70,21 +70,21 @@ std::string time_ago(time_t last_time) return "one minute ago"; } else if (delta < (60 * 60)) { - fmt = "%d minutes ago"; + fmt = "%d minutes ago"; amount = delta / 60; } else if (delta < (2 * 60 * 60)) { return "one hour ago"; } else if (delta < (24 * 60 * 60)) { - fmt = "%d hours ago"; + fmt = "%d hours ago"; amount = delta / (60 * 60); } else if (delta < (2 * 24 * 60 * 60)) { return "one day ago"; } else if (delta < (365 * 24 * 60 * 60)) { - fmt = "%d days ago"; + fmt = "%d days ago"; amount = delta / (24 * 60 * 60); } else { @@ -104,7 +104,7 @@ void sqlite_close_wrapper(void *mem) std::string get_current_dir(void) { - char cwd[FILENAME_MAX]; + char cwd[FILENAME_MAX]; std::string retval = "."; if (getcwd(cwd, sizeof(cwd)) == NULL) { diff --git a/src/lnav_util.hh b/src/lnav_util.hh index 7bd6b364..e3cce080 100644 --- a/src/lnav_util.hh +++ b/src/lnav_util.hh @@ -91,7 +91,8 @@ std::string time_ago(time_t last_time); struct sha_updater { 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()); } @@ -102,23 +103,23 @@ std::string hash_string(const std::string &str); template struct object_field_t { - object_field_t(UnaryFunction &func, Member &mem) - : of_func(func), of_mem(mem) { - - }; + : of_func(func), of_mem(mem) {}; template - void operator()(Object obj) { + void operator()(Object obj) + { this->of_func(obj.*(this->of_mem)); }; UnaryFunction &of_func; - Member of_mem; + Member of_mem; }; template -object_field_t object_field(UnaryFunction &func, Member mem) { +object_field_t object_field(UnaryFunction &func, + Member mem) +{ return object_field_t(func, mem); } @@ -135,5 +136,4 @@ enum file_format_t { }; file_format_t detect_file_format(const std::string &filename); - #endif diff --git a/src/log_data_table.hh b/src/log_data_table.hh index afdd7d14..5b8d0774 100644 --- a/src/log_data_table.hh +++ b/src/log_data_table.hh @@ -47,7 +47,8 @@ class log_data_table : public log_vtab_impl { 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), ldt_template_line(template_line) {}; @@ -56,7 +57,7 @@ public: content_line_t cl_copy = this->ldt_template_line; logfile * lf = lnav_data.ld_log_source.find( cl_copy); - std::string val = lf->read_line( + std::string val = lf->read_line( lf->begin() + cl_copy); struct line_range body; string_attrs_t sa; @@ -78,7 +79,7 @@ public: dp.dp_pairs.begin(); pair_iter != dp.dp_pairs.end(); ++pair_iter) { - std::string key_str = dp.get_element_string( + std::string key_str = dp.get_element_string( pair_iter->e_sub_elements->front()); std::string colname = cn.add_column(key_str); int sql_type = SQLITE3_TEXT; @@ -116,7 +117,7 @@ public: return true; } - content_line_t cl; + content_line_t cl; cl = lss.at(lc.lc_curr_line); logfile * lf = lss.find(cl); @@ -148,8 +149,8 @@ public: lf_iter->set_schema(dp.dp_schema_id); - // The cached schema ID in the log line is not complete, so we still - // need to check for a full match. + /* The cached schema ID in the log line is not complete, so we still */ + /* need to check for a full match. */ if (dp.dp_schema_id != this->ldt_schema_id) { return false; } @@ -165,21 +166,22 @@ public: std::vector &values) { for (data_parser::element_list_t::iterator pair_iter = - this->ldt_pairs.begin(); + this->ldt_pairs.begin(); pair_iter != this->ldt_pairs.end(); ++pair_iter) { const data_parser::element &pvalue = pair_iter->get_pair_value(); - 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()); - switch(pvalue.value_token()) { + switch (pvalue.value_token()) { case DT_NUMBER: { - double d = 0; + double d = 0; + + sscanf(tmp.c_str(), "%lf", &d); + values.push_back(logline_value("", d)); + } + break; - sscanf(tmp.c_str(), "%lf", &d); - values.push_back(logline_value("", d)); - } - break; default: values.push_back(logline_value("", tmp)); break; diff --git a/src/log_format.cc b/src/log_format.cc index 65496eda..58774a28 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -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 retval = logline::LEVEL_UNKNOWN; + int (*cmpfunc)(const char *, const char *); - if (exact) + if (exact) { cmpfunc = strcasecmp; - else + } + else{ cmpfunc = strcasestr_i; + } if (cmpfunc(levelstr, "TRACE") == 0) { retval = logline::LEVEL_TRACE; diff --git a/src/log_format.hh b/src/log_format.hh index a3b81b83..1b65b5f8 100644 --- a/src/log_format.hh +++ b/src/log_format.hh @@ -95,7 +95,8 @@ public: ll_time(t), ll_millis(millis), ll_level(l), - ll_module(m) { + ll_module(m) + { memset(this->ll_schema, 0, sizeof(this->ll_schema)); }; @@ -130,21 +131,23 @@ public: /** * @return True if there is a schema value set for this log line. */ - bool has_schema(void) const { - return (this->ll_schema[0] != 0 || - this->ll_schema[1] != 0 || - this->ll_schema[2] != 0 || - this->ll_schema[3] != 0); + bool has_schema(void) const + { + return this->ll_schema[0] != 0 || + this->ll_schema[1] != 0 || + this->ll_schema[2] != 0 || + this->ll_schema[3] != 0; }; /** * Set the "schema" for this log line. The schema ID is used to match log * lines that have a similar format when generating the logline table. The * schema is set lazily so that startup is faster. - * + * * @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)); }; @@ -152,12 +155,13 @@ public: * Perform a partial match of the given schema against this log line. * Storing the full schema is not practical, so we just keep the first four * bytes. - * + * * @param ba The SHA-1 hash of the constant parts of a log line. * @return True if the first four bytes of the given schema match the * 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; } diff --git a/src/log_format_impls.cc b/src/log_format_impls.cc index 04e06edd..baca986e 100644 --- a/src/log_format_impls.cc +++ b/src/log_format_impls.cc @@ -153,27 +153,26 @@ class access_log_format : public log_format { logline_value::kind_t kind; } columns[] = { { "c_ip", - logline_value::VALUE_TEXT }, + logline_value::VALUE_TEXT }, { "cs_username", - logline_value::VALUE_TEXT }, - { "", - }, + logline_value::VALUE_TEXT }, + { "", }, { "cs_method", - logline_value::VALUE_TEXT }, + logline_value::VALUE_TEXT }, { "cs_uri_stem", - logline_value::VALUE_TEXT }, + logline_value::VALUE_TEXT }, { "cs_uri_query", - logline_value::VALUE_TEXT }, + logline_value::VALUE_TEXT }, { "cs_version", - logline_value::VALUE_TEXT }, + logline_value::VALUE_TEXT }, { "sc_status", - logline_value::VALUE_INTEGER }, + logline_value::VALUE_INTEGER }, { "sc_bytes", - logline_value::VALUE_INTEGER }, + logline_value::VALUE_INTEGER }, { "cs_referer", - logline_value::VALUE_TEXT }, + logline_value::VALUE_TEXT }, { "cs_user_agent", - logline_value::VALUE_TEXT }, + logline_value::VALUE_TEXT }, { NULL }, }; @@ -693,11 +692,11 @@ class glog_log_format : public log_format { const char * name; logline_value::kind_t kind; } columns[] = { - { "micros", logline_value::VALUE_INTEGER }, - { "thread", logline_value::VALUE_TEXT }, - { "src_file", logline_value::VALUE_TEXT }, - { "src_line", logline_value::VALUE_TEXT }, - { "message", logline_value::VALUE_TEXT }, + { "micros", logline_value::VALUE_INTEGER }, + { "thread", logline_value::VALUE_TEXT }, + { "src_file", logline_value::VALUE_TEXT }, + { "src_line", logline_value::VALUE_TEXT }, + { "message", logline_value::VALUE_TEXT }, { NULL } }; @@ -824,10 +823,10 @@ class strace_log_format : public log_format { const char * name; logline_value::kind_t kind; } columns[] = { - { "funcname", logline_value::VALUE_TEXT }, - { "args", logline_value::VALUE_TEXT }, - { "result", logline_value::VALUE_TEXT }, - { "duration", logline_value::VALUE_TEXT }, + { "funcname", logline_value::VALUE_TEXT }, + { "args", logline_value::VALUE_TEXT }, + { "result", logline_value::VALUE_TEXT }, + { "duration", logline_value::VALUE_TEXT }, { NULL }, }; diff --git a/src/log_vtab_impl.cc b/src/log_vtab_impl.cc index 0e2cbebd..e5189146 100644 --- a/src/log_vtab_impl.cc +++ b/src/log_vtab_impl.cc @@ -109,7 +109,7 @@ static int vt_create(sqlite3 *db, char **pzErr) { log_vtab_manager *vm = (log_vtab_manager *)pAux; - int rc = SQLITE_OK; + int rc = SQLITE_OK; vtab *p_vt; /* Allocate the sqlite3_vtab/vtab structure itself */ @@ -418,8 +418,8 @@ string log_vtab_manager::register_vtab(log_vtab_impl *vi) if (this->vm_impls.find(vi->get_name()) == this->vm_impls.end()) { auto_mem errmsg(sqlite3_free); - char *sql; - int rc; + char * sql; + int rc; this->vm_impls[vi->get_name()] = vi; diff --git a/src/log_vtab_impl.hh b/src/log_vtab_impl.hh index dbf3fe39..30473102 100644 --- a/src/log_vtab_impl.hh +++ b/src/log_vtab_impl.hh @@ -101,7 +101,8 @@ public: virtual void get_columns(std::vector &cols) { }; - virtual void get_foreign_keys(std::vector &keys_inout) { + virtual void get_foreign_keys(std::vector &keys_inout) + { keys_inout.push_back("log_line"); }; @@ -140,11 +141,13 @@ public: return this->vm_impls[name]; }; - iterator begin() const { + iterator begin() const + { return this->vm_impls.begin(); }; - iterator end() const { + iterator end() const + { return this->vm_impls.end(); }; diff --git a/src/logfile_sub_source.cc b/src/logfile_sub_source.cc index d5f805bf..f8e571ba 100644 --- a/src/logfile_sub_source.cc +++ b/src/logfile_sub_source.cc @@ -222,10 +222,10 @@ void logfile_sub_source::text_value_for_line(textview_curses &tc, const char *format; const char *symbol; } intervals[] = { - { 1000, "%03qd%s", "" }, - { 60, "%qd%s", "s" }, - { 60, "%qd%s", "m" }, - { 0, "%qd%s", "h" }, + { 1000, "%03qd%s", "" }, + { 60, "%qd%s", "s" }, + { 60, "%qd%s", "m" }, + { 0, "%qd%s", "h" }, { 0, NULL } }; diff --git a/src/logfile_sub_source.hh b/src/logfile_sub_source.hh index a0a68c37..35e0410f 100644 --- a/src/logfile_sub_source.hh +++ b/src/logfile_sub_source.hh @@ -90,7 +90,7 @@ public: class observer : public logfile_observer { - public: +public: virtual void logfile_sub_source_filtering(logfile_sub_source &lss, content_line_t cl, size_t total) = 0; @@ -206,7 +206,7 @@ public: ++mark_iter) { content_line_t mark_curr = content_line_t( file_index * MAX_LINES_PER_FILE); - content_line_t mark_end = content_line_t( + content_line_t mark_end = content_line_t( (file_index + 1) * MAX_LINES_PER_FILE); bookmark_vector::iterator bv_iter; bookmark_vector & bv = @@ -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); }; @@ -330,11 +331,13 @@ public: typedef std::vector::iterator iterator; - iterator begin() { + iterator begin() + { return this->lss_files.begin(); }; - iterator end() { + iterator end() + { return this->lss_files.end(); }; diff --git a/src/network-extension-functions.cc b/src/network-extension-functions.cc index 63090170..5f1d9383 100644 --- a/src/network-extension-functions.cc +++ b/src/network-extension-functions.cc @@ -110,7 +110,7 @@ static void sql_gethostbyaddr(sqlite3_context *context, memset(&sa, 0, sizeof(sa)); if (strchr(addr_str, ':')) { - family = AF_INET6; + family = AF_INET6; socklen = sizeof(struct sockaddr_in6); sa.sin6.sin6_family = family; addr_raw = (char *)&sa.sin6.sin6_addr; diff --git a/src/pcrepp.cc b/src/pcrepp.cc index 0efe904e..b21415a9 100644 --- a/src/pcrepp.cc +++ b/src/pcrepp.cc @@ -47,6 +47,7 @@ pcre_jit_stack *pcrepp::jit_stack(void) return retval; } + #else #warning "pcrejit is not available, search performance will be degraded" diff --git a/src/pcrepp.hh b/src/pcrepp.hh index ddf42acc..4bf7a648 100644 --- a/src/pcrepp.hh +++ b/src/pcrepp.hh @@ -191,9 +191,10 @@ public: iter->length()); }; - void reset(const char *str, size_t off = 0, size_t len = -1) { - this->pi_string = str; - this->pi_offset = off; + void reset(const char *str, size_t off = 0, size_t len = -1) + { + this->pi_string = str; + this->pi_offset = off; this->pi_next_offset = off; if (this->pi_length == (size_t)-1) { this->pi_length = strlen(str); @@ -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()); } @@ -237,7 +239,8 @@ public: 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; int eoff; @@ -271,40 +274,41 @@ public: bool match(pcre_context &pc, pcre_input &pi, int options = 0) const { - int length, startoffset, filtered_options = options; - int count = pc.get_max_count(); + int length, startoffset, filtered_options = options; + int count = pc.get_max_count(); const char *str; - int rc; + int rc; pi.pi_offset = pi.pi_next_offset; str = pi.get_string(); if (filtered_options & PCRE_ANCHORED) { filtered_options &= ~PCRE_ANCHORED; - str = &str[pi.pi_offset]; + str = &str[pi.pi_offset]; startoffset = 0; - length = pi.pi_length - pi.pi_offset; + length = pi.pi_length - pi.pi_offset; } else { startoffset = pi.pi_offset; - length = pi.pi_length; + length = pi.pi_length; } - rc = pcre_exec(this->p_code, - this->p_code_extra.in(), - str, - length, - startoffset, - filtered_options, - (int *)pc.all(), - count * 2); + rc = pcre_exec(this->p_code, + this->p_code_extra.in(), + str, + length, + startoffset, + filtered_options, + (int *)pc.all(), + count * 2); if (rc < 0) { switch (rc) { case PCRE_ERROR_NOMATCH: break; + default: - fprintf(stderr, "pcre err %d\n", rc); - break; + fprintf(stderr, "pcre err %d\n", rc); + break; } } else if (rc == 0) { @@ -320,7 +324,7 @@ public: continue; } pc.all()[lpc].c_begin += pi.pi_offset; - pc.all()[lpc].c_end += pi.pi_offset; + pc.all()[lpc].c_end += pi.pi_offset; } } pi.pi_next_offset = pc.all()->c_end; @@ -333,13 +337,15 @@ public: #ifdef PCRE_STUDY_JIT_COMPILE static pcre_jit_stack *jit_stack(void); + #else static void pcre_free_study(pcre_extra *); #endif private: - void study(void) { + void study(void) + { const char *errptr; this->p_code_extra = pcre_study(this->p_code, @@ -355,9 +361,9 @@ private: if (this->p_code_extra != NULL) { pcre_extra *extra = this->p_code_extra; - extra->flags |= (PCRE_EXTRA_MATCH_LIMIT| + extra->flags |= (PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION); - extra->match_limit = 10000; + extra->match_limit = 10000; extra->match_limit_recursion = 500; #ifdef PCRE_STUDY_JIT_COMPILE pcre_assign_jit_stack(extra, NULL, jit_stack()); diff --git a/src/readline_curses.cc b/src/readline_curses.cc index 9ed22919..35e41873 100644 --- a/src/readline_curses.cc +++ b/src/readline_curses.cc @@ -61,7 +61,7 @@ using namespace std; -static int got_line = 0; +static int got_line = 0; static sig_atomic_t got_timeout = 0; static sig_atomic_t got_winch = 0; static readline_curses *child_this; @@ -416,7 +416,7 @@ void readline_curses::start(void) if (got_line) { struct itimerval itv; - got_line = 0; + got_line = 0; itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 0; itv.it_interval.tv_sec = 0; @@ -631,9 +631,9 @@ void readline_curses::clear_possibilities(int context, string type) void readline_curses::do_update(void) { if (this->rc_active_context == -1) { - int alt_start = -1; + int alt_start = -1; struct line_range lr = { 0, }; - attr_line_t al, alt_al; + attr_line_t al, alt_al; wmove(this->vc_window, this->get_actual_y(), 0); wclrtoeol(this->vc_window); diff --git a/src/readline_curses.hh b/src/readline_curses.hh index 6e004e14..4b4fd46e 100644 --- a/src/readline_curses.hh +++ b/src/readline_curses.hh @@ -200,13 +200,17 @@ public: void set_perform_action(action va) { this->rc_perform = va; }; void set_timeout_action(action va) { this->rc_timeout = va; }; - void set_value(const std::string &value) { - this->rc_value = value; + void set_value(const std::string &value) + { + this->rc_value = value; this->rc_value_expiration = time(NULL) + VALUE_EXPIRATION; }; 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; }; int update_fd_set(fd_set &readfds) @@ -248,7 +252,8 @@ public: void add_possibility(int context, const std::string &type, - const char *values[]) { + const char *values[]) + { for (int lpc = 0; values[lpc]; lpc++) { this->add_possibility(context, type, values[lpc]); } @@ -273,9 +278,9 @@ private: auto_fd rc_command_pipe[2]; std::map rc_contexts; std::string rc_value; - time_t rc_value_expiration; + time_t rc_value_expiration; std::string rc_alt_value; - + action rc_perform; action rc_timeout; }; diff --git a/src/session_data.cc b/src/session_data.cc index 86a7b220..f19a398e 100644 --- a/src/session_data.cc +++ b/src/session_data.cc @@ -50,14 +50,14 @@ using namespace std; -static const size_t MAX_SESSIONS = 8; +static const size_t MAX_SESSIONS = 8; static const size_t MAX_SESSION_FILE_COUNT = 256; typedef std::vector > timestamped_list_t; static string bookmark_file_name(const string &name) { - char mark_base_name[256]; + char mark_base_name[256]; string hash; hash = hash_string(name); @@ -73,9 +73,10 @@ static string bookmark_file_name(const string &name) static string latest_bookmark_file(const string &name) { timestamped_list_t file_names; + static_root_mem file_list; string mark_file_pattern; - char mark_base_name[256]; + char mark_base_name[256]; string hash; hash = hash_string(name); @@ -90,7 +91,7 @@ static string latest_bookmark_file(const string &name) for (size_t lpc = 0; lpc < file_list->gl_pathc; lpc++) { const char *path = file_list->gl_pathv[lpc]; const char *base; - int timestamp; + int timestamp; base = strrchr(path, '/') + 1; if (sscanf(base, "file-%*[^.].ts%d.json", ×tamp) == 1) { @@ -101,8 +102,9 @@ static string latest_bookmark_file(const string &name) sort(file_names.begin(), file_names.end()); - if (file_names.empty()) + if (file_names.empty()) { return ""; + } return file_names.back().second; } @@ -111,28 +113,30 @@ struct session_file_info { session_file_info(int timestamp, const string &id, 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 { - if (this->sfi_timestamp < other.sfi_timestamp) + bool operator<(const session_file_info &other) const + { + if (this->sfi_timestamp < other.sfi_timestamp) { return true; - if (this->sfi_path < other.sfi_path) + } + if (this->sfi_path < other.sfi_path) { return true; + } return false; }; - int sfi_timestamp; + int sfi_timestamp; string sfi_id; string sfi_path; }; static void cleanup_session_data(void) { - static_root_mem session_file_list; + static_root_mem session_file_list; std::list session_info_list; map session_count; - string session_file_pattern; + string session_file_pattern; session_file_pattern = dotlnav_path("*-*.ts*.json"); @@ -142,8 +146,8 @@ static void cleanup_session_data(void) session_file_list.inout()) == 0) { for (size_t lpc = 0; lpc < session_file_list->gl_pathc; lpc++) { const char *path = session_file_list->gl_pathv[lpc]; - char hash_id[64]; - int timestamp; + char hash_id[64]; + int timestamp; const char *base; base = strrchr(path, '/') + 1; @@ -151,7 +155,7 @@ static void cleanup_session_data(void) hash_id, ×tamp) == 2) { session_count[hash_id] += 1; session_info_list.push_back(session_file_info( - timestamp, hash_id, path)); + timestamp, hash_id, path)); } if (sscanf(base, "view-info-%63[^.].ts%d.ppid%*d.json", @@ -159,7 +163,7 @@ static void cleanup_session_data(void) ×tamp) == 2) { session_count[hash_id] += 1; session_info_list.push_back(session_file_info( - timestamp, hash_id, path)); + timestamp, hash_id, path)); } } } @@ -221,13 +225,15 @@ void init_session(void) void scan_sessions(void) { - std::list &session_file_names = lnav_data.ld_session_file_names; - static_root_mem view_info_list; + std::list &session_file_names = + lnav_data.ld_session_file_names; + + static_root_mem view_info_list; std::list::iterator iter; - char view_info_pattern_base[128]; + char view_info_pattern_base[128]; string view_info_pattern; string old_session_name; - int index; + int index; cleanup_session_data(); @@ -245,10 +251,11 @@ void scan_sessions(void) "view-info-%s.*.json", lnav_data.ld_session_id.c_str()); 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++) { const char *path = view_info_list->gl_pathv[lpc]; - int timestamp, ppid; + int timestamp, ppid; const char *base; base = strrchr(path, '/') + 1; @@ -258,7 +265,7 @@ void scan_sessions(void) &ppid) == 2) { ppid_time_pair_t ptp; - ptp.first = (ppid == getppid()) ? 1 : 0; + ptp.first = (ppid == getppid()) ? 1 : 0; ptp.second = timestamp; session_file_names.push_back(make_pair(ptp, path)); } @@ -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) { yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx; + pair *pair; fprintf(stderr, "read line %qd\n", num); @@ -311,7 +319,7 @@ static int read_marks(void *ctx, long long num) } static struct json_path_handler file_handlers[] = { - json_path_handler("/path", read_path), + json_path_handler("/path", read_path), json_path_handler("/marks#", read_marks), json_path_handler() @@ -325,11 +333,11 @@ void load_bookmarks(void) iter != lnav_data.ld_log_source.end(); ++iter) { pair logfile_pair; - yajlpp_parse_context ypc(file_handlers); + yajlpp_parse_context ypc(file_handlers); const string &log_name = iter->ld_file->get_filename(); - string mark_file_name; - yajl_handle handle; - int fd; + string mark_file_name; + yajl_handle handle; + int fd; fprintf(stderr, "load %s\n", log_name.c_str()); @@ -341,8 +349,9 @@ void load_bookmarks(void) } mark_file_name = latest_bookmark_file(log_name.c_str()); - if (mark_file_name.empty()) + if (mark_file_name.empty()) { continue; + } fprintf(stderr, "loading %s\n", mark_file_name.c_str()); handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc); @@ -353,7 +362,7 @@ void load_bookmarks(void) } else { unsigned char buffer[1024]; - size_t rc; + size_t rc; while ((rc = read(fd, buffer, sizeof(buffer))) > 0) { yajl_parse(handle, buffer, rc); @@ -379,9 +388,9 @@ static int read_files(void *ctx, const unsigned char *str, size_t len) static int read_last_search(void *ctx, const unsigned char *str, size_t len) { yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx; - string regex = std::string((const char *)str, len); + string regex = std::string((const char *)str, len); const char **view_name; - int view_index; + int view_index; view_name = find(lnav_view_strings, lnav_view_strings + LNV__MAX, @@ -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) { yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx; - const char **view_name; + const char ** view_name; int view_index; view_name = find(lnav_view_strings, @@ -409,8 +418,9 @@ static int read_top_line(void *ctx, long long value) if (view_index < LNV__MAX) { 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)); + } } return 1; @@ -426,11 +436,11 @@ static int read_commands(void *ctx, const unsigned char *str, size_t len) } static struct json_path_handler view_info_handlers[] = { - json_path_handler("/save-time", read_save_time), - json_path_handler("/files#", read_files), + json_path_handler("/save-time", read_save_time), + json_path_handler("/files#", read_files), json_path_handler("/views/([^.]+)/top_line", read_top_line), - json_path_handler("/views/([^.]+)/search", read_last_search), - json_path_handler("/commands#", read_commands), + json_path_handler("/views/([^.]+)/search", read_last_search), + json_path_handler("/commands#", read_commands), json_path_handler() }; @@ -439,7 +449,7 @@ void load_session(void) { std::list::iterator sess_iter; yajlpp_parse_context ypc(view_info_handlers); - yajl_handle handle; + yajl_handle handle; int fd; load_bookmarks(); @@ -448,7 +458,7 @@ void load_session(void) return; } - handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc); + handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc); sess_iter = lnav_data.ld_session_file_names.begin(); advance(sess_iter, lnav_data.ld_session_file_index); lnav_data.ld_session_save_time = sess_iter->first.second; @@ -459,7 +469,7 @@ void load_session(void) } else { unsigned char buffer[1024]; - size_t rc; + size_t rc; while ((rc = read(fd, buffer, sizeof(buffer))) > 0) { yajl_parse(handle, buffer, rc); @@ -479,25 +489,28 @@ static void yajl_writer(void *context, const char *str, size_t len) void save_bookmarks(void) { logfile_sub_source &lss = lnav_data.ld_log_source; - bookmarks::type &bm = lss.get_user_bookmarks(); - bookmark_vector &user_marks = bm[&textview_curses::BM_USER]; + + bookmarks::type &bm = + lss.get_user_bookmarks(); + bookmark_vector &user_marks = + bm[&textview_curses::BM_USER]; logfile_sub_source::iterator file_iter; bookmark_vector::iterator iter; - string mark_file_name, mark_file_tmp_name; + string mark_file_name, mark_file_tmp_name; auto_mem file(fclose); - logfile *curr_lf = NULL; - yajl_gen handle = NULL; + logfile * curr_lf = NULL; + yajl_gen handle = NULL; for (file_iter = lnav_data.ld_log_source.begin(); file_iter != lnav_data.ld_log_source.end(); ++file_iter) { - logfile *lf = file_iter->ld_file; - string mark_base_name = bookmark_file_name(lf->get_filename()); + logfile *lf = file_iter->ld_file; + string mark_base_name = bookmark_file_name(lf->get_filename()); - mark_file_name = dotlnav_path(mark_base_name.c_str()); + mark_file_name = dotlnav_path(mark_base_name.c_str()); mark_file_tmp_name = mark_file_name + ".tmp"; - file = fopen(mark_file_tmp_name.c_str(), "w"); + file = fopen(mark_file_tmp_name.c_str(), "w"); handle = yajl_gen_alloc(NULL); yajl_gen_config(handle, yajl_gen_beautify, 1); yajl_gen_config(handle, @@ -524,11 +537,10 @@ void save_bookmarks(void) for (iter = user_marks.begin(); iter != user_marks.end(); ++iter) { content_line_t cl = *iter; - logfile *lf; + logfile * lf; lf = lss.find(cl); if (curr_lf != lf) { - if (handle) { yajl_gen_array_close(handle); yajl_gen_map_close(handle); @@ -540,10 +552,10 @@ void save_bookmarks(void) } string mark_base_name = bookmark_file_name(lf->get_filename()); - mark_file_name = dotlnav_path(mark_base_name.c_str()); + mark_file_name = dotlnav_path(mark_base_name.c_str()); mark_file_tmp_name = mark_file_name + ".tmp"; - file = fopen(mark_file_name.c_str(), "w"); + file = fopen(mark_file_name.c_str(), "w"); handle = yajl_gen_alloc(NULL); yajl_gen_config(handle, yajl_gen_beautify, 1); yajl_gen_config(handle, @@ -571,9 +583,10 @@ void save_bookmarks(void) void save_session(void) { string view_file_name, view_file_tmp_name; + auto_mem file(fclose); - char view_base_name[256]; - yajl_gen handle = NULL; + char view_base_name[256]; + yajl_gen handle = NULL; save_bookmarks(); @@ -585,7 +598,7 @@ void save_session(void) lnav_data.ld_session_time, getppid()); - view_file_name = dotlnav_path(view_base_name); + view_file_name = dotlnav_path(view_base_name); view_file_tmp_name = view_file_name + ".tmp"; if ((file = fopen(view_file_tmp_name.c_str(), "w")) == NULL) { @@ -612,7 +625,8 @@ void save_session(void) for_each(lnav_data.ld_file_names.begin(), lnav_data.ld_file_names.end(), - object_field(file_list.gen, &pair::first)); + object_field(file_list.gen, + &pair::first)); } root_map.gen("views"); @@ -622,8 +636,8 @@ void save_session(void) for (int lpc = 0; lpc < LNV__MAX; lpc++) { textview_curses &tc = lnav_data.ld_views[lpc]; - unsigned long width; - vis_line_t height; + unsigned long width; + vis_line_t height; top_view_map.gen(lnav_view_strings[lpc]); @@ -632,10 +646,12 @@ void save_session(void) view_map.gen("top_line"); 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); - else + } + else{ view_map.gen((long long)tc.get_top()); + } view_map.gen("search"); view_map.gen(lnav_data.ld_last_search[lpc]); @@ -654,20 +670,23 @@ void save_session(void) for (filter_iter = fs.begin(); filter_iter != fs.end(); ++filter_iter) { - if (!(*filter_iter)->is_enabled()) + if (!(*filter_iter)->is_enabled()) { continue; + } 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; for (hl_iter = hmap.begin(); hl_iter != hmap.end(); ++hl_iter) { - if (hl_iter->first[0] == '$') + if (hl_iter->first[0] == '$') { continue; + } cmd_array.gen("highlight " + hl_iter->first); } } @@ -684,7 +703,8 @@ void save_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(); save_session(); diff --git a/src/session_data.hh b/src/session_data.hh index 8b5811d0..304f3bd8 100644 --- a/src/session_data.hh +++ b/src/session_data.hh @@ -37,5 +37,4 @@ void load_session(void); void save_session(void); void reset_session(void); void scan_sessions(void); - #endif diff --git a/src/sql_util.cc b/src/sql_util.cc index 275756dd..a8ce6db4 100644 --- a/src/sql_util.cc +++ b/src/sql_util.cc @@ -168,7 +168,7 @@ const char *sql_keywords[] = { }; const char *sql_function_names[] = { - // http://www.sqlite.org/lang_aggfunc.html + /* http://www.sqlite.org/lang_aggfunc.html */ "avg", "count", "group_concat", @@ -177,7 +177,7 @@ const char *sql_function_names[] = { "sum", "total", - // http://www.sqlite.org/lang_corefunc.html + /* http://www.sqlite.org/lang_corefunc.html */ "abs", "changes", "char", @@ -231,7 +231,7 @@ static int handle_db_list(void *ptr, struct table_list_data { 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, @@ -279,7 +279,7 @@ int walk_sqlite_metadata(sqlite3 *db, struct sqlite_metadata_callbacks &smc) for (db_table_map_t::iterator iter = smc.smc_db_list.begin(); iter != smc.smc_db_list.end(); ++iter) { - struct table_list_data tld = { &smc, &iter }; + struct table_list_data tld = { &smc, &iter }; auto_mem query; query = sqlite3_mprintf("SELECT name FROM %Q.sqlite_master " @@ -361,7 +361,7 @@ void attach_sqlite_db(sqlite3 *db, const std::string &filename) stmt.out(), NULL) != SQLITE_OK) { fprintf(stderr, - "error: could not prepare DB attach statement -- %s\n", + "error: could not prepare DB attach statement -- %s\n", sqlite3_errmsg(db)); return; } @@ -370,7 +370,7 @@ void attach_sqlite_db(sqlite3 *db, const std::string &filename) filename.c_str(), filename.length(), SQLITE_TRANSIENT) != SQLITE_OK) { fprintf(stderr, - "error: could not bind DB attach statement -- %s\n", + "error: could not bind DB attach statement -- %s\n", sqlite3_errmsg(db)); return; } @@ -391,14 +391,14 @@ void attach_sqlite_db(sqlite3 *db, const std::string &filename) db_name.c_str(), db_name.length(), SQLITE_TRANSIENT) != SQLITE_OK) { fprintf(stderr, - "error: could not bind DB attach statement -- %s\n", + "error: could not bind DB attach statement -- %s\n", sqlite3_errmsg(db)); return; } if (sqlite3_step(stmt.in()) != SQLITE_DONE) { fprintf(stderr, - "error: could not execute DB attach statement -- %s\n", + "error: could not execute DB attach statement -- %s\n", sqlite3_errmsg(db)); return; } diff --git a/src/sql_util.hh b/src/sql_util.hh index a3bdc20e..fa7b9b0a 100644 --- a/src/sql_util.hh +++ b/src/sql_util.hh @@ -42,7 +42,7 @@ extern const char *sql_keywords[]; extern const char *sql_function_names[]; typedef int (*sqlite_exec_callback)(void *, int, char **, char **); -typedef std::vector db_table_list_t; +typedef std::vector db_table_list_t; typedef std::map db_table_map_t; struct sqlite_metadata_callbacks { @@ -51,11 +51,10 @@ struct sqlite_metadata_callbacks { sqlite_exec_callback smc_table_list; sqlite_exec_callback smc_table_info; sqlite_exec_callback smc_foreign_key_list; - db_table_map_t smc_db_list; + db_table_map_t smc_db_list; }; int walk_sqlite_metadata(sqlite3 *db, struct sqlite_metadata_callbacks &smc); void attach_sqlite_db(sqlite3 *db, const std::string &filename); - #endif diff --git a/src/statusview_curses.cc b/src/statusview_curses.cc index 6d318f56..a08339a1 100644 --- a/src/statusview_curses.cc +++ b/src/statusview_curses.cc @@ -54,7 +54,7 @@ void statusview_curses::do_update(void) field_count = this->sc_source->statusview_fields(); for (field = 0; field < field_count; field++) { - status_field &sf = this->sc_source->statusview_value_for_field( + status_field &sf = this->sc_source->statusview_value_for_field( field); struct line_range lr = { 0, sf.get_width() }; attr_line_t val; diff --git a/src/statusview_curses.hh b/src/statusview_curses.hh index 060ad318..fd477bf7 100644 --- a/src/statusview_curses.hh +++ b/src/statusview_curses.hh @@ -128,15 +128,16 @@ public: va_end(args); }; - void set_stitch_value(int color_pair) { - string_attrs_t &sa = this->sf_value.get_attrs(); + void set_stitch_value(int color_pair) + { + string_attrs_t & sa = this->sf_value.get_attrs(); struct line_range lr = { 0, 1 }; this->sf_value.get_string() = "::"; 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_end = 2; + lr.lr_end = 2; sa[lr].insert(make_string_attr("style", COLOR_PAIR(color_pair))); }; @@ -173,11 +174,11 @@ public: int get_share() const { return this->sf_share; }; protected: - size_t sf_width; /*< The maximum display width, in chars. */ - size_t sf_min_width; /*< The minimum display width, in chars. */ - bool sf_right_justify; - bool sf_cylon; - size_t sf_cylon_pos; + size_t sf_width; /*< The maximum display width, in chars. */ + size_t sf_min_width; /*< The minimum display width, in chars. */ + bool sf_right_justify; + bool sf_cylon; + size_t sf_cylon_pos; attr_line_t sf_value; /*< The value to display for this field. */ view_colors::role_t sf_role; /*< The color role for this field. */ int sf_share; diff --git a/src/string-extension-functions.cc b/src/string-extension-functions.cc index 1e9f7176..618c1466 100644 --- a/src/string-extension-functions.cc +++ b/src/string-extension-functions.cc @@ -19,31 +19,31 @@ #include "sqlite-extension-func.h" typedef struct { - char *s; - pcre *p; + char * s; + pcre * p; pcre_extra *e; } cache_entry; #ifndef CACHE_SIZE -#define CACHE_SIZE 16 +#define CACHE_SIZE 16 #endif static void regexp(sqlite3_context *ctx, int argc, sqlite3_value **argv) { const char *re, *str; - pcre *p; + pcre * p; pcre_extra *e; assert(argc == 2); - re = (const char *) sqlite3_value_text(argv[0]); + re = (const char *)sqlite3_value_text(argv[0]); if (!re) { sqlite3_result_error(ctx, "no regexp", -1); return; } - str = (const char *) sqlite3_value_text(argv[1]); + str = (const char *)sqlite3_value_text(argv[1]); if (!str) { sqlite3_result_error(ctx, "no string", -1); return; @@ -71,7 +71,7 @@ void regexp(sqlite3_context *ctx, int argc, sqlite3_value **argv) else { cache_entry c; const char *err; - int pos; + int pos; c.p = pcre_compile(re, 0, &err, &pos, NULL); if (!c.p) { char *e2 = sqlite3_mprintf("%s: %s (offset %d)", re, err, pos); diff --git a/src/test_override.cc b/src/test_override.cc index 712cb009..51063761 100644 --- a/src/test_override.cc +++ b/src/test_override.cc @@ -1,4 +1,3 @@ - #include "config.h" #include diff --git a/src/textview_curses.cc b/src/textview_curses.cc index 3053e2f6..d38e3d26 100644 --- a/src/textview_curses.cc +++ b/src/textview_curses.cc @@ -97,10 +97,10 @@ void textview_curses::listview_value_for_row(const listview_curses &lv, attr_line_t &value_out) { bookmark_vector &user_marks = this->tc_bookmarks[&BM_USER]; - string_attrs_t & sa = value_out.get_attrs(); - string & str = value_out.get_string(); - highlight_map_t::iterator iter; - string::iterator str_iter; + string_attrs_t & sa = value_out.get_attrs(); + string & str = value_out.get_string(); + highlight_map_t::iterator iter; + string::iterator str_iter; this->tc_sub_source->text_value_for_line(*this, row, str); this->tc_sub_source->text_attrs_for_line(*this, row, sa); diff --git a/src/textview_curses.hh b/src/textview_curses.hh index 819ef31e..47512b95 100644 --- a/src/textview_curses.hh +++ b/src/textview_curses.hh @@ -155,9 +155,9 @@ public: if (this->h_code_extra != NULL) { pcre_extra *extra = this->h_code_extra; - extra->flags |= (PCRE_EXTRA_MATCH_LIMIT| + extra->flags |= (PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION); - extra->match_limit = 10000; + extra->match_limit = 10000; extra->match_limit_recursion = 500; } }; @@ -187,7 +187,7 @@ public: }; pcre * h_code; - pcre_extra *h_code_extra; + pcre_extra * h_code_extra; bool h_multiple; std::vector h_roles; }; diff --git a/src/top_status_source.hh b/src/top_status_source.hh index 64f3438c..cb191fdd 100644 --- a/src/top_status_source.hh +++ b/src/top_status_source.hh @@ -62,12 +62,14 @@ public: this->tss_fields[TSF_VIEW_NAME].set_width(6); 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_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_FORMAT].set_width(13); 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_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_FILENAME].set_min_width(35); /* XXX */ this->tss_fields[TSF_FILENAME].set_share(1); @@ -97,9 +99,9 @@ public: void update_filename(listview_curses *lc) { - status_field &sf_format = this->tss_fields[TSF_FORMAT]; - status_field &sf_filename = this->tss_fields[TSF_FILENAME]; - struct line_range lr = { 0, -1 }; + status_field & sf_format = this->tss_fields[TSF_FORMAT]; + status_field & sf_filename = this->tss_fields[TSF_FILENAME]; + struct line_range lr = { 0, -1 }; if (lc->get_inner_height() > 0) { attrs_map_t::iterator iter; @@ -136,8 +138,8 @@ public: sf_filename.clear(); } sf_format.get_value().get_attrs()[lr].insert( - make_string_attr("style", A_REVERSE|COLOR_PAIR( - view_colors::VC_CYAN_ON_BLACK))); + make_string_attr("style", A_REVERSE | COLOR_PAIR( + view_colors::VC_CYAN_ON_BLACK))); }; private: diff --git a/src/view_curses.cc b/src/view_curses.cc index c73e2f51..6ca674aa 100644 --- a/src/view_curses.cc +++ b/src/view_curses.cc @@ -287,8 +287,9 @@ void view_colors::init(void) for (int lpc = 0; lpc < 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); } } diff --git a/src/view_curses.hh b/src/view_curses.hh index 23abecd0..0dc81f7d 100644 --- a/src/view_curses.hh +++ b/src/view_curses.hh @@ -58,7 +58,7 @@ #include #include -#define KEY_CTRL_R 18 +#define KEY_CTRL_R 18 class view_curses; @@ -424,11 +424,13 @@ public: 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); }; - 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)); }; diff --git a/src/yajlpp.cc b/src/yajlpp.cc index 0fd3d9ee..cb4a187d 100644 --- a/src/yajlpp.cc +++ b/src/yajlpp.cc @@ -47,7 +47,7 @@ int yajlpp_parse_context::map_key(void *ctx, { yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx; - ypc->ypc_path = ypc->ypc_path.substr(0, ypc->ypc_path_index_stack.back()); + ypc->ypc_path = ypc->ypc_path.substr(0, ypc->ypc_path_index_stack.back()); ypc->ypc_path += "/" + std::string((const char *)key, len); ypc->update_callbacks(); @@ -64,11 +64,11 @@ void yajlpp_parse_context::update_callbacks(void) const json_path_handler &jph = this->ypc_handlers[lpc]; if (jph.jph_regex.match(this->ypc_pcre_context, pi)) { - this->ypc_callbacks.yajl_null = jph.jph_callbacks.yajl_null; + this->ypc_callbacks.yajl_null = jph.jph_callbacks.yajl_null; this->ypc_callbacks.yajl_boolean = jph.jph_callbacks.yajl_boolean; this->ypc_callbacks.yajl_integer = jph.jph_callbacks.yajl_integer; - this->ypc_callbacks.yajl_double = jph.jph_callbacks.yajl_double; - this->ypc_callbacks.yajl_string = jph.jph_callbacks.yajl_string; + this->ypc_callbacks.yajl_double = jph.jph_callbacks.yajl_double; + this->ypc_callbacks.yajl_string = jph.jph_callbacks.yajl_string; break; } } diff --git a/src/yajlpp.hh b/src/yajlpp.hh index e43c1153..ac99c801 100644 --- a/src/yajlpp.hh +++ b/src/yajlpp.hh @@ -61,43 +61,49 @@ yajl_gen_status yajl_gen_string(yajl_gen hand, const std::string &str) } 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)); }; - const char *jph_path; - pcrepp jph_regex; + const char * jph_path; + pcrepp jph_regex; yajl_callbacks jph_callbacks; }; struct json_path_handler : public json_path_handler_base { - json_path_handler(const char *path, int (*null_func)(void *)) - : json_path_handler_base(path) { - this->jph_callbacks.yajl_null = null_func; - }; + json_path_handler(const char *path, int(*null_func)(void *)) + : json_path_handler_base(path) + { + this->jph_callbacks.yajl_null = null_func; + }; - json_path_handler(const char *path, int (*bool_func)(void *, int)) - : json_path_handler_base(path) { - this->jph_callbacks.yajl_boolean = bool_func; - } + json_path_handler(const char *path, int(*bool_func)(void *, int)) + : json_path_handler_base(path) + { + this->jph_callbacks.yajl_boolean = bool_func; + } - json_path_handler(const char *path, int (*int_func)(void *, long long)) - : json_path_handler_base(path) { - this->jph_callbacks.yajl_integer = int_func; - } + json_path_handler(const char *path, int(*int_func)(void *, long long)) + : json_path_handler_base(path) + { + this->jph_callbacks.yajl_integer = int_func; + } - json_path_handler(const char *path, int (*double_func)(void *, double)) - : json_path_handler_base(path) { - this->jph_callbacks.yajl_double = double_func; - } + json_path_handler(const char *path, int(*double_func)(void *, double)) + : json_path_handler_base(path) + { + 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_base(path) { - this->jph_callbacks.yajl_string = str_func; - } + json_path_handler(const char *path, + int(*str_func)(void *, const unsigned char *, size_t)) + : json_path_handler_base(path) + { + 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 { @@ -106,45 +112,47 @@ public: struct json_path_element { json_path_element(int index = 0) : jpe_index(index) { }; 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) - : 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); }; std::string jpe_name; - 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; }; - std::string get_path_fragment(int offset) const { + std::string get_path_fragment(int offset) const + { size_t start, end; if (offset < 0) { offset = this->ypc_path_index_stack.size() + offset; } 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]; - else + } + else{ end = std::string::npos; + } return this->ypc_path.substr(start, end - start); }; struct json_path_handler *ypc_handlers; - void *ypc_userdata; - yajl_callbacks ypc_callbacks; - std::string ypc_path; - std::vector ypc_path_index_stack; + void * ypc_userdata; + yajl_callbacks ypc_callbacks; + std::string ypc_path; + std::vector ypc_path_index_stack; pcre_context_static<30> ypc_pcre_context; private: @@ -163,11 +171,13 @@ class yajlpp_generator { public: 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); }; - void operator()(long long value) { + void operator()(long long value) + { yajl_gen_integer(this->yg_handle, value); }; @@ -178,15 +188,15 @@ private: class yajlpp_container_base { public: 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); }; - void operator()(long long value) { + void operator()(long long value) + { yajl_gen_integer(this->ycb_handle, value); }; @@ -197,24 +207,22 @@ protected: }; class yajlpp_map : public yajlpp_container_base { - public: - yajlpp_map(yajl_gen handle) : yajlpp_container_base(handle) { + yajlpp_map(yajl_gen handle) : yajlpp_container_base(handle) + { yajl_gen_map_open(handle); }; ~yajlpp_map() { yajl_gen_map_close(this->ycb_handle); }; - }; class yajlpp_array : public yajlpp_container_base { - public: - yajlpp_array(yajl_gen handle) : yajlpp_container_base(handle) { + yajlpp_array(yajl_gen handle) : yajlpp_container_base(handle) + { yajl_gen_array_open(handle); }; ~yajlpp_array() { yajl_gen_array_close(this->ycb_handle); }; }; - #endif