Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jan 1999 15:53:25 +1300
From:      Joe Abley <jabley@clear.co.nz>
To:        Mike Smith <mike@smith.net.au>
Cc:        freebsd-hackers@FreeBSD.ORG, jabley@clear.co.nz
Subject:   Re: FICL and setting BTX variables
Message-ID:  <19990112155325.A32880@clear.co.nz>
In-Reply-To: <199901111023.CAA88602@dingo.cdrom.com>; from Mike Smith on Mon, Jan 11, 1999 at 02:23:45AM -0800
References:  <19990111210558.A29444@clear.co.nz> <199901111023.CAA88602@dingo.cdrom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 11, 1999 at 02:23:45AM -0800, Mike Smith wrote:
> > > 
> > > I'm not sure about the whole softwords/help text munging thing.  Using 
> > > Perl scripts is bad for various reasons, but I'm not sure that I want 
> > > to go to having committed generated files (like the kernel uses) or the 
> > > other way to compiled special-purpose tools.  Anyone handy with awk 
> > > want to try fixing these - both would probably succumb to the awesome 
> > > power of awk.
> > 
> > Eh? <wakes up at mention of awk>
> > 
> > If someone needs some awk writing, and can describe clearly what needs
> > doing, I'll do it.
> 
> There are two separate tasks, each with their own interesting 
> requirements.  The easiest way to understand them is probably to look 
> at what the current perl scripts are doing.  The first transforms the 
> Forth softwords files into a large string array, stripping all the 
> unnecessary bits; that's /sys/boot/ficl/softwords/softcore.pl.
> 
> Run it as per the Makefile to see the output it produces; inferring the 
> rules from that should be pretty straightforward.

Have a look at softcore.awk (below) - I haven't run too much through it,
but I think it should work ok.

It uses two gawk-specific extensions:

 + a function, to aid readability, but it's not a biggie and the function
   calls could certainly be rolled out if they offend anybody

 + one call to strftime() to generate the "last updated" line in the
   resulting c fragment header. This could also be made to go away if we
   don't like gawk-isms.

The use of "[[:space:]]" I think is more readable than " " - these
character classes are defined in the POSIX standard, but may not exist in
other traditional implementations. I like them because hard-coding what a
space is on an arbitrary system seems like a bad thing (although I suspect
most people agree what a space is, and I had to hard-code the tab handling
anyway with \t...)

I'll have a look at the second part in a little while. Meanwhile, please
point out all the bugs in the first part :)


Joe

#!/usr/bin/awk -f
# Convert forth source files to a giant C string
# Joe Abley <jabley@patho.gen.nz>, 12 January 1999

BEGIN \
{
  printf "/***************************************************************\n";
  printf "** s o f t c o r e . c\n";
  printf "** Forth Inspired Command Language -\n";
  printf "** Words from CORE set written in FICL\n";
  printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n";
  printf "** Created: 27 December 1997\n";
  printf "** Last update: %s\n", strftime();
  printf "***************************************************************/\n";
  printf "\n/*\n";
  printf "** This file contains definitions that are compiled into the\n";
  printf "** system dictionary by the first virtual machine to be created.\n";
  printf "** Created automagically by ficl/softwords/softcore.awk\n";
  printf "*/\n";
  printf "\n#include \"ficl.h\"\n";
  printf "\nstatic char softWords[] =\n";

  commenting = 0;
}

# some general early substitutions
{
  gsub("\t", "    ");			# replace each tab with 4 spaces
  gsub("\"", "\\\"");			# escape quotes
  gsub("\\\\[[:space:]]+$", "");	# toss empty comments
}

# strip out empty lines
/^ *$/ \
{
  next;
}

# emit / ** lines as multi-line C comments
/^\\[[:space:]]\*\*/ && (commenting == 0) \
{
  sub("^\\\\[[:space:]]", "");
  printf "/*\n%s\n", $0;
  commenting = 1;
  next;
}

/^\\[[:space:]]\*\*/ \
{
  sub("^\\\\[[:space:]]", "");
  printf "%s\n", $0;
  next;
}

# function to close a comment, used later
function end_comments()
{
  commenting = 0;
  printf "*/\n";
}

# pass commented preprocessor directives
/^\\[[:space:]]#/ \
{
  if (commenting) end_comments();
  sub("^\\\\[[:space:]]", "");
  printf "%s\n", $0;
  next;
}

# toss all other full-line comments
/^\\/ \
{
  if (commenting) end_comments();
  next;
}

# emit all other lines as quoted string fragments
{
  if (commenting) end_comments();

  sub("\\\\[[:space:]]+.*$", "");	# lop off trailing \ comments
  sub("[[:space:]]+$", "");		# remove trailing spaces
  printf "    \"%s \\n\"\n", $0;
  next;
}

END \
{
  if (commenting) end_comments();
  printf "    \"quit \";\n";
  printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n";
  printf "{\n";
  printf "    assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n";
  printf "}\n";
}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990112155325.A32880>