1
1
mirror of https://github.com/tstack/lnav.git synced 2024-09-11 13:05:51 +03:00

[test] add a test for the ansi scrubber

This commit is contained in:
Timothy Stack 2013-06-08 10:51:54 -07:00
parent 47846bae4c
commit 8f0aac9dbd
8 changed files with 307 additions and 226 deletions

View File

@ -27,6 +27,7 @@ LDADD = \
-lcrypto
noinst_HEADERS = \
ansi_scrubber.hh \
auto_fd.hh \
auto_mem.hh \
bookmarks.hh \
@ -89,6 +90,7 @@ noinst_HEADERS = \
yajl/yajl_version.h
libdiag_a_SOURCES = \
ansi_scrubber.cc \
bookmarks.cc \
collation-functions.cc \
extension-functions.c \

View File

@ -105,7 +105,7 @@ am__v_AR_0 = @echo " AR " $@;
am__v_AR_1 =
libdiag_a_AR = $(AR) $(ARFLAGS)
libdiag_a_LIBADD =
am_libdiag_a_OBJECTS = bookmarks.$(OBJEXT) \
am_libdiag_a_OBJECTS = ansi_scrubber.$(OBJEXT) bookmarks.$(OBJEXT) \
collation-functions.$(OBJEXT) extension-functions.$(OBJEXT) \
fs-extension-functions.$(OBJEXT) grep_proc.$(OBJEXT) \
hist_source.$(OBJEXT) line_buffer.$(OBJEXT) \
@ -351,6 +351,7 @@ LDADD = \
-lcrypto
noinst_HEADERS = \
ansi_scrubber.hh \
auto_fd.hh \
auto_mem.hh \
bookmarks.hh \
@ -413,6 +414,7 @@ noinst_HEADERS = \
yajl/yajl_version.h
libdiag_a_SOURCES = \
ansi_scrubber.cc \
bookmarks.cc \
collation-functions.cc \
extension-functions.c \
@ -589,6 +591,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ansi_scrubber.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bin2c.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bookmarks.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collation-functions.Po@am__quote@

131
src/ansi_scrubber.cc Normal file
View File

