...
 
Commits (10)
......@@ -10,10 +10,7 @@
# BSD `install'.
# undocumented
CFLAGS_DEBUG = -Wall -Wextra -Wshadow -Wformat -Wconversion -Wundef -Wno-unused \
-Wconditional-uninitialized -Wmissing-variable-declarations \
-Wmissing-prototypes -Wstrict-prototypes \
-g -O0 -std=c89 -pedantic
DEBUG_CFLAGS = -g -O0 -std=c89 -pedantic # works with Clang
C_FILES = ${SRCDIR}/main.c ${SRCDIR}/draw.c
......
......@@ -53,7 +53,7 @@ features:
* `--use-posixtime`: Use higher-resolution time for better random numbers
* more to come…
Run `./configure --help' for info on installation paths, compilers, etc.
Run `./configure --help` for info on installation paths, compilers, etc.
Some notes
----------
......
......@@ -44,38 +44,46 @@ use_color="no"
use_sysexits="no"
use_posixtime="no"
# Check whether shell/system `echo' supports flags
if test "`echo -n`" = "-n"; then
n=""
else
# $n expands to this in `echo $n`, removing the newline
n="-n"
fi
###########################################################
# PARSE OPTIONS
# The `us_' variables are left undefined unless specified as options
for arg in $@; do
for arg in "$@"; do
case $arg in
--bindir=*)
us_bindir=`echo $arg | sed 's/--bindir=//'`
us_bindir=`echo "$arg" | sed 's/--bindir=//'`
;;
--datadir=*)
us_datadir=`echo $arg | sed 's/--datadir=//'`
us_datadir=`echo "$arg" | sed 's/--datadir=//'`
;;
--help | -help | -h | --h)
helpme="yes"
;;
--mandir=*)
us_mandir=`echo $arg | sed 's/--mandir=//'`
us_mandir=`echo "$arg" | sed 's/--mandir=//'`
;;
--no-ifndef-guards)
ifndef_guards="no"
;;
--prefix=*)
us_prefix=`echo $arg | sed 's/--prefix=//'`
us_prefix=`echo "$arg" | sed 's/--prefix=//'`
;;
--quiet | -q)
is_quiet="yes"
;;
--srcdir=*)
us_srcdir=`echo $arg | sed 's/--srcdir=//'`
us_srcdir=`echo "$arg" | sed 's/--srcdir=//'`
;;
--use-*)
feature=`echo $arg | sed 's/--use-//; s/[-.]/_/'`
feature=`echo "$arg" | sed 's/--use-//; s/[-.]/_/'`
# If the feature variable isn't already initialised to
# a default value up above, it (probably) doesn't exist
if eval test -n \"\$use_$feature\"; then
......@@ -148,9 +156,9 @@ fi
test "$is_verbose" = "yes" && echo "Entering verbose mode."
# Check whether PWD is usable
test "$is_verbose" = "$yes" &&
echo -n "Checking whether PWD is read-/write-able... "
cs_pwd=`pwd` && test -n $cs_pwd &&
test "$is_verbose" = "yes" &&
echo $n "Checking whether PWD is read-/write-able... "
cs_pwd=`pwd` && test -n "$cs_pwd" &&
ls_di=`ls -di .` &&
pwd_ls_di=`cd "$cd_pwd" && ls -di .` ||
{
......@@ -187,12 +195,12 @@ else
# In verbose mode, "Checking for..." displays each iteration;
# otherwise, just show this catch-all message
test "$is_quiet" = "no" && test "$is_verbose" = "no" &&
echo -n "Checking for a valid compiler... "
echo $n "Checking for a valid compiler... "
# XXX There has to be a more elegant way to do this
while true; do
test "$is_verbose" = "yes" &&
echo -n "Checking for Clang toolkit... "
echo $n "Checking for Clang toolkit... "
if command -v clang >/dev/null 2>&1; then
test "$is_quiet" = "no" && echo "found."
CC="clang"
......@@ -202,7 +210,7 @@ else
fi
test "$is_verbose" = "yes" &&
echo -n "Checking for GNU toolkit... "
echo $n "Checking for GNU toolkit... "
if command -v gcc >/dev/null 2>&1; then
test "$is_quiet" = "no" && echo "found."
CC="gcc"
......@@ -213,7 +221,7 @@ else
# XXX probably dangerous
test "$is_verbose" = "yes" &&
echo -n "Checking for something named \`cc'... "
echo $n "Checking for something named \`cc'... "
if command -v cc >/dev/null 2>&1; then
test "$is_quiet" = "no" && echo "found."
CC="cc"
......@@ -229,11 +237,12 @@ else
"running this script." >&2
exit 1
done
test "$is_verbose" = "yes" && echo "CC: $CC"
fi
# Check for C standard library (at least those used in the program)
test "$is_quiet" = "no" &&
echo -n "Checking for C89 standard library headers... "
echo $n "Checking for C89 standard library headers... "
cat >conftest.c <<_EOF
#include <ctype.h>
#include <errno.h>
......@@ -260,7 +269,7 @@ fi
# Check for POSIX standard library
test "$is_quiet" = "no" &&
echo -n "Checking for POSIX standard library headers... "
echo $n "Checking for POSIX standard library headers... "
cat >conftest.c <<_EOF
#include <unistd.h>
......@@ -282,7 +291,7 @@ fi
# Check for `sysexits.h'
if test "$use_sysexits" = "yes"; then
test "$is_quiet" = "no" &&
echo -n "Checking for \`sysexits.h'... "
echo $n "Checking for \`sysexits.h'... "
cat >conftest.c <<_EOF
#include <sysexits.h>
......@@ -305,7 +314,7 @@ fi
# Check for POSIX `sys/time.h'
if test "$use_posixtime" = "yes"; then
test "$is_quiet" = "no" &&
echo -n "Checking for POSIX \`sys/time.h'... "
echo $n "Checking for POSIX \`sys/time.h'... "
cat >conftest.c <<_EOF
#include <sys/time.h>
......@@ -327,14 +336,16 @@ fi
# Generate `$CFLAGS' based on what the user specified
test "$is_verbose" = "yes" &&
echo -n "Computing CFLAGS... "
echo $n "Computing CFLAGS... "
test -z "$CFLAGS" && CFLAGS=""
CFLAGS="$CFLAGS $default_CFLAGS"
test "$is_verbose" = "yes" && echo "done."
test "$is_verbose" = "yes" && test -n "$CFLAGS" &&
echo "CFLAGS: $CFLAGS"
# Generate `$feature_flags` based on `--use-FEATURE` variables
test "$is_verbose" = "yes" &&
echo -n "Computing feature CFLAGS... "
echo $n "Computing feature CFLAGS... "
feature_CFLAGS=""
test "$use_color" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_COLOR"
......@@ -343,11 +354,13 @@ test "$use_sysexits" = "yes" &&
test "$use_posixtime" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_POSIXTIME"
test "$is_verbose" = "yes" && echo "done."
test "$is_verbose" = "yes" && test -n "$feature_CFLAGS" &&
echo "FEATURE_CFLAGS: $feature_CFLAGS"
# =============
test "$is_quiet" = "no" &&
echo -n "Generating Makefile... "
echo $n "Generating Makefile... "
cat >Makefile <<_EOF
## Makefile for varlpenis
......@@ -406,7 +419,7 @@ cat Makefile.in >> Makefile
test "$is_quiet" = "no" && echo "done."
test "$is_quiet" = "no" &&
echo -n "Generating \`check.sh'... "
echo $n "Generating \`check.sh'... "
cat >check.sh <<_EOF
#!/bin/sh
test -f ./varlpenis || { echo "not found"; exit 1; }
......
.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
......
......@@ -19,6 +19,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);
......
......@@ -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",
......@@ -170,7 +175,7 @@ int main(int argc, char *argv[])
* included in the `if' blocks, calling `varlpenis -vh' would print
* version info and exit before printing the help message. */
if (options.flags & OPT_VERSION)
printf("%1$s v%2$s - %3$s\n%4$s\n",
printf("%s v%s - %s\n%s\n",
VP_PROGRAM_NAME, VP_VERSION_STR, VP_PROGRAM_DESC,
VP_COPYRIGHT);
if (options.flags & OPT_HELP)
......
......@@ -17,24 +17,25 @@ 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 {
enum OPTIONS_E flags;
/* Only evaluated for error-handling */
enum OPTIONS_ERROR_E error_code;
char error_char;
/* If the LENGTH and/or DISTANCE flags are set, `main()' will use
* the respective of these numbers instead of a random value */
unsigned int length;
unsigned int distance;
/* Only evaluated for error-handling */
enum OPTIONS_ERROR_E error_code;
char error_char;
};
#endif /* ! VP_OPTIONS_H */
......@@ -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"
......