Initial Commit

This commit is contained in:
R. Eric Wheeler 2015-07-01 07:44:53 -07:00
parent 1f08a3bf36
commit 6bc03baa3e
11 changed files with 1716 additions and 19 deletions

27
.gitignore vendored
View File

@ -15,22 +15,11 @@ robots.txt
/MAINTAINERS.txt
/UPGRADE.txt
/README.txt
sites/all/README.txt
sites/all/modules/README.txt
sites/all/themes/README.txt
# Ignore everything but the "sites" folder ( for non core developer )
.htaccess
web.config
authorize.php
cron.php
index.php
install.php
update.php
xmlrpc.php
/includes
/misc
/modules
/profiles
/scripts
/themes
.deps
config
/AUTHORS
Makefile
NEWS
pipecolors.pc
README
test

0
ChangeLog Normal file
View File

17
Makefile.am Executable file
View File

@ -0,0 +1,17 @@
pkgconfig_DATA = pipecolors.pc
AM_CXXFLAGS = -std=c++11 -fPIC -pipe
ACLOCAL_AMFLAGS = -I m4
LIBTOOL_DEPS = @LIBTOOL_DEPS@
libtool: $(LIBTOOL_DEPS)
$(SHELL) ./config.status libtool
pkginclude_HEADERS = pipecolors.h
soinclude_HEADERS = pipecolors.h
soincludedir = $(prefix)/include
sodir=$(libdir)
so_PROGRAMS = libpipecolors.so
libpipecolors_so_SOURCES = libpipecolors.cpp
libpipecolors_so_LDFLAGS = \
-shared \
-fPIC \
-Wl,-soname,libpipecolors.so.0.1

17
acinclude.m4 Normal file
View File

@ -0,0 +1,17 @@
AC_DEFUN([AC_CHECK_CXX_ARGUMENT], [
AC_MSG_CHECKING([if ${CXX-g++} supports argument $1])
OLD_CXX_FLAGS=$CXXFLAGS
CXXFLAGS="$1 $CXXFLAGS"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [])],
[AC_MSG_RESULT(yes)
if test "x$EXTRA_CXXFLAGS" = x; then
EXTRA_CXXFLAGS="$1"
AC_SUBST([EXTRA_CXXFLAGS])
else
EXTRA_CXXFLAGS="$1 $EXTRA_CXXFLAGS"
fi
ifelse([$2], , :, [$2])],
[AC_MSG_RESULT([no])
ifelse([$3], , :, [$3])])
CXXFLAGS=$OLD_CXX_FLAGS])

1371
aclocal.m4 vendored Normal file

File diff suppressed because it is too large Load Diff

10
autogen.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
set -x
test -d autom4te.cache && rm -rf autom4te.cache
libtoolize --install --copy || exit 1
aclocal -I config || exit 1
autoheader || exit 1
autoconf || exit 1
automake --add-missing --copy || exit 1

131
configure.ac Executable file
View File

