diff --git a/modules/libcom/RTEMS/epicsMakeMemFs.pl b/modules/libcom/RTEMS/epicsMakeMemFs.pl index a97074e0e..a7470bdc4 100644 --- a/modules/libcom/RTEMS/epicsMakeMemFs.pl +++ b/modules/libcom/RTEMS/epicsMakeMemFs.pl @@ -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 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 <