~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/scripts/extract_env_vars.pl

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
#########################################################################
 
4
 
5
#  The Contents of this file are made available subject to the terms of
 
6
#  the Sun Industry Standards Source License Version 1.2
 
7
 
8
#  Sun Microsystems Inc., March, 2001
 
9
 
10
 
11
#  Sun Industry Standards Source License Version 1.2
 
12
#  =================================================
 
13
#  The contents of this file are subject to the Sun Industry Standards
 
14
#  Source License Version 1.2 (the "License"); You may not use this file
 
15
#  except in compliance with the License. You may obtain a copy of the
 
16
#  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
17
 
18
#  Software provided under this License is provided on an "AS IS" basis,
 
19
#  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
20
#  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
21
#  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
22
#  See the License for the specific provisions governing your rights and
 
23
#  obligations concerning the Software.
 
24
 
25
#   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
26
 
27
#   Copyright: 2001 by Sun Microsystems, Inc.
 
28
 
29
#   All Rights Reserved.
 
30
 
31
#########################################################################
 
32
#
 
33
# This script recursively searches all .c files under the current
 
34
# directory for uses of setenv() or getenv().  Whenever such a function
 
35
# call is found, an attempt is made to determine the environment variable
 
36
# used.  If the argument to the function call matches the pattern
 
37
# "[A-Z0-9_]+", the argument is assumed to be an env var.  If the argument
 
38
# matches the pattern [A-Z0-9_]+, the argument is assumed to be a macro.
 
39
# The script will then recursively search all .c and .h files under the
 
40
# current directory for a macro definition.  If the -a switch is given,
 
41
# anything not matching either of the above patterns is assumed to be a
 
42
# variable expression and is not resolved any further.  If the -g switch is
 
43
# given, only getenv() calls are included.  If the -s switch is given, only
 
44
# setenv() calls are included.
 
45
# The output of this script is a list of the names of the env vars found,
 
46
# one per line, followed the names of the files in which they where found,
 
47
# indented and one per line.  In the case of macros, the name takes the
 
48
# form:
 
49
#    macro(resolved_value)
 
50
# In the case of variable expressions, the name takes the form:
 
51
#    (variable_expression)
 
52
#
 
53
# Syntax:
 
54
#    Usage: extract_env_vars.pl [-a] [-g|-s]
 
55
#
 
56
#########################################################################
 
57
 
 
58
my %list, %macros, $do_all, $do_gets, $do_sets, $arg;
 
59
 
 
60
sub usage {
 
61
   print "Usage:   extract_env_vars.pl [-a] [-g|-s]\n";
 
62
   exit (1);
 
63
}
 
64
 
 
65
sub help {
 
66
   print "extract_env_vars.pl [-a] [-g|-s]\n";
 
67
   print "\t-a\tinclude variable expressions\n";
 
68
   print "\t-g\tinclude only getenv() calls\n";
 
69
   print "\t-s\tinclude only setenv() calls\n";
 
70
   exit (0);
 
71
}
 
72
 
 
73
$do_all = 0;
 
74
$do_gets = 1;
 
75
$do_sets = 1;
 
76
 
 
77
while (@ARGV > 0) {
 
78
   $arg = shift (@ARGV);
 
79
 
 
80
   if ($arg eq "-help") {
 
81
      help();
 
82
   }
 
83
   elsif ($arg eq "-a") {
 
84
      $do_all = 1;
 
85
   }
 
86
   elsif ($arg eq "-s") {
 
87
      $do_sets = 1;
 
88
      $do_gets = 0;
 
89
   }
 
90
   elsif ($arg eq "-g") {
 
91
      $do_gets = 1;
 
92
      $do_sets = 0;
 
93
   }
 
94
   else {
 
95
      usage ();
 
96
   }
 
97
}
 
98
 
 
99
open (GREP, '/usr/bin/csh -c "/usr/bin/grep etenv {*.c,*/*.c,*/*/*.c,*/*/*/*.c}" |');
 
100
 
 
101
my $file;
 
102
 
 
103
while (<GREP>) {
 
104
   if (/^(.+?):.*(sge_|[^a-zA-Z_])([gs])etenv\s*\(\s*(.+?)\s*\)/) {
 
105
      $file = $1;
 
106
      $arg = $4;
 
107
 
 
108
#      print "$3: $4 in $1\n";
 
109
 
 
110
      if ($do_gets && ($3 eq "g")) {
 
111
         # With quotes is an env var.
 
112
         if ($arg =~ /^"([A-Z0-9_]+)"$/) {
 
113
            push (@{$list{$1}}, $file);
 
114
         }
 
115
         # Without quotes is a macro.
 
116
         elsif ($arg =~ /^([A-Z0-9_]+)$/) {
 
117
            push (@{$macros{$1}}, $file);
 
118
         }
 
119
         # Lower case is a variable expression.
 
120
         elsif ($do_all) {
 
121
            if (index ($arg, "(") != -1) {
 
122
               $arg = "$arg)";
 
123
            }
 
124
 
 
125
            push (@{$list{"($arg)"}}, $file);
 
126
         }
 
127
      }
 
128
      elsif ($do_sets && ($3 eq "s")) {
 
129
         # With quotes is an env var.
 
130
         if ($arg =~ /^"([A-Z0-9_]+?)"\s*,.+$/) {
 
131
            push (@{$list{$1}}, $file);
 
132
         }
 
133
         # Without quotes is a macro.
 
134
         elsif ($arg =~ /^([A-Z0-9_]+?)\s*,.+$/) {
 
135
            push (@{$macros{$1}}, $file);
 
136
         }
 
137
         # Lower case is a variable expression.
 
138
         elsif ($do_all && ($arg =~ /^(.+)\s*,.+$/)) {
 
139
            $arg = $1;
 
140
 
 
141
            if (index ($arg, "(") != -1) {
 
142
               $arg = "$arg)";
 
143
            }
 
144
 
 
145
            push (@{$list{"($arg)"}}, $file);
 
146
         }
 
147
      }
 
148
   }
 
149
 
 
150
}
 
151
 
 
152
close GREP;
 
153
 
 
154
#exit;
 
155
 
 
156
my $var, $found;
 
157
 
 
158
# Resolve macros
 
159
foreach $var (keys (%macros)) {
 
160
   open (GREP, "/usr/bin/csh -c \"/usr/bin/grep $var {*.c,*/*.c,*/*/*.c,*/*/*/*.c,*.h,*/*.h,*/*/*.h,*/*/*/*.h} | /usr/bin/grep #define\" |");
 
161
 
 
162
   $found = 0;
 
163
 
 
164
   while (<GREP>) {
 
165
      if (/#define\s+"?$var"?\s+(.*?\S)\s*(\/\*|\r?\n)/) {
 
166
         push (@{$list{"$var($1)"}}, @{$macros{$var}});
 
167
         $found = 1;
 
168
      }
 
169
   }
 
170
 
 
171
   close GREP;
 
172
 
 
173
   if (!$found) {
 
174
      push (@{$list{"$var(?)"}}, @{$macros{$var}});;
 
175
   }
 
176
}
 
177
 
 
178
my $file, $last_file;
 
179
 
 
180
foreach $var (sort (keys (%list))) {
 
181
   print "$var:\n";
 
182
 
 
183
   $last_file = "";
 
184
 
 
185
   foreach $file (sort (@{$list{$var}})) {
 
186
      if ($file ne $last_file) {
 
187
         print "   $file\n";
 
188
         $last_file = $file;
 
189
      }
 
190
   }
 
191
}
 
 
b'\\ No newline at end of file'