]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/examples/list_perms.pl
LP#1838995: (follow-up) adjust ID for new permission
[Evergreen.git] / Open-ILS / examples / list_perms.pl
1 #!/usr/bin/perl -w
2
3 # Extract permission names from the output of the dump_idl utility.
4
5 # The logic necessarily makes assumptions about the format of
6 # dump_idl's output.  If that format changes, the logic may no longer work.
7
8 # In the output: each permission name appears on a separate line, 
9 # flush left.  Normally the output should be piped into sort -u in
10 # order to eliminate duplicates.
11
12 use strict;
13
14 my $in_perms = 0;
15 my $perm_indent;
16
17 # Return the number of leading white space characters.
18 # We do not distinguish between tabs and spaces.
19 sub indent_level {
20         my $str = shift;
21         return 0 unless (defined( $str ));
22         $str =~ s/\S.*//;       # Remove everything after the leading white space
23         return length $str;     # Take the length of what's left
24 }
25
26 while(<>) {
27         if( $in_perms ) {
28                 
29                 # Check the indentation to see if we're still
30                 # inside the list of permissions.
31
32                 if ( indent_level( $_ ) > $perm_indent ) {
33
34                         # This line contains a permission name.
35                         # Strip off the leading white space and write it.
36
37                         s/^\s*//;
38                         print;
39                 } else {
40
41                         # We're no longer inside the list of permissions.
42
43                         $in_perms = 0;
44                 }
45         } elsif (/\s+permission [(]string array[)]$/) {
46
47                 # We are entering a list of permissions, each of which is
48                 # indented further than this line.  When we see a line that
49                 # is *not* further indented, that will end the list.
50
51                 # The indentation is defined as the number of leading white
52                 # space characters, be they tabs or spaces.  If the format of
53                 # the dump_idl output is changed to involve some bizarre and
54                 # perverse mixture of tabs and spaces, this logic may not work.
55
56                 $in_perms = 1;
57                 $perm_indent = indent_level( $_ );
58         }
59 }