]> granicus.if.org Git - fortune-mod/commitdiff
Convert more manpages to DocBook 5 XML.
authorShlomi Fish <shlomif@shlomifish.org>
Sat, 15 Aug 2020 15:44:15 +0000 (18:44 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Sat, 15 Aug 2020 15:44:15 +0000 (18:44 +0300)
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/gen-randstr-manpage.pl [new file with mode: 0644]
fortune-mod/util/randstr.docbook5.xml [new file with mode: 0644]
fortune-mod/util/randstr.man [deleted file]

index 54818123064ee8b4664cd4d62e55f9222dc934c3..8a285fdc1b7ab4bfcb73ff67c3e42bfab8eab77c 100644 (file)
@@ -210,11 +210,25 @@ 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_man_docbook}"
 )
 
 LIST(APPEND _my_man_pages_list "${_my_man_page}")
 INSTALL_RENAME_MAN("strfile.man" "1" "strfile" "${_my_man_page_dir}")
+
+SET (_my_man_page_dir "${CMAKE_CURRENT_SOURCE_DIR}/util")
+SET (_my_man_page "${_my_man_page_dir}/randstr.man")
+SET (_my_man_docbook "${_my_man_page_dir}/randstr.docbook5.xml")
+SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/gen-randstr-manpage.pl")
+SET (_my_args "--src-dir" "${CMAKE_CURRENT_SOURCE_DIR}")
+ADD_CUSTOM_COMMAND(
+    OUTPUT "${_my_man_page}"
+    COMMAND "${PERL_EXECUTABLE}"
+    ARGS "${_my_man_gen}" ${_my_args}
+    DEPENDS "${_my_man_gen}" "${_my_man_docbook}"
+)
+
+LIST(APPEND _my_man_pages_list "${_my_man_page}")
 ADD_CUSTOM_TARGET(
     generate_man_page
     ALL DEPENDS ${_my_man_pages_list}
diff --git a/fortune-mod/fortune/gen-randstr-manpage.pl b/fortune-mod/fortune/gen-randstr-manpage.pl
new file mode 100644 (file)
index 0000000..05e0cf5
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+
+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;
+}
+
+my $output_fn;
+my $cookiedir;
+my $ocookiedir;
+my $no_offensive = 0;
+my $CMAKE_CURRENT_SOURCE_DIR;
+GetOptions(
+    '--src-dir=s'          => \$CMAKE_CURRENT_SOURCE_DIR,
+    '--cookiedir=s'        => \$cookiedir,
+    '--ocookiedir=s'       => \$ocookiedir,
+    '--without-offensive!' => \$no_offensive,
+    '--output=s'           => \$output_fn,
+) or die "Wrong options - $!";
+
+die "missing --src-dir" if ( not $CMAKE_CURRENT_SOURCE_DIR );
+__PACKAGE__->do_system(
+    {
+        cmd => [
+            "docmake", "manpages",
+            "${CMAKE_CURRENT_SOURCE_DIR}/util/randstr.docbook5.xml",
+        ],
+    },
+);
+
+path("${CMAKE_CURRENT_SOURCE_DIR}/util/randstr.man")
+    ->spew_utf8(
+    cwd()->child("randstr.1")->slurp_utf8() =~ s#^\s+(\.RE|\.PP)\s*$#$1#gmsr =~
+        s#^\s+$##gmsr );
diff --git a/fortune-mod/util/randstr.docbook5.xml b/fortune-mod/util/randstr.docbook5.xml
new file mode 100644 (file)
index 0000000..5a32fc1
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- lifted from man+troff by doclifter -->
+<refentry xmlns='http://docbook.org/ns/docbook' version='5.0' xml:lang='en' xml:id='randstrman'>
+
+<!-- Randstr: grab a random text string from a specified text file
+Amy A. Lewis, October, 1995 -->
+
+<refmeta>
+<refentrytitle>RANDSTR</refentrytitle>
+<manvolnum>1</manvolnum>
+<refmiscinfo class='source'>October 1995</refmiscinfo>
+<refmiscinfo class='manual'>Linux hackery</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>randstr</refname>
+<refpurpose>fetch a random text string from a specified file</refpurpose>
+</refnamediv>
+<!-- body begins here -->
+
+<refsect1 xml:id='synopis'><title>SYNOPIS</title>
+<para><emphasis role='strong' remap='B'>randstr </emphasis><emphasis remap='I'>filename</emphasis></para>
+</refsect1>
+
+<refsect1 xml:id='description'><title>DESCRIPTION</title>
+<para>In essence,
+<emphasis role='strong' remap='B'>randstr</emphasis>
+is a stripped-down, minimalist version of the popular
+<citerefentry><refentrytitle>fortune</refentrytitle><manvolnum>6</manvolnum></citerefentry>
+program.</para>
+
+<para>It reads files with the same structure as the fortunes databases, and
+displays a random string.</para>
+
+<refsect2 xml:id='usage'><title>Usage</title>
+<para><emphasis role='strong' remap='B'>randstr</emphasis>
+might be used, with a database of signatures created with a text editor
+and the
+<citerefentry><refentrytitle>strfile</refentrytitle><manvolnum>8</manvolnum></citerefentry> and <citerefentry><refentrytitle>unstr</refentrytitle><manvolnum>8</manvolnum></citerefentry>
+utilities, to randomly change the
+<emphasis remap='I'>$HOME/.signature</emphasis>
+file.  To do so, create the necessary database as, for example,
+<emphasis remap='I'>signatures</emphasis> and <emphasis remap='I'>signatures.dat</emphasis>
+in the home directory, and add the following line to
+<markup>.profile</markup> or <markup>.login</markup>:</para>
+  <blockquote remap='RS'>
+<para><emphasis role='strong' remap='B'>randstr </emphasis><emphasis remap='I'>signatures</emphasis>
+&gt;<markup>.signature</markup>
+  </para></blockquote> <!-- remap='RE' -->
+
+<para>As superuser, a similar sort of thing could be placed in the
+<citerefentry><refentrytitle>Pnews</refentrytitle><manvolnum>1</manvolnum></citerefentry> or <citerefentry><refentrytitle>Rnmail</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+scripts, although it should certainly test to be certain that the files
+exist, and creating the files of signatures might require a good deal of
+help for a lot of users.</para>
+
+<para>Also as superuser, one might use
+<emphasis role='strong' remap='B'>randstr</emphasis>
+with a shell or
+<emphasis role='strong' remap='B'>Perl</emphasis>
+script to read the
+<emphasis remap='I'>etc/passwd</emphasis>
+database and create a
+<emphasis remap='I'>strfile</emphasis>
+type database, and use this database to run a monthly lottery.</para>
+</refsect2>
+</refsect1>
+
+<refsect1 xml:id='bugs'><title>BUGS</title>
+<para>None known.</para>
+</refsect1>
+
+<refsect1 xml:id='see_also'><title>SEE ALSO</title>
+<para><citerefentry><refentrytitle>fortune</refentrytitle><manvolnum>6</manvolnum></citerefentry>, <citerefentry><refentrytitle>strfile</refentrytitle><manvolnum>1</manvolnum></citerefentry></para>
+</refsect1>
+</refentry>
+
diff --git a/fortune-mod/util/randstr.man b/fortune-mod/util/randstr.man
deleted file mode 100644 (file)
index f55581f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-.\"
-.\" Randstr: grab a random text string from a specified text file
-.\" Amy A. Lewis, October, 1995
-.\"
-.TH RANDSTR 1 "October 1995" "Linux hackery"
-.SH NAME
-randstr \- fetch a random text string from a specified file
-.SH SYNOPIS
-.BI "randstr " filename
-.SH DESCRIPTION
-In essence,
-.B randstr
-is a stripped-down, minimalist version of the popular
-.BR fortune (6)
-program.
-.PP
-It reads files with the same structure as the fortunes databases, and
-displays a random string.
-.SS Usage
-.B randstr
-might be used, with a database of signatures created with a text editor
-and the
-.BR strfile "(8) and " unstr (8)
-utilities, to randomly change the
-.I $HOME/.signature
-file.  To do so, create the necessary database as, for example,
-.IR signatures " and " signatures.dat
-in the home directory, and add the following line to
-.IR .profile " or " .login :
-.RS
-.BI "randstr " signatures
-.RI > .signature
-.RE
-.PP
-As superuser, a similar sort of thing could be placed in the
-.BR Pnews "(1) or " Rnmail (1)
-scripts, although it should certainly test to be certain that the files
-exist, and creating the files of signatures might require a good deal of
-help for a lot of users.
-.PP
-Also as superuser, one might use
-.B randstr
-with a shell or
-.B Perl
-script to read the
-.I etc/passwd
-database and create a
-.I strfile
-type database, and use this database to run a monthly lottery.
-.SH BUGS
-None known.
-.SH SEE ALSO
-.BR fortune "(6), " strfile (1)