From d691c451ef2f03a5bd425ae374b3756c436d63d2 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 18 Aug 2020 15:02:39 +0300 Subject: [PATCH] Convert more manpages to DocBook 5 XML. post process the directory names. See: * https://github.com/shlomif/fortune-mod/issues/41 Made use of doclifter ( http://www.catb.org/~esr/doclifter/ ), docmake ( https://www.shlomifish.org/open-source/projects/docmake/ ), cmake, and Perl 5. Thanks! The current plan is to provide the resultant nroff outputs (or easily 's/.../.../'able templates of them) inside the source tarballs to avoid a build time dependency on DocBook XSL and docmake. --- fortune-mod/CMakeLists.txt | 8 +- .../fortune/process-fortune-man-template.pl | 73 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 fortune-mod/fortune/process-fortune-man-template.pl diff --git a/fortune-mod/CMakeLists.txt b/fortune-mod/CMakeLists.txt index 7d9a9e0..f190827 100644 --- a/fortune-mod/CMakeLists.txt +++ b/fortune-mod/CMakeLists.txt @@ -182,18 +182,22 @@ my_exe( 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/gen-fortune-man-page.pl") +SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/process-fortune-man-template.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_with_offensive.template.man") +ELSE() + SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_without_offensive.template.man") 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}" + DEPENDS "${_my_man_gen}" "${_MY_IN}" ) SET (_my_man_pages_list) diff --git a/fortune-mod/fortune/process-fortune-man-template.pl b/fortune-mod/fortune/process-fortune-man-template.pl new file mode 100644 index 0000000..5c80fe0 --- /dev/null +++ b/fortune-mod/fortune/process-fortune-man-template.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use autodie; + +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); + +sub _utf8_slurp +{ + my $filename = shift; + + open my $in, '<:encoding(utf8)', $filename + or die "Cannot open '$filename' for slurping - $!"; + + local $/; + my $contents = <$in>; + + close($in); + + return $contents; +} + +die if ( $text =~ s#\Q[[cookiedir_placeholder]]\E#${cookiedir}#gms ) > 1; +die if ( $text =~ s#\Q[[ocookiedir_placeholder]]\E#${ocookiedir}#gms ) > 1; +$out->print($text); +close($out); -- 2.40.0