15 |
|
# file() : return the filename corresponding to url of the document |
16 |
|
# ProcessedFile() : return the filename corresponding to processed url |
17 |
|
# of the document |
18 |
< |
# line(number) : Return the line and fileobj corresponding to number in |
18 |
> |
# realline(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) : |
36 |
|
"", $self, "", $self); |
37 |
|
} |
38 |
|
|
39 |
< |
sub line { |
39 |
> |
sub realline { |
40 |
|
my $self=shift; |
41 |
|
my $origline=shift; |
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) ) { |
50 |
< |
$line=$line-$inc->lines()+1+($inc->endline()-$startline); |
48 |
> |
last if ( $line <= $startline ); |
49 |
> |
if ( $line >= ($inc->lines()+$startline+2) ) { |
50 |
> |
# take out the 2 carriage returns added |
51 |
> |
$line=$line-($inc->lines()+$startline-$inc->endline())-2; |
52 |
|
# n lines in original map to m lines in expanded |
53 |
|
} |
54 |
|
else { # must be in the include file |
55 |
< |
@fileobs=$self->config()->find($inc->file()); |
56 |
< |
print $inc->file()." line = $line-$startline $fileob\n"; |
58 |
< |
($line, $fileob)=$fileobs[0]->line($line-$startline+1); |
55 |
> |
($line, $fileob)=$self->{includes}[$i]->realline($line-$startline); |
56 |
> |
last; |
57 |
|
} |
58 |
|
} |
59 |
|
|
62 |
– |
print "line = $line $fileob\n"; |
60 |
|
return ($line, $fileob); |
61 |
|
} |
62 |
|
|
63 |
+ |
sub line { |
64 |
+ |
my $self=shift; |
65 |
+ |
my $line=$self->{currentparser}->line(); |
66 |
+ |
return $line, $self; |
67 |
+ |
} |
68 |
+ |
|
69 |
|
sub url { |
70 |
|
my $self=shift; |
71 |
|
|
72 |
|
if ( @_ ) { |
73 |
< |
my $url=shift; |
74 |
< |
($self->{url}, $file)=$self->{urlhandler}->get($url); |
75 |
< |
} |
76 |
< |
else { |
77 |
< |
$self->{url}; |
78 |
< |
} |
73 |
> |
my $url=shift; |
74 |
> |
($self->{url}, $file)=$self->{urlhandler}->get($url); |
75 |
> |
} |
76 |
> |
else { |
77 |
> |
$self->{url}; |
78 |
> |
} |
79 |
|
} |
80 |
|
|
81 |
|
sub ProcessedFile { |
87 |
|
my $self=shift; |
88 |
|
|
89 |
|
my ($url, $file)=$self->{urlhandler}->get($self->url()); |
87 |
– |
print $file." = File\n"; |
90 |
|
return $file; |
91 |
|
} |
92 |
|
|
93 |
< |
sub includefile { |
92 |
< |
use ActiveDoc::IncFile; |
93 |
> |
sub ProcessFile { |
94 |
|
my $self=shift; |
95 |
< |
my $fileobj=shift; |
95 |
< |
my $startline=shift; |
96 |
< |
my $endline=shift; |
97 |
< |
my $lines=shift; |
98 |
< |
|
99 |
< |
my $obj=IncFile->new(); |
100 |
< |
push @{$self->{includes}}, $obj; |
101 |
< |
$obj->init($fileobj,$startline,$endline,$lines); |
95 |
> |
return $self->file(); |
96 |
|
} |
97 |
|
|
98 |
|
sub update { |
99 |
|
my $self=shift; |
100 |
|
|
101 |
|
my $rv=0; |
102 |
+ |
my $outfile="_preprocess_".$self->url(); |
103 |
+ |
my $fileobj; |
104 |
+ |
my $sn; |
105 |
+ |
@{$self->{updatedfiles}}=(); |
106 |
|
|
107 |
< |
print "\nEntering Updating ".$self->url()."\n"; |
108 |
< |
# check file update OK |
109 |
< |
if ( $self->{lastsequence} != |
110 |
< |
$self->config()->cache()->updatenumber($self->url()) ){ |
113 |
< |
$rv=1; |
114 |
< |
} |
115 |
< |
# check dependencies |
116 |
< |
foreach $inc ( @{$self->{includes}} ) { |
117 |
< |
@fileobs=$self->config()->find($inc->file()); |
118 |
< |
$rv=$rv+$fileobjs[0]->update(); |
119 |
< |
if ( $inc->lastsequence() ne |
120 |
< |
$self->ObjectSpace->sequence($inc->file()) ) { |
121 |
< |
$rv=0; |
122 |
< |
} |
107 |
> |
# -- check the input file snd output sequence numbers are in sync |
108 |
> |
my $basefilenumber=$self->config()->cache()->updatenumber($self->url()); |
109 |
> |
if ( $basefilenumber != $self->{lastsequence} ) { |
110 |
> |
$rv=1; |
111 |
|
} |
112 |
< |
if ( $rv ) { |
113 |
< |
print " Need to Update\n"; |
112 |
> |
else { |
113 |
> |
# -- update dependencies |
114 |
> |
for (my $i=0; $i<=$#{$self->{includes}}; $i++ ) { |
115 |
> |
$fileobj=$self->{includes}[$i]; |
116 |
> |
$rv=$rv+$fileobj->update(); # make sure it up to date |
117 |
> |
|
118 |
> |
# -- has it changed since last time we built this object |
119 |
> |
$sn=$self->config()->sequence($fileobj->url()); |
120 |
> |
if ( $self->{includesdesc}[$i]->lastsequence() != $sn ) { |
121 |
> |
$rv++; |
122 |
> |
push @{$self->{updatedfiles}},$fileobj->url(); # record for test |
123 |
> |
} |
124 |
> |
} |
125 |
> |
} |
126 |
> |
|
127 |
> |
if ( $rv != 0 ) { |
128 |
> |
$self->verbose(" Need to Update ".$self->url()); |
129 |
|
# ---- sort out the preprocessed file in the cache |
130 |
|
my $newfile=$self->config()->cache()-> |
131 |
< |
filename("_preprocess_".$self->url()); |
132 |
< |
$self->config()->cache()->store("_preprocess_".$self->url(),$newfile); |
131 |
> |
filename($outfile); |
132 |
> |
$self->config()->cache()->store($outfile,$newfile); |
133 |
|
|
134 |
|
$self->process($self->config()->cache()->file($self->url()),$newfile); |
135 |
< |
$self->{lastsequence}++; |
135 |
> |
$self->{lastsequence}=$basefilenumber; |
136 |
> |
# store self in the objectstore by url |
137 |
> |
$self->config->store($self,$self->url()); |
138 |
> |
} |
139 |
> |
else { |
140 |
> |
$self->verbose("No Need to Update ".$self->url()); |
141 |
|
} |
142 |
|
return $rv; |
143 |
|
} |
144 |
|
|
145 |
+ |
sub updatedfiles { |
146 |
+ |
my $self=shift; |
147 |
+ |
return @{$self->{updatedfiles}}; |
148 |
+ |
} |
149 |
+ |
|
150 |
|
sub process { |
151 |
|
my $self=shift; |
152 |
|
my $filein=shift; |
153 |
|
my $fileout=shift; |
154 |
|
|
155 |
|
#-- create a new file in the url cache |
143 |
– |
print "PreProcessing $file\n output= $fileout \n"; |
156 |
|
$self->_cleanup(); |
157 |
|
$self->{fileout}=FileHandle->new(); |
158 |
|
$self->{fileout}->open(">".$fileout) or die "Unable to open $newfile\n" |
162 |
|
$self->parse("include", $self->{fileout}, "include_starttag"); |
163 |
|
|
164 |
|
$self->{fileout}->close(); |
165 |
+ |
$self->verbose("$fileout Created"); |
166 |
|
} |
167 |
|
|
168 |
|
sub store { |
175 |
|
print $fh $self->{lastsequence}."\n"; |
176 |
|
print $fh ($self->url()?$self->url():""); |
177 |
|
print $fh "\n"; |
178 |
< |
foreach $inc ( @{$self->{includes}} ) { |
178 |
> |
foreach $inc ( @{$self->{includesdesc}} ) { |
179 |
|
print $fh ">\n"; |
180 |
|
$inc->store($fh); |
181 |
|
} |
186 |
|
my $self=shift; |
187 |
|
my $location=shift; |
188 |
|
|
189 |
< |
my $fh=$self->openfile($location); |
189 |
> |
my $fh=$self->openfile("<".$location); |
190 |
|
|
191 |
|
$self->{lastsequence}=<$fh>; |
192 |
|
chomp $self->{lastsequence}; |
193 |
|
$self->{url}=<$fh>; |
194 |
|
chomp $self->{url}; |
195 |
|
while ( <$fh> ) { |
196 |
< |
if ( $_ eq ">") { |
196 |
> |
if ( $_ eq ">\n") { |
197 |
|
$inc=IncFile->new(); |
198 |
|
$inc->restore($fh); |
199 |
< |
push @{$self->{includes}}, $inc; |
199 |
> |
push @{$self->{includesdesc}}, $inc; |
200 |
> |
# resurrect the appropriate object ID |
201 |
> |
push @{$self->{includes}}, $self->getfile($inc->file()); |
202 |
|
} |
203 |
|
} |
204 |
|
$fh->close(); |
206 |
|
|
207 |
|
sub _cleanup { |
208 |
|
my $self=shift; |
209 |
< |
foreach $inc ( @{$self->{includes}} ) { |
209 |
> |
foreach $inc ( @{$self->{includesdesc}} ) { |
210 |
|
undef $inc; |
211 |
|
} |
212 |
+ |
undef @{$self->{includesdesc}}; |
213 |
|
undef @{$self->{includes}}; |
214 |
|
} |
215 |
|
|
216 |
+ |
sub _includefile { |
217 |
+ |
use ActiveDoc::IncFile; |
218 |
+ |
my $self=shift; |
219 |
+ |
my $fileobj=shift; |
220 |
+ |
my $startline=shift; |
221 |
+ |
my $endline=shift; |
222 |
+ |
my $lines=shift; |
223 |
+ |
|
224 |
+ |
my $obj=IncFile->new(); |
225 |
+ |
my $url=$fileobj->url(); |
226 |
+ |
my $sn=$self->config()->sequence($url); |
227 |
+ |
$obj->init($url,$startline,$endline,$lines, $sn); |
228 |
+ |
push @{$self->{includes}}, $fileobj; |
229 |
+ |
push @{$self->{includesdesc}}, $obj; |
230 |
+ |
} |
231 |
+ |
|
232 |
|
# ------------------------ Tag Routines ------------------------------- |
233 |
|
|
234 |
|
# |
243 |
|
print "Including ".$$hashref{'url'}."\n"; |
244 |
|
my $fileObj=$self->getfile($$hashref{'url'}); |
245 |
|
if ( defined $fileObj ) { |
214 |
– |
push @{$self->{includes}}, $fileObj; |
246 |
|
# dump out to our file in construction |
247 |
|
my $fh=FileHandle->new(); |
248 |
|
my $outfilename=$fileObj->ProcessedFile(); |
218 |
– |
print "Opening ".$fileObj->ProcessedFile()." for inclusion\n"; |
249 |
|
$fh->open("<".$outfilename) or die "Unable to open $outfilename\n"; |
250 |
|
print {$self->{fileout}} "\n";# always start an include on a new line |
251 |
+ |
my $linecount=0; |
252 |
|
while ( <$fh> ) { |
253 |
+ |
$linecount++; |
254 |
|
print {$self->{fileout}} $_; |
255 |
|
} |
256 |
|
print {$self->{fileout}} "\n";# always end include with new line |
257 |
|
undef $fh; |
258 |
+ |
$self->_includefile($fileObj, $self->{currentparser}->tagstartline(), |
259 |
+ |
$self->{currentparser}->line(), $linecount); |
260 |
|
} |
261 |
|
} |
262 |
|
|