ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/PreProcessedFile.pm
(Generate patch)

Comparing COMP/SCRAM/src/ActiveDoc/PreProcessedFile.pm (file contents):
Revision 1.2 by williamc, Fri Nov 19 17:15:28 1999 UTC vs.
Revision 1.5 by williamc, Fri Feb 18 10:32:16 2000 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines