[2] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
[74] | 3 | # Base subroutines for the Project-Builder project
|
---|
[2] | 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
| 7 |
|
---|
[18] | 8 | use strict;
|
---|
[5] | 9 | use lib qw (lib);
|
---|
[2] | 10 | use File::Basename;
|
---|
[9] | 11 | use File::Path;
|
---|
[2] | 12 | use File::Temp qw /tempdir/;
|
---|
[74] | 13 | use AppConfig qw(ARGCOUNT_HASH);
|
---|
[8] | 14 | use Data::Dumper;
|
---|
[2] | 15 |
|
---|
[49] | 16 | $ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
|
---|
[5] | 17 |
|
---|
[74] | 18 | sub pb_env_init {
|
---|
[2] | 19 |
|
---|
[5] | 20 | my $proj=shift;
|
---|
| 21 | my $ver;
|
---|
| 22 | my $tag;
|
---|
[2] | 23 |
|
---|
[8] | 24 | #
|
---|
[5] | 25 | # Check project name
|
---|
[49] | 26 | # Could be with env var PBPROJ
|
---|
| 27 | # or option -p
|
---|
| 28 | # if not define take the first in conf file
|
---|
[8] | 29 | #
|
---|
[5] | 30 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
| 31 | (not (defined $proj))) {
|
---|
| 32 | $proj = $ENV{'PBPROJ'};
|
---|
| 33 | }
|
---|
[69] | 34 |
|
---|
[49] | 35 | #
|
---|
[69] | 36 | # We get the pbrc file for that project
|
---|
| 37 | # and use its content
|
---|
| 38 | #
|
---|
[89] | 39 | my ($pbrc) = pb_conf_read("$ENV{'PBETC'}","pbrc");
|
---|
[74] | 40 | print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
|
---|
[69] | 41 |
|
---|
[70] | 42 | %pbrc = %$pbrc;
|
---|
[69] | 43 | if (not defined $proj) {
|
---|
| 44 | # Take the first as the default project
|
---|
| 45 | $proj = (keys %pbrc)[0];
|
---|
| 46 | print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
|
---|
| 47 | }
|
---|
| 48 | die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
|
---|
| 49 |
|
---|
| 50 | #
|
---|
| 51 | # Set delivery directory
|
---|
| 52 | #
|
---|
[71] | 53 | my $topdir=dirname($pbrc{$proj});
|
---|
[69] | 54 | chdir $topdir || die "Unable to change directory to $topdir";
|
---|
| 55 | $ENV{'PBDESTDIR'}=$topdir."/delivery";
|
---|
| 56 |
|
---|
| 57 | #
|
---|
[67] | 58 | # Use project configuration file if needed
|
---|
[49] | 59 | #
|
---|
[67] | 60 | if (not defined $ENV{'PBROOT'}) {
|
---|
[69] | 61 | if (-f $pbrc{$proj}) {
|
---|
[89] | 62 | my ($pbroot) = pb_conf_read($pbrc{$proj},"pbroot");
|
---|
[71] | 63 | my %pbroot = %$pbroot;
|
---|
[77] | 64 | # All lines should point to the same pbroot so take the first
|
---|
[69] | 65 | $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
|
---|
| 66 | print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
|
---|
[67] | 67 | }
|
---|
[69] | 68 | die "No pbroot defined - use env var PBROOT or -r pbroot " if (not defined $ENV{'PBROOT'});
|
---|
[49] | 69 | }
|
---|
[2] | 70 |
|
---|
[8] | 71 | #
|
---|
[49] | 72 | # Check pb conf compliance
|
---|
[8] | 73 | #
|
---|
[49] | 74 | $ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
|
---|
| 75 | die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
|
---|
[2] | 76 |
|
---|
[74] | 77 | my %version = ();
|
---|
| 78 |
|
---|
[49] | 79 | if (-f "$ENV{'PBCONF'}/$proj.pb") {
|
---|
[74] | 80 | # List of pkg to build by default (mandatory)
|
---|
| 81 | # List of additional pkg to build when all is called (optional)
|
---|
| 82 | # Valid version names (optional)
|
---|
| 83 | # List of files to filter (optional)
|
---|
[89] | 84 | my ($defpkgdir, $extpkgdir, $version, $filteredfiles) = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","defpkgdir","extpkgdir","version","filteredfiles");
|
---|
[74] | 85 | print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
|
---|
| 86 | print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
|
---|
| 87 | print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
|
---|
| 88 | print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
|
---|
| 89 | die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
|
---|
| 90 | # Global
|
---|
| 91 | %defpkgdir = %$defpkgdir;
|
---|
| 92 | # Global
|
---|
| 93 | %extpkgdir = ();
|
---|
| 94 | %extpkgdir = %$defpkgdir if (defined $defpkgdir);
|
---|
| 95 | %version = ();
|
---|
| 96 | %version = %$version if (defined $version);
|
---|
| 97 | # Global
|
---|
| 98 | %filteredfiles = ();
|
---|
| 99 | %filteredfiles = %$filteredfiles if (defined $filteredfiles);
|
---|
[38] | 100 | } else {
|
---|
[49] | 101 | die "Unable to open $ENV{'PBCONF'}/$proj.pb";
|
---|
[38] | 102 | }
|
---|
| 103 |
|
---|
[8] | 104 | #
|
---|
[5] | 105 | # Set temp directory
|
---|
[8] | 106 | #
|
---|
[7] | 107 | if (not defined $ENV{'TMPDIR'}) {
|
---|
[2] | 108 | $ENV{'TMPDIR'}="/tmp";
|
---|
| 109 | }
|
---|
[5] | 110 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
[2] | 111 |
|
---|
[8] | 112 | #
|
---|
[5] | 113 | # Get global VERSION
|
---|
[8] | 114 | #
|
---|
[11] | 115 | open(VER, "$ENV{'PBCONF'}/VERSION") || die "Unable to open $ENV{'PBCONF'}/VERSION: $?";
|
---|
[5] | 116 | $ver = <VER>;
|
---|
| 117 | chomp($ver);
|
---|
[8] | 118 | #print Dumper(%version);
|
---|
| 119 | die "Invalid version name $ver in $ENV{'PBROOT'}/VERSION" if ($ver !~ /[0-9.]+/) && (not exists $version{$ver});
|
---|
[5] | 120 | $ENV{'PBVER'}=$ver;
|
---|
| 121 | close(VER);
|
---|
| 122 |
|
---|
[8] | 123 | #
|
---|
[74] | 124 | # Get global TAG
|
---|
[8] | 125 | #
|
---|
[11] | 126 | open(TAG, "$ENV{'PBCONF'}/TAG") || die "Unable to open $ENV{'PBCONF'}/TAG: $?";
|
---|
[5] | 127 | $tag = <TAG>;
|
---|
| 128 | chomp($tag);
|
---|
[8] | 129 | die "Invalid tag name $tag in $ENV{'PBROOT'}/TAG" if ($tag !~ /[0-9]+/);
|
---|
[5] | 130 | $ENV{'PBTAG'}=$tag;
|
---|
| 131 | close(TAG);
|
---|
| 132 |
|
---|
[8] | 133 | #
|
---|
[69] | 134 | # Removes all directory existing below the delivery dir
|
---|
| 135 | # as they are temp dir only
|
---|
[68] | 136 | # Files stay and have to be cleaned up manually
|
---|
[8] | 137 | #
|
---|
[25] | 138 | if (-d $ENV{'PBDESTDIR'}) {
|
---|
| 139 | opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
|
---|
| 140 | foreach my $d (readdir(DIR)) {
|
---|
| 141 | next if ($d =~ /^\./);
|
---|
[68] | 142 | next if (-f "$ENV{'PBDESTDIR'}/$d");
|
---|
[74] | 143 | pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
|
---|
[25] | 144 | }
|
---|
| 145 | closedir(DIR);
|
---|
| 146 | }
|
---|
| 147 | if (! -d "$ENV{'PBDESTDIR'}") {
|
---|
[74] | 148 | pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
|
---|
[25] | 149 | }
|
---|
[5] | 150 |
|
---|
[25] | 151 | #
|
---|
| 152 | # Set build directory
|
---|
| 153 | #
|
---|
[71] | 154 | $ENV{'PBBUILDDIR'}=$topdir."/build";
|
---|
[74] | 155 | pb_rm_rf($ENV{'PBBUILDDIR'}) if (-d "$ENV{'PBBUILDDIR'}");
|
---|
| 156 | pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
|
---|
[25] | 157 |
|
---|
[8] | 158 | umask 0022;
|
---|
| 159 | return($proj);
|
---|
[2] | 160 | }
|
---|
[9] | 161 |
|
---|
[74] | 162 | # Internal mkdir -p function
|
---|
| 163 | sub pb_mkdir_p {
|
---|
[29] | 164 | my @dir = @_;
|
---|
| 165 | my $ret = mkpath(@dir, 0, 0755);
|
---|
| 166 | return($ret);
|
---|
[9] | 167 | }
|
---|
| 168 |
|
---|
[74] | 169 | # Internal rm -rf function
|
---|
| 170 | sub pb_rm_rf {
|
---|
[29] | 171 | my @dir = @_;
|
---|
| 172 | my $ret = rmtree(@dir, 0, 0);
|
---|
| 173 | return($ret);
|
---|
[9] | 174 | }
|
---|
| 175 |
|
---|
[74] | 176 | # Internal system function
|
---|
| 177 | sub pb_system {
|
---|
[29] | 178 |
|
---|
| 179 | my $cmd=shift;
|
---|
[30] | 180 | my $cmt=shift || $cmd;
|
---|
[29] | 181 |
|
---|
[30] | 182 | print $LOG "$cmt... ";
|
---|
[29] | 183 | system("$cmd");
|
---|
| 184 | if ($? == -1) {
|
---|
| 185 | print $LOG "failed to execute: $!\n" if ($debug >= 0);
|
---|
| 186 | } elsif ($? & 127) {
|
---|
| 187 | printf $LOG "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' if ($debug >= 0);
|
---|
| 188 | } else {
|
---|
[30] | 189 | print $LOG "OK\n" if ($debug >= 0);
|
---|
[29] | 190 | }
|
---|
[30] | 191 | }
|
---|
[74] | 192 |
|
---|
| 193 | # Function which returns a pointer on a hash
|
---|
[88] | 194 | # corresponding to a declaration (arg2) in the main conf file
|
---|
| 195 | # and test the returned vaue as they need to exist in that case
|
---|
| 196 | sub pb_conf_get {
|
---|
| 197 |
|
---|
| 198 | my @param = @_;
|
---|
| 199 |
|
---|
[89] | 200 | my @ptr = pb_conf_read("$ENV{'PBETC'}", @param);
|
---|
| 201 |
|
---|
[88] | 202 | foreach my $i (0..$#param) {
|
---|
| 203 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $ptr[$i]);
|
---|
| 204 | my $p = $ptr[$i];
|
---|
| 205 | $p->{$ENV{'PBPROJ'}} = $p->{'default'} if (not defined $p->{$ENV{'PBPROJ'}});
|
---|
| 206 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $p->{$ENV{'PBPROJ'}});
|
---|
| 207 | }
|
---|
[89] | 208 | print "DEBUG: param: ".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
| 209 | return(@ptr);
|
---|
[88] | 210 | }
|
---|
| 211 |
|
---|
| 212 | # Function which returns a pointer on a hash
|
---|
[74] | 213 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
| 214 | sub pb_conf_read {
|
---|
| 215 |
|
---|
| 216 | my $conffile = shift;
|
---|
| 217 | my @param = @_;
|
---|
| 218 | my $trace;
|
---|
| 219 | my @ptr;
|
---|
| 220 |
|
---|
| 221 | if ($debug > 0) {
|
---|
| 222 | $trace = 1;
|
---|
| 223 | } else {
|
---|
| 224 | $trace = 0;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | my $config = AppConfig->new({
|
---|
| 229 | # Auto Create variables mentioned in Conf file
|
---|
| 230 | CREATE => 1,
|
---|
| 231 | DEBUG => $trace,
|
---|
| 232 | GLOBAL => {
|
---|
| 233 | # Each conf item is a hash
|
---|
| 234 | ARGCOUNT => ARGCOUNT_HASH,
|
---|
| 235 | },
|
---|
| 236 | });
|
---|
| 237 | $config->file($conffile);
|
---|
| 238 | for my $param (@param) {
|
---|
| 239 | push @ptr,$config->get($param);
|
---|
| 240 | }
|
---|
[89] | 241 | print "DEBUG: params: ".Dumper(@param)." ".Dumper(@ptr)."\n" if ($debug >= 1);
|
---|
| 242 | return(@ptr);
|
---|
[74] | 243 | }
|
---|
| 244 |
|
---|
| 245 | # Setup environment for CMS system
|
---|
| 246 | sub pb_cms_init {
|
---|
| 247 |
|
---|
| 248 | my $proj = shift || undef;
|
---|
| 249 | my $ret;
|
---|
| 250 |
|
---|
[89] | 251 | my ($cms) = pb_conf_get("cms");
|
---|
[88] | 252 | # This one is optional
|
---|
[89] | 253 | my ($cvsroot) = pb_conf_read($ENV{'PBETC'},"cvsroot");
|
---|
[74] | 254 |
|
---|
[88] | 255 | if ($cms->{$proj} eq "svn") {
|
---|
[74] | 256 | $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
|
---|
| 257 | chomp($ENV{'PBREVISION'});
|
---|
| 258 | $ENV{'PBCMSLOG'}="svn log";
|
---|
| 259 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
| 260 | $ENV{'PBCMSEXP'}="svn export";
|
---|
[88] | 261 | } elsif ($cms->{$proj} eq "cvs") {
|
---|
[74] | 262 | $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
| 263 | chomp($ENV{'PBREVISION'});
|
---|
| 264 | $ENV{'PBCMSLOG'}="cvs log";
|
---|
| 265 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
[88] | 266 | $ENV{'PBCMSEXP'}="cvs export";
|
---|
[87] | 267 | #
|
---|
| 268 | # Export content if needed
|
---|
| 269 | #
|
---|
[88] | 270 | $ENV{'CVSROOT'} = $cvsroot->{$proj} if (defined $cvsroot->{$proj});
|
---|
[74] | 271 | } else {
|
---|
[88] | 272 | die "cms $cms->{$proj} unknown";
|
---|
[74] | 273 | }
|
---|
| 274 | }
|
---|
| 275 |
|
---|
[77] | 276 | # Get all filters to apply
|
---|
| 277 | # They're cumulative from less specific to most specific
|
---|
| 278 | # suffix is .pbf
|
---|
| 279 |
|
---|
| 280 | sub pb_get_filters {
|
---|
| 281 |
|
---|
| 282 | my @ffiles;
|
---|
| 283 | my ($ffile0, $ffile1, $ffile2, $ffile3);
|
---|
| 284 | my $pbpkg = shift || die "No package specified";
|
---|
| 285 | my $dtype = shift || die "No dtype specified";
|
---|
| 286 | my $dfam = shift || die "No dfam specified";
|
---|
| 287 | my $ddir = shift || die "No ddir specified";
|
---|
| 288 | my $dver = shift || die "No dver specified";
|
---|
| 289 | my $ptr; # returned value pointer on the hash of filters
|
---|
[79] | 290 | my %ptr;
|
---|
[77] | 291 |
|
---|
| 292 | if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
|
---|
| 293 | $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
| 294 | $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
| 295 | $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
| 296 | $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
| 297 |
|
---|
| 298 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
| 299 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
| 300 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
| 301 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
| 302 | }
|
---|
| 303 | if (@ffiles) {
|
---|
| 304 | print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
|
---|
[79] | 305 |
|
---|
| 306 | my $config = AppConfig->new({
|
---|
| 307 | # Auto Create variables mentioned in Conf file
|
---|
| 308 | CREATE => 1,
|
---|
| 309 | DEBUG => 0,
|
---|
| 310 | GLOBAL => {
|
---|
| 311 | # Each conf item is a hash
|
---|
| 312 | ARGCOUNT => AppConfig::ARGCOUNT_HASH
|
---|
| 313 | }
|
---|
| 314 | });
|
---|
| 315 |
|
---|
[77] | 316 | $config->file(@ffiles);
|
---|
| 317 | $ptr = $config->get("filter");
|
---|
| 318 | print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
|
---|
| 319 | } else {
|
---|
| 320 | $ptr = { };
|
---|
| 321 | }
|
---|
[79] | 322 | %ptr = %$ptr;
|
---|
| 323 | return(\%ptr);
|
---|
[77] | 324 | }
|
---|
| 325 |
|
---|
| 326 | # Function which applies filter on files (only for pb)
|
---|
| 327 | sub pb_filter_file_pb {
|
---|
| 328 |
|
---|
| 329 | my $f=shift;
|
---|
| 330 | my $ptr=shift;
|
---|
| 331 | my %filter=%$ptr;
|
---|
| 332 | my $destfile=shift;
|
---|
| 333 | my $dtype=shift;
|
---|
| 334 | my $dsuf=shift;
|
---|
[80] | 335 | my $pbpkg=shift;
|
---|
| 336 | my $pbver=shift;
|
---|
| 337 | my $pbtag=shift;
|
---|
| 338 | my $pbrev=shift;
|
---|
| 339 | my $pbdate=shift;
|
---|
[77] | 340 |
|
---|
| 341 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 342 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 343 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 344 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 345 | while (<FILE>) {
|
---|
| 346 | my $line = $_;
|
---|
| 347 | foreach my $s (keys %filter) {
|
---|
| 348 | # Process single variables
|
---|
[79] | 349 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
|
---|
[77] | 350 | my $tmp = $filter{$s};
|
---|
| 351 | next if (not defined $tmp);
|
---|
| 352 | # Expand variables if any single one found
|
---|
[79] | 353 | print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
|
---|
[77] | 354 | if ($tmp =~ /\$/) {
|
---|
| 355 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 356 | # special case for ChangeLog only for pb
|
---|
| 357 | } elsif (($tmp =~ /^yes$/) && ($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
| 358 | $tmp = "";
|
---|
[82] | 359 | my $p = $defpkgdir{$pbpkg};
|
---|
| 360 | $p = $extpkgdir{$pbpkg} if (not defined $p);
|
---|
| 361 | pb_changelog($dtype, $pbpkg, $pbtag, $dsuf, $p, \*DEST);
|
---|
[77] | 362 | }
|
---|
| 363 | $line =~ s|$s|$tmp|;
|
---|
| 364 | }
|
---|
| 365 | print DEST $line;
|
---|
| 366 | }
|
---|
| 367 | close(FILE);
|
---|
| 368 | close(DEST);
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | # Function which applies filter on files (external call)
|
---|
| 372 | sub pb_filter_file {
|
---|
| 373 |
|
---|
| 374 | my $f=shift;
|
---|
| 375 | my $ptr=shift;
|
---|
| 376 | my %filter=%$ptr;
|
---|
| 377 | my $destfile=shift;
|
---|
[80] | 378 | my $pbpkg=shift;
|
---|
| 379 | my $pbver=shift;
|
---|
| 380 | my $pbtag=shift;
|
---|
| 381 | my $pbrev=shift;
|
---|
| 382 | my $pbdate=shift;
|
---|
[77] | 383 |
|
---|
| 384 | print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
|
---|
| 385 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
| 386 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
| 387 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
| 388 | while (<FILE>) {
|
---|
| 389 | my $line = $_;
|
---|
| 390 | foreach my $s (keys %filter) {
|
---|
| 391 | # Process single variables
|
---|
| 392 | print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
|
---|
| 393 | my $tmp = $filter{$s};
|
---|
| 394 | next if (not defined $tmp);
|
---|
| 395 | # Expand variables if any single one found
|
---|
| 396 | if ($tmp =~ /\$/) {
|
---|
| 397 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
| 398 | }
|
---|
| 399 | $line =~ s|$s|$tmp|;
|
---|
| 400 | }
|
---|
| 401 | print DEST $line;
|
---|
| 402 | }
|
---|
| 403 | close(FILE);
|
---|
| 404 | close(DEST);
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 |
|
---|
[2] | 408 | 1;
|
---|