Fixes
This commit is contained in:
parent
d5aa7198a9
commit
76f40de626
15
Makefile.am
15
Makefile.am
|
@ -1,19 +1,25 @@
|
||||||
pkgconfig_DATA = libpipecolors.pc
|
pkgconfig_DATA = libpipecolors.pc
|
||||||
|
|
||||||
|
AM_LDFLAGS = $(LDFLAGS)
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4 -I config
|
ACLOCAL_AMFLAGS = -I m4 -I config
|
||||||
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||||
|
|
||||||
libtool: $(LIBTOOL_DEPS)
|
|
||||||
$(SHELL) ./config.status libtool
|
|
||||||
|
|
||||||
lib_LTLIBRARIES = libpipecolors.la
|
lib_LTLIBRARIES = libpipecolors.la
|
||||||
libpipecolors_la_SOURCES = libpipecolors.cpp
|
libpipecolors_la_SOURCES = libpipecolors.cpp
|
||||||
libpipecolors_la_LIBS = -lboost_regex
|
libpipecolors_la_LIBS = -lboost_regex
|
||||||
libpipecolors_la_CFLAGS = -fPIC -DPIC -pthread
|
libpipecolors_la_CFLAGS = -fPIC -DPIC -pthread
|
||||||
|
|
||||||
|
if PC_REMOVE_INVALID
|
||||||
|
AM_CPPFLAGS = -DPC_REMOVE_INVALID
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
libpipecolors_la_LDFLAGS = -module \
|
libpipecolors_la_LDFLAGS = -module \
|
||||||
-release ${PIPECOLORS_VERSION}
|
-release ${PIPECOLORS_VERSION}
|
||||||
|
|
||||||
include_HEADERS = pipecolors.h
|
include_HEADERS = pipecolors.h
|
||||||
|
noinst_HEADERS = config.h
|
||||||
|
|
||||||
man_MANS = libpipecolors.7 pcprintf.3
|
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 -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 -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
|
test -f $(mandir)/man7/libpipecolors.7.gz && rm -f /usr/share/man/man7/libpipecolors.7.gz
|
||||||
|
|
||||||
|
libtool: $(LIBTOOL_DEPS)
|
||||||
|
$(SHELL) ./config.status libtool
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
test -f configure && autoreconf -i && exit 0 ||
|
||||||
|
|
||||||
test -d autom4te.cache && rm -rf autom4te.cache
|
test -d autom4te.cache && rm -rf autom4te.cache
|
||||||
test -d config && rm -rf config
|
test -d config && rm -rf config
|
||||||
mkdir config || exit 1
|
mkdir config || exit 1
|
||||||
|
|
68
configure.ac
68
configure.ac
|
@ -14,7 +14,6 @@ m4_define([pipecolors_version],
|
||||||
|
|
||||||
AC_INIT([pipecolors], [pipecolors_version])
|
AC_INIT([pipecolors], [pipecolors_version])
|
||||||
|
|
||||||
PKG_PROG_PKG_CONFIG
|
|
||||||
|
|
||||||
AC_SUBST(PIPECOLORS_VERSION_BASE, pipecolors_version_base)
|
AC_SUBST(PIPECOLORS_VERSION_BASE, pipecolors_version_base)
|
||||||
AC_SUBST(PIPECOLORS_VERSION_BETA, pipecolors_version_beta)
|
AC_SUBST(PIPECOLORS_VERSION_BETA, pipecolors_version_beta)
|
||||||
|
@ -28,11 +27,14 @@ PKG_INSTALLDIR
|
||||||
AC_CONFIG_SRCDIR([libpipecolors.cpp])
|
AC_CONFIG_SRCDIR([libpipecolors.cpp])
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AC_CONFIG_AUX_DIR([config])
|
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 std-options])
|
||||||
|
|
||||||
AM_SILENT_RULES
|
AM_SILENT_RULES
|
||||||
AC_GNU_SOURCE
|
AC_GNU_SOURCE
|
||||||
AC_CANONICAL_HOST
|
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
AC_PROG_CXXCPP
|
AC_PROG_CXXCPP
|
||||||
AM_PROG_AR
|
AM_PROG_AR
|
||||||
|
@ -60,23 +62,73 @@ if test "${gcc_minor_vers}" -lt 9; then
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT([${gcc_full_vers} ... acceptable])
|
AC_MSG_RESULT([${gcc_full_vers} ... acceptable])
|
||||||
fi
|
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_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_HEADER([boost/regex.hpp],[],[AC_MSG_ERROR([Please install the libboost-regex header library.])])
|
||||||
AC_CHECK_LIB([boost_regex], [main])
|
AC_CHECK_LIB([boost_regex], [main], [], [AC_MSG_ERROR([Please install the libboost-regex libs on your system.])])
|
||||||
AC_CHECK_FUNCS([vasprintf])
|
|
||||||
AC_CHECK_TYPE([size_t])
|
|
||||||
|
|
||||||
AC_CHECK_TYPES([std::string], [], [], [[
|
AC_CHECK_TYPES([std::string], [], [], [[
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
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_ARG_ENABLE([the-force],
|
||||||
[AC_HELP_STRING([--enable-the-force], [use the force [default=no]])],
|
[AC_HELP_STRING([--enable-the-force], [use the force [default=no]])],
|
||||||
[], [enable_the_force=no])
|
[], [enable_the_force=no])
|
||||||
AM_CONDITIONAL([ENABLE_THE_FORCE], [test "x$enable_the_force" = "xyes"])
|
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_CONFIG_COMMANDS([timestamp], [date >timestamp])
|
||||||
AC_OUTPUT
|
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
|
||||||
|
|
Binary file not shown.
|
@ -8,7 +8,7 @@ int main(void) {
|
||||||
|
|
||||||
int num = 5;
|
int num = 5;
|
||||||
const char* str = "My number is";
|
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;
|
return 0;
|
||||||
}
|
}
|
|
@ -1,60 +1,41 @@
|
||||||
.\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
|
.\" Copyright (c) 2015 Eric Wheeler (eric@rewiv.com)
|
||||||
.\" <mtk.manpages@gmail.com>
|
|
||||||
.\"
|
.\"
|
||||||
.\" %%%LICENSE_START(VERBATIM)
|
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
|
||||||
.\" Permission is granted to make and distribute verbatim copies of this
|
.\" This is free documentation; you can redistribute it and/or
|
||||||
.\" manual provided the copyright notice and this permission notice are
|
.\" modify it under the terms of the GNU General Public License as
|
||||||
.\" preserved on all copies.
|
.\" 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
|
.\" The GNU General Public License's references to "object code"
|
||||||
.\" manual under the conditions for verbatim copying, provided that the
|
.\" and "executables" are to be interpreted as the output of any
|
||||||
.\" entire resulting derived work is distributed under the terms of a
|
.\" document formatting or typesetting system, including
|
||||||
.\" permission notice identical to this one.
|
.\" intermediate and printed output.
|
||||||
.\"
|
.\"
|
||||||
.\" Since the Linux kernel and libraries are constantly changing, this
|
.\" This manual is distributed in the hope that it will be useful,
|
||||||
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
.\" responsibility for errors or omissions, or for damages resulting from
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
.\" the use of the information contained herein. The author(s) may not
|
.\" GNU General Public License for more details.
|
||||||
.\" 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.
|
|
||||||
.\"
|
.\"
|
||||||
.\" Formatted or processed versions of this manual, if unaccompanied by
|
.\" You should have received a copy of the GNU General Public
|
||||||
.\" the source, must acknowledge the copyright and authors of this work.
|
.\" License along with this manual; if not, see
|
||||||
|
.\" <http://www.gnu.org/licenses/>.
|
||||||
.\" %%%LICENSE_END
|
.\" %%%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
|
.SH NAME
|
||||||
libpipecolors \- print old bbs/renegade style pipecodes in c/c++
|
libpipecolors \- print old bbs/renegade style pipecodes in c/c++
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B #include <pipecolors.h>
|
||||||
|
.sp
|
||||||
|
.B using namespace pipecolors;
|
||||||
.SH DESCRIPTION
|
.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
|
.SH SEE ALSO
|
||||||
.BR pcprintf (3),
|
.BR pcprintf (3),
|
||||||
.BR pcsprintf (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/.
|
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* 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 <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -69,8 +74,6 @@ namespace pipecolors {
|
||||||
|
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
std::size_t index;
|
|
||||||
|
|
||||||
regex re( "(\\|\\d\\d)" );
|
regex re( "(\\|\\d\\d)" );
|
||||||
match_results<std::string::const_iterator> match;
|
match_results<std::string::const_iterator> match;
|
||||||
match_flag_type flags = boost::match_default;
|
match_flag_type flags = boost::match_default;
|
||||||
|
@ -83,24 +86,17 @@ namespace pipecolors {
|
||||||
|
|
||||||
while(regex_search(start, end, match, re, flags))
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
skip:;
|
||||||
//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());
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
|
|
||||||
start = match[0].second;
|
start = match[0].second;
|
||||||
// update flags:
|
flags |= boost::match_prev_avail | boost::match_not_bob;
|
||||||
flags |= boost::match_prev_avail;
|
|
||||||
flags |= boost::match_not_bob;
|
|
||||||
}
|
}
|
||||||
return(s);
|
return(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ pcsprintf \- convert pipecode (|10) to ansi colors
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B #include <pipecolors.h>
|
.B #include <pipecolors.h>
|
||||||
.sp
|
.sp
|
||||||
|
.B using namespace pipecolors;
|
||||||
|
.sp
|
||||||
.BI "int pcprintf(const char *" format ", ...);"
|
.BI "int pcprintf(const char *" format ", ...);"
|
||||||
.br
|
.br
|
||||||
.BI "int pcsprintf(char *" str ", const char *" format ", ...);"
|
.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.
|
The final code \fB|39\fR resets to the default color.
|
||||||
.fi
|
.fi
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
|
.BR libpipecolors (7),
|
||||||
.BR printf (3),
|
.BR printf (3),
|
||||||
.BR sprintf (3),
|
.BR sprintf (3),
|
||||||
.BR vprintf (3),
|
.BR vprintf (3),
|
||||||
|
|
Loading…
Reference in New Issue