On 01/13/2012 07:59 PM, Robert Epprecht wrote:
> Matthias Trute<[email protected]> writes:
>> Another tool to use is am4up with minicom (a small
>
>> The downside is that it does not honor the include commands.
> No problem. I think putting the include logic into the upload
> tool might be questionable design anyway.
ACK! I added these lines into the makefile
TARGET=main
CONSOLE=/dev/ttyUSB0
...
upload_file:
cat $(TARGET).fs | unfold_fs > $(TARGET).fs.unfold
trim_fs $(TARGET).fs.unfold > $(TARGET).fs.upload
upload: upload_file
amforth-upload.py -t ${CONSOLE} $(TARGET).fs.upload
to produce the following commands
$ make -n upload
cat main.fs | unfold_fs > main.fs.unfold
trim_fs main.fs.unfold > main.fs.upload
amforth-upload.py -t /dev/ttyUSB0 main.fs.upload
unfold_fs treats all include directives adding comment lines
(begin end of file X) and the content of file X into the
output stream. trim_fs removes all comments of form
\ ... line
or
... ( comment ) ...
and it compresses consecutive spaces, possibly in undesired places.
Please find the two scripts below for anyone's use
Comments and patches are, of course, welcome.
Cheers,
Erich
# ----------------------------------------------------------------
$ cat ~/bin/unfold_fs
#!/usr/bin/perl -w
# 2007-12-08 EW
#
# filter, read all input, expand lines like
# "^.include filename$"
# with the content found in filename
#
# this is written unfold amforth projects before
# transferring them to the target controller.
use strict;
my $Prog=$0;
my $file="";
my $pattern='^[#]*include\s+(\S+)';
my $comment='\ ---';
my $verbose=0;
while (<>)
{
if (m/$pattern/)
{
$file = "$1";
print STDERR " $file\n" if ($verbose);
if (not -r $file)
{
print STDERR "$Prog: file $file not found!\n";
exit 2;
}
print "$comment include begin $file\n";
system("$Prog $file") == 0 or die "failed.\n";
print "$comment include end $file\n";
}
else
{
print $_;
}
}
# ----------------------------------------------------------------
$ cat ~/bin/trim_fs
#!/usr/bin/perl -w
# 2007-12-08 EW
# trim_fs
#
# filter, remove comments, leading and trailing whitespace and empty lines
#
# this is written to trim unfolded amforth projects
use strict;
my $Prog=$0;
while (<>)
{
chomp;
s/\\[ \t].*$//; # remove line comments
s/\( .* \)//; # remove inline comments
#s/^\s+//; # delete leading whitespace / well no, keep indendation
s/\s+$//; # delete trailing whitespace
s/\b\s+/ /g; # compress white space after first word
next if /^$/; # delete empty lines
print "$_\n";
}
# ----------------------------------------------------------------
------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
[email protected]
https://lists.sourceforge.net/lists/listinfo/amforth-devel