From 76f40de6268d3feca849794b440c6db87cb7d0d0 Mon Sep 17 00:00:00 2001 From: sk-5 Date: Tue, 7 Jul 2015 15:09:36 -0700 Subject: [PATCH] Fixes --- Makefile.am | 15 ++++++-- autogen.sh | 4 ++- configure.ac | 68 ++++++++++++++++++++++++++++++++----- examples/example2 | Bin 8904 -> 8904 bytes examples/example2.cpp | 2 +- libpipecolors.7 | 77 ++++++++++++++++-------------------------- libpipecolors.cpp | 30 +++++++--------- pcprintf.3 | 3 ++ 8 files changed, 121 insertions(+), 78 deletions(-) diff --git a/Makefile.am b/Makefile.am index 842f0ff..4509c67 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,19 +1,25 @@ pkgconfig_DATA = libpipecolors.pc +AM_LDFLAGS = $(LDFLAGS) + ACLOCAL_AMFLAGS = -I m4 -I config LIBTOOL_DEPS = @LIBTOOL_DEPS@ -libtool: $(LIBTOOL_DEPS) - $(SHELL) ./config.status libtool - lib_LTLIBRARIES = libpipecolors.la libpipecolors_la_SOURCES = libpipecolors.cpp libpipecolors_la_LIBS = -lboost_regex libpipecolors_la_CFLAGS = -fPIC -DPIC -pthread + +if PC_REMOVE_INVALID +AM_CPPFLAGS = -DPC_REMOVE_INVALID +endif + + libpipecolors_la_LDFLAGS = -module \ -release ${PIPECOLORS_VERSION} include_HEADERS = pipecolors.h +noinst_HEADERS = config.h man_MANS = libpipecolors.7 pcprintf.3 @@ -44,3 +50,6 @@ 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 + +libtool: $(LIBTOOL_DEPS) + $(SHELL) ./config.status libtool diff --git a/autogen.sh b/autogen.sh index 5e46be5..6801d1f 100755 --- a/autogen.sh +++ b/autogen.sh @@ -2,6 +2,8 @@ set -x +test -f configure && autoreconf -i && exit 0 || + test -d autom4te.cache && rm -rf autom4te.cache test -d config && rm -rf config mkdir config || exit 1 @@ -9,4 +11,4 @@ libtoolize --install --copy || exit 1 aclocal -I config || exit 1 autoheader || exit 1 autoconf || exit 1 -automake --add-missing --copy || exit 1 +automake --add-missing --copy || exit 1 \ No newline at end of file diff --git a/configure.ac b/configure.ac index 0132f6a..7d92a90 100644 --- a/configure.ac +++ b/configure.ac @@ -14,7 +14,6 @@ m4_define([pipecolors_version], AC_INIT([pipecolors], [pipecolors_version]) -PKG_PROG_PKG_CONFIG AC_SUBST(PIPECOLORS_VERSION_BASE, pipecolors_version_base) AC_SUBST(PIPECOLORS_VERSION_BETA, pipecolors_version_beta) @@ -28,11 +27,14 @@ PKG_INSTALLDIR AC_CONFIG_SRCDIR([libpipecolors.cpp]) 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_SILENT_RULES AC_GNU_SOURCE -AC_CANONICAL_HOST AC_PROG_INSTALL AC_PROG_CXXCPP AM_PROG_AR @@ -60,23 +62,73 @@ if test "${gcc_minor_vers}" -lt 9; then 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.])]) -AC_CHECK_LIB([boost_regex], [main]) -AC_CHECK_FUNCS([vasprintf]) -AC_CHECK_TYPE([size_t]) +AC_CHECK_LIB([boost_regex], [main], [], [AC_MSG_ERROR([Please install the libboost-regex libs on your system.])]) + AC_CHECK_TYPES([std::string], [], [], [[ #include #include ]]) +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_ARG_ENABLE([the-force], [AC_HELP_STRING([--enable-the-force], [use the force [default=no]])], [], [enable_the_force=no]) AM_CONDITIONAL([ENABLE_THE_FORCE], [test "x$enable_the_force" = "xyes"]) -AC_CONFIG_FILES([Makefile libpipecolors.pc:libpipecolors.pc.in],[],[APIVERSION=PIPECOLORS_VERSION]) + +AC_CONFIG_FILES([Makefile libpipecolors.pc:libpipecolors.pc.in libpipecolors.h:libpipecolors.h.in],[],[APIVERSION=PIPECOLORS_VERSION]) AC_CONFIG_COMMANDS([timestamp], [date >timestamp]) AC_OUTPUT + +resetc=$(tput sgr0); +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 + +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 be filtered + ${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 diff --git a/examples/example2 b/examples/example2 index 109f910add16ce5bf89e73e16fd3a96a46f91814..c25205039d39b5f3192d894222eb06c6e7435d2e 100755 GIT binary patch delta 63 zcmV-F0KosqMaV_4gaQ;SUIk3zp3UBS_WARIxCbX^fXubCm;!nR5il_&b0B;)F?=vN VC1iXvISR8Q2?Z7bB(o_Wp967>7mNS^ delta 63 zcmV-F0KosqMaV_4gaQ;>>GJI2Y}lnBcHF?OyG4J`{BY#6m;!nR5i~F*b0B;$H6>(x VGdT(X006Ti2?Z7bA+sqTp99cI7~cQ@ diff --git a/examples/example2.cpp b/examples/example2.cpp index 8990b86..252f45c 100644 --- a/examples/example2.cpp +++ b/examples/example2.cpp @@ -8,7 +8,7 @@ int main(void) { int num = 5; const char* str = "My number is"; - pcprintf("|40%s |05%d|39\n", str, num); + pcprintf("|01%s |41|09%d|39\n", str, num); return 0; } \ No newline at end of file diff --git a/libpipecolors.7 b/libpipecolors.7 index 7d15bb1..6550a90 100644 --- a/libpipecolors.7 +++ b/libpipecolors.7 @@ -1,60 +1,41 @@ -.\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk -.\" +.\" Copyright (c) 2015 Eric Wheeler (eric@rewiv.com) .\" -.\" %%%LICENSE_START(VERBATIM) -.\" Permission is granted to make and distribute verbatim copies of this -.\" manual provided the copyright notice and this permission notice are -.\" preserved on all copies. +.\" %%%LICENSE_START(GPLv2+_DOC_FULL) +.\" This is free documentation; you can redistribute it and/or +.\" modify it under the terms of the GNU General Public License as +.\" published by the Free Software Foundation; either version 2 of +.\" the License, or (at your option) any later version. .\" -.\" Permission is granted to copy and distribute modified versions of this -.\" manual under the conditions for verbatim copying, provided that the -.\" entire resulting derived work is distributed under the terms of a -.\" permission notice identical to this one. +.\" The GNU General Public License's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. .\" -.\" Since the Linux kernel and libraries are constantly changing, this -.\" manual page may be incorrect or out-of-date. The author(s) assume no -.\" responsibility for errors or omissions, or for damages resulting from -.\" the use of the information contained herein. The author(s) may not -.\" have taken the same level of care in the production of this manual, -.\" which is licensed free of charge, as they might when working -.\" professionally. +.\" This manual 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 General Public License for more details. .\" -.\" Formatted or processed versions of this manual, if unaccompanied by -.\" the source, must acknowledge the copyright and authors of this work. +.\" You should have received a copy of the GNU General Public +.\" License along with this manual; if not, see +.\" . .\" %%%LICENSE_END .\" -.TH LIBPIPECOLORS 7 2015-07-01 "Linux" "libpipecolors" +.\" 2015-07-06 eric@rewiv.com \- initial program +.\" +.TH libpipecolors 3 2015-07-06 "LIBPIPECOLORS" "libpipecolors c++/c library" .SH NAME libpipecolors \- print old bbs/renegade style pipecodes in c/c++ +.SH SYNOPSIS +.B #include +.sp +.B using namespace pipecolors; .SH DESCRIPTION +\fIlibpipecolors\fR is a library that parses a string with pipe color codes \fB|01\fR and replaces them with ansi color codes for the linux terminal. +.SS On the web +.PR +https://github.com/sk-5/libpipecolors/ -.I libpipecolors -is a library that parses a string with pipe color codes -.B |01 -and replaces them with ansi color codes for the linux terminal. -.SS Other C libraries -.UR http://www.uclibc.org/ -.I uClibc -.UE , -.UR http://www.fefe.de/dietlibc/ -.I dietlibc -.UE , -and -.UR http://www.musl-libc.org/ -.I "musl libc" -.UE . -Details of these libraries are covered by the -.I man-pages -project, where they are known. .SH SEE ALSO .BR pcprintf (3), -.BR pcsprintf (3), -.SH COLOPHON -This page is part of release 0.1 of -.I libpipecolors -. -A description of the project, -information about reporting bugs, -and the latest version of this page, -can be found at -\%https://github.com/sk-5/libpipecolors/. +.BR pcsprintf (3) diff --git a/libpipecolors.cpp b/libpipecolors.cpp index 64e4937..fd903df 100644 --- a/libpipecolors.cpp +++ b/libpipecolors.cpp @@ -18,6 +18,11 @@ * 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 #include #include @@ -69,8 +74,6 @@ namespace pipecolors { using namespace boost; - std::size_t index; - regex re( "(\\|\\d\\d)" ); match_results match; match_flag_type flags = boost::match_default; @@ -83,24 +86,17 @@ namespace pipecolors { while(regex_search(start, end, match, re, flags)) { + if(colors[match[0]].empty() && PC_REMOVE_INVALID == false) goto skip; + 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()); + } - - //while ((index = s.find(match[0])) != std::string::npos) - //{ - if(has_colors() && !colors[match[0]].empty()) { - //if(colors[match[0]].empty()) continue; - s.replace(s.find(match[0]), match[0].length(), colors[match[0]]); - } else { - //if(colors[match[0]].empty()) continue; - s.erase(s.find(match[0]), match[0].length()); - } - //} - + skip:; start = match[0].second; - // update flags: - flags |= boost::match_prev_avail; - flags |= boost::match_not_bob; + flags |= boost::match_prev_avail | boost::match_not_bob; } return(s); } diff --git a/pcprintf.3 b/pcprintf.3 index 8736fb9..6650885 100644 --- a/pcprintf.3 +++ b/pcprintf.3 @@ -30,6 +30,8 @@ pcsprintf \- convert pipecode (|10) to ansi colors .SH SYNOPSIS .B #include .sp +.B using namespace pipecolors; +.sp .BI "int pcprintf(const char *" format ", ...);" .br .BI "int pcsprintf(char *" str ", const char *" format ", ...);" @@ -117,6 +119,7 @@ This would print \fBMy Number is\fR in dark green and \fI5\fR in light green. The final code \fB|39\fR resets to the default color. .fi .SH SEE ALSO +.BR libpipecolors (7), .BR printf (3), .BR sprintf (3), .BR vprintf (3),