ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolDoc.pm
Revision: 1.1.2.8
Committed: Tue Apr 25 14:13:46 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_12_2, V0_12_1
Changes since 1.1.2.7: +1 -1 lines
Log Message:
bugfixes

File Contents

# User Rev Content
1 williamc 1.1.2.1 #
2     # ToolDoc.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # SimpleDoc interface to initialise Tool objects
9     #
10     # Interface
11     # ---------
12     # new() : A new ToolDoc object
13     # tool(toolobj) : set the tool object for the class
14     # setup(file,$name,$version) : setup a tool object from the specified file
15 williamc 1.1.2.3 # return 0 for OK 1 for cancel
16 williamc 1.1.2.1 # interactive([0|1]) : set the interactive node 0=off 1=on
17    
18     package BuildSystem::ToolDoc;
19     require 5.004;
20     use ActiveDoc::SimpleDoc;
21    
22     sub new {
23     my $class=shift;
24     $self={};
25     bless $self, $class;
26     $self->init();
27     return $self;
28     }
29    
30     sub init {
31     my $self=shift;
32     $self->{switch}=ActiveDoc::SimpleDoc->new();
33     $self->{switch}->newparse("setup");
34     $self->{switch}->addtag("setup","Tool",\&Tool_Start, $self,
35     "", $self,
36     \&Tool_End, $self);
37     $self->{switch}->addtag("setup","Lib",\&Lib, $self,
38     "", $self,
39     "", $self);
40     $self->{switch}->addtag("setup","External",\&External_Start, $self,
41     "", $self,
42     "", $self);
43     $self->{switch}->addtag("setup","Client",\&Client_start, $self,
44     "", $self,
45     \&Client_end, $self);
46     $self->{switch}->addtag("setup","Environment",
47     \&Environment_Start, $self,
48     \&Env_text, $self,
49     \&Environment_End, $self);
50     $self->{switch}->grouptag("Tool","setup");
51     $self->{switch}->addtag("setup","Architecture",
52     \&Arch_Start,$self,
53     "", $self,
54     \&Arch_End,$self);
55     $self->{Arch}=1;
56 williamc 1.1.2.6 push @{$self->{ARCHBLOCK}}, $self->{Arch};
57 williamc 1.1.2.1
58     }
59    
60     sub interactive {
61     my $self=shift;
62    
63     @_?$self->{interactive}=shift
64     :((defined $self->{interactive})?$self->{interactive}:0);
65     }
66    
67     sub tool {
68     my $self=shift;
69     $self->{tool}=shift;
70     }
71    
72     sub setup {
73     my $self=shift;
74     my $file=shift;
75     my $name=shift;
76     my $version=shift;
77    
78     $self->{ToolEnv}{'SCRAMtoolname'}=$name;
79     $self->{ToolEnv}{'SCRAMtoolversion'}=$version;
80     $self->{ToolEnv}{'SCRAM_ARCH'}=$ENV{'SCRAM_ARCH'};
81    
82     $name=~tr[A-Z][a-z];
83     $self->{tool}->name($name);
84     $self->{tool}->version($version);
85 williamc 1.1.2.3 $self->{tool}->url($file);
86 williamc 1.1.2.1 $self->{switch}->filetoparse($file);
87 williamc 1.1.2.4 $self->{toolfound}=1;
88 williamc 1.1.2.1 $self->{switch}->parse("setup");
89 williamc 1.1.2.4 return $self->{toolfound};
90 williamc 1.1.2.1 }
91    
92     sub featuretext {
93     my $self=shift;
94     my $feature=shift;
95    
96     if ( @_ ) {
97     $self->{featuretext}{$feature}=shift;
98     }
99     else {
100     return ($self->{featuretext}{$feature});
101     }
102     }
103    
104     sub _checkdefault {
105     my $self=shift;
106     my $hashref=shift;
107    
108     if ( defined $$hashref{'default'} ) { #check default
109     my $default;
110     foreach $default ( split /:/, $$hashref{'default'} ) {
111     $default=~s/\"//;
112     if ($self->_testlocation($default,
113     [ $self->{tool}->getfeature($$hashref{'type'})] )) { return 1; }
114     }
115     }
116     return 0;
117     }
118    
119     sub _testlocation {
120     my $self=shift;
121     my $default=shift;
122     my $testfiles=shift;
123     my $OK='false';
124     my $file;
125    
126     chomp $default;
127     $default=$self->_expandvars($default);
128     print "Trying $default .... ";
129     if ( -f $default ) {
130     $OK="true";
131     }
132     else {
133     my $fh=FileHandle->new();
134     opendir $fh, $default or do { print "No \n"; return 0; };
135     ($#{$testfiles}==-1) ? $OK='false' : $OK='true';
136     print "\n";
137     my @files=readdir $fh;
138     undef $fh;
139     foreach $file ( @$testfiles ) {
140     print " Checking for $file .... ";
141     # now check that the required files are actually there
142     if ( ( $number = grep /\Q$file\L/, @files) == 0 ) {
143     $OK='false';
144     print "not found\n";
145     last;
146     }
147     print "found\n";
148     }
149     }
150     if ( $OK eq 'true' ) {
151     print "Directory Check Complete\n";
152     return 1
153     }
154     return 0
155     }
156    
157     sub _expandvars {
158     my $self=shift;
159     my $string=shift;
160    
161     return "" , if ( ! defined $string );
162     $string=~s{
163     \$\((\w+)\)
164     }{
165     if (defined $self->{ToolEnv}{$1}) {
166     $self->_expandvars($self->{ToolEnv}{$1});
167     } else {
168     "\$$1";
169     }
170     }egx;
171     $string=~s{
172     \$(\w+)
173     }{
174     if (defined $self->{ToolEnv}{$1}) {
175     $self->_expandvars($self->{ToolEnv}{$1});
176     } else {
177     "\$$1";
178     }
179     }egx;
180     return $string;
181     }
182    
183    
184     sub _askuser {
185     my $self=shift;
186     my $querystring=shift;
187     my $varname=shift;
188    
189     print $self->featuretext($self->{EnvContext});
190     for ( ;; ) {
191     print "\n".$querystring." (RETURN to log as missing)\nset $varname = ";
192     $path=<STDIN>;
193     chomp $path;
194     if ( $path ne "" ) {
195     if ( defined $self->{'client'}) { # must be a location
196     if ( $self->_testlocation($path , "H", $Envtype{$type} )) {
197     return $path;
198     }
199     print "Error : ".$path." does not exist.\n";
200     next;
201     }
202     }
203     else {
204     return $path;
205     }
206     } #end for
207    
208     }
209    
210     # -- Tag Routines
211    
212     sub Client_start {
213     my $self=shift;
214     my $name=shift;
215     my $hashref=shift;
216    
217     if ( $self->{Arch} ) {
218     $self->{'client'}=1;
219     }
220     }
221    
222     sub Client_end {
223     my $self=shift;
224     if ( $self->{Arch} ) {
225     undef $self->{'client'};
226     }
227     }
228    
229     sub Tool_Start {
230     my $self=shift;
231     my $name=shift;
232     my $hashref=shift;
233    
234     $self->{switch}->checktag($name, $hashref, 'name');
235     $self->{switch}->checktag($name, $hashref, 'version');
236     $self->{switch}->opengroup("Toolactive");
237    
238     # lower case the name
239     $$hashref{'name'}=~tr[A-Z][a-z];
240     # make sure we only pick up the tool requested
241     if ( ( $self->{tool}->name() eq $$hashref{'name'} ) &&
242     ($self->{tool}->version() eq $$hashref{'version'})) {
243     $self->{switch}->
244     allowgroup("Toolactive",$self->{switch}->currentparsename());
245     $self->{ToolEnv}{'SCRAMtoolname'}=$$hashref{'name'};
246     $self->{ToolEnv}{'SCRAMtoolversion'}=$$hashref{'version'};
247 williamc 1.1.2.4 $self->{toolfound}=0;
248 williamc 1.1.2.1 }
249     else {
250     $self->{switch}->disallowgroup("Toolactive",
251     $self->{switch}->currentparsename());
252     }
253     }
254    
255     sub Tool_End {
256     my $self=shift;
257     my $name=shift;
258     my $hashref=shift;
259    
260     $self->{switch}->closegroup("Toolactive");
261     }
262    
263     sub Environment_Start {
264     my $self=shift;
265     my $name=shift;
266     my $hashref=shift;
267    
268     $self->{switch}->checktag($name, $hashref, 'name');
269     if ( $self->{Arch} ) {
270     if ( defined $self->{EnvContext} ) {
271     $self->parserror(" Attempted to open new <$name> context".
272     " without closing the previous one");
273     }
274     $self->{currentenvtext}="";
275     $self->{EnvContext}=$$hashref{'name'};
276     undef $self->{Envvalue};
277     if ( exists $$hahsref{'type'} ) {
278     $self->{tool}->type($$hashref{'name'},$$hahsref{'type'});
279     }
280     if ( exists $$hashref{'value'}) {
281     $self->{Envvalue}=$$hashref{'value'};
282     }
283     elsif ( ! $self->interactive() ) {
284 williamc 1.1.2.5 # check the environment
285     if ( defined $ENV{$$hashref{'name'}} ) {
286     $self->{Envvalue}=$ENV{$$hashref{'name'}};
287     }
288     elsif ( $self->_checkdefault($hashref) ) {
289 williamc 1.1.2.1 $self->{Envvalue}=$$hashref{'default'};
290     }
291     }
292     }
293     }
294    
295     sub Env_text {
296     my $self=shift;
297     my $name=shift;
298     my $string=shift;
299    
300     if ( $self->{Arch} ) {
301     $self->{currentenvtext}=$self->{currentenvtext}.$string;
302     }
303     }
304    
305     sub Environment_End {
306     my $self=shift;
307     my $name=shift;
308    
309     if ( $self->{Arch} ) {
310     if ( ! defined $self->{EnvContext} ) {
311 williamc 1.1.2.8 $self->{switch}->parseerror("</$name> without an opening context");
312 williamc 1.1.2.1 }
313     # - set the help text
314     $self->featuretext($self->{EnvContext},$self->{currentenvtext});
315     if ( ! defined $self->{Envvalue} ) {
316     $self->{Envvalue}=$self->_askuser("Please Enter the Value Below:",
317     $self->{EnvContext});
318     }
319     $self->{Envvalue}=$self->_expandvars($self->{Envvalue});
320     $self->{tool}->addfeature($self->{EnvContext}, $self->{Envvalue});
321     $self->{ToolEnv}{$self->{EnvContext}}=$self->{Envvalue};
322     undef $self->{EnvContext};
323     undef $self->{Envvalue};
324     }
325     }
326    
327     sub Lib {
328     my $self=shift;
329     my $name=shift;
330     my $hashref=shift;
331    
332     $self->{switch}->checktag($name, $hashref, 'name');
333     if ( $self->{Arch} ) {
334     $self->{tool}->addfeature("lib",$$hashref{'name'});
335     }
336     }
337    
338     sub External_Start {
339     my $self=shift;
340     my $name=shift;
341     my $hashref=shift;
342    
343     $self->{switch}->checktag($name, $hashref,'ref');
344     if ( $self->{Arch} ) {
345 williamc 1.1.2.2 $self->{tool}->addfeature("_externals",$$hashref{'ref'});
346 williamc 1.1.2.1 }
347     }
348    
349     sub Arch_Start {
350     my $self=shift;
351     my $name=shift;
352     my $hashref=shift;
353    
354 williamc 1.1.2.5 $self->{switch}->checktag($name, $hashref,'name');
355 williamc 1.1.2.1 ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
356     : ($self->{Arch}=0);
357     push @{$self->{ARCHBLOCK}}, $self->{Arch};
358     }
359    
360     sub Arch_End {
361     my $self=shift;
362     my $name=shift;
363    
364     pop @{$self->{ARCHBLOCK}};
365     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
366     }
367    
368