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
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.
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 *****
41 use Archive
::Zip
(':ERROR_CODES');
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");
54 if (!fixBuildconfig
($ARGV[0], $ARGV[1], $ARGV[2])) {
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');
69 my ($contents1, $contents2);
70 my ($ze, $zip1, $zip2);
73 $zip1 = Archive
::Zip
->new();
74 if (($ze = $zip1->read($path1)) != AZ_OK
) {
75 print STDERR
($0.': could not read "'.$path1.'": error '.$ze."\n");
78 $zip2 = Archive
::Zip
->new();
79 if (($ze = $zip2->read($path2)) != AZ_OK
) {
80 print STDERR
($0.': could not read "'.$path2.'": error '.$ze."\n");
84 $contents1 = $zip1->contents($BUILDCONFIG);
85 $contents2 = $zip2->contents($BUILDCONFIG);
86 } elsif ($mode eq 'file') {
90 open($file1, '<'.$path1.$BUILDCONFIG) or return 0;
91 open($file2, '<'.$path2.$BUILDCONFIG) or return 0;
93 $contents1 = <$file1>;
94 $contents2 = <$file2>;
100 if (!defined($contents1)) {
101 print STDERR
($0.': could not get "'.$BUILDCONFIG.'" from "'.$path1.'"'.
105 if (!defined($contents2)) {
106 print STDERR
($0.': could not get "'.$BUILDCONFIG.'" from "'.$path2.'"'.
111 my (@lines1, @lines2);
112 @lines1 = split(/\n/, $contents1);
113 @lines2 = split(/\n/, $contents2);
115 my ($line, @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>') {
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>') {
135 while ($line = shift(@lines2)) {
136 push(@linesNew, $line);
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.'"'.
148 if (!defined($zip2->contents($BUILDCONFIG, $contentsNew))) {
149 print STDERR
($0.': could not set "'.$BUILDCONFIG.'" to "'.$path2.'"'.
154 if (($ze = $zip1->overwrite()) != AZ_OK
) {
155 print STDERR
($0.': could not write "'.$path1.'": error '.$ze."\n");
158 if (($ze = $zip2->overwrite()) != AZ_OK
) {
159 print STDERR
($0.': could not write "'.$path2.'": error '.$ze."\n");
162 } elsif ($mode eq 'file') {
165 open($file1, '>'.$path1.$BUILDCONFIG) or return 0;
166 open($file2, '>'.$path2.$BUILDCONFIG) or return 0;
168 print $file1 ($contentsNew);
169 print $file2 ($contentsNew);