]> granicus.if.org Git - fortune-mod/commitdiff
Convert more manpages to DocBook 5 XML.
authorShlomi Fish <shlomif@shlomifish.org>
Tue, 18 Aug 2020 12:02:39 +0000 (15:02 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Wed, 16 Sep 2020 11:00:36 +0000 (14:00 +0300)
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
fortune-mod/fortune/process-fortune-man-template.pl [new file with mode: 0644]

index 7d9a9e0dea1e37d080445950779f83b42e099129..f1908273fa9c2691f2da50f006b9edeb44c5fc22 100644 (file)
@@ -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 (file)
index 0000000..5c80fe0
--- /dev/null
@@ -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);