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.3 by williamc, Tue Nov 23 17:20:40 1999 UTC vs.
Revision 1.11 by sashby, Fri Dec 10 13:41:36 2004 UTC

# Line 9 | Line 9
9   #
10   # Interface
11   # ---------
12 < # new()         : A new PreProcessedFile object
12 > # new(cache,dbstore)  : A new PreProcessedFile object
13   # url([url])    : return the full url. With an argument will take the given
14   #                 url and expand it in the context of the current url base.
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
19 < #                 processed file
20 < # update()          : update the preprocessed file as required.
21 < # store(filename)   :
18 > # realline(number): Return the line and fileobj corresponding to number in
19 > #                   processed file
20 > # update()        : update the preprocessed file as required.
21 > # store(filename) :
22   # restore(filename) :
23  
24   package ActiveDoc::PreProcessedFile;
25   use ActiveDoc::ActiveDoc;
26 + use ActiveDoc::IncFile;
27 + use Utilities::Verbose;
28 + use ObjectUtilities::StorableObject;
29   require 5.004;
30 < @ISA=qw(ActiveDoc::ActiveDoc);
30 > @ISA=qw(ObjectUtilities::StorableObject Utilities::Verbose);
31 >
32 >
33 > sub new {
34 >        my $class=shift;
35 >        my $self={};
36 >        bless $self, $class;
37 >        $self->{dbstore}=shift;
38 >        $self->cache($self->{dbstore}->cache());
39 >        bless $self, $class;
40 >        return $self;
41 > }
42 >
43 > sub cache {
44 >        my $self=shift;
45 >        if ( @_ ) {
46 >           $self->{cache}=shift;
47 >           $self->init();
48 >        }
49 >        return $self->{cache};
50 > }
51  
52   sub init {
53          my $self=shift;
54          $self->{lastsequence}=-1;
55 <        # Specific Tags
56 <        $self->newparse("include");
57 <        $self->addurltags("include");
58 <        $self->addtag("include","Include", \&Include_Start, $self,      
55 >        $self->{switch}=ActiveDoc::ActiveDoc->new($self->{dbstore});
56 >
57 >        # -- Specific Tags
58 >        $self->{switch}->newparse("include");
59 >        $self->{switch}->addbasetags("include");
60 >        $self->{switch}->addtag("include","include", \&Include_Start, $self,    
61                                            "", $self, "", $self);
62   }
63  
64 < sub line {
64 > sub realline {
65          my $self=shift;
66          my $origline=shift;
67  
# Line 45 | Line 70 | sub line {
70          for(my $i=0; $i<=$#{$self->{includesdesc}}; $i++ ) {
71            $inc=$self->{includesdesc}[$i];
72            $startline=$inc->startline();
73 <          last if ( $line < $startline );
74 <          if ( $line > ($inc->lines()+$startline) ) {
75 <            $line=$line-$inc->lines()+1+($inc->endline()-$startline);
73 >          last if ( $line <= $startline );
74 >          if ( $line >= ($inc->lines()+$startline+2) ) {
75 >                                        # take out the 2 carriage returns added
76 >            $line=$line-($inc->lines()+$startline-$inc->endline())-2;
77                           # n lines in original map to m lines in expanded
78            }
79            else { # must be in the include file
80 <            ($line, $fileob)=$self->{includes}[$i]->
81 <                                        line($line-$startline+1);
80 >            ($line, $fileob)=$self->{includes}[$i]->realline($line-$startline);
81 >            last;
82            }
83          }
84          
85          return ($line, $fileob);
86   }
87  
88 + sub line {
89 +        my $self=shift;
90 +        my $line=$self->{switch}->currentparser()->line();
91 +        return $line, $self;
92 + }
93 +
94   sub url {
95          my $self=shift;
96  
97          if ( @_ ) {
98 <          my $url=shift;
99 <          ($self->{url}, $file)=$self->{urlhandler}->get($url);
100 <        }
101 <        else {
102 <          $self->{url};
103 <        }
98 >           my $url=shift;
99 >          ($self->{url}, $file)=$self->{switch}->urlget($url);
100 >          $self->{switch}->filetoparse($file);
101 >          $self->{switch}->filenameref($self->{url}." ($file)");
102 >        }
103 >        return $self->{url};
104   }
105  
106   sub ProcessedFile {
107          my $self=shift;
108 <        $self->config()->cache()->file("_preprocess_".$self->url());
108 >        $self->{cache}->file("_preprocess_".$self->url());
109   }
110  
111   sub file {
112          my $self=shift;
113          
114 <        my ($url, $file)=$self->{urlhandler}->get($self->url());
114 >        my ($url, $file)=$self->{switch}->urlget($self->url());
115 >        $self->verbose("Getting file ".$self->url()." = $file");
116          return $file;
117   }
118  
119 + sub ProcessFile {
120 +        my $self=shift;
121 +        return $self->file();
122 + }
123  
124   sub update {
125          my $self=shift;
# Line 92 | Line 129 | sub update {
129          my $fileobj;
130          my $sn;
131          @{$self->{updatedfiles}}=();
132 <        
132 >
133          # -- check the input file snd output sequence numbers are in sync
134 <        my $basefilenumber=$self->config()->cache()->updatenumber($self->url());
134 >        my $basefilenumber=$self->{cache}->updatenumber($self->url());
135          if ( $basefilenumber != $self->{lastsequence} ) {
136              $rv=1;
137          }
# Line 105 | Line 142 | sub update {
142               $rv=$rv+$fileobj->update(); # make sure it up to date
143  
144               # -- has it changed since last time we built this object
145 <             $sn=$self->config()->sequence($fileobj->url());
145 >             $sn=$self->{dbstore}->sequence($fileobj->url());
146               if ( $self->{includesdesc}[$i]->lastsequence() != $sn ) {
147                 $rv++;
148                 push @{$self->{updatedfiles}},$fileobj->url(); # record for test
# Line 114 | Line 151 | sub update {
151          }
152  
153          if ( $rv != 0 ) {
154 <         print " Need to Update ".$self->url()."\n";
154 >         $self->verbose(" Need to Update ".$self->url());
155            # ---- sort out the preprocessed file in the cache
156 <          my $newfile=$self->config()->cache()->
120 <                                filename($outfile);
121 <          $self->config()->cache()->store($outfile,$newfile);
156 >          my $newfile=$self->{cache}->filename($outfile);
157            
158 <          $self->process($self->config()->cache()->file($self->url()),$newfile);
158 >          $self->process($self->{cache}->file($self->url()),$newfile);
159 >          $self->{cache}->store($outfile,$newfile);
160            $self->{lastsequence}=$basefilenumber;
161 <          # store self in the objectstore by url
162 <          $self->config->store($self,$self->url());
161 >          # -- store self in the objectstore by url
162 >          $self->{dbstore}->store($self,$self->url());
163          }
164          else {
165 <            print "No Need to Update ".$self->url()."\n";
165 >            $self->verbose("No Need to Update ".$self->url());
166          }
167          return $rv;
168   }
# Line 141 | Line 177 | sub process {
177          my $filein=shift;
178          my $fileout=shift;
179  
180 <        #-- create a new file in the url cache
180 >        # -- create a new file in the url cache
181          $self->_cleanup();
182          $self->{fileout}=FileHandle->new();
183          $self->{fileout}->open(">".$fileout) or die "Unable to open $newfile\n"
184                                  ."$!\n";
185  
186 <        # turn on the switch streamer
187 <        $self->parse("include", $self->{fileout}, "include_starttag");
186 >        # -- turn on the switch streamer
187 >        $self->{switch}->parse("include", $self->{fileout}, "include_starttag");
188  
189          $self->{fileout}->close();
190 +        $self->verbose("$fileout Created");
191   }
192  
193   sub store {
# Line 159 | Line 196 | sub store {
196  
197          my $fh=$self->openfile(">".$location);
198  
199 <        # get all include objects to store themselves
199 >        # -- get all include objects to store themselves
200          print $fh $self->{lastsequence}."\n";
201 +        print $fh ref($self->cache()).":::".$self->cache()->location()."\n";
202          print $fh ($self->url()?$self->url():"");
203          print $fh "\n";
204          foreach $inc ( @{$self->{includesdesc}} ) {
# Line 178 | Line 216 | sub restore {
216  
217          $self->{lastsequence}=<$fh>;
218          chomp $self->{lastsequence};
219 <        $self->{url}=<$fh>;
220 <        chomp $self->{url};
219 >        # -- recreate the cache
220 >        my $cacheinfo=<$fh>;
221 >        chomp $cacheinfo;
222 >        my ($type,$cachelocation)=split /:::/, $cacheinfo;
223 >        my $cache=$type->new($cachelocation);
224 >        $self->cache($cache);
225 >
226 >        my $url=<$fh>;
227 >        chomp $url;
228 >        $self->url($url);
229          while ( <$fh> ) {
230             if ( $_ eq ">\n") {
231 <                $inc=IncFile->new();
231 >                $inc=ActiveDoc::IncFile->new($self->{dbstore});
232                  $inc->restore($fh);
233                  push @{$self->{includesdesc}}, $inc;
234                  # resurrect the appropriate object ID
235 <                push @{$self->{includes}}, $self->getfile($inc->file());
235 >                push @{$self->{includes}}, $self->{switch}->getfile($inc->file());
236             }
237          }
238          $fh->close();
# Line 202 | Line 248 | sub _cleanup {
248   }
249  
250   sub _includefile {
205        use ActiveDoc::IncFile;
251          my $self=shift;
252          my $fileobj=shift;
253          my $startline=shift;
254          my $endline=shift;
255          my $lines=shift;
256          
257 <        my $obj=IncFile->new();
257 >        my $obj=ActiveDoc::IncFile->new();
258          my $url=$fileobj->url();
259 <        my $sn=$self->config()->sequence($url);
259 >        my $sn=$self->{dbstore}->sequence($url);
260          $obj->init($url,$startline,$endline,$lines, $sn);
261          push @{$self->{includes}}, $fileobj;
262          push @{$self->{includesdesc}}, $obj;
# Line 227 | Line 272 | sub Include_Start {
272          my $name=shift;
273          my $hashref=shift;
274  
275 <        $self->checktag( $name,$hashref, "url");
276 <        print "Including ".$$hashref{'url'}."\n";
277 <        my $fileObj=$self->getfile($$hashref{'url'});
275 >        $self->{switch}->checktag( $name,$hashref, "url");
276 >        $self->verbose("Including ".$$hashref{'url'});
277 >        my $fileObj=$self->{switch}->getfile($$hashref{'url'});
278          if ( defined $fileObj ) {
279            # dump out to our file in construction
280            my $fh=FileHandle->new();
# Line 238 | Line 283 | sub Include_Start {
283            print {$self->{fileout}} "\n";# always start an include on a new line
284            my $linecount=0;
285            while ( <$fh> ) {
286 <            $linecount++;
286 >          # Enable comments in files. Skip line if it
287 >          # starts with a hash:
288 >          next if /^#/;
289 >          $linecount++;
290              print {$self->{fileout}} $_;
291            }
292            print {$self->{fileout}} "\n";# always end include with new line
293            undef $fh;
294 <          $self->_includefile($fileObj, $self->{currentparser}->tagstartline(),
295 <                $self->{currentparser}->line(), $linecount);
294 >          $self->_includefile($fileObj,
295 >                $self->{switch}->currentparser()->tagstartline(),
296 >                $self->{switch}->currentparser()->line(), $linecount);
297          }
298   }
299  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines