Change RIME max time to fit in 16 bit timer
[contiki-2.x.git] / tools / avr-makefsdata
blob2aaca18781472db78a58d0c1451d4feac9a4fd6d
1 #!/usr/bin/perl
3 open(OUTPUT, "> httpd-fsdata.c");
5 chdir("httpd-fs");
7 opendir(DIR, ".");
8 @files = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
9 closedir(DIR);
11 foreach $file (@files) {
13 if(-d $file && $file !~ /^\./) {
14 print "Processing directory $file\n";
15 opendir(DIR, $file);
16 @newfiles = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
17 closedir(DIR);
18 printf "Adding files @newfiles\n";
19 @files = (@files, map { $_ = "$file/$_" } @newfiles);
20 next;
24 foreach $file (@files) {
25 if(-f $file) {
27 print "Adding file $file\n";
29 open(FILE, $file) || die "Could not open file $file\n";
30 if (grep /.png/,$file) {binmode FILE;}
31 if (grep /.jpg/,$file) {binmode FILE;}
32 if (grep /.gif/,$file) {binmode FILE;}
34 $file =~ s-^-/-;
35 $fvar = $file;
36 $fvar =~ s-/-_-g;
37 $fvar =~ s-\.-_-g;
38 # for AVR, add PROGMEM here
39 print(OUTPUT "static const char data".$fvar."[] PROGMEM = {\n");
40 print(OUTPUT "\t/* $file */\n\t");
41 for($j = 0; $j < length($file); $j++) {
42 printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));
44 printf(OUTPUT "0,\n");
47 $i = 0;
48 while(read(FILE, $data, 1)) {
49 if($i == 0) {
50 print(OUTPUT "\t");
52 printf(OUTPUT "%#02x, ", unpack("C", $data));
53 $i++;
54 if($i == 10) {
55 print(OUTPUT "\n");
56 $i = 0;
59 print(OUTPUT "0};\n\n");
60 close(FILE);
61 push(@fvars, $fvar);
62 push(@pfiles, $file);
66 for($i = 0; $i < @fvars; $i++) {
67 $file = $pfiles[$i];
68 $fvar = $fvars[$i];
70 if($i == 0) {
71 $prevfile = "NULL";
72 } else {
73 $prevfile = "file" . $fvars[$i - 1];
75 # for AVR, add PROGMEM here
76 print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] PROGMEM = {{$prevfile, data$fvar, ");
77 print(OUTPUT "data$fvar + ". (length($file) + 1) .", ");
78 print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n");
81 print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
82 print(OUTPUT "#define HTTPD_FS_NUMFILES $i\n");