3
#########################################################################
5
# The Contents of this file are made available subject to the terms of
6
# the Sun Industry Standards Source License Version 1.2
8
# Sun Microsystems Inc., March, 2001
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
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.
25
# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
27
# Copyright: 2001 by Sun Microsystems, Inc.
29
# All Rights Reserved.
31
#########################################################################
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
49
# macro(resolved_value)
50
# In the case of variable expressions, the name takes the form:
51
# (variable_expression)
54
# Usage: extract_env_vars.pl [-a] [-g|-s]
56
#########################################################################
58
my %list, %macros, $do_all, $do_gets, $do_sets, $arg;
61
print "Usage: extract_env_vars.pl [-a] [-g|-s]\n";
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";
80
if ($arg eq "-help") {
83
elsif ($arg eq "-a") {
86
elsif ($arg eq "-s") {
90
elsif ($arg eq "-g") {
99
open (GREP, '/usr/bin/csh -c "/usr/bin/grep etenv {*.c,*/*.c,*/*/*.c,*/*/*/*.c}" |');
104
if (/^(.+?):.*(sge_|[^a-zA-Z_])([gs])etenv\s*\(\s*(.+?)\s*\)/) {
108
# print "$3: $4 in $1\n";
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);
115
# Without quotes is a macro.
116
elsif ($arg =~ /^([A-Z0-9_]+)$/) {
117
push (@{$macros{$1}}, $file);
119
# Lower case is a variable expression.
121
if (index ($arg, "(") != -1) {
125
push (@{$list{"($arg)"}}, $file);
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);
133
# Without quotes is a macro.
134
elsif ($arg =~ /^([A-Z0-9_]+?)\s*,.+$/) {
135
push (@{$macros{$1}}, $file);
137
# Lower case is a variable expression.
138
elsif ($do_all && ($arg =~ /^(.+)\s*,.+$/)) {
141
if (index ($arg, "(") != -1) {
145
push (@{$list{"($arg)"}}, $file);
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\" |");
165
if (/#define\s+"?$var"?\s+(.*?\S)\s*(\/\*|\r?\n)/) {
166
push (@{$list{"$var($1)"}}, @{$macros{$var}});
174
push (@{$list{"$var(?)"}}, @{$macros{$var}});;
178
my $file, $last_file;
180
foreach $var (sort (keys (%list))) {
185
foreach $file (sort (@{$list{$var}})) {
186
if ($file ne $last_file) {
b'\\ No newline at end of file'