Added clause for no color

This commit is contained in:
R. Eric Wheeler 2015-07-06 15:29:02 -07:00
parent 4513387026
commit 57517f914a
7 changed files with 118 additions and 1098 deletions

1
.gitignore vendored
View File

@ -30,6 +30,7 @@ libpipecolors.so
libpipecolors.la
libpipecolors.lo
libpipecolors.pc
tests/
test/
timestamp
# Ignore backup files

View File

@ -31,3 +31,16 @@ MAINTAINERCLEANFILES = \
-rf m4 \
configure \
Makefile.in
install-man: install-man3 install-man7 install-man-gzip
uninstall-man: uninstall-man3 uninstall-man7 uninstall-man-gzip
install-man-gzip:
test -f $(mandir)/man3/pcprintf.3 && gzip -qf /usr/share/man/man3/pcprintf.3
test -f $(mandir)/man7/libpipecolors.7 && gzip -qf /usr/share/man/man7/libpipecolors.7
test -f $(mandir)/man3/pcprintf.3.gz && ln -sf /usr/share/man/man3/pcprintf.3.gz /usr/share/man/man3/pcsprintf.3.gz
uninstall-man-gzip:
test -f $(mandir)/man3/pcprintf.3.gz && rm -f /usr/share/man/man3/pcprintf.3.gz
test -h $(mandir)/man3/pcsprintf.3.gz && rm -f /usr/share/man/man3/pcsprintf.3.gz
test -f $(mandir)/man7/libpipecolors.7.gz && rm -f /usr/share/man/man7/libpipecolors.7.gz

View File

@ -34,7 +34,6 @@ AM_SILENT_RULES
AC_GNU_SOURCE
AC_CANONICAL_HOST
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_CXXCPP
AM_PROG_AR
AC_PROG_LIBTOOL
@ -43,8 +42,7 @@ AC_PROG_LN_S
LT_INIT
AC_LANG_CPLUSPLUS
AC_PREFIX_DEFAULT([/usr])
#AC_CHECK_LIB([pipecolors], [cprintf])
AC_CHECK_LIB([boost_regex], [main])
# Checks for programs.
AC_CONFIG_MACRO_DIR([m4])
@ -55,9 +53,6 @@ gcc_major_vers=`echo ${gcc_full_vers} | cut -f1 -d.`
gcc_minor_vers=`echo ${gcc_full_vers} | cut -f2 -d.`
gcc_micro_vers=`echo ${gcc_full_vers} | cut -f3 -d.`
# Checks for functions
#AC_CHECK_CXX_ARGUMENT([-std=c++11], [], [AC_MSG_ERROR([C++11 support is required.])])
AC_MSG_CHECKING([${CXX-c++} version])
if test "${gcc_minor_vers}" -lt 9; then
@ -65,13 +60,11 @@ if test "${gcc_minor_vers}" -lt 9; then
else
AC_MSG_RESULT([${gcc_full_vers} ... acceptable])
fi
#AC_HEADER_STDC
# Checks for libraries.
AC_CHECK_HEADERS([stdarg.h stdlib.h unistd.h string iostream map],[],[AC_MSG_ERROR([We couldn't find some of the headers.])])
AC_CHECK_HEADERS([stdarg.h stdlib.h unistd.h string iostream map],[],[AC_MSG_ERROR([We couldn't find one or more of the required headers.])])
AC_CHECK_HEADER([boost/regex.hpp],[],[AC_MSG_ERROR([Please install the libboost-regex header library.])])
AC_CHECK_FUNCS([vprintf vsprintf vasprintf printf])
AC_CHECK_LIB([boost_regex], [main])
AC_CHECK_FUNCS([vasprintf])
AC_CHECK_TYPE([size_t])
AC_CHECK_TYPES([std::string], [], [], [[

View File

@ -1,15 +0,0 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pipecolors.h>
main() {
int a,b;
const char* str = "|0101|0202|0303|0404|0505|0606|0707|0808|0909|1010|1111|1212|1313|1414|1515|07";
const char* name = "|01P|02i|03p|04e|05c|06ol|07o|08r|09s |10l|11i|12b|13r|14a|15r|14y |130|12.|111|07";
a = pcprintf("\n%s\n\n", name);
b = pcprintf("%s\n", str);
}

View File

@ -1,19 +0,0 @@
#include <stdio.h>
#include <iostream>
#include <unistd.h>
#include <pipecolors.h>
using namespace pipecolors;
int main(void) {
const char* str = "|0101|0202|0303|0404|0505|0606|0707|0808|0909|1010|1111|1212|1313|1414|1515|07";
const char* name = "|01P|02i|03p|04e|05c|06ol|07o|08r|09s |10l|11i|12b|13r|14a|15r|14y |130|12.|111|07";
pcprintf("\n%s\n\n", name);
pcprintf("%s\n", str);
int size = pcprintf("%s", str);
std::cout << std::endl << "Size : " << size << std::endl;
return 0;
}

View File

@ -26,8 +26,6 @@
#include <boost/regex.hpp>
#include "pipecolors.h"
using namespace boost;
namespace pipecolors {
std::map<std::string, std::string> colors;
@ -67,12 +65,50 @@ namespace pipecolors {
return isatty(fileno(stdout));
}
std::string replace_colors( std::string s) {
using namespace boost;
std::size_t index;
regex re( "(\\|\\d\\d)" );
match_results<std::string::const_iterator> match;
match_flag_type flags = boost::match_default;
std::string::const_iterator start, end;
start = s.begin();
end = s.end();
colors = getColors();
while(regex_search(start, end, match, re, flags))
{
if(colors[match[0]].empty()) continue;
//while ((index = s.find(match[0])) != std::string::npos)
//{
if(has_colors()) {
s.replace(s.find(match[0]), match[0].length(), colors[match[0]]);
} else {
s.erase(s.find(match[0]), match[0].length());
}
//}
start = match[0].second;
// update flags:
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
return(s);
}
int pcprintf( const char * fmt, ...)
{
char * buffer;
va_list args;
int ret;
colors = getColors();
va_start(args, fmt);
ret = vasprintf(&buffer, fmt, args);
va_end(args);
@ -81,32 +117,12 @@ namespace pipecolors {
exit(EXIT_FAILURE);
}
std::string s(buffer), result(buffer);
std::string s(buffer);
free(buffer);
regex re( "(\\|\\d\\d)" );
std::size_t index;
std::string::const_iterator start, end;
start = s.begin();
end = s.end();
match_results<std::string::const_iterator> match;
match_flag_type flags = boost::match_default;
while(regex_search(start, end, match, re, flags))
{
while ((index = s.find(match[0])) != std::string::npos)
{
s.replace(index, match[0].length(), colors[match[0]]);
}
start = match[0].second;
// update flags:
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
std::cout << s;
std::cout << replace_colors(s);
return(ret);
}
} // namespace

1085
pcprintf.3

File diff suppressed because it is too large Load Diff