Fixed std::out_of_range error

This commit is contained in:
R. Eric Wheeler 2015-07-17 14:37:57 -07:00
parent ca0105a800
commit e987ef0159
5 changed files with 89 additions and 12 deletions

View File

@ -1,3 +1,7 @@
2015-07-16 R. Eric Wheeler <eric@rewiv.com> Version 1.2.0
2015-07-16 R. Eric Wheeler <eric@rewiv.com> Version 1.2.0
* Initial Release
2015-07-17 R. Eric Wheeler <eric@rewiv.com> Version 1.2.1
* Fixed std::out_of_range error when --disable-pipe-stripping is enabled

View File

@ -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])

View File

@ -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}

View File

@ -22,6 +22,9 @@
#ifndef PC_REMOVE_INVALID
#define PC_REMOVE_INVALID false
#endif
#ifndef PC_DEBUG
#define PC_DEBUG false
#endif
#include <cstdio>
#include <iostream>
@ -31,6 +34,7 @@
#include <unistd.h>
#include "pipecolors.h"
namespace pipecolors {
const char * ansi(std::string code) {
@ -85,23 +89,26 @@ namespace pipecolors {
void removePipe(std::pair<std::string,std::string> &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<std::string,int> replace_colors( std::string s ) {

65
src/pcprintf.cc Normal file
View File

@ -0,0 +1,65 @@
#include <cstdio>
#include <iostream>
#include <pipecolors.h>
#include <climits>
#include <cstring>
#include <cstdarg>
#include <vector>
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;
}