Man examples

This commit is contained in:
R. Eric Wheeler 2015-07-02 12:52:49 -07:00
parent cbff6e4441
commit 6e50286618
6 changed files with 1224 additions and 41 deletions

Binary file not shown.

View File

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

60
libpipecolors.7 Normal file
View File

@ -0,0 +1,60 @@
.\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
.\" <mtk.manpages@gmail.com>
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" 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
.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
.TH LIBPIPECOLORS 7 2015-07-01 "Linux" "libpipecolors"
.SH NAME
libpipecolors \- print old bbs/renegade style pipecodes in c/c++
.SH DESCRIPTION
.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
.BR pcprintf (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/.

View File

@ -18,8 +18,7 @@
* 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
*/ */
//#include <cstdio>
//#include <stdio.h>
#include <iostream> #include <iostream>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
@ -29,45 +28,45 @@
#include <regex> #include <regex>
#include "pipecolors.h" #include "pipecolors.h"
namespace pipecolors {
#define C_DEFAULT 0 #define C_DEFAULT 0
#define C_BOLD 1 #define C_BOLD 1
#define C_ITALIC 3 #define C_ITALIC 3
#define C_UNDERLINE 4 #define C_UNDERLINE 4
#define C_INVERT 7 #define C_INVERT 7
#define C_B0 "\033[1m" #define C_B0 "\x1b[1m"
#define C_B1 "\033[0m" #define C_B1 "\x1b[0m"
#define C_FG_BLACK "\033[0;30m" #define C_FG_BLACK "\x1b[0;30m"
#define C_FG_RED "\033[0;31m" #define C_FG_RED "\x1b[0;31m"
#define C_FG_GREEN "\033[0;32m" #define C_FG_GREEN "\x1b[0;32m"
#define C_FG_YELLOW "\033[0;33m" #define C_FG_YELLOW "\x1b[0;33m"
#define C_FG_BLUE "\033[0;34m" #define C_FG_BLUE "\x1b[0;34m"
#define C_FG_MAGENTA "\033[0;35m" #define C_FG_MAGENTA "\x1b[0;35m"
#define C_FG_CYAN "\033[0;36m" #define C_FG_CYAN "\x1b[0;36m"
#define C_FG_GRAY "\033[0;37m" #define C_FG_GRAY "\x1b[0;37m"
#define C_FG_DEFAULT "\033[0;39m" #define C_FG_DEFAULT "\x1b[0;39m"
#define C_FG_GRAY_D "\033[0;90m" #define C_FG_GRAY_D "\x1b[0;90m"
#define C_FG_RED_L "\033[0;91m" #define C_FG_RED_L "\x1b[0;91m"
#define C_FG_GREEN_L "\033[0;92m" #define C_FG_GREEN_L "\x1b[0;92m"
#define C_FG_YELLOW_L "\033[0;93m" #define C_FG_YELLOW_L "\x1b[0;93m"
#define C_FG_BLUE_L "\033[0;94m" #define C_FG_BLUE_L "\x1b[0;94m"
#define C_FG_MAGENTA_L "\033[0;95m" #define C_FG_MAGENTA_L "\x1b[0;95m"
#define C_FG_CYAN_L "\033[0;96m" #define C_FG_CYAN_L "\x1b[0;96m"
#define C_FG_WHITE "\033[0;97m" #define C_FG_WHITE "\x1b[0;97m"
#define C_BG_NONE "" #define C_BG_NONE ""
#define C_BG_RED "\033[1;41m" #define C_BG_RED "\x1b[1;41m"
#define C_BG_GREEN "\033[1;42m" #define C_BG_GREEN "\x1b[1;42m"
#define C_BG_BLUE "\033[1;44m" #define C_BG_BLUE "\x1b[1;44m"
#define C_BG_DEFAULT "\033[1;49m" #define C_BG_DEFAULT "\x1b[1;49m"
std::map<std::string, std::string> getColors() { std::map<std::string, std::string> getColors() {
std::map<std::string, std::string> colors; std::map<std::string, std::string> colors;
colors["|30"] = C_B0;
colors["|31"] = C_B1;
colors["|00"] = C_FG_BLACK; colors["|00"] = C_FG_BLACK;
colors["|01"] = C_FG_BLUE; colors["|01"] = C_FG_BLUE;
colors["|02"] = C_FG_GREEN; colors["|02"] = C_FG_GREEN;
@ -92,27 +91,23 @@
colors["|21"] = C_BG_RED; // C_BG_MAGENTA colors["|21"] = C_BG_RED; // C_BG_MAGENTA
colors["|22"] = C_FG_WHITE; //C_BG_BROWN colors["|22"] = C_FG_WHITE; //C_BG_BROWN
colors["|23"] = C_BG_DEFAULT; // C_BG_WHITE colors["|23"] = C_BG_DEFAULT; // C_BG_WHITE
colors["|30"] = C_B0; //Bold OFF
colors["|31"] = C_B1; // Bold ON
return colors; return colors;
} }
bool has_colors(void) { bool has_colors(void) {
return isatty(fileno(stdout));
if( isatty(fileno(stdout)) ) {
return true;
} else {
return false;
}
} }
void cprintf( const char * format, ... ) { void pcprintf( const char * fmt, ... ) {
char buffer[256]; char buffer[256];
std::map<std::string, std::string> colors; std::map<std::string, std::string> colors;
va_list args; va_list args;
va_start(args, format); va_start(args, fmt);
vsprintf(buffer, format, args); vasprintf(buffer, fmt, args);
std::string text(buffer), s(buffer); std::string text(buffer), s(buffer);
va_end(args); va_end(args);
std::size_t index; std::size_t index;
@ -132,3 +127,4 @@ void cprintf( const char * format, ... ) {
std::cout << s; std::cout << s;
} }
}

1123
pcprintf.3 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,15 +4,16 @@
#ifndef _PIPECOLORS_H #ifndef _PIPECOLORS_H
#define _PIPECOLORS_H #define _PIPECOLORS_H
#endif #endif
namespace pipecolors {
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void cprintf(const char* format, ...); void pcprintf(const char* fmt, ...);
void csprintf(void); void pcsprintf(char **strp, const char *fmt, va_list ap);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
}