added test.c

This commit is contained in:
= 2015-07-02 20:20:18 -07:00
parent 82326e64a7
commit 344b9ed855
6 changed files with 51 additions and 48 deletions

View File

@ -1,5 +1,9 @@
pkgconfig_DATA = pipecolors.pc
VERSION = 0.1.0
man-hook:
gzip $(mandir)/man7/libpipecolors.7
gzip $(mandir)/man3/pcprintf.3
pkgconfig_DATA = libpipecolors.pc
AM_CXXFLAGS = -std=c++11
ACLOCAL_AMFLAGS = -I m4 -I config
LIBTOOL_DEPS = @LIBTOOL_DEPS@
@ -15,3 +19,19 @@ libpipecolors_la_LDFLAGS = -module \
-release ${PIPECOLORS_VERSION}
include_HEADERS = pipecolors.h
man_MANS = libpipecolors.7 pcprintf.3
docdir = $(datadir)/doc/@PACKAGE@
doc_DATA = README NEWS AUTHORS ChangeLog COPYING
MAINTAINERCLEANFILES = \
aclocal.m4 \
config.h \
config.h.in \
config.h.in~ \
config.log \
stamp-h1 \
-rf config \
-rf m4 \
configure \

View File

@ -29,23 +29,25 @@ AC_CONFIG_SRCDIR([libpipecolors.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE([-Wall -Werror])
AM_INIT_AUTOMAKE([gnu dist-bzip2 dist-zip std-options])
AM_SILENT_RULES
AC_GNU_SOURCE
AC_CANONICAL_HOST
AC_PROG_CXX
AC_PROG_CXX_C_O
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_CXXCPP
AM_PROG_AR
AC_PROG_LIBTOOL
AC_PROG_LN_S
LT_INIT
AC_LANG_CPLUSPLUS
AC_PREFIX_DEFAULT([/usr])
#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])
@ -58,18 +60,6 @@ gcc_micro_vers=`echo ${gcc_full_vers} | cut -f3 -d.`
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}])
@ -77,16 +67,15 @@ else
AC_MSG_RESULT([${gcc_full_vers} ... acceptable])
fi
AC_HEADER_STDC
AC_CHECK_FUNCS([vprintf vsprintf printf])
AC_CHECK_FUNCS([vprintf vsprintf vasprintf printf])
# Checks for libraries.
AC_CHECK_HEADERS([stdarg.h regex.h iostream map string unistd.h stdlib.h],[],[AC_MSG_ERROR[no]])
AC_CHECK_TYPE([size_t])
AC_CHECK_TYPES([std::string], [], [], [[
#include <stdio.h>
#include <string>
#include <iostream>
#include <string>
]])
AC_ARG_ENABLE([the-force],
@ -94,6 +83,6 @@ AC_ARG_ENABLE([the-force],
[], [enable_the_force=no])
AM_CONDITIONAL([ENABLE_THE_FORCE], [test "x$enable_the_force" = "xyes"])
AC_CONFIG_FILES([Makefile pipecolors.pc:pipecolors.pc.in],[],[APIVERSION=PIPECOLORS_VERSION])
AC_CONFIG_FILES([Makefile libpipecolors.pc:libpipecolors.pc.in],[],[APIVERSION=PIPECOLORS_VERSION])
AC_CONFIG_COMMANDS([default],[[]],[[]])
AC_OUTPUT

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <unistd.h>
#include <pipecolors.h>
#define printf cprintf
using namespace pipecolors;
@ -10,9 +10,7 @@ int main(void) {
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";
cprintf("\n%s\n\n", name);
cprintf("%s\n", str);
if( isatty(fileno(stdout)) ) {
printf("Awesome!");
}
pcprintf("\n%s\n\n", name);
pcprintf("%s\n", str);
}

View File

@ -26,7 +26,7 @@
#include <string>
#include <map>
#include <regex>
#include "pipecolors.h"
//#include "libpipecolors.h"
namespace pipecolors {
@ -102,17 +102,23 @@ bool has_colors(void) {
void pcprintf( const char * fmt, ... ) {
char buffer[256];
char *buffer;
std::map<std::string, std::string> colors;
std::size_t index;
std::smatch matches;
va_list args;
va_start(args, fmt);
vasprintf(buffer, fmt, args);
if(int size = vasprintf(&buffer, fmt, args) == -1) {
free(buffer);
exit(EXIT_FAILURE);
}
std::string text(buffer), s(buffer);
va_end(args);
std::size_t index;
free(buffer);
std::smatch matches;
std::regex reg ("(\\|\\d\\d)", std::regex_constants::ECMAScript | std::regex_constants::nosubs);
colors = getColors();

View File

@ -4,8 +4,9 @@
#ifndef _PIPECOLORS_H
#define _PIPECOLORS_H
#endif
namespace pipecolors {
#ifdef __cplusplus
namespace pipecolors {
extern "C" {
#endif
@ -14,6 +15,5 @@ void pcsprintf(char **strp, const char *fmt, va_list ap);
#ifdef __cplusplus
}
#endif
}
#endif

View File

@ -1,10 +0,0 @@
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