Subversion Repositories gelsvn

Rev

Rev 68 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 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 71 2005-08-25 08:41:49Z bj $
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 71 2005-08-25 08:41:49Z bj $';
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",
71 bj 41
               "Combine multiple dsw's into a single dsw.  You can use ",
68 bj 42
               "MPC to generate\n",
43
               "dynamic projects and then generate static projects using ",
44
               "the -static,\n",
45
               "-name_modifier and -apply_project options together.  You ",
46
               "can then run this\n",
47
               "script to combine the workspaces into one.\n";
48
  exit(0);
49
}
50
 
51
# ******************************************************************
52
# Main Section
53
# ******************************************************************
54
 
55
my($output) = undef;
56
my($unlink) = undef;
57
my(@input)  = ();
58
 
59
for(my $i = 0; $i <= $#ARGV; $i++) {
60
  my($arg) = $ARGV[$i];
61
  if ($arg =~ /^-/) {
71 bj 62
    if ($arg eq '-u') {
68 bj 63
      $unlink = 1;
64
    }
65
    else {
66
      usageAndExit("Unknown option: $arg");
67
    }
68
  }
69
  else {
70
    if (!defined $output) {
71
      $output = $arg;
72
    }
73
    else {
74
      push(@input, $arg);
75
    }
76
  }
77
}
78
 
79
if (!defined $output || !defined $input[0]) {
80
  usageAndExit();
81
}
82
 
83
my($tmp) = "$output.tmp";
84
my($oh)  = new FileHandle();
85
 
86
if (open($oh, ">$tmp")) {
87
  my($msident) = 0;
88
  for(my $i = 0; $i <= $#input; ++$i) {
89
    my($input)  = $input[$i];
90
    my($fh)     = new FileHandle();
91
    my($global) = ($i == $#input);
92
 
93
    if (open($fh, $input)) {
94
      my($in_global) = 0;
95
      while(<$fh>) {
96
        if (/Microsoft\s+Developer\s+Studio/) {
97
          if ($msident == 0) {
98
            $msident = 1;
99
            print $oh $_;
100
          }
101
        }
102
        else {
103
          if (/^Global:/) {
104
            $in_global = 1;
105
          }
106
          elsif ($in_global && /^[#]{79,}/) {
107
            $in_global = 0;
108
            $_ = '';
109
          }
110
          if (!$in_global || ($global && $in_global)) {
111
            print $oh $_;
112
          }
113
        }
114
      }
115
      close($fh);
116
    }
117
    else {
118
      print STDERR "ERROR: Unable to open '$input' for reading\n";
119
      exit(2);
120
    }
121
  }
122
  close($oh);
123
 
124
  if ($unlink) {
125
    foreach my $input (@input) {
126
      unlink($input);
127
    }
128
  }
129
 
130
  unlink($output);
131
  rename($tmp, $output);
132
}
133
else {
134
  print STDERR "ERROR: Unable to open '$tmp' for writing\n";
135
  exit(1);
136
}