blob: 89f210d2c7a0c39c7b2a4f9a0581373516f67599 [file] [log] [blame]
adamdunkels9fcf9d62003-09-04 19:46:32 +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 $!;
adamdunkelsf57466f2003-09-05 21:24:08 +000019 if($file =~ /404.html/) {
20 print(HEADER "HTTP/1.0 404 File not found\r\n");
21 } else {
22 print(HEADER "HTTP/1.0 200 OK\r\n");
23 }
adamdunkels9fcf9d62003-09-04 19:46:32 +000024 print(HEADER "Server: Contiki/pre-1.1 (http://dunkels.com/adam/contiki/)\r\n");
25 if($file =~ /\.html$/) {
26 print(HEADER "Content-type: text/html\r\n");
27 } elsif($file =~ /\.gif$/) {
28 print(HEADER "Content-type: image/gif\r\n");
29 } elsif($file =~ /\.png$/) {
30 print(HEADER "Content-type: image/png\r\n");
31 } elsif($file =~ /\.jpg$/) {
32 print(HEADER "Content-type: image/jpeg\r\n");
33 } elsif($file =~ /\.css$/) {
34 print(HEADER "Content-type: text/css\r\n");
35 } else {
36 print(HEADER "Content-type: text/plain\r\n");
37 }
38 print(HEADER "\r\n");
39 close(HEADER);
40
41 unless($file =~ /\.plain$/ || $file =~ /cgi/) {
42 system("cat /tmp/header $file > /tmp/file");
43 } else {
44 system("cp $file /tmp/file");
45 }
46
47 open(FILE, "/tmp/file");
48 unlink("/tmp/file");
49 unlink("/tmp/header");
50
51 $file =~ s/\.//;
52 $fvar = $file;
53 $fvar =~ s-/-_-g;
54 $fvar =~ s-\.-_-g;
55 print(OUTPUT "static const unsigned char data".$fvar."[] __attribute__ ((aligned (2))) = {\n");
56 print(OUTPUT "\t/* $file */\n\t");
57 for($j = 0; $j < length($file); $j++) {
58 printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));
59 }
60 printf(OUTPUT "0,\n");
61
62 if((length($file) & 1) == 0) {
63 printf(OUTPUT "0,\n");
64 }
65
66 $i = 0;
67 while(read(FILE, $data, 1)) {
68 if($i == 0) {
69 print(OUTPUT "\t");
70 }
71 printf(OUTPUT "%#02x, ", unpack("C", $data));
72 $i++;
73 if($i == 10) {
74 printf(OUTPUT "\n");
75 $i = 0;
76 }
77
78 }
79 print(OUTPUT "};\n\n");
80 close(FILE);
81 push(@fvars, $fvar);
82 push(@files, $file);
83}
84
85for($i = 0; $i < @fvars; $i++) {
86 $file = $files[$i];
87 $fvar = $fvars[$i];
88
89 if($i == 0) {
90 $prevfile = "NULL";
91 } else {
92 $prevfile = "file" . $fvars[$i - 1];
93 }
94 $len = length($file) + 1;
95 if(($len & 1) == 1) {
96 $len++;
97 }
98 print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] = {{$prevfile, data$fvar, ");
99 print(OUTPUT "data$fvar + ". $len .", ");
100 print(OUTPUT "sizeof(data$fvar) - ". $len ."}};\n\n");
101}
102
103print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
104print(OUTPUT "#define HTTPD_FS_NUMFILES $i");