blob: 83bbc5b2b57b81ae921783d4b15e0ab4161601f0 [file] [log] [blame]
kthacker62e146c2006-04-17 15:11:35 +00001#!/usr/bin/perl
2
3open(OUTPUT, "> httpd-fsdata.c");
4
5chdir("httpd-fs");
6open(FILES, "find . -type f |");
7
8
9while($file = <FILES>) {
10
11 # Do not include files in CVS directories nor backup files.
12 if($file =~ /(CVS|~)/) {
13 next;
14 }
15
16 chop($file);
17
18 open(HEADER, "> /tmp/header") || die $!;
19 print(HEADER "HTTP/1.0 200 OK\r\n");
20 print(HEADER "Server: Contiki/pre-1.1 (http://dunkels.com/adam/contiki/)\r\n");
21 if($file =~ /\.html$/) {
22 print(HEADER "Content-type: text/html\r\n");
23 } elsif($file =~ /\.gif$/) {
24 print(HEADER "Content-type: image/gif\r\n");
25 } elsif($file =~ /\.png$/) {
26 print(HEADER "Content-type: image/png\r\n");
27 } elsif($file =~ /\.jpg$/) {
28 print(HEADER "Content-type: image/jpeg\r\n");
29 } elsif($file =~ /\.css$/) {
30 print(HEADER "Content-type: text/css\r\n");
31 } else {
32 print(HEADER "Content-type: text/plain\r\n");
33 }
34 print(HEADER "\r\n");
35 close(HEADER);
36
37 unless($file =~ /\.plain$/ || $file =~ /cgi/) {
38 system("cat /tmp/header $file > /tmp/file");
39 } else {
40 system("cp $file /tmp/file");
41 }
42
43 open(FILE, "/tmp/file");
44 unlink("/tmp/file");
45 unlink("/tmp/header");
46
47 $file =~ s/\.//;
48 $fvar = $file;
49 $fvar =~ s-/-_-g;
50 $fvar =~ s-\.-_-g;
51 print(OUTPUT "static const char data".$fvar."[] = {\n");
52 print(OUTPUT "\t/* $file */\n\t");
53 for($j = 0; $j < length($file); $j++) {
54 printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));
55 }
56 printf(OUTPUT "0,\n");
57
58
59 $i = 0;
60 while(read(FILE, $data, 1)) {
61 if($i == 0) {
62 print(OUTPUT "\t");
63 }
64 printf(OUTPUT "%#02x, ", unpack("C", $data));
65 $i++;
66 if($i == 10) {
67 print(OUTPUT "\n");
68 $i = 0;
69 }
70 }
71 print(OUTPUT "};\n\n");
72 close(FILE);
73 push(@fvars, $fvar);
74 push(@files, $file);
75}
76
77for($i = 0; $i < @fvars; $i++) {
78 $file = $files[$i];
79 $fvar = $fvars[$i];
80
81 if($i == 0) {
82 $prevfile = "NULL";
83 } else {
84 $prevfile = "file" . $fvars[$i - 1];
85 }
86 print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] = {{$prevfile, data$fvar, ");
87 print(OUTPUT "data$fvar + ". (length($file) + 1) .", ");
88 print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n");
89}
90
91print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
92print(OUTPUT "#define HTTPD_FS_NUMFILES $i");