[Bio] / FigKernelPackages / DocUtils.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/DocUtils.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6, Wed May 10 03:02:15 2006 UTC revision 1.7, Mon Jun 5 05:46:18 2006 UTC
# Line 196  Line 196 
196    
197  =head3 ModifyConfigFile  =head3 ModifyConfigFile
198    
199  C<< DocUtils::ModifyConfigFile($targetFile, \%changes); >>  C<< DocUtils::ModifyConfigFile($targetFile, \%changes, $one_flag); >>
200    
201  Modify the contents of a PERL configuration file. A PERL configuration file contains a  Modify the contents of a PERL configuration file. A PERL configuration file contains a
202  C<package> statement followed by a set of assignments having the form  C<package> statement followed by a set of assignments having the form
# Line 219  Line 219 
219    
220  Reference to a hash mapping variable names to string values.  Reference to a hash mapping variable names to string values.
221    
222    =item one_flag
223    
224    If TRUE, a check will be made to insure the file returns a value of 1.
225    
226  =back  =back
227    
228  =cut  =cut
# Line 237  Line 241 
241          # Open the target file for input and the temp file for output.          # Open the target file for input and the temp file for output.
242          Open(\*CONFIGIN, "<$targetFile");          Open(\*CONFIGIN, "<$targetFile");
243          Open(\*CONFIGOUT, ">$tempFile");          Open(\*CONFIGOUT, ">$tempFile");
244            # Denote we haven't found a trailer line.
245            my $oneFound = 0;
246          # Read through the target file.          # Read through the target file.
247          while (my $line = <CONFIGIN>) {          while (my $line = <CONFIGIN>) {
248              # Parse the input line. Note we look for the longest possible string value              # Parse the input line. Note we look for the longest possible string value
# Line 256  Line 262 
262                  print CONFIGOUT $newLine;                  print CONFIGOUT $newLine;
263              } elsif ($line =~ /^1;/) {              } elsif ($line =~ /^1;/) {
264                  # This is the end line, so we write out the rest of the variables.                  # This is the end line, so we write out the rest of the variables.
265                    my $lineCount = 0;
266                  for my $varName (keys %{$changes}) {                  for my $varName (keys %{$changes}) {
267                      # Find out if this variable has already been seen.                      # Find out if this variable has already been seen.
268                      if (! exists $varHash{$varName}) {                      if (! exists $varHash{$varName}) {
269                          # It hasn't been seen, so we need to add it to the output.                          # It hasn't been seen, so we need to add it to the output.
270                          my $value = $changes->{$varName};                          my $value = $changes->{$varName};
271                          my $newLine = _BuildAssignment($varName, $value, "");                          my $newLine = _BuildAssignment($varName, $value, "");
272                            Trace("Adding new value for $varName to config file.") if T(3);
273                          print CONFIGOUT $newLine;                          print CONFIGOUT $newLine;
274                            $lineCount++;
275                      }                      }
276                  }                  }
277                    Trace("$lineCount lines updated in config file.") if T(2);
278                    # Write out the end line.
279                    print CONFIGOUT "1;\n";
280                    # Denote we found it.
281                    $oneFound = 1;
282              } else {              } else {
283                  # Here the line doesn't parse, so we write it unmodified.                  # Here the line doesn't parse, so we write it unmodified.
284                  print CONFIGOUT $line;                  print CONFIGOUT $line;
285              }              }
286          }          }
287            # Complain if we didn't find a trailer.
288            if (! $oneFound) {
289                Confess("No trailer (1;) found in FIG_Config.pm.");
290            } else {
291          # Close the files and rename the output file so it overwrites the input file.          # Close the files and rename the output file so it overwrites the input file.
292          close CONFIGIN;          close CONFIGIN;
293          close CONFIGOUT;          close CONFIGOUT;
294          rename $tempFile, $targetFile;          rename $tempFile, $targetFile;
295      }      }
296  }  }
297    }
298    
299  =head3 Augment  =head3 Augment
300    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3