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

Comparing COMP/SCRAM/src/ActiveDoc/Switcher.pm (file contents):
Revision 1.6 by williamc, Tue Nov 9 11:24:54 1999 UTC vs.
Revision 1.13 by williamc, Wed Mar 1 11:48:11 2000 UTC

# Line 12 | Line 12
12   #                                    to the desired routines
13   # usegroupchecker(groupchecker)    : Set a groupchecker
14   # parse()                          : Parse the file                            
15 # checkparam($name,$par)    : Exit with an error message if parameter
16 #                             is undefined in tag $name
15   # line()                    : return the current line number of the parse
16 + # tagstartline()            : return the line number on which the current
17 + #                             tag was opened
18   # stream(filehandle)        : stream output to the filehandle if not handled
19   #                               in any other way
20   package ActiveDoc::Switcher;
# Line 40 | Line 40 | sub stream {
40          $self->{stream}=shift;
41   }
42  
43 + sub streamexclude {
44 +        my $self=shift;
45 +        my $tag=shift;
46 +
47 +        $tag=~tr/A-Z/a-z/;
48 +        $self->{streamexclude}{$tag}=1;
49 + }
50 +
51   sub _initialise (hash1) {
52          my $self=shift;
53          $self->{filename}=shift;
# Line 76 | Line 84 | sub parse {
84          $self->{linecount}=0;
85          $self->_resetvars();
86          $self->{streamstore}="";
87 +        $self->{streamtmp}="";
88  
89          # Open the file
90          use FileHandle;
# Line 99 | Line 108 | sub parse {
108          $self->_printstream();
109   }
110  
102 sub checkparam($name, $key) {
103        my $self=shift;
104        my $name=shift;
105        my $key=shift;
106
107        if ( ! defined $self->{tagvar}{$key} ) {
108           print "Switcher: Badly formed $name tag -".
109                        " undefined $key parameter\n";
110           exit 1;
111        }
112 }
113
111   #
112   # return the current line number
113   #
# Line 118 | Line 115 | sub line {
115          my $self=shift;
116          return $self->{linecount};
117   }
118 +
119 + # return the line the current tag was opened
120 + sub tagstartline {
121 +        my $self=shift;
122 +        $self->{tagstart};
123 + }
124   # --------------- Utility routines ----------------------------
125  
126   #
# Line 177 | Line 180 | sub _opentag {
180          my $self=shift;
181          my $char;
182  
183 +        # Keep a record of where the tag started
184 +        $self->{tagstart}=$self->line();
185 +
186          # Close the last text segment
187 +        $self->{streamtmp}=$self->_popstream();
188          $self->_calltag($self->{textcontext}, $self->{textcontext},
189                                                          $self->_getstore());
190          $self->_resetstore();
191          $self->_resetlabels();
192  
186        $self->{scramtmp}=$self->_popstream();
193          # Do we have an opening or closing tag?
194          if ( ($char=$self->_nextchar()) eq "/" ) { #we have a closing tag
195            $self->{tagcontext}="endtag";
# Line 206 | Line 212 | sub _closetag {
212          $self->_closelabel();
213          
214          # -- Call the associated tag function if appropriate
215 <        $tagroutine=$self->{tagname}."_".$self->{tagcontext};
216 <        $self->_calltag($tagroutine, $self->{tagname},
215 >        if ( defined $self->{tagname} ) {
216 >         $tagroutine=$self->{tagname}."_".$self->{tagcontext};
217 >         $self->_calltag($tagroutine, $self->{tagname},
218                                                          $self->{tagvar});
219 <        #print "\nDebug : Closing Tag $tagroutine\n";
219 >         #print "\nDebug : Closing Tag $tagroutine\n";
220  
221 <        # -- Now make sure the text context is set for calling routines to
222 <        # -- deal with text portions outside of tags
223 <        if ( $self->{tagcontext} eq "starttag" ) {
221 >         # -- Now make sure the text context is set for calling routines to
222 >         # -- deal with text portions outside of tags
223 >         if ( $self->{tagcontext} eq "starttag" ) {
224            push @{$self->{textstack}} , $self->{textcontext};
225            $self->{textcontext}=$self->{tagname};
226 <        }
227 <        else {
226 >         }
227 >         else {
228            if ( $#{$self->{textstack}} > -1 ) {
229              if ( $self->{textcontext} eq $self->{tagname} ) {  
230                 $self->{textcontext}=pop @{$self->{textstack}};
# Line 232 | Line 239 | sub _closetag {
239               print "Warning : Unmatched </...> tag on line ".
240                                          $self->line()."\n";    
241            }
242 +         }
243          }
244          # Reset context back to text
245          $self->{tagcontext}="text";
# Line 246 | Line 254 | sub _calltag {
254  
255          if ( $self->{groupchecker}->status() ||
256                  ( $self->{tagcontainer}->inquiregroup($tagroutine)) ) {
257 <          $rt=$self->{tagcontainer}->getroutine($tagroutine);
257 >          ($rt,$obj)=$self->{tagcontainer}->getroutine($tagroutine);
258            if ( $rt ne "" ) {
259 +             if ( ! defined $obj ) {
260                 &{$rt}( $self->{allw},@_);
261 <               $found=1;
261 >             }
262 >             else {
263 >               &{$rt}( $obj,@_);
264 >             }
265 >             $found=1;
266            }
267          }
268          
269 <        if ( ! $found ) {
269 >        # stream function
270 >        if ( ! exists $self->{streamexclude}{$tagroutine} ) {
271              $self->_printstream();
272          }
273          $self->_clearstream();
# Line 353 | Line 367 | sub _labeltest {
367   sub _resetlabels {
368          my $self=shift;
369          undef $self->{tagvar};
370 +        undef $self->{tagname};
371   }
372  
373   sub _closelabel {
# Line 364 | Line 379 | sub _closelabel {
379           $self->{lastlabel}="";
380          }
381          elsif ( $self->_getstore() ne "") {
382 <         #Then it must be the tag name
383 <         ($self->{tagname}=$self->_getstore())=~tr/A-Z/a-z/;
382 >         # Then it must be the tag name
383 >         if ( ! defined $self->{tagname} ) {
384 >            ($self->{tagname}=$self->_getstore())=~tr/A-Z/a-z/;
385 >         }
386 >         else {
387 >            die ">Tag syntax error in $self->{tagname} on line ".
388 >                $self->line()." of file \n$self->{filename}";
389 >         }
390          }
391          $self->_resetstore();
392   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines