Rework epicsMakeMemFs.pl script to use higher level constructs
This commit is contained in:
@@ -2,51 +2,59 @@
|
||||
#
|
||||
|
||||
use File::Basename;
|
||||
use Text::Wrap;
|
||||
|
||||
use strict;
|
||||
|
||||
my $outfile = shift;
|
||||
my $varname = shift;
|
||||
|
||||
open(my $DST, '>', $outfile) or die "Failed to open $outfile";
|
||||
open(my $DST, '>', $outfile)
|
||||
or die "Failed to open $outfile";
|
||||
|
||||
my $inputs = join "\n * ", @ARGV;
|
||||
print $DST <<EOF;
|
||||
/* $outfile containing
|
||||
* $inputs
|
||||
*/
|
||||
|
||||
#include <epicsMemFs.h>
|
||||
|
||||
EOF
|
||||
|
||||
my $N = 0;
|
||||
|
||||
$Text::Wrap::break = ',';
|
||||
$Text::Wrap::columns = 78;
|
||||
$Text::Wrap::separator = ",\n";
|
||||
|
||||
for my $fname (@ARGV) {
|
||||
print "<- $fname\n";
|
||||
my $realfname = $fname;
|
||||
|
||||
# strip leading "../" "./" or "/"
|
||||
while ($fname =~ /^\.*\/(.*)$/) { $fname = $1; }
|
||||
$fname =~ s(^\.{0,2}/)()g;
|
||||
|
||||
my $file = basename($fname);
|
||||
my @dirs = split('/', dirname($fname));
|
||||
|
||||
print $DST "/* begin $realfname */\nstatic const char * const file_${N}_dir[] = {";
|
||||
for my $dpart (@dirs) {
|
||||
print $DST "\"$dpart\", ";
|
||||
}
|
||||
print $DST "NULL};\nstatic const char file_${N}_data[] = {\n ";
|
||||
print $DST "/* $realfname */\n",
|
||||
"static const char * const file_${N}_dir[] = {",
|
||||
map("\"$_\", ", @dirs), "NULL};\n",
|
||||
"static const char file_${N}_data[] = {\n",
|
||||
" ";
|
||||
|
||||
open(my $SRC, '<', $realfname) or die "Failed to open $realfname";
|
||||
binmode($SRC);
|
||||
open(my $SRC, '<', $realfname)
|
||||
or die "Failed to open $realfname";
|
||||
binmode $SRC;
|
||||
|
||||
my $buf;
|
||||
my $total = 0;
|
||||
while (my $num = read($SRC, $buf, 32)) {
|
||||
if($total != 0) {
|
||||
print $DST ",\n ";
|
||||
}
|
||||
$total += $num;
|
||||
my $out = join(",",map(ord,split(//,$buf)));
|
||||
print $DST "$out";
|
||||
my ($buf, @bufs);
|
||||
while (read($SRC, $buf, 4096)) {
|
||||
@bufs[-1] .= ',' if @bufs; # Need ',' between buffers
|
||||
push @bufs, join(",", map(ord, split(//, $buf)));
|
||||
}
|
||||
|
||||
close($SRC);
|
||||
print $DST wrap('', ' ', @bufs);
|
||||
|
||||
close $SRC;
|
||||
|
||||
print $DST <<EOF;
|
||||
|
||||
@@ -55,29 +63,23 @@ static const epicsMemFile file_${N} = {
|
||||
file_${N}_dir,
|
||||
\"$file\",
|
||||
file_${N}_data,
|
||||
$total
|
||||
sizeof(file_${N}_data)
|
||||
};
|
||||
/* end $realfname */
|
||||
|
||||
EOF
|
||||
$N = $N + 1;
|
||||
$N++;
|
||||
}
|
||||
|
||||
my $files = join ', ', map "&file_${_}", (0 .. $N-1);
|
||||
|
||||
print $DST <<EOF;
|
||||
static const epicsMemFile* files[] = {
|
||||
EOF
|
||||
|
||||
$N = $N - 1;
|
||||
|
||||
for my $i (0..${N}) {
|
||||
print $DST " &file_${i},";
|
||||
}
|
||||
|
||||
print $DST <<EOF;
|
||||
NULL
|
||||
$files, NULL
|
||||
};
|
||||
|
||||
static
|
||||
const epicsMemFS ${varname}_image = {&files[0]};
|
||||
const epicsMemFS * $varname = &${varname}_image;
|
||||
EOF
|
||||
|
||||
close($DST);
|
||||
close $DST;
|
||||
|
||||
Reference in New Issue
Block a user