-
Notifications
You must be signed in to change notification settings - Fork 46
/
mimetypemerge
executable file
·52 lines (42 loc) · 1.29 KB
/
mimetypemerge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl -w
# primitive merger for mime.type files
my $types;
my $headers;
for my $file (@ARGV) {
open (IN, $file);
while (my $line = <IN>) {
chomp($line);
if ($line !~ /^(\#\s+)?[a-z-]+\//) {
push @{$headers->{$file}}, $line;
#print "seeing $line as header\n";
next;
}
my $enabled = 1;
my @elem = split ('\s+', $line);
if ($elem[0] eq "#") {
$enabled = 0;
shift (@elem);
}
#print "line : ".($enabled ? "" : "# " ).join(',',@elem)."\n";
my $type = shift (@elem);
if ($enabled) {
push @{$types->{$type}->{'enabled'}}, @elem;
} else {
push @{$types->{$type}->{'disabled'}}, @elem;
}
}
close (IN);
}
print join("\n",@{$headers->{$ARGV[-1]}})."\n";
sub unify {
my %h = map {$_ => 1} @_;
return grep(delete($h{$_}), @_);
}
for my $type (sort keys (%{$types})) {
@{$types->{$type}->{'disabled'}} = unify (@{$types->{$type}->{'disabled'}}) if $types->{$type}->{'disabled'};
@{$types->{$type}->{'enabled'}} = unify (@{$types->{$type}->{'enabled'}}) if $types->{$type}->{'enabled'};
}
for my $type (sort keys (%{$types})) {
printf "%-48s %s\n", "# $type", join(" ",@{$types->{$type}->{'disabled'}}) if $types->{$type}->{'disabled'};
printf "%-48s %s\n", $type, join(" ",@{$types->{$type}->{'enabled'}}) if $types->{$type}->{'enabled'};
}