added test.c
This commit is contained in:
parent
82326e64a7
commit
344b9ed855
24
Makefile.am
24
Makefile.am
|
@ -1,5 +1,9 @@
|
||||||
pkgconfig_DATA = pipecolors.pc
|
man-hook:
|
||||||
VERSION = 0.1.0
|
gzip $(mandir)/man7/libpipecolors.7
|
||||||
|
gzip $(mandir)/man3/pcprintf.3
|
||||||
|
|
||||||
|
|
||||||
|
pkgconfig_DATA = libpipecolors.pc
|
||||||
AM_CXXFLAGS = -std=c++11
|
AM_CXXFLAGS = -std=c++11
|
||||||
ACLOCAL_AMFLAGS = -I m4 -I config
|
ACLOCAL_AMFLAGS = -I m4 -I config
|
||||||
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||||
|
@ -15,3 +19,19 @@ libpipecolors_la_LDFLAGS = -module \
|
||||||
-release ${PIPECOLORS_VERSION}
|
-release ${PIPECOLORS_VERSION}
|
||||||
|
|
||||||
include_HEADERS = pipecolors.h
|
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 \
|
||||||
|
|
33
configure.ac
33
configure.ac
|
@ -29,23 +29,25 @@ 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])
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE([-Wall -Werror])
|
AM_INIT_AUTOMAKE([gnu dist-bzip2 dist-zip std-options])
|
||||||
|
AM_SILENT_RULES
|
||||||
AC_GNU_SOURCE
|
AC_GNU_SOURCE
|
||||||
AC_CANONICAL_HOST
|
AC_CANONICAL_HOST
|
||||||
AC_PROG_CXX
|
AC_PROG_INSTALL
|
||||||
AC_PROG_CXX_C_O
|
AC_PROG_MAKE_SET
|
||||||
AC_PROG_CXXCPP
|
AC_PROG_CXXCPP
|
||||||
AM_PROG_AR
|
AM_PROG_AR
|
||||||
AC_PROG_LIBTOOL
|
AC_PROG_LIBTOOL
|
||||||
|
AC_PROG_LN_S
|
||||||
|
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
|
||||||
AC_LANG_CPLUSPLUS
|
AC_LANG_CPLUSPLUS
|
||||||
AC_PREFIX_DEFAULT([/usr])
|
AC_PREFIX_DEFAULT([/usr])
|
||||||
#AC_CHECK_LIB([pipecolors], [cprintf])
|
#AC_CHECK_LIB([pipecolors], [cprintf])
|
||||||
#PKG_CHECK_MODULES([LIBPIPECOLORS], [pipecolors])
|
|
||||||
# Checks for programs.
|
# Checks for programs.
|
||||||
AM_CONDITIONAL(CXX, test "$CXX" = yes) # let the Makefile know if we're gcc
|
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AC_SUBST([LIBTOOL_DEPS])
|
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_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])
|
AC_MSG_CHECKING([${CXX-c++} version])
|
||||||
if test "${gcc_minor_vers}" -lt 9; then
|
if test "${gcc_minor_vers}" -lt 9; then
|
||||||
AC_MSG_ERROR([GCC >= 4.9 is required, you have version ${gcc_full_vers}])
|
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])
|
AC_MSG_RESULT([${gcc_full_vers} ... acceptable])
|
||||||
fi
|
fi
|
||||||
AC_HEADER_STDC
|
AC_HEADER_STDC
|
||||||
AC_CHECK_FUNCS([vprintf vsprintf printf])
|
AC_CHECK_FUNCS([vprintf vsprintf vasprintf printf])
|
||||||
|
|
||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
AC_CHECK_HEADERS([stdarg.h regex.h iostream map string unistd.h stdlib.h],[],[AC_MSG_ERROR[no]])
|
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_TYPE([size_t])
|
||||||
|
|
||||||
AC_CHECK_TYPES([std::string], [], [], [[
|
AC_CHECK_TYPES([std::string], [], [], [[
|
||||||
#include <stdio.h>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AC_ARG_ENABLE([the-force],
|
AC_ARG_ENABLE([the-force],
|
||||||
|
@ -94,6 +83,6 @@ AC_ARG_ENABLE([the-force],
|
||||||
[], [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 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_CONFIG_COMMANDS([default],[[]],[[]])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pipecolors.h>
|
#include <pipecolors.h>
|
||||||
#define printf cprintf
|
|
||||||
|
|
||||||
using namespace pipecolors;
|
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* 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";
|
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);
|
pcprintf("\n%s\n\n", name);
|
||||||
cprintf("%s\n", str);
|
pcprintf("%s\n", str);
|
||||||
if( isatty(fileno(stdout)) ) {
|
|
||||||
printf("Awesome!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include "pipecolors.h"
|
//#include "libpipecolors.h"
|
||||||
|
|
||||||
namespace pipecolors {
|
namespace pipecolors {
|
||||||
|
|
||||||
|
@ -102,17 +102,23 @@ bool has_colors(void) {
|
||||||
|
|
||||||
void pcprintf( const char * fmt, ... ) {
|
void pcprintf( const char * fmt, ... ) {
|
||||||
|
|
||||||
char buffer[256];
|
char *buffer;
|
||||||
std::map<std::string, std::string> colors;
|
std::map<std::string, std::string> colors;
|
||||||
|
std::size_t index;
|
||||||
|
std::smatch matches;
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
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);
|
std::string text(buffer), s(buffer);
|
||||||
va_end(args);
|
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);
|
std::regex reg ("(\\|\\d\\d)", std::regex_constants::ECMAScript | std::regex_constants::nosubs);
|
||||||
|
|
||||||
colors = getColors();
|
colors = getColors();
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
#ifndef _PIPECOLORS_H
|
#ifndef _PIPECOLORS_H
|
||||||
#define _PIPECOLORS_H
|
#define _PIPECOLORS_H
|
||||||
#endif
|
#endif
|
||||||
namespace pipecolors {
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
namespace pipecolors {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -14,6 +15,5 @@ void pcsprintf(char **strp, const char *fmt, va_list ap);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in New Issue