Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
315 dpurdie 1
########################################################################
2
# Copyright (C) 2010 ERG Limited, All rights reserved
3
#
4
# Module name   : jats_vars.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Program to show the environment variables passed into
10
#                 a program invoked by JATS
11
#
12
# Usage:        jats vars
13
#
14
#......................................................................#
15
 
16
require 5.008_002;
17
use strict;
18
use warnings;
19
 
20
use Pod::Usage;
21
use Getopt::Long;
22
use Cwd;
23
 
24
use JatsError qw(:name=JatsVars);
25
 
26
#
27
#   Local variables
28
#
29
my $VERSION = "1.0.0";                      # Update this
30
my $opt_verbose = $ENV{'GBE_VERBOSE'} || 0;
31
my $opt_help = 0;
32
my $indent = 17;
33
my $GBE_UNIX = $ENV{GBE_UNIX} || 0;
34
my $CWD;
35
my $PSPLIT;
36
 
37
#-------------------------------------------------------------------------------
38
# Function        : Main Entry
39
#
40
# Description     :
41
#
42
# Inputs          :
43
#
44
# Returns         :
45
#
46
my $result = GetOptions (
47
                "help:+"        => \$opt_help,          # flag, multiple use allowed
48
                "manual:3"      => \$opt_help,          # flag
49
                "verbose:+"     => \$opt_verbose,       # flag
50
                );
51
 
52
#
53
#   Process help and manual options
54
#
55
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
56
pod2usage(-verbose => 1)  if ($opt_help == 2 );
57
pod2usage(-verbose => 2)  if ($opt_help > 2);
58
 
59
#
60
#   Init some useful variables
61
#
62
$CWD = getcwd();
63
$PSPLIT = $GBE_UNIX ? ':' : ';';                               # Win/Unix path splitter
64
if ( $opt_verbose > 1 ) {
65
    dump_full();
66
} else {
67
    dump_vars();
68
}
69
 
70
#-------------------------------------------------------------------------------
71
# Function        : display functions
72
#
73
# Description     : 
74
#
75
# Inputs          : 
76
#
77
# Returns         : 
78
#
79
 
80
#   Display an array separated list, one entry per line, with dir sanity check
81
sub alist
82
{
83
    my ($text, @var) = @_;
84
    my $sep = "=";
85
    for ( @var )
86
    {
87
        my $valid = ( -d $_ || -f $_ ) ? " " : "*";
88
        printf "%-${indent}s%s%s%s\n", $text, $sep, $valid, $_;
89
        $text = "";
90
        $sep = " ";
91
    }
92
}
93
 
94
# Simple print of name and variable
95
sub pvar
96
{
97
    my ($text, $data) = @_;
98
    $data =~ s~\n~\\n~g;
99
    printf "%-${indent}s= %s\n", $text, $data;
100
}
101
 
102
# Print of name and variable of directory with sanity check
103
sub dvar
104
{
105
    my ($text, $data) = @_;
106
    my $valid = ( ! $data || -d $data || -f $data ) ? " " : "*";
107
    printf "%-${indent}s=%s%s\n", $text, $valid, $data;
108
}
109
 
110
# Display a variable extracted from the environment
111
sub penv
112
{
113
    my ($var) = @_;
114
    pvar $var, $ENV{$var} || '';
115
}
116
 
117
# Display a variable extracted from the environment with dir sanity check
118
sub denv
119
{
120
    my ($var) = @_;
121
    dvar $var, $ENV{$var} || '';
122
}
123
 
124
#   Display a ';' or ':' separated list, one entry per line based on EnvVar
125
sub lenv
126
{
127
    my ($var) = @_;
128
    alist( $var, split $PSPLIT, $ENV{$var} || " " );
129
}
130
 
131
 
132
#-------------------------------------------------------------------------------
133
# Function        : dump_full
134
#
135
# Description     : Display ALL EnvVars
136
#
137
# Inputs          : 
138
#
139
# Returns         : 
140
#
141
sub dump_full
142
{
143
    Message ("Complete environment dump");
144
 
145
    $indent = 33;
146
    foreach my $var ( sort keys(%ENV) )
147
    {
148
        penv ($var);
149
    }
150
    return;
151
}
152
 
