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.3 by williamc, Wed Sep 29 11:52:28 1999 UTC vs.
Revision 1.12 by williamc, Tue Nov 23 17:20:40 1999 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 <
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;
21   require 5.001;
22   use Carp;
# Line 26 | Line 27 | sub new {
27          my $objectname=shift;
28          my $groupchecker=shift;
29  
30 <        my $self = {};
30 >        $self = {};
31          $self->{allw}=$objectname;
32          bless $self, $class;
33          $self->_initialise($file);
34          return $self;
35   }
36  
37 + sub stream {
38 +        my $self=shift;
39 +
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 65 | Line 80 | sub usegroupchecker {
80   sub parse {
81          my $self=shift;
82          my $char;
83 +        my $buf;
84          $self->{linecount}=0;
85          $self->_resetvars();
86 +        $self->{streamstore}="";
87 +        $self->{streamtmp}="";
88  
89          # Open the file
90          use FileHandle;
91 <        my $filehandle=FileHandle->new();
92 <        open( $filehandle , "$self->{filename}" )
91 >        local $filehandle;
92 >        $filehandle=FileHandle->new();
93 >        $filehandle->open("<".$self->{filename})
94             or return 1;
95 < #               or carp "Switcher: Cannot open $self->{filename} $! \n";
95 >        # The buffering seems all messed up - best not to use it
96 >        $filehandle->setvbuf($buf, _IONBF, 3000);
97  
78        print "Starting Parse $self->{filename}\n";
98          # Start file processing
99 <        while ( <$filehandle> ) {
99 >        while ( ($_=<$filehandle>) ) {
100           $self->{linecount}++;
101           $self->{currentline}=$_;
102           $self->{stringpos}=0;
# Line 85 | Line 104 | sub parse {
104             $self->_checkchar($char);
105           } # end char while
106          } # End String while loop
107 <        close $filehandle;
108 <        print "Exiting Parse $self->{filename}\n";
90 < }
91 <
92 < sub checkparam($name, $key) {
93 <        my $self=shift;
94 <        my $name=shift;
95 <        my $key=shift;
96 <
97 <        if ( ! defined $self->{tagvar}{$key} ) {
98 <           print "Switcher: Badly formed $name tag -".
99 <                        " undefined $key parameter\n";
100 <           exit 1;
101 <        }
107 >        undef $filehandle;
108 >        $self->_printstream();
109   }
110  
111   #
# Line 108 | 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 130 | Line 143 | sub _checkchar {
143          my $char=shift;
144          my $string;
145  
146 +
147          # ---- In a tag
148          if ( $self->{tagcontext}=~/tag/ ) {
149             if ( ! $self->_quotetest($char) ) {
# Line 155 | Line 169 | sub _nextchar() {
169          my $char;
170          $char=substr($self->{currentline},$self->{stringpos}++,1);
171   #       print "Debug : Fetching character $char\n";
172 +
173 +        # Keep a record for any stream processes
174 +        $self->{streamstore}=$self->{streamstore}.$char;
175 +
176          return $char;
177   }
178  
# Line 162 | 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();
# Line 226 | Line 248 | sub _calltag {
248          my $tagroutine=shift;
249          my @args=@_;
250          my $rt;
251 +        my $found=0;
252  
253          if ( $self->{groupchecker}->status() ||
254                  ( $self->{tagcontainer}->inquiregroup($tagroutine)) ) {
255 <          $rt=$self->{tagcontainer}->getroutine($tagroutine);
255 >          ($rt,$obj)=$self->{tagcontainer}->getroutine($tagroutine);
256            if ( $rt ne "" ) {
257 +             if ( ! defined $obj ) {
258                 &{$rt}( $self->{allw},@_);
259 +             }
260 +             else {
261 +               &{$rt}( $obj,@_);
262 +             }
263 +             $found=1;
264            }
265          }
266 +        
267 +        # stream function
268 +        if ( ! exists $self->{streamexclude}{$tagroutine} ) {
269 +            $self->_printstream();
270 +        }
271 +        $self->_clearstream();
272 + }
273 +
274 + sub _clearstream {
275 +        my $self=shift;
276 +        $self->{streamstore}=(($self->{streamtmp} ne "")?$self->{streamtmp}:"");
277 +        $self->{streamtmp}="";
278 + }
279 +
280 + sub _popstream {
281 +        my $self=shift;
282 +        $self->{streamstore}=~s/(.*)(.)$/$1/;
283 +        return $2;
284 + }
285 +
286 + sub _printstream {
287 +
288 +        my $self=shift;
289 +
290 +        # Stream output functionality
291 +        if ( defined $self->{stream} ) {
292 +            print {$self->{stream}} "$self->{streamstore}";
293 +        }
294   }
295  
296   sub _removefromstack {
# Line 308 | Line 365 | sub _labeltest {
365   sub _resetlabels {
366          my $self=shift;
367          undef $self->{tagvar};
368 +        undef $self->{tagname};
369   }
370  
371   sub _closelabel {
# Line 319 | Line 377 | sub _closelabel {
377           $self->{lastlabel}="";
378          }
379          elsif ( $self->_getstore() ne "") {
380 <         #Then it must be the tag name
381 <         ($self->{tagname}=$self->_getstore())=~tr/A-Z/a-z/;
380 >         # Then it must be the tag name
381 >         if ( ! defined $self->{tagname} ) {
382 >            ($self->{tagname}=$self->_getstore())=~tr/A-Z/a-z/;
383 >         }
384 >         else {
385 >            die ">Tag syntax error in $self->{tagname} on line ".
386 >                $self->line()." of file \n$self->{filename}";
387 >         }
388          }
389          $self->_resetstore();
390   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines