Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / build / macosx / universal / fix-buildconfig
blob35eff984ff8a0ea2f6d3c4a97e992561a3054565
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) != 2) {
50 print STDERR ("usage: fix-buildconfig <zipfile1> <zipfile2>\n");
51 exit(1);
54 if (!fixBuildconfig($ARGV[0], $ARGV[1])) {
55 exit(1);
58 exit(0);
60 sub fixBuildconfig($$) {
61 my ($zipPath1, $zipPath2);
62 ($zipPath1, $zipPath2) = @_;
64 my ($ze, $zip1, $zip2);
66 $zip1 = Archive::Zip->new();
67 if (($ze = $zip1->read($zipPath1)) != AZ_OK) {
68 print STDERR ($0.': could not read "'.$zipPath1.'": error '.$ze."\n");
69 return 0;
71 $zip2 = Archive::Zip->new();
72 if (($ze = $zip2->read($zipPath2)) != AZ_OK) {
73 print STDERR ($0.': could not read "'.$zipPath2.'": error '.$ze."\n");
74 return 0;
77 my ($contents1, $contents2);
78 if (!defined($contents1 = $zip1->contents($BUILDCONFIG))) {
79 print STDERR ($0.': could not get "'.$BUILDCONFIG.'" from "'.$zipPath1.'"'.
80 "\n");
81 return 0;
83 if (!defined($contents2 = $zip2->contents($BUILDCONFIG))) {
84 print STDERR ($0.': could not get "'.$BUILDCONFIG.'" from "'.$zipPath2.'"'.
85 "\n");
86 return 0;
89 my (@lines1, @lines2);
90 @lines1 = split(/\n/, $contents1);
91 @lines2 = split(/\n/, $contents2);
93 my ($line, @linesNew);
94 @linesNew = ();
96 # Copy everything from the first file up to the end of its <body>.
97 while ($line = shift(@lines1)) {
98 if ($line eq '</body>') {
99 last;
101 push(@linesNew, $line);
104 # Insert a <hr> between the two files.
105 push (@linesNew, '<hr> </hr>');
107 # Copy the second file's content beginning after its leading <h1> and <p>.
108 while ($line = shift(@lines2)) {
109 if ($line eq '<p> </p>') {
110 last;
113 while ($line = shift(@lines2)) {
114 push(@linesNew, $line);
117 my ($contentsNew);
118 $contentsNew = join("\n", @linesNew);
120 if (!defined($zip1->contents($BUILDCONFIG, $contentsNew))) {
121 print STDERR ($0.': could not set "'.$BUILDCONFIG.'" to "'.$zipPath1.'"'.
122 "\n");
123 return 0;
125 if (!defined($zip2->contents($BUILDCONFIG, $contentsNew))) {
126 print STDERR ($0.': could not set "'.$BUILDCONFIG.'" to "'.$zipPath2.'"'.
127 "\n");
128 return 0;
132 if (($ze = $zip1->overwrite()) != AZ_OK) {
133 print STDERR ($0.': could not write "'.$zipPath1.'": error '.$ze."\n");
134 return 0;
136 if (($ze = $zip2->overwrite()) != AZ_OK) {
137 print STDERR ($0.': could not write "'.$zipPath2.'": error '.$ze."\n");
138 return 0;
141 return 1;