From 30677181439d0e63c337318e99a0148feda13a58 Mon Sep 17 00:00:00 2001 From: Karai Csaba Date: Sun, 1 May 2016 07:48:32 +0200 Subject: [PATCH] Added: script for creating file system --- createEspFs.pl | 114 ++++++++++++++++++++++++++++ examples/web-server/GZipped.html.gz | Bin 0 -> 70 bytes examples/web-server/LED.html | 3 + html/web-server.html | 2 +- 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100755 createEspFs.pl create mode 100644 examples/web-server/GZipped.html.gz create mode 100644 examples/web-server/LED.html diff --git a/createEspFs.pl b/createEspFs.pl new file mode 100755 index 0000000..721b3a3 --- /dev/null +++ b/createEspFs.pl @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use strict; +use Data::Dumper; + +my $dir = shift @ARGV; +my $out = shift @ARGV; + +my $espfs = ''; + +my @structured = read_dir_structure($dir, ""); + +for my $file (@structured) +{ + my $flags = 0; + my $name = $file; + my $compression = 0; + + if( $name =~ /\.gz$/ ) + { + $flags |= 2; + $name =~ s/\.gz$//; + } + + my $head = 'esp-link
'; + + open IF, "<", "$dir/$file" or die "Can't read file: $!"; + my @fc = ; + close(IF); + my $cnt = join("", @fc); + + if( $name =~ /\.html$/ ) + { + if( ! ( $flags & 2 ) ) + { + $cnt = "$head$cnt"; + } + else + { + printf("TODO: prepend headers to GZipped HTML content!\n"); + } + } + + $name .= chr(0); + $name .= chr(0) while( (length($name) & 3) != 0 ); + + my $size = length($cnt); + + $espfs .= "ESfs"; + $espfs .= chr($flags); + $espfs .= chr($compression); + $espfs .= chr( length($name) & 255 ); + $espfs .= chr( length($name) / 256 ); + $espfs .= chr( $size & 255 ); + $espfs .= chr( ( $size / 0x100 ) & 255 ); + $espfs .= chr( ( $size / 0x10000 ) & 255 ); + $espfs .= chr( ( $size / 0x1000000 ) & 255 ); + $espfs .= chr( $size & 255 ); + $espfs .= chr( ( $size / 0x100 ) & 255 ); + $espfs .= chr( ( $size / 0x10000 ) & 255 ); + $espfs .= chr( ( $size / 0x1000000 ) & 255 ); + + $espfs .= $name; + + + + $cnt .= chr(0) while( (length($cnt) & 3) != 0 ); + $espfs .= $cnt; +} + +$espfs .= "ESfs"; +$espfs .= chr(1); +for(my $i=0; $i < 11; $i++) +{ + $espfs .= chr(0); +} + +open FH, ">", $out or die "Can't open file for write, $!"; +print FH $espfs; +close(FH); + + +exit(0); + +sub read_dir_structure +{ + my ($dir, $base) = @_; + + my @files; + + opendir my $dh, $dir or die "Could not open '$dir' for reading: $!\n"; + + while (my $file = readdir $dh) { + if ($file eq '.' or $file eq '..') { + next; + } + + my $path = "$dir/$file"; + if( -d "$path" ) + { + my @sd = read_dir_structure($path, "$base/$file"); + push @files, @sd ; + } + else + { + push @files, "$base/$file"; + } + } + + close( $dh ); + + $_ =~ s/^\/// for(@files); + return @files; +} diff --git a/examples/web-server/GZipped.html.gz b/examples/web-server/GZipped.html.gz new file mode 100644 index 0000000000000000000000000000000000000000..e9c012cb904e9c9107c4e843e72fcd11459dc711 GIT binary patch literal 70 zcmV-M0J;AkiwFohktJ6E14mkEaByX0E@*UZYyeYGut~`*v*S_#0-Fp&yO4~`Vg(>d cugWYaNKLWP2Z{kDZS=va0Q%qKmo5MR09@P}TmS$7 literal 0 HcmV?d00001 diff --git a/examples/web-server/LED.html b/examples/web-server/LED.html new file mode 100644 index 0000000..4c88681 --- /dev/null +++ b/examples/web-server/LED.html @@ -0,0 +1,3 @@ +
+

Hello

+
diff --git a/html/web-server.html b/html/web-server.html index c73e59c..4fa5bd4 100644 --- a/html/web-server.html +++ b/html/web-server.html @@ -15,4 +15,4 @@
- \ No newline at end of file +