2007-08-27 01:12:17 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
open(OUTPUT, "> httpd-fsdata.c");
|
|
|
|
|
|
|
|
chdir("httpd-fs");
|
|
|
|
|
|
|
|
opendir(DIR, ".");
|
|
|
|
@files = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
|
|
|
|
closedir(DIR);
|
|
|
|
|
|
|
|
foreach $file (@files) {
|
|
|
|
|
|
|
|
if(-d $file && $file !~ /^\./) {
|
|
|
|
print "Processing directory $file\n";
|
|
|
|
opendir(DIR, $file);
|
|
|
|
@newfiles = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
|
|
|
|
closedir(DIR);
|
|
|
|
printf "Adding files @newfiles\n";
|
|
|
|
@files = (@files, map { $_ = "$file/$_" } @newfiles);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach $file (@files) {
|
|
|
|
if(-f $file) {
|
|
|
|
|
|
|
|
print "Adding file $file\n";
|
2009-03-22 17:10:28 +01:00
|
|
|
|
2007-08-27 01:12:17 +02:00
|
|
|
open(FILE, $file) || die "Could not open file $file\n";
|
|
|
|
|
|
|
|
$file =~ s-^-/-;
|
|
|
|
$fvar = $file;
|
|
|
|
$fvar =~ s-/-_-g;
|
|
|
|
$fvar =~ s-\.-_-g;
|
|
|
|
# for AVR, add PROGMEM here
|
2009-03-22 17:10:28 +01:00
|
|
|
print(OUTPUT "static const unsigned char data".$fvar."[] =\n");
|
|
|
|
print(OUTPUT "{\n /* $file */\n\n ");
|
2007-08-27 01:12:17 +02:00
|
|
|
for($j = 0; $j < length($file); $j++) {
|
|
|
|
printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));
|
|
|
|
}
|
2009-03-22 17:10:28 +01:00
|
|
|
printf(OUTPUT "0x00,\n ");
|
2007-08-27 01:12:17 +02:00
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while(read(FILE, $data, 1)) {
|
|
|
|
printf(OUTPUT "%#02x, ", unpack("C", $data));
|
|
|
|
$i++;
|
|
|
|
if($i == 10) {
|
|
|
|
print(OUTPUT "\n");
|
|
|
|
$i = 0;
|
2009-03-22 17:10:28 +01:00
|
|
|
print(OUTPUT " ");
|
2007-08-27 01:12:17 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-22 17:10:28 +01:00
|
|
|
print(OUTPUT "0x00\n};\n\n");
|
2007-08-27 01:12:17 +02:00
|
|
|
close(FILE);
|
|
|
|
push(@fvars, $fvar);
|
|
|
|
push(@pfiles, $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for($i = 0; $i < @fvars; $i++) {
|
|
|
|
$file = $pfiles[$i];
|
|
|
|
$fvar = $fvars[$i];
|
|
|
|
|
|
|
|
if($i == 0) {
|
|
|
|
$prevfile = "NULL";
|
|
|
|
} else {
|
|
|
|
$prevfile = "file" . $fvars[$i - 1];
|
|
|
|
}
|
|
|
|
print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] = {{$prevfile, data$fvar, ");
|
|
|
|
print(OUTPUT "data$fvar + ". (length($file) + 1) .", ");
|
|
|
|
print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n");
|
|
|
|
}
|
|
|
|
|
2009-03-22 17:10:28 +01:00
|
|
|
print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
|
2007-08-27 01:12:17 +02:00
|
|
|
print(OUTPUT "#define HTTPD_FS_NUMFILES $i\n");
|