15 |
|
# checkparam($name,$par) : Exit with an error message if parameter |
16 |
|
# is undefined in tag $name |
17 |
|
# line() : return the current line number of the parse |
18 |
< |
|
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; |
34 |
|
return $self; |
35 |
|
} |
36 |
|
|
37 |
+ |
sub stream { |
38 |
+ |
my $self=shift; |
39 |
+ |
|
40 |
+ |
$self->{stream}=shift; |
41 |
+ |
} |
42 |
+ |
|
43 |
|
sub _initialise (hash1) { |
44 |
|
my $self=shift; |
45 |
|
$self->{filename}=shift; |
75 |
|
my $buf; |
76 |
|
$self->{linecount}=0; |
77 |
|
$self->_resetvars(); |
78 |
+ |
$self->{streamstore}=""; |
79 |
|
|
80 |
|
# Open the file |
81 |
|
use FileHandle; |
82 |
< |
my $filehandle; |
82 |
> |
local $filehandle; |
83 |
|
$filehandle=FileHandle->new(); |
84 |
< |
$filehandle->open("<$self->{filename}") |
84 |
> |
$filehandle->open("<".$self->{filename}) |
85 |
|
or return 1; |
86 |
|
# The buffering seems all messed up - best not to use it |
87 |
< |
$filehandle->setvbuf($buf, _IONBF, 300); |
87 |
> |
$filehandle->setvbuf($buf, _IONBF, 3000); |
88 |
|
|
89 |
|
# Start file processing |
90 |
|
while ( ($_=<$filehandle>) ) { |
91 |
|
$self->{linecount}++; |
92 |
|
$self->{currentline}=$_; |
85 |
– |
if ( $self->{linecount} > 5 ) { |
86 |
– |
$DB::single=1; |
87 |
– |
} |
93 |
|
$self->{stringpos}=0; |
94 |
|
while ( ($char=$self->_nextchar()) ne "" ) { |
95 |
|
$self->_checkchar($char); |
96 |
|
} # end char while |
97 |
|
} # End String while loop |
98 |
< |
close $filehandle; |
99 |
< |
1; |
98 |
> |
undef $filehandle; |
99 |
> |
$self->_printstream(); |
100 |
|
} |
101 |
|
|
102 |
|
sub checkparam($name, $key) { |
140 |
|
my $char=shift; |
141 |
|
my $string; |
142 |
|
|
143 |
+ |
|
144 |
|
# ---- In a tag |
145 |
|
if ( $self->{tagcontext}=~/tag/ ) { |
146 |
|
if ( ! $self->_quotetest($char) ) { |
166 |
|
my $char; |
167 |
|
$char=substr($self->{currentline},$self->{stringpos}++,1); |
168 |
|
# print "Debug : Fetching character $char\n"; |
169 |
+ |
|
170 |
+ |
# Keep a record for any stream processes |
171 |
+ |
$self->{streamstore}=$self->{streamstore}.$char; |
172 |
+ |
|
173 |
|
return $char; |
174 |
|
} |
175 |
|
|
183 |
|
$self->_resetstore(); |
184 |
|
$self->_resetlabels(); |
185 |
|
|
186 |
+ |
$self->{scramtmp}=$self->_popstream(); |
187 |
|
# Do we have an opening or closing tag? |
188 |
|
if ( ($char=$self->_nextchar()) eq "/" ) { #we have a closing tag |
189 |
|
$self->{tagcontext}="endtag"; |
242 |
|
my $tagroutine=shift; |
243 |
|
my @args=@_; |
244 |
|
my $rt; |
245 |
+ |
my $found=0; |
246 |
|
|
247 |
|
if ( $self->{groupchecker}->status() || |
248 |
|
( $self->{tagcontainer}->inquiregroup($tagroutine)) ) { |
249 |
|
$rt=$self->{tagcontainer}->getroutine($tagroutine); |
250 |
|
if ( $rt ne "" ) { |
251 |
|
&{$rt}( $self->{allw},@_); |
252 |
+ |
$found=1; |
253 |
|
} |
254 |
|
} |
255 |
+ |
|
256 |
+ |
if ( ! $found ) { |
257 |
+ |
$self->_printstream(); |
258 |
+ |
} |
259 |
+ |
$self->_clearstream(); |
260 |
+ |
} |
261 |
+ |
|
262 |
+ |
sub _clearstream { |
263 |
+ |
my $self=shift; |
264 |
+ |
$self->{streamstore}=(($self->{streamtmp} ne "")?$self->{streamtmp}:""); |
265 |
+ |
$self->{streamtmp}=""; |
266 |
+ |
} |
267 |
+ |
|
268 |
+ |
sub _popstream { |
269 |
+ |
my $self=shift; |
270 |
+ |
$self->{streamstore}=~s/(.*)(.)$/$1/; |
271 |
+ |
return $2; |
272 |
+ |
} |
273 |
+ |
|
274 |
+ |
sub _printstream { |
275 |
+ |
|
276 |
+ |
my $self=shift; |
277 |
+ |
|
278 |
+ |
# Stream output functionality |
279 |
+ |
if ( defined $self->{stream} ) { |
280 |
+ |
print {$self->{stream}} "$self->{streamstore}"; |
281 |
+ |
} |
282 |
|
} |
283 |
|
|
284 |
|
sub _removefromstack { |