@ -0,0 +1,131 @@
/**
* Copyright (c) 2013, Timothy Stack
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Timothy Stack nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <vector>
#include "ansi_scrubber.hh"
using namespace std;
void ansi_scrubber::scrub_value(std::string &str, string_attrs_t &sa)
{
view_colors &vc = view_colors::singleton();
vector<pair<string, string_attr_t> > attr_queue;
pcre_context_static<60> context;
vector<line_range> range_queue;
pcre_input pi(str);
while (this->as_regex.match(context, pi)) {
pcre_context::capture_t *caps = context.all();
struct line_range lr;
bool has_attrs = false;
int attrs = 0;
int bg = 0;
int fg = 0;
int lpc;
switch (pi.get_substr_start(&caps[2])[0]) {
case 'm':
for (lpc = caps[1].c_begin;
lpc != (int)string::npos && lpc < caps[1].c_end; ) {
int ansi_code = 0;
if (sscanf(&(str[lpc]), "%d", &ansi_code) == 1) {
if (90 <= ansi_code && ansi_code <= 97) {
ansi_code -= 60;
attrs |= A_STANDOUT;
}
if (30 <= ansi_code && ansi_code <= 37) {
fg = ansi_code - 30;
}
if (40 <= ansi_code && ansi_code <= 47) {
bg = ansi_code - 40;
}
switch (ansi_code) {
case 1:
attrs |= A_BOLD;
break;
case 2:
attrs |= A_DIM;
break;
case 4:
attrs |= A_UNDERLINE;
break;
case 7:
attrs |= A_REVERSE;
break;
}
}
lpc = str.find(";", lpc);
if (lpc != (int)string::npos) {
lpc += 1;
}
}
if (fg != 0 || bg != 0) {
attrs |= vc.ansi_color_pair(fg, bg);
}
has_attrs = true;
break;
case 'C':
{
int spaces = 0;
if (sscanf(&(str[caps[1].c_begin]), "%d", &spaces) == 1) {
str.insert(caps[0].c_end, spaces, ' ');
}
}
break;
}
str.erase(str.begin() + caps[0].c_begin,
str.begin() + caps[0].c_end);
if (has_attrs) {
if (!range_queue.empty()) {
range_queue.back().lr_end = caps[0].c_begin;
}
lr.lr_start = caps[0].c_begin;
lr.lr_end = -1;
range_queue.push_back(lr);
attr_queue.push_back(make_string_attr("style", attrs));
}
pi.reset(str);
}
for (size_t lpc = 0; lpc < range_queue.size(); lpc++) {
sa[range_queue[lpc]].insert(attr_queue[lpc]);
}
}

57
src/ansi_scrubber.hh Normal file
View File

@ -0,0 +1,57 @@
/**
* Copyright (c) 2013, Timothy Stack
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Timothy Stack nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ansi_scrubber_hh
#define _ansi_scrubber_hh
#include <string>
#include "pcrepp.hh"
#include "view_curses.hh"
class ansi_scrubber {
public:
static ansi_scrubber &singleton()
{
static ansi_scrubber s_as;
return s_as;
}
void scrub_value(std::string &str, string_attrs_t &sa);
private:
ansi_scrubber()
: as_regex("\x1b\\[([\\d=;]*)([a-zA-Z])") {
};
pcrepp as_regex;
};
#endif

View File

@ -35,6 +35,7 @@
#include "pcrepp.hh"
#include "lnav_util.hh"
#include "data_parser.hh"
#include "ansi_scrubber.hh"
#include "textview_curses.hh"
using namespace std;
@ -42,120 +43,6 @@ using namespace std;
bookmark_type_t textview_curses::BM_USER;
bookmark_type_t textview_curses::BM_SEARCH;
class ansi_scrubber {
/* XXX move to view_curses.cc ; actually, move to it's own file and call
* from there.
*/
public:
static ansi_scrubber &singleton()
{
static ansi_scrubber s_as;
return s_as;
}
void scrub_value(string &str, string_attrs_t &sa)
{
view_colors &vc = view_colors::singleton();
vector<pair<string, string_attr_t> > attr_queue;
pcre_context_static<60> context;
vector<line_range> range_queue;
pcre_input pi(str);
while (this->as_regex.match(context, pi)) {
pcre_context::capture_t *caps = context.all();
struct line_range lr;
bool has_attrs = false;
int attrs = 0;
int bg = 0;
int fg = 0;
int lpc;
switch (pi.get_substr_start(&caps[2])[0]) {
case 'm':
for (lpc = caps[1].c_begin;
lpc != (int)string::npos && lpc < caps[1].c_end; ) {
int ansi_code = 0;
if (sscanf(&(str[lpc]), "%d", &ansi_code) == 1) {
if (90 <= ansi_code && ansi_code <= 97) {
ansi_code -= 60;
attrs |= A_STANDOUT;
}
if (30 <= ansi_code && ansi_code <= 37) {
fg = ansi_code - 30;
}
if (40 <= ansi_code && ansi_code <= 47) {
bg = ansi_code - 40;
}
switch (ansi_code) {
case 1:
attrs |= A_BOLD;
break;
case 2:
attrs |= A_DIM;
break;
case 4:
attrs |= A_UNDERLINE;
break;
case 7:
attrs |= A_REVERSE;
break;
}
}
lpc = str.find(";", lpc);
if (lpc != (int)string::npos) {
lpc += 1;
}
}
if (fg != 0 || bg != 0) {
attrs |= vc.ansi_color_pair(fg, bg);
}
has_attrs = true;
break;
case 'C':
{
int spaces = 0;
if (sscanf(&(str[caps[1].c_begin]), "%d", &spaces) == 1) {
str.insert(caps[0].c_end, spaces, ' ');
}
}
break;
}
str.erase(str.begin() + caps[0].c_begin,
str.begin() + caps[0].c_end);
if (has_attrs) {
if (!range_queue.empty()) {
range_queue.back().lr_end = caps[0].c_begin;
}
lr.lr_start = caps[0].c_begin;
lr.lr_end = -1;
range_queue.push_back(lr);
attr_queue.push_back(make_string_attr("style", attrs));
}
pi.reset(str);
}
for (size_t lpc = 0; lpc < range_queue.size(); lpc++) {
sa[range_queue[lpc]].insert(attr_queue[lpc]);
}
};
private:
ansi_scrubber()
: as_regex("\x1b\\[([\\d=;]*)([a-zA-Z])") {
};
pcrepp as_regex;
};
textview_curses::textview_curses()
: tc_searching(false),
tc_follow_search(false)

