ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolDoc.pm
Revision: 1.1.2.9
Committed: Thu May 4 18:30:26 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_12_3
Changes since 1.1.2.8: +0 -1 lines
Log Message:
fix tool searching in other projects

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     $self->{switch}->filetoparse($file);
86 williamc 1.1.2.4 $self->{toolfound}=1;
87 williamc 1.1.2.1 $self->{switch}->parse("setup");
88 williamc 1.1.2.4 return $self->{toolfound};
89 williamc 1.1.2.1 }
90    
91     sub featuretext {
92     my $self=shift;
93     my $feature=shift;
94    
95     if ( @_ ) {
96     $self->{featuretext}{$feature}=shift;
97     }
98     else {
99     return ($self->{featuretext}{$feature});
100     }
101     }
102    
103     sub _checkdefault {
104     my $self=shift;
105     my $hashref=shift;
106    
107     if ( defined $$hashref{'default'} ) { #check default
108     my $default;
109     foreach $default ( split /:/, $$hashref{'default'} ) {
110     $default=~s/\"//;
111     if ($self->_testlocation($default,
112     [ $self->{tool}->getfeature($$hashref{'type'})] )) { return 1; }
113     }
114     }
115     return 0;
116     }
117    
118     sub _testlocation {
119     my $self=shift;
120     my $default=shift;
121     my $testfiles=shift;
122     my $OK='false';
123     my $file;
124    
125     chomp $default;
126     $default=$self->_expandvars($default);
127     print "Trying $default .... ";
128     if ( -f $default ) {
129     $OK="true";
130     }
131     else {
132     my $fh=FileHandle->new();
133     opendir $fh, $default or do { print "No \n"; return 0; };
134     ($#{$testfiles}==-1) ? $OK='false' : $OK='true';
135     print "\n";
136     my @files=readdir $fh;
137     undef $fh;
138     foreach $file ( @$testfiles ) {
139     print " Checking for $file .... ";
140     # now check that the required files are actually there
141     if ( ( $number = grep /\Q$file\L/, @files) == 0 ) {
142     $OK='false';
143     print "not found\n";
144     last;
145     }
146     print "found\n";
147     }
148     }
149     if ( $OK eq 'true' ) {
150     print "Directory Check Complete\n";
151     return 1
152     }
153     return 0
154     }
155    
156     sub _expandvars {
157     my $self=shift;
158     my $string=shift;
159    
160     return "" , if ( ! defined $string );
161     $string=~s{
162     \$\((\w+)\)
163     }{
164     if (defined $self->{ToolEnv}{$1}) {
165     $self->_expandvars($self->{ToolEnv}{$1});
166     } else {
167     "\$$1";
168     }
169     }egx;
170     $string=~s{
171     \$(\w+)
172     }{
173     if (defined $self->{ToolEnv}{$1}) {
174     $self->_expandvars($self->{ToolEnv}{$1});
175     } else {
176     "\$$1";
177     }
178     }egx;
179     return $string;
180     }
181    
182    
183     sub _askuser {
184     my $self=shift;
185     my $querystring=shift;
186     my $varname=shift;
187    
188     print $self->featuretext($self->{EnvContext});
189     for ( ;; ) {
190     print "\n".$querystring." (RETURN to log as missing)\nset $varname = ";
191     $path=<STDIN>;
192     chomp $path;
193     if ( $path ne "" ) {
194     if ( defined $self->{'client'}) { # must be a location
195     if ( $self->_testlocation($path , "H", $Envtype{$type} )) {
196     return $path;
197     }
198     print "Error : ".$path." does not exist.\n";
199     next;
200     }
201     }
202     else {
203     return $path;
204     }
205     } #end for
206    
207     }
208    
209     # -- Tag Routines
210    
211     sub Client_start {
212     my $self=shift;
213     my $name=shift;
214     my $hashref=shift;
215    
216     if ( $self->{Arch} ) {
217     $self->{'client'}=1;
218     }
219     }
220    
221     sub Client_end {
222     my $self=shift;
223     if ( $self->{Arch} ) {
224     undef $self->{'client'};
225     }
226     }
227    
228     sub Tool_Start {
229     my $self=shift;
230     my $name=shift;
231     my $hashref=shift;
232    
233     $self->{switch}->checktag($name, $hashref, 'name');
234     $self->{switch}->checktag($name, $hashref, 'version');
235     $self->{switch}->opengroup("Toolactive");
236    
237     # lower case the name
238     $$hashref{'name'}=~tr[A-Z][a-z];
239     # make sure we only pick up the tool requested
240     if ( ( $self->{tool}->name() eq $$hashref{'name'} ) &&
241     ($self->{tool}->version() eq $$hashref{'version'})) {
242     $self->{switch}->
243     allowgroup("Toolactive",$self->{switch}->currentparsename());
244     $self->{ToolEnv}{'SCRAMtoolname'}=$$hashref{'name'};
245     $self->{ToolEnv}{'SCRAMtoolversion'}=$$hashref{'version'};
246 williamc 1.1.2.4 $self->{toolfound}=0;
247 williamc 1.1.2.1 }
248     else {
249     $self->{switch}->disallowgroup("Toolactive",
250     $self->{switch}->currentparsename());
251     }
252     }
253    
254     sub Tool_End {
255     my $self=shift;
256     my $name=shift;
257     my $hashref=shift;
258    
259     $self->{switch}->closegroup("Toolactive");
260     }
261    
262     sub Environment_Start {
263     my $self=shift;
264     my $name=shift;
265     my $hashref=shift;
266    
267     $self->{switch}->checktag($name, $hashref, 'name');
268     if ( $self->{Arch} ) {
269     if ( defined $self->{EnvContext} ) {
270     $self->parserror(" Attempted to open new <$name> context".
271     " without closing the previous one");
272     }
273     $self->{currentenvtext}="";
274     $self->{EnvContext}=$$hashref{'name'};
275     undef $self->{Envvalue};
276     if ( exists $$hahsref{'type'} ) {
277     $self->{tool}->type($$hashref{'name'},$$hahsref{'type'});
278     }
279     if ( exists $$hashref{'value'}) {
280     $self->{Envvalue}=$$hashref{'value'};
281     }
282     elsif ( ! $self->interactive() ) {
283 williamc 1.1.2.5 # check the environment
284     if ( defined $ENV{$$hashref{'name'}} ) {
285     $self->{Envvalue}=$ENV{$$hashref{'name'}};
286     }
287     elsif ( $self->_checkdefault($hashref) ) {
288 williamc 1.1.2.1 $self->{Envvalue}=$$hashref{'default'};
289     }
290     }
291     }
292     }
293    
294     sub Env_text {
295     my $self=shift;
296     my $name=shift;
297     my $string=shift;
298    
299     if ( $self->{Arch} ) {
300     $self->{currentenvtext}=$self->{currentenvtext}.$string;
301     }
302     }
303    
304     sub Environment_End {
305     my $self=shift;
306     my $name=shift;
307    
308     if ( $self->{Arch} ) {
309     if ( ! defined $self->{EnvContext} ) {
310 williamc 1.1.2.8 $self->{switch}->parseerror("</$name> without an opening context");
311 williamc 1.1.2.1 }
312     # - set the help text
313     $self->featuretext($self->{EnvContext},$self->{currentenvtext});
314     if ( ! defined $self->{Envvalue} ) {
315     $self->{Envvalue}=$self->_askuser("Please Enter the Value Below:",
316     $self->{EnvContext});
317     }
318     $self->{Envvalue}=$self->_expandvars($self->{Envvalue});
319     $self->{tool}->addfeature($self->{EnvContext}, $self->{Envvalue});
320     $self->{ToolEnv}{$self->{EnvContext}}=$self->{Envvalue};
321     undef $self->{EnvContext};
322     undef $self->{Envvalue};
323     }
324     }
325    
326     sub Lib {
327     my $self=shift;
328     my $name=shift;
329     my $hashref=shift;
330    
331     $self->{switch}->checktag($name, $hashref, 'name');
332     if ( $self->{Arch} ) {
333     $self->{tool}->addfeature("lib",$$hashref{'name'});
334     }
335     }
336    
337     sub External_Start {
338     my $self=shift;
339     my $name=shift;
340     my $hashref=shift;
341    
342     $self->{switch}->checktag($name, $hashref,'ref');
343     if ( $self->{Arch} ) {
344 williamc 1.1.2.2 $self->{tool}->addfeature("_externals",$$hashref{'ref'});
345 williamc 1.1.2.1 }
346     }
347    
348     sub Arch_Start {
349     my $self=shift;
350     my $name=shift;
351     my $hashref=shift;
352    
353 williamc 1.1.2.5 $self->{switch}->checktag($name, $hashref,'name');
354 williamc 1.1.2.1 ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
355     : ($self->{Arch}=0);
356     push @{$self->{ARCHBLOCK}}, $self->{Arch};
357     }
358    
359     sub Arch_End {
360     my $self=shift;
361     my $name=shift;
362    
363     pop @{$self->{ARCHBLOCK}};
364     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
365     }
366    
367