The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/openzfs/scripts/enum-extract.pl

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #!/usr/bin/env perl
    2 
    3 my $usage = <<EOT;
    4 usage: config-enum enum [file ...]
    5 
    6 Returns the elements from an enum declaration.
    7 
    8 "Best effort": we're not building an entire C interpreter here!
    9 EOT
   10 
   11 use warnings;
   12 use strict;
   13 use Getopt::Std;
   14 
   15 my %opts;
   16 
   17 if (!getopts("", \%opts) || @ARGV < 1) {
   18         print $usage;
   19         exit 2;
   20 }
   21 
   22 my $enum = shift;
   23 
   24 my $in_enum = 0;
   25 
   26 while (<>) {
   27         # comments
   28         s/\/\*.*\*\///;
   29         if (m/\/\*/) {
   30                 while ($_ .= <>) {
   31                         last if s/\/\*.*\*\///s;
   32                 }
   33         }
   34 
   35         # preprocessor stuff
   36         next if /^#/;
   37 
   38         # find our enum
   39         $in_enum = 1 if s/^\s*enum\s+${enum}(?:\s|$)//;
   40         next unless $in_enum;
   41 
   42         # remove explicit values
   43         s/\s*=[^,]+,/,/g;
   44 
   45         # extract each identifier
   46         while (m/\b([a-z_][a-z0-9_]*)\b/ig) {
   47                 print $1, "\n";
   48         }
   49 
   50         #
   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.
   54         #
   55         $in_enum = 0 if m/}\s*;/;
   56 }
   57 
   58 exit 0;

Cache object: 02911fc0b5c3a9b5cd5a2dc5df1ec9cf


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.