source: trunk/third/firefox/config/build-list.pl @ 21695

Revision 21695, 2.1 KB checked in by rbasch, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21694, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1#!env perl
2
3#
4# The contents of this file are subject to the Mozilla Public
5# License Version 1.1 (the "License"); you may not use this file
6# except in compliance with the License. You may obtain a copy of
7# the License at http://www.mozilla.org/MPL/
8#
9# Software distributed under the License is distributed on an "AS
10# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11# implied. See the License for the specific language governing
12# rights and limitations under the License.
13#
14# The Original Code is mozilla.org code.
15#
16# The Initial Developer of the Original Code is Netscape
17# Communications Corporation.  Portions created by Netscape are
18# Copyright (C) 2001 Netscape Communications Corporation. All
19# Rights Reserved.
20#
21# Contributor(s):
22#       Christopher Seawood <cls@seawood.org>
23
24#
25# A generic script to add entries to a file
26# if the entry does not already exist
27#
28# Usage: $0 [-l] <filename> <entry> [<entry> <entry>]
29#
30#   -l do not attempt flock the file.
31
32use Fcntl qw(:DEFAULT :flock);
33use Getopt::Std;
34use mozLock;
35
36sub usage() {
37    print "$0 [-l] <filename> <entry>\n";
38    exit(1);
39}
40
41$nofilelocks = 0;
42
43getopts("l");
44
45$nofilelocks = 1 if defined($::opt_l);
46
47$file = shift;
48
49undef @entrylist;
50while ($entry = shift) {
51    push @entrylist, $entry;
52}
53
54$lockfile = $file . ".lck";
55
56# touch the file if it doesn't exist
57if ( ! -e "$file") {
58    $now = time;
59    utime $now, $now, $file;
60}
61
62# This needs to be atomic
63mozLock($lockfile) unless $nofilelocks;
64
65# Read entire file into mem
66undef @inbuf;
67if ( -e "$file" ) {
68    open(IN, "$file") || die ("$file: $!\n");
69    binmode(IN);
70    while ($tmp = <IN>) {
71        chomp($tmp);
72        push @inbuf, $tmp;
73    }
74    close(IN);
75}
76
77undef @outbuf;
78# Add each entry to file if it's not already there
79foreach $entry (@entrylist) {
80    push @outbuf, $entry if (!grep(/^$entry$/, @inbuf));
81}
82
83$count = $#outbuf + 1;
84
85# Append new entry to file
86if ($count) {
87    open(OUT, ">>$file") || die ("$file: $!\n");
88    binmode(OUT);
89    foreach $entry (@outbuf) {
90        print OUT "$entry\n";
91    }
92    close(OUT);
93}
94
95mozUnlock($lockfile) unless $nofilelocks;
96
97exit(0);
Note: See TracBrowser for help on using the repository browser.