From 87228f5b6070af72377e8ddac78c0d70a38a965d Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 9 Feb 2017 19:57:45 +0200 Subject: [PATCH] add the NO_OFFENSIVE compile-time option. Inspired by the Fedora patches. It's still somewhat incomplete. --- fortune-mod/CMakeLists.txt | 5 +++++ fortune-mod/fortune/fortune.c | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/fortune-mod/CMakeLists.txt b/fortune-mod/CMakeLists.txt index 4550d78..c44be26 100644 --- a/fortune-mod/CMakeLists.txt +++ b/fortune-mod/CMakeLists.txt @@ -86,6 +86,7 @@ SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) SET (WITH_TEST_SUITE CACHE BOOL "") +SET (NO_OFFENSIVE CACHE BOOL "Exclude the offensive option.") SET (LOCALDIR "${CMAKE_INSTALL_PREFIX}/local/share/games/fortunes" CACHE STRING "LOCALDIR fortunes dir") SET (LOCALODIR "${LOCALDIR}/off" CACHE STRING "offensive fortunes localdir") SET (COOKIEDIR "${CMAKE_INSTALL_PREFIX}/share/games/fortunes" CACHE STRING "cookie dir not under /usr/local") @@ -135,6 +136,10 @@ ADD_DEFINITIONS("-DLOCFORTDIR=\"${LOCALDIR}\"") ADD_DEFINITIONS("-DOFFDIR=\"${OCOOKIEDIR}\"") ADD_DEFINITIONS("-DFORTDIR=\"${COOKIEDIR}\"") +IF ("${NO_OFFENSIVE}") + ADD_DEFINITIONS("-DNO_OFFENSIVE=1") +ENDIF() + INCLUDE(CheckIncludeFile) CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H) diff --git a/fortune-mod/fortune/fortune.c b/fortune-mod/fortune/fortune.c index 2b20f13..639572e 100644 --- a/fortune-mod/fortune/fortune.c +++ b/fortune-mod/fortune/fortune.c @@ -253,7 +253,11 @@ static void __attribute__((noreturn)) usage(void) #ifndef NO_REGEX (void) fprintf(stderr, "i"); #endif /* NO_REGEX */ - (void) fprintf(stderr, "losw]"); + (void) fprintf(stderr, "l"); +#ifndef NO_OFFENSIVE + (void) fprintf(stderr, "o"); +#endif + (void) fprintf(stderr, "sw]"); #ifndef NO_REGEX (void) fprintf(stderr, " [-m pattern]"); #endif /* NO_REGEX */ @@ -1005,10 +1009,18 @@ static void getargs(int argc, char **argv) ignore_case = FALSE; #ifdef DEBUG - while ((ch = getopt(argc, argv, "acDefilm:n:osvw")) != EOF) +#define DEBUG_GETOPT "D" #else - while ((ch = getopt(argc, argv, "acefilm:n:osvw")) != EOF) -#endif /* DEBUG */ +#define DEBUG_GETOPT +#endif + +#ifdef NO_OFFENSIVE +#define OFFENSIVE_GETOPT +#else +#define OFFENSIVE_GETOPT "o" +#endif + + while ((ch = getopt(argc, argv, "ac" DEBUG_GETOPT "efilm:n:" OFFENSIVE_GETOPT "svw")) != EOF) switch (ch) { case 'a': /* any fortune */ @@ -1032,9 +1044,11 @@ static void getargs(int argc, char **argv) case 'n': SLEN = atoi(optarg); break; +#ifndef NO_OFFENSIVE case 'o': /* offensive ones only */ Offend++; break; +#endif case 's': /* short ones only */ Short_only++; Long_only = FALSE; -- 2.40.0