@ -0,0 +1,131 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
m4_define([pipecolors_version_major],[0])
m4_define([pipecolors_version_minor],[1])
m4_define([pipecolors_version_micro],[0])
m4_define([pipecolors_version_beta], [1])
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])])
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)
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_HEADERS([config.h])
AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE([-Wall -Werror])
AC_GNU_SOURCE
AC_CANONICAL_HOST
AC_PROG_CXX
AC_PROG_CXX_C_O
AC_PROG_CXXCPP
AC_PROG_LIBTOOL
LT_INIT
AC_DISABLE_SHARED
AC_ENABLE_STATIC
AC_LANG_CPLUSPLUS
#AC_CHECK_LIB([pipecolors], [cprintf])
#PKG_CHECK_MODULES([LIBPIPECOLORS], [pipecolors])
# Checks for programs.
AM_CONDITIONAL(CXX, test "$CXX" = yes) # let the Makefile know if we're gcc
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.`
# Checks for functions
AC_CHECK_CXX_ARGUMENT([-std=c++11], [], [AC_MSG_ERROR([C++11 support is required.])])
AC_MSG_CHECKING([if ${CXX-c++} supports nullptr])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[],
[[
char *char_null = nullptr;
]])],
[AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_NULLPTR, 1,
[Define to 1 if the compiler supports the nullptr C++11 constant])],
[AC_MSG_RESULT(no)])
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_HEADER_STDC
AC_CHECK_FUNCS([vprintf vsprintf printf])
# Checks for libraries.
AC_CHECK_HEADERS([stdarg.h regex.h termcap.h])
AC_CHECK_LIB([termcap], [getenv], [termcap=yes], [termcap=no])
if test "${termcap}" = "no"; then
AC_MSG_ERROR([requirement not found : getenv in -ltermcap])
fi
AC_CHECK_TYPE([size_t])
AC_CHECK_TYPES([std::string], [], [], [[
#include <stdio.h>
#include <string>
#include <iostream>
]])
AC_ARG_WITH(arch,
AS_HELP_STRING([--with-arch=ARCH],
[On x86_64 systems, compile with -fno-omit-frame-pointer (see INSTALL)]))
if test z${with_arch} = "z"; then
AC_CHECK_PROG(ARCH_PROG, arch, "found", "no")
if test $ARCH_PROG = "no"; then
AC_CHECK_PROG(UNAME_PROG, uname, "found", "no")
if test $UNAME_PROG = "no"; then
AC_MSG_ERROR([Could not detect your architecture, please set --with-arch=ARCH.])
else
with_arch=`uname -i`
fi
else
with_arch=`arch`
fi
fi
AC_MSG_NOTICE([building for ${with_arch} platform])
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
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 pipecolors.pc:pipecolors.pc.in],[],[API_VERSION='0.1'])
AC_CONFIG_COMMANDS([default],[[]],[[]])
AC_OUTPUT

124
libpipecolors.cpp Executable file
View File

@ -0,0 +1,124 @@
#include <stdio.h>
#include <iostream>
#include <stdarg.h>
#include <stdlib.h>
#include <string>
#include <map>
#include <regex>
#include <termcap.h>
#include "pipecolors.h"
#define C_DEFAULT 0
#define C_BOLD 1
#define C_ITALIC 3
#define C_UNDERLINE 4
#define C_INVERT 7
#define C_B0 "\033[1m"
#define C_B1 "\033[0m"
#define C_FG_BLACK "\033[0;30m"
#define C_FG_RED "\033[0;31m"
#define C_FG_GREEN "\033[0;32m"
#define C_FG_YELLOW "\033[0;33m"
#define C_FG_BLUE "\033[0;34m"
#define C_FG_MAGENTA "\033[0;35m"
#define C_FG_CYAN "\033[0;36m"
#define C_FG_GRAY "\033[0;37m"
#define C_FG_DEFAULT "\033[0;39m"
#define C_FG_GRAY_D "\033[0;90m"
#define C_FG_RED_L "\033[0;91m"
#define C_FG_GREEN_L "\033[0;92m"
#define C_FG_YELLOW_L "\033[0;93m"
#define C_FG_BLUE_L "\033[0;94m"
#define C_FG_MAGENTA_L "\033[0;95m"
#define C_FG_CYAN_L "\033[0;96m"
#define C_FG_WHITE "\033[0;97m"
#define C_BG_NONE ""
#define C_BG_RED "\033[1;41m"
#define C_BG_GREEN "\033[1;42m"
#define C_BG_BLUE "\033[1;44m"
#define C_BG_DEFAULT "\033[1;49m"
std::map<std::string, std::string> getColors() {
std::map<std::string, std::string> colors;
colors["|30"] = C_B0;
colors["|31"] = C_B1;
colors["|00"] = C_FG_BLACK;
colors["|01"] = C_FG_BLUE;
colors["|02"] = C_FG_GREEN;
colors["|03"] = C_FG_CYAN;
colors["|04"] = C_FG_RED;
colors["|05"] = C_FG_MAGENTA;
colors["|06"] = C_FG_YELLOW;
colors["|07"] = C_FG_GRAY;
colors["|08"] = C_FG_GRAY_D;
colors["|09"] = C_FG_BLUE_L;
colors["|10"] = C_FG_GREEN_L;
colors["|11"] = C_FG_CYAN_L;
colors["|12"] = C_FG_RED_L;
colors["|13"] = C_FG_MAGENTA_L;
colors["|14"] = C_FG_YELLOW_L;
colors["|15"] = C_FG_WHITE;
colors["|16"] = C_BG_DEFAULT; // C_BG_BLACK
colors["|17"] = C_BG_BLUE;
colors["|18"] = C_BG_GREEN;
colors["|19"] = C_BG_BLUE; // C_BG_CYAN
colors["|20"] = C_BG_RED;
colors["|21"] = C_BG_RED; // C_BG_MAGENTA
colors["|22"] = C_FG_WHITE; //C_BG_BROWN
colors["|23"] = C_BG_DEFAULT; // C_BG_WHITE
return colors;
}
bool has_colors(void) {
char buffer[1024];
int c;
tgetent(buffer, getenv("TERM"));
c = tgetnum("Co");
if(c > 0 || c == -1) {
return true;
} else {
return false;
}
}
void cprintf( const char * format, ... ) {
char buffer[256];
std::map<std::string, std::string> colors;
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
std::string text(buffer), s(buffer);
va_end(args);
std::size_t index;
std::smatch matches;
std::regex reg ("(\\|\\d\\d)", std::regex_constants::ECMAScript | std::regex_constants::nosubs);
colors = getColors();
while (std::regex_search (text,matches,reg)) {
for (auto x:matches) {
while ((index = s.find(x)) != std::string::npos)
s.replace(index, x.length(), colors[x]);
}
text = matches.suffix().str();
}
std::cout << s;
}
int main(void) {
cprintf("\n%s\n\n", "|01P|02i|03p|04e|05c|06ol|07o|08r|09s |10l|11i|12b|13r|14a|15r|14y |130|12.|111|07");
return 0;
}

16
pipecolors.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __PIPECOLORS_H
#define __PIPECOLORS_H
#ifndef PIPECOLORS_VERSION
#define PIPECOLORS_VERSION 0.1b
#endif
#ifdef __cplusplus
extern "C" {
#endif
void cprintf(const char* format, ...);
#ifdef __cplusplus
}
#endif
#endif

10
pipecolors.pc.in Executable file
View File

@ -0,0 +1,10 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: pipecolors
Description: Uses old renegade pipe color scheme to print colors to the terminal
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lpipecolors
Cflags: -I${includedir}/pipecolors

12
test.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include <pipecolors/pipecolors.h>
int main(void) {
const char* str = "|0101|0202|0303|0404|0505|0606|0707|0808|0909|1010|1111|1212|1313|1414|1515";
const char* name = "|01P|02i|03p|04e|05c|06ol|07o|08r|09s |10l|11i|12b|13r|14a|15r|14y |130|12.|111|07"
cprintf("\n%s\n\n", name);
cprintf("%s\n", str);
}