2 eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
3 & eval 'exec perl -w -S $0 $argv:q'
6 # ******************************************************************
10 # Description: Combined multiple dsw's into a single dsw
11 # ******************************************************************
13 # ******************************************************************
15 # ******************************************************************
21 # ******************************************************************
23 # ******************************************************************
27 # ******************************************************************
29 # ******************************************************************
33 print STDERR
"$str\n" if (defined $str);
34 print STDERR
"Combine DSW v$version\n",
35 "Usage: ", basename
($0),
36 " [-u] <output file> <input files...>\n\n",
37 "-u Each input file will be removed after successful ",
39 "NOTE: This script will work for vcw's too.\n\n",
40 "Combine multiple dsw's into a single dsw. You can use ",
42 "dynamic projects and then generate static projects using ",
44 "-name_modifier and -apply_project options together. You ",
45 "can then run this\n",
46 "script to combine the workspaces into one.\n";
50 # ******************************************************************
52 # ******************************************************************
58 for(my $i = 0; $i <= $#ARGV; $i++) {
65 usageAndExit
("Unknown option: $arg");
69 if (!defined $output) {
78 ## Print the usage if there is no output file provided or there isn't at
79 ## least two input files.
80 usageAndExit
() if (!defined $output ||
81 !defined $input[0] || !defined $input[1]);
83 my $tmp = "$output.$$.tmp";
84 my $oh = new FileHandle
();
86 if (open($oh, ">$tmp")) {
88 for(my $i = 0; $i <= $#input; ++$i) {
89 ## We only want to take the global settings from the last input file.
90 my $input = $input[$i];
91 my $global = ($i == $#input);
93 ## Read in the input file and write out the parts that are common
94 ## between multiple workspace files (but only on the first input
95 ## file). After that, write out the project information from each
97 my $fh = new FileHandle
();
98 if (open($fh, $input)) {
101 if (/Microsoft\s+(Developer\s+Studio|eMbedded\s+Visual)/) {
102 ## We only want to print out the identifier from the first
113 elsif ($in_global && /^[#]{79,}/) {
118 ## Only print out the line if it's not part of the global
119 ## settings (unless this is the last input file).
120 print $oh $_ if (!$in_global || ($global && $in_global));
126 print STDERR
"ERROR: Unable to open '$input' for reading\n";
132 ## If the user wants us to remove the input files after successfully
133 ## combining them, then do so here.
134 unlink(@input) if ($unlink);
136 ## We have written the new workspace to a temporary file to allow an
137 ## input file to be the same as an output file. Once we're done, we
138 ## need to move it to it's correct output name.
140 rename($tmp, $output);
143 print STDERR
"ERROR: Unable to open '$tmp' for writing\n";