X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/1bb2bd75f0185ca53c92f1c63cdc0b5ceef3f1f2..6659366cda3f80390387c11b71b781d96a367a7d:/build-aux/cross-options.pl diff --git a/build-aux/cross-options.pl b/build-aux/cross-options.pl index cbd11888..2cec3696 100755 --- a/build-aux/cross-options.pl +++ b/build-aux/cross-options.pl @@ -7,16 +7,29 @@ use strict; my %option; while (<>) { - if (/^\s*(?:(-\w), )?(--[-\w]+)(\[?)(=[-\w]+)?\]?/) + if (/^\s* # Initial spaces. + (?:(-\w),\s+)? # $1: $short: Possible short option. + (--[-\w]+) # $2: $long: Long option. + (\[?) # $3: $opt: '[' iff the argument is optional. + (?:=(\S+))? # $4: $arg: Possible argument name. + \s # Spaces. + /x) { my ($short, $long, $opt, $arg) = ($1, $2, $3, $4); $short = defined $short ? '@option{' . $short . '}' : ''; if ($arg) { + # if $opt, $arg contains the closing ]. + substr ($arg, -1) = '' + if $opt eq '['; $arg =~ s/^=//; - $arg = '@var{' . lc ($arg) . '}'; + $arg = lc ($arg); + # If the argument is compite (e.g., for --define[=NAME[=VALUE]]), + # put each word in @var, to build @var{name}[=@var{value}], not + # @var{name[=value]}]. + $arg =~ s/(\w+)/\@var{$1}/g; $arg = '[' . $arg . ']' - if defined $opt; + if $opt eq '['; $option{"$long=$arg"} = $short ? "$short $arg" : ''; } else @@ -28,5 +41,8 @@ while (<>) foreach my $long (sort keys %option) { - printf "\@item %-40s \@tab %s\n", '@option{' . $long . '}', $option{$long}; + # Avoid trailing spaces. + printf ("\@item %-40s \@tab%s\n", + '@option{' . $long . '}', + $option{$long} ? " $option{$long}" : ""); }