Commit bf8fff81 authored by Seth Price's avatar Seth Price

Use exit values from `sysexits.h`

* Return using values from `sysexits.h` if supported (use included
  `exits.h` otherwise)
* Add `--use-sysexits` feature in configure script to automatically
  compile with necessary macros
* Update documentation to reflect changes

Merged locally; no relevant merge request
parent 6fc1e5eb
......@@ -49,6 +49,7 @@ Use any of the following when running `./configure` to control optional
features:
* `--use-color`: Enable colour support using ANSI escape codes
* `--use-sysexits`: Use exit values from system's `sysexits.h`
* more to come…
Run `./configure --help' for info on installation paths, compilers, etc.
......
......@@ -41,6 +41,7 @@ ifndef_guards="yes"
# Default feature values
use_color="no"
use_sysexits="no"
###########################################################
# PARSE OPTIONS
......@@ -120,6 +121,7 @@ Installation directories:
Optional features (using --use-FEATURE [all are off by default]):
color Enable colour support using ANSI escape codes
sysexits Exit with values from system's \`sysexits.h'
Environment variables:
CC C compiler command [ auto-detected ]
......@@ -273,6 +275,29 @@ else
exit 1
fi
# Check for `sysexits.h'
if test "$use_sysexits" = "yes"; then
test "$is_quiet" = "no" &&
echo -n "Checking for \`sysexits.h'... "
cat >conftest.c <<_EOF
#include <sysexits.h>
int main() { return EX_OK; }
_EOF
(eval $CC $CFLAGS conftest.c -o conftest) 2>conftest.err
rm -f conftest.o conftest.c conftest
if test ! -s conftest.err; then
test "$is_quiet" = "no" && echo "found."
rm -f conftest.err
else
test "$is_quiet" = "no" && echo "not found."
echo "$log_e: \`sysexits.h' does not work as expected." >&2
echo "$log_e: Specify a valid include dir in your CFLAGS with "\
"\`CFLAGS=-I/path/to/dir' when running this script." >&2
exit 1
fi
fi
# Generate `$CFLAGS' based on what the user specified
test "$is_verbose" = "yes" &&
echo -n "Computing CFLAGS... "
......@@ -286,6 +311,8 @@ test "$is_verbose" = "yes" &&
feature_CFLAGS=""
test "$use_color" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_COLOR"
test "$use_sysexits" = "yes" &&
feature_CFLAGS="$feature_CFLAGS -DVP_USE_SYSEXITS"
test "$is_verbose" = "yes" && echo "done."
# =============
......
......@@ -42,7 +42,11 @@ Print version information and exit.
.El
.Sh EXIT STATUS
.Nm
exits with 0 on success, and >0 if an error occurs.
exits with 0 on success, and >0 if an error occurs. If compiled with
.Dv -DVP_USE_SYSEXITS ,
codes from
.xr sysexits 3
are used instead.
.Sh STANDARDS
.St -ansiC
.Sh AUTHORS
......
/**
* varlpenis - Generate ASCII-art penis of arbitrary length
* Seth Price <https://www.gitlab.com/ssterling/varlpenis>
*
* See `LICENSE' file for copyright information.
*/
#ifndef VP_EXITS_H
#define VP_EXITS_H
/* If `sysexits.h' is available (and `VP_USE_SYSEXITS' is defined),
* its exit values will be implemented. Otherwise, standard
* `0' on success and `1' on failure is used. */
#ifdef VP_USE_SYSEXITS
#include <sysexits.h>
#else /* ! VP_USE_SYSEXITS */
#define EX_OK 0
#define EX_USAGE 1
#define EX_SOFTWARE 1
#endif /* ! VP_USE_SYSEXITS */
#endif /* ! VP_EXITS_H */
......@@ -15,6 +15,7 @@
#include "draw.h"
#include "options.h"
#include "strings.h"
#include "exits.h"
int main(int argc, char *argv[])
{
......@@ -102,12 +103,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error: option `-%c' requires a "
"positive integer as an argument\n",
options.error_char);
return 1;
return EX_USAGE;
case ERR_NOTINT:
fprintf(stderr, "Error: argument to option `-%c' "
"must be a positive integer\n",
options.error_char);
return 1;
return EX_USAGE;
case ERR_UNKNOWNCHAR:
if (isprint(options.error_char))
fprintf(stderr, "Error: unknown option `-%c'\n",
......@@ -116,15 +117,15 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error: unknown option char "
"`\\x%x'\n",
(int)options.error_char);
return 1;
return EX_USAGE;
default:
fprintf(stderr, "Error: bogus error code received "
"from options parser\n");
return 1;
return EX_SOFTWARE;
}
/* The code here is a bit clunky, but the intention is to print both
* version and help information if requested. -- If `return 0' was
* version and help information if requested. -- If `return' was
* included in the `if' blocks, calling `varlpenis -vh' would print
* version info and exit before printing the help message. */
if (options.flags & OPT_VERSION)
......@@ -151,7 +152,7 @@ int main(int argc, char *argv[])
VP_PROGRAM_NAME);
#endif /* VP_USE_COLOR */
if (options.flags & OPT_HELP || options.flags & OPT_VERSION)
return 0;
return EX_OK;
/* If these flags are set, length/distance are user-specified */
if (options.flags & OPT_LENGTH)
......@@ -162,5 +163,5 @@ int main(int argc, char *argv[])
/* `draw_penis()' prints to stdout and returns nothing */
draw_penis(length, distance, flags);
return 0;
return EX_OK;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment