ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Runtime.pm
Revision: 1.2
Committed: Mon Aug 28 08:35:12 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.1: +218 -0 lines
Log Message:
remove Interface.pm

File Contents

# User Rev Content
1 williamc 1.2 #
2     # Runtime.pm
3     #
4     # Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # Prepare a runtime environment
9     #
10     # Interface
11     # ---------
12     # new() : A new Runtime object
13     # file(file) : Specify an environment description file
14     # doc(var) : Print out any documentation for the runtime env
15     # list() : return a list of all variables set
16     # printenv(shell) : output environment to stdout in shell format
17     # getvalue(var) : return a string - modified by type for the var specified
18    
19     package Runtime;
20     require 5.004;
21     use ActiveDoc::SimpleDoc;
22    
23     sub new {
24     my $class=shift;
25     $self={};
26     $self->{Arch}=1;
27     $self->{validtypes}={ 'path'=>1 };
28     push @{$self->{ARCHBLOCK}}, $self->{Arch};
29     bless $self, $class;
30     return $self;
31     }
32    
33     sub file {
34     my $self=shift;
35     my $filename=shift;
36     $self->_parsefile($filename);
37     }
38    
39     sub printenv {
40     my $self=shift;
41     my $shell=shift;
42    
43     foreach $var ( @{$self->{'varlist'}} ) {
44     $self->_printoutenv($shell,$var,
45     $self->_expandvar($self->getvalue($var)));
46     }
47     }
48    
49     sub list {
50     my $self=shift;
51     return @{$self->{'varlist'}};
52     }
53    
54     sub doc {
55     my $self=shift;
56     my $var=shift;
57     return $self->{vardoc}{$var};
58     }
59    
60     sub getvalue {
61     my $self=shift;
62     my $name=shift;
63    
64     my $string;
65     my @vals=@{$self->{vars}{$name}};
66    
67     if ( defined $self->{'vartype'}{$name} ) { #any type proceesing
68     $string=&{"_".$self->{'vartype'}{$name}}(@vals);
69     }
70     else {
71     $string=$vals[0];
72     }
73     return $string;
74     }
75    
76     # ---- Support Routines
77     sub _expandvar {
78     my $self=shift;
79     my $string=shift;
80    
81     return "" , if ( ! defined $string );
82     $string=~s{
83     \$\((\w+)\)
84     }{
85     if (defined $ENV{$1}) {
86     $self->_expandvar($ENV{$1});
87     } else {
88     "\$".$1;
89     }
90     }egx;
91     $string=~s{
92     \$(\w+)
93     }{
94     if (defined $ENV{$1}) {
95     $self->_expandvar($ENV{$1});
96     } else {
97     "\$".$1;
98     }
99     }egx;
100     return $string;
101     }
102    
103     sub _path {
104     my $self=shift;
105     my @vals=@_;
106    
107     @vals=$self->_removedoubles(@vals);
108     my $string=join ":", @vals;
109     return $string;
110     }
111    
112     sub _parsefile {
113     my $self=shift;
114     my $filename=shift;
115    
116     $self->{switch}=ActiveDoc::SimpleDoc->new();
117     $self->{switch}->newparse("runtime");
118     $self->{switch}->addignoretags("runtime");
119     $self->{switch}->filetoparse($filename);
120     $self->{switch}->addtag("runtime","Runtime",
121     \&Runtime_start, $self,
122     \&Runtime_text, $self,
123     \&Runtime_end, $self);
124     $self->{switch}->addtag("runtime","Architecture",
125     \&Arch_Start, $self, "",$self, \&Arch_End, $self);
126     $self->{Runtimecontext}=0;
127     $self->{switch}->parse("runtime");
128     }
129    
130     sub _printoutenv {
131     my $self=shift;
132     my $shell=shift;
133     my $variable=shift;
134     my $value=shift;
135    
136     if ( $shell eq "csh" ) {
137     print "setenv $variable \"$value\";\n";
138     }
139     elsif ( $shell eq "sh" ) {
140     print "$variable=\"$value\";\n";
141     print "export $variable;\n";
142     }
143     }
144    
145     # ------ Tag Routines
146    
147     sub Runtime_start {
148     my $self=shift;
149     my $name=shift;
150     my $hashref=shift;
151    
152     $self->{switch}->checktag($name,$hashref,'name');
153     $self->{switch}->checktag($name,$hashref,'value');
154     if ( $self->{Arch} ) {
155     if ( $self->{Runtimecontext} == 1 ) {
156     $self->{switch}->parseerror("No </$name> before new tag");
157     }
158     $self->{Runtimecontext}=1;
159    
160     push @{$self->{'varlist'}}, $$hashref{'name'};
161     push @{$self->{'vars'}{$$hashref{'name'}}}, $$hashref{'value'};
162     if ( defined $$hashref{'type'} ) {
163     if ( ( exists $self->{'vartype'}{$$hashref{'name'}} ) &&
164     ( $self->{'vartype'}{$$hashref{'name'}} ne $$hashref{'type'}) ){
165     $self->{switch}->parseerror("Redefinition of Variable".
166     " type for ".$$hashref{'name'});
167     }
168     $self->{'vartype'}{$$hashref{'name'}}=$$hashref{'type'};
169     if ( defined $self->{validtypes}{$$hashref{'type'}} ) {
170     $self->{switch}->parseerror(
171     "Unknown type ".$$hashref{'type'});
172     }
173     }
174     else {
175     $self->{'vartype'}{$$hashref{'name'}}=undef;
176     }
177     }
178     }
179    
180     sub Runtime_text {
181     my $self=shift;
182     my $name=shift;
183     my @vars=@_;
184    
185     if ( $self->{Arch} ) {
186     my $var=$self->{varlist}[$#{$self->{varlist}}];
187     $self->{'vardoc'}{$var}=$self->{'vardoc'}{$var}.
188     (join "", @vars);
189     }
190     }
191    
192     sub Runtime_end {
193     my $self=shift;
194     my $name=shift;
195     if ( $self->{Arch} ) {
196     $self->{Runtimecontext}=0;
197     }
198     }
199    
200     sub Arch_Start {
201     my $self=shift;
202     my $name=shift;
203     my $hashref=shift;
204    
205     $toolswitch->checktag($name, $hashref,'name');
206     ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
207     : ($self->{Arch}=0);
208     push @{$self->{ARCHBLOCK}}, $self->{Arch};
209     }
210    
211     sub Arch_End {
212     my $self=shift;
213     my $name=shift;
214    
215     pop @{$self->{ARCHBLOCK}};
216     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
217     }
218