...
 
Commits (9)
......@@ -48,7 +48,8 @@ else. Written in ANSI C using only the standard library.
Use any of the following when running `./configure` to control optional
features:
* `--use-color`: Enable colour support using ANSI escape codes
* `--use-color-ansi`: Enable colour support using ANSI escape codes
* `--use-color-woe32`: Enable colour support for Windows console
* `--use-sysexits`: Use exit values from system's `sysexits.h`
* `--use-posixtime`: Use higher-resolution time for better random numbers
* more to come…
......
......@@ -41,6 +41,8 @@ ifndef_guards="yes"
# Default feature values
use_color="no"
use_color_ansi="no"
use_color_woe32="no"
use_sysexits="no"
use_posixtime="no"
......@@ -117,7 +119,7 @@ To assign environment variables (e.g. CC, CFLAGS), specify them with
Script configuration:
-h, --help Display this message and exit
-q, --quiet Do not print \'Checking...' messages
-q, --quiet Do not print \`Checking...' messages
-v, --verbose Be verbose in saying what's going on
--srcdir=DIR Find the source files in directory DIR
......@@ -129,7 +131,8 @@ Installation directories:
--no-ifndef-guards Ignore environment variables for installation dirs
Optional features (using --use-FEATURE [all are off by default]):
color Enable colour support using ANSI escape codes
color-ansi Enable color output using ANSI escape codes
-woe32 ... using Windows Console API commands
posixtime Use higher-resolution time for better random numbers
sysexits Exit with values from system's \`sysexits.h'
......@@ -343,12 +346,27 @@ test "$is_verbose" = "yes" && echo "done."
test "$is_verbose" = "yes" && test -n "$CFLAGS" &&
echo "CFLAGS: $CFLAGS"
# Alias old `--use-color' to new `--use-color-ansi'
if test "$use_color" = "yes" && test "$use_color_ansi" = "no"; then
test "$is_quiet" = "no" &&
echo "$log_w: \`--use-color' is now deprecated; use \`--use-color-ansi'"
use_color_ansi="yes"
fi
# If `--use-color-<type>' is specified, implicitly enable `color' feature
test "$use_color_ansi" = "yes" && test "$use_color" = "no" &&
use_color="yes"
# Generate `$feature_flags` based on `--use-FEATURE` variables
test "$is_verbose" = "yes" &&
echo $n "Computing feature CFLAGS... "
feature_CFLAGS=""
test "$use_color" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_COLOR"
test "$use_color_ansi" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_COLOR_ANSI"
test "$use_color_woe32" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_COLOR_WOE32"
test "$use_sysexits" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_SYSEXITS"
test "$use_posixtime" = "yes" &&
......
.Dd April 1, 2019
.Dd September 25, 2019
.Dt VARLPENIS 6
.Os
.Sh NAME
......@@ -46,7 +46,7 @@ exits with 0 on success, and >0 if an error occurs. If compiled with
.Dv VP_USE_SYSEXITS ,
codes from
.Xr sysexits 3
are used instead.
are used.
.Sh STANDARDS
.St -ansiC
.Sh AUTHORS
......
......@@ -11,6 +11,10 @@
#include "draw.h"
#if defined VP_USE_COLOR && defined _WIN32
#include <windows.h>
#endif /* _VP_USE_COLOR && _WIN32 */
/* The `main()' function is 99% options-parsing and error-handling;
* this file itself (and the corresponding `draw.h') can be utilised
* independently inside another program or whatnot if desired */
......@@ -19,6 +23,11 @@ static char *repeat_char(const char ch, unsigned int count)
{
char *ret;
if (count == 0) {
ret = "\0";
return ret;
}
ret = malloc(count + 1);
strncpy(ret, &ch, 1);
......@@ -31,8 +40,22 @@ static char *repeat_char(const char ch, unsigned int count)
void draw_penis(const unsigned int length, const unsigned int distance,
const enum DRAW_FLAGS_E flags)
{
#ifdef VP_USE_COLOR
/* Global variables for Winblows (when using color) */
#if defined VP_USE_COLOR && _WIN32
HANDLE console;
CONSOLE_SCREEN_BUFFER_INFO console_info;
WORD original_attribs;
#endif /* VP_USE_COLOR && _WIN32 */
#ifdef VP_USE_COLOR_ANSI
if (flags & COLOR)
/* ANSI codes are indeed supported in the new Woe10 console,
* but they need to be enabled with a specific command first */
#ifdef _WIN32
console = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleMode(console, ENABLE_VIRTUAL_TERMINAL_PROCESSING);
#endif /* _WIN32 */
printf("%s%c%s%s%s%c%s%s%s\n",
SCROTUM_COLOR_ANSI, SCROTUM_CHAR,
SHAFT_COLOR_ANSI, repeat_char(SHAFT_CHAR, length),
......@@ -43,9 +66,29 @@ void draw_penis(const unsigned int length, const unsigned int distance,
printf("%c%s%c%s\n",
SCROTUM_CHAR, repeat_char(SHAFT_CHAR, length),
HEAD_CHAR, repeat_char(EJAC_CHAR, distance));
#else /* VP_USE_COLOR */
#elif defined VP_USE_COLOR_WOE32
if (flags & COLOR)
console = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(console, &console_info);
original_attribs = console_info.wAttributes;
SetConsoleTextAttribute(console, SCROTUM_COLOR_WOE32);
printf("%s", SCROTUM_CHAR);
SetConsoleTextAttribute(console, SHAFT_COLOR_WOE32);
printf("%s", repeat_char(SHAFT_CHAR, length));
SetConsoleTextAttribute(console, HEAD_COLOR_WOE32);
printf("%s", HEAD_CHAR);
SetConsoleTextAttribute(console, EJAC_COLOR_WOE32);
printf("%s", repeat_char(EJAC_CHAR, distance));
SetConsoleTextAttribute(console, original_attribs);
printf("\n");
else
printf("%c%s%c%s\n",
SCROTUM_CHAR, repeat_char(SHAFT_CHAR, length),
HEAD_CHAR, repeat_char(EJAC_CHAR, distance));
#else /* VP_USE_COLOR_<type> */
printf("%c%s%c%s\n",
SCROTUM_CHAR, repeat_char(SHAFT_CHAR, length),
HEAD_CHAR, repeat_char(EJAC_CHAR, distance));
#endif /* VP_USE_COLOR */
#endif /* VP_USE_COLOR_<type> */
}
......@@ -11,6 +11,24 @@
#ifndef VP_DRAW_H
#define VP_DRAW_H
/* Just in case it wasn't already explicitly defined,
* `VP_USE_COLOR_<type>' should implicitly define `VP_USE_COLOR' */
#if (defined VP_USE_COLOR_ANSI || defined VP_USE_COLOR_WOE32) && \
!defined VP_USE_COLOR
#warning `VP_USE_COLOR_<type>' is defined, but not `VP_USE_COLOR'; \
`VP_USE_COLOR' will be implicitly defined for now
#define VP_USE_COLOR
#endif /* VP_USE_COLOR_<type> && ! VP_USE_COLOR */
/* And, if for some reason, `VP_USE_COLOR` is defined but no
* `VP_USE_COLOR_<type>', throw an error */
#if defined VP_USE_COLOR && \
!(defined VP_USE_COLOR_ANSI || defined VP_USE_COLOR_WOE32)
#warning `VP_USE_COLOR' is defined but no `VP_USE_COLOR_<type>'; \
assuming `VP_USE_COLOR_ANSI'
#define VP_USE_COLOR_ANSI
#endif /* VP_USE_COLOR && ! VP_USE_COLOR_<type> */
#define LENGTH_MIN 1
#define LENGTH_MAX RAND_MAX
#define DISTANCE_MIN 1
......@@ -27,13 +45,20 @@
#define HEAD_CHAR 'D'
#define EJAC_CHAR '~'
#ifdef VP_USE_COLOR
#ifdef VP_USE_COLOR_ANSI
#define SCROTUM_COLOR_ANSI "\33[33m" /* yellow */
#define SHAFT_COLOR_ANSI "\33[1m\33[33m" /* bright yellow */
#define HEAD_COLOR_ANSI "\33[1m\33[31m" /* bright red */
#define EJAC_COLOR_ANSI "\33[1m\33[37m" /* bright white */
#define RESET_CODE_ANSI "\33[0m"
#endif /* VP_USE_COLOR */
#endif /* VP_USE_COLOR_ANSI */
#ifdef VP_USE_COLOR_WOE32
#define SCROTUM_COLOR_WOE32 6 /* yellow */
#define SHAFT_COLOR_WOE32 14 /* bright yellow */
#define HEAD_COLOR_WOE32 12 /* bright red */
#define EJAC_COLOR_WOE32 15 /* bright white */
#endif /* VP_USE_COLOR_WOE32 */
/* To avoid changing numbers in potential future expansion,
* all flags will be compiled regardless of enabled features */
......
......@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
options.error_code = ERR_BIGUINT;
options.error_char = 'e';
goto BREAK_FROM_GETOPT;
} else if (strtol_tmp < 1) {
} else if (strtol_tmp < 0) {
options.error_code = ERR_NOTINT;
options.error_char = 'e';
goto BREAK_FROM_GETOPT;
......@@ -145,6 +145,11 @@ int main(int argc, char *argv[])
"must be a positive integer\n",
options.error_char);
return EX_USAGE;
case ERR_NOTINTORZERO:
fprintf(stderr, "Error: argument to option `-%c' "
"must be zero or a positive integer\n",
options.error_char);
return EX_USAGE;
case ERR_BIGUINT:
fprintf(stderr, "Error: argument to option `-%c' "
"is too large (above `UINT_MAX').\n",
......
......@@ -17,11 +17,12 @@ enum OPTIONS_E {
};
enum OPTIONS_ERROR_E {
ERR_OK = 0,
ERR_NOARG = 1,
ERR_NOTINT = 2,
ERR_UNKNOWNCHAR = 3,
ERR_BIGUINT = 4
ERR_OK = 0,
ERR_NOARG = 1,
ERR_NOTINT = 2,
ERR_UNKNOWNCHAR = 3,
ERR_BIGUINT = 4,
ERR_NOTINTORZERO = 5
};
struct OPTIONS_S {
......
......@@ -9,7 +9,7 @@
#define VP_STRINGS_H
#define VP_PROGRAM_NAME "varlpenis"
#define VP_VERSION_STR "1.2"
#define VP_VERSION_STR "1.3"
#define VP_PROGRAM_DESC "Generate an ASCII-art penis of arbitrary length"
#define VP_COPYRIGHT "Copyright 2019 Seth Price. See LICENSE file for details"
......