Commit 56c25fc9940ff06ed9b1b597a78b1df99f93f81d
1 parent
4ca182f3
--no commit message
Showing
1 changed file
with
98 additions
and
0 deletions
Project/applications/smartcities/makefsdata/makefsdata
0 → 100644
1 | +#!/usr/bin/perl | |
2 | + | |
3 | +open(OUTPUT, "> fsdata.c"); | |
4 | + | |
5 | +chdir("fs"); | |
6 | +open(FILES, "find . -type f |"); | |
7 | + | |
8 | +while($file = <FILES>) { | |
9 | + | |
10 | + # Do not include files in CVS directories nor backup files. | |
11 | + if($file =~ /(CVS|~)/) { | |
12 | + next; | |
13 | + } | |
14 | + | |
15 | + chop($file); | |
16 | + | |
17 | + open(HEADER, "> /tmp/header") || die $!; | |
18 | + if($file =~ /404/) { | |
19 | + #print(HEADER "HTTP/1.0 404 File not found\r\n"); | |
20 | + } else { | |
21 | + #print(HEADER "HTTP/1.0 200 OK\r\n"); | |
22 | + } | |
23 | + #print(HEADER "Server: lwIP/pre-0.6 (http://www.sics.se/~adam/lwip/)\r\n"); | |
24 | + if($file =~ /\.html$/) { | |
25 | + #print(HEADER "Content-type: text/html\r\n"); | |
26 | + } elsif($file =~ /\.gif$/) { | |
27 | + #print(HEADER "Content-type: image/gif\r\n"); | |
28 | + } elsif($file =~ /\.png$/) { | |
29 | + #print(HEADER "Content-type: image/png\r\n"); | |
30 | + } elsif($file =~ /\.jpg$/) { | |
31 | + #print(HEADER "Content-type: image/jpeg\r\n"); | |
32 | + } elsif($file =~ /\.class$/) { | |
33 | + #print(HEADER "Content-type: application/octet-stream\r\n"); | |
34 | + } elsif($file =~ /\.ram$/) { | |
35 | + #print(HEADER "Content-type: audio/x-pn-realaudio\r\n"); | |
36 | + } else { | |
37 | + #print(HEADER "Content-type: text/plain\r\n"); | |
38 | + } | |
39 | + #print(HEADER "\r\n"); | |
40 | + close(HEADER); | |
41 | + | |
42 | + unless($file =~ /\.plain$/ || $file =~ /cgi/) { | |
43 | + system("cat /tmp/header $file > /tmp/file"); | |
44 | + } else { | |
45 | + system("cp $file /tmp/file"); | |
46 | + } | |
47 | + | |
48 | + open(FILE, "/tmp/file"); | |
49 | + unlink("/tmp/file"); | |
50 | + unlink("/tmp/header"); | |
51 | + | |
52 | + $file =~ s/\.//; | |
53 | + $fvar = $file; | |
54 | + $fvar =~ s-/-_-g; | |
55 | + $fvar =~ s-\.-_-g; | |
56 | + print(OUTPUT "static const char data".$fvar."[] = {\n"); | |
57 | + print(OUTPUT "\t/* $file */\n"); | |
58 | + for($j = 0; $j < length($file); $j++) | |
59 | + { | |
60 | + #printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1))); | |
61 | + } | |
62 | + #printf(OUTPUT "0,\n"); | |
63 | + | |
64 | + | |
65 | + $i = 0; | |
66 | + while(read(FILE, $data, 1)) { | |
67 | + if($i == 0) { | |
68 | + print(OUTPUT "\t"); | |
69 | + } | |
70 | + printf(OUTPUT "%#02x, ", unpack("C", $data)); | |
71 | + $i++; | |
72 | + if($i == 10) { | |
73 | + print(OUTPUT "\n"); | |
74 | + $i = 0; | |
75 | + } | |
76 | + } | |
77 | + print(OUTPUT "};\n\n"); | |
78 | + close(FILE); | |
79 | + push(@fvars, $fvar); | |
80 | + push(@files, $file); | |
81 | +} | |
82 | + | |
83 | +for($i = 0; $i < @fvars; $i++) { | |
84 | + $file = $files[$i]; | |
85 | + $fvar = $fvars[$i]; | |
86 | + | |
87 | + if($i == 0) { | |
88 | + $prevfile = "NULL"; | |
89 | + } else { | |
90 | + $prevfile = "file" . $fvars[$i - 1]; | |
91 | + } | |
92 | + #print(OUTPUT "const struct fsdata_file file".$fvar."[] = {{$prevfile, data$fvar, "); | |
93 | + #print(OUTPUT "data$fvar + ". (length($file) + 1) .", "); | |
94 | + #print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n"); | |
95 | +} | |
96 | + | |
97 | +#print(OUTPUT "#define FS_ROOT file$fvars[$i - 1]\n\n"); | |
98 | +print(OUTPUT "#define FS_NUMFILES $i\n"); | ... | ... |