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 |
---|
27 | cgi |
---|
28 | scm |
---|
29 | exe |
---|
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 |
---|
49 | zip |
---|
50 | pdf |
---|
51 | ps |
---|
52 | doc |
---|
53 | xls |
---|
54 | ppt |
---|
55 | swf |
---|
56 | mp3 |
---|
57 | mov |
---|
58 | wmv |
---|
59 | mpg |
---|
60 | mpeg |
---|
61 | avi |
---|
62 | il |
---|
63 | xhtml |
---|
64 | svg |
---|
65 | xaml |
---|
66 | xap |
---|
67 | wav |
---|
68 | mid |
---|
69 | midi |
---|
70 | ttf |
---|
71 | otf |
---|
72 | ); |
---|
73 | |
---|
74 | my %map; |
---|
75 | open(TYPES, "./mime.types"); |
---|
76 | while(my $line = <TYPES>) { |
---|
77 | next if($line =~ /^\#/ or $line =~ /^\s*$/); |
---|
78 | my ($type, $exts) = ($line =~ /^(\S*)\s+(.*)$/); |
---|
79 | next if($exts =~ /^\s*$/); |
---|
80 | |
---|
81 | foreach my $ext (split " ", $exts) { |
---|
82 | $map{$ext} = $type; |
---|
83 | } |
---|
84 | } |
---|
85 | close(TYPES); |
---|
86 | |
---|
87 | undef $/; |
---|
88 | my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)'; |
---|
89 | |
---|
90 | open(CONF, ">./execsys.conf"); |
---|
91 | |
---|
92 | foreach my $ext (@dynamic, @static) { |
---|
93 | print CONF <<END |
---|
94 | <FilesMatch "(?i)\\.$ext\$"> |
---|
95 | SetHandler cgi-script |
---|
96 | Options +ExecCGI |
---|
97 | </FilesMatch> |
---|
98 | |
---|
99 | END |
---|
100 | } |
---|
101 | close(CONF); |
---|
102 | |
---|
103 | open(CAT, "./static-cat.c.pre"); |
---|
104 | my $file = <CAT>; |
---|
105 | my ($fstart, $fend) = ($file =~ /$regexp/s); |
---|
106 | close(CAT); |
---|
107 | |
---|
108 | open(CAT, ">./static-cat.c"); |
---|
109 | print CAT $fstart, "\n"; |
---|
110 | print CAT '#define NEXTS ', scalar(@static), "\n"; |
---|
111 | print CAT "const char *map[2 * NEXTS] = {\n"; |
---|
112 | for(my $i = 0; $i < scalar(@static); $i++) { |
---|
113 | my $comma = ( $i < scalar(@static)-1 ? "," : "" ); |
---|
114 | print CAT "\t\"$static[$i]\", \"$map{$static[$i]}\"$comma\n"; |
---|
115 | } |
---|
116 | print CAT "};\n"; |
---|
117 | print CAT $fend; |
---|
118 | close(CAT); |
---|