]>
Commit | Line | Data |
---|---|---|
f4101aa6 AD |
1 | #! /usr/bin/env perl |
2 | ||
3 | use warnings; | |
4 | use 5.005; | |
5 | use strict; | |
6 | ||
7 | my %option; | |
8 | while (<>) | |
9 | { | |
0213d651 AD |
10 | if (/^\s* # Initial spaces. |
11 | (?:(-\w),\s+)? # $1: $short: Possible short option. | |
12 | (--[-\w]+) # $2: $long: Long option. | |
13 | (\[?) # $3: $opt: '[' iff the argument is optional. | |
14 | (?:=(\S+))? # $4: $arg: Possible argument name. | |
15 | \s # Spaces. | |
7020f1e9 | 16 | /x) |
f4101aa6 AD |
17 | { |
18 | my ($short, $long, $opt, $arg) = ($1, $2, $3, $4); | |
19 | $short = defined $short ? '@option{' . $short . '}' : ''; | |
20 | if ($arg) | |
21 | { | |
0213d651 AD |
22 | # if $opt, $arg contains the closing ]. |
23 | substr ($arg, -1) = '' | |
24 | if $opt eq '['; | |
f4101aa6 | 25 | $arg =~ s/^=//; |
0213d651 AD |
26 | $arg = lc ($arg); |
27 | # If the argument is compite (e.g., for --define[=NAME[=VALUE]]), | |
28 | # put each word in @var, to build @var{name}[=@var{value}], not | |
29 | # @var{name[=value]}]. | |
30 | $arg =~ s/(\w+)/\@var{$1}/g; | |
ecd1b61c JD |
31 | my $long_arg = "=$arg"; |
32 | if ($opt eq '[') { | |
33 | $long_arg = "[$long_arg]"; | |
34 | $arg = "[$arg]"; | |
35 | } | |
36 | $option{"$long$long_arg"} = $short ? "$short $arg" : ''; | |
f4101aa6 AD |
37 | } |
38 | else | |
39 | { | |
40 | $option{"$long"} = "$short"; | |
41 | } | |
42 | } | |
43 | } | |
44 | ||
45 | foreach my $long (sort keys %option) | |
46 | { | |
0213d651 AD |
47 | # Avoid trailing spaces. |
48 | printf ("\@item %-40s \@tab%s\n", | |
49 | '@option{' . $long . '}', | |
50 | $option{$long} ? " $option{$long}" : ""); | |
f4101aa6 | 51 | } |