]> git.saurik.com Git - bison.git/blame - build-aux/cross-options.pl
Factor %FLAG at scan level.
[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);
25 $dir = '' if index ($scanner, "\"$dir\"") < 0;
f4101aa6
AD
26 if ($arg)
27 {
74eae918
AD
28 # if $opt, $arg contains the closing ].
29 substr ($arg, -1) = ''
30 if $opt eq '[';
f4101aa6 31 $arg =~ s/^=//;
74eae918 32 $arg = lc ($arg);
a7c09cba 33 my $dir_arg = $arg;
74eae918
AD
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;
f4101aa6 38 $arg = '[' . $arg . ']'
7020f1e9 39 if $opt eq '[';
a7c09cba
DJ
40 # For arguments of directives: this only works if all arguments
41 # are strings and have the same syntax as on the command line.
42 if ($dir_arg eq 'name[=value]')
43 {
44 $dir_arg = '@var{name} ["@var{value}"]';
45 }
46 else
47 {
48 $dir_arg =~ s/(\w+)/\@var{"$1"}/g;
49 $dir_arg = '[' . $dir_arg . ']'
50 if $opt eq '[';
51 }
52 $long = "$long=$arg";
53 $short = "$short $arg" if $short && $short ne '-d';
54 $dir = "$dir $dir_arg" if $dir;
f4101aa6 55 }
a7c09cba
DJ
56 $option{$long} = $short;
57 $directive{$long} = $dir;
f4101aa6
AD
58 }
59}
60
01466c3e 61my $sep = '';
f4101aa6
AD
62foreach my $long (sort keys %option)
63{
74eae918 64 # Avoid trailing spaces.
01466c3e
AD
65 print $sep;
66 $sep = "\n";
a7c09cba
DJ
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";
f4101aa6 72}