[1] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | |
---|
| 4 | # upd-execsys |
---|
| 5 | # Copyright (C) 2006 Jeff Arnold <jbarnold@mit.edu> |
---|
| 6 | # |
---|
| 7 | # This program is free software; you can redistribute it and/or |
---|
| 8 | # modify it under the terms of the GNU General Public License |
---|
| 9 | # as published by the Free Software Foundation; either version 2 |
---|
| 10 | # of the License, or (at your option) any later version. |
---|
| 11 | # |
---|
| 12 | # This program is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
| 16 | # |
---|
| 17 | # You should have received a copy of the GNU General Public License |
---|
| 18 | # along with this program; if not, write to the Free Software |
---|
| 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
---|
| 20 | # |
---|
| 21 | # See /COPYRIGHT in this repository for more information. |
---|
| 22 | |
---|
| 23 | my @dynamic = qw( |
---|
| 24 | pl |
---|
| 25 | php |
---|
| 26 | py |
---|
[26] | 27 | cgi |
---|
[1] | 28 | scm |
---|
[163] | 29 | exe |
---|
[1] | 30 | ); |
---|
| 31 | |
---|
| 32 | my @static = qw( |
---|
| 33 | html |
---|
| 34 | css |
---|
| 35 | gif |
---|
| 36 | jpg |
---|
| 37 | png |
---|
| 38 | htm |
---|
| 39 | jpeg |
---|
| 40 | js |
---|
| 41 | ico |
---|
| 42 | xml |
---|
| 43 | xsl |
---|
| 44 | tiff |
---|
| 45 | tif |
---|
| 46 | tgz |
---|
| 47 | tar |
---|
| 48 | jar |
---|
[254] | 49 | zip |
---|
[1] | 50 | pdf |
---|
| 51 | ps |
---|
| 52 | doc |
---|
| 53 | xls |
---|
| 54 | ppt |
---|
[1877] | 55 | dot |
---|
| 56 | docx |
---|
| 57 | dotx |
---|
| 58 | docm |
---|
| 59 | dotm |
---|
| 60 | xlt |
---|
| 61 | xla |
---|
| 62 | xlsx |
---|
| 63 | xltx |
---|
| 64 | xlsm |
---|
| 65 | xltm |
---|
| 66 | xlam |
---|
| 67 | xlsb |
---|
| 68 | pot |
---|
| 69 | pps |
---|
| 70 | ppa |
---|
| 71 | pptx |
---|
| 72 | potx |
---|
| 73 | ppsx |
---|
| 74 | ppam |
---|
| 75 | pptm |
---|
| 76 | potm |
---|
| 77 | ppsm |
---|
[1] | 78 | swf |
---|
| 79 | mp3 |
---|
[254] | 80 | mov |
---|
| 81 | wmv |
---|
[255] | 82 | mpg |
---|
| 83 | mpeg |
---|
| 84 | avi |
---|
[254] | 85 | il |
---|
[315] | 86 | xhtml |
---|
[617] | 87 | svg |
---|
[944] | 88 | xaml |
---|
| 89 | xap |
---|
[1464] | 90 | wav |
---|
| 91 | mid |
---|
| 92 | midi |
---|
[1784] | 93 | ttf |
---|
| 94 | otf |
---|
[1877] | 95 | odc |
---|
| 96 | odb |
---|
| 97 | odf |
---|
| 98 | odg |
---|
| 99 | otg |
---|
| 100 | odi |
---|
| 101 | odp |
---|
| 102 | otp |
---|
| 103 | ods |
---|
| 104 | ots |
---|
| 105 | odt |
---|
| 106 | odm |
---|
| 107 | ott |
---|
| 108 | oth |
---|
[1] | 109 | ); |
---|
| 110 | |
---|
| 111 | my %map; |
---|
| 112 | open(TYPES, "./mime.types"); |
---|
| 113 | while(my $line = <TYPES>) { |
---|
| 114 | next if($line =~ /^\#/ or $line =~ /^\s*$/); |
---|
| 115 | my ($type, $exts) = ($line =~ /^(\S*)\s+(.*)$/); |
---|
| 116 | next if($exts =~ /^\s*$/); |
---|
| 117 | |
---|
| 118 | foreach my $ext (split " ", $exts) { |
---|
| 119 | $map{$ext} = $type; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | close(TYPES); |
---|
| 123 | |
---|
| 124 | undef $/; |
---|
| 125 | my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)'; |
---|
| 126 | |
---|
| 127 | open(CONF, ">./execsys.conf"); |
---|
| 128 | |
---|
| 129 | foreach my $ext (@dynamic, @static) { |
---|
| 130 | print CONF <<END |
---|
[1464] | 131 | <FilesMatch "(?i)\\.$ext\$"> |
---|
[1] | 132 | SetHandler cgi-script |
---|
| 133 | Options +ExecCGI |
---|
[1464] | 134 | </FilesMatch> |
---|
[1] | 135 | |
---|
| 136 | END |
---|
| 137 | } |
---|
| 138 | close(CONF); |
---|
| 139 | |
---|
[104] | 140 | open(CAT, "./static-cat.c.pre"); |
---|
[1358] | 141 | my $file = <CAT>; |
---|
| 142 | my ($fstart, $fend) = ($file =~ /$regexp/s); |
---|
[1] | 143 | close(CAT); |
---|
| 144 | |
---|
[104] | 145 | open(CAT, ">./static-cat.c"); |
---|
[1] | 146 | print CAT $fstart, "\n"; |
---|
| 147 | print CAT '#define NEXTS ', scalar(@static), "\n"; |
---|
| 148 | print CAT "const char *map[2 * NEXTS] = {\n"; |
---|
| 149 | for(my $i = 0; $i < scalar(@static); $i++) { |
---|
| 150 | my $comma = ( $i < scalar(@static)-1 ? "," : "" ); |
---|
| 151 | print CAT "\t\"$static[$i]\", \"$map{$static[$i]}\"$comma\n"; |
---|
| 152 | } |
---|
| 153 | print CAT "};\n"; |
---|
| 154 | print CAT $fend; |
---|
| 155 | close(CAT); |
---|