~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gfx/idl/geniid.pl

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/perl
 
2
 
 
3
require "find.pl";
 
4
 
 
5
$uuid = 0x6f7652e0;
 
6
$format = "{ 0x%x,  0xee43, 0x11d1, \\\
 
7
 { 0x9c, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }";
 
8
$pattern = "--- IID GOES HERE ---";
 
9
$mydir = cwd();
 
10
 
 
11
sub replaceText {
 
12
    local ($oldname) = $_;
 
13
    local ($newname) = $_;
 
14
    local ($found) = 0;
 
15
    local ($tempname) = $oldname.'.orig';
 
16
    local ($replacement);
 
17
 
 
18
    if (-T $oldname && -s $oldname) {
 
19
        open(FILE, "<$oldname")
 
20
            || die "Unable to open $oldname\n";
 
21
        while (<FILE>) {
 
22
            if (/$pattern/) {
 
23
                $found = 1;
 
24
                last;
 
25
            }
 
26
        }
 
27
        close(FILE);
 
28
 
 
29
        if ($found) {
 
30
            print "Setting IID for file: ", $oldname, "\n";
 
31
            rename($oldname, $tempname)
 
32
                || die "Unable to rename $oldname as $tempname";
 
33
            open(REPLACEFILE, ">$newname")
 
34
                || die "Unable to open $newname for writing\n";
 
35
 
 
36
            open(SEARCHFILE, "<$tempname")
 
37
                || die "Unable to open $tempname\n";
 
38
 
 
39
            while (<SEARCHFILE>) { 
 
40
                if (/$pattern/) {
 
41
                    $replacement = sprintf($format, $uuid++);
 
42
                    s/$pattern/$replacement /g;
 
43
                }
 
44
                print REPLACEFILE;
 
45
            }
 
46
            close(SEARCHFILE);
 
47
            close(REPLACEFILE);
 
48
            if (-z $newname) {
 
49
                die "$newname has zero size\n."
 
50
                    ."Restore manually from $tempname\n";
 
51
            } else {
 
52
                unlink($tempname);
 
53
            }
 
54
 
 
55
            warn "$name: Renaming as $newname\n" if $newname ne $oldname;
 
56
 
 
57
            $_ = $oldname;
 
58
            return;
 
59
        }
 
60
    }
 
61
    if ($newname ne $oldname) {
 
62
        warn "$name: Renaming as $newname\n";
 
63
        rename($oldname, $newname) || warn "Unable to rename $oldname\n";
 
64
    }
 
65
    $_ = $oldname;
 
66
}
 
67
 
 
68
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
 
69
        if $running_under_some_shell;
 
70
 
 
71
# Traverse desired filesystems
 
72
$dont_use_nlink = 1;
 
73
 
 
74
if (!$ARGV[0]) {
 
75
    &find('.');
 
76
}
 
77
else {
 
78
    foreach $file (@ARGV) {
 
79
        chdir $mydir
 
80
        &find($file);
 
81
    }
 
82
}
 
83
 
 
84
exit;
 
85
 
 
86
sub wanted {
 
87
    /^nsIDOM.*\.h$/ &&
 
88
    &replaceText($name);
 
89
}