From e987ef0159010ef94e46629b3cdd5bb3804e48a3 Mon Sep 17 00:00:00 2001 From: sk-5 Date: Fri, 17 Jul 2015 14:37:57 -0700 Subject: [PATCH] Fixed std::out_of_range error --- ChangeLog | 6 +++- configure.ac | 6 ++-- src/Makefile.am | 7 +++-- src/libpipecolors.cc | 17 ++++++++---- src/pcprintf.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 src/pcprintf.cc diff --git a/ChangeLog b/ChangeLog index f6fc878..217e97b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ -2015-07-16 R. Eric Wheeler Version 1.2.0 +2015-07-16 R. Eric Wheeler Version 1.2.0 * Initial Release + +2015-07-17 R. Eric Wheeler Version 1.2.1 + + * Fixed std::out_of_range error when --disable-pipe-stripping is enabled diff --git a/configure.ac b/configure.ac index c972c52..52ae93b 100644 --- a/configure.ac +++ b/configure.ac @@ -66,12 +66,12 @@ AM_COND_IF([PC_REMOVE_INVALID], AC_ARG_ENABLE([debug], [AC_HELP_STRING([--enable-debug], [enable debuging [default=no]])], - [], [enable_debug=no]) + [enable_debug=no], [enable_debug=yes]) AM_CONDITIONAL([PC_DEBUG], [test "x$enable_debug" = "xno"]) AM_COND_IF([PC_DEBUG], - [], - [AC_MSG_NOTICE([Debugging enabled.])]) + [AC_MSG_NOTICE([Debugging enabled.])], + []) AC_CONFIG_FILES([Makefile src/Makefile man/Makefile src/libpipecolors.pc:src/libpipecolors.pc.in src/libpipecolors.h:src/libpipecolors.h.in],[],[APIVERSION=PIPECOLORS_VERSION]) AC_CONFIG_COMMANDS([timestamp], [date >timestamp]) diff --git a/src/Makefile.am b/src/Makefile.am index 5d49db0..de3e373 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,14 +7,15 @@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ lib_LTLIBRARIES = libpipecolors.la libpipecolors_la_SOURCES = libpipecolors.cc -#libpipecolors_la_LIBS = -lboost_regex libpipecolors_la_CFLAGS = -fPIC -DPIC -pthread if PC_REMOVE_INVALID AM_CPPFLAGSINVALID = -DPC_REMOVE_INVALID endif - -AM_CPPFLAGS = $(AM_CPPFLAGSINVALID) +if PC_DEBUG +AM_CPPFLAGSDEBUG = -DPC_DEBUG +endif +AM_CPPFLAGS = $(AM_CPPFLAGSINVALID) $(AM_CPPFLAGSDEBUG) libpipecolors_la_LDFLAGS = -module \ -release ${PIPECOLORS_VERSION} diff --git a/src/libpipecolors.cc b/src/libpipecolors.cc index dfff623..0f934de 100644 --- a/src/libpipecolors.cc +++ b/src/libpipecolors.cc @@ -22,6 +22,9 @@ #ifndef PC_REMOVE_INVALID #define PC_REMOVE_INVALID false #endif +#ifndef PC_DEBUG +#define PC_DEBUG false +#endif #include #include @@ -31,6 +34,7 @@ #include #include "pipecolors.h" + namespace pipecolors { const char * ansi(std::string code) { @@ -85,23 +89,26 @@ namespace pipecolors { void removePipe(std::pair &str, std::string pipe) { size_t index = 0; - + int strlen = 0; while( ( index = str.first.find(pipe, index) ) != std::string::npos ) { str.second.erase(str.second.find(pipe), pipe.length()); - if(ansi(pipe) == "nocode" && PC_REMOVE_INVALID == false) goto skip; + if(ansi(pipe) == "nocode" && PC_REMOVE_INVALID == false) strlen += 3; + if(has_colors() && ansi(pipe) != "nocode") { str.first.replace(index, pipe.length(), ansi(pipe) ); - } else { + } else if(has_colors() && ansi(pipe) == "nocode" && PC_REMOVE_INVALID == true) { str.first.erase(index, pipe.length()); + } else { + index += 3; + goto skip; } - skip:; index += std::string::npos; } - + if(strlen > 0) str.second.insert(str.second.end(), strlen, '\0'); } std::pair replace_colors( std::string s ) { diff --git a/src/pcprintf.cc b/src/pcprintf.cc new file mode 100644 index 0000000..fc3b73a --- /dev/null +++ b/src/pcprintf.cc @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace pipecolors; +using namespace std; + + +void usage() { + pcprintf("|10|30 * |15|30pcprintf|39: |12|30usage|39: |15pcprintf |03\"|11|30string|03\"|39\n"); +} + +void bprintf(const char * format, ... ) { + + + char * buf; + + va_list args; + va_start(args, format); + vprintf(format, args); + va_end(args); + //pcprintf(buf); + //delete[] buf; + +} + +int +ssvprintf(const char *fmt, ...) +{ + va_list args, rag; + va_start(args,fmt); + va_copy(rag, args); + va_end(args); + char * val = va_arg(rag, char*); + printf(fmt, val ); + + + va_end(rag); + +} +int +g (const char *a, ...) +{ + va_list ap; + va_start (ap, a); + va_arg (ap, char*); + if (va_arg (ap, int) != 1234) + std::cout << "Hello" << std::endl; + + va_end (ap); +} +int main( int argc, char * argv[] ) { + + + if(argc <= 1 || argc > 2) { + usage(); + return(1); + } + pcprintf(argv[1],argv[2]); + + return 0; +}