View File

@ -26,6 +26,7 @@ check_PROGRAMS = \
drive_readline_curses \
slicer \
scripty \
test_ansi_scrubber \
test_auto_fd \
test_auto_mem \
test_bookmarks \
@ -40,6 +41,9 @@ AM_LDFLAGS = \
LDADD = -lz
test_ansi_scrubber_SOURCES = test_ansi_scrubber.cc
test_ansi_scrubber_LDADD = ../src/libdiag.a $(CURSES_LIB)
test_auto_fd_SOURCES = test_auto_fd.cc
test_auto_mem_SOURCES = test_auto_mem.cc
@ -65,19 +69,8 @@ test_line_buffer2_SOURCES = \
test_pcrepp_SOURCES = \
test_pcrepp.cc
test_top_status_SOURCES = \
../src/bookmarks.cc \
../src/logfile.cc \
../src/line_buffer.cc \
../src/log_format.cc \
../src/logfile_sub_source.cc \
../src/listview_curses.cc \
../src/textview_curses.cc \
../src/data_scanner.cc \
../src/data_parser.cc \
../src/view_curses.cc \
test_top_status.cc
test_top_status_LDADD = $(CURSES_LIB) -lz
test_top_status_SOURCES = test_top_status.cc
test_top_status_LDADD = ../src/libdiag.a $(CURSES_LIB) -lz
drive_line_buffer_SOURCES = \
../src/line_buffer.cc \
@ -194,9 +187,11 @@ dist_noinst_DATA = \
nodist_noinst_DATA = \
simple-db.db
TESTS = test_bookmarks \
TESTS = \
test_ansi_scrubber \
test_auto_fd \
test_auto_mem \
test_bookmarks \
test_line_buffer.sh \
test_line_buffer2 \
test_grep_proc.sh \

View File

