File: convert.pl

package info (click to toggle)
horde2 2.2.8-1sarge3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,832 kB
  • ctags: 2,897
  • sloc: php: 12,784; sh: 954; sql: 149; makefile: 104; perl: 97; xml: 24; pascal: 6
file content (85 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl -w
#
# $Horde: horde/scripts/mime_mapping/convert.pl,v 1.4.2.3 2003/08/04 16:04:00 slusarz Exp $
#
# Copyright 2001 Anil Madhavapeddy <anil@recoil.org>
# Copyright 2002 Michael Slusarz <slusarz@bigworm.colorado.edu>
#
# See the enclosed file COPYING for license information (GPL).  If you
# did not receive this file, see http://www.fsf.org/copyleft/gpl.html.

use strict;
use Sys::Hostname;

# Files containing MIME extensions
my(@FILES) = qw(mime.types mime.types.horde);

# Variables used
local(*IN);
my(@out);
my(%exts);
my($maxlength) = 0;

# Map the mime extensions file(s) into the %ext hash
foreach (@FILES) {
    open(IN, $_) or warn("Could not open $_.");
    while (<IN>) {
        # Remove trailing whitespace
        chomp();

        # Skip comments
        next if (/^#/);

        # These are tab-delimited files. Skip the entry if there is no
        # extension information. 
        my(@fields) = split(/\s+/, $_, 2);
        if (exists($fields[1])) {
            foreach (split(/\s+/, $fields[1])) {
                $exts{$_} = $fields[0];
                if (length($_) > $maxlength) {
                    $maxlength = length($_);
                }
            }
        }
    }
    close(IN);
}

# Assemble/sort the extenstions into an output array
foreach (sort(keys(%exts))) {
    push(@out, "'" . $_ . "'" . " " x ($maxlength - length($_)) . " => '" . $exts{$_} . "'");
}

# Implode the output array into a PHP file.
print << 'HEADER';
<?php
/**
 * This file contains a mapping of common file extensions to
 * MIME types. It has been automatically generated from the
 * horde/scripts/mime_mapping directory.
 *
 * ALL changes should be made to horde/scripts/mime_mapping/mime.types.horde
 * or else they will be lost when this file is regenerated.
 *
 * Any unknown file extensions will automatically be mapped to
 * 'x-extension/<ext>' where <ext> is the unknown file extension.
 *
HEADER

# Add the generated information
print " * \$" . "Horde" . "\$\n";
print " *\n";
print " * Generated: " . (scalar localtime()) . " by " . getpwuid($<) .
      " on " . hostname() . "\n";
print " */\n";

print << 'HEADER';
$mime_extension_map = array(
HEADER
print join(",\n",@out);
print << 'FOOTER';

);
FOOTER

exit;