6 |
|
# processed. |
7 |
|
# Interface |
8 |
|
# --------- |
9 |
+ |
# |
10 |
|
# new(file,objectref) : A new object - filename of file to parse |
11 |
< |
# objectref->of the methods |
11 |
> |
# objectref->of the methods |
12 |
|
# usetags(tagobjref) : Specify a tagcontainer set to direct to |
13 |
|
# to the desired routines |
14 |
|
# usegroupchecker(groupchecker) : Set a groupchecker |
15 |
|
# parse() : Parse the file |
16 |
< |
# line() : return the current line number of the parse |
17 |
< |
# tagstartline() : return the line number on which the current |
18 |
< |
# tag was opened |
19 |
< |
# stream(filehandle) : stream output to the filehandle if not handled |
20 |
< |
# in any other way |
16 |
> |
# line() : return the current line number of the parse |
17 |
> |
# tagstartline() : return the line number on which the current |
18 |
> |
# tag was opened |
19 |
> |
# stream(filehandle) : stream output to the filehandle if not handled |
20 |
> |
# in any other way |
21 |
|
package ActiveDoc::Switcher; |
22 |
+ |
use Utilities::Verbose; |
23 |
|
require 5.001; |
24 |
|
use Carp; |
25 |
|
|
26 |
+ |
BEGIN { print __PACKAGE__." still used.\n"; exit(1) } |
27 |
+ |
|
28 |
+ |
@ISA=qw(Utilities::Verbose); |
29 |
+ |
|
30 |
|
sub new { |
31 |
|
my $class=shift; |
32 |
|
my $file=shift; |
54 |
|
$self->{streamexclude}{$tag}=1; |
55 |
|
} |
56 |
|
|
57 |
< |
sub _initialise (hash1) { |
58 |
< |
my $self=shift; |
59 |
< |
$self->{filename}=shift; |
60 |
< |
|
61 |
< |
# add a default groupchecker |
62 |
< |
use ActiveDoc::GroupChecker; |
63 |
< |
$self->{groupchecker}=GroupChecker->new(); |
64 |
< |
$self->{groupchecker}->include("all"); |
65 |
< |
|
66 |
< |
# Add a default TagContainer |
67 |
< |
use ActiveDoc::TagContainer; |
68 |
< |
$self->{tagcontainer}=ActiveDoc::TagContainer->new(); |
69 |
< |
|
70 |
< |
} |
57 |
> |
sub _initialise (hash1) |
58 |
> |
{ |
59 |
> |
my $self=shift; |
60 |
> |
$self->{filename}=shift; |
61 |
> |
$self->verbose(">> New ActiveDoc::Switcher created."); |
62 |
> |
# add a default groupchecker |
63 |
> |
use ActiveDoc::GroupChecker; |
64 |
> |
$self->{groupchecker}=GroupChecker->new(); |
65 |
> |
$self->{groupchecker}->include("all"); |
66 |
> |
|
67 |
> |
# Add a default TagContainer |
68 |
> |
use ActiveDoc::TagContainer; |
69 |
> |
$self->{tagcontainer}=ActiveDoc::TagContainer->new(); |
70 |
> |
|
71 |
> |
} |
72 |
|
|
73 |
|
sub usetags { |
74 |
|
my $self=shift; |
97 |
|
use FileHandle; |
98 |
|
local $filehandle; |
99 |
|
$filehandle=FileHandle->new(); |
100 |
+ |
|
101 |
+ |
$self->verbose(">> Reading file: ".$self->{filename}." "); |
102 |
+ |
|
103 |
|
$filehandle->open("<".$self->{filename}) |
104 |
|
or return 1; |
95 |
– |
# The buffering seems all messed up - best not to use it |
96 |
– |
$filehandle->setvbuf($buf, _IONBF, 3000); |
105 |
|
|
106 |
|
# Start file processing |
107 |
|
while ( ($_=<$filehandle>) ) { |
108 |
|
$self->{linecount}++; |
109 |
+ |
# Skip lines that start with a hash. A better way |
110 |
+ |
# of adding comments than ignore tags: |
111 |
+ |
next if (/^#/); |
112 |
|
$self->{currentline}=$_; |
113 |
|
$self->{stringpos}=0; |
114 |
|
while ( ($char=$self->_nextchar()) ne "" ) { |
119 |
|
# make sure we close the last buffer |
120 |
|
$self->_calltag($self->{textcontext}, $self->{textcontext}, |
121 |
|
$self->_getstore()); |
111 |
– |
#$self->_printstream(); |
122 |
|
} |
123 |
+ |
|
124 |
+ |
sub parsefilelist |
125 |
+ |
{ |
126 |
+ |
my $self=shift; |
127 |
+ |
my ($char,$buf); |
128 |
+ |
|
129 |
+ |
$self->{linecount}=0; |
130 |
+ |
$self->_resetvars(); |
131 |
+ |
$self->{streamstore}=""; |
132 |
+ |
$self->{streamtmp}=""; |
133 |
+ |
|
134 |
+ |
foreach my $buildfile (@{$self->{filename}}) |
135 |
+ |
{ |
136 |
+ |
if ( -f $buildfile) |
137 |
+ |
{ |
138 |
+ |
# Open the file |
139 |
+ |
use FileHandle; |
140 |
+ |
local $filehandle; |
141 |
+ |
$filehandle=FileHandle->new(); |
142 |
+ |
$self->verbose(">> Reading file: ".$buildfile." "); |
143 |
+ |
$filehandle->open("<".$buildfile) or return 1; |
144 |
+ |
|
145 |
+ |
# Start file processing |
146 |
+ |
while ( ($_=<$filehandle>) ) |
147 |
+ |
{ |
148 |
+ |
$self->{linecount}++; |
149 |
+ |
# Skip lines that start with a hash. A better way |
150 |
+ |
# of adding comments than ignore tags: |
151 |
+ |
next if (/^#/); |
152 |
+ |
$self->{currentline}=$_; |
153 |
+ |
$self->{stringpos}=0; |
154 |
+ |
while ( ($char=$self->_nextchar()) ne "" ) |
155 |
+ |
{ |
156 |
+ |
$self->_checkchar($char); |
157 |
+ |
} # end char while |
158 |
+ |
} # End String while loop |
159 |
+ |
undef $filehandle; |
160 |
+ |
# Make sure we close the last buffer: |
161 |
+ |
$self->_calltag($self->{textcontext}, $self->{textcontext}, |
162 |
+ |
$self->_getstore()); |
163 |
+ |
} |
164 |
+ |
} |
165 |
+ |
} |
166 |
|
|
167 |
|
# |
168 |
|
# return the current line number |
202 |
|
|
203 |
|
# ---- In a tag |
204 |
|
if ( $self->{tagcontext}=~/tag/ ) { |
205 |
+ |
$self->{tagbuff}=$self->{tagbuff}.$char; |
206 |
|
if ( ! $self->_quotetest($char) ) { |
207 |
|
if ( ! $self->_labeltest($char) ) { |
208 |
|
if ( $char eq ">") { $self->_closetag(); } |
225 |
|
my $self=shift; |
226 |
|
my $char; |
227 |
|
$char=substr($self->{currentline},$self->{stringpos}++,1); |
174 |
– |
#print "Debug : Fetching character $char\n"; |
228 |
|
|
229 |
|
# Keep a record for any stream processes |
230 |
|
$self->{streamstore}=$self->{streamstore}.$char; |
248 |
|
|
249 |
|
# Do we have an opening or closing tag? |
250 |
|
if ( ($char=$self->_nextchar()) eq "/" ) { #we have a closing tag |
251 |
+ |
$self->{tagbuff}="<".$char; |
252 |
|
$self->{tagcontext}="endtag"; |
253 |
|
} |
254 |
|
else { # an opening tag |
255 |
+ |
$self->{tagbuff}="<"; |
256 |
|
$self->{tagcontext}="starttag"; |
257 |
|
$self->_checkchar($char); |
258 |
|
} |
204 |
– |
#print "\nDebug : Opening $self->{tagcontext}\n"; |
259 |
|
} |
260 |
|
|
261 |
|
# |
273 |
|
$tagroutine=$self->{tagname}."_".$self->{tagcontext}; |
274 |
|
$self->_calltag($tagroutine, $self->{tagname}, |
275 |
|
$self->{tagvar}); |
222 |
– |
#print "\nDebug : Closing Tag $tagroutine\n"; |
276 |
|
|
277 |
|
# -- Now make sure the text context is set for calling routines to |
278 |
|
# -- deal with text portions outside of tags |
315 |
|
my $rt; |
316 |
|
my $found=0; |
317 |
|
|
318 |
+ |
# print "TAGROUTINE: ",$tagroutine,"\n"; |
319 |
+ |
|
320 |
|
if ( $self->{groupchecker}->status() || |
321 |
|
( $self->{tagcontainer}->inquiregroup($tagroutine)) ) { |
322 |
|
($rt,$obj)=$self->{tagcontainer}->getroutine($tagroutine); |
367 |
|
my $this; |
368 |
|
|
369 |
|
undef @tempstack; |
315 |
– |
#print "In ----".$#{$stack}; |
370 |
|
# Keep popping until we find our string |
371 |
|
while ( ($this=(pop @{$stack})) ne "$name") { |
372 |
|
push @tempstack, $this; |
377 |
|
$this=pop @tempstack; |
378 |
|
push @{$stack}, $this; |
379 |
|
} |
326 |
– |
#print " Out ----".$#{$stack}; |
380 |
|
} |
381 |
|
|
382 |
|
# |
448 |
|
($self->{tagname}=$self->_getstore())=~tr/A-Z/a-z/; |
449 |
|
} |
450 |
|
else { |
451 |
< |
die ">Tag syntax error in $self->{tagname} on line ". |
452 |
< |
$self->line()." of file \n$self->{filename}"; |
451 |
> |
# -- assume that this is plain text |
452 |
> |
$self->{tagcontext}="text"; |
453 |
> |
$self->_resetstore(); |
454 |
> |
$self->_unshiftstore($self->{tagbuff}); |
455 |
> |
$self->{tagbuff}=""; |
456 |
> |
return; |
457 |
|
} |
458 |
|
} |
459 |
|
$self->_resetstore(); |
469 |
|
$self->{stringbuff}=$self->{stringbuff}.$char; |
470 |
|
} |
471 |
|
|
472 |
+ |
sub _unshiftstore() { |
473 |
+ |
my $self=shift; |
474 |
+ |
my $char=shift; |
475 |
+ |
|
476 |
+ |
$self->{stringbuff}=$char.$self->{stringbuff}; |
477 |
+ |
} |
478 |
+ |
|
479 |
|
sub _getstore() { |
480 |
|
my $self=shift; |
481 |
|
|