ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/TreeMonkey.pm
(Generate patch)

Comparing COMP/SCRAM/src/ActiveDoc/TreeMonkey.pm (file contents):
Revision 1.1 by williamc, Wed Aug 18 15:38:29 1999 UTC vs.
Revision 1.2 by williamc, Fri Aug 20 09:07:19 1999 UTC

# Line 10 | Line 10
10   # goto(TreeNode)  : Tell the monkey to go to a particular node in the tree
11  
12   package TreeMonkey;
13 + require 5.001;
14 + use Utilities::ListIterator;
15  
16   sub new {
17          my $class=shift;
# Line 20 | Line 22 | sub new {
22  
23   sub goto {
24          my $self=shift;
25 <        $self->{currentnode)=shift;
25 >        my $node=shift;
26 >
27 >        $self->{currentnode}=$node;
28   }
29  
30   sub find {
# Line 29 | Line 33 | sub find {
33          my @words;
34          my $first;
35          my $found=0;
36 +        my $branch="";
37  
38          # Split string
39          ($first, @words)=split '/', $string;
40  
41          # Search towards root for first word or until we reach root
42 <        while ( ( $self->{currentnode}->name() ne $first ) ||
43 <                                   ( $self->{currentnode)->parent() ne "" ) ) {
44 <                $self->{currentnode)=$self->{currentnode)->parent();
42 >        while ( ( $self->{currentnode}->parent() ne '/' ) &&
43 >                        ( $self->{currentnode}->name() ne $first ) ) {
44 >                $self->{currentnode}=$self->{currentnode}->parent();
45          }
46          
47          # Check the case of just a single word
48 <        if (( $#words == 0 ) && ( $self->{currentnode}->name() eq $first )) {
48 >        if (( $#words < 0 )) {
49 >          if (( $self->{currentnode}->name() eq $first )) {
50                  $found=1;
51 +          }
52 +        }
53 +        else { #if we have some more words...
54 +          $f=1;
55 +          $n=0;
56 +          while ( ($f!=0)  && ( $n < $#words  ) ) {
57 +                my $branchlist=$self->{currentnode}->nodeList();
58 +                $f=$self->_checklist($words[$n],$branchlist);
59 +                $n++;
60 +                print $n." ".$f."\n";
61 +          }
62 +          $found=$f;
63          }
64  
65          # Now Search the child branches for the pattern
48        my $n=0;
49        my $i=0;
50        while ( $found==0 && $n>=0 ) {
51           $children=$self->{currentnode}->listbranch()) {
52           $n=$#children;
53           $branch=$children[$n]
54           if ( $branch eq $words[$i] ) {
55                $self->{currentnode}=$branch;
56                $i++;
57                if ( $n > $#words ) { $found=1; }
58           }
59           else {
60                $n--;  
61           }
62        } # end while
63
66          # Now return the object ID of the found node or null
67          if ( $found==1 ) {
68                  return $self->{currentnode};
# Line 69 | Line 71 | sub find {
71                 return "";
72          }
73   }
74 +
75 + # ------------------------ Support Routines ------------------------------
76 +
77 + sub _checklist {
78 +        my $self=shift;
79 +        my $word=shift;
80 +        my $branchlist=shift;
81 +        my $bit;
82 +        my $branch;
83 +        my $found=0;
84 +
85 +        $bit=ListIterator->new($branchlist);
86 +
87 +        while ( ($found==0)  && ( ! $bit->last() ) ) {
88 +           $branch=$bit->next();
89 +           if ( $branch->name() eq $word) {
90 +                $self->{currentnode}=$branch;
91 +                   $found=1;
92 +           }
93 +        } # end while
94 +        return $found;
95 + }
96 +
97 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines