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 |
> |
#+($inc->endline()-$startline); |
53 |
|
# n lines in original map to m lines in expanded |
54 |
+ |
print "Included file lines = ".$inc->lines()." +2 \n"; |
55 |
+ |
print "Start tag= $startline , endtag=".$inc->endline()."\n"; |
56 |
|
} |
57 |
|
else { # must be in the include file |
58 |
< |
@fileobs=$self->config()->find($inc->file()); |
59 |
< |
($line, $fileob)=$fileobs[0]->line($line-$startline+1); |
58 |
> |
print "Passing $line-$startline \n"; |
59 |
> |
($line, $fileob)=$self->{includes}[$i]-> |
60 |
> |
realline($line-$startline); |
61 |
|
} |
62 |
|
} |
63 |
|
|
64 |
|
return ($line, $fileob); |
65 |
|
} |
66 |
|
|
67 |
+ |
sub line { |
68 |
+ |
my $self=shift; |
69 |
+ |
my $line=$self->{currentparser}->line(); |
70 |
+ |
return $line, $self; |
71 |
+ |
} |
72 |
+ |
|
73 |
|
sub url { |
74 |
|
my $self=shift; |
75 |
|
|
76 |
|
if ( @_ ) { |
77 |
< |
my $url=shift; |
78 |
< |
($self->{url}, $file)=$self->{urlhandler}->get($url); |
79 |
< |
} |
80 |
< |
else { |
81 |
< |
$self->{url}; |
82 |
< |
} |
77 |
> |
my $url=shift; |
78 |
> |
($self->{url}, $file)=$self->{urlhandler}->get($url); |
79 |
> |
} |
80 |
> |
else { |
81 |
> |
$self->{url}; |
82 |
> |
} |
83 |
|
} |
84 |
|
|
85 |
|
sub ProcessedFile { |
94 |
|
return $file; |
95 |
|
} |
96 |
|
|
97 |
< |
sub includefile { |
89 |
< |
use ActiveDoc::IncFile; |
97 |
> |
sub ProcessFile { |
98 |
|
my $self=shift; |
99 |
< |
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 |
> |
return $self->file(); |
100 |
|
} |
101 |
|
|
102 |
|
sub update { |
103 |
|
my $self=shift; |
104 |
|
|
105 |
|
my $rv=0; |
106 |
+ |
my $outfile="_preprocess_".$self->url(); |
107 |
+ |
my $fileobj; |
108 |
+ |
my $sn; |
109 |
+ |
@{$self->{updatedfiles}}=(); |
110 |
|
|
111 |
< |
# check file update OK |
112 |
< |
if ( $self->{lastsequence} != |
113 |
< |
$self->config()->cache()->updatenumber($self->url()) ){ |
114 |
< |
$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 |
< |
} |
111 |
> |
# -- check the input file snd output sequence numbers are in sync |
112 |
> |
my $basefilenumber=$self->config()->cache()->updatenumber($self->url()); |
113 |
> |
if ( $basefilenumber != $self->{lastsequence} ) { |
114 |
> |
$rv=1; |
115 |
|
} |
116 |
< |
if ( $rv ) { |
117 |
< |
print " Need to Update\n"; |
116 |
> |
else { |
117 |
> |
# -- update dependencies |
118 |
> |
for (my $i=0; $i<=$#{$self->{includes}}; $i++ ) { |
119 |
> |
$fileobj=$self->{includes}[$i]; |
120 |
> |
$rv=$rv+$fileobj->update(); # make sure it up to date |
121 |
> |
|
122 |
> |
# -- has it changed since last time we built this object |
123 |
> |
$sn=$self->config()->sequence($fileobj->url()); |
124 |
> |
if ( $self->{includesdesc}[$i]->lastsequence() != $sn ) { |
125 |
> |
$rv++; |
126 |
> |
push @{$self->{updatedfiles}},$fileobj->url(); # record for test |
127 |
> |
} |
128 |
> |
} |
129 |
> |
} |
130 |
> |
|
131 |
> |
if ( $rv != 0 ) { |
132 |
> |
$self->verbose(" Need to Update ".$self->url()); |
133 |
|
# ---- sort out the preprocessed file in the cache |
134 |
|
my $newfile=$self->config()->cache()-> |
135 |
< |
filename("_preprocess_".$self->url()); |
136 |
< |
$self->config()->cache()->store("_preprocess_".$self->url(),$newfile); |
135 |
> |
filename($outfile); |
136 |
> |
$self->config()->cache()->store($outfile,$newfile); |
137 |
|
|
138 |
|
$self->process($self->config()->cache()->file($self->url()),$newfile); |
139 |
< |
$self->{lastsequence}++; |
139 |
> |
$self->{lastsequence}=$basefilenumber; |
140 |
> |
# store self in the objectstore by url |
141 |
> |
$self->config->store($self,$self->url()); |
142 |
> |
} |
143 |
> |
else { |
144 |
> |
$self->verbose("No Need to Update ".$self->url()); |
145 |
|
} |
146 |
|
return $rv; |
147 |
|
} |
148 |
|
|
149 |
+ |
sub updatedfiles { |
150 |
+ |
my $self=shift; |
151 |
+ |
return @{$self->{updatedfiles}}; |
152 |
+ |
} |
153 |
+ |
|
154 |
|
sub process { |
155 |
|
my $self=shift; |
156 |
|
my $filein=shift; |
157 |
|
my $fileout=shift; |
158 |
|
|
159 |
|
#-- create a new file in the url cache |
139 |
– |
print "PreProcessing $file\n output= $fileout \n"; |
160 |
|
$self->_cleanup(); |
161 |
|
$self->{fileout}=FileHandle->new(); |
162 |
|
$self->{fileout}->open(">".$fileout) or die "Unable to open $newfile\n" |
166 |
|
$self->parse("include", $self->{fileout}, "include_starttag"); |
167 |
|
|
168 |
|
$self->{fileout}->close(); |
169 |
+ |
$self->verbose("$fileout Created"); |
170 |
|
} |
171 |
|
|
172 |
|
sub store { |
179 |
|
print $fh $self->{lastsequence}."\n"; |
180 |
|
print $fh ($self->url()?$self->url():""); |
181 |
|
print $fh "\n"; |
182 |
< |
foreach $inc ( @{$self->{includes}} ) { |
182 |
> |
foreach $inc ( @{$self->{includesdesc}} ) { |
183 |
|
print $fh ">\n"; |
184 |
|
$inc->store($fh); |
185 |
|
} |
190 |
|
my $self=shift; |
191 |
|
my $location=shift; |
192 |
|
|
193 |
< |
my $fh=$self->openfile($location); |
193 |
> |
my $fh=$self->openfile("<".$location); |
194 |
|
|
195 |
|
$self->{lastsequence}=<$fh>; |
196 |
|
chomp $self->{lastsequence}; |
197 |
|
$self->{url}=<$fh>; |
198 |
|
chomp $self->{url}; |
199 |
|
while ( <$fh> ) { |
200 |
< |
if ( $_ eq ">") { |
200 |
> |
if ( $_ eq ">\n") { |
201 |
|
$inc=IncFile->new(); |
202 |
|
$inc->restore($fh); |
203 |
< |
push @{$self->{includes}}, $inc; |
203 |
> |
push @{$self->{includesdesc}}, $inc; |
204 |
> |
# resurrect the appropriate object ID |
205 |
> |
push @{$self->{includes}}, $self->getfile($inc->file()); |
206 |
|
} |
207 |
|
} |
208 |
|
$fh->close(); |
210 |
|
|
211 |
|
sub _cleanup { |
212 |
|
my $self=shift; |
213 |
< |
foreach $inc ( @{$self->{includes}} ) { |
213 |
> |
foreach $inc ( @{$self->{includesdesc}} ) { |
214 |
|
undef $inc; |
215 |
|
} |
216 |
+ |
undef @{$self->{includesdesc}}; |
217 |
|
undef @{$self->{includes}}; |
218 |
|
} |
219 |
|
|
220 |
+ |
sub _includefile { |
221 |
+ |
use ActiveDoc::IncFile; |
222 |
+ |
my $self=shift; |
223 |
+ |
my $fileobj=shift; |
224 |
+ |
my $startline=shift; |
225 |
+ |
my $endline=shift; |
226 |
+ |
my $lines=shift; |
227 |
+ |
|
228 |
+ |
my $obj=IncFile->new(); |
229 |
+ |
my $url=$fileobj->url(); |
230 |
+ |
my $sn=$self->config()->sequence($url); |
231 |
+ |
$obj->init($url,$startline,$endline,$lines, $sn); |
232 |
+ |
push @{$self->{includes}}, $fileobj; |
233 |
+ |
push @{$self->{includesdesc}}, $obj; |
234 |
+ |
} |
235 |
+ |
|
236 |
|
# ------------------------ Tag Routines ------------------------------- |
237 |
|
|
238 |
|
# |
247 |
|
print "Including ".$$hashref{'url'}."\n"; |
248 |
|
my $fileObj=$self->getfile($$hashref{'url'}); |
249 |
|
if ( defined $fileObj ) { |
210 |
– |
push @{$self->{includes}}, $fileObj; |
250 |
|
# dump out to our file in construction |
251 |
|
my $fh=FileHandle->new(); |
252 |
|
my $outfilename=$fileObj->ProcessedFile(); |
253 |
|
$fh->open("<".$outfilename) or die "Unable to open $outfilename\n"; |
254 |
|
print {$self->{fileout}} "\n";# always start an include on a new line |
255 |
+ |
my $linecount=0; |
256 |
|
while ( <$fh> ) { |
257 |
+ |
$linecount++; |
258 |
|
print {$self->{fileout}} $_; |
259 |
|
} |
260 |
|
print {$self->{fileout}} "\n";# always end include with new line |
261 |
|
undef $fh; |
262 |
+ |
$self->_includefile($fileObj, $self->{currentparser}->tagstartline(), |
263 |
+ |
$self->{currentparser}->line(), $linecount); |
264 |
|
} |
265 |
|
} |
266 |
|
|