Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 19 additions & 55 deletions fortune-mod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 20 additions & 64 deletions fortune-mod/fortune/gen-fortune-docbook-page.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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';
<?xml version="1.0" encoding="UTF-8"?>
<!-- lifted from man+troff by doclifter -->
<refentry version='5.0' xml:lang='en' xml:id='fortune'>
Expand Down Expand Up @@ -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';
</para>

<refsect2 xml:id='options'><title>Options</title>
Expand All @@ -146,8 +121,8 @@

END_OF_STRING

$out->print(
$OFF
print(
$ocookiedir
? <<'EOF'
<para>Choose from all lists of maxims, both offensive and not. (See the
<emphasis role='strong' remap='B'>-o</emphasis>
Expand All @@ -158,7 +133,7 @@
EOF
);

$out->print(<<'END_OF_STRING');
print <<'END_OF_STRING';
</listitem>
</varlistentry>
<varlistentry>
Expand Down Expand Up @@ -229,9 +204,7 @@

END_OF_STRING

if ($OFF)
{
$out->print(<<'END_OF_STRING');
print <<'END_OF_STRING' if $ocookiedir;

<varlistentry>
<term>
Expand Down Expand Up @@ -264,9 +237,8 @@
</varlistentry>

END_OF_STRING
}

$out->print(<<'END_OF_STRING');
print <<'END_OF_STRING';
<varlistentry>
<term>
<emphasis role='strong' remap='B'>-s</emphasis>
Expand Down Expand Up @@ -360,9 +332,7 @@
</para></blockquote> <!-- remap='RE' -->
END_OF_STRING

if ($OFF)
{
$out->print(<<'END_OF_STRING');
print <<'END_OF_STRING' if $ocookiedir;


<para>This fortune also supports the BSD method of appending “-o” to
Expand Down Expand Up @@ -391,9 +361,8 @@
</para></blockquote> <!-- remap='RE' -->

END_OF_STRING
}

$out->print(<<"END_OF_STRING");
print <<"END_OF_STRING";

</refsect2>
</refsect1>
Expand All @@ -408,16 +377,13 @@

END_OF_STRING

if ($OFF)
{
$out->print(<<"EOF");
print <<"EOF" if $ocookiedir;

<para><emphasis remap='I'>${ocookiedir}</emphasis>
Directory for offensive fortunes.</para>
EOF
}

$out->print(<<'END_OF_STRING');
print <<'END_OF_STRING';
<!-- PD -->

<para>If a particular set of fortunes is particularly unwanted, there is an
Expand All @@ -432,9 +398,7 @@
<refsect1 xml:id='bugs'><title>BUGS</title>
END_OF_STRING

if ($OFF)
{
$out->print(<<'END_OF_STRING');
print <<'END_OF_STRING' if $ocookiedir;
<para>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
Expand All @@ -446,9 +410,8 @@
option.</para>

END_OF_STRING
}

$out->print(<<'END_OF_STRING');
print <<'END_OF_STRING';
<para>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
Expand All @@ -457,25 +420,20 @@

<para>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
files potentially offensive, probably, though a strong attempt has been
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';

</para>

Expand Down Expand Up @@ -522,5 +480,3 @@
</refentry>

END_OF_STRING

close($out);
79 changes: 0 additions & 79 deletions fortune-mod/fortune/process-fortune-man-template.pl

This file was deleted.

Loading