diff --git a/fortune-mod/CMakeLists.txt b/fortune-mod/CMakeLists.txt index 8b28821..0436fa3 100644 --- a/fortune-mod/CMakeLists.txt +++ b/fortune-mod/CMakeLists.txt @@ -199,81 +199,45 @@ my_exe( "bin" ) -SET (_my_man_page_dir "${CMAKE_CURRENT_BINARY_DIR}/manpages") -SET (_my_man_page "${_my_man_page_dir}/fortune.6") -SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/process-fortune-man-template.pl") +SET (_my_man_page "${CMAKE_CURRENT_BINARY_DIR}/fortune.docbook5.xml") +SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/gen-fortune-docbook-page.pl") SET (_my_args) -LIST(APPEND _my_args "--cookiedir" "${COOKIEDIR}" "--ocookiedir" "${OCOOKIEDIR}" "--output" "${_my_man_page}") -IF (NO_OFFENSIVE) - LIST(APPEND _my_args "--without-offensive") - SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_without_offensive.template.man") -ELSE() - SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_with_offensive.template.man") +LIST(APPEND _my_args "--cookiedir" "${COOKIEDIR}" ">" "${_my_man_page}") +IF (NOT NO_OFFENSIVE) + LIST(APPEND _my_args "--ocookiedir=${OCOOKIEDIR}") ENDIF() -LIST(APPEND _my_args "--input" "${_MY_IN}") ADD_CUSTOM_COMMAND( OUTPUT "${_my_man_page}" COMMAND "${PERL_EXECUTABLE}" ARGS "${_my_man_gen}" ${_my_args} - DEPENDS "${_my_man_gen}" "${_MY_IN}" + DEPENDS "${_my_man_gen}" ) SET (_my_man_pages_list) -LIST(APPEND _my_man_pages_list "${_my_man_page}") - -INSTALL_RENAME_MAN("fortune.6" "6" "fortune" "${_my_man_page_dir}") +MACRO(_fortune__generate_manpage _my_man_page_dir basename section installed) -SET (_util_dir "${CMAKE_CURRENT_SOURCE_DIR}/util") -MACRO(_fortune__generate_docbook basename offensive_flags) - - SET (_my_man_page_dir "${CMAKE_CURRENT_SOURCE_DIR}/fortune") - SET (_dest_basename "${basename}.template") - SET (_my_man_page "${_my_man_page_dir}/${_dest_basename}.man") + SET (_my_man_page "${CMAKE_CURRENT_BINARY_DIR}/${basename}.${section}") SET (_my_man_docbook "${_my_man_page_dir}/${basename}.docbook5.xml") - SET (_my_man_prog "${_my_man_page_dir}/gen-fortune-docbook-page.pl") - SET (_my_args "${_my_man_prog}" "--output" "${_my_man_docbook}" --cookiedir "[[cookiedir_placeholder]]" --ocookiedir "[[ocookiedir_placeholder]]" ${offensive_flags}) - ADD_CUSTOM_COMMAND( - OUTPUT "${_my_man_docbook}" - COMMAND "${PERL_EXECUTABLE}" - ARGS ${_my_args} - DEPENDS "${_my_man_prog}" - ) - - LIST(APPEND _my_man_pages_list "${_my_man_docbook}") - SET (_my_args "-I${_util_dir}" "${_util_dir}/fortmod_gen_manpage.pl" "--src-dir" "${CMAKE_CURRENT_SOURCE_DIR}" "--basename=${basename}" "--dest-basename=${_dest_basename}" "--out-section=6" "--out-basename=fortune" "--subdir=fortune") ADD_CUSTOM_COMMAND( OUTPUT "${_my_man_page}" - COMMAND "${PERL_EXECUTABLE}" - ARGS ${_my_args} - DEPENDS "${_my_man_docbook}" - ) - - LIST(APPEND _my_man_pages_list "${_my_man_page}") -ENDMACRO() - -_fortune__generate_docbook("fortune_with_offensive" "") -_fortune__generate_docbook("fortune_without_offensive" "--without-offensive") - -MACRO(_fortune__generate_manpage basename) - - SET (_my_man_page_dir "${CMAKE_CURRENT_SOURCE_DIR}/util") - SET (_my_man_page "${_my_man_page_dir}/${basename}.man") - SET (_my_man_docbook "${_my_man_page_dir}/${basename}.docbook5.xml") - SET (_my_args "-I${_util_dir}" "${_util_dir}/fortmod_gen_manpage.pl" "--src-dir" "${CMAKE_CURRENT_SOURCE_DIR}" "--basename=${basename}") - ADD_CUSTOM_COMMAND( - OUTPUT "${_my_man_page}" - COMMAND "${PERL_EXECUTABLE}" - ARGS ${_my_args} + COMMAND "docbook2x-man" "${_my_man_docbook}" "--to-stdout" + ">" "${_my_man_page}" DEPENDS "${_my_man_docbook}" ) LIST(APPEND _my_man_pages_list "${_my_man_page}") + if(${installed}) + install( + FILES "${_my_man_page}" + DESTINATION "${CMAKE_INSTALL_MANDIR}/man${section}" + ) + endif() ENDMACRO() -_fortune__generate_manpage("strfile") -INSTALL_RENAME_MAN("strfile.man" "1" "strfile" "${_my_man_page_dir}") -_fortune__generate_manpage("randstr") +_fortune__generate_manpage("${CMAKE_CURRENT_BINARY_DIR}" fortune 6 ON) +_fortune__generate_manpage("${CMAKE_CURRENT_SOURCE_DIR}/util" strfile 1 ON) +_fortune__generate_manpage("${CMAKE_CURRENT_SOURCE_DIR}/util" randstr 1 OFF) ADD_CUSTOM_TARGET( generate_man_page diff --git a/fortune-mod/fortune/gen-fortune-docbook-page.pl b/fortune-mod/fortune/gen-fortune-docbook-page.pl index f0aa960..bbba315 100644 --- a/fortune-mod/fortune/gen-fortune-docbook-page.pl +++ b/fortune-mod/fortune/gen-fortune-docbook-page.pl @@ -4,49 +4,24 @@ use warnings; use autodie; use utf8; - -use File::Basename qw / dirname /; -use File::Path qw / mkpath /; use Getopt::Long qw/ GetOptions /; -my $output_fn; my $cookiedir; my $ocookiedir; -my $no_offensive = 0; GetOptions( '--cookiedir=s' => \$cookiedir, '--ocookiedir=s' => \$ocookiedir, - '--without-offensive!' => \$no_offensive, - '--output=s' => \$output_fn, ) or die "Wrong options - $!"; -if ( !defined($output_fn) ) -{ - die "Please specify --output"; -} - if ( !defined($cookiedir) ) { die "Please specify cookiedir"; } -my $OFF = ( !$no_offensive ); - -if ( $OFF and !defined($ocookiedir) ) -{ - die "Please specify ocookiedir"; -} - -my $dirname = dirname($output_fn); -if ( $dirname and ( !-e $dirname ) ) -{ - mkpath($dirname); -} - # The :raw is to prevent CRs on Win32/etc. -open my $out, '>:raw:encoding(utf-8)', $output_fn; +binmode STDOUT, ":raw:encoding(utf-8)"; -$out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING'; @@ -127,14 +102,14 @@ is run with no arguments it prints out a random epigram. Epigrams are END_OF_STRING -$out->print( - $OFF +print( + $ocookiedir ? "divided into several categories, where each category is sub-divided into those which are potentially offensive and those which are not." : "divided into several categories." ); -$out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING'; Options @@ -146,8 +121,8 @@ END_OF_STRING -$out->print( - $OFF +print( + $ocookiedir ? <<'EOF' Choose from all lists of maxims, both offensive and not. (See the -o @@ -158,7 +133,7 @@ EOF ); -$out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING'; @@ -229,9 +204,7 @@ END_OF_STRING -if ($OFF) -{ - $out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING' if $ocookiedir; @@ -264,9 +237,8 @@ END_OF_STRING -} -$out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING'; -s @@ -360,9 +332,7 @@ END_OF_STRING -if ($OFF) -{ - $out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING' if $ocookiedir; This fortune also supports the BSD method of appending “-o” to @@ -391,9 +361,8 @@ END_OF_STRING -} -$out->print(<<"END_OF_STRING"); +print <<"END_OF_STRING"; @@ -408,16 +377,13 @@ END_OF_STRING -if ($OFF) -{ - $out->print(<<"EOF"); +print <<"EOF" if $ocookiedir; ${ocookiedir} Directory for offensive fortunes. EOF -} -$out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING'; If a particular set of fortunes is particularly unwanted, there is an @@ -432,9 +398,7 @@ BUGS END_OF_STRING -if ($OFF) -{ - $out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING' if $ocookiedir; The division of fortunes into offensive and non-offensive by directory, rather than via the `-o' file infix, is not 100% compatible with original BSD fortune. Although the `-o' infix is recognised as referring @@ -446,9 +410,8 @@ option. END_OF_STRING -} -$out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING'; The supplied fortune databases have been attacked, in order to correct orthographical and grammatical errors, and particularly to reduce redundancy and repetition and redundancy. But especially to avoid @@ -457,12 +420,11 @@ The fortune databases are now divided into a larger number of smaller files, some organized by format (poetry, definitions), and some by +content (religion, politics). END_OF_STRING -$out->print( - $OFF - ? <<'EOF' -content (religion, politics). There are parallel files in the main +print <<'EOF' if $ocookiedir; +There are parallel files in the main directory and in the offensive files directory (e.g., fortunes/definitions and fortunes/off/definitions). Not all the potentially offensive fortunes are in the offensive fortunes files, nor are all the fortunes in the offensive @@ -470,12 +432,8 @@ made to achieve greater consistency. Also, a better division might be made. EOF - : <<'EOF' -content (religion, politics). -EOF -); -$out->print(<<'END_OF_STRING'); +print <<'END_OF_STRING'; @@ -522,5 +480,3 @@ END_OF_STRING - -close($out); diff --git a/fortune-mod/fortune/process-fortune-man-template.pl b/fortune-mod/fortune/process-fortune-man-template.pl deleted file mode 100644 index 84e8c03..0000000 --- a/fortune-mod/fortune/process-fortune-man-template.pl +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use autodie; - -sub _utf8_slurp -{ - my $filename = shift; - - open my $in, '<:encoding(utf-8)', $filename - or die "Cannot open '$filename' for slurping - $!"; - - local $/; - my $contents = <$in>; - - close($in); - - return $contents; -} - -use File::Basename qw / dirname /; -use File::Path qw / mkpath /; -use Getopt::Long qw/ GetOptions /; - -my $input_fn; -my $output_fn; -my $cookiedir; -my $ocookiedir; -my $no_offensive = 0; -GetOptions( - '--cookiedir=s' => \$cookiedir, - '--ocookiedir=s' => \$ocookiedir, - '--without-offensive!' => \$no_offensive, - '--output=s' => \$output_fn, - '--input=s' => \$input_fn, -) or die "Wrong options - $!"; - -if ( !defined($input_fn) ) -{ - die "Please specify --input"; -} -if ( !defined($output_fn) ) -{ - die "Please specify --output"; -} - -if ( !defined($cookiedir) ) -{ - die "Please specify cookiedir"; -} - -my $OFF = ( !$no_offensive ); - -if ( $OFF and !defined($ocookiedir) ) -{ - die "Please specify ocookiedir"; -} - -my $dirname = dirname($output_fn); -if ( $dirname and ( !-e $dirname ) ) -{ - mkpath($dirname); -} - -# The :raw is to prevent CRs on Win32/etc. -open my $out, '>:encoding(utf-8)', $output_fn; -my $text = _utf8_slurp($input_fn); - -if ( ( $text =~ s#\Q[[cookiedir_placeholder]]\E#${cookiedir}#gms ) > 1 ) -{ - die "too many cookiedir_placeholder substitutions!"; -} -if ( ( $text =~ s#\Q[[ocookiedir_placeholder]]\E#${ocookiedir}#gms ) > 1 ) -{ - die "too many ocookiedir_placeholder substitutions!"; -} -$out->print($text); -close($out); diff --git a/fortune-mod/util/FortuneMod/ManPage/Generate/App.pm b/fortune-mod/util/FortuneMod/ManPage/Generate/App.pm deleted file mode 100644 index 92e6586..0000000 --- a/fortune-mod/util/FortuneMod/ManPage/Generate/App.pm +++ /dev/null @@ -1,85 +0,0 @@ -package FortuneMod::ManPage::Generate::App; - -use strict; -use warnings; -use autodie; - -use Getopt::Long qw/ GetOptions /; -use Path::Tiny qw/ path tempdir tempfile cwd /; - -sub do_system -{ - my ( $self, $args ) = @_; - - my $cmd = $args->{cmd}; - print "Running [@$cmd]\n"; - if ( system(@$cmd) ) - { - die "Running [@$cmd] failed!"; - } - - return; -} - -sub run -{ - my $self = shift; - my $CMAKE_CURRENT_SOURCE_DIR; - my $basename; - my $dest_basename; - my $out_basename; - my $out_section = '1'; - my $subdir = 'util'; - GetOptions( - '--basename=s' => \$basename, - '--dest-basename=s' => \$dest_basename, - '--out-basename=s' => \$out_basename, - '--out-section=s' => \$out_section, - '--src-dir=s' => \$CMAKE_CURRENT_SOURCE_DIR, - '--subdir=s' => \$subdir, - ) or die "Wrong options - $!"; - $dest_basename = $basename if ( not defined $dest_basename ); - $out_basename = $basename if ( not defined $out_basename ); - - die "missing --src-dir" if ( not $CMAKE_CURRENT_SOURCE_DIR ); - { - local %ENV = %ENV; - if ( my $path_prefix = delete( $ENV{DOCMAKE_PATH_PREFIX} ) ) - { - $ENV{PATH} = $path_prefix . $ENV{PATH}; - } - my @args = ( - "manpages", - "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/${basename}.docbook5.xml", - ); - eval { - require App::Docmake; - local @ARGV = @args; - if ( App::Docmake->new( { argv => [@ARGV] } )->run() ) - { - warn "could not invoke App::Docmake :: run() properly"; - die; - } - }; - my $Err = $@; - if ($Err) - { - warn "App::Docmake from CPAN malfunctioned. $@"; - __PACKAGE__->do_system( - { - cmd => [ "docmake", @args, ], - }, - ); - } - } - - path("${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/${dest_basename}.man") - ->spew_utf8( - cwd()->child("${out_basename}.${out_section}")->slurp_utf8() =~ - s#^[\t ]+(\.RE|\.PP)[\t ]*$#$1#gmrs =~ s#^[\t ]+$##gmrs =~ - s#\n\n+#\n\n#gmrs ); - - return; -} - -1; diff --git a/fortune-mod/util/fortmod_gen_manpage.pl b/fortune-mod/util/fortmod_gen_manpage.pl deleted file mode 100644 index cd61e77..0000000 --- a/fortune-mod/util/fortmod_gen_manpage.pl +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env perl -# -# Short description for fortmod_gen_manpage.pl -# -# Version 0.0.1 -# Copyright (C) 2020 Shlomi Fish < https://www.shlomifish.org/ > -# -# Licensed under the terms of the MIT license. - -use strict; -use warnings; -use 5.014; -use autodie; - -use Path::Tiny qw/ path tempdir tempfile cwd /; - -use FortuneMod::ManPage::Generate::App (); - -FortuneMod::ManPage::Generate::App->run();