17 |
|
# of the document |
18 |
|
# line(number) : Return the line and fileobj corresponding to number in |
19 |
|
# processed file |
20 |
– |
# includefile(PreProcessedFileID, startline, endline, lines_in_file) : |
21 |
– |
# indicate a file object to be included in place of |
22 |
– |
# startline-endline in original file. |
20 |
|
# update() : update the preprocessed file as required. |
21 |
|
# store(filename) : |
22 |
|
# restore(filename) : |
42 |
|
|
43 |
|
my $fileob=$self; |
44 |
|
my $line=$origline; |
45 |
< |
foreach $inc ( @{$self->{includes}} ) { |
45 |
> |
for(my $i=0; $i<=$#{$self->{includesdesc}}; $i++ ) { |
46 |
> |
$inc=$self->{includesdesc}[$i]; |
47 |
|
$startline=$inc->startline(); |
48 |
|
last if ( $line < $startline ); |
49 |
|
if ( $line > ($inc->lines()+$startline) ) { |
51 |
|
# n lines in original map to m lines in expanded |
52 |
|
} |
53 |
|
else { # must be in the include file |
54 |
< |
@fileobs=$self->config()->find($inc->file()); |
55 |
< |
($line, $fileob)=$fileobs[0]->line($line-$startline+1); |
54 |
> |
($line, $fileob)=$self->{includes}[$i]-> |
55 |
> |
line($line-$startline+1); |
56 |
|
} |
57 |
|
} |
58 |
|
|
83 |
|
return $file; |
84 |
|
} |
85 |
|
|
88 |
– |
sub includefile { |
89 |
– |
use ActiveDoc::IncFile; |
90 |
– |
my $self=shift; |
91 |
– |
my $fileobj=shift; |
92 |
– |
my $startline=shift; |
93 |
– |
my $endline=shift; |
94 |
– |
my $lines=shift; |
95 |
– |
|
96 |
– |
my $obj=IncFile->new(); |
97 |
– |
push @{$self->{includes}}, $obj; |
98 |
– |
$obj->init($fileobj,$startline,$endline,$lines); |
99 |
– |
} |
86 |
|
|
87 |
|
sub update { |
88 |
|
my $self=shift; |
89 |
|
|
90 |
|
my $rv=0; |
91 |
+ |
my $outfile="_preprocess_".$self->url(); |
92 |
+ |
my $fileobj; |
93 |
+ |
my $sn; |
94 |
+ |
@{$self->{updatedfiles}}=(); |
95 |
|
|
96 |
< |
# check file update OK |
97 |
< |
if ( $self->{lastsequence} != |
98 |
< |
$self->config()->cache()->updatenumber($self->url()) ){ |
99 |
< |
$rv=1; |
110 |
< |
} |
111 |
< |
# check dependencies |
112 |
< |
foreach $inc ( @{$self->{includes}} ) { |
113 |
< |
@fileobs=$self->config()->find($inc->file()); |
114 |
< |
$rv=$rv+$fileobjs[0]->update(); |
115 |
< |
if ( $inc->lastsequence() ne |
116 |
< |
$self->ObjectSpace->sequence($inc->file()) ) { |
117 |
< |
$rv=0; |
118 |
< |
} |
96 |
> |
# -- check the input file snd output sequence numbers are in sync |
97 |
> |
my $basefilenumber=$self->config()->cache()->updatenumber($self->url()); |
98 |
> |
if ( $basefilenumber != $self->{lastsequence} ) { |
99 |
> |
$rv=1; |
100 |
|
} |
101 |
< |
if ( $rv ) { |
102 |
< |
print " Need to Update\n"; |
101 |
> |
else { |
102 |
> |
# -- update dependencies |
103 |
> |
for (my $i=0; $i<=$#{$self->{includes}}; $i++ ) { |
104 |
> |
$fileobj=$self->{includes}[$i]; |
105 |
> |
$rv=$rv+$fileobj->update(); # make sure it up to date |
106 |
> |
|
107 |
> |
# -- has it changed since last time we built this object |
108 |
> |
$sn=$self->config()->sequence($fileobj->url()); |
109 |
> |
if ( $self->{includesdesc}[$i]->lastsequence() != $sn ) { |
110 |
> |
$rv++; |
111 |
> |
push @{$self->{updatedfiles}},$fileobj->url(); # record for test |
112 |
> |
} |
113 |
> |
} |
114 |
> |
} |
115 |
> |
|
116 |
> |
if ( $rv != 0 ) { |
117 |
> |
print " Need to Update ".$self->url()."\n"; |
118 |
|
# ---- sort out the preprocessed file in the cache |
119 |
|
my $newfile=$self->config()->cache()-> |
120 |
< |
filename("_preprocess_".$self->url()); |
121 |
< |
$self->config()->cache()->store("_preprocess_".$self->url(),$newfile); |
120 |
> |
filename($outfile); |
121 |
> |
$self->config()->cache()->store($outfile,$newfile); |
122 |
|
|
123 |
|
$self->process($self->config()->cache()->file($self->url()),$newfile); |
124 |
< |
$self->{lastsequence}++; |
124 |
> |
$self->{lastsequence}=$basefilenumber; |
125 |
> |
# store self in the objectstore by url |
126 |
> |
$self->config->store($self,$self->url()); |
127 |
> |
} |
128 |
> |
else { |
129 |
> |
print "No Need to Update ".$self->url()."\n"; |
130 |
|
} |
131 |
|
return $rv; |
132 |
|
} |
133 |
|
|
134 |
+ |
sub updatedfiles { |
135 |
+ |
my $self=shift; |
136 |
+ |
return @{$self->{updatedfiles}}; |
137 |
+ |
} |
138 |
+ |
|
139 |
|
sub process { |
140 |
|
my $self=shift; |
141 |
|
my $filein=shift; |
142 |
|
my $fileout=shift; |
143 |
|
|
144 |
|
#-- create a new file in the url cache |
139 |
– |
print "PreProcessing $file\n output= $fileout \n"; |
145 |
|
$self->_cleanup(); |
146 |
|
$self->{fileout}=FileHandle->new(); |
147 |
|
$self->{fileout}->open(">".$fileout) or die "Unable to open $newfile\n" |
163 |
|
print $fh $self->{lastsequence}."\n"; |
164 |
|
print $fh ($self->url()?$self->url():""); |
165 |
|
print $fh "\n"; |
166 |
< |
foreach $inc ( @{$self->{includes}} ) { |
166 |
> |
foreach $inc ( @{$self->{includesdesc}} ) { |
167 |
|
print $fh ">\n"; |
168 |
|
$inc->store($fh); |
169 |
|
} |
174 |
|
my $self=shift; |
175 |
|
my $location=shift; |
176 |
|
|
177 |
< |
my $fh=$self->openfile($location); |
177 |
> |
my $fh=$self->openfile("<".$location); |
178 |
|
|
179 |
|
$self->{lastsequence}=<$fh>; |
180 |
|
chomp $self->{lastsequence}; |
181 |
|
$self->{url}=<$fh>; |
182 |
|
chomp $self->{url}; |
183 |
|
while ( <$fh> ) { |
184 |
< |
if ( $_ eq ">") { |
184 |
> |
if ( $_ eq ">\n") { |
185 |
|
$inc=IncFile->new(); |
186 |
|
$inc->restore($fh); |
187 |
< |
push @{$self->{includes}}, $inc; |
187 |
> |
push @{$self->{includesdesc}}, $inc; |
188 |
> |
# resurrect the appropriate object ID |
189 |
> |
push @{$self->{includes}}, $self->getfile($inc->file()); |
190 |
|
} |
191 |
|
} |
192 |
|
$fh->close(); |
194 |
|
|
195 |
|
sub _cleanup { |
196 |
|
my $self=shift; |
197 |
< |
foreach $inc ( @{$self->{includes}} ) { |
197 |
> |
foreach $inc ( @{$self->{includesdesc}} ) { |
198 |
|
undef $inc; |
199 |
|
} |
200 |
+ |
undef @{$self->{includesdesc}}; |
201 |
|
undef @{$self->{includes}}; |
202 |
|
} |
203 |
|
|
204 |
+ |
sub _includefile { |
205 |
+ |
use ActiveDoc::IncFile; |
206 |
+ |
my $self=shift; |
207 |
+ |
my $fileobj=shift; |
208 |
+ |
my $startline=shift; |
209 |
+ |
my $endline=shift; |
210 |
+ |
my $lines=shift; |
211 |
+ |
|
212 |
+ |
my $obj=IncFile->new(); |
213 |
+ |
my $url=$fileobj->url(); |
214 |
+ |
my $sn=$self->config()->sequence($url); |
215 |
+ |
$obj->init($url,$startline,$endline,$lines, $sn); |
216 |
+ |
push @{$self->{includes}}, $fileobj; |
217 |
+ |
push @{$self->{includesdesc}}, $obj; |
218 |
+ |
} |
219 |
+ |
|
220 |
|
# ------------------------ Tag Routines ------------------------------- |
221 |
|
|
222 |
|
# |
231 |
|
print "Including ".$$hashref{'url'}."\n"; |
232 |
|
my $fileObj=$self->getfile($$hashref{'url'}); |
233 |
|
if ( defined $fileObj ) { |
210 |
– |
push @{$self->{includes}}, $fileObj; |
234 |
|
# dump out to our file in construction |
235 |
|
my $fh=FileHandle->new(); |
236 |
|
my $outfilename=$fileObj->ProcessedFile(); |
237 |
|
$fh->open("<".$outfilename) or die "Unable to open $outfilename\n"; |
238 |
|
print {$self->{fileout}} "\n";# always start an include on a new line |
239 |
+ |
my $linecount=0; |
240 |
|
while ( <$fh> ) { |
241 |
+ |
$linecount++; |
242 |
|
print {$self->{fileout}} $_; |
243 |
|
} |
244 |
|
print {$self->{fileout}} "\n";# always end include with new line |
245 |
|
undef $fh; |
246 |
+ |
$self->_includefile($fileObj, $self->{currentparser}->tagstartline(), |
247 |
+ |
$self->{currentparser}->line(), $linecount); |
248 |
|
} |
249 |
|
} |
250 |
|
|