@ -85,16 +85,18 @@ check_PROGRAMS = drive_data_scanner$(EXEEXT) \
drive_sequencer$(EXEEXT) drive_sql$(EXEEXT) \
drive_view_colors$(EXEEXT) drive_vt52_curses$(EXEEXT) \
drive_readline_curses$(EXEEXT) slicer$(EXEEXT) \
scripty$(EXEEXT) test_auto_fd$(EXEEXT) test_auto_mem$(EXEEXT) \
scripty$(EXEEXT) test_ansi_scrubber$(EXEEXT) \
test_auto_fd$(EXEEXT) test_auto_mem$(EXEEXT) \
test_bookmarks$(EXEEXT) test_grep_proc2$(EXEEXT) \
test_hist_source$(EXEEXT) test_line_buffer2$(EXEEXT) \
test_pcrepp$(EXEEXT) test_top_status$(EXEEXT)
TESTS = test_bookmarks$(EXEEXT) test_auto_fd$(EXEEXT) \
test_auto_mem$(EXEEXT) test_line_buffer.sh \
test_line_buffer2$(EXEEXT) test_grep_proc.sh \
test_grep_proc2$(EXEEXT) test_hist_source$(EXEEXT) \
test_listview.sh test_pcrepp$(EXEEXT) test_sql_coll_func.sh \
test_sql_fs_func.sh test_view_colors.sh test_vt52_curses.sh \
TESTS = test_ansi_scrubber$(EXEEXT) test_auto_fd$(EXEEXT) \
test_auto_mem$(EXEEXT) test_bookmarks$(EXEEXT) \
test_line_buffer.sh test_line_buffer2$(EXEEXT) \
test_grep_proc.sh test_grep_proc2$(EXEEXT) \
test_hist_source$(EXEEXT) test_listview.sh \
test_pcrepp$(EXEEXT) test_sql_coll_func.sh test_sql_fs_func.sh \
test_view_colors.sh test_vt52_curses.sh \
test_top_status$(EXEEXT) test_data_parser.sh
subdir = test
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
@ -162,6 +164,10 @@ am_slicer_OBJECTS = line_buffer.$(OBJEXT) slicer.$(OBJEXT)
slicer_OBJECTS = $(am_slicer_OBJECTS)
slicer_LDADD = $(LDADD)
slicer_DEPENDENCIES =
am_test_ansi_scrubber_OBJECTS = test_ansi_scrubber.$(OBJEXT)
test_ansi_scrubber_OBJECTS = $(am_test_ansi_scrubber_OBJECTS)
test_ansi_scrubber_DEPENDENCIES = ../src/libdiag.a \
$(am__DEPENDENCIES_1)
am_test_auto_fd_OBJECTS = test_auto_fd.$(OBJEXT)
test_auto_fd_OBJECTS = $(am_test_auto_fd_OBJECTS)
test_auto_fd_LDADD = $(LDADD)
@ -192,14 +198,9 @@ am_test_pcrepp_OBJECTS = test_pcrepp.$(OBJEXT)
test_pcrepp_OBJECTS = $(am_test_pcrepp_OBJECTS)
test_pcrepp_LDADD = $(LDADD)
test_pcrepp_DEPENDENCIES =
am_test_top_status_OBJECTS = bookmarks.$(OBJEXT) logfile.$(OBJEXT) \
line_buffer.$(OBJEXT) log_format.$(OBJEXT) \
logfile_sub_source.$(OBJEXT) listview_curses.$(OBJEXT) \
textview_curses.$(OBJEXT) data_scanner.$(OBJEXT) \
data_parser.$(OBJEXT) view_curses.$(OBJEXT) \
test_top_status.$(OBJEXT)
am_test_top_status_OBJECTS = test_top_status.$(OBJEXT)
test_top_status_OBJECTS = $(am_test_top_status_OBJECTS)
test_top_status_DEPENDENCIES = $(am__DEPENDENCIES_1)
test_top_status_DEPENDENCIES = ../src/libdiag.a $(am__DEPENDENCIES_1)
SCRIPTS = $(dist_noinst_SCRIPTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@ -239,7 +240,8 @@ SOURCES = $(drive_data_scanner_SOURCES) $(drive_grep_proc_SOURCES) \
$(drive_logfile_SOURCES) $(drive_readline_curses_SOURCES) \
$(drive_sequencer_SOURCES) $(drive_sql_SOURCES) \
$(drive_view_colors_SOURCES) $(drive_vt52_curses_SOURCES) \
$(scripty_SOURCES) $(slicer_SOURCES) $(test_auto_fd_SOURCES) \
$(scripty_SOURCES) $(slicer_SOURCES) \
$(test_ansi_scrubber_SOURCES) $(test_auto_fd_SOURCES) \
$(test_auto_mem_SOURCES) $(test_bookmarks_SOURCES) \
$(test_grep_proc2_SOURCES) $(test_hist_source_SOURCES) \
$(test_line_buffer2_SOURCES) $(test_pcrepp_SOURCES) \
@ -250,11 +252,11 @@ DIST_SOURCES = $(drive_data_scanner_SOURCES) \
$(drive_readline_curses_SOURCES) $(drive_sequencer_SOURCES) \
$(drive_sql_SOURCES) $(drive_view_colors_SOURCES) \
$(drive_vt52_curses_SOURCES) $(scripty_SOURCES) \
$(slicer_SOURCES) $(test_auto_fd_SOURCES) \
$(test_auto_mem_SOURCES) $(test_bookmarks_SOURCES) \
$(test_grep_proc2_SOURCES) $(test_hist_source_SOURCES) \
$(test_line_buffer2_SOURCES) $(test_pcrepp_SOURCES) \
$(test_top_status_SOURCES)
$(slicer_SOURCES) $(test_ansi_scrubber_SOURCES) \
$(test_auto_fd_SOURCES) $(test_auto_mem_SOURCES) \
$(test_bookmarks_SOURCES) $(test_grep_proc2_SOURCES) \
$(test_hist_source_SOURCES) $(test_line_buffer2_SOURCES) \
$(test_pcrepp_SOURCES) $(test_top_status_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@ -609,6 +611,8 @@ AM_LDFLAGS = \
$(SQLITE3_LDFLAGS)
LDADD = -lz
test_ansi_scrubber_SOURCES = test_ansi_scrubber.cc
test_ansi_scrubber_LDADD = ../src/libdiag.a $(CURSES_LIB)
test_auto_fd_SOURCES = test_auto_fd.cc
test_auto_mem_SOURCES = test_auto_mem.cc
test_bookmarks_SOURCES = test_bookmarks.cc ../src/bookmarks.cc
@ -631,20 +635,8 @@ test_line_buffer2_SOURCES = \
test_pcrepp_SOURCES = \
test_pcrepp.cc
test_top_status_SOURCES = \
../src/bookmarks.cc \
../src/logfile.cc \
../src/line_buffer.cc \
../src/log_format.cc \
../src/logfile_sub_source.cc \
../src/listview_curses.cc \
../src/textview_curses.cc \
../src/data_scanner.cc \
../src/data_parser.cc \
../src/view_curses.cc \
test_top_status.cc
test_top_status_LDADD = $(CURSES_LIB) -lz
test_top_status_SOURCES = test_top_status.cc
test_top_status_LDADD = ../src/libdiag.a $(CURSES_LIB) -lz
drive_line_buffer_SOURCES = \
../src/line_buffer.cc \
drive_line_buffer.cc
@ -853,6 +845,10 @@ slicer$(EXEEXT): $(slicer_OBJECTS) $(slicer_DEPENDENCIES) $(EXTRA_slicer_DEPENDE
@rm -f slicer$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(slicer_OBJECTS) $(slicer_LDADD) $(LIBS)
test_ansi_scrubber$(EXEEXT): $(test_ansi_scrubber_OBJECTS) $(test_ansi_scrubber_DEPENDENCIES) $(EXTRA_test_ansi_scrubber_DEPENDENCIES)
@rm -f test_ansi_scrubber$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(test_ansi_scrubber_OBJECTS) $(test_ansi_scrubber_LDADD) $(LIBS)
test_auto_fd$(EXEEXT): $(test_auto_fd_OBJECTS) $(test_auto_fd_DEPENDENCIES) $(EXTRA_test_auto_fd_DEPENDENCIES)
@rm -f test_auto_fd$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(test_auto_fd_OBJECTS) $(test_auto_fd_LDADD) $(LIBS)
@ -892,8 +888,6 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bookmarks.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/data_parser.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/data_scanner.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/drive_data_scanner.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/drive_grep_proc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/drive_line_buffer.Po@am__quote@
@ -910,11 +904,11 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/listview_curses.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log_format.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logfile.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logfile_sub_source.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readline_curses.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scripty.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sequence_matcher.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slicer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_ansi_scrubber.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_auto_fd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_auto_mem.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_bookmarks.Po@am__quote@
@ -923,7 +917,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_line_buffer2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_pcrepp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_top_status.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/textview_curses.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/view_curses.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vt52_curses.Po@am__quote@
@ -1095,62 +1088,6 @@ hist_source.obj: ../src/hist_source.cc
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o hist_source.obj `if test -f '../src/hist_source.cc'; then $(CYGPATH_W) '../src/hist_source.cc'; else $(CYGPATH_W) '$(srcdir)/../src/hist_source.cc'; fi`
logfile_sub_source.o: ../src/logfile_sub_source.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT logfile_sub_source.o -MD -MP -MF $(DEPDIR)/logfile_sub_source.Tpo -c -o logfile_sub_source.o `test -f '../src/logfile_sub_source.cc' || echo '$(srcdir)/'`../src/logfile_sub_source.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/logfile_sub_source.Tpo $(DEPDIR)/logfile_sub_source.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/logfile_sub_source.cc' object='logfile_sub_source.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o logfile_sub_source.o `test -f '../src/logfile_sub_source.cc' || echo '$(srcdir)/'`../src/logfile_sub_source.cc
logfile_sub_source.obj: ../src/logfile_sub_source.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT logfile_sub_source.obj -MD -MP -MF $(DEPDIR)/logfile_sub_source.Tpo -c -o logfile_sub_source.obj `if test -f '../src/logfile_sub_source.cc'; then $(CYGPATH_W) '../src/logfile_sub_source.cc'; else $(CYGPATH_W) '$(srcdir)/../src/logfile_sub_source.cc'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/logfile_sub_source.Tpo $(DEPDIR)/logfile_sub_source.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/logfile_sub_source.cc' object='logfile_sub_source.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o logfile_sub_source.obj `if test -f '../src/logfile_sub_source.cc'; then $(CYGPATH_W) '../src/logfile_sub_source.cc'; else $(CYGPATH_W) '$(srcdir)/../src/logfile_sub_source.cc'; fi`
textview_curses.o: ../src/textview_curses.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT textview_curses.o -MD -MP -MF $(DEPDIR)/textview_curses.Tpo -c -o textview_curses.o `test -f '../src/textview_curses.cc' || echo '$(srcdir)/'`../src/textview_curses.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/textview_curses.Tpo $(DEPDIR)/textview_curses.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/textview_curses.cc' object='textview_curses.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o textview_curses.o `test -f '../src/textview_curses.cc' || echo '$(srcdir)/'`../src/textview_curses.cc
textview_curses.obj: ../src/textview_curses.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT textview_curses.obj -MD -MP -MF $(DEPDIR)/textview_curses.Tpo -c -o textview_curses.obj `if test -f '../src/textview_curses.cc'; then $(CYGPATH_W) '../src/textview_curses.cc'; else $(CYGPATH_W) '$(srcdir)/../src/textview_curses.cc'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/textview_curses.Tpo $(DEPDIR)/textview_curses.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/textview_curses.cc' object='textview_curses.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o textview_curses.obj `if test -f '../src/textview_curses.cc'; then $(CYGPATH_W) '../src/textview_curses.cc'; else $(CYGPATH_W) '$(srcdir)/../src/textview_curses.cc'; fi`
data_scanner.o: ../src/data_scanner.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT data_scanner.o -MD -MP -MF $(DEPDIR)/data_scanner.Tpo -c -o data_scanner.o `test -f '../src/data_scanner.cc' || echo '$(srcdir)/'`../src/data_scanner.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/data_scanner.Tpo $(DEPDIR)/data_scanner.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/data_scanner.cc' object='data_scanner.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o data_scanner.o `test -f '../src/data_scanner.cc' || echo '$(srcdir)/'`../src/data_scanner.cc
data_scanner.obj: ../src/data_scanner.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT data_scanner.obj -MD -MP -MF $(DEPDIR)/data_scanner.Tpo -c -o data_scanner.obj `if test -f '../src/data_scanner.cc'; then $(CYGPATH_W) '../src/data_scanner.cc'; else $(CYGPATH_W) '$(srcdir)/../src/data_scanner.cc'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/data_scanner.Tpo $(DEPDIR)/data_scanner.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/data_scanner.cc' object='data_scanner.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o data_scanner.obj `if test -f '../src/data_scanner.cc'; then $(CYGPATH_W) '../src/data_scanner.cc'; else $(CYGPATH_W) '$(srcdir)/../src/data_scanner.cc'; fi`
data_parser.o: ../src/data_parser.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT data_parser.o -MD -MP -MF $(DEPDIR)/data_parser.Tpo -c -o data_parser.o `test -f '../src/data_parser.cc' || echo '$(srcdir)/'`../src/data_parser.cc
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/data_parser.Tpo $(DEPDIR)/data_parser.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/data_parser.cc' object='data_parser.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o data_parser.o `test -f '../src/data_parser.cc' || echo '$(srcdir)/'`../src/data_parser.cc
data_parser.obj: ../src/data_parser.cc
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT data_parser.obj -MD -MP -MF $(DEPDIR)/data_parser.Tpo -c -o data_parser.obj `if test -f '../src/data_parser.cc'; then $(CYGPATH_W) '../src/data_parser.cc'; else $(CYGPATH_W) '$(srcdir)/../src/data_parser.cc'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/data_parser.Tpo $(DEPDIR)/data_parser.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='../src/data_parser.cc' object='data_parser.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o data_parser.obj `if test -f '../src/data_parser.cc'; then $(CYGPATH_W) '../src/data_parser.cc'; else $(CYGPATH_W) '$(srcdir)/../src/data_parser.cc'; fi`
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
@ -1344,9 +1281,9 @@ recheck: all $(check_PROGRAMS)
am__force_recheck=am--force-recheck \
TEST_LOGS="$$log_list"; \
exit $$?
test_bookmarks.log: test_bookmarks$(EXEEXT)
@p='test_bookmarks$(EXEEXT)'; \
b='test_bookmarks'; \
test_ansi_scrubber.log: test_ansi_scrubber$(EXEEXT)
@p='test_ansi_scrubber$(EXEEXT)'; \
b='test_ansi_scrubber'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
@ -1365,6 +1302,13 @@ test_auto_mem.log: test_auto_mem$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_bookmarks.log: test_bookmarks$(EXEEXT)
@p='test_bookmarks$(EXEEXT)'; \
b='test_bookmarks'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_line_buffer.sh.log: test_line_buffer.sh
@p='test_line_buffer.sh'; \
b='test_line_buffer.sh'; \

View File

@ -0,0 +1,62 @@
/**
* Copyright (c) 2013, Timothy Stack
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Timothy Stack nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ansi_scrubber.hh"
using namespace std;
int main(int argc, char *argv[])
{
ansi_scrubber &as = ansi_scrubber::singleton();
view_colors &vc = view_colors::singleton();
string_attrs_t::iterator iter;
string_attrs_t sa;
string str_cp;
str_cp = "Hello, World!";
as.scrub_value(str_cp, sa);
assert(str_cp == "Hello, World!");
assert(sa.empty());
str_cp = "Hello\x1b[44;m, \x1b[33;mWorld\x1b[0;m!";
as.scrub_value(str_cp, sa);
assert(str_cp == "Hello, World!");
iter = sa.begin();
assert(iter->second.find("style")->second.sa_int == vc.ansi_color_pair(0, 4));
assert(iter->first.lr_start == 5);
assert(iter->first.lr_end == 7);
++iter;
assert(iter->second.find("style")->second.sa_int == vc.ansi_color_pair(3, 0));
assert(iter->first.lr_start == 7);
assert(iter->first.lr_end == 12);
}