diff options
author | elliott_c <ocielliottc@users.noreply.github.com> | 2008-07-18 16:05:54 +0000 |
---|---|---|
committer | elliott_c <ocielliottc@users.noreply.github.com> | 2008-07-18 16:05:54 +0000 |
commit | 6fd3ad3f828f394c6f668cc6b43981a22e1f6317 (patch) | |
tree | 61c90e72b7bf915d9d80c8e5e1837abbbaaadb0d /combine_dsw.pl | |
parent | 97fa1ff1e6cf30fa55cb9c32081ea3ef9055fbd2 (diff) | |
download | MPC-6fd3ad3f828f394c6f668cc6b43981a22e1f6317.tar.gz |
ChangeLogTag: Fri Jul 18 16:03:52 UTC 2008 Chad Elliott <elliott_c@ociweb.com>
Diffstat (limited to 'combine_dsw.pl')
-rwxr-xr-x | combine_dsw.pl | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/combine_dsw.pl b/combine_dsw.pl index 70308b3e..7f283c5f 100755 --- a/combine_dsw.pl +++ b/combine_dsw.pl @@ -29,9 +29,7 @@ my $version = '1.3'; sub usageAndExit { my $str = shift; - if (defined $str) { - print STDERR "$str\n"; - } + print STDERR "$str\n" if (defined $str); print STDERR "Combine DSW v$version\n", "Usage: ", basename($0), " [-u] <output file> <input files...>\n\n", @@ -76,25 +74,33 @@ for(my $i = 0; $i <= $#ARGV; $i++) { } } -if (!defined $output || !defined $input[0]) { - usageAndExit(); -} +## Print the usage if there is no output file provided or there isn't at +## least two input files. +usageAndExit() if (!defined $output || + !defined $input[0] || !defined $input[1]); -my $tmp = "$output.tmp"; +my $tmp = "$output.$$.tmp"; my $oh = new FileHandle(); if (open($oh, ">$tmp")) { - my $msident = 0; + my $msident; for(my $i = 0; $i <= $#input; ++$i) { + ## We only want to take the global settings from the last input file. my $input = $input[$i]; - my $fh = new FileHandle(); my $global = ($i == $#input); + ## Read in the input file and write out the parts that are common + ## between multiple workspace files (but only on the first input + ## file). After that, write out the project information from each + ## input file. + my $fh = new FileHandle(); if (open($fh, $input)) { my $in_global = 0; while(<$fh>) { if (/Microsoft\s+(Developer\s+Studio|eMbedded\s+Visual)/) { - if ($msident == 0) { + ## We only want to print out the identifier from the first + ## input file. + if (!$msident) { $msident = 1; print $oh $_; } @@ -107,9 +113,10 @@ if (open($oh, ">$tmp")) { $in_global = 0; $_ = ''; } - if (!$in_global || ($global && $in_global)) { - print $oh $_; - } + + ## Only print out the line if it's not part of the global + ## settings (unless this is the last input file). + print $oh $_ if (!$in_global || ($global && $in_global)); } } close($fh); @@ -121,12 +128,13 @@ if (open($oh, ">$tmp")) { } close($oh); - if ($unlink) { - foreach my $input (@input) { - unlink($input); - } - } + ## If the user wants us to remove the input files after successfully + ## combining them, then do so here. + unlink(@input) if ($unlink); + ## We have written the new workspace to a temporary file to allow an + ## input file to be the same as an output file. Once we're done, we + ## need to move it to it's correct output name. unlink($output); rename($tmp, $output); } |