summaryrefslogtreecommitdiff
path: root/help2man.h2m.PL
diff options
context:
space:
mode:
authorBrendan O'Dea <bod@debian.org>2010-03-14 22:05:05 +1100
committerBrendan O'Dea <bod@debian.org>2010-03-14 22:05:05 +1100
commit5994a1513c9abe639412380e89051eadf2c76c50 (patch)
tree919537ee5fb8f642394f7f29259b444e78404397 /help2man.h2m.PL
parentdaad40c9912d93769c54e2b0a68dcb125a6f36cc (diff)
downloadhelp2man-5994a1513c9abe639412380e89051eadf2c76c50.tar.gz
generate help2man.h2m, to simplify translation
Diffstat (limited to 'help2man.h2m.PL')
-rwxr-xr-x[-rw-r--r--]help2man.h2m.PL142
1 files changed, 120 insertions, 22 deletions
diff --git a/help2man.h2m.PL b/help2man.h2m.PL
index 0e07c9e..fc8010b 100644..100755
--- a/help2man.h2m.PL
+++ b/help2man.h2m.PL
@@ -1,11 +1,78 @@
-Include file for help2man man page
+#!/usr/bin/perl
---locale=C
+#
+# Self extracting help2man.h2m script.
+#
+# -q, --quiet Suppress extraction message
+# -s, --stdout Extract to stdout
+# -l, --locale=STRING Output file for locale STRING
+# -m, --message-dir=DIR Directory for message catalogs
+#
-[name]
-help2man \- generate a simple manual page
+use 5.008;
+use Config;
+use Getopt::Long;
+use POSIX qw(setlocale LC_ALL);
-[include files]
+my %opts;
+die "Usage: $0 [--quiet] [--stdout] [--locale=STRING] [--message-dir=DIR]\n"
+ unless GetOptions \%opts, qw(quiet stdout locale=s message-dir=s) and !@ARGV;
+
+my $DOMAIN = 'help2man';
+my $target = $0;
+if ($opts{stdout})
+{
+ *OUT = *STDOUT;
+ $opts{quiet} = 1;
+}
+else
+{
+ $target =~ s!.*/!!;
+ $target =~ s/\.PL$// or die "$0: can't determine target name\n";
+ if ($opts{locale})
+ {
+ $target =~ s/(\.[^.]*)$/.$opts{locale}$1/
+ or $target =~ s/$/.$opts{locale}/;
+ }
+
+ unlink $target or die "$0: can't unlink $target ($!)\n" if -e $target;
+ open OUT, ">$target" or die "$0: can't create $target ($!)\n";
+}
+
+my $msg = "Extracting $target";
+$msg .= " (with locale substitutions)" if $opts{locale};
+print $msg, "\n" unless $opts{quiet};
+
+sub _;
+if ($opts{locale})
+{
+ delete @ENV{qw(LANGUAGE LC_MESSAGES LANG)};
+ setlocale LC_ALL, $ENV{LC_ALL} = $opts{locale};
+
+ require Locale::gettext;
+ require I18N::Langinfo;
+ require Encode;
+ my $gettext = Locale::gettext->domain($DOMAIN);
+ $gettext->dir($opts{'message-dir'}) if $opts{'message-dir'};
+ my $encoding = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
+ *_ = sub { Encode::encode($encoding, $gettext->get($_[0])) }
+}
+else
+{
+ *_ = sub { $_[0] }
+}
+
+print OUT _("Include file for help2man man page\n");
+print OUT "\n";
+print OUT "--locale=", $opts{locale} || 'C', "\n";
+print OUT "\n";
+
+print OUT '[', _('NAME'), "]\n";
+print OUT _('help2man \- generate a simple manual page'), "\n";
+print OUT "\n";
+
+print OUT '[', _('INCLUDE FILES'), "]\n";
+print OUT _(<<'EOT');
Additional material may be included in the generated output with the
.B \-\-include
and
@@ -18,12 +85,18 @@ options. The format is simple:
/pattern/
text
+EOT
+
+print OUT _(<<'EOT');
Blocks of verbatim *roff text are inserted into the output either at
the start of the given
.BI [ section ]
(case insensitive), or after a paragraph matching
.BI / pattern /\fR.
+EOT
+
+print OUT _(<<'EOT');
Patterns use the Perl regular expression syntax and may be followed by
the
.IR i ,
@@ -33,41 +106,66 @@ or
modifiers (see
.BR perlre (1)).
+EOT
+
+print OUT _(<<'EOT');
Lines before the first section or pattern which begin with `\-' are
processed as options. Anything else is silently ignored and may be
used for comments, RCS keywords and the like.
-The section output order (for those included) is:
-
- NAME
- SYNOPSIS
- DESCRIPTION
- OPTIONS
- ENVIRONMENT
- FILES
- EXAMPLES
- \fIother\fR
- AUTHOR
- REPORTING BUGS
- COPYRIGHT
- SEE ALSO
+EOT
+
+print OUT "The section output order (for those included) is:\n";
+print OUT "\n";
+print OUT " ", _('NAME'), "\n";
+print OUT " ", _('SYNOPSIS'), "\n";
+print OUT " ", _('DESCRIPTION'), "\n";
+print OUT " ", _('OPTIONS'), "\n";
+print OUT " ", _('ENVIRONMENT'), "\n";
+print OUT " ", _('FILES'), "\n";
+print OUT " ", _('EXAMPLES'), "\n";
+print OUT " ", _('\fIother\fR'), "\n";
+print OUT " ", _('AUTHOR'), "\n";
+print OUT " ", _('REPORTING BUGS'), "\n";
+print OUT " ", _('COPYRIGHT'), "\n";
+print OUT " ", _('SEE ALSO'), "\n";
+print OUT "\n";
+print OUT _(<<'EOT');
Any
-.B [name]
+.B [NAME]
or
-.B [synopsis]
+.B [SYNOPSIS]
sections appearing in the include file will replace what would have
automatically been produced (although you can still override the
former with
.B --name
if required).
+EOT
+
+print OUT _(<<'EOT');
Other sections are prepended to the automatically produced output for
the standard sections given above, or included at
.I other
(above) in the order they were encountered in the include file.
-[availability]
+EOT
+
+print OUT '[', _('AVAILABILITY'), "]\n";
+print OUT _(<<'EOT');
The latest version of this distribution is available on-line from:
ftp://ftp.gnu.org/gnu/help2man/
+EOT
+
+# Fix permissions and set timestamps to match the source
+unless ($opts{stdout})
+{
+ close OUT;
+ chmod 0444, $target or warn "$0: can't change mode of $target ($!)\n";
+ utime +(stat DATA)[8,9], $target
+ or warn "$0: can't set time of $target ($!)\n";
+}
+
+exit 0;