diff --git a/.gitignore b/.gitignore index 55b34ec..c530b42 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ timestamp # Ignore backup files *~ libpipecolors.h +cpp-btree/ \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 4509c67..0134d2d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,9 +11,14 @@ libpipecolors_la_LIBS = -lboost_regex libpipecolors_la_CFLAGS = -fPIC -DPIC -pthread if PC_REMOVE_INVALID -AM_CPPFLAGS = -DPC_REMOVE_INVALID +AM_CPPFLAGSINVALID = -DPC_REMOVE_INVALID endif +if BUILD_WITH_BTREE +AM_CPPFLAGSBTREE = -DBUILD_WITH_BTREE +endif + +AM_CPPFLAGS = $(AM_CPPFLAGSBTREE) $(AM_CPPFLAGSINVALID) libpipecolors_la_LDFLAGS = -module \ -release ${PIPECOLORS_VERSION} diff --git a/configure.ac b/configure.ac index ec2fcd0..715cebf 100644 --- a/configure.ac +++ b/configure.ac @@ -77,11 +77,47 @@ AC_ARG_ENABLE([pipe-stripping], [AC_HELP_STRING([--disable-pipe-stripping], [strip invalid pipe codes [default=no]])], [], [disable_pipe_stripping=no]) AM_CONDITIONAL([PC_REMOVE_INVALID], [test "x$disable_pipe_stripping" = "xno"]) + AM_COND_IF([PC_REMOVE_INVALID], - [AC_MSG_NOTICE([Invalid pipe codes will be filtered. - e.g. (|41Hello will show as Hello World instead of |41Hello World)])], - [AC_MSG_NOTICE([Invalid pipe codes will not be filtered. - e.g. (|41Hello will show |41Hello World instead of Hello World)])]) + [AC_MSG_NOTICE([Invalid pipe codes will be filtered.])], + [AC_MSG_NOTICE([Invalid pipe codes will not be filtered.])]) + +AC_ARG_ENABLE([btree], + [AC_HELP_STRING([--enable-btree], [enable googles btree instead of stl map [default=no]])], + [enable_btree=yes]) +AM_CONDITIONAL([BUILD_WITH_BTREE], [test "x$enable_btree" = "xyes"]) + +if test "x$enable_btree" == "xyes"; then + + AC_CHECK_TOOL([MERCURIAL], [hg], [no]) + + AM_CONDITIONAL([HAVE_HG_BIN], [test "x${MERCURIAL}" = "xhg"]) + + AC_MSG_CHECKING([for ${srcdir}/cpp-btree/btree.h]) + + AM_CONDITIONAL([HAVE_BTREE_H], [test -f ${srcdir}/cpp-btree/btree.h]) + + AM_COND_IF([HAVE_BTREE_H], + [AC_MSG_RESULT([found]) + have_btree_h=1], + [AC_MSG_RESULT([no])]) + + if test x$have_btree_h = x1 && ! test ${HAVE_HG_BIN}; then + AC_VERBOSE([Using already existing btree.]) + AM_CONDITIONAL([BUILD_WITH_BTREE], [true]) + elif ${HAVE_HG_BIN} && test x$have_btree_h != x1; then + AC_VERBOSE([Downloading btree headers with mercurial]) + $(which hg) clone https://code.google.com/p/cpp-btree/ + else + AC_VERBOSE([ + * Could not find hg in $PATH + * Building with STL maps instead of Google Btree + ]) + AM_CONDITIONAL([BUILD_WITH_BTREE], [false]) + fi + +fi + AC_ARG_ENABLE([the-force], [AC_HELP_STRING([--enable-the-force], [use the force [default=no]])], [], [enable_the_force=no]) diff --git a/libpipecolors.cpp b/libpipecolors.cpp index 7070522..6134160 100644 --- a/libpipecolors.cpp +++ b/libpipecolors.cpp @@ -25,18 +25,19 @@ #include #include -#include -#include +#include +#include #include #include #include "pipecolors.h" namespace pipecolors { - std::map colors; + //typedef btree::btree_map colors; + typedef std::map colorMap; - std::map getColors() { - std::map colors; + colorMap getColors() { + colorMap colors; colors["|00"] = "\x1b[0;30m"; // FG_BLACK; colors["|01"] = "\x1b[0;34m"; // FG_BLUE; colors["|02"] = "\x1b[0;32m"; // FG_GREEN; @@ -66,6 +67,7 @@ namespace pipecolors { colors["|39"] = "\x1b[0;39m"; // FG_DEFAULT return colors; } + bool has_colors(void) { return isatty(fileno(stdout)); } @@ -83,7 +85,7 @@ namespace pipecolors { end = s.end(); std::string len(s); - colors = getColors(); + colorMap colors = getColors(); while(regex_search(start, end, match, re, flags)) { @@ -112,6 +114,7 @@ namespace pipecolors { char * buffer; va_list args; int ret; + std::pair result; va_start(args, format); ret = vasprintf(&buffer, format, args); @@ -124,8 +127,9 @@ namespace pipecolors { std::string s(buffer); free(buffer); - std::pair result = replace_colors(s); - std::cout << result.first; + result = replace_colors(s); + + printf("%s", result.first.c_str()); return(result.second);