4 my $copyright = <<'EOF';
5 /* Copyright (C) 2012,2013,2015,2016,2017 Olly Betts
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to
9 * deal in the Software without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 my $srcdir = shift @ARGV;
31 -d
'docs/inc' or mkdir 'docs/inc' or die $!;
33 my $hdr = Tokeniseise
->new('mimemap.h', 'Map extension to MIME Content-Type', $copyright, 'OMEGA_INCLUDED_MIMEMAP_H', 'mime_type', 2);
34 $hdr->append('static const char * const default_mime_map[] = {');
36 my $max_mimetype_len = 0;
41 my ($ext, $mimetype) = split /\s+/;
42 my $enum = uc $mimetype;
43 $enum =~ s![-+/.]!_!g;
44 $hdr->add($ext, $enum);
45 $max_ext_len = length($ext) if length($ext) > $max_ext_len;
46 if (!exists $mime_table{$mimetype}) {
47 $hdr->append(" \"$mimetype\",");
48 if (length($mimetype) > $max_mimetype_len) {
49 $max_mimetype_len = length($mimetype) if length($mimetype);
51 $mime_table{$mimetype} = [];
53 push @
{$mime_table{$mimetype}}, $ext;
57 $hdr->append("const size_t MAX_BUILTIN_MIMEMAP_EXTENSION_LEN = $max_ext_len;");
61 open IGNORED
, '>', 'docs/inc/ignored.rst' or die $!;
62 if (exists $mime_table{'ignore'}) {
63 foreach my $ext (sort @
{$mime_table{'ignore'}}) {
64 print IGNORED
" - $ext\n";
67 close IGNORED
or die $!;
69 open MIMETYPES
, '>', 'docs/inc/mimetypes.rst' or die $!;
73 $a =~ s!^application/!1/!;
75 $a =~ s!^message/!3/!;
77 $b =~ s!^application/!1/!;
79 $b =~ s!^message/!3/!;
82 my $fmt = "\% -${max_mimetype_len}s \% -${max_ext_len}s\n";
83 my $drule = '='x
$max_mimetype_len . ' ' . '='x
${max_ext_len
} . "\n";
84 my $srule = '-'x
$max_mimetype_len . ' ' . '-'x
${max_ext_len
} . "\n";
85 print MIMETYPES
$drule;
86 printf MIMETYPES
$fmt, 'MIME Type', 'Extensions';
87 print MIMETYPES
$drule;
89 foreach my $mimetype (sort {mimetype_order
($a, $b)} keys %mime_table) {
90 if ($mimetype eq 'ignore') {
93 } elsif ($mimetype eq 'skip') {
94 # FIXME: Currently nothing is mapped to this by default.
100 print MIMETYPES
$srule;
102 my @exts = @
{$mime_table{$mimetype}};
103 printf MIMETYPES
$fmt, $mimetype, shift @exts;
105 printf MIMETYPES
$fmt, '', $_;
108 print MIMETYPES
$drule;
109 close MIMETYPES
or die $!;