mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 11:19:32 +03:00
bfaa1d98f4
This is a portability issue. The issue had already been fixed for
scripts/cstyle.pl by 2dbf1bf829
.
scripts/enum-extract.pl was added to the repository the following year
without this portability fix.
Michael Bishop informed me that this broke his attempt to build ZFS
2.1.6 on NixOS, since he was building manually outside of their package
manager (that usually rewrites the shebangs to NixOS' unusual paths).
NixOS puts all of the paths into $PATH, so scripts that portably rely
on env to find the interpreter still work.
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14012
59 lines
956 B
Perl
Executable File
59 lines
956 B
Perl
Executable File
#!/usr/bin/env perl
|
|
|
|
my $usage = <<EOT;
|
|
usage: config-enum enum [file ...]
|
|
|
|
Returns the elements from an enum declaration.
|
|
|
|
"Best effort": we're not building an entire C interpreter here!
|
|
EOT
|
|
|
|
use warnings;
|
|
use strict;
|
|
use Getopt::Std;
|
|
|
|
my %opts;
|
|
|
|
if (!getopts("", \%opts) || @ARGV < 1) {
|
|
print $usage;
|
|
exit 2;
|
|
}
|
|
|
|
my $enum = shift;
|
|
|
|
my $in_enum = 0;
|
|
|
|
while (<>) {
|
|
# comments
|
|
s/\/\*.*\*\///;
|
|
if (m/\/\*/) {
|
|
while ($_ .= <>) {
|
|
last if s/\/\*.*\*\///s;
|
|
}
|
|
}
|
|
|
|
# preprocessor stuff
|
|
next if /^#/;
|
|
|
|
# find our enum
|
|
$in_enum = 1 if s/^\s*enum\s+${enum}(?:\s|$)//;
|
|
next unless $in_enum;
|
|
|
|
# remove explicit values
|
|
s/\s*=[^,]+,/,/g;
|
|
|
|
# extract each identifier
|
|
while (m/\b([a-z_][a-z0-9_]*)\b/ig) {
|
|
print $1, "\n";
|
|
}
|
|
|
|
#
|
|
# don't exit: there may be multiple versions of the same enum, e.g.
|
|
# inside different #ifdef blocks. Let's explicitly return all of
|
|
# them and let external tooling deal with it.
|
|
#
|
|
$in_enum = 0 if m/}\s*;/;
|
|
}
|
|
|
|
exit 0;
|