Linux: Reclaim unused spl_kmem_cache_reclaim
[zfs.git] / scripts / enum-extract.pl
blob5dc2e34551452ef22e02c49f27dbff92a48cdb90
1 #!/usr/bin/env perl
3 my $usage = <<EOT;
4 usage: config-enum enum [file ...]
6 Returns the elements from an enum declaration.
8 "Best effort": we're not building an entire C interpreter here!
9 EOT
11 use warnings;
12 use strict;
13 use Getopt::Std;
15 my %opts;
17 if (!getopts("", \%opts) || @ARGV < 1) {
18 print $usage;
19 exit 2;
22 my $enum = shift;
24 my $in_enum = 0;
26 while (<>) {
27 # comments
28 s/\/\*.*\*\///;
29 if (m/\/\*/) {
30 while ($_ .= <>) {
31 last if s/\/\*.*\*\///s;
35 # preprocessor stuff
36 next if /^#/;
38 # find our enum
39 $in_enum = 1 if s/^\s*enum\s+${enum}(?:\s|$)//;
40 next unless $in_enum;
42 # remove explicit values
43 s/\s*=[^,]+,/,/g;
45 # extract each identifier
46 while (m/\b([a-z_][a-z0-9_]*)\b/ig) {
47 print $1, "\n";
51 # don't exit: there may be multiple versions of the same enum, e.g.
52 # inside different #ifdef blocks. Let's explicitly return all of
53 # them and let external tooling deal with it.
55 $in_enum = 0 if m/}\s*;/;
58 exit 0;