Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
218 bj 1
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
2
    & eval 'exec perl -w -S $0 $argv:q'
3
    if 0;
4
 
5
# ******************************************************************
6
#      Author: Chad Elliott
7
#        Date: 4/8/2004
8
#         $Id: combine_dsw.pl,v 1.3 2006/02/22 20:05:55 elliott_c Exp $
9
# Description: Combined multiple dsw's into a single dsw
10
# ******************************************************************
11
 
12
# ******************************************************************
13
# Pragma Section
14
# ******************************************************************
15
 
16
use strict;
17
use FileHandle;
18
use File::Basename;
19
 
20
# ******************************************************************
21
# Data Section
22
# ******************************************************************
23
 
24
my($version) = '$Id: combine_dsw.pl,v 1.3 2006/02/22 20:05:55 elliott_c Exp $';
25
$version =~ s/.*\s+(\d+[\.\d]+)\s+.*/$1/;
26
 
27
# ******************************************************************
28
# Subroutine Section
29
# ******************************************************************
30
 
31
sub usageAndExit {
32
  my($str) = shift;
33
  if (defined $str) {
34
    print STDERR "$str\n";
35
  }
36
  print STDERR "Combine DSW v$version\n",
37
               "Usage: ", basename($0),
38
               " [-u] <output file> <input files...>\n\n",
39
               "-u  Each input file will be removed after successful ",
40
               "combination\n\n",
41
               "NOTE: This script will work for vcw's too.\n\n",
42
               "Combine multiple dsw's into a single dsw.  You can use ",
43
               "MPC to generate\n",
44
               "dynamic projects and then generate static projects using ",
45
               "the -static,\n",
46
               "-name_modifier and -apply_project options together.  You ",
47
               "can then run this\n",
48
               "script to combine the workspaces into one.\n";
49
  exit(0);
50
}
51
 
52
# ******************************************************************
53
# Main Section
54
# ******************************************************************
55
 
56
my($output) = undef;
57
my($unlink) = undef;
58
my(@input)  = ();
59
 
60
for(my $i = 0; $i <= $#ARGV; $i++) {
61
  my($arg) = $ARGV[$i];
62
  if ($arg =~ /^-/) {
63
    if ($arg eq '-u') {
64
      $unlink = 1;
65
    }
66
    else {
67
      usageAndExit("Unknown option: $arg");
68
    }
69
  }
70
  else {
71
    if (!defined $output) {
72
      $output = $arg;
73
    }
74
    else {
75
      push(@input, $arg);
76
    }
77
  }
78
}
79
 
80
if (!defined $output || !defined $input[0]) {
81
  usageAndExit();
82
}
83
 
84
my($tmp) = "$output.tmp";
85
my($oh)  = new FileHandle();
86
 
87
if (open($oh, ">$tmp")) {
88
  my($msident) = 0;
89
  for(my $i = 0; $i <= $#input; ++$i) {
90
    my($input)  = $input[$i];
91
    my($fh)     = new FileHandle();
92
    my($global) = ($i == $#input);
93
 
94
    if (open($fh, $input)) {
95
      my($in_global) = 0;
96
      while(<$fh>) {
97
        if (/Microsoft\s+(Developer\s+Studio|eMbedded\s+Visual)/) {
98
          if ($msident == 0) {
99
            $msident = 1;
100
            print $oh $_;
101
          }
102
        }
103
        else {
104
          if (/^Global:/) {
105
            $in_global = 1;
106
          }
107
          elsif ($in_global && /^[#]{79,}/) {
108
            $in_global = 0;
109
            $_ = '';
110
          }
111
          if (!$in_global || ($global && $in_global)) {
112
            print $oh $_;
113
          }
114
        }
115
      }
116
      close($fh);
117
    }
118
    else {
119
      print STDERR "ERROR: Unable to open '$input' for reading\n";
120
      exit(2);
121
    }
122
  }
123
  close($oh);
124
 
125
  if ($unlink) {
126
    foreach my $input (@input) {
127
      unlink($input);
128
    }
129
  }
130
 
131
  unlink($output);
132
  rename($tmp, $output);
133
}
134
else {
135
  print STDERR "ERROR: Unable to open '$tmp' for writing\n";
136
  exit(1);
137
}