Removed std::map requirement
This commit is contained in:
parent
24bbfed64d
commit
1c5e2e8645
|
@ -6,7 +6,7 @@ ACLOCAL_AMFLAGS = -I m4 -I config
|
|||
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||
|
||||
lib_LTLIBRARIES = libpipecolors.la
|
||||
libpipecolors_la_SOURCES = libpipecolors.cpp
|
||||
libpipecolors_la_SOURCES = libpipecolors.cc
|
||||
libpipecolors_la_LIBS = -lboost_regex
|
||||
libpipecolors_la_CFLAGS = -fPIC -DPIC -pthread
|
||||
|
||||
|
@ -14,11 +14,7 @@ if PC_REMOVE_INVALID
|
|||
AM_CPPFLAGSINVALID = -DPC_REMOVE_INVALID
|
||||
endif
|
||||
|
||||
if BUILD_WITH_BTREE
|
||||
AM_CPPFLAGSBTREE = -DBUILD_WITH_BTREE -std=c++11
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS = $(AM_CPPFLAGSBTREE) $(AM_CPPFLAGSINVALID) -std=c++11
|
||||
AM_CPPFLAGS = $(AM_CPPFLAGSINVALID)
|
||||
|
||||
libpipecolors_la_LDFLAGS = -module \
|
||||
-release ${PIPECOLORS_VERSION}
|
||||
|
|
108
configure.ac
108
configure.ac
|
@ -4,34 +4,27 @@
|
|||
AC_PREREQ([2.69])
|
||||
|
||||
m4_define([pipecolors_version_major],[0])
|
||||
m4_define([pipecolors_version_minor],[1])
|
||||
m4_define([pipecolors_version_minor],[2])
|
||||
m4_define([pipecolors_version_micro],[0])
|
||||
m4_define([pipecolors_version_beta], [])
|
||||
|
||||
m4_define([pipecolors_version_base], [pipecolors_version_major.pipecolors_version_minor.pipecolors_version_micro])
|
||||
m4_define([pipecolors_version],
|
||||
[ifelse(pipecolors_version_beta, [], [pipecolors_version_base], [pipecolors_version_base.pipecolors_version_beta])])
|
||||
m4_define([pipecolors_version], [pipecolors_version_major.pipecolors_version_minor.pipecolors_version_micro])
|
||||
|
||||
AC_INIT([pipecolors], [pipecolors_version])
|
||||
|
||||
|
||||
AC_SUBST(PIPECOLORS_VERSION_BASE, pipecolors_version_base)
|
||||
AC_SUBST(PIPECOLORS_VERSION_BETA, pipecolors_version_beta)
|
||||
|
||||
AC_SUBST([PIPECOLORS_VERSION_MAJOR], [pipecolors_version_major])
|
||||
AC_SUBST([PIPECOLORS_VERSION_MINOR], [pipecolors_version_minor])
|
||||
AC_SUBST([PIPECOLORS_VERSION_MICRO], [pipecolors_version_micro])
|
||||
AC_SUBST([PIPECOLORS_VERSION], [pipecolors_version])
|
||||
|
||||
PKG_INSTALLDIR
|
||||
AC_CONFIG_SRCDIR([libpipecolors.cpp])
|
||||
AC_CONFIG_SRCDIR([libpipecolors.cc])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_AUX_DIR([config])
|
||||
AC_CANONICAL_TARGET
|
||||
AC_CANONICAL_HOST
|
||||
AC_CANONICAL_BUILD
|
||||
PKG_PROG_PKG_CONFIG
|
||||
AM_INIT_AUTOMAKE([gnu dist-bzip2 dist-zip std-options])
|
||||
AM_INIT_AUTOMAKE([gnu dist-bzip2 dist-zip])
|
||||
|
||||
AM_SILENT_RULES
|
||||
AC_GNU_SOURCE
|
||||
|
@ -50,18 +43,6 @@ AC_PREFIX_DEFAULT([/usr])
|
|||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_SUBST([LIBTOOL_DEPS])
|
||||
|
||||
gcc_full_vers=`g++ -dumpversion`
|
||||
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.`
|
||||
|
||||
|
||||
#AC_MSG_CHECKING([${CXX-c++} version])
|
||||
#if test "${gcc_minor_vers}" -lt 9; then
|
||||
# AC_MSG_ERROR([GCC >= 4.9 is required, you have version ${gcc_full_vers}])
|
||||
#else
|
||||
# AC_MSG_RESULT([${gcc_full_vers} ... acceptable])
|
||||
#fi
|
||||
AC_CHECK_FUNCS([vasprintf], [], [AC_MSG_ERROR([Why don't you have this? Install basic c++ header files.])])
|
||||
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.])])
|
||||
|
@ -82,51 +63,6 @@ AM_COND_IF([PC_REMOVE_INVALID],
|
|||
[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_CXX_ARGUMENT([-std=c++11])
|
||||
|
||||
AC_CHECK_TOOL([MERCURIAL], [hg], [no])
|
||||
|
||||
|
||||
if test "x${MERCURIAL}" = "xhg"; then
|
||||
have_hg_bin=1
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for ${srcdir}/cpp-btree/btree_map.h])
|
||||
|
||||
if test -f ${srcdir}/cpp-btree/btree_map.h; then
|
||||
have_btree_h=1
|
||||
AC_MSG_RESULT([found.])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
if test "x$have_btree_h" = "x1"; then
|
||||
AC_VERBOSE([Using already existing btree.])
|
||||
AM_CONDITIONAL([BUILD_WITH_BTREE], [true])
|
||||
elif test "x$have_hg_bin" = "x1"; then
|
||||
AC_VERBOSE([
|
||||
* Downloading btree headers with mercurial
|
||||
])
|
||||
|
||||
$(which hg) clone https://code.google.com/p/cpp-btree/
|
||||
AM_CONDITIONAL([BUILD_WITH_BTREE], [true])
|
||||
else
|
||||
AC_VERBOSE([
|
||||
* Could not find hg in your 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])
|
||||
|
@ -142,38 +78,30 @@ green=$(tput bold; tput setaf 2)
|
|||
blue=$(tput bold; tput setaf 4)
|
||||
cyan=$(tput bold; tput setaf 6)
|
||||
white=$(tput bold; tput setaf 7)
|
||||
|
||||
|
||||
if test "x$disable_pipe_stripping" == "xno" ; then
|
||||
under=$(tput smul)
|
||||
underoff=$(tput rmul)
|
||||
|
||||
cat << EOF
|
||||
|
||||
${reset}
|
||||
${resetc}
|
||||
${green}* ${white}Prefix ${resetc}: ${cyan}${prefix}
|
||||
${green}* ${white}Exec Prefix ${resetc}: ${cyan}${exec_prefix}
|
||||
${green}* ${white}Library ${resetc}: ${cyan}${libdir}
|
||||
${green}* ${white}Include ${resetc}: ${cyan}${includedir}
|
||||
${green}* ${resetc}Configure finished type '${cyan}make${resetc}' to build and '${cyan}make install${resetc}' to install.
|
||||
${green}* ${resetc}Invalid pipe codes will be filtered
|
||||
EOF
|
||||
if test "x$disable_pipe_stripping" == "xno" ; then
|
||||
cat << EOF
|
||||
${green}* ${resetc}Invalid pipe codes ${white}${under}will${resetc}${underoff} be filtered.
|
||||
EOF
|
||||
else
|
||||
cat << EOF
|
||||
${green}* ${resetc}Invalid pipe codes ${white}${under}will not${resetc}${underoff} be filtered.
|
||||
EOF
|
||||
fi
|
||||
cat << EOF
|
||||
${green}* ${resetc} e.g. ('${white}|41${resetc}Hello World' will show as 'Hello World' instead of '${white}|41${resetc}Hello World')
|
||||
${green}* ${resetc} You can change this behavior by using the ${white}--disable-pipe-stripping ${resetc}configure flag.
|
||||
|
||||
EOF
|
||||
|
||||
else
|
||||
|
||||
cat << EOF
|
||||
|
||||
${reset}
|
||||
${green}* ${white}Prefix ${resetc}: ${cyan}${prefix}
|
||||
${green}* ${white}Exec Prefix ${resetc}: ${cyan}${exec_prefix}
|
||||
${green}* ${white}Library ${resetc}: ${cyan}${libdir}
|
||||
${green}* ${white}Include ${resetc}: ${cyan}${includedir}
|
||||
${green}* ${resetc}Configure finished type '${cyan}make${resetc}' to build and '${cyan}make install${resetc}' to install.
|
||||
${green}* ${resetc}Invalid pipe codes will not be filtered.
|
||||
${green}* ${resetc} e.g. ('${white}|41${resetc}Hello World' will show as '${white}|41${resetc}Hello World' instead of 'Hello World')
|
||||
${green}* ${resetc} You can change this behavior by removing the ${white}--disable-pipe-stripping ${resetc}configure flag.
|
||||
|
||||
EOF
|
||||
|
||||
fi
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <pipecolors.h>
|
||||
|
||||
#include <climits>
|
||||
using namespace pipecolors;
|
||||
|
||||
int main(void) {
|
||||
|
||||
char buffer[256];
|
||||
char buffer[UCHAR_MAX];
|
||||
int num = 5;
|
||||
const char* str = "My number is";
|
||||
const char* str2 = "|10My number is|07";
|
||||
int len = pcprintf("|01%s |09%d|39\n", str, num);
|
||||
const char* str2 = "|03My number is|11|30";
|
||||
int len = pcprintf("|01%s |41|09|30%d|39\n", str, num);
|
||||
pcprintf("|10Length of Len is : |15|30%d\n|07", len);
|
||||
int len2 = pcsprintf(buffer, "%s %d\n", str2, num);
|
||||
printf("\n%s %d\n", buffer, len2);
|
||||
int len2 = pcsprintf(buffer, "%s %d|39\n", str2, num);
|
||||
printf("%s", buffer);
|
||||
pcprintf("|10Length of Len2 is : |15|30%d\n|07", len2);
|
||||
return 0;
|
||||
}
|
|
@ -23,7 +23,7 @@
|
|||
.\"
|
||||
.\" 2015-07-06 eric@rewiv.com \- initial program
|
||||
.\"
|
||||
.TH libpipecolors 3 2015-07-06 "LIBPIPECOLORS" "libpipecolors c++/c library"
|
||||
.TH libpipecolors 3 2015-07-15 "LIBPIPECOLORS" "libpipecolors c++/c library"
|
||||
.SH NAME
|
||||
libpipecolors \- print old bbs/renegade style pipecodes in c/c++
|
||||
.SH SYNOPSIS
|
||||
|
|
|
@ -1,168 +0,0 @@
|
|||
/*
|
||||
* libpipecolors: linux color code library
|
||||
*
|
||||
* Authors:
|
||||
* Eric Wheeler <eric@ericwheeler.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PC_REMOVE_INVALID
|
||||
#define PC_REMOVE_INVALID false
|
||||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <boost/regex.hpp>
|
||||
#include "pipecolors.h"
|
||||
|
||||
namespace pipecolors {
|
||||
|
||||
#ifndef BUILD_WITH_BTREE
|
||||
#include <map>
|
||||
typedef std::map<std::string, std::string> colorMap;
|
||||
#else
|
||||
#include "cpp-btree/btree_map.h"
|
||||
typedef btree::btree_map<std::string, std::string> colorMap;
|
||||
#endif
|
||||
|
||||
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;
|
||||
colors["|03"] = "\x1b[0;36m"; // FG_CYAN;
|
||||
colors["|04"] = "\x1b[0;31m"; // FG_RED;
|
||||
colors["|05"] = "\x1b[0;35m"; // FG_MAGENTA;
|
||||
colors["|06"] = "\x1b[0;33m"; // FG_YELLOW;
|
||||
colors["|07"] = "\x1b[0;37m"; // FG_GRAY;
|
||||
colors["|08"] = "\x1b[0;90m"; // FG_GRAY_D;
|
||||
colors["|09"] = "\x1b[0;94m"; // FG_BLUE_L;
|
||||
colors["|10"] = "\x1b[0;92m"; // FG_GREEN_L;
|
||||
colors["|11"] = "\x1b[0;96m"; // FG_CYAN_L;
|
||||
colors["|12"] = "\x1b[0;91m"; // FG_RED_L;
|
||||
colors["|13"] = "\x1b[0;95m"; // FG_MAGENTA_L;
|
||||
colors["|14"] = "\x1b[0;93m"; // FG_YELLOW_L;
|
||||
colors["|15"] = "\x1b[0;97m"; // FG_WHITE;
|
||||
colors["|16"] = "\x1b[1;40m"; // BG_DEFAULT;
|
||||
colors["|17"] = "\x1b[1;44m"; // BG_BLUE;
|
||||
colors["|18"] = "\x1b[1;42m"; // BG_GREEN;
|
||||
colors["|19"] = "\x1b[1;46m"; // BG_CYAN;
|
||||
colors["|20"] = "\x1b[1;41m"; // BG_RED;
|
||||
colors["|21"] = "\x1b[1;45m"; // BG_MAGENTA;
|
||||
colors["|22"] = "\x1b[1;43m"; // BG_YELLOW;
|
||||
colors["|23"] = "\x1b[1;47m"; // BG_WHITE;
|
||||
colors["|30"] = "\x1b[1m"; // Bold ON
|
||||
colors["|31"] = "\x1b[0m"; // Bold OFF
|
||||
colors["|39"] = "\x1b[0;39m"; // FG_DEFAULT
|
||||
return colors;
|
||||
}
|
||||
|
||||
bool has_colors(void) {
|
||||
return isatty(fileno(stdout));
|
||||
}
|
||||
|
||||
std::pair<std::string,int> replace_colors( std::string s) {
|
||||
|
||||
using namespace boost;
|
||||
|
||||
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();
|
||||
std::string len(s);
|
||||
|
||||
|
||||
colorMap colors = getColors();
|
||||
|
||||
|
||||
while(regex_search(start, end, match, re, flags))
|
||||
{
|
||||
|
||||
if(colors[match[0]].empty() && PC_REMOVE_INVALID == false) goto skip;
|
||||
|
||||
len.erase(len.find(match[0]), match[0].length());
|
||||
|
||||
if(has_colors() && !colors[match[0]].empty()) {
|
||||
s.replace(s.find(match[0]), match[0].length(), colors[match[0]]);
|
||||
} else {
|
||||
s.erase(s.find(match[0]), match[0].length());
|
||||
}
|
||||
|
||||
skip:;
|
||||
start = match[0].second;
|
||||
flags |= boost::match_prev_avail | boost::match_not_bob;
|
||||
}
|
||||
|
||||
return std::make_pair(s, len.length());
|
||||
|
||||
}
|
||||
|
||||
int pcprintf( const char * format, ...)
|
||||
{
|
||||
char * buffer;
|
||||
va_list args;
|
||||
int ret;
|
||||
std::pair<std::string, int> result;
|
||||
|
||||
va_start(args, format);
|
||||
ret = vasprintf(&buffer, format, args);
|
||||
va_end(args);
|
||||
if(ret == -1) {
|
||||
free(buffer);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string s(buffer);
|
||||
free(buffer);
|
||||
|
||||
result = replace_colors(s);
|
||||
|
||||
printf("%s", result.first.c_str());
|
||||
|
||||
return(result.second);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int pcsprintf( char * str, const char * format, ... ) {
|
||||
|
||||
int ret;
|
||||
std::cout << sizeof(str);
|
||||
char** str1 = (char**)str;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
ret = vasprintf(str1, format, args);
|
||||
va_end(args);
|
||||
|
||||
if(ret == -1) {
|
||||
free(str1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string s(*str1);
|
||||
free(*str1);
|
||||
std::pair<std::string, int> result = replace_colors(s);
|
||||
const char * s2 = (const char *)result.first.c_str();
|
||||
strcpy(str, s2);
|
||||
return result.second;
|
||||
}
|
||||
} // namespace
|
|
@ -23,7 +23,7 @@
|
|||
.\"
|
||||
.\" 2015-07-06 eric@rewiv.com \- initial program
|
||||
.\"
|
||||
.TH pcprintf 3 2015-07-06 "LIBPIPECOLORS" "Using pcprintf to print colors"
|
||||
.TH pcprintf 3 2015-07-15 "LIBPIPECOLORS" "Using pcprintf to print colors"
|
||||
.SH NAME
|
||||
pcprintf,
|
||||
pcsprintf \- convert pipecode (|10) to ansi colors
|
||||
|
|
Loading…
Reference in New Issue