mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
[yajlpp] support for array indexes in paths; also force log times to be in order
This commit is contained in:
parent
f1087184d6
commit
bb62711678
@ -161,6 +161,18 @@ void logfile::process_prefix(off_t offset, char *prefix, int len)
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (this->lf_index.size() >= 2) {
|
||||
logline &second_to_last = this->lf_index[this->lf_index.size() - 2];
|
||||
logline &latest = this->lf_index.back();
|
||||
|
||||
if (latest < second_to_last) {
|
||||
latest.set_time(second_to_last.get_time());
|
||||
latest.set_millis(second_to_last.get_millis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If the scanner didn't match, than we need to add it. */
|
||||
if (!found) {
|
||||
logline::level_t last_level = logline::LEVEL_UNKNOWN;
|
||||
|
@ -38,6 +38,11 @@ int yajlpp_parse_context::map_start(void *ctx)
|
||||
yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx;
|
||||
|
||||
ypc->ypc_path_index_stack.push_back(ypc->ypc_path.length());
|
||||
|
||||
if (ypc->ypc_path[ypc->ypc_path.size() - 1] == '#') {
|
||||
ypc->ypc_array_index.back() += 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -91,6 +96,7 @@ int yajlpp_parse_context::array_start(void *ctx)
|
||||
|
||||
ypc->ypc_path_index_stack.push_back(ypc->ypc_path.length());
|
||||
ypc->ypc_path += "#";
|
||||
ypc->ypc_array_index.push_back(-1);
|
||||
|
||||
ypc->update_callbacks();
|
||||
|
||||
@ -103,6 +109,7 @@ int yajlpp_parse_context::array_end(void *ctx)
|
||||
|
||||
ypc->ypc_path = ypc->ypc_path.substr(0, ypc->ypc_path_index_stack.back());
|
||||
ypc->ypc_path_index_stack.pop_back();
|
||||
ypc->ypc_array_index.pop_back();
|
||||
|
||||
ypc->update_callbacks();
|
||||
|
||||
|
@ -153,6 +153,7 @@ public:
|
||||
yajl_callbacks ypc_callbacks;
|
||||
std::string ypc_path;
|
||||
std::vector<size_t> ypc_path_index_stack;
|
||||
std::vector<int> ypc_array_index;
|
||||
pcre_context_static<30> ypc_pcre_context;
|
||||
|
||||
private:
|
||||
|
@ -34,7 +34,8 @@ check_PROGRAMS = \
|
||||
test_hist_source \
|
||||
test_line_buffer2 \
|
||||
test_pcrepp \
|
||||
test_top_status
|
||||
test_top_status \
|
||||
test_yajlpp
|
||||
|
||||
AM_LDFLAGS = \
|
||||
$(SQLITE3_LDFLAGS)
|
||||
@ -74,6 +75,9 @@ test_pcrepp_SOURCES = \
|
||||
test_top_status_SOURCES = test_top_status.cc
|
||||
test_top_status_LDADD = ../src/libdiag.a $(CURSES_LIB) -lz
|
||||
|
||||
test_yajlpp_SOURCES = test_yajlpp.cc
|
||||
test_yajlpp_LDADD = ../src/libdiag.a
|
||||
|
||||
drive_line_buffer_SOURCES = \
|
||||
../src/line_buffer.cc \
|
||||
drive_line_buffer.cc
|
||||
@ -219,7 +223,8 @@ TESTS = \
|
||||
test_view_colors.sh \
|
||||
test_vt52_curses.sh \
|
||||
test_top_status \
|
||||
test_data_parser.sh
|
||||
test_data_parser.sh \
|
||||
test_yajlpp
|
||||
|
||||
DISTCLEANFILES = \
|
||||
*.dat \
|
||||
|
@ -89,7 +89,8 @@ check_PROGRAMS = drive_data_scanner$(EXEEXT) \
|
||||
test_auto_fd$(EXEEXT) test_auto_mem$(EXEEXT) \
|
||||
test_bookmarks$(EXEEXT) test_grep_proc2$(EXEEXT) \
|
||||
test_hist_source$(EXEEXT) test_line_buffer2$(EXEEXT) \
|
||||
test_pcrepp$(EXEEXT) test_top_status$(EXEEXT)
|
||||
test_pcrepp$(EXEEXT) test_top_status$(EXEEXT) \
|
||||
test_yajlpp$(EXEEXT)
|
||||
TESTS = test_ansi_scrubber$(EXEEXT) test_auto_fd$(EXEEXT) \
|
||||
test_auto_mem$(EXEEXT) test_bookmarks$(EXEEXT) \
|
||||
test_line_buffer.sh test_line_buffer2$(EXEEXT) \
|
||||
@ -97,7 +98,8 @@ TESTS = test_ansi_scrubber$(EXEEXT) test_auto_fd$(EXEEXT) \
|
||||
test_hist_source$(EXEEXT) test_listview.sh \
|
||||
test_pcrepp$(EXEEXT) test_sql_coll_func.sh test_sql_fs_func.sh \
|
||||
test_view_colors.sh test_vt52_curses.sh \
|
||||
test_top_status$(EXEEXT) test_data_parser.sh
|
||||
test_top_status$(EXEEXT) test_data_parser.sh \
|
||||
test_yajlpp$(EXEEXT)
|
||||
subdir = test
|
||||
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
|
||||
$(top_srcdir)/mkinstalldirs $(dist_noinst_SCRIPTS) \
|
||||
@ -204,6 +206,9 @@ test_pcrepp_DEPENDENCIES =
|
||||
am_test_top_status_OBJECTS = test_top_status.$(OBJEXT)
|
||||
test_top_status_OBJECTS = $(am_test_top_status_OBJECTS)
|
||||
test_top_status_DEPENDENCIES = ../src/libdiag.a $(am__DEPENDENCIES_1)
|
||||
am_test_yajlpp_OBJECTS = test_yajlpp.$(OBJEXT)
|
||||
test_yajlpp_OBJECTS = $(am_test_yajlpp_OBJECTS)
|
||||
test_yajlpp_DEPENDENCIES = ../src/libdiag.a
|
||||
SCRIPTS = $(dist_noinst_SCRIPTS)
|
||||
AM_V_P = $(am__v_P_@AM_V@)
|
||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||
@ -248,7 +253,7 @@ SOURCES = $(drive_data_scanner_SOURCES) $(drive_grep_proc_SOURCES) \
|
||||
$(test_auto_mem_SOURCES) $(test_bookmarks_SOURCES) \
|
||||
$(test_grep_proc2_SOURCES) $(test_hist_source_SOURCES) \
|
||||
$(test_line_buffer2_SOURCES) $(test_pcrepp_SOURCES) \
|
||||
$(test_top_status_SOURCES)
|
||||
$(test_top_status_SOURCES) $(test_yajlpp_SOURCES)
|
||||
DIST_SOURCES = $(drive_data_scanner_SOURCES) \
|
||||
$(drive_grep_proc_SOURCES) $(drive_line_buffer_SOURCES) \
|
||||
$(drive_listview_SOURCES) $(drive_logfile_SOURCES) \
|
||||
@ -259,7 +264,8 @@ DIST_SOURCES = $(drive_data_scanner_SOURCES) \
|
||||
$(test_auto_fd_SOURCES) $(test_auto_mem_SOURCES) \
|
||||
$(test_bookmarks_SOURCES) $(test_grep_proc2_SOURCES) \
|
||||
$(test_hist_source_SOURCES) $(test_line_buffer2_SOURCES) \
|
||||
$(test_pcrepp_SOURCES) $(test_top_status_SOURCES)
|
||||
$(test_pcrepp_SOURCES) $(test_top_status_SOURCES) \
|
||||
$(test_yajlpp_SOURCES)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
@ -651,6 +657,8 @@ test_pcrepp_SOURCES = \
|
||||
|
||||
test_top_status_SOURCES = test_top_status.cc
|
||||
test_top_status_LDADD = ../src/libdiag.a $(CURSES_LIB) -lz
|
||||
test_yajlpp_SOURCES = test_yajlpp.cc
|
||||
test_yajlpp_LDADD = ../src/libdiag.a
|
||||
drive_line_buffer_SOURCES = \
|
||||
../src/line_buffer.cc \
|
||||
drive_line_buffer.cc
|
||||
@ -909,6 +917,10 @@ test_top_status$(EXEEXT): $(test_top_status_OBJECTS) $(test_top_status_DEPENDENC
|
||||
@rm -f test_top_status$(EXEEXT)
|
||||
$(AM_V_CXXLD)$(CXXLINK) $(test_top_status_OBJECTS) $(test_top_status_LDADD) $(LIBS)
|
||||
|
||||
test_yajlpp$(EXEEXT): $(test_yajlpp_OBJECTS) $(test_yajlpp_DEPENDENCIES) $(EXTRA_test_yajlpp_DEPENDENCIES)
|
||||
@rm -f test_yajlpp$(EXEEXT)
|
||||
$(AM_V_CXXLD)$(CXXLINK) $(test_yajlpp_OBJECTS) $(test_yajlpp_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
@ -947,6 +959,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_line_buffer2.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_pcrepp.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_top_status.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_yajlpp.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/view_curses.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vt52_curses.Po@am__quote@
|
||||
|
||||
@ -1458,6 +1471,13 @@ test_data_parser.sh.log: test_data_parser.sh
|
||||
--log-file $$b.log --trs-file $$b.trs \
|
||||
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
|
||||
"$$tst" $(AM_TESTS_FD_REDIRECT)
|
||||
test_yajlpp.log: test_yajlpp$(EXEEXT)
|
||||
@p='test_yajlpp$(EXEEXT)'; \
|
||||
b='test_yajlpp'; \
|
||||
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
|
||||
--log-file $$b.log --trs-file $$b.trs \
|
||||
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
|
||||
"$$tst" $(AM_TESTS_FD_REDIRECT)
|
||||
.test.log:
|
||||
@p='$<'; \
|
||||
$(am__set_b); \
|
||||
|
73
test/test_yajlpp.cc
Normal file
73
test/test_yajlpp.cc
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2013, Timothy Stack
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* * Neither the name of Timothy Stack nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @file test_yajlpp.cc
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "yajlpp.hh"
|
||||
|
||||
const char *TEST_DATA =
|
||||
"[{ \"foo\": 0 }, { \"foo\": 1 }]";
|
||||
|
||||
static int FOO_COUNT = 0;
|
||||
|
||||
static int read_foo(void *ctx, long long value)
|
||||
{
|
||||
yajlpp_parse_context *ypc = (yajlpp_parse_context *)ctx;
|
||||
|
||||
assert(value == FOO_COUNT);
|
||||
assert(ypc->ypc_array_index.back() == FOO_COUNT);
|
||||
|
||||
FOO_COUNT += 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct json_path_handler test_handlers[] = {
|
||||
json_path_handler("#/foo", read_foo),
|
||||
|
||||
json_path_handler()
|
||||
};
|
||||
|
||||
yajlpp_parse_context ypc(test_handlers);
|
||||
yajl_handle handle;
|
||||
|
||||
handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc);
|
||||
yajl_parse(handle, (const unsigned char *)TEST_DATA, strlen(TEST_DATA));
|
||||
yajl_complete_parse(handle);
|
||||
yajl_free(handle);
|
||||
|
||||
assert(FOO_COUNT == 2);
|
||||
}
|
Loading…
Reference in New Issue
Block a user