Debian Codegraph @

man/help2man

raw
1 #!/usr/bin/perl -w
2
3 # Generate a short man page from --help and --version output.
4 # Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009,
5 # 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, see <https://www.gnu.org/licenses/>.
19
20 # Written by Brendan O'Dea <[email protected]>
21 # Available from https://ftp.gnu.org/gnu/help2man/
22
23 use 5.008;
24 use strict;
25 use Getopt::Long;
26 use Text::ParseWords qw(shellwords);
27 use Text::Tabs qw(expand);
28 use POSIX qw(strftime setlocale LC_ALL);
29
30 my $this_program = 'help2man';
31 my $this_version = '1.47.3';
32
33 sub _ { $_[0] }
34 sub configure_locale
35 {
36 my $locale = shift;
37 die "$this_program: no locale support (Locale::gettext required)\n"
38 unless $locale eq 'C';
39 }
40
41 sub dec { $_[0] }
42 sub enc { $_[0] }
43 sub enc_user { $_[0] }
44 sub kark { die +(sprintf shift, @_), "\n" }
45 sub N_ { $_[0] }
46
47 sub program_basename;
48 sub get_option_value;
49 sub convert_option;
50 sub fix_italic_spacing;
51
52 my $version_info = enc_user sprintf _(<<'EOT'), $this_program, $this_version;
53 GNU %s %s
54
55 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009, 2010,
56 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.
57 This is free software; see the source for copying conditions. There is NO
58 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
59
60 Written by Brendan O'Dea <[email protected]>
61 EOT
62
63 my $help_info = enc_user sprintf _(<<'EOT'), $this_program, $this_program;
64 `%s' generates a man page out of `--help' and `--version' output.
65
66 Usage: %s [OPTION]... EXECUTABLE
67
68 -n, --name=STRING description for the NAME paragraph
69 -s, --section=SECTION section number for manual page (1, 6, 8)
70 -m, --manual=TEXT name of manual (User Commands, ...)
71 -S, --source=TEXT source of program (FSF, Debian, ...)
72 -L, --locale=STRING select locale (default "C")
73 -i, --include=FILE include material from `FILE'
74 -I, --opt-include=FILE include material from `FILE' if it exists
75 -o, --output=FILE send output to `FILE'
76 -p, --info-page=TEXT name of Texinfo manual
77 -N, --no-info suppress pointer to Texinfo manual
78 -l, --libtool exclude the `lt-' from the program name
79 --help print this help, then exit
80 --version print version number, then exit
81
82 EXECUTABLE should accept `--help' and `--version' options and produce output on
83 stdout although alternatives may be specified using:
84
85 -h, --help-option=STRING help option string
86 -v, --version-option=STRING version option string
87 --version-string=STRING version string
88 --no-discard-stderr include stderr when parsing option output
89
90 Report bugs to <[email protected]>.
91 EOT
92
93 my $section = 1;
94 my $manual = '';
95 my $source = '';
96 my $help_option = '--help';
97 my $version_option = '--version';
98 my $discard_stderr = 1;
99 my ($opt_name, @opt_include, $opt_output, $opt_info, $opt_no_info, $opt_libtool,
100 $version_text);
101
102 my %opt_def = (
103 'n|name=s' => \$opt_name,
104 's|section=s' => \$section,
105 'm|manual=s' => \$manual,
106 'S|source=s' => \$source,
107 'L|locale=s' => sub { configure_locale pop },
108 'i|include=s' => sub { push @opt_include, [ pop, 1 ] },
109 'I|opt-include=s' => sub { push @opt_include, [ pop, 0 ] },
110 'o|output=s' => \$opt_output,
111 'p|info-page=s' => \$opt_info,
112 'N|no-info' => \$opt_no_info,
113 'l|libtool' => \$opt_libtool,
114 'help' => sub { print $help_info; exit },
115 'version' => sub { print $version_info; exit },
116 'h|help-option=s' => \$help_option,
117 'v|version-option=s' => \$version_option,
118 'version-string=s' => \$version_text,
119 'discard-stderr!' => \$discard_stderr,
120 );
121
122 # Parse options.
123 Getopt::Long::config('bundling');
124 die $help_info unless GetOptions %opt_def and @ARGV == 1;
125
126 my %include = ();
127 my %replace = ();
128 my %append = ();
129 my %append_match = ();
130 my @sections = (); # retain order of include file or in-line *section*s
131
132 # Process include file (if given). Format is:
133 #
134 # Optional initial text, ignored. May include lines starting with `-'
135 # which are processed as options.
136 #
137 # [section]
138 # Verbatim text to be included in the named section. By default at
139 # the start, but in the case of `name' and `synopsis' the content
140 # will replace the autogenerated contents.
141 #
142 # [<section]
143 # Verbatim text to be inserted at the start of the named section.
144 #
145 # [=section]
146
147 # Verbatim text to replace the named section.
148 #
149 # [>section]
150 # Verbatim text to be appended to the end of the named section.
151 #
152 # /pattern/
153 # Verbatim text for inclusion below a paragraph matching `pattern'.
154 #
155
156 while (@opt_include)
157 {
158 my ($inc, $required) = @{shift @opt_include};
159
160 next unless -f $inc or $required;
161 kark N_("%s: can't open `%s' (%s)"), $this_program, $inc, $!
162 unless open INC, $inc;
163
164 my $key;
165 my $hash;
166
167
168 while (<INC>)
169 {
170 # Convert input to internal Perl format, so that multibyte
171 # sequences are treated as single characters.
172 $_ = dec $_;
173
174 # [section]
175 if (/^\[([^]]+)\]\s*$/)
176 {
177 $key = uc $1;
178 $key =~ s/^\s+//;
179 $key =~ s/\s+$//;
180 $hash = \%include;
181 # Handle explicit [<section], [=section] and [>section]
182 if ($key =~ s/^([<>=])\s*//)
183 {
184 if ($1 eq '>') { $hash = \%append; }
185 elsif ($1 eq '=') { $hash = \%replace; }
186 }
187 # NAME/SYNOPSIS replace by default
188 elsif ($key eq _('NAME') or $key eq _('SYNOPSIS'))
189 {
190 $hash = \%replace;
191 }
192 else
193 {
194 $hash = \%include;
195 }
196
197 push @sections, $key;
198 next;
199 }
200
201 # /pattern/
202 if (m!^/(.*)/([ims]*)\s*$!)
203 {
204 my $pat = $2 ? "(?$2)$1" : $1;
205
206 # Check pattern.
207 eval { $key = qr($pat) };
208 if ($@)
209 {
210 $@ =~ s/ at .*? line \d.*//;
211 die "$inc:$.:$@";
212 }
213
214 $hash = \%append_match;
215 next;
216 }
217
218 # Check for options before the first section--anything else is
219 # silently ignored, allowing the first for comments and
220 # revision info.
221 unless ($key)
222 {
223 # handle options
224 if (/^-/)
225 {
226 local @ARGV = shellwords $_;
227 GetOptions %opt_def;
228 }
229
230 next;
231 }
232
233 $hash->{$key} .= $_;
234 }
235
236 close INC;
237
238 kark N_("%s: no valid information found in `%s'"), $this_program, $inc
239 unless $key;
240 }
241
242 # Compress trailing blank lines.
243 for my $hash (\(%include, %replace, %append, %append_match))
244 {
245 for (keys %$hash) { $hash->{$_} =~ s/\n+$/\n/ }
246 }
247
248 # Grab help and version info from executable.
249 my $help_text = get_option_value $ARGV[0], $help_option;
250 $version_text ||= get_option_value $ARGV[0], $version_option;
251
252 # By default the generated manual pages will include the current date. This may
253 # however be overriden by setting the environment variable $SOURCE_DATE_EPOCH
254 # to an integer value of the seconds since the UNIX epoch. This is primarily
255 # intended to support reproducible builds (wiki.debian.org/ReproducibleBuilds)
256 # and will additionally ensure that the output date string is UTC.
257 my $epoch_secs = time;
258 if (exists $ENV{SOURCE_DATE_EPOCH} and $ENV{SOURCE_DATE_EPOCH} =~ /^(\d+)$/)
259 {
260 $epoch_secs = $1;
261 $ENV{TZ} = 'UTC0';
262 }
263
264 # Translators: the following message is a strftime(3) format string, which in
265 # the English version expands to the month as a word and the full year. It
266 # is used on the footer of the generated manual pages. If in doubt, you may
267 # just use %x as the value (which should be the full locale-specific date).
268 my $date = enc strftime _("%B %Y"), localtime $epoch_secs;
269 my $program = program_basename $ARGV[0];
270 my $package = $program;
271 my $version;
272
273 if ($opt_output)
274 {
275 unlink $opt_output or kark N_("%s: can't unlink %s (%s)"),
276 $this_program, $opt_output, $! if -e $opt_output;
277
278 open STDOUT, ">$opt_output"
279 or kark N_("%s: can't create %s (%s)"), $this_program, $opt_output, $!;
280 }
281
282 # The first line of the --version information is assumed to be in one
283 # of the following formats:
284 #
285 # <version>
286 # <program> <version>
287 # {GNU,Free} <program> <version>
288 # <program> ({GNU,Free} <package>) <version>
289 # <program> - {GNU,Free} <package> <version>
290 #
291 # and separated from any copyright/author details by a blank line.
292
293 ($_, $version_text) = ((split /\n+/, $version_text, 2), '');
294
295 if (/^(\S+) +\(((?:GNU|Free) +[^)]+)\) +(.*)/ or
296 /^(\S+) +- *((?:GNU|Free) +\S+) +(.*)/)
297 {
298 $program = program_basename $1;
299 $package = $2;
300 $version = $3;
301 }
302 elsif (/^((?:GNU|Free) +)?(\S+) +(.*)/)
303 {
304 $program = program_basename $2;
305 $package = $1 ? "$1$program" : $program;
306 $version = $3;
307 }
308 else
309 {
310 $version = $_;
311 }
312
313 # No info for `info' itself.
314 $opt_no_info = 1 if $program eq 'info';
315
316 if ($opt_name)
317 {
318 # --name overrides --include contents.
319 $replace{_('NAME')} = "$program \\- $opt_name\n";
320 }
321
322 # Translators: "NAME", "SYNOPSIS" and other one or two word strings in all
323 # upper case are manual page section headings. The man(1) manual page in your
324 # language, if available should provide the conventional translations.
325 for ($replace{_('NAME')} || ($include{_('NAME')} ||= ''))
326 {
327 if ($_) # Use first name given as $program
328 {
329 $program = $1 if /^([^\s,]+)(?:,?\s*[^\s,\\-]+)*\s+\\?-/;
330 }
331 else # Set a default (useless) NAME paragraph.
332 {
333 $_ = sprintf _("%s \\- manual page for %s %s") . "\n", $program,
334 $program, $version;
335 }
336 }
337
338 # Man pages traditionally have the page title in caps.
339 my $PROGRAM = uc $program;
340
341 # Set default page head/footers
342 $source ||= "$program $version";
343 unless ($manual)
344 {
345 for ($section)
346 {
347 if (/^(1[Mm]|8)/) { $manual = enc _('System Administration Utilities') }
348 elsif (/^6/) { $manual = enc _('Games') }
349 else { $manual = enc _('User Commands') }
350 }
351 }
352
353 # Extract usage clause(s) [if any] for SYNOPSIS.
354 # Translators: "Usage" and "or" here are patterns (regular expressions) which
355 # are used to match the usage synopsis in program output. An example from cp
356 # (GNU coreutils) which contains both strings:
357 # Usage: cp [OPTION]... [-T] SOURCE DEST
358 # or: cp [OPTION]... SOURCE... DIRECTORY
359 # or: cp [OPTION]... -t DIRECTORY SOURCE...
360 my $PAT_USAGE = _('Usage');
361 my $PAT_USAGE_CONT = _('or');
362 if ($help_text =~ s/^($PAT_USAGE):( +(\S+))(.*)((?:\n(?: {6}\1| *($PAT_USAGE_CONT): +\S).*)*)//om)
363 {
364 my @syn = $3 . $4;
365
366 if ($_ = $5)
367 {
368 s/^\n//;
369 for (split /\n/) { s/^ *(($PAT_USAGE_CONT): +)?//o; push @syn, $_ }
370 }
371
372 my $synopsis = '';
373 for (@syn)
374 {
375 $synopsis .= ".br\n" if $synopsis;
376 s!^\S*/!!;
377 s/^lt-// if $opt_libtool;
378 s/^(\S+) *//;
379 $synopsis .= ".B $1\n";
380 s/\s+$//;
381 s/(([][]|\.\.+)+)/\\fR$1\\fI/g;
382 s/^/\\fI/ unless s/^\\fR//;
383 $_ .= '\fR';
384 s/(\\fI)( *)/$2$1/g;
385 s/\\fI\\fR//g;
386 s/^\\fR//;
387 s/\\fI$//;
388 s/^\./\\&./;
389
390 $_ = fix_italic_spacing $_;
391 $synopsis .= "$_\n";
392 }
393
394 $include{_('SYNOPSIS')} .= $synopsis;
395 }
396
397 # Process text, initial section is DESCRIPTION.
398 my $sect = _('DESCRIPTION');
399 $_ = "$help_text\n\n$version_text";
400
401 # Normalise paragraph breaks.
402 s/^\n+//;
403 s/\n*$/\n/;
404 s/\n\n+/\n\n/g;
405
406 # Join hyphenated lines.
407 s/([A-Za-z])-\n *([A-Za-z])/$1$2/g;
408
409 # Temporarily exchange leading dots, apostrophes and backslashes for
410 # tokens.
411 s/^\./\x80/mg;
412 s/^'/\x81/mg;
413 s/\\/\x82/g;
414
415 # Translators: patterns are used to match common program output. In the source
416 # these strings are all of the form of "my $PAT_something = _('...');" and are
417 # regular expressions. If there is more than one commonly used string, you
418 # may separate alternatives with "|". Spaces in these expressions are written
419 # as " +" to indicate that more than one space may be matched. The string
420 # "(?:[\\w-]+ +)?" in the bug reporting pattern is used to indicate an
421 # optional word, so that either "Report bugs" or "Report _program_ bugs" will
422 # be matched.
423 my $PAT_BUGS = _('Report +(?:[\w-]+ +)?bugs|' .
424 'Email +bug +reports +to|' .
425 '.* +online +help:');
426 my $PAT_AUTHOR = _('Written +by');
427 my $PAT_OPTIONS = _('Options');
428 my $PAT_ENVIRONMENT = _('Environment');
429 my $PAT_FILES = _('Files');
430 my $PAT_EXAMPLES = _('Examples');
431 my $PAT_FREE_SOFTWARE = _('This +is +free +software');
432 my $PAT_SEE_ALSO = _('Full +documentation');
433
434 # Start a new paragraph (if required) for these.
435 s/([^\n])\n($PAT_BUGS|$PAT_AUTHOR|$PAT_SEE_ALSO) /$1\n\n$2 /og;
436
437 # Convert iso-8859-1 copyright symbol or (c) to nroff
438 # character.
439 s/^Copyright +(?:\xa9|\([Cc]\))/Copyright \\(co/mg;
440
441 while (length)
442 {
443 # Convert some standard paragraph names.
444 if (s/^($PAT_OPTIONS): *\n+//o)
445 {
446 $sect = _('OPTIONS');
447 next;
448 }
449 if (s/^($PAT_ENVIRONMENT): *\n+//o)
450 {
451 $sect = _('ENVIRONMENT');
452 next;
453 }
454 if (s/^($PAT_FILES): *\n+//o)
455 {
456 $sect = _('FILES');
457 next;
458 }
459 elsif (s/^($PAT_EXAMPLES): *\n+//o)
460 {
461 $sect = _('EXAMPLES');
462 next;
463 }
464
465 # Custom section indicated by a line containing "*Section Name*".
466 if (s/^\*(\w(.*\w)?)\* *\n+//)
467 {
468 $sect = uc $1;
469 $sect =~ tr/*/ /; # also accept *Section*Name*
470 push @sections, $sect;
471 next;
472 }
473
474 # Copyright section.
475 if (/^Copyright /)
476 {
477 $sect = _('COPYRIGHT');
478 }
479
480 # Bug reporting section.
481 elsif (/^($PAT_BUGS) /o)
482 {
483 $sect = _('REPORTING BUGS');
484 }
485
486 # Author section.
487 elsif (/^($PAT_AUTHOR)/o)
488 {
489 $sect = _('AUTHOR');
490 }
491
492 elsif (/^($PAT_SEE_ALSO)/o)
493 {
494 $sect = _('SEE ALSO');
495 $opt_no_info = 1;
496 }
497
498 # Examples, indicated by an indented leading $, % or > are
499 # rendered in a constant width font.
500 if (/^( +)([\$\%>] )\S/)
501 {
502 my $indent = $1;
503 my $prefix = $2;
504 my $break = '.IP';
505 while (s/^$indent\Q$prefix\E(\S.*)\n*//)
506 {
507 $include{$sect} .= "$break\n\\f(CW$prefix$1\\fR\n";
508 $break = '.br';
509 }
510
511 next;
512 }
513
514 my $matched = '';
515
516 # Sub-sections have a trailing colon and the second line indented.
517 if (s/^(\S.*:) *\n / /)
518 {
519 $matched .= $& if %append_match;
520 $include{$sect} .= qq(.SS "$1"\n);
521 }
522
523 my $indent = 0;
524 my $content = '';
525
526 # Option with description.
527 if (s/^( {1,10}([+-]\S.*?))(?:( +(?!-))|\n( {20,}))(\S.*)\n//)
528 {
529 $matched .= $& if %append_match;
530 $indent = length ($4 || "$1$3");
531 $content = ".TP\n\x84$2\n\x84$5\n";
532 unless ($4)
533 {
534 # Indent may be different on second line.
535 $indent = length $& if /^ {20,}/;
536 }
537 }
538
539 # Option without description.
540 elsif (s/^ {1,10}([+-]\S.*)\n//)
541 {
542 $matched .= $& if %append_match;
543 $content = ".HP\n\x84$1\n";
544 $indent = 80; # not continued
545 }
546
547 # Indented paragraph with tag.
548 elsif (s/^( +(\S.*?) +)(\S.*)\n//)
549 {
550 $matched .= $& if %append_match;
551 $indent = length $1;
552 $content = ".TP\n\x84$2\n\x84$3\n";
553 }
554
555 # Indented paragraph.
556 elsif (s/^( +)(\S.*)\n//)
557 {
558 $matched .= $& if %append_match;
559 $indent = length $1;
560 $content = ".IP\n\x84$2\n";
561 }
562
563 # Left justified paragraph.
564 else
565 {
566 s/(.*)\n//;
567 $matched .= $& if %append_match;
568 $content = ".PP\n" if $include{$sect};
569 $content .= "$1\n";
570 }
571
572 # Append continuations.
573 while ($indent ? s/^ {$indent}(\S.*)\n// : s/^(\S.*)\n//)
574 {
575 $matched .= $& if %append_match;
576 $content .= "\x84$1\n";
577 }
578
579 # Move to next paragraph.
580 s/^\n+//;
581
582 for ($content)
583 {
584 # Leading dot and apostrophe protection.
585 s/\x84\./\x80/g;
586 s/\x84'/\x81/g;
587 s/\x84//g;
588
589 # Examples should be verbatim.
590 unless ($sect eq _('EXAMPLES'))
591 {
592 # Convert options.
593 s/(^|[ (])(-[][\w=-]+)/$1 . convert_option $2/mge;
594
595 # Italicise filenames: /a/b, $VAR/c/d, ~/e/f
596 s!
597 (^|[ (]) # space/punctuation before
598 (
599 (?:\$\w+|~)? # leading variable, or tilde
600 (?:/\w(?:[\w.-]*\w)?)+ # path components
601 )
602 ($|[ ,;.)]) # space/punctuation after
603 !$1\\fI$2\\fP$3!xmg;
604
605 $_ = fix_italic_spacing $_;
606 }
607
608 # Escape remaining hyphens.
609 s/-/\x83/g;
610
611 if ($sect eq _('COPYRIGHT'))
612 {
613 # Insert line breaks before additional copyright messages
614 # and the disclaimer.
615 s/\n(Copyright |$PAT_FREE_SOFTWARE)/\n.br\n$1/og;
616 }
617 elsif ($sect eq _('REPORTING BUGS'))
618 {
619 # Handle multi-line bug reporting sections of the form:
620 #
621 # Report <program> bugs to <addr>
622 # GNU <package> home page: <url>
623 # ...
624 s/\n([[:upper:]])/\n.br\n$1/g;
625 }
626 elsif ($sect eq _('SEE ALSO'))
627 {
628 # Handle external references of the form:
629 #
630 # GNU <package> online resources: <addr>
631 # Full documentation at: <addr>
632 # or available locally via: info ...
633 #
634 s/\'/\\(aq/g; # shell quotes for info command
635 s/\n(.)/\n.br\n$1/g; # separate lines for each item
636 }
637 }
638
639 # Check if matched paragraph contains /pat/.
640 if (%append_match)
641 {
642 for my $pat (keys %append_match)
643 {
644 if ($matched =~ $pat)
645 {
646 $content .= ".PP\n" unless $append_match{$pat} =~ /^\./;
647 $content .= $append_match{$pat};
648 }
649 }
650 }
651
652 $include{$sect} .= $content;
653 }
654
655 # Refer to the real documentation.
656 unless ($opt_no_info)
657 {
658 my $info_page = $opt_info || $program;
659
660 $sect = _('SEE ALSO');
661 $include{$sect} .= ".PP\n" if $include{$sect};
662 $include{$sect} .= sprintf _(<<'EOT'), $program, $program, $info_page;
663 The full documentation for
664 .B %s
665 is maintained as a Texinfo manual. If the
666 .B info
667 and
668 .B %s
669 programs are properly installed at your site, the command
670 .IP
671 .B info %s
672 .PP
673 should give you access to the complete manual.
674 EOT
675 }
676
677 # Append additional text.
678 while (my ($sect, $text) = each %append)
679 {
680 $include{$sect} .= $append{$sect};
681 }
682
683 # Replace sections.
684 while (my ($sect, $text) = each %replace)
685 {
686 $include{$sect} = $replace{$sect};
687 }
688
689 # Output header.
690 print <<EOT;
691 .\\" DO NOT MODIFY THIS FILE! It was generated by $this_program $this_version.
692 .TH $PROGRAM "$section" "$date" "$source" "$manual"
693 EOT
694
695 # Section ordering.
696 my @pre = (_('NAME'), _('SYNOPSIS'), _('DESCRIPTION'), _('OPTIONS'),
697 _('EXAMPLES'));
698 my @post = (_('ENVIRONMENT'), _('FILES'), _('AUTHOR'),
699 _('REPORTING BUGS'), _('COPYRIGHT'), _('SEE ALSO'));
700 my %filter = map { $_ => 1 } @pre, @post;
701
702 # Output content.
703 my %done;
704 for my $sect (@pre, (grep !$filter{$_}, @sections), @post)
705 {
706 next if $done{$sect}++; # ignore duplicates
707 next unless $include{$sect};
708 if ($include{$sect})
709 {
710 my $quote = $sect =~ /\W/ ? '"' : '';
711 print enc ".SH $quote$sect$quote\n";
712
713 for ($include{$sect})
714 {
715 # Replace leading dot, apostrophe, backslash and hyphen
716 # tokens.
717 s/\x80/\\&./g;
718 s/\x81/\\&'/g;
719 s/\x82/\\e/g;
720 s/\x83/\\-/g;
721
722 # Convert some latin1 chars to troff equivalents
723 s/\xa0/\\ /g; # non-breaking space
724
725 print enc $_;
726 }
727 }
728 }
729
730 close STDOUT or kark N_("%s: error writing to %s (%s)"), $this_program,
731 $opt_output || 'stdout', $!;
732
733 exit;
734
735 # Get program basename, and strip libtool "lt-" prefix if required.
736 sub program_basename
737 {
738 local $_ = shift;
739 s!.*/!!;
740 s/^lt-// if $opt_libtool;
741 $_;
742 }
743
744 # Call program with given option and return results.
745 sub get_option_value
746 {
747 my ($prog, $opt) = @_;
748 my $stderr = $discard_stderr ? '/dev/null' : '&1';
749 my $value = join '',
750 map { s/ +$//; expand $_ }
751 map { dec $_ }
752 `$prog $opt 2>$stderr`;
753
754 unless ($value)
755 {
756 my $err = N_("%s: can't get `%s' info from %s%s");
757 my $extra = $discard_stderr
758 ? "\n" . N_("Try `--no-discard-stderr' if option outputs to stderr")
759 : '';
760
761 kark $err, $this_program, $opt, $prog, $extra;
762 }
763
764 $value;
765 }
766
767 # Convert option dashes to \- to stop nroff from hyphenating 'em, and
768 # embolden. Option arguments get italicised.
769 sub convert_option
770 {
771 local $_ = '\fB' . shift;
772
773 s/-/\x83/g;
774 unless (s/\[=(.*)\]$/\\fR[=\\fI$1\\fR]/)
775 {
776 s/=(.)/\\fR=\\fI$1/;
777 s/ (.)/ \\fI$1/;
778 $_ .= '\fR';
779 }
780
781 $_;
782 }
783
784 # Insert spacing escape characters \, and \/ before and after italic text. See
785 # https://www.gnu.org/software/groff/manual/html_node/Ligatures-and-Kerning.html
786 sub fix_italic_spacing
787 {
788 local $_ = shift;
789 s!\\fI(.*?)\\f([BRP])!\\fI\\,$1\\/\\f$2!g;
790 return $_;
791 }