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