Initial import to Tizen
[profile/ivi/sphinxbase.git] / doc / args2man.pl
1 #!/usr/bin/env perl
2 use strict;
3 use Pod::Usage;
4
5 my $program = shift;
6 pod2usage(2) unless defined($program);
7
8 open ARGTEXT, "$program 2>&1 |" or die "Failed to run $program: $!";
9 my $inargs = 0;
10 my @args;
11 while (<ARGTEXT>) {
12     chomp;
13     if (/^\[NAME/) {
14         $inargs = 1;
15         next;
16     }
17     next unless $inargs;
18     last if /^\s*$/;
19     my ($name, $deflt, $descr) = /^(\S+)\s+(\S+)\s+(.*)$/;
20     push @args, [$name, $deflt, $descr];
21 }
22 die "No arguments found!" unless @args;
23
24 while (<>) {
25     if (/\.\\\" ### ARGUMENTS ###/) {
26         foreach (@args) {
27             my ($name, $deflt, $descr) = @$_;
28             $name =~ s/-/\\-/g;
29             $descr =~ s/ (-\S+)/ \\fB\\$1\\fR/g;
30             print <<"EOA";
31 .TP
32 .B $name
33 $descr
34 EOA
35         }
36     }
37     else {
38         print;
39     }
40 }
41
42 __END__
43
44 =head1 NAME
45
46 sphinx_args2man - Generate manual pages from the output of Sphinx programs
47
48 =head1 SYNOPSIS
49
50 B<sphinx_args2man> I<PROGRAM> E<lt> I<TEMPLATE> E<gt> I<OUTPUT>
51
52 =head1 DESCRIPTION
53
54 This program runs a Sphinx program I<PROGRAM>, reads a template file
55 from standard input, and writes a manual page in L<man(7)> format to
56 standard output.
57
58 The template file is a manual page in L<man(7)> format, containing a
59 comment line of the form:
60
61  .\" ### ARGUMENTS ###
62
63 Which will be replaced in the output with the arguments and their
64 descriptions from I<PROGRAM>.
65
66 =head1 AUTHOR
67
68 David Huggins-Daines <dhuggins@cs.cmu.edu>
69
70 =head1 COPYRIGHT
71
72 Copyright (c) 2007 Carnegie Mellon University.  You may copy and
73 distribute this file under the same conditions as the rest of
74 PocketSphinx.  See the file COPYING for more information.
75
76 =cut