Removed boost requirement

This commit is contained in:
R. Eric Wheeler 2015-07-16 13:47:06 -07:00
parent 65ece9ac6c
commit 631e501393
7 changed files with 93 additions and 77 deletions

View File

@ -3,17 +3,17 @@
AC_PREREQ([2.69])
m4_define([pipecolors_version_major],[0])
m4_define([pipecolors_version_major],[1])
m4_define([pipecolors_version_minor],[2])
m4_define([pipecolors_version_micro],[1])
m4_define([pipecolors_version_patch],[0])
m4_define([pipecolors_version], [pipecolors_version_major.pipecolors_version_minor.pipecolors_version_micro])
m4_define([pipecolors_version], [pipecolors_version_major.pipecolors_version_minor.pipecolors_version_patch])
AC_INIT([pipecolors], [pipecolors_version])
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_PATCH], [pipecolors_version_patch])
AC_SUBST([PIPECOLORS_VERSION], [pipecolors_version])
PKG_INSTALLDIR
@ -47,13 +47,7 @@ AC_SUBST([LIBTOOL_DEPS])
AC_CHECK_FUNCS([vasprintf], [], [AC_MSG_ERROR([Why don't you have this? Install basic c++ header files.])])
# Check for Headers
AC_CHECK_HEADERS([cstdio iostream cstring cstdlib cstdarg],[],[AC_MSG_ERROR([We couldn't find one or more of the required headers.])])
# Check for boost_regex header
AC_CHECK_HEADER([boost/regex.hpp],[],[AC_MSG_ERROR([Please install the libboost-regex header library.])])
# Check that we can use boost_regex.so
AC_CHECK_LIB([boost_regex], [main], [], [AC_MSG_ERROR([Please install the libboost-regex libs on your system.])])
AC_CHECK_HEADERS([cstdio iostream cstring cstdlib cstdarg unistd.h],[],[AC_MSG_ERROR([We couldn't find one or more of the required headers.])])
AC_CHECK_TYPES([std::string], [], [], [[
@ -70,12 +64,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([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 src/Makefile man/Makefile src/libpipecolors.pc:src/libpipecolors.pc.in src/libpipecolors.h:src/libpipecolors.h.in],[],[APIVERSION=PIPECOLORS_VERSION])
AC_CONFIG_COMMANDS([timestamp], [date >timestamp])
AC_OUTPUT

1
dist/timestamp vendored
View File

@ -1 +0,0 @@
Tue Jul 14 17:47:22 PDT 2015

View File

@ -3,13 +3,23 @@
#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";
int main() {
a = pcprintf("\n%s\n\n", name);
b = pcprintf("%s\n", str);
char buffer[100];
int num = 5;
const char* str = "My number is";
const char* str2 = "|03My number is";
pcprintf("\n\n\t|01P|02i|03p|04e|05c|06ol|07o|08r|09s |10l|11i|12b|13r|14a|15r|14y |131|12.|112|10.|090|07 |15* |0101|0202|0303|0404|0505|0606|0707|0808|0909|1010|1111|1212|1313|1414|1515\n\n");
int len = pcprintf("\t|01%s |41|09|30%d|39 (pcprintf)\n", str, num);
pcprintf("\t|02Length of |15pcprintf |02is : |10|30%d|39 : We count escape characters just like printf\n", len);
int len2 = pcsprintf(buffer, "\t%s |11|30%d|39 (pcsprintf)\n", str2, num);
printf("%s", buffer);
pcprintf("\t|02Length of |15pcsprintf |02is : |10|30%d|39 : We count escape characters just like sprintf\n\n", len2);
return 0;
}

27
examples/example.cc Normal file
View File

@ -0,0 +1,27 @@
#include <cstdio>
#include <iostream>
#include <pipecolors.h>
using namespace pipecolors;
using namespace std;
int main(void) {
char buffer[100];
int num = 5;
const char* str = "My number is";
const char* str2 = "|03My number is";
pcprintf("\n\n\t|01P|02i|03p|04e|05c|06ol|07o|08r|09s |10l|11i|12b|13r|14a|15r|14y |131|12.|112|10.|090|07 |15* |0101|0202|0303|0404|0505|0606|0707|0808|0909|1010|1111|1212|1313|1414|1515\n\n");
int len = pcprintf("\t|01%s |41|09|30%d|39 (pcprintf)\n", str, num);
pcprintf("\t|02Length of |15pcprintf |02is : |10|30%d|39 : We count escape characters just like printf\n", len);
int len2 = pcsprintf(buffer, "\t%s |11|30%d|39 (pcsprintf)\n", str2, num);
printf("%s", buffer);
pcprintf("\t|02Length of |15pcsprintf |02is : |10|30%d|39 : We count escape characters just like sprintf\n\n", len2);
return 0;
}

View File

@ -1,19 +0,0 @@
#include <cstdio>
#include <iostream>
#include <pipecolors.h>
#include <climits>
using namespace pipecolors;
int main(void) {
char buffer[UCHAR_MAX];
int num = 5;
const char* str = "My number is";
const char* str2 = "|03My number is|11|30";
int len = pcprintf("|01%s |41|09|30%d|39\n", str, num);
pcprintf("|02Length of Len is : |10|30%d\n|07", len);
int len2 = pcsprintf(buffer, "%s %d|39\n", str2, num);
printf("%s", buffer);
pcprintf("|02Length of Len2 is : |10|30%d\n|07", len2);
return 0;
}

View File

@ -7,7 +7,7 @@ LIBTOOL_DEPS = @LIBTOOL_DEPS@
lib_LTLIBRARIES = libpipecolors.la
libpipecolors_la_SOURCES = libpipecolors.cc
libpipecolors_la_LIBS = -lboost_regex
#libpipecolors_la_LIBS = -lboost_regex
libpipecolors_la_CFLAGS = -fPIC -DPIC -pthread
if PC_REMOVE_INVALID

View File

@ -28,7 +28,7 @@
#include <cstring>
#include <cstdlib>
#include <cstdarg>
#include <boost/regex.hpp>
#include <unistd.h>
#include "pipecolors.h"
namespace pipecolors {
@ -38,7 +38,7 @@ namespace pipecolors {
char * buf;
int sret = asprintf(&buf, "%c%c", code[1], code[2]);
int pc = atoi( buf );
delete buf;
delete[] buf;
if(sret == -1) {
return "failure";
@ -82,38 +82,47 @@ namespace pipecolors {
return isatty(fileno(stdout));
}
std::pair<std::string,int> replace_colors( std::string s) {
void removePipe(std::pair<std::string,std::string> &str, std::string pipe) {
using namespace boost;
size_t index = 0;
regex re( "(\\|\\d\\d)" );
match_results<std::string::const_iterator> match;
match_flag_type flags = boost::match_default;
while( ( index = str.first.find(pipe, index) ) != std::string::npos ) {
std::string::const_iterator start, end;
start = s.begin();
end = s.end();
std::string len(s);
str.second.erase(str.second.find(pipe), pipe.length());
while(regex_search(start, end, match, re, flags))
{
if(ansi(pipe) == "nocode" && PC_REMOVE_INVALID == false) goto skip;
if(ansi(match[0].str()) == "nocode" && PC_REMOVE_INVALID == false) goto skip;
len.erase(len.find(match[0]), match[0].length());
if(has_colors() && ansi(match[0].str()) != "nocode") {
s.replace(s.find(match[0]), match[0].length(), ansi(match[0].str()) );
if(has_colors() && ansi(pipe) != "nocode") {
str.first.replace(index, pipe.length(), ansi(pipe) );
} else {
s.erase(s.find(match[0]), match[0].length());
str.first.erase(index, pipe.length());
}
skip:;
start = match[0].second;
flags |= boost::match_prev_avail | boost::match_not_bob;
index += std::string::npos;
}
return std::make_pair(s, len.length());
}
std::pair<std::string,int> replace_colors( std::string s ) {
char pcodes[99][4] = {};
std::pair <std::string,std::string> str = std::make_pair(s,s);
char * buf;
for(int c = 0; c<=99; c++) {
int len = ( c < 10 ? asprintf(&buf, "%c0%d", '|', c) : asprintf(&buf, "%c%d", '|', c) );
strcpy(pcodes[c], buf);
}
for(int i=0; i<=99; i++) {
removePipe(str, pcodes[i]);
}
std::pair <std::string,int> result = std::make_pair(str.first,str.second.length());
delete[] buf;
return result;
}
@ -121,21 +130,20 @@ namespace pipecolors {
{
char * buffer;
va_list args;
int ret;
std::pair<std::string, int> result;
va_start(args, format);
ret = vasprintf(&buffer, format, args);
int ret = vasprintf(&buffer, format, args);
va_end(args);
if(ret == -1) {
free(buffer);
exit(EXIT_FAILURE);
delete[] buffer;
exit(EXIT_FAILURE);
}
std::string s(buffer);
free(buffer);
delete[] buffer;
result = replace_colors(s);
result = replace_colors(s);
printf("%s", result.first.c_str());
@ -146,24 +154,27 @@ namespace pipecolors {
int pcsprintf( char * str, const char * format, ... ) {
int ret;
char** str1 = (char**)str;
va_list args;
va_start(args, format);
ret = vasprintf(str1, format, args);
int ret = vasprintf(str1, format, args);
va_end(args);
if(ret == -1) {
free(str1);
delete[] str1;
exit(EXIT_FAILURE);
}
std::string s(*str1);
free(*str1);
delete[] *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