153
#-------------------------------------------------------------------------------
154
# Function        : dump_vars
155
#
156
# Description     : Dump selected environment varaibles
157
#
158
# Inputs          : 
159
#
160
# Returns         : 
161
#
162
sub dump_vars
163
{
164
    #
165
    #   Complete environment dump
166
    #
167
    if ( $opt_verbose > 1 )
168
    {
169
    }
170
 
171
    #
172
    #   Partial dump
173
    #   Display selected parts
174
    #
175
    penv    "GBE_VERSION";
176
    penv    "GBE_SCRIPT";
177
    penv    "GBE_DEBUG";
178
    penv    "GBE_VERBOSE";
179
 
180
    if ( $opt_verbose )
181
    {
182
        penv    "GBE_JATS_VERSION";
183
        penv    "GBE_JATS_SANE";
184
    }
185
    penv    "GBE_MACHTYPE";
186
    penv    "GBE_HOSTMACH";
187
    penv    "GBE_UNIX";
188
    penv    "GBE_DRV";
189
    denv    "GBE_PERL";
190
    denv    "GBE_CORE";
191
    denv    "GBE_BIN";
192
    denv    "GBE_TOOLS";
193
    denv    "GBE_CONFIG";
194
    penv    "GBE_CACHE_JATS";
195
    lenv    "GBE_SANDBOX";
196
    lenv    "GBE_DPKG_STORE";
197
    lenv    "GBE_DPKG";
198
    lenv    "GBE_DPKG_CACHE";
199
    lenv    "GBE_DPKG_LOCAL";
200
    lenv    "GBE_DPKG_SBOX";
201
    lenv    "GBE_DPLY";
202
    penv    "GBE_PLATFORM";
203
    penv    "GBE_BUILDFILTER";
204
    penv    "GBE_ABT";
205
    denv    "GBE_VIEWBASE";
206
    penv    "GBE_HOSTNAME";
207
    dvar    "CWD", $CWD;
208
 
209
    penv    "COMSPEC";
210
    penv    "SHELL";
211
    penv    "USER";
212
    lenv    "PATH";
213
 
214
    #
215
    #   Display variables used by various "known" toolsets
216
    #   These do cause grief sometime, so only do it for verbose
217
    #
218
    if ( $opt_verbose )
219
    {
220
 
221
        print "\nPerl Environment\n";
222
        pvar  "VERSION"         ,$];
223
        penv  "PERL5SHELL";
224
        penv  "PERL5OPT";
225
        lenv  "PERL5LIB";
226
        alist "INC"             ,@INC;
227
 
228
        print "\nJava Environment\n";
229
        foreach my $var ( sort grep ( {/^JAVA_HOME/ } keys %ENV) )
230
        {
231
            denv  $var;
232
        }
233
        denv  "ANT_HOME";
234
        denv  "JATS_HOME";
235
        lenv  "CLASSPATH";
236
    }
237
 
238
    if ( $opt_verbose || $ENV{GBE_ABT} )
239
    {
240
        print "\nRelease Manager Environment\n";
241
        penv    "GBE_RM_LOCATION";
242
        penv    "GBE_RM_USERNAME";
243
        penv    "GBE_RM_PASSWORD";
244
        penv    "GBE_RM_URL";
245
        penv    "GBE_DM_LOCATION";
246
        penv    "GBE_DM_USERNAME";
247
        penv    "GBE_DM_PASSWORD";
248
        penv    "GBE_DM_URL";
249
    }
250
 
341 dpurdie 251
    if ( $opt_verbose || $ENV{GBE_SVN_URL} || $ENV{GBE_SVN_USERNAME} || $ENV{GBE_SVN_PATH} )
315 dpurdie 252
    {
341 dpurdie 253
        print "\nSubVersion\n";
315 dpurdie 254
        denv    "GBE_SVN_PATH";
255
        penv    "GBE_SVN_URL";
256
        penv    "GBE_SVN_USERNAME";
257
        penv    "GBE_SVN_PASSWORD";
258
    }
259
 
260
    if ( $opt_verbose && ! $GBE_UNIX)
261
    {
262
        print "\nWindows Environment\n";
263
        denv  "TEMP";
264
        denv  "TMP";
265
 
266
        print "\nMicrosoft Studio Variables\n";
267
        denv  "PROGRAMFILES";
268
        denv  "WINDIR";
269
        denv  "MSVCDir";
270
 
271
        print "\nMicroTec Compiler Variables\n";
272
        denv "MRI_68K";
273
        denv "MRI_CF";
274
        denv "VISIONCLICK";
275
 
276
        print "\nPCLint Variables\n";
277
        denv "PCLINT";
278
        penv "LINTPACKAGE";
279
    }
280
}
281
 
282
#-------------------------------------------------------------------------------
283
#   Documentation
284
#
285
 
286
=pod
287
 
288
=head1 NAME
289
 
290
vars - Display Jats Related Environment Variables
291
 
292
=head1 SYNOPSIS
293
 
294
  jats vars [options]
295
 
296
 Options:
297
    -help              - brief help message
298
    -help -help        - Detailed help message
299
    -man               - Full documentation
300
    -verbose[=n]       - Verbose operation
301
 
302
=head1 OPTIONS
303
 
304
=over 8
305
 
306
=item B<-help>
307
 
308
Print a brief help message and exits.
309
 
310
=item B<-help -help>
311
 
312
Print a detailed help message with an explanation for each option.
313
 
314
=item B<-man>
315
 
316
Prints the manual page and exits.
317
This is the same as -help=3.
318
 
319
=item B<-man[=n]>
320
 
321
Set the help level directly. Valid values are 0,1,2 and 3.
322
 
323
=item B<-verbose[=n]>
324
 
325
This option will increase the level of verbosity of the command.
326
 
327
The allowed verbosity levels are:
328
 
329
=over 4
330
 
331
=item 0 Basic variable display
332
 
333
=item 1 will display additional JATS related information.
334
 
335
=item 2 will display all the Environment varaibles.
336
 
337
=back
338
 
339
=back
340
 
341
=head1 DESCRIPTION
342
 
343
This program will display the values of all JATS related environment variables.
344
 
345
Many of the variables will be displayed with sanity information. If the
346
variable is a PATH and and the PATH does not exist, then the displayed value
347
will be prefxied with a '*'
348
 
349
=cut
350