3 # Self extracting help2man.h2m script.
5 # -q, --quiet Suppress extraction message
6 # -s, --stdout Extract to stdout
7 # -o, --output=FILE Extract to FILE
8 # -l, --locale=STRING Output file for locale STRING
9 # -m, --message-dir=DIR Directory for message catalogs
11 # Copyright (C) 2012, 2013, 2014 Free Software Foundation, Inc.
13 # Copying and distribution of this file, with or without modification,
14 # are permitted in any medium without royalty provided the copyright
15 # notice and this notice are preserved. This file is offered as-is,
16 # without any warranty.
18 # Written by Brendan O'Dea <bod@debian.org>
23 use POSIX qw(setlocale LC_ALL);
26 die "Usage: $0 [--quiet] [--stdout|--output=FILE] [--locale=STRING] ",
27 "[--message-dir=DIR]\n" unless GetOptions \%opts,
28 qw(quiet stdout output=s locale=s message-dir=s) and !@ARGV;
30 my $DOMAIN = 'help2man';
42 $target = $opts{output};
47 $target =~ s/\.PL$// or die "$0: can't determine target name\n";
50 $target =~ s/(\.[^.]*)$/.$opts{locale}$1/
51 or $target =~ s/$/.$opts{locale}/;
55 $tmp = "$target.tmp$$";
56 unlink $tmp or die "$0: can't unlink $tmp ($!)\n" if -e $tmp;
57 open OUT, ">$tmp" or die "$0: can't create $tmp ($!)\n";
60 my $msg = "Extracting $target";
61 $msg .= ' (with locale substitutions)' if $opts{locale};
62 print $msg, "\n" unless $opts{quiet};
67 delete @ENV{qw(LANGUAGE LC_MESSAGES LANG)};
68 setlocale LC_ALL, $ENV{LC_ALL} = $opts{locale};
70 require Locale::gettext;
71 require I18N::Langinfo;
73 my $gettext = Locale::gettext->domain($DOMAIN);
74 $gettext->dir($opts{'message-dir'}) if $opts{'message-dir'};
75 my $encoding = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
76 *_ = sub { Encode::encode($encoding, $gettext->get($_[0])) }
83 print OUT _('Include file for help2man man page'), "\n";
85 print OUT '--locale=', $opts{locale} || 'C', "\n";
88 print OUT '[', _('NAME'), "]\n";
89 print OUT _('help2man \- generate a simple manual page'), "\n";
92 print OUT '[', _('INCLUDE FILES'), "]\n";
94 Additional material may be included in the generated output with the
98 options. The format is simple:
108 print OUT _(<<'EOT');
109 Blocks of verbatim *roff text are inserted into the output either at
110 the start of the given
112 (case insensitive), or after a paragraph matching
117 print OUT _(<<'EOT');
118 Patterns use the Perl regular expression syntax and may be followed by
129 print OUT _(<<'EOT');
130 Lines before the first section or pattern which begin with `\-' are
131 processed as options. Anything else is silently ignored and may be
132 used for comments, RCS keywords and the like.
136 print OUT _('The section output order (for those included) is:'), "\n";
138 print OUT ' ', _('NAME'), "\n";
139 print OUT ' ', _('SYNOPSIS'), "\n";
140 print OUT ' ', _('DESCRIPTION'), "\n";
141 print OUT ' ', _('OPTIONS'), "\n";
142 print OUT ' ', _('ENVIRONMENT'), "\n";
143 print OUT ' ', _('FILES'), "\n";
144 print OUT ' ', _('EXAMPLES'), "\n";
145 print OUT ' \fI', _('other'), "\\fR\n";
146 print OUT ' ', _('AUTHOR'), "\n";
147 print OUT ' ', _('REPORTING BUGS'), "\n";
148 print OUT ' ', _('COPYRIGHT'), "\n";
149 print OUT ' ', _('SEE ALSO'), "\n";
152 print OUT _(<<'EOT');
157 sections appearing in the include file will replace what would have
158 automatically been produced (although you can still override the
165 print OUT _(<<'EOT');
166 Other sections are prepended to the automatically produced output for
167 the standard sections given above, or included at
169 (above) in the order they were encountered in the include file.
173 print OUT _(<<'EOT');
174 Placement of the text within the section may be explicitly requested by using
180 to place the additional text before, in place of, or after the default
185 print OUT '[', _('AVAILABILITY'), "]\n";
186 print OUT _('The latest version of this distribution is available on-line from:'), "\n";
188 print OUT " ftp://ftp.gnu.org/gnu/help2man/\n";
190 # Fix output file permissions
191 unless ($opts{stdout})
194 rename $tmp, $target or die "$0: can't rename $tmp to $target ($!)\n";
195 chmod 0444, $target or warn "$0: can't change mode of $target ($!)\n";