From fb7d6eafaf838b0252a4f08b6e331679d9fae75e Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Wed, 8 May 2019 05:30:59 -0700 Subject: [PATCH] [build] some refactoring of files --- configure.ac | 5 + src/CMakeLists.txt | 363 ++++++++++---------- src/Makefile.am | 58 +--- src/ansi_scrubber.cc | 2 +- src/auto_fd.hh | 2 +- src/auto_mem.hh | 41 +-- src/base/Makefile.am | 9 + src/{ => base}/lnav_log.cc | 0 src/{ => base}/lnav_log.hh | 0 src/{ => base}/pthreadpp.hh | 0 src/bookmarks.hh | 2 +- src/byte_array.hh | 2 +- src/command_executor.cc | 2 +- src/curl_looper.hh | 4 +- src/data_parser.hh | 4 +- src/data_scanner.cc | 2 +- src/data_scanner.hh | 2 +- src/db_sub_source.cc | 2 +- src/elem_to_json.cc | 2 +- src/environ_vtab.cc | 2 +- src/file_vtab.cc | 2 +- src/fmtlib/Makefile.am | 6 + src/fstat_vtab.cc | 2 +- src/grep_proc.cc | 2 +- src/grep_proc.hh | 4 +- src/help_text.hh | 206 +++++++++++ src/help_text_formatter.cc | 60 ++-- src/help_text_formatter.hh | 182 +--------- src/highlighter.hh | 2 +- src/hist_source.hh | 2 +- src/input_dispatcher.cc | 5 +- src/json-extension-functions.cc | 20 +- src/line_buffer.hh | 2 +- src/listview_curses.cc | 2 +- src/lnav.cc | 8 +- src/lnav.hh | 1 + src/lnav_commands.cc | 56 ++- src/lnav_config.cc | 63 ++-- src/lnav_config.hh | 2 +- src/lnav_util.cc | 2 +- src/log_accel.hh | 2 +- src/log_data_helper.hh | 4 +- src/log_format.cc | 4 +- src/log_format.hh | 6 +- src/log_format_impls.cc | 2 +- src/log_format_loader.cc | 4 +- src/log_level.cc | 2 +- src/log_vtab_impl.cc | 4 +- src/logfile.hh | 2 +- src/logfile_sub_source.hh | 2 +- src/papertrail_proc.cc | 2 +- src/papertrail_proc.hh | 2 +- src/pcrepp/Makefile.am | 12 + src/{ => pcrepp}/pcrepp.cc | 0 src/{ => pcrepp}/pcrepp.hh | 2 +- src/piper_proc.cc | 2 +- src/ptimec.hh | 2 +- src/readline_callbacks.cc | 4 +- src/readline_curses.cc | 4 +- src/readline_highlighters.cc | 2 +- src/readline_possibilities.cc | 2 +- src/regexp_vtab.cc | 2 +- src/relative_time.cc | 2 +- src/session_data.cc | 4 +- src/shared_buffer.hh | 2 +- src/shlex.hh | 2 +- src/simdutf8check.h | 2 +- src/sql_util.cc | 4 +- src/sqlite-extension-func.cc | 6 +- src/string-extension-functions.cc | 16 +- src/sysclip.cc | 2 +- src/text_format.cc | 2 +- src/textview_curses.cc | 2 +- src/textview_curses.hh | 2 +- src/timer.cc | 2 +- src/view_curses.cc | 6 +- src/view_curses.hh | 2 +- src/view_helpers.cc | 38 +- src/views_vtab.cc | 2 +- src/vt52_curses.cc | 2 +- src/vtab_module.hh | 2 +- src/xterm_mouse.cc | 63 ++++ src/xterm_mouse.hh | 72 +--- src/yajl/Makefile.am | 37 ++ src/yajlpp/Makefile.am | 52 +++ {test => src/yajlpp}/drive_json_op.cc | 4 +- {test => src/yajlpp}/drive_json_ptr_walk.cc | 53 ++- src/{ => yajlpp}/json_op.cc | 28 +- src/{ => yajlpp}/json_op.hh | 20 +- src/{ => yajlpp}/json_ptr.cc | 34 +- src/{ => yajlpp}/json_ptr.hh | 25 +- {test => src/yajlpp}/test_json_op.sh | 0 {test => src/yajlpp}/test_json_ptr.cc | 2 +- {test => src/yajlpp}/test_json_ptr_walk.sh | 12 +- {test => src/yajlpp}/test_yajlpp.cc | 4 +- src/{ => yajlpp}/yajlpp.cc | 1 - src/{ => yajlpp}/yajlpp.hh | 27 +- src/{ => yajlpp}/yajlpp_def.hh | 0 test/CMakeLists.txt | 35 +- test/Makefile.am | 122 ++----- test/drive_data_scanner.cc | 2 +- test/drive_sequencer.cc | 2 +- test/drive_sql.cc | 3 - test/test_ansi_scrubber.cc | 1 - test/test_pcrepp.cc | 2 +- 105 files changed, 970 insertions(+), 932 deletions(-) create mode 100644 src/base/Makefile.am rename src/{ => base}/lnav_log.cc (100%) rename src/{ => base}/lnav_log.hh (100%) rename src/{ => base}/pthreadpp.hh (100%) create mode 100644 src/fmtlib/Makefile.am create mode 100644 src/help_text.hh create mode 100644 src/pcrepp/Makefile.am rename src/{ => pcrepp}/pcrepp.cc (100%) rename src/{ => pcrepp}/pcrepp.hh (99%) create mode 100644 src/yajl/Makefile.am create mode 100644 src/yajlpp/Makefile.am rename {test => src/yajlpp}/drive_json_op.cc (99%) rename {test => src/yajlpp}/drive_json_ptr_walk.cc (66%) rename src/{ => yajlpp}/json_op.cc (91%) rename src/{ => yajlpp}/json_op.hh (87%) rename src/{ => yajlpp}/json_ptr.cc (93%) rename src/{ => yajlpp}/json_ptr.hh (89%) rename {test => src/yajlpp}/test_json_op.sh (100%) mode change 100644 => 100755 rename {test => src/yajlpp}/test_json_ptr.cc (98%) rename {test => src/yajlpp}/test_json_ptr_walk.sh (84%) rename {test => src/yajlpp}/test_yajlpp.cc (97%) rename src/{ => yajlpp}/yajlpp.cc (99%) rename src/{ => yajlpp}/yajlpp.hh (97%) rename src/{ => yajlpp}/yajlpp_def.hh (100%) diff --git a/configure.ac b/configure.ac index 148dbccb..9b37adf3 100644 --- a/configure.ac +++ b/configure.ac @@ -246,6 +246,11 @@ AC_CONFIG_HEADERS([src/config.h]) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([TESTS_ENVIRONMENT]) AC_CONFIG_FILES([src/Makefile]) +AC_CONFIG_FILES([src/base/Makefile]) +AC_CONFIG_FILES([src/fmtlib/Makefile]) +AC_CONFIG_FILES([src/pcrepp/Makefile]) +AC_CONFIG_FILES([src/yajl/Makefile]) +AC_CONFIG_FILES([src/yajlpp/Makefile]) AC_CONFIG_FILES([test/Makefile]) AC_OUTPUT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6c499a49..44f4ef0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,190 +1,191 @@ set(diag_STAT_SRCS - ansi_scrubber.cc - bookmarks.cc - bottom_status_source.cc - collation-functions.cc - command_executor.cc - curl_looper.cc - db_sub_source.cc - elem_to_json.cc - environ_vtab.cc - extension-functions.cc - field_overlay_source.cc - file_vtab.cc - filter_observer.cc - filter_status_source.cc - filter_sub_source.cc - fs-extension-functions.cc - fstat_vtab.cc - fts_fuzzy_match.cc - grep_proc.cc - help_text_formatter.cc - hist_source.cc - hotkeys.cc - input_dispatcher.cc - intern_string.cc - is_utf8.cc - json-extension-functions.cc - json_op.cc - json_ptr.cc - line_buffer.cc - listview_curses.cc - lnav_commands.cc - lnav_config.cc - lnav_log.cc - lnav_util.cc - log_accel.cc - log_actions.cc - log_format.cc - log_format_loader.cc - log_level.cc - logfile.cc - logfile_sub_source.cc - network-extension-functions.cc - data_scanner.cc - data_parser.cc - papertrail_proc.cc - ptimec_rt.cc - pretty_printer.cc - readline_callbacks.cc - readline_curses.cc - readline_highlighters.cc - readline_possibilities.cc - regexp_vtab.cc - relative_time.cc - session_data.cc - sequence_matcher.cc - shared_buffer.cc - shlex.cc - sqlite-extension-func.cc - statusview_curses.cc - string-extension-functions.cc - sysclip.cc - pcrepp.cc - piper_proc.cc - ptimec.cc - sql_util.cc - state-extension-functions.cc - strnatcmp.c - text_format.cc - textfile_highlighters.cc - textview_curses.cc - time-extension-functions.cc - timer.cc - unique_path.hh - view_curses.cc - view_helpers.cc - views_vtab.cc - vt52_curses.cc - vtab_module.cc - log_vtab_impl.cc - xterm_mouse.cc - yajlpp.cc - yajl/yajl.c - yajl/yajl_alloc.c - yajl/yajl_alloc.h - yajl/yajl_buf.c - yajl/yajl_buf.h - yajl/yajl_bytestack.h - yajl/yajl_encode.c - yajl/yajl_encode.h - yajl/yajl_gen.c - yajl/yajl_lex.c - yajl/yajl_lex.h - yajl/yajl_parser.c - yajl/yajl_parser.h - yajl/yajl_tree.c - yajl/yajl_version.c - spookyhash/SpookyV2.cpp + ansi_scrubber.cc + bookmarks.cc + bottom_status_source.cc + collation-functions.cc + command_executor.cc + curl_looper.cc + db_sub_source.cc + elem_to_json.cc + environ_vtab.cc + extension-functions.cc + field_overlay_source.cc + file_vtab.cc + filter_observer.cc + filter_status_source.cc + filter_sub_source.cc + fs-extension-functions.cc + fstat_vtab.cc + fts_fuzzy_match.cc + grep_proc.cc + help_text_formatter.cc + hist_source.cc + hotkeys.cc + input_dispatcher.cc + intern_string.cc + is_utf8.cc + json-extension-functions.cc + yajlpp/json_op.cc + yajlpp/json_ptr.cc + line_buffer.cc + listview_curses.cc + lnav_commands.cc + lnav_config.cc + base/lnav_log.cc + lnav_util.cc + log_accel.cc + log_actions.cc + log_format.cc + log_format_loader.cc + log_level.cc + logfile.cc + logfile_sub_source.cc + network-extension-functions.cc + data_scanner.cc + data_parser.cc + papertrail_proc.cc + ptimec_rt.cc + pretty_printer.cc + readline_callbacks.cc + readline_curses.cc + readline_highlighters.cc + readline_possibilities.cc + regexp_vtab.cc + relative_time.cc + session_data.cc + sequence_matcher.cc + shared_buffer.cc + shlex.cc + sqlite-extension-func.cc + statusview_curses.cc + string-extension-functions.cc + sysclip.cc + pcrepp/pcrepp.cc + piper_proc.cc + ptimec.cc + sql_util.cc + state-extension-functions.cc + strnatcmp.c + text_format.cc + textfile_highlighters.cc + textview_curses.cc + time-extension-functions.cc + timer.cc + unique_path.hh + view_curses.cc + view_helpers.cc + views_vtab.cc + vt52_curses.cc + vtab_module.cc + log_vtab_impl.cc + xterm_mouse.cc + yajlpp/yajlpp.cc + yajl/yajl.c + yajl/yajl_alloc.c + yajl/yajl_alloc.h + yajl/yajl_buf.c + yajl/yajl_buf.h + yajl/yajl_bytestack.h + yajl/yajl_encode.c + yajl/yajl_encode.h + yajl/yajl_gen.c + yajl/yajl_lex.c + yajl/yajl_lex.h + yajl/yajl_parser.c + yajl/yajl_parser.h + yajl/yajl_tree.c + yajl/yajl_version.c + spookyhash/SpookyV2.cpp - all_logs_vtab.hh - attr_line.hh - auto_fd.hh - auto_mem.hh - auto_pid.hh - big_array.hh - bottom_status_source.hh - byte_array.hh - command_executor.hh - column_namer.hh - curl_looper.hh - default-log-formats-json.hh - doc_status_source.hh - elem_to_json.hh - field_overlay_source.hh - file_vtab.hh - filter_observer.hh - filter_status_source.hh - filter_sub_source.hh - format-text-files.hh - fstat_vtab.hh - fts_fuzzy_match.hh - grep_highlighter.hh - help.hh - help_text_formatter.hh - highlighter.hh - hotkeys.hh - init-sql.hh - input_dispatcher.hh - intern_string.hh - is_utf8.hh - k_merge_tree.h - log_actions.hh - log_data_helper.hh - log_data_table.hh - log_format_impls.cc - log_gutter_source.hh - log_level.hh - log_search_table.hh - logfile_stats.hh - optional.hpp - papertrail_proc.hh - plain_text_source.hh - pretty_printer.hh - preview_status_source.hh - ptimec.hh - pthreadpp.hh - readline_callbacks.hh - readline_possibilities.hh - regexp_vtab.hh - relative_time.hh + all_logs_vtab.hh + attr_line.hh + auto_fd.hh + auto_mem.hh + auto_pid.hh + big_array.hh + bottom_status_source.hh + byte_array.hh + command_executor.hh + column_namer.hh + curl_looper.hh + default-log-formats-json.hh + doc_status_source.hh + elem_to_json.hh + field_overlay_source.hh + file_vtab.hh + filter_observer.hh + filter_status_source.hh + filter_sub_source.hh + format-text-files.hh + fstat_vtab.hh + fts_fuzzy_match.hh + grep_highlighter.hh + help.hh + help_text.hh + help_text_formatter.hh + highlighter.hh + hotkeys.hh + init-sql.hh + input_dispatcher.hh + intern_string.hh + is_utf8.hh + k_merge_tree.h + log_actions.hh + log_data_helper.hh + log_data_table.hh + log_format_impls.cc + log_gutter_source.hh + log_level.hh + log_search_table.hh + logfile_stats.hh + optional.hpp + papertrail_proc.hh + plain_text_source.hh + pretty_printer.hh + preview_status_source.hh + ptimec.hh + base/pthreadpp.hh + readline_callbacks.hh + readline_possibilities.hh + regexp_vtab.hh + relative_time.hh styling.hh - ring_span.hh - sequence_sink.hh - shlex.hh - simdutf8check.h - spectro_source.hh - strong_int.hh - sysclip.hh - term_extra.hh - termios_guard.hh - text_format.hh - textfile_highlighters.hh - textfile_sub_source.hh - time_T.hh - timer.hh - top_status_source.hh - url_loader.hh - views_vtab.hh - vtab_module.hh - xterm-palette.hh - yajlpp.hh - yajlpp_def.hh + ring_span.hh + sequence_sink.hh + shlex.hh + simdutf8check.h + spectro_source.hh + strong_int.hh + sysclip.hh + term_extra.hh + termios_guard.hh + text_format.hh + textfile_highlighters.hh + textfile_sub_source.hh + time_T.hh + timer.hh + top_status_source.hh + url_loader.hh + views_vtab.hh + vtab_module.hh + xterm-palette.hh + yajlpp/yajlpp.hh + yajlpp/yajlpp_def.hh - mapbox/recursive_wrapper.hpp - mapbox/variant.hpp - mapbox/variant_io.hpp - mapbox/variant_visitor.hpp + mapbox/recursive_wrapper.hpp + mapbox/variant.hpp + mapbox/variant_io.hpp + mapbox/variant_visitor.hpp - yajl/api/yajl_common.h - yajl/api/yajl_gen.h - yajl/api/yajl_parse.h - yajl/api/yajl_tree.h + yajl/api/yajl_common.h + yajl/api/yajl_gen.h + yajl/api/yajl_parse.h + yajl/api/yajl_tree.h - filesystem/fwd.h - filesystem/path.h - filesystem/resolver.h + filesystem/fwd.h + filesystem/path.h + filesystem/resolver.h fmtlib/posix.cc fmtlib/fmt/time.h @@ -201,7 +202,7 @@ set(diag_STAT_SRCS fmtlib/format.cc ../../lbuild-debug/src/config.h - ) + ) set(lnav_SRCS lnav.cc) diff --git a/src/Makefile.am b/src/Makefile.am index 50f73948..6cec1a59 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,6 @@ +SUBDIRS = base fmtlib pcrepp yajl yajlpp . + bin_PROGRAMS = lnav noinst_PROGRAMS = bin2c ptimec lnav-test @@ -129,6 +131,11 @@ AM_CPPFLAGS = \ LDADD = \ libdiag.a \ + base/libbase.a \ + fmtlib/libcppfmt.a \ + pcrepp/libpcrepp.a \ + yajl/libyajl.a \ + yajlpp/libyajlpp.a \ $(READLINE_LIBS) \ $(CURSES_LIB) \ $(SQLITE3_LIBS) \ @@ -186,6 +193,7 @@ noinst_HEADERS = \ grep_proc.hh \ help.hh \ help.txt \ + help_text.hh \ help_text_formatter.hh \ highlighter.hh \ hist_source.hh \ @@ -195,15 +203,12 @@ noinst_HEADERS = \ input_dispatcher.hh \ intern_string.hh \ is_utf8.hh \ - json_op.hh \ - json_ptr.hh \ k_merge_tree.h \ line_buffer.hh \ listview_curses.hh \ lnav.hh \ lnav_commands.hh \ lnav_config.hh \ - lnav_log.hh \ lnav_util.hh \ log_accel.hh \ log_actions.hh \ @@ -223,12 +228,10 @@ noinst_HEADERS = \ mapbox/variant_visitor.hpp \ optional.hpp \ papertrail_proc.hh \ - pcrepp.hh \ piper_proc.hh \ plain_text_source.hh \ pretty_printer.hh \ preview_status_source.hh \ - pthreadpp.hh \ ptimec.hh \ readline_callbacks.hh \ readline_curses.hh \ @@ -270,8 +273,6 @@ noinst_HEADERS = \ log_format_impls.cc \ xterm_mouse.hh \ xterm-palette.hh \ - yajlpp.hh \ - yajlpp_def.hh \ spookyhash/SpookyV2.h \ filesystem/fwd.h \ filesystem/path.h \ @@ -288,22 +289,6 @@ noinst_HEADERS = \ fmtlib/fmt/posix.h \ fmtlib/fmt/format.h -if USE_INCLUDED_YAJL -noinst_HEADERS += yajl/api/yajl_common.h \ - yajl/api/yajl_gen.h \ - yajl/api/yajl_parse.h \ - yajl/api/yajl_tree.h \ - yajl/yajl_alloc.h \ - yajl/yajl_buf.h \ - yajl/yajl_bytestack.h \ - yajl/yajl_common.h \ - yajl/yajl_encode.h \ - yajl/yajl_lex.h \ - yajl/yajl_parser.h \ - yajl/yajl_version.h -endif - - libdiag_a_SOURCES = \ ansi-palette.c \ ansi_scrubber.cc \ @@ -332,13 +317,10 @@ libdiag_a_SOURCES = \ intern_string.cc \ is_utf8.cc \ json-extension-functions.cc \ - json_op.cc \ - json_ptr.cc \ line_buffer.cc \ listview_curses.cc \ lnav_commands.cc \ lnav_config.cc \ - lnav_log.cc \ lnav_util.cc \ log_accel.cc \ log_actions.cc \ @@ -370,7 +352,6 @@ libdiag_a_SOURCES = \ string-extension-functions.cc \ text_format.cc \ timer.cc \ - pcrepp.cc \ piper_proc.cc \ sql_util.cc \ state-extension-functions.cc \ @@ -388,28 +369,7 @@ libdiag_a_SOURCES = \ log_vtab_impl.cc \ xterm_mouse.cc \ xterm-palette.c \ - yajlpp.cc \ - spookyhash/SpookyV2.cpp \ - fmtlib/posix.cc \ - fmtlib/format.cc - -if USE_INCLUDED_YAJL -libdiag_a_SOURCES += yajl/yajl.c \ - yajl/yajl_alloc.c \ - yajl/yajl_alloc.h \ - yajl/yajl_buf.c \ - yajl/yajl_buf.h \ - yajl/yajl_bytestack.h \ - yajl/yajl_encode.c \ - yajl/yajl_encode.h \ - yajl/yajl_gen.c \ - yajl/yajl_lex.c \ - yajl/yajl_lex.h \ - yajl/yajl_parser.c \ - yajl/yajl_parser.h \ - yajl/yajl_tree.c \ - yajl/yajl_version.c -endif + spookyhash/SpookyV2.cpp TEXT2C_FILES = \ ansi-palette.o \ diff --git a/src/ansi_scrubber.cc b/src/ansi_scrubber.cc index c6fb5815..eb58720d 100644 --- a/src/ansi_scrubber.cc +++ b/src/ansi_scrubber.cc @@ -34,7 +34,7 @@ #include #include "view_curses.hh" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "ansi_scrubber.hh" using namespace std; diff --git a/src/auto_fd.hh b/src/auto_fd.hh index dbe3d93a..c16bff88 100644 --- a/src/auto_fd.hh +++ b/src/auto_fd.hh @@ -39,7 +39,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" /** * Resource management class for file descriptors. diff --git a/src/auto_mem.hh b/src/auto_mem.hh index 1ae55f0f..e0bb66e7 100644 --- a/src/auto_mem.hh +++ b/src/auto_mem.hh @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007-2012, Timothy Stack + * Copyright (c) 2007-2019, Timothy Stack * * All rights reserved. * @@ -29,8 +29,8 @@ * @file auto_mem.hh */ -#ifndef __auto_mem_hh -#define __auto_mem_hh +#ifndef lnav_auto_mem_hh +#define lnav_auto_mem_hh #include #include @@ -49,23 +49,24 @@ typedef void (*free_func_t)(void *); template class auto_mem { public: - auto_mem(T *ptr = NULL) : am_ptr(ptr), am_free_func(default_free) { }; + explicit auto_mem(T *ptr = nullptr) + : am_ptr(ptr), am_free_func(default_free) { + }; - auto_mem(auto_mem & am) + auto_mem(auto_mem &am) : am_ptr(am.release()), am_free_func(am.am_free_func) {}; template - auto_mem(F free_func) - : am_ptr(NULL), am_free_func((free_func_t)free_func) { }; + explicit auto_mem(F free_func) + : am_ptr(nullptr), am_free_func((free_func_t)free_func) { }; - auto_mem(auto_mem &&other) : am_ptr(nullptr) { - this->reset(other.release()); - this->am_free_func = other.am_free_func; + auto_mem(auto_mem &&other) noexcept + : am_ptr(other.release()), + am_free_func(other.am_free_func) { }; - ~auto_mem() - { + ~auto_mem() { this->reset(); }; @@ -88,7 +89,7 @@ public: { T *retval = this->am_ptr; - this->am_ptr = NULL; + this->am_ptr = nullptr; return retval; }; @@ -103,10 +104,10 @@ public: return &this->am_ptr; }; - void reset(T *ptr = NULL) + void reset(T *ptr = nullptr) { if (this->am_ptr != ptr) { - if (this->am_ptr != NULL) { + if (this->am_ptr != nullptr) { this->am_free_func((void *)this->am_ptr); } this->am_ptr = ptr; @@ -121,18 +122,17 @@ private: template class static_root_mem { public: - static_root_mem() - { + static_root_mem() { memset(&this->srm_value, 0, sizeof(T)); }; ~static_root_mem() { free_func(&this->srm_value); }; - const T *operator->(void) const { return &this->srm_value; }; + const T *operator->() const { return &this->srm_value; }; - const T &in(void) const { return this->srm_value; }; + const T &in() const { return this->srm_value; }; - T *inout(void) { + T *inout() { free_func(&this->srm_value); memset(&this->srm_value, 0, sizeof(T)); return &this->srm_value; @@ -145,4 +145,5 @@ private: T srm_value; }; + #endif diff --git a/src/base/Makefile.am b/src/base/Makefile.am new file mode 100644 index 00000000..6de3714b --- /dev/null +++ b/src/base/Makefile.am @@ -0,0 +1,9 @@ + +noinst_LIBRARIES = libbase.a + +noinst_HEADERS = \ + lnav_log.hh \ + pthreadpp.hh + +libbase_a_SOURCES = \ + lnav_log.cc diff --git a/src/lnav_log.cc b/src/base/lnav_log.cc similarity index 100% rename from src/lnav_log.cc rename to src/base/lnav_log.cc diff --git a/src/lnav_log.hh b/src/base/lnav_log.hh similarity index 100% rename from src/lnav_log.hh rename to src/base/lnav_log.hh diff --git a/src/pthreadpp.hh b/src/base/pthreadpp.hh similarity index 100% rename from src/pthreadpp.hh rename to src/base/pthreadpp.hh diff --git a/src/bookmarks.hh b/src/bookmarks.hh index 45d3aa80..f4482545 100644 --- a/src/bookmarks.hh +++ b/src/bookmarks.hh @@ -40,7 +40,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" struct bookmark_metadata { static std::set KNOWN_TAGS; diff --git a/src/byte_array.hh b/src/byte_array.hh index edb66314..a2ad623e 100644 --- a/src/byte_array.hh +++ b/src/byte_array.hh @@ -35,7 +35,7 @@ #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" template struct byte_array { diff --git a/src/command_executor.cc b/src/command_executor.cc index 20e1fe15..d5e9a3b2 100644 --- a/src/command_executor.cc +++ b/src/command_executor.cc @@ -31,7 +31,7 @@ #include -#include "json_ptr.hh" +#include "yajlpp/json_ptr.hh" #include "pcrecpp.h" #include "lnav.hh" #include "log_format_loader.hh" diff --git a/src/curl_looper.hh b/src/curl_looper.hh index a7113be0..9b420a32 100644 --- a/src/curl_looper.hh +++ b/src/curl_looper.hh @@ -59,9 +59,9 @@ public: #include #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" -#include "pthreadpp.hh" +#include "base/pthreadpp.hh" class curl_request { public: diff --git a/src/data_parser.hh b/src/data_parser.hh index 030dc401..90a48b96 100644 --- a/src/data_parser.hh +++ b/src/data_parser.hh @@ -40,9 +40,9 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "byte_array.hh" #include "data_scanner.hh" diff --git a/src/data_scanner.cc b/src/data_scanner.cc index 9fe56b50..f144f3d1 100644 --- a/src/data_scanner.cc +++ b/src/data_scanner.cc @@ -33,7 +33,7 @@ #include #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "data_scanner.hh" using namespace std; diff --git a/src/data_scanner.hh b/src/data_scanner.hh index 290fa0a8..cabef56b 100644 --- a/src/data_scanner.hh +++ b/src/data_scanner.hh @@ -32,7 +32,7 @@ #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "shared_buffer.hh" enum data_token_t { diff --git a/src/db_sub_source.cc b/src/db_sub_source.cc index 2ca5587f..2cf4900b 100644 --- a/src/db_sub_source.cc +++ b/src/db_sub_source.cc @@ -29,7 +29,7 @@ #include "config.h" -#include "json_ptr.hh" +#include "yajlpp/json_ptr.hh" #include "db_sub_source.hh" const char *db_label_source::NULL_STR = ""; diff --git a/src/elem_to_json.cc b/src/elem_to_json.cc index 39dc61b1..a7d3048c 100644 --- a/src/elem_to_json.cc +++ b/src/elem_to_json.cc @@ -30,7 +30,7 @@ #include "config.h" #include "elem_to_json.hh" -#include "yajlpp.hh" +#include "yajlpp/yajlpp.hh" using namespace std; diff --git a/src/environ_vtab.cc b/src/environ_vtab.cc index ab51e50e..9fc4adc5 100644 --- a/src/environ_vtab.cc +++ b/src/environ_vtab.cc @@ -35,7 +35,7 @@ #include #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sql_util.hh" #include "environ_vtab.hh" diff --git a/src/file_vtab.cc b/src/file_vtab.cc index 887c0f48..660b9637 100644 --- a/src/file_vtab.cc +++ b/src/file_vtab.cc @@ -35,7 +35,7 @@ #include "lnav.hh" #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sql_util.hh" #include "file_vtab.hh" #include "vtab_module.hh" diff --git a/src/fmtlib/Makefile.am b/src/fmtlib/Makefile.am new file mode 100644 index 00000000..90939129 --- /dev/null +++ b/src/fmtlib/Makefile.am @@ -0,0 +1,6 @@ + +noinst_LIBRARIES = libcppfmt.a + +libcppfmt_a_SOURCES = \ + format.cc \ + posix.cc diff --git a/src/fstat_vtab.cc b/src/fstat_vtab.cc index 54eae205..079702f2 100644 --- a/src/fstat_vtab.cc +++ b/src/fstat_vtab.cc @@ -38,7 +38,7 @@ #include #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sql_util.hh" #include "vtab_module.hh" #include "fstat_vtab.hh" diff --git a/src/grep_proc.cc b/src/grep_proc.cc index 135f0848..02723686 100644 --- a/src/grep_proc.cc +++ b/src/grep_proc.cc @@ -40,7 +40,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" #include "grep_proc.hh" #include "listview_curses.hh" diff --git a/src/grep_proc.hh b/src/grep_proc.hh index cbcaae25..5e9aa5b1 100644 --- a/src/grep_proc.hh +++ b/src/grep_proc.hh @@ -50,10 +50,10 @@ #include #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "auto_fd.hh" #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "strong_int.hh" #include "line_buffer.hh" diff --git a/src/help_text.hh b/src/help_text.hh new file mode 100644 index 00000000..7ea49fbe --- /dev/null +++ b/src/help_text.hh @@ -0,0 +1,206 @@ +/** + * Copyright (c) 2019, Timothy Stack + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Timothy Stack nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LNAV_HELP_TEXT_HH +#define LNAV_HELP_TEXT_HH + +#include +#include +#include + +enum class help_context_t { + HC_NONE, + HC_PARAMETER, + HC_RESULT, + HC_COMMAND, + HC_SQL_KEYWORD, + HC_SQL_FUNCTION, + HC_SQL_TABLE_VALUED_FUNCTION, +}; + +enum class help_nargs_t { + HN_REQUIRED, + HN_OPTIONAL, + HN_ZERO_OR_MORE, + HN_ONE_OR_MORE, +}; + +enum class help_parameter_format_t { + HPF_STRING, + HPF_REGEX, + HPF_INTEGER, + HPF_NUMBER, + HPF_DATETIME, + HPF_ENUM, +}; + +struct help_example { + const char *he_cmd{nullptr}; + const char *he_result{nullptr}; +}; + +struct help_text { + help_context_t ht_context{help_context_t::HC_NONE}; + const char *ht_name{nullptr}; + const char *ht_summary{nullptr}; + const char *ht_flag_name{nullptr}; + const char *ht_group_start{nullptr}; + const char *ht_group_end{nullptr}; + const char *ht_description{nullptr}; + std::vector ht_parameters; + std::vector ht_results; + std::vector ht_example; + help_nargs_t ht_nargs{help_nargs_t::HN_REQUIRED}; + help_parameter_format_t ht_format{help_parameter_format_t::HPF_STRING}; + std::vector ht_enum_values; + std::vector ht_tags; + std::vector ht_opposites; + + help_text() = default; + + help_text(const char *name, const char *summary = nullptr) + : ht_name(name), + ht_summary(summary) { + if (name[0] == ':') { + this->ht_context = help_context_t::HC_COMMAND; + this->ht_name = &name[1]; + } + }; + + help_text &command() { + this->ht_context = help_context_t::HC_COMMAND; + return *this; + }; + + help_text &sql_function() { + this->ht_context = help_context_t::HC_SQL_FUNCTION; + return *this; + }; + + help_text &sql_table_valued_function() { + this->ht_context = help_context_t::HC_SQL_TABLE_VALUED_FUNCTION; + return *this; + }; + + help_text &sql_keyword() { + this->ht_context = help_context_t::HC_SQL_KEYWORD; + return *this; + }; + + help_text &with_summary(const char *summary) { + this->ht_summary = summary; + return *this; + }; + + help_text &with_flag_name(const char *flag) { + this->ht_flag_name = flag; + return *this; + } + + help_text &with_grouping(const char *group_start, const char *group_end) { + this->ht_group_start = group_start; + this->ht_group_end = group_end; + return *this; + } + + help_text &with_parameters(const std::initializer_list ¶ms) { + this->ht_parameters = params; + for (auto ¶m : this->ht_parameters) { + param.ht_context = help_context_t::HC_PARAMETER; + } + return *this; + } + + help_text &with_parameter(const help_text &ht) { + this->ht_parameters.emplace_back(ht); + this->ht_parameters.back().ht_context = help_context_t::HC_PARAMETER; + return *this; + }; + + help_text &with_result(const help_text &ht) { + this->ht_results.emplace_back(ht); + this->ht_results.back().ht_context = help_context_t::HC_RESULT; + return *this; + }; + + help_text &with_examples(const std::initializer_list &examples) { + this->ht_example = examples; + return *this; + } + + help_text &with_example(const help_example &example) { + this->ht_example.emplace_back(example); + return *this; + } + + help_text &optional() { + this->ht_nargs = help_nargs_t::HN_OPTIONAL; + return *this; + }; + + help_text &zero_or_more() { + this->ht_nargs = help_nargs_t::HN_ZERO_OR_MORE; + return *this; + }; + + help_text &one_or_more() { + this->ht_nargs = help_nargs_t::HN_ONE_OR_MORE; + return *this; + }; + + help_text &with_format(help_parameter_format_t format) { + this->ht_format = format; + return *this; + } + + help_text &with_enum_values(const std::initializer_list &enum_values) { + this->ht_enum_values = enum_values; + return *this; + }; + + help_text &with_tags(const std::initializer_list &tags) { + this->ht_tags = tags; + return *this; + }; + + help_text &with_opposites(const std::initializer_list &opps) { + this->ht_opposites = opps; + return *this; + }; + + void index_tags() { + for (const auto &tag: this->ht_tags) { + TAGGED.insert(std::make_pair(tag, this)); + } + }; + + static std::multimap TAGGED; +}; + +#endif diff --git a/src/help_text_formatter.cc b/src/help_text_formatter.cc index 83e8ed31..2dc1f373 100644 --- a/src/help_text_formatter.cc +++ b/src/help_text_formatter.cc @@ -43,7 +43,7 @@ std::multimap help_text::TAGGED; void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, bool synopsis_only) { - static size_t body_indent = 2; + static const size_t body_indent = 2; view_colors &vc = view_colors::singleton(); text_wrap_settings tws; @@ -52,7 +52,7 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, tws.with_width(width); switch (ht.ht_context) { - case HC_COMMAND: { + case help_context_t::HC_COMMAND: { out.append("Synopsis", &view_curses::VC_STYLE, A_UNDERLINE) .append("\n") .append(body_indent, ' ') @@ -60,14 +60,14 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, .append(ht.ht_name, &view_curses::VC_STYLE, A_BOLD); for (auto ¶m : ht.ht_parameters) { out.append(" "); - if (param.ht_nargs == HN_OPTIONAL) { + if (param.ht_nargs == help_nargs_t::HN_OPTIONAL) { out.append("["); } out.append(param.ht_name, &view_curses::VC_STYLE, A_UNDERLINE); - if (param.ht_nargs == HN_OPTIONAL) { + if (param.ht_nargs == help_nargs_t::HN_OPTIONAL) { out.append("]"); } - if (param.ht_nargs == HN_ONE_OR_MORE) { + if (param.ht_nargs == help_nargs_t::HN_ONE_OR_MORE) { out.append("1", &view_curses::VC_STYLE, A_UNDERLINE); out.append(" ["); out.append("...", &view_curses::VC_STYLE, A_UNDERLINE); @@ -84,8 +84,8 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, .append("\n"); break; } - case HC_SQL_FUNCTION: - case HC_SQL_TABLE_VALUED_FUNCTION: { + case help_context_t::HC_SQL_FUNCTION: + case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: { bool needs_comma = false; out.append("Synopsis", &view_curses::VC_STYLE, A_UNDERLINE) @@ -102,8 +102,8 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, out.append(", "); } out.append(param.ht_name, &view_curses::VC_STYLE, A_UNDERLINE); - if (param.ht_nargs == HN_ZERO_OR_MORE || - param.ht_nargs == HN_ONE_OR_MORE) { + if (param.ht_nargs == help_nargs_t::HN_ZERO_OR_MORE || + param.ht_nargs == help_nargs_t::HN_ONE_OR_MORE) { out.append(", ..."); } needs_comma = true; @@ -114,7 +114,7 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, .append("\n"); break; } - case HC_SQL_KEYWORD: { + case help_context_t::HC_SQL_KEYWORD: { size_t line_start = body_indent; bool break_all = false; @@ -133,8 +133,8 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, out.append(body_indent + strlen(ht.ht_name) + 1, ' '); break_all = true; } - if (param.ht_nargs == HN_ZERO_OR_MORE || - param.ht_nargs == HN_OPTIONAL) { + if (param.ht_nargs == help_nargs_t::HN_ZERO_OR_MORE || + param.ht_nargs == help_nargs_t::HN_OPTIONAL) { if (!break_all) { out.append(" "); } @@ -155,8 +155,8 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, .append(param.ht_name, &view_curses::VC_STYLE, A_UNDERLINE); if (!param.ht_parameters.empty()) { - if (param.ht_nargs == HN_ZERO_OR_MORE || - param.ht_nargs == HN_ONE_OR_MORE) { + if (param.ht_nargs == help_nargs_t::HN_ZERO_OR_MORE || + param.ht_nargs == help_nargs_t::HN_ONE_OR_MORE) { out.append("1", &view_curses::VC_STYLE, A_UNDERLINE); } if (param.ht_parameters[0].ht_flag_name) { @@ -171,8 +171,8 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, A_UNDERLINE); } } - if (param.ht_nargs == HN_ZERO_OR_MORE || - param.ht_nargs == HN_ONE_OR_MORE) { + if (param.ht_nargs == help_nargs_t::HN_ZERO_OR_MORE || + param.ht_nargs == help_nargs_t::HN_ONE_OR_MORE) { bool needs_comma = param.ht_parameters.empty() || !param.ht_flag_name; @@ -209,8 +209,8 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, .append(param.ht_group_end, &view_curses::VC_STYLE, A_BOLD); } - if (param.ht_nargs == HN_ZERO_OR_MORE || - param.ht_nargs == HN_OPTIONAL) { + if (param.ht_nargs == help_nargs_t::HN_ZERO_OR_MORE || + param.ht_nargs == help_nargs_t::HN_OPTIONAL) { out.append("]"); } } @@ -312,11 +312,11 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, string name = related.ht_name; switch (related.ht_context) { - case HC_COMMAND: + case help_context_t::HC_COMMAND: name = ":" + name; break; - case HC_SQL_FUNCTION: - case HC_SQL_TABLE_VALUED_FUNCTION: + case help_context_t::HC_SQL_FUNCTION: + case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: name = name + "()"; break; default: @@ -349,19 +349,17 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, } } -void format_example_text_for_term(const help_text &ht, int width, attr_line_t &out) +void format_example_text_for_term(const help_text &ht, + const help_example_to_attr_line_fun_t eval, + int width, attr_line_t &out) { text_wrap_settings tws; tws.with_width(width); if (!ht.ht_example.empty()) { - map vars; int count = 1; - vars["name"] = ht.ht_name; - add_ansi_vars(vars); - out.append(ht.ht_example.size() == 1 ? "Example" : "Examples", &view_curses::VC_STYLE, A_UNDERLINE) @@ -379,15 +377,15 @@ void format_example_text_for_term(const help_text &ht, int width, attr_line_t &o out.append("\n"); } switch (ht.ht_context) { - case HC_COMMAND: + case help_context_t::HC_COMMAND: ex_line.insert(0, 1, ' '); ex_line.insert(0, 1, ':'); ex_line.insert(1, ht.ht_name); readline_command_highlighter(ex_line, 0); break; - case HC_SQL_KEYWORD: - case HC_SQL_FUNCTION: - case HC_SQL_TABLE_VALUED_FUNCTION: + case help_context_t::HC_SQL_KEYWORD: + case help_context_t::HC_SQL_FUNCTION: + case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: readline_sqlite_highlighter(ex_line, 0); prompt = ";"; break; @@ -402,7 +400,7 @@ void format_example_text_for_term(const help_text &ht, int width, attr_line_t &o .append(ex_line, &tws.with_indent(3 + keyword_offset + 1)) .append("\n") .append(3, ' ') - .append(ex.he_result, &tws.with_indent(3)) + .append(eval(ht, ex), &tws.with_indent(3)) .append("\n"); count += 1; diff --git a/src/help_text_formatter.hh b/src/help_text_formatter.hh index 6dd23480..82799b42 100644 --- a/src/help_text_formatter.hh +++ b/src/help_text_formatter.hh @@ -30,184 +30,18 @@ #ifndef LNAV_HELP_TEXT_FORMATTER_HH #define LNAV_HELP_TEXT_FORMATTER_HH -#include -#include -#include +#include +#include "help_text.hh" #include "attr_line.hh" -enum help_context_t { - HC_NONE, - HC_PARAMETER, - HC_RESULT, - HC_COMMAND, - HC_SQL_KEYWORD, - HC_SQL_FUNCTION, - HC_SQL_TABLE_VALUED_FUNCTION, -}; - -enum help_nargs_t { - HN_REQUIRED, - HN_OPTIONAL, - HN_ZERO_OR_MORE, - HN_ONE_OR_MORE, -}; - -enum help_parameter_format_t { - HPF_STRING, - HPF_REGEX, - HPF_INTEGER, - HPF_NUMBER, - HPF_DATETIME, - HPF_ENUM, -}; - -struct help_example { - const char *he_cmd; - attr_line_t he_result; -}; - -struct help_text { - help_context_t ht_context{HC_NONE}; - const char *ht_name; - const char *ht_summary; - const char *ht_flag_name{nullptr}; - const char *ht_group_start{nullptr}; - const char *ht_group_end{nullptr}; - const char *ht_description{nullptr}; - std::vector ht_parameters; - std::vector ht_results; - std::vector ht_example; - help_nargs_t ht_nargs{HN_REQUIRED}; - help_parameter_format_t ht_format{HPF_STRING}; - std::vector ht_enum_values; - std::vector ht_tags; - std::vector ht_opposites; - - help_text() { - - }; - - help_text(const char *name, const char *summary = nullptr) - : ht_name(name), - ht_summary(summary) { - if (name[0] == ':') { - this->ht_context = HC_COMMAND; - this->ht_name = &name[1]; - } - }; - - help_text &command() { - this->ht_context = HC_COMMAND; - return *this; - }; - - help_text &sql_function() { - this->ht_context = HC_SQL_FUNCTION; - return *this; - }; - - help_text &sql_table_valued_function() { - this->ht_context = HC_SQL_TABLE_VALUED_FUNCTION; - return *this; - }; - - help_text &sql_keyword() { - this->ht_context = HC_SQL_KEYWORD; - return *this; - }; - - help_text &with_summary(const char *summary) { - this->ht_summary = summary; - return *this; - }; - - help_text &with_flag_name(const char *flag) { - this->ht_flag_name = flag; - return *this; - } - - help_text &with_grouping(const char *group_start, const char *group_end) { - this->ht_group_start = group_start; - this->ht_group_end = group_end; - return *this; - } - - help_text &with_parameters(const std::initializer_list ¶ms) { - this->ht_parameters = params; - for (auto ¶m : this->ht_parameters) { - param.ht_context = HC_PARAMETER; - } - return *this; - } - - help_text &with_parameter(const help_text &ht) { - this->ht_parameters.emplace_back(ht); - this->ht_parameters.back().ht_context = HC_PARAMETER; - return *this; - }; - - help_text &with_result(const help_text &ht) { - this->ht_results.emplace_back(ht); - this->ht_results.back().ht_context = HC_RESULT; - return *this; - }; - - help_text &with_examples(const std::initializer_list &examples) { - this->ht_example = examples; - return *this; - } - - help_text &with_example(const help_example &example) { - this->ht_example.emplace_back(example); - return *this; - } - - help_text &optional() { - this->ht_nargs = HN_OPTIONAL; - return *this; - }; - - help_text &zero_or_more() { - this->ht_nargs = HN_ZERO_OR_MORE; - return *this; - }; - - help_text &one_or_more() { - this->ht_nargs = HN_ONE_OR_MORE; - return *this; - }; - - help_text &with_format(help_parameter_format_t format) { - this->ht_format = format; - return *this; - } - - help_text &with_enum_values(const std::initializer_list &enum_values) { - this->ht_enum_values = enum_values; - return *this; - }; - - help_text &with_tags(const std::initializer_list &tags) { - this->ht_tags = tags; - return *this; - }; - - help_text &with_opposites(const std::initializer_list &opps) { - this->ht_opposites = opps; - return *this; - }; - - void index_tags() { - for (const auto &tag: this->ht_tags) { - TAGGED.insert(std::make_pair(tag, this)); - } - }; - - static std::multimap TAGGED; -}; +using help_example_to_attr_line_fun_t = + std::function; void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out, bool synopsis_only = false); -void format_example_text_for_term(const help_text &ht, int width, attr_line_t &out); +void format_example_text_for_term( + const help_text &ht, + const help_example_to_attr_line_fun_t eval, + int width, attr_line_t &out); #endif //LNAV_HELP_TEXT_FORMATTER_HH diff --git a/src/highlighter.hh b/src/highlighter.hh index de3b533c..76184768 100644 --- a/src/highlighter.hh +++ b/src/highlighter.hh @@ -33,7 +33,7 @@ #define __highlighter_hh #include "optional.hpp" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "text_format.hh" #include "view_curses.hh" diff --git a/src/hist_source.hh b/src/hist_source.hh index cefeb252..6678731f 100644 --- a/src/hist_source.hh +++ b/src/hist_source.hh @@ -40,7 +40,7 @@ #include "mapbox/variant.hpp" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "strong_int.hh" #include "textview_curses.hh" diff --git a/src/input_dispatcher.cc b/src/input_dispatcher.cc index 38b4497d..9bc33cb7 100644 --- a/src/input_dispatcher.cc +++ b/src/input_dispatcher.cc @@ -48,6 +48,7 @@ # error "SysV or X/Open-compatible Curses header file required" #endif +#include "base/lnav_log.hh" #include "input_dispatcher.hh" void input_dispatcher::new_input(const struct timeval ¤t_time, int ch) @@ -63,12 +64,12 @@ void input_dispatcher::new_input(const struct timeval ¤t_time, int ch) break; default: if (this->id_escape_index > 0) { + this->append_to_escape_buffer(ch); + if (strcmp("\x1b[", this->id_escape_buffer) == 0) { this->id_mouse_handler(); this->id_escape_index = 0; } else { - this->append_to_escape_buffer(ch); - switch (this->id_escape_matcher(this->id_escape_buffer)) { case escape_match_t::NONE: for (int lpc = 0; this->id_escape_buffer[lpc]; lpc++) { diff --git a/src/json-extension-functions.cc b/src/json-extension-functions.cc index 02dd0f0d..6c4a0bd6 100644 --- a/src/json-extension-functions.cc +++ b/src/json-extension-functions.cc @@ -40,8 +40,8 @@ #include "sqlite3.h" -#include "yajlpp.hh" -#include "json_op.hh" +#include "yajlpp/yajlpp.hh" +#include "yajlpp/json_op.hh" #include "mapbox/variant.hpp" #include "vtab_module.hh" @@ -197,18 +197,17 @@ static void sql_jget(sqlite3_context *context, const char *ptr_in = (const char *)sqlite3_value_text(argv[1]); json_ptr jp(ptr_in); sql_json_op jo(jp); - auto_mem gen(yajl_gen_free); auto_mem handle(yajl_free); const unsigned char *err; + yajlpp_gen gen; - gen = yajl_gen_alloc(nullptr); - yajl_gen_config(gen.in(), yajl_gen_beautify, false); + yajl_gen_config(gen, yajl_gen_beautify, false); jo.jo_ptr_callbacks = json_op::gen_callbacks; jo.jo_ptr_callbacks.yajl_null = gen_handle_null; jo.jo_ptr_callbacks.yajl_boolean = gen_handle_boolean; jo.jo_ptr_callbacks.yajl_string = gen_handle_string; - jo.jo_ptr_data = gen.in(); + jo.jo_ptr_data = gen.get_handle(); handle.reset(yajl_alloc(&json_op::ptr_callbacks, nullptr, &jo)); switch (yajl_parse(handle.in(), (const unsigned char *)json_in, strlen(json_in))) { @@ -257,17 +256,14 @@ static void sql_jget(sqlite3_context *context, return; } - const unsigned char *buf; - size_t len; + string_fragment result = gen.to_string_fragment(); - yajl_gen_get_buf(gen, &buf, &len); - - if (len == 0) { + if (result.empty()) { null_or_default(context, argc, argv); return; } - sqlite3_result_text(context, (const char *) buf, len, SQLITE_TRANSIENT); + sqlite3_result_text(context, result.data(), result.length(), SQLITE_TRANSIENT); } struct json_agg_context { diff --git a/src/line_buffer.hh b/src/line_buffer.hh index 1dc01322..ca6dcb50 100644 --- a/src/line_buffer.hh +++ b/src/line_buffer.hh @@ -39,7 +39,7 @@ #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "auto_fd.hh" #include "auto_mem.hh" #include "shared_buffer.hh" diff --git a/src/listview_curses.cc b/src/listview_curses.cc index 224bf799..e7a29aca 100644 --- a/src/listview_curses.cc +++ b/src/listview_curses.cc @@ -36,7 +36,7 @@ #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "listview_curses.hh" using namespace std; diff --git a/src/lnav.cc b/src/lnav.cc index a5f1f383..b88d6671 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -83,7 +83,7 @@ #include "help.hh" #include "init-sql.hh" #include "logfile.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "log_accel.hh" #include "lnav_util.hh" #include "ansi_scrubber.hh" @@ -133,7 +133,7 @@ #endif #include "papertrail_proc.hh" -#include "yajlpp.hh" +#include "yajlpp/yajlpp.hh" #include "readline_callbacks.hh" #include "command_executor.hh" #include "plain_text_source.hh" @@ -338,8 +338,8 @@ bool setup_logline_table(exec_context &ec) for (const auto &pair : sqlite_function_help) { switch (pair.second->ht_context) { - case HC_SQL_FUNCTION: - case HC_SQL_TABLE_VALUED_FUNCTION: { + case help_context_t::HC_SQL_FUNCTION: + case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: { string poss = pair.first + (pair.second->ht_parameters.empty() ? "()" : ("(")); diff --git a/src/lnav.hh b/src/lnav.hh index 58a0ae47..6b1f4aa1 100644 --- a/src/lnav.hh +++ b/src/lnav.hh @@ -332,6 +332,7 @@ extern const ssize_t ZOOM_COUNT; void rebuild_hist(); void rebuild_indexes(); void execute_examples(); +attr_line_t eval_example(const help_text &ht, const help_example &ex); bool ensure_view(textview_curses *expected_tc); bool toggle_view(textview_curses *toggle_tc); diff --git a/src/lnav_commands.cc b/src/lnav_commands.cc index a407af3b..0d867629 100644 --- a/src/lnav_commands.cc +++ b/src/lnav_commands.cc @@ -58,7 +58,7 @@ #include "yajl/api/yajl_parse.h" #include "db_sub_source.hh" #include "papertrail_proc.hh" -#include "json_op.hh" +#include "yajlpp/json_op.hh" using namespace std; @@ -767,30 +767,22 @@ static string com_save_to(exec_context &ec, string cmdline, vector &args } } else if (args[0] == "write-json-to") { - yajl_gen handle = NULL; + yajlpp_gen gen; - if ((handle = yajl_gen_alloc(NULL)) == NULL) { - if (outfile != stdout) { - closer(outfile); - } - return "error: unable to allocate memory"; - } - else { - yajl_gen_config(handle, yajl_gen_beautify, 1); - yajl_gen_config(handle, - yajl_gen_print_callback, yajl_writer, outfile); + yajl_gen_config(gen, yajl_gen_beautify, 1); + yajl_gen_config(gen, + yajl_gen_print_callback, yajl_writer, outfile); - { - yajlpp_array root_array(handle); - - for (size_t row = 0; row < dls.dls_rows.size(); row++) { - if (ec.ec_dry_run && row > 10) { - break; - } + { + yajlpp_array root_array(gen); - json_write_row(handle, row); - line_count += 1; + for (size_t row = 0; row < dls.dls_rows.size(); row++) { + if (ec.ec_dry_run && row > 10) { + break; } + + json_write_row(gen, row); + line_count += 1; } } } @@ -3222,26 +3214,18 @@ static string com_config(exec_context &ec, string cmdline, vector &args) } if (jph != nullptr) { - auto_mem handle(yajl_gen_free); - - handle = yajl_gen_alloc(nullptr); - - yajlpp_gen_context ygc(handle, lnav_config_handlers); - yajl_gen_config(handle, yajl_gen_beautify, 1); + yajlpp_gen gen; + yajlpp_gen_context ygc(gen, lnav_config_handlers); + yajl_gen_config(gen, yajl_gen_beautify, 1); ygc.with_context(ypc); if (ypc.ypc_current_handler == nullptr) { ygc.gen(); } else { - jph->gen(ygc, handle); + jph->gen(ygc, gen); } - const unsigned char *buffer; - size_t len; - - yajl_gen_get_buf(handle, &buffer, &len); - - string old_value((char *) buffer, len); + string old_value = gen.to_string_fragment().to_string(); if (args.size() == 2 || ypc.ypc_current_handler == nullptr) { vector errors; @@ -3760,7 +3744,7 @@ readline_context::command_t STD_COMMANDS[] = { help_text(":adjust-log-time") .with_summary("Change the timestamps of the top file to be relative to the given date") .with_parameter(help_text("timestamp", "The new timestamp for the top line in the view") - .with_format(HPF_DATETIME)) + .with_format(help_parameter_format_t::HPF_DATETIME)) .with_example({"2017-01-02T05:33:00", ""}) .with_example({"-1h"}) }, @@ -3772,7 +3756,7 @@ readline_context::command_t STD_COMMANDS[] = { help_text(":unix-time") .with_summary("Convert epoch time to a human-readable form") .with_parameter(help_text("seconds", "The epoch timestamp to convert") - .with_format(HPF_INTEGER)) + .with_format(help_parameter_format_t::HPF_INTEGER)) .with_example({"1490191111", "Wed Mar 22 06:58:31 2017 -0700 PDT -- 1490191111"}) }, { diff --git a/src/lnav_config.cc b/src/lnav_config.cc index c12a2a68..e890c39b 100644 --- a/src/lnav_config.cc +++ b/src/lnav_config.cc @@ -42,17 +42,18 @@ #include #include +#include #include "pcrecpp.h" #include "auto_fd.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" #include "auto_mem.hh" #include "auto_pid.hh" #include "lnav_config.hh" -#include "yajlpp.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp.hh" +#include "yajlpp/yajlpp_def.hh" #include "shlex.hh" #include "styling.hh" @@ -830,49 +831,35 @@ void reset_config(const std::string &path) string save_config() { - auto_mem handle(yajl_gen_free); - - if ((handle = yajl_gen_alloc(NULL)) == NULL) { - return "error: Unable to create yajl_gen_object"; - } - else { - char filename[128]; - - snprintf(filename, sizeof(filename), "config.json.%d.tmp", getpid()); - - string user_config_tmp = dotlnav_path(filename); - string user_config = dotlnav_path("config.json"); - - yajl_gen_config(handle, yajl_gen_beautify, true); - - yajlpp_gen_context ygc(handle, lnav_config_handlers); - vector errors; + yajlpp_gen gen; + string filename = fmt::format("config.json.{}.tmp", getpid()); + string user_config_tmp = dotlnav_path(filename.c_str()); + string user_config = dotlnav_path("config.json"); - ygc.with_default_obj(lnav_default_config) - .with_obj(lnav_config); - ygc.gen(); + yajl_gen_config(gen, yajl_gen_beautify, true); + yajlpp_gen_context ygc(gen, lnav_config_handlers); + vector errors; - const unsigned char *buffer; - size_t len; + ygc.with_default_obj(lnav_default_config) + .with_obj(lnav_config); + ygc.gen(); - yajl_gen_get_buf(handle, &buffer, &len); + { + auto_fd fd; - { - auto_fd fd; + if ((fd = open(user_config_tmp.c_str(), + O_WRONLY | O_CREAT | O_TRUNC, 0600)) == -1) { + return "error: unable to save configuration -- " + + string(strerror(errno)); + } else { + string_fragment bits = gen.to_string_fragment(); - if ((fd = open(user_config_tmp.c_str(), - O_WRONLY | O_CREAT | O_TRUNC, 0600)) == -1) { - return "error: unable to save configuration -- " + - string(strerror(errno)); - } - else { - log_perror(write(fd, buffer, len)); - } + log_perror(write(fd, bits.data(), bits.length())); } - - rename(user_config_tmp.c_str(), user_config.c_str()); } + rename(user_config_tmp.c_str(), user_config.c_str()); + return "info: configuration saved"; } diff --git a/src/lnav_config.hh b/src/lnav_config.hh index 8f59169b..2dff6669 100644 --- a/src/lnav_config.hh +++ b/src/lnav_config.hh @@ -40,7 +40,7 @@ #include #include -#include "yajlpp.hh" +#include "yajlpp/yajlpp.hh" #include "log_level.hh" #include "styling.hh" diff --git a/src/lnav_util.cc b/src/lnav_util.cc index 61825b06..8c7f0c7a 100644 --- a/src/lnav_util.cc +++ b/src/lnav_util.cc @@ -42,7 +42,7 @@ #include "auto_fd.hh" #include "lnav_util.hh" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "lnav_config.hh" using namespace std; diff --git a/src/log_accel.hh b/src/log_accel.hh index 0b2d8df5..00f53be4 100644 --- a/src/log_accel.hh +++ b/src/log_accel.hh @@ -37,7 +37,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" /** * Helper class for figuring out changes in the log message rate. diff --git a/src/log_data_helper.hh b/src/log_data_helper.hh index f80e2a30..46794af6 100644 --- a/src/log_data_helper.hh +++ b/src/log_data_helper.hh @@ -41,8 +41,8 @@ #include "logfile_sub_source.hh" #include "data_parser.hh" #include "column_namer.hh" -#include "json_ptr.hh" -#include "lnav_log.hh" +#include "yajlpp/json_ptr.hh" +#include "base/lnav_log.hh" #include "sql_util.hh" class log_data_helper diff --git a/src/log_format.cc b/src/log_format.cc index 62516ebb..93e683a4 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -34,8 +34,8 @@ #include #include -#include "yajlpp.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp.hh" +#include "yajlpp/yajlpp_def.hh" #include "sql_util.hh" #include "log_format.hh" #include "log_vtab_impl.hh" diff --git a/src/log_format.hh b/src/log_format.hh index 6e106471..92ae587b 100644 --- a/src/log_format.hh +++ b/src/log_format.hh @@ -48,9 +48,9 @@ #include #include "optional.hpp" -#include "pcrepp.hh" -#include "yajlpp.hh" -#include "lnav_log.hh" +#include "pcrepp/pcrepp.hh" +#include "yajlpp/yajlpp.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" #include "byte_array.hh" #include "view_curses.hh" diff --git a/src/log_format_impls.cc b/src/log_format_impls.cc index 9db7e5ea..a8ae0b9e 100644 --- a/src/log_format_impls.cc +++ b/src/log_format_impls.cc @@ -33,7 +33,7 @@ #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "sql_util.hh" #include "log_format.hh" #include "log_vtab_impl.hh" diff --git a/src/log_format_loader.cc b/src/log_format_loader.cc index de4e6e75..7880c678 100644 --- a/src/log_format_loader.cc +++ b/src/log_format_loader.cc @@ -41,8 +41,8 @@ #include #include -#include "yajlpp.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp.hh" +#include "yajlpp/yajlpp_def.hh" #include "lnav_config.hh" #include "log_format.hh" #include "auto_fd.hh" diff --git a/src/log_level.cc b/src/log_level.cc index 1f391db5..61a5831b 100644 --- a/src/log_level.cc +++ b/src/log_level.cc @@ -29,7 +29,7 @@ #include "config.h" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "log_level.hh" const char *level_names[LEVEL__MAX + 1] = { diff --git a/src/log_vtab_impl.cc b/src/log_vtab_impl.cc index a9d4f220..e9dff56c 100644 --- a/src/log_vtab_impl.cc +++ b/src/log_vtab_impl.cc @@ -29,10 +29,10 @@ #include "config.h" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sql_util.hh" #include "log_vtab_impl.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp_def.hh" #include "vtab_module.hh" #include "logfile_sub_source.hh" diff --git a/src/logfile.hh b/src/logfile.hh index 61fa284a..a98a9898 100644 --- a/src/logfile.hh +++ b/src/logfile.hh @@ -44,7 +44,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "byte_array.hh" #include "line_buffer.hh" #include "log_format.hh" diff --git a/src/logfile_sub_source.hh b/src/logfile_sub_source.hh index b0bdee64..dca558b5 100644 --- a/src/logfile_sub_source.hh +++ b/src/logfile_sub_source.hh @@ -41,7 +41,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "log_accel.hh" #include "strong_int.hh" #include "logfile.hh" diff --git a/src/papertrail_proc.cc b/src/papertrail_proc.cc index d2d40aef..39e6eb0a 100644 --- a/src/papertrail_proc.cc +++ b/src/papertrail_proc.cc @@ -35,7 +35,7 @@ #include #include "papertrail_proc.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp_def.hh" #include "yajl/api/yajl_parse.h" const char *papertrail_proc::PT_SEARCH_URL = diff --git a/src/papertrail_proc.hh b/src/papertrail_proc.hh index 63a96398..dc989169 100644 --- a/src/papertrail_proc.hh +++ b/src/papertrail_proc.hh @@ -45,7 +45,7 @@ #include "auto_fd.hh" #include "auto_mem.hh" -#include "yajlpp.hh" +#include "yajlpp/yajlpp.hh" #include "curl_looper.hh" #include "line_buffer.hh" diff --git a/src/pcrepp/Makefile.am b/src/pcrepp/Makefile.am new file mode 100644 index 00000000..52deed2b --- /dev/null +++ b/src/pcrepp/Makefile.am @@ -0,0 +1,12 @@ + +AM_CPPFLAGS = \ + -Wall \ + -I$(top_srcdir)/src + +noinst_LIBRARIES = libpcrepp.a + +noinst_HEADERS = \ + pcrepp.hh + +libpcrepp_a_SOURCES = \ + pcrepp.cc diff --git a/src/pcrepp.cc b/src/pcrepp/pcrepp.cc similarity index 100% rename from src/pcrepp.cc rename to src/pcrepp/pcrepp.cc diff --git a/src/pcrepp.hh b/src/pcrepp/pcrepp.hh similarity index 99% rename from src/pcrepp.hh rename to src/pcrepp/pcrepp.hh index d2857aaf..0b06c390 100644 --- a/src/pcrepp.hh +++ b/src/pcrepp/pcrepp.hh @@ -55,7 +55,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "auto_mem.hh" #include "intern_string.hh" diff --git a/src/piper_proc.cc b/src/piper_proc.cc index b9e4be9d..caa666a4 100644 --- a/src/piper_proc.cc +++ b/src/piper_proc.cc @@ -45,7 +45,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "piper_proc.hh" #include "line_buffer.hh" diff --git a/src/ptimec.hh b/src/ptimec.hh index 5c05f5bd..9004dbc8 100644 --- a/src/ptimec.hh +++ b/src/ptimec.hh @@ -448,7 +448,7 @@ inline void ftime_i(char *dst, off_t &off_inout, ssize_t len, const struct exttm off_inout = strlen(dst); } -#include "lnav_log.hh" +#include "base/lnav_log.hh" inline bool ptime_6(struct exttm *dst, const char *str, off_t &off_inout, ssize_t len) { diff --git a/src/readline_callbacks.cc b/src/readline_callbacks.cc index c3b178d2..e5aa8eca 100644 --- a/src/readline_callbacks.cc +++ b/src/readline_callbacks.cc @@ -221,7 +221,7 @@ void rl_change(void *dummy, readline_curses *rc) al.clear(); etc.get_dimensions(height, width); - format_example_text_for_term(ht, width, al); + format_example_text_for_term(ht, eval_example, width, al); lnav_data.ld_example_source.replace_with(al); } @@ -418,7 +418,7 @@ static void rl_search_internal(void *dummy, readline_curses *rc, bool complete = format_help_text_for_term(ht, min(70UL, doc_width), doc_al, help_count > 1); if (help_count == 1) { - format_example_text_for_term(ht, ex_width, ex_al); + format_example_text_for_term(ht, eval_example, ex_width, ex_al); } } diff --git a/src/readline_curses.cc b/src/readline_curses.cc index 17d85947..a7794f0d 100644 --- a/src/readline_curses.cc +++ b/src/readline_curses.cc @@ -55,10 +55,10 @@ #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "shlex.hh" #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" #include "ansi_scrubber.hh" #include "readline_curses.hh" diff --git a/src/readline_highlighters.cc b/src/readline_highlighters.cc index f27162ae..7c2d3ac8 100644 --- a/src/readline_highlighters.cc +++ b/src/readline_highlighters.cc @@ -31,7 +31,7 @@ #include "config.h" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "sql_util.hh" #include "shlex.hh" #include "lnav_util.hh" diff --git a/src/readline_possibilities.cc b/src/readline_possibilities.cc index 9f613c1f..fa648585 100644 --- a/src/readline_possibilities.cc +++ b/src/readline_possibilities.cc @@ -37,7 +37,7 @@ #include "sql_util.hh" #include "data_parser.hh" #include "sysclip.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp_def.hh" #include "lnav_config.hh" #include "sqlite-extension-func.hh" diff --git a/src/regexp_vtab.cc b/src/regexp_vtab.cc index 8f65d753..b6729a11 100644 --- a/src/regexp_vtab.cc +++ b/src/regexp_vtab.cc @@ -35,7 +35,7 @@ #include "logfile.hh" #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sql_util.hh" #include "file_vtab.hh" #include "vtab_module.hh" diff --git a/src/relative_time.cc b/src/relative_time.cc index eb4cc781..d98e9b60 100644 --- a/src/relative_time.cc +++ b/src/relative_time.cc @@ -33,7 +33,7 @@ #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "lnav_util.hh" #include "relative_time.hh" diff --git a/src/session_data.cc b/src/session_data.cc index aa72287f..c35e61a7 100644 --- a/src/session_data.cc +++ b/src/session_data.cc @@ -43,8 +43,8 @@ #include #include -#include "yajlpp.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp.hh" +#include "yajlpp/yajlpp_def.hh" #include "lnav.hh" #include "logfile.hh" #include "sql_util.hh" diff --git a/src/shared_buffer.hh b/src/shared_buffer.hh index d059ea21..973552d9 100644 --- a/src/shared_buffer.hh +++ b/src/shared_buffer.hh @@ -38,7 +38,7 @@ #include #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" class shared_buffer; diff --git a/src/shlex.hh b/src/shlex.hh index 01acd235..07592928 100644 --- a/src/shlex.hh +++ b/src/shlex.hh @@ -36,7 +36,7 @@ #include #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" enum shlex_token_t { ST_ERROR, diff --git a/src/simdutf8check.h b/src/simdutf8check.h index bacab160..4a3a3645 100644 --- a/src/simdutf8check.h +++ b/src/simdutf8check.h @@ -9,7 +9,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #ifdef __cplusplus extern "C" { diff --git a/src/sql_util.cc b/src/sql_util.cc index 59936dcf..d2105841 100644 --- a/src/sql_util.cc +++ b/src/sql_util.cc @@ -40,9 +40,9 @@ #include "auto_mem.hh" #include "sql_util.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" using namespace std; diff --git a/src/sqlite-extension-func.cc b/src/sqlite-extension-func.cc index d8702ce1..88f48a91 100644 --- a/src/sqlite-extension-func.cc +++ b/src/sqlite-extension-func.cc @@ -35,7 +35,7 @@ #include #include "lnav_util.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sqlite-extension-func.hh" @@ -83,7 +83,7 @@ int register_sqlite_funcs(sqlite3 *db, sqlite_registration_func_t *reg_funcs) nullptr, nullptr); - if (fd.fd_help.ht_context != HC_NONE) { + if (fd.fd_help.ht_context != help_context_t::HC_NONE) { help_text &ht = fd.fd_help; sqlite_function_help.insert(make_pair(ht.ht_name, &ht)); @@ -104,7 +104,7 @@ int register_sqlite_funcs(sqlite3 *db, sqlite_registration_func_t *reg_funcs) agg_funcs[i].xStep, agg_funcs[i].xFinalize); - if (fda.fda_help.ht_context != HC_NONE) { + if (fda.fda_help.ht_context != help_context_t::HC_NONE) { help_text &ht = fda.fda_help; sqlite_function_help.insert(make_pair(ht.ht_name, &ht)); diff --git a/src/string-extension-functions.cc b/src/string-extension-functions.cc index f95b5873..58ff37ac 100644 --- a/src/string-extension-functions.cc +++ b/src/string-extension-functions.cc @@ -17,9 +17,9 @@ #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" -#include "yajlpp.hh" +#include "yajlpp/yajlpp.hh" #include "column_namer.hh" #include "yajl/api/yajl_gen.h" #include "sqlite-extension-func.hh" @@ -89,10 +89,8 @@ regexp_match(const char *re, const char *str) return static_cast(nullptr); } - auto_mem gen(yajl_gen_free); - - gen = yajl_gen_alloc(nullptr); - yajl_gen_config(gen.in(), yajl_gen_beautify, false); + yajlpp_gen gen; + yajl_gen_config(gen, yajl_gen_beautify, false); if (extractor.get_capture_count() == 1) { pcre_context::capture_t *cap = pc[0]; @@ -178,10 +176,8 @@ json_string extract(const char *str) dp.parse(); // dp.print(stderr, dp.dp_pairs); - auto_mem gen(yajl_gen_free); - - gen = yajl_gen_alloc(NULL); - yajl_gen_config(gen.in(), yajl_gen_beautify, false); + yajlpp_gen gen; + yajl_gen_config(gen, yajl_gen_beautify, false); elements_to_json(gen, dp, &dp.dp_pairs); diff --git a/src/sysclip.cc b/src/sysclip.cc index e4f252c3..5f97d576 100644 --- a/src/sysclip.cc +++ b/src/sysclip.cc @@ -33,7 +33,7 @@ #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sysclip.hh" struct clip_command { diff --git a/src/text_format.cc b/src/text_format.cc index 1c9094fc..a6804a44 100644 --- a/src/text_format.cc +++ b/src/text_format.cc @@ -31,7 +31,7 @@ #include "config.h" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "text_format.hh" diff --git a/src/textview_curses.cc b/src/textview_curses.cc index baa27d6f..5c9c5a2c 100644 --- a/src/textview_curses.cc +++ b/src/textview_curses.cc @@ -34,7 +34,7 @@ #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "lnav_util.hh" #include "data_parser.hh" #include "ansi_scrubber.hh" diff --git a/src/textview_curses.hh b/src/textview_curses.hh index 5e3e4f3d..b49ea360 100644 --- a/src/textview_curses.hh +++ b/src/textview_curses.hh @@ -39,7 +39,7 @@ #include "grep_proc.hh" #include "bookmarks.hh" #include "listview_curses.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "text_format.hh" #include "logfile.hh" #include "highlighter.hh" diff --git a/src/timer.cc b/src/timer.cc index 8c0fa902..eea7f8f3 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -30,7 +30,7 @@ #include "config.h" #include "timer.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" static const struct itimerval DISABLE_TV = { { 0, 0 }, diff --git a/src/view_curses.cc b/src/view_curses.cc index a167c35d..fbe2e950 100644 --- a/src/view_curses.cc +++ b/src/view_curses.cc @@ -35,12 +35,12 @@ #include #include "auto_mem.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "view_curses.hh" #include "ansi_scrubber.hh" #include "lnav_config.hh" -#include "yajlpp.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp.hh" +#include "yajlpp/yajlpp_def.hh" #include "xterm-palette.hh" #include "attr_line.hh" #include "shlex.hh" diff --git a/src/view_curses.hh b/src/view_curses.hh index 4ed096af..7933dccd 100644 --- a/src/view_curses.hh +++ b/src/view_curses.hh @@ -60,7 +60,7 @@ #include #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "attr_line.hh" #include "optional.hpp" #include "lnav_util.hh" diff --git a/src/view_helpers.cc b/src/view_helpers.cc index 825e86bd..f2fe81ce 100644 --- a/src/view_helpers.cc +++ b/src/view_helpers.cc @@ -175,11 +175,11 @@ static void build_all_help_text() for (const auto &iter : sqlite_function_help) { switch (iter.second->ht_context) { - case HC_SQL_FUNCTION: - case HC_SQL_TABLE_VALUED_FUNCTION: + case help_context_t::HC_SQL_FUNCTION: + case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: sql_funcs[iter.second->ht_name] = iter.second; break; - case HC_SQL_KEYWORD: + case help_context_t::HC_SQL_KEYWORD: sql_keywords[iter.second->ht_name] = iter.second; break; default: @@ -192,7 +192,7 @@ static void build_all_help_text() format_help_text_for_term(*iter.second, 79, all_help_text); if (!iter.second->ht_example.empty()) { all_help_text.append(1, '\n'); - format_example_text_for_term(*iter.second, 90, all_help_text); + format_example_text_for_term(*iter.second, eval_example, 90, all_help_text); } } @@ -201,7 +201,7 @@ static void build_all_help_text() format_help_text_for_term(*iter.second, 79, all_help_text); if (!iter.second->ht_example.empty()) { all_help_text.append(1, '\n'); - format_example_text_for_term(*iter.second, 79, all_help_text); + format_example_text_for_term(*iter.second, eval_example, 79, all_help_text); } } @@ -325,6 +325,8 @@ void layout_views() lnav_data.ld_rl_view->set_width(width); } +static unordered_map EXAMPLE_RESULTS; + void execute_examples() { exec_context &ec = lnav_data.ld_exec_context; @@ -337,22 +339,23 @@ void execute_examples() for (auto &ex : ht.ht_example) { string alt_msg; + attr_line_t result; switch (ht.ht_context) { - case HC_SQL_FUNCTION: - case HC_SQL_TABLE_VALUED_FUNCTION: { + case help_context_t::HC_SQL_FUNCTION: + case help_context_t::HC_SQL_TABLE_VALUED_FUNCTION: { execute_sql(ec, ex.he_cmd, alt_msg); if (dls.dls_rows.size() == 1 && dls.dls_rows[0].size() == 1) { - ex.he_result.append(dls.dls_rows[0][0]); + result.append(dls.dls_rows[0][0]); } else { attr_line_t al; dos.list_value_for_overlay(db_tc, 0, 1, vis_line_t(0), al); - ex.he_result.append(al); + result.append(al); for (int lpc = 0; lpc < (int)dls.text_line_count(); lpc++) { al.clear(); @@ -361,14 +364,16 @@ void execute_examples() false); dls.text_attrs_for_line(db_tc, lpc, al.get_attrs()); - ex.he_result.append("\n") + result.append("\n") .append(al); } } + EXAMPLE_RESULTS[ex.he_cmd] = result; + log_debug("example: %s", ex.he_cmd); log_debug("example result: %s", - ex.he_result.get_string().c_str()); + result.get_string().c_str()); break; } default: @@ -381,6 +386,17 @@ void execute_examples() dls.clear(); } +attr_line_t eval_example(const help_text &ht, const help_example &ex) +{ + auto iter = EXAMPLE_RESULTS.find(ex.he_cmd); + + if (iter != EXAMPLE_RESULTS.end()) { + return iter->second; + } + + return ""; +} + bool toggle_view(textview_curses *toggle_tc) { textview_curses *tc = lnav_data.ld_view_stack.top().value_or(nullptr); diff --git a/src/views_vtab.cc b/src/views_vtab.cc index 809aea82..dd3a1a00 100644 --- a/src/views_vtab.cc +++ b/src/views_vtab.cc @@ -40,7 +40,7 @@ #include #include "lnav.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "sql_util.hh" #include "views_vtab.hh" #include "view_curses.hh" diff --git a/src/vt52_curses.cc b/src/vt52_curses.cc index 69ac2f2a..f1e7d5c0 100644 --- a/src/vt52_curses.cc +++ b/src/vt52_curses.cc @@ -36,7 +36,7 @@ #include -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "vt52_curses.hh" #if defined HAVE_NCURSESW_CURSES_H diff --git a/src/vtab_module.hh b/src/vtab_module.hh index b9c877c6..07517f5e 100644 --- a/src/vtab_module.hh +++ b/src/vtab_module.hh @@ -37,7 +37,7 @@ #include #include "optional.hpp" -#include "lnav_log.hh" +#include "base/lnav_log.hh" #include "lnav_util.hh" #include "auto_mem.hh" #include "yajl/api/yajl_gen.h" diff --git a/src/xterm_mouse.cc b/src/xterm_mouse.cc index 1ec4db89..9f29cbc1 100644 --- a/src/xterm_mouse.cc +++ b/src/xterm_mouse.cc @@ -34,3 +34,66 @@ const char *xterm_mouse::XT_TERMCAP = "\033[?1000%?%p1%{1}%=%th%el%;"; const char *xterm_mouse::XT_TERMCAP_TRACKING = "\033[?1002%?%p1%{1}%=%th%el%;"; const char *xterm_mouse::XT_TERMCAP_SGR = "\033[?1006%?%p1%{1}%=%th%el%;"; + +void xterm_mouse::handle_mouse() +{ + bool release = false; + int ch; + size_t index = 0; + int bstate, x, y; + char buffer[64]; + bool done = false; + + while (!done) { + if (index >= sizeof(buffer) - 1) { + break; + } + ch = getch(); + switch (ch) { + case 'm': + release = true; + done = true; + break; + case 'M': + done = true; + break; + default: + buffer[index++] = (char)ch; + break; + } + } + buffer[index] = '\0'; + + if (sscanf(buffer, "<%d;%d;%d", &bstate, &x, &y) == 3) { + if (this->xm_behavior) { + this->xm_behavior->mouse_event(bstate, release, x, y); + } + } + else { + log_error("bad mouse escape sequence: %s", buffer); + } +} + +void xterm_mouse::set_enabled(bool enabled) +{ + if (is_available()) { + putp(tparm((char *)XT_TERMCAP, enabled ? 1 : 0)); + putp(tparm((char *)XT_TERMCAP_TRACKING, enabled ? 1 : 0)); + putp(tparm((char *)XT_TERMCAP_SGR, enabled ? 1 : 0)); + fflush(stdout); + this->xm_enabled = enabled; + } else { + log_warning("mouse support is not available"); + } +} + +bool xterm_mouse::is_available() +{ + const char *termname = getenv("TERM"); + bool retval = false; + + if (termname and strstr(termname, "xterm") != NULL) { + retval = isatty(STDOUT_FILENO); + } + return retval; +} diff --git a/src/xterm_mouse.hh b/src/xterm_mouse.hh index bc4de72f..2be5186e 100644 --- a/src/xterm_mouse.hh +++ b/src/xterm_mouse.hh @@ -52,7 +52,7 @@ # error "SysV or X/Open-compatible Curses header file required" #endif -#include "lnav_log.hh" +#include "base/lnav_log.hh" /** * Base class for delegates of the xterm_mouse class. @@ -102,39 +102,20 @@ public: /** * @return True if the user's terminal supports xterm-mouse events. */ - static bool is_available() - { - const char *termname = getenv("TERM"); - bool retval = false; - - if (termname and strstr(termname, "xterm") != NULL) { - retval = isatty(STDOUT_FILENO); - } - return retval; - }; - - xterm_mouse() : xm_enabled(false), xm_behavior(NULL) {}; + static bool is_available(); ~xterm_mouse() { - if (this->is_enabled()) + if (this->is_enabled()) { set_enabled(false); + } }; /** * @param enabled True if xterm mouse support should be enabled in the * terminal. */ - void set_enabled(bool enabled) - { - if (is_available()) { - putp(tparm((char *)XT_TERMCAP, enabled ? 1 : 0)); - putp(tparm((char *)XT_TERMCAP_TRACKING, enabled ? 1 : 0)); - putp(tparm((char *)XT_TERMCAP_SGR, enabled ? 1 : 0)); - fflush(stdout); - this->xm_enabled = enabled; - } - }; + void set_enabled(bool enabled); /** * @return True if xterm mouse support is enabled, false otherwise. @@ -158,47 +139,10 @@ public: * Handle a KEY_MOUSE character from ncurses. * @param ch unused */ - void handle_mouse() - { - bool release = false; - int ch; - size_t index = 0; - int bstate, x, y; - char buffer[64]; - bool done = false; - - while (!done) { - if (index >= sizeof(buffer) - 1) { - break; - } - ch = getch(); - switch (ch) { - case 'm': - release = true; - done = true; - break; - case 'M': - done = true; - break; - default: - buffer[index++] = (char)ch; - break; - } - } - buffer[index] = '\0'; - - if (sscanf(buffer, "<%d;%d;%d", &bstate, &x, &y) == 3) { - if (this->xm_behavior) { - this->xm_behavior->mouse_event(bstate, release, x, y); - } - } - else { - log_error("bad mouse escape sequence: %s", buffer); - } - }; + void handle_mouse(); private: - bool xm_enabled; - mouse_behavior *xm_behavior; + bool xm_enabled{false}; + mouse_behavior *xm_behavior{nullptr}; }; #endif diff --git a/src/yajl/Makefile.am b/src/yajl/Makefile.am new file mode 100644 index 00000000..629185e6 --- /dev/null +++ b/src/yajl/Makefile.am @@ -0,0 +1,37 @@ + +AM_CPPFLAGS = -I$(top_srcdir)/src + +noinst_LIBRARIES = libyajl.a + +noinst_HEADERS = \ + api/yajl_common.h \ + api/yajl_gen.h \ + api/yajl_parse.h \ + api/yajl_tree.h \ + yajl_alloc.h \ + yajl_buf.h \ + yajl_bytestack.h \ + yajl_common.h \ + yajl_encode.h \ + yajl_lex.h \ + yajl_parser.h \ + yajl_version.h + +if USE_INCLUDED_YAJL +libyajl_a_SOURCES = \ + yajl.c \ + yajl_alloc.c \ + yajl_alloc.h \ + yajl_buf.c \ + yajl_buf.h \ + yajl_bytestack.h \ + yajl_encode.c \ + yajl_encode.h \ + yajl_gen.c \ + yajl_lex.c \ + yajl_lex.h \ + yajl_parser.c \ + yajl_parser.h \ + yajl_tree.c \ + yajl_version.c +endif diff --git a/src/yajlpp/Makefile.am b/src/yajlpp/Makefile.am new file mode 100644 index 00000000..9c05b97e --- /dev/null +++ b/src/yajlpp/Makefile.am @@ -0,0 +1,52 @@ + +TESTS_ENVIRONMENT = $(SHELL) $(top_builddir)/TESTS_ENVIRONMENT +LOG_COMPILER = $(SHELL) $(top_builddir)/TESTS_ENVIRONMENT + +AM_CPPFLAGS = \ + -Wall \ + -I$(top_srcdir)/src/ \ + -I$(top_srcdir)/src/fmtlib + +noinst_LIBRARIES = libyajlpp.a + +noinst_HEADERS = \ + json_op.hh \ + json_ptr.hh \ + yajlpp.hh \ + yajlpp_def.hh + +libyajlpp_a_SOURCES = \ + json_op.cc \ + json_ptr.cc \ + yajlpp.cc + +check_PROGRAMS = \ + drive_json_op \ + drive_json_ptr_walk \ + test_json_ptr \ + test_yajlpp + +drive_json_op_SOURCES = drive_json_op.cc + +drive_json_ptr_walk_SOURCES = drive_json_ptr_walk.cc + +test_json_ptr_SOURCES = test_json_ptr.cc + +test_yajlpp_SOURCES = test_yajlpp.cc + +LDADD = \ + $(top_builddir)/src/base/libbase.a \ + $(top_builddir)/src/fmtlib/libcppfmt.a \ + $(top_builddir)/src/pcrepp/libpcrepp.a \ + $(top_builddir)/src/yajl/libyajl.a \ + libyajlpp.a + +dist_noinst_SCRIPTS = \ + test_json_op.sh \ + test_json_ptr_walk.sh + +TESTS = \ + test_json_op.sh \ + test_json_ptr \ + test_json_ptr_walk.sh \ + test_yajlpp diff --git a/test/drive_json_op.cc b/src/yajlpp/drive_json_op.cc similarity index 99% rename from test/drive_json_op.cc rename to src/yajlpp/drive_json_op.cc index 7fe49eb0..e924610a 100644 --- a/test/drive_json_op.cc +++ b/src/yajlpp/drive_json_op.cc @@ -35,8 +35,8 @@ #include "yajl/api/yajl_gen.h" -#include "json_op.hh" -#include "lnav_log.hh" +#include "yajlpp/json_op.hh" +#include "base/lnav_log.hh" static void printer(void *ctx, const char *numberVal, size_t numberLen) { diff --git a/test/drive_json_ptr_walk.cc b/src/yajlpp/drive_json_ptr_walk.cc similarity index 66% rename from test/drive_json_ptr_walk.cc rename to src/yajlpp/drive_json_ptr_walk.cc index eae962e3..fb142031 100644 --- a/test/drive_json_ptr_walk.cc +++ b/src/yajlpp/drive_json_ptr_walk.cc @@ -31,40 +31,43 @@ #include "config.h" +#include #include +#include "yajlpp.hh" +#include "json_op.hh" #include "json_ptr.hh" -#include "lnav_log.hh" +#include "yajl/api/yajl_gen.h" +#include "base/lnav_log.hh" + +using namespace std; int main(int argc, char *argv[]) { int retval = EXIT_SUCCESS; - - char buffer[1024]; yajl_status status; json_ptr_walk jpw; - ssize_t rc; log_argv(argc, argv); - while ((rc = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) { - status = jpw.parse(buffer, rc); - if (status == yajl_status_error) { - fprintf(stderr, "error:cannot parse JSON input -- %s\n", + std::string json_input(std::istreambuf_iterator(cin), {}); + + status = jpw.parse(json_input.c_str(), json_input.size()); + if (status == yajl_status_error) { + fprintf(stderr, "error:cannot parse JSON input -- %s\n", jpw.jpw_error_msg.c_str()); - retval = EXIT_FAILURE; - break; - } - else if (status == yajl_status_client_canceled) { - fprintf(stderr, "client cancel\n"); - break; - } + return EXIT_FAILURE; + } + + if (status == yajl_status_client_canceled) { + fprintf(stderr, "client cancel\n"); } + status = jpw.complete_parse(); if (status == yajl_status_error) { fprintf(stderr, "error:cannot parse JSON input -- %s\n", jpw.jpw_error_msg.c_str()); - retval = EXIT_FAILURE; + return EXIT_FAILURE; } else if (status == yajl_status_client_canceled) { fprintf(stderr, "client cancel\n"); @@ -74,6 +77,24 @@ int main(int argc, char *argv[]) iter != jpw.jpw_values.end(); ++iter) { printf("%s = %s\n", iter->wt_ptr.c_str(), iter->wt_value.c_str()); + + { + auto_mem parse_handle(yajl_free); + json_ptr jp(iter->wt_ptr.c_str()); + json_op jo(jp); + yajlpp_gen gen; + + jo.jo_ptr_callbacks = json_op::gen_callbacks; + jo.jo_ptr_data = gen.get_handle(); + parse_handle.reset(yajl_alloc(&json_op::ptr_callbacks, nullptr, &jo)); + + yajl_parse(parse_handle.in(), + (const unsigned char *) json_input.c_str(), + json_input.size()); + yajl_complete_parse(parse_handle.in()); + + assert(iter->wt_value == gen.to_string_fragment().to_string()); + } } return retval; diff --git a/src/json_op.cc b/src/yajlpp/json_op.cc similarity index 91% rename from src/json_op.cc rename to src/yajlpp/json_op.cc index d893b6d4..55117499 100644 --- a/src/json_op.cc +++ b/src/yajlpp/json_op.cc @@ -34,7 +34,7 @@ #include "yajl/api/yajl_gen.h" #include "json_op.hh" -#include "lnav_log.hh" +#include "base/lnav_log.hh" static int gen_handle_start_map(void *ctx) { @@ -129,8 +129,8 @@ static int gen_handle_end_array(void *ctx) const yajl_callbacks json_op::gen_callbacks = { gen_handle_null, gen_handle_boolean, - NULL, - NULL, + nullptr, + nullptr, gen_handle_number, gen_handle_string, gen_handle_start_map, @@ -143,8 +143,8 @@ const yajl_callbacks json_op::gen_callbacks = { const yajl_callbacks json_op::ptr_callbacks = { handle_null, handle_boolean, - NULL, - NULL, + nullptr, + nullptr, handle_number, handle_string, handle_start_map, @@ -160,7 +160,7 @@ int json_op::handle_null(void *ctx) int retval = 1; if (jo->check_index()) { - if (jo->jo_ptr_callbacks.yajl_null != NULL) { + if (jo->jo_ptr_callbacks.yajl_null != nullptr) { retval = jo->jo_ptr_callbacks.yajl_null(ctx); } } @@ -174,7 +174,7 @@ int json_op::handle_boolean(void *ctx, int boolVal) int retval = 1; if (jo->check_index()) { - if (jo->jo_ptr_callbacks.yajl_boolean != NULL) { + if (jo->jo_ptr_callbacks.yajl_boolean != nullptr) { retval = jo->jo_ptr_callbacks.yajl_boolean(ctx, boolVal); } } @@ -188,7 +188,7 @@ int json_op::handle_number(void *ctx, const char *numberVal, size_t numberLen) int retval = 1; if (jo->check_index()) { - if (jo->jo_ptr_callbacks.yajl_number != NULL) { + if (jo->jo_ptr_callbacks.yajl_number != nullptr) { retval = jo->jo_ptr_callbacks.yajl_number(ctx, numberVal, numberLen); } } @@ -202,7 +202,7 @@ int json_op::handle_string(void *ctx, const unsigned char *stringVal, size_t str int retval = 1; if (jo->check_index()) { - if (jo->jo_ptr_callbacks.yajl_string != NULL) { + if (jo->jo_ptr_callbacks.yajl_string != nullptr) { retval = jo->jo_ptr_callbacks.yajl_string(ctx, stringVal, stringLen); } } @@ -216,7 +216,7 @@ int json_op::handle_start_map(void *ctx) int retval = 1; if (jo->check_index(false)) { - if (jo->jo_ptr_callbacks.yajl_start_map != NULL) { + if (jo->jo_ptr_callbacks.yajl_start_map != nullptr) { retval = jo->jo_ptr_callbacks.yajl_start_map(ctx); } } @@ -234,7 +234,7 @@ int json_op::handle_map_key(void *ctx, const unsigned char * key, size_t len) int retval = 1; if (jo->check_index(false)) { - if (jo->jo_ptr_callbacks.yajl_map_key != NULL) { + if (jo->jo_ptr_callbacks.yajl_map_key != nullptr) { retval = jo->jo_ptr_callbacks.yajl_map_key(ctx, key, len); } } @@ -252,7 +252,7 @@ int json_op::handle_end_map(void *ctx) int retval = 1; if (jo->check_index()) { - if (jo->jo_ptr_callbacks.yajl_end_map != NULL) { + if (jo->jo_ptr_callbacks.yajl_end_map != nullptr) { retval = jo->jo_ptr_callbacks.yajl_end_map(ctx); } } @@ -268,7 +268,7 @@ int json_op::handle_start_array(void *ctx) int retval = 1; if (jo->check_index(false)) { - if (jo->jo_ptr_callbacks.yajl_start_array != NULL) { + if (jo->jo_ptr_callbacks.yajl_start_array != nullptr) { retval = jo->jo_ptr_callbacks.yajl_start_array(ctx); } } @@ -284,7 +284,7 @@ int json_op::handle_end_array(void *ctx) int retval = 1; if (jo->check_index()) { - if (jo->jo_ptr_callbacks.yajl_end_array != NULL) { + if (jo->jo_ptr_callbacks.yajl_end_array != nullptr) { retval = jo->jo_ptr_callbacks.yajl_end_array(ctx); } } diff --git a/src/json_op.hh b/src/yajlpp/json_op.hh similarity index 87% rename from src/json_op.hh rename to src/yajlpp/json_op.hh index 6213666d..519a9d92 100644 --- a/src/json_op.hh +++ b/src/yajlpp/json_op.hh @@ -36,7 +36,7 @@ #include -#include "json_ptr.hh" +#include "yajlpp/json_ptr.hh" #include "yajl/api/yajl_parse.h" class json_op { @@ -55,27 +55,23 @@ public: const static yajl_callbacks gen_callbacks; const static yajl_callbacks ptr_callbacks; - json_op(json_ptr &ptr) - : jo_depth(0), - jo_array_index(-1), - jo_ptr(ptr), - jo_ptr_data(NULL), - jo_ptr_error_code(0) { - memset(&this->jo_ptr_callbacks, 0, sizeof(this->jo_ptr_callbacks)); + explicit json_op(const json_ptr &ptr) + : jo_ptr(ptr), + jo_ptr_callbacks(gen_callbacks) { }; bool check_index(bool primitive = true) { return this->jo_ptr.at_index(this->jo_depth, this->jo_array_index, primitive); }; - int jo_depth; - int jo_array_index; + int jo_depth{0}; + int jo_array_index{-1}; json_ptr jo_ptr; yajl_callbacks jo_ptr_callbacks; - void *jo_ptr_data; + void *jo_ptr_data{nullptr}; std::string jo_ptr_error; - int jo_ptr_error_code; + int jo_ptr_error_code{0}; }; #endif diff --git a/src/json_ptr.cc b/src/yajlpp/json_ptr.cc similarity index 93% rename from src/json_ptr.cc rename to src/yajlpp/json_ptr.cc index caf35673..6de5d33a 100644 --- a/src/json_ptr.cc +++ b/src/yajlpp/json_ptr.cc @@ -33,7 +33,7 @@ #include "yajl/api/yajl_gen.h" -#include "json_ptr.hh" +#include "yajlpp/json_ptr.hh" using namespace std; @@ -114,14 +114,14 @@ static int handle_map_key(void *ctx, const unsigned char * key, size_t len) required_len = json_ptr::encode(partially_encoded_key, sizeof(partially_encoded_key), (const char *)key, len); if (required_len < sizeof(partially_encoded_key)) { - jpw->jpw_keys.push_back(string(partially_encoded_key, required_len)); + jpw->jpw_keys.emplace_back(&partially_encoded_key[0], required_len); } else { char fully_encoded_key[required_len]; json_ptr::encode(fully_encoded_key, sizeof(fully_encoded_key), (const char *)key, len); - jpw->jpw_keys.push_back(string(fully_encoded_key, required_len)); + jpw->jpw_keys.emplace_back(&fully_encoded_key[0], required_len); } return 1; @@ -163,8 +163,8 @@ static int handle_end_array(void *ctx) const yajl_callbacks json_ptr_walk::callbacks = { handle_null, handle_boolean, - NULL, - NULL, + nullptr, + nullptr, handle_number, handle_string, handle_start_map, @@ -362,7 +362,7 @@ bool json_ptr::expect_array(int32_t &depth, int32_t &index) else if (this->reached_end()) { retval = true; } - else if (this->jp_pos[0] == '/') { + else if (this->jp_pos[0] == '/' && index == this->jp_array_index) { int offset; this->jp_depth += 1; @@ -436,3 +436,25 @@ bool json_ptr::at_index(int32_t &depth, int32_t &index, bool primitive) return retval; } + +std::string json_ptr_walk::current_ptr() +{ + std::string retval; + + for (size_t lpc = 0; lpc < this->jpw_array_indexes.size(); lpc++) { + retval.append("/"); + if (this->jpw_array_indexes[lpc] == -1) { + retval.append(this->jpw_keys[lpc]); + } + else { + char num[64]; + + snprintf(num, sizeof(num), "%d", this->jpw_array_indexes[lpc]); + retval.append(num); + } + } + + this->jpw_max_ptr_len = std::max(this->jpw_max_ptr_len, retval.size()); + + return retval; +} diff --git a/src/json_ptr.hh b/src/yajlpp/json_ptr.hh similarity index 89% rename from src/json_ptr.hh rename to src/yajlpp/json_ptr.hh index f30f2435..736c8a3a 100644 --- a/src/json_ptr.hh +++ b/src/yajlpp/json_ptr.hh @@ -1,7 +1,5 @@ -#include - /** - * Copyright (c) 2014, Timothy Stack + * Copyright (c) 2014-2019, Timothy Stack * * All rights reserved. * @@ -95,26 +93,7 @@ public: } }; - std::string current_ptr() { - std::string retval; - - for (size_t lpc = 0; lpc < this->jpw_array_indexes.size(); lpc++) { - retval.append("/"); - if (this->jpw_array_indexes[lpc] == -1) { - retval.append(this->jpw_keys[lpc]); - } - else { - char num[64]; - - snprintf(num, sizeof(num), "%d", this->jpw_array_indexes[lpc]); - retval.append(num); - } - } - - this->jpw_max_ptr_len = std::max(this->jpw_max_ptr_len, retval.size()); - - return retval; - }; + std::string current_ptr(); struct walk_triple { walk_triple(std::string ptr, yajl_type type, std::string value) diff --git a/test/test_json_op.sh b/src/yajlpp/test_json_op.sh old mode 100644 new mode 100755 similarity index 100% rename from test/test_json_op.sh rename to src/yajlpp/test_json_op.sh diff --git a/test/test_json_ptr.cc b/src/yajlpp/test_json_ptr.cc similarity index 98% rename from test/test_json_ptr.cc rename to src/yajlpp/test_json_ptr.cc index e70a9342..2e776d11 100644 --- a/test/test_json_ptr.cc +++ b/src/yajlpp/test_json_ptr.cc @@ -35,7 +35,7 @@ #include #include -#include "json_ptr.hh" +#include "yajlpp/json_ptr.hh" int main(int argc, const char *argv[]) { diff --git a/test/test_json_ptr_walk.sh b/src/yajlpp/test_json_ptr_walk.sh similarity index 84% rename from test/test_json_ptr_walk.sh rename to src/yajlpp/test_json_ptr_walk.sh index 1b19a28e..bcaf1ecd 100644 --- a/test/test_json_ptr_walk.sh +++ b/src/yajlpp/test_json_ptr_walk.sh @@ -35,7 +35,7 @@ check_output "array" < #include -#include "yajlpp.hh" -#include "yajlpp_def.hh" +#include "yajlpp/yajlpp.hh" +#include "yajlpp/yajlpp_def.hh" const char *TEST_DATA = "[{ \"foo\": 0 }, { \"foo\": 1 }]"; diff --git a/src/yajlpp.cc b/src/yajlpp/yajlpp.cc similarity index 99% rename from src/yajlpp.cc rename to src/yajlpp/yajlpp.cc index e807fbde..f0f6f1db 100644 --- a/src/yajlpp.cc +++ b/src/yajlpp/yajlpp.cc @@ -556,7 +556,6 @@ void yajlpp_gen_context::gen() yajlpp_gen_context &yajlpp_gen_context::with_context(yajlpp_parse_context &ypc) { this->ygc_obj_stack = ypc.ypc_obj_stack; - this->ygc_base_name = ypc.get_path_fragment(-1); if (ypc.ypc_current_handler == nullptr && !ypc.ypc_handler_stack.empty() && ypc.ypc_handler_stack.back() != nullptr) { diff --git a/src/yajlpp.hh b/src/yajlpp/yajlpp.hh similarity index 97% rename from src/yajlpp.hh rename to src/yajlpp/yajlpp.hh index fc4cfdac..9e885620 100644 --- a/src/yajlpp.hh +++ b/src/yajlpp/yajlpp.hh @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013, Timothy Stack + * Copyright (c) 2013-2019, Timothy Stack * * All rights reserved. * @@ -47,7 +47,7 @@ #include #include "optional.hpp" -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "json_ptr.hh" #include "intern_string.hh" @@ -135,17 +135,16 @@ struct json_path_handler_base { json_path_handler_base(const char *path) : jph_path(path), jph_regex(path, PCRE_ANCHORED), - jph_gen_callback(NULL), + jph_gen_callback(nullptr), jph_field_getter(nullptr), - jph_obj_provider(NULL), - jph_path_provider(NULL), + jph_obj_provider(nullptr), + jph_path_provider(nullptr), jph_synopsis(""), jph_description(""), - jph_children(NULL), - jph_kv_pair(false), + jph_children(nullptr), jph_min_length(0), jph_max_length(INT_MAX), - jph_enum_values(NULL), + jph_enum_values(nullptr), jph_min_value(LLONG_MIN), jph_optional_wrapper(false) { @@ -184,7 +183,6 @@ struct json_path_handler_base { const char * jph_synopsis; const char * jph_description; json_path_handler_base *jph_children; - bool jph_kv_pair; std::shared_ptr jph_pattern; const char * jph_pattern_re{nullptr}; std::function jph_string_validator; @@ -368,7 +366,7 @@ public: } }; - yajl_status complete_parse();; + yajl_status complete_parse(); void report_error(lnav_log_level_t level, const char *format, ...) { va_list args; @@ -587,17 +585,20 @@ public: int ygc_depth; std::stack ygc_default_stack; std::stack ygc_obj_stack; - std::string ygc_base_name; json_path_handler *ygc_handlers; }; class yajlpp_gen { public: yajlpp_gen() : yg_handle(yajl_gen_free) { - this->yg_handle = yajl_gen_alloc(NULL); + this->yg_handle = yajl_gen_alloc(nullptr); }; - operator yajl_gen_t *() { + yajl_gen get_handle() const { + return this->yg_handle.in(); + }; + + operator yajl_gen () { return this->yg_handle.in(); }; diff --git a/src/yajlpp_def.hh b/src/yajlpp/yajlpp_def.hh similarity index 100% rename from src/yajlpp_def.hh rename to src/yajlpp/yajlpp_def.hh diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b0eb9f98..0a19d02a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,42 +6,28 @@ add_executable(lnav_doctests ../src/relative_time.cc ../../lbuild-debug/src/time_fmts.cc ../src/ptimec_rt.cc - ../src/pcrepp.cc - ../src/lnav_log.cc) -add_executable(test_pcrepp test_pcrepp.cc ../src/lnav_log.cc ../src/pcrepp.cc) + ../src/pcrepp/pcrepp.cc + ../src/base/lnav_log.cc) +add_executable(test_pcrepp test_pcrepp.cc ../src/base/lnav_log.cc ../src/pcrepp/pcrepp.cc) add_executable(test_reltime test_reltime.cc ../src/relative_time.cc - ../src/pcrepp.cc - ../src/lnav_log.cc) + ../src/pcrepp/pcrepp.cc + ../src/base/lnav_log.cc) add_executable(test_date_time_scanner test_date_time_scanner.cc ../src/lnav_util.cc ../../lbuild-debug/src/time_fmts.cc ../src/ptimec_rt.cc - ../src/pcrepp.cc - ../src/lnav_log.cc + ../src/pcrepp/pcrepp.cc + ../src/base/lnav_log.cc ../src/spookyhash/SpookyV2.cpp) add_executable(test_abbrev test_abbrev.cc ../src/lnav_util.cc ../../lbuild-debug/src/time_fmts.cc ../src/ptimec_rt.cc - ../src/pcrepp.cc - ../src/lnav_log.cc + ../src/pcrepp/pcrepp.cc + ../src/base/lnav_log.cc ../src/spookyhash/SpookyV2.cpp) -add_executable(test_json_ptr test_json_ptr.cc - ../src/lnav_util.cc - ../../lbuild-debug/src/time_fmts.cc - ../src/ptimec_rt.cc - ../src/pcrepp.cc - ../src/lnav_log.cc - ../src/spookyhash/SpookyV2.cpp) -add_executable(drive_json_op drive_json_op.cc - ../src/lnav_util.cc - ../../lbuild-debug/src/time_fmts.cc - ../src/ptimec_rt.cc - ../src/pcrepp.cc - ../src/lnav_log.cc - ../src/spookyhash/SpookyV2.cpp) -add_executable(drive_sql_anno drive_sql_anno.cc ../src/lnav_log.cc ../src/pcrepp.cc) +add_executable(drive_sql_anno drive_sql_anno.cc ../src/base/lnav_log.cc ../src/pcrepp/pcrepp.cc) link_directories(/opt/local/lib) target_link_libraries(test_pcrepp /usr/local/lib/libpcre.a) target_link_libraries(test_reltime /usr/local/lib/libpcre.a) @@ -49,4 +35,3 @@ target_link_libraries(lnav_doctests /usr/local/lib/libpcre.a) target_link_libraries(test_date_time_scanner /usr/local/lib/libpcre.a) target_link_libraries(test_abbrev /usr/local/lib/libpcre.a) target_link_libraries(drive_sql_anno /usr/local/lib/libpcre.a) -target_link_libraries(test_json_ptr /usr/local/lib/libpcre.a) diff --git a/test/Makefile.am b/test/Makefile.am index 0dab9cf9..d81ffd9c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -19,8 +19,6 @@ check_PROGRAMS = \ drive_data_scanner \ drive_line_buffer \ drive_grep_proc \ - drive_json_op \ - drive_json_ptr_walk \ drive_listview \ drive_logfile \ drive_mvwattrline \ @@ -41,14 +39,12 @@ check_PROGRAMS = \ test_bookmarks \ test_date_time_scanner \ test_grep_proc2 \ - test_json_ptr \ test_line_buffer2 \ test_log_accel \ test_ncurses_unicode \ test_pcrepp \ test_reltime \ - test_top_status \ - test_yajlpp + test_top_status AM_LDFLAGS = \ $(STATIC_LDFLAGS) \ @@ -62,159 +58,88 @@ CONFIG_OBJS = \ ../src/keymap-default.o TEXT2C_OBJS = \ + ../src/default-log-formats-json.o \ ../src/dhclient-summary.o \ ../src/dump-pid-sh.o \ ../src/lnav-pop-view.o \ ../src/partition-by-boot.o \ ../src/search-for.o -LDADD = -lz $(CURSES_LIB) +LDADD = \ + -lz \ + $(CURSES_LIB) \ + $(CONFIG_OBJS) \ + $(TEXT2C_OBJS) \ + $(top_builddir)/src/base/libbase.a \ + $(top_builddir)/src/fmtlib/libcppfmt.a \ + $(top_builddir)/src/pcrepp/libpcrepp.a \ + $(top_builddir)/src/yajl/libyajl.a \ + $(top_builddir)/src/yajlpp/libyajlpp.a \ + $(top_builddir)/src/libdiag.a \ + $(SQLITE3_LIBS) \ + $(PCRE_LIBS) \ + $(READLINE_LIBS) \ + $(LIBCURL) \ + -lpcrecpp test_ansi_scrubber_SOURCES = test_ansi_scrubber.cc -test_ansi_scrubber_LDADD = ../src/libdiag.a $(CURSES_LIB) \ - $(CONFIG_OBJS) test_auto_fd_SOURCES = test_auto_fd.cc -test_auto_fd_LDADD = ../src/libdiag.a test_auto_mem_SOURCES = test_auto_mem.cc test_bookmarks_SOURCES = test_bookmarks.cc -test_bookmarks_LDADD = ../src/libdiag.a test_date_time_scanner_SOURCES = test_date_time_scanner.cc -test_date_time_scanner_LDADD = ../src/libdiag.a $(SQLITE3_LIBS) test_grep_proc2_SOURCES = test_grep_proc2.cc -test_grep_proc2_LDADD = ../src/libdiag.a $(PCRE_LIBS) -lz test_line_buffer2_SOURCES = test_line_buffer2.cc -test_line_buffer2_LDADD = ../src/libdiag.a test_log_accel_SOURCES = test_log_accel.cc -test_log_accel_LDADD = ../src/libdiag.a test_pcrepp_SOURCES = test_pcrepp.cc -test_pcrepp_LDADD = ../src/libdiag.a $(PCRE_LIBS) -lz test_top_status_SOURCES = test_top_status.cc -test_top_status_LDADD = \ - ../src/libdiag.a \ - $(CONFIG_OBJS) \ - $(CURSES_LIB) \ - $(PCRE_LIBS) \ - $(SQLITE3_LIBS) \ - $(LIBCURL) \ - -lz - -test_yajlpp_SOURCES = test_yajlpp.cc -test_yajlpp_LDADD = ../src/libdiag.a test_abbrev_SOURCES = test_abbrev.cc -test_abbrev_LDADD = ../src/libdiag.a - -test_json_ptr_SOURCES = test_json_ptr.cc -test_json_ptr_LDADD = ../src/libdiag.a test_reltime_SOURCES = test_reltime.cc -test_reltime_LDADD = ../src/libdiag.a test_ncurses_unicode_SOURCES = test_ncurses_unicode.cc lnav_doctests_SOURCES = lnav_doctests.cc -lnav_doctests_LDADD = ../src/libdiag.a $(CONFIG_OBJS) $(CURSES_LIB) drive_line_buffer_SOURCES = drive_line_buffer.cc -drive_line_buffer_LDADD = ../src/libdiag.a $(CURSES_LIB) -lz $(CURSES_LIB) drive_grep_proc_SOURCES = drive_grep_proc.cc -drive_grep_proc_LDADD = ../src/libdiag.a $(PCRE_LIBS) -lz $(CURSES_LIB) - -drive_json_op_SOURCES = drive_json_op.cc -drive_json_op_LDADD = ../src/libdiag.a $(PCRE_LIBS) -lz $(CURSES_LIB) - -drive_json_ptr_walk_SOURCES = drive_json_ptr_walk.cc -drive_json_ptr_walk_LDADD = ../src/libdiag.a $(PCRE_LIBS) -lz $(CURSES_LIB) drive_listview_SOURCES = drive_listview.cc -drive_listview_LDADD = ../src/libdiag.a $(CURSES_LIB) -lz $(CURSES_LIB) \ - $(CONFIG_OBJS) drive_logfile_SOURCES = drive_logfile.cc -drive_logfile_LDADD = \ - ../src/libdiag.a \ - ../src/default-log-formats-json.o \ - $(CONFIG_OBJS) \ - $(TEXT2C_OBJS) \ - $(CURSES_LIB) \ - $(SQLITE3_LIBS) \ - $(PCRE_LIBS) \ - -lpcrecpp drive_sequencer_SOURCES = drive_sequencer.cc -drive_sequencer_LDADD = ../src/libdiag.a $(CURSES_LIB) $(SQLITE3_LIBS) drive_shlexer_SOURCES = drive_shlexer.cc -drive_shlexer_LDADD = ../src/libdiag.a drive_data_scanner_SOURCES = \ drive_data_scanner.cc -drive_data_scanner_LDADD = \ - ../src/libdiag.a \ - ../src/default-log-formats-json.o \ - $(CONFIG_OBJS) \ - $(TEXT2C_OBJS) \ - $(LIBCURL) \ - $(PCRE_LIBS) \ - $(SQLITE3_LIBS) \ - -lpcrecpp \ - $(CURSES_LIB) drive_mvwattrline_SOURCES = drive_mvwattrline.cc -drive_mvwattrline_LDADD = ../src/libdiag.a $(CURSES_LIB) \ - $(CONFIG_OBJS) drive_view_colors_SOURCES = drive_view_colors.cc -drive_view_colors_LDADD = ../src/libdiag.a $(CURSES_LIB) \ - $(CONFIG_OBJS) drive_vt52_curses_SOURCES = drive_vt52_curses.cc -drive_vt52_curses_LDADD = ../src/libdiag.a $(CURSES_LIB) $(CONFIG_OBJS) drive_readline_curses_SOURCES = drive_readline_curses.cc -drive_readline_curses_LDADD = ../src/libdiag.a $(READLINE_LIBS) $(CURSES_LIB) \ - $(CONFIG_OBJS) - -drive_sql_SOURCES = \ - drive_sql.cc -drive_sql_LDADD = \ - ../src/libdiag.a \ - $(CONFIG_OBJS) \ - $(SQLITE3_LIBS) \ - $(PCRE_LIBS) \ - $(CURSES_LIB) \ - $(READLINE_LIBS) \ - $(LIBCURL) \ - $(TEXT2C_OBJS) \ - -lpcrecpp -drive_sql_anno_SOURCES = \ - drive_sql_anno.cc -drive_sql_anno_LDADD = \ - ../src/libdiag.a \ - $(CONFIG_OBJS) \ - $(SQLITE3_LIBS) \ - $(PCRE_LIBS) \ - $(CURSES_LIB) \ - $(READLINE_LIBS) \ - $(LIBCURL) \ - -lpcrecpp +drive_sql_SOURCES = drive_sql.cc + +drive_sql_anno_SOURCES = drive_sql_anno.cc slicer_SOURCES = slicer.cc -slicer_LDADD = ../src/libdiag.a $(CURSES_LIB) scripty_SOURCES = scripty.cc -scripty_LDADD = ../src/libdiag.a $(CURSES_LIB) dist_noinst_SCRIPTS = \ parser_debugger.py \ @@ -227,8 +152,6 @@ dist_noinst_SCRIPTS = \ test_format_loader.sh \ test_grep_proc.sh \ test_json_format.sh \ - test_json_op.sh \ - test_json_ptr_walk.sh \ test_line_buffer.sh \ test_listview.sh \ test_logfile.sh \ @@ -384,8 +307,6 @@ TESTS = \ test_grep_proc.sh \ test_grep_proc2 \ test_json_format.sh \ - test_json_op.sh \ - test_json_ptr_walk.sh \ test_log_accel \ test_logfile.sh \ test_pcrepp \ @@ -400,7 +321,6 @@ TESTS = \ test_sql_str_func.sh \ test_sql_time_func.sh \ test_data_parser.sh \ - test_yajlpp \ test_pretty_print.sh DISABLED_TESTS = \ diff --git a/test/drive_data_scanner.cc b/test/drive_data_scanner.cc index 16580844..0f69b0aa 100644 --- a/test/drive_data_scanner.cc +++ b/test/drive_data_scanner.cc @@ -35,7 +35,7 @@ #include #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "textview_curses.hh" #include "data_scanner.hh" #include "data_parser.hh" diff --git a/test/drive_sequencer.cc b/test/drive_sequencer.cc index 351af682..c35021c8 100644 --- a/test/drive_sequencer.cc +++ b/test/drive_sequencer.cc @@ -43,7 +43,7 @@ #include #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" #include "logfile.hh" #include "sequence_sink.hh" #include "sequence_matcher.hh" diff --git a/test/drive_sql.cc b/test/drive_sql.cc index d7f67108..f651de33 100644 --- a/test/drive_sql.cc +++ b/test/drive_sql.cc @@ -64,9 +64,6 @@ extern "C" { const char *help_txt = ""; } -extern "C" { -const char *default_log_formats_json = ""; -} int main(int argc, char *argv[]) { int retval = EXIT_SUCCESS; diff --git a/test/test_ansi_scrubber.cc b/test/test_ansi_scrubber.cc index 20a69f3f..36a75d5b 100644 --- a/test/test_ansi_scrubber.cc +++ b/test/test_ansi_scrubber.cc @@ -46,7 +46,6 @@ using namespace std; int main(int argc, char *argv[]) { view_colors &vc = view_colors::singleton(); - string_attrs_t::iterator iter; string_attrs_t sa; string str_cp; diff --git a/test/test_pcrepp.cc b/test/test_pcrepp.cc index f95b04fe..cf9d1bc8 100644 --- a/test/test_pcrepp.cc +++ b/test/test_pcrepp.cc @@ -35,7 +35,7 @@ #include -#include "pcrepp.hh" +#include "pcrepp/pcrepp.hh" int main(int argc, char *argv[]) {