Bug 575870 - Enable the firefox button on xp themed, classic, and aero basic. r=dao...
[mozilla-central.git] / build / macosx / universal / fix-buildconfig
blob16124d7087de997cf79cd266705141766c6da3df
1 #!/usr/bin/perl
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
15 # The Original Code is the Mozilla Mac OS X Universal Binary Packaging System
17 # The Initial Developer of the Original Code is Google Inc.
18 # Portions created by the Initial Developer are Copyright (C) 2006
19 # the Initial Developer. All Rights Reserved.
21 # Contributor(s):
22 # Mark Mentovai <mark@moxienet.com> (Original Author)
24 # Alternatively, the contents of this file may be used under the terms of
25 # either the GNU General Public License Version 2 or later (the "GPL"), or
26 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 # in which case the provisions of the GPL or the LGPL are applicable instead
28 # of those above. If you wish to allow use of your version of this file only
29 # under the terms of either the GPL or the LGPL, and not to allow others to
30 # use your version of this file under the terms of the MPL, indicate your
31 # decision by deleting the provisions above and replace them with the notice
32 # and other provisions required by the GPL or the LGPL. If you do not delete
33 # the provisions above, a recipient may use your version of this file under
34 # the terms of any one of the MPL, the GPL or the LGPL.
36 # ***** END LICENSE BLOCK *****
38 use strict;
39 use warnings;
41 use Archive::Zip(':ERROR_CODES');
43 my ($BUILDCONFIG);
45 sub fixBuildconfig($$$);
47 $BUILDCONFIG = 'content/global/buildconfig.html';
49 if (scalar(@ARGV) != 3) {
50 print STDERR ("usage: fix-buildconfig <jar|file> <file1> <file2>\n");
51 exit(1);
54 if (!fixBuildconfig($ARGV[0], $ARGV[1], $ARGV[2])) {
55 exit(1);
58 exit(0);
60 sub fixBuildconfig($$$) {
61 my ($mode, $path1, $path2);
62 ($mode, $path1, $path2) = @_;
64 if ($mode ne 'jar' && $mode ne 'file') {
65 print STDERR ($0.': must specify jar or file\n');
66 return 0;
69 my ($contents1, $contents2);
70 my ($ze, $zip1, $zip2);
72 if ($mode eq 'jar') {
73 $zip1 = Archive::Zip->new();
74 if (($ze = $zip1->read($path1)) != AZ_OK) {
75 print STDERR ($0.': could not read "'.$path1.'": error '.$ze."\n");
76 return 0;
78 $zip2 = Archive::Zip->new();
79 if (($ze = $zip2->read($path2)) != AZ_OK) {
80 print STDERR ($0.': could not read "'.$path2.'": error '.$ze."\n");
81 return 0;
84 $contents1 = $zip1->contents($BUILDCONFIG);
85 $contents2 = $zip2->contents($BUILDCONFIG);
86 } elsif ($mode eq 'file') {
87 local($/);
88 my ($file1, $file2);
90 open($file1, '<'.$path1.$BUILDCONFIG) or return 0;
91 open($file2, '<'.$path2.$BUILDCONFIG) or return 0;
93 $contents1 = <$file1>;
94 $contents2 = <$file2>;
96 close($file1);
97 close($file2);
100 if (!defined($contents1)) {
101 print STDERR ($0.': could not get "'.$BUILDCONFIG.'" from "'.$path1.'"'.
102 "\n");
103 return 0;
105 if (!defined($contents2)) {
106 print STDERR ($0.': could not get "'.$BUILDCONFIG.'" from "'.$path2.'"'.
107 "\n");
108 return 0;
111 my (@lines1, @lines2);
112 @lines1 = split(/\n/, $contents1);
113 @lines2 = split(/\n/, $contents2);
115 my ($line, @linesNew);
116 @linesNew = ();
118 # Copy everything from the first file up to the end of its <body>.
119 while ($line = shift(@lines1)) {
120 if ($line eq '</body>') {
121 last;
123 push(@linesNew, $line);
126 # Insert a <hr> between the two files.
127 push (@linesNew, '<hr> </hr>');
129 # Copy the second file's content beginning after its leading <h1> and <p>.
130 while ($line = shift(@lines2)) {
131 if ($line eq '<p> </p>') {
132 last;
135 while ($line = shift(@lines2)) {
136 push(@linesNew, $line);
139 my ($contentsNew);
140 $contentsNew = join("\n", @linesNew);
142 if ($mode eq 'jar') {
143 if (!defined($zip1->contents($BUILDCONFIG, $contentsNew))) {
144 print STDERR ($0.': could not set "'.$BUILDCONFIG.'" to "'.$path1.'"'.
145 "\n");
146 return 0;
148 if (!defined($zip2->contents($BUILDCONFIG, $contentsNew))) {
149 print STDERR ($0.': could not set "'.$BUILDCONFIG.'" to "'.$path2.'"'.
150 "\n");
151 return 0;
154 if (($ze = $zip1->overwrite()) != AZ_OK) {
155 print STDERR ($0.': could not write "'.$path1.'": error '.$ze."\n");
156 return 0;
158 if (($ze = $zip2->overwrite()) != AZ_OK) {
159 print STDERR ($0.': could not write "'.$path2.'": error '.$ze."\n");
160 return 0;
162 } elsif ($mode eq 'file') {
163 my ($file1, $file2);
165 open($file1, '>'.$path1.$BUILDCONFIG) or return 0;
166 open($file2, '>'.$path2.$BUILDCONFIG) or return 0;
168 print $file1 ($contentsNew);
169 print $file2 ($contentsNew);
171 close($file1);
172 close($file2);
175 return 1;