@@ -293,7 +293,15 @@ $self->boss->message(5, "PATCHING '$new' '$dst' '$dir' $tt_vars $no_backup\n");
293293if ($dst =~ / \* $ / ) {
294294 warn " WE IS PATCHIN '$new '" ;
295295}
296- if (!-f $new ) {
296+ if ($new eq ' config_H.gc' and ref ($dst ) =~ / HASH/ ) {
297+ $self -> boss-> message(5, " _patch_file: using hash of values to update config_H.gc'\n " );
298+ $self -> _update_config_H_gc (" $dir /win32/config_H.gc" , $dst );
299+ }
300+ elsif ($new eq ' config.gc' and ref ($dst ) =~ / HASH/ ) {
301+ $self -> boss-> message(5, " _patch_file: using hash of values to update config.gc'\n " );
302+ $self -> _update_config_gc (" $dir /win32/config.gc" , $dst );
303+ }
304+ elsif (!-f $new ) {
297305 warn " ERROR: non-existing file '$new '" ;
298306 }
299307 elsif ($new =~ / \. tt$ / ) {
@@ -519,5 +527,96 @@ sub _apply_patch {
519527 }
520528}
521529
530+ sub _update_config_H_gc {
531+ my ($self , $fname , $update_hash ) = @_ ;
532+
533+ die " update hash arg is not a hash ref"
534+ if not ref ($update_hash ) =~ / HASH/ ;
535+
536+ open my $fh , $fname or die " Unable to open $fname , $! " ;
537+
538+ my $output ;
539+ while (defined (my $line = <$fh >)) {
540+ $line =~ s / [\r\n ]+$// ;
541+ if ($line =~ / #define\s +(\w +)/ and exists $update_hash -> {$1 }) {
542+ my $key = $1 ;
543+ $line
544+ = !defined $update_hash -> {$key } ? " /*#define $key \t\t / **/"
545+ : $update_hash -> {$key } eq ' define' ? " #define $key \t\t /* */"
546+ : " $update_hash ->{$key }" ;
547+ }
548+ $output .= " $line \n " ;
549+ }
550+
551+ $fh -> close ;
552+
553+
554+ rename $fname , " $fname .orig" or die $! ;
555+ open my $ofh , ' >' , $fname or die " Unable to open $fname to write to, $! " ;
556+ print {$ofh } $output ;
557+ $ofh -> close ;
558+
559+ }
560+
561+ sub _update_config_gc {
562+ my ($self , $fname , $update_hash ) = @_ ;
563+
564+ die " update hash arg is not a hash ref"
565+ if not ref ($update_hash ) =~ / HASH/ ;
566+
567+ open my $fh , $fname or die " Unable to open $fname , $! " ;
568+
569+ my @lines = (<$fh >);
570+ close $fh ;
571+
572+ my %data ;
573+ my @output ;
574+ my @perl_lines ; # lines starting with PERL
575+
576+ while (defined (my $line = shift @lines )) {
577+ $line =~ s / [\r\n ]+$// ;
578+ if ($line =~ / ^#/ ) {
579+ # headers stay as they are
580+ push @output , $line ;
581+ }
582+ elsif ($line =~ / ^PERL/ ) {
583+ push @perl_lines , $line ;
584+ }
585+ else {
586+ $line =~ m / ^([\w ]+)=(.+)$ / ;
587+ $data {$1 } = $2 ;
588+ }
589+ }
590+
591+ # fix up quoting of values
592+ foreach my $val (values %$update_hash ) {
593+ next if $val =~ / ^'/ ; # assumes symmetry, i.e. opening and closing
594+ $val = " '$val '" ;
595+ }
596+
597+ @data {keys %$update_hash } = values %$update_hash ;
598+ # foreach my $key (sort keys %$update_hash) {
599+ #
600+ # $self->boss->message(3, "Setting config, $key => $update_hash->{$key}");
601+ # $data{$key} = $update_hash->{$key};
602+ # }
603+
604+ my (@ucfirst_lines , @lcfirst_lines );
605+ foreach my $key (grep {/ ^[A-Z]/ } keys %data ) {
606+ push @ucfirst_lines , " $key =$data {$key }" ;
607+ }
608+ foreach my $key (grep {/ ^[_a-z]/ } keys %data ) {
609+ push @lcfirst_lines , " $key =$data {$key }" ;
610+ }
611+ push @output , (sort @ucfirst_lines ), (sort @lcfirst_lines ), @perl_lines ;
612+
613+ rename $fname , " $fname .orig" or die $! ;
614+ open my $ofh , ' >' , $fname or die " Unable to open $fname to write to, $! " ;
615+ say {$ofh } join " \n " , @output ;
616+ $ofh -> close ;
617+
618+ }
619+
620+
5226211;
523622
0 commit comments