]> git.saurik.com Git - bison.git/blob - build-aux/cross-options.pl
Improves options in the manual.
[bison.git] / build-aux / cross-options.pl
1 #! /usr/bin/env perl
2
3 use warnings;
4 use 5.005;
5 use strict;
6
7 my %option;
8 my %directive;
9 my $scanner = `grep -i '"%[a-z]' $ARGV[0]`;
10 $scanner =~ s/"\[-_\]"/-/g;
11 while (<STDIN>)
12 {
13 if (/^\s* # Initial spaces.
14 (?:(-\w),\s+)? # $1: $short: Possible short option.
15 (--[-\w]+) # $2: $long: Long option.
16 (\[?) # $3: $opt: '[' iff the argument is optional.
17 (?:=(\S+))? # $4: $arg: Possible argument name.
18 \s # Spaces.
19 /x)
20 {
21 my ($short, $long, $opt, $arg) = ($1, $2, $3, $4);
22 $short = '' if ! defined $short;
23 $short = '-d' if $long eq '--defines' && ! $short;
24 my $dir = '%' . substr($long, 2);
25 $dir = '' if index ($scanner, "\"$dir\"") < 0;
26 if ($arg)
27 {
28 # if $opt, $arg contains the closing ].
29 substr ($arg, -1) = ''
30 if $opt eq '[';
31 $arg =~ s/^=//;
32 $arg = lc ($arg);
33 my $dir_arg = $arg;
34 # If the argument is compite (e.g., for --define[=NAME[=VALUE]]),
35 # put each word in @var, to build @var{name}[=@var{value}], not
36 # @var{name[=value]}].
37 $arg =~ s/(\w+)/\@var{$1}/g;
38 my $long_arg = "=$arg";
39 if ($opt eq '[') {
40 $long_arg = "[$long_arg]";
41 $arg = "[$arg]";
42 }
43 # For arguments of directives: this only works if all arguments
44 # are strings and have the same syntax as on the command line.
45 if ($dir_arg eq 'name[=value]')
46 {
47 $dir_arg = '@var{name} ["@var{value}"]';
48 }
49 else
50 {
51 $dir_arg =~ s/(\w+)/\@var{"$1"}/g;
52 $dir_arg = '[' . $dir_arg . ']'
53 if $opt eq '[';
54 }
55 $long = "$long$long_arg";
56 $short = "$short $arg" if $short && $short ne '-d';
57 $dir = "$dir $dir_arg" if $dir;
58 }
59 $option{$long} = $short;
60 $directive{$long} = $dir;
61 }
62 }
63
64 foreach my $long (sort keys %option)
65 {
66 # Avoid trailing spaces.
67 print '@item @option{', $long, "}\n\@tab";
68 print ' @option{', $option{$long}, '}' if $option{$long};
69 print "\n\@tab";
70 print ' @code{', $directive{$long}, '}' if $directive{$long};
71 print "\n";
72 }