1999-01-18 19:05:27 +00:00
|
|
|
#!/usr/bin/awk -f
|
2000-05-26 22:58:10 +00:00
|
|
|
#
|
1999-01-18 19:05:27 +00:00
|
|
|
# Convert forth source files to a giant C string
|
2000-05-26 22:58:10 +00:00
|
|
|
#
|
1999-01-18 19:05:27 +00:00
|
|
|
# Joe Abley <jabley@patho.gen.nz>, 12 January 1999
|
2000-05-26 22:58:10 +00:00
|
|
|
#
|
|
|
|
# 02-oct-1999: Cleaned up awk slightly; added some additional logic
|
|
|
|
# suggested by dcs to compress the stored forth program.
|
|
|
|
#
|
|
|
|
# Note! This script uses strftime() which is a gawk-ism, and the
|
|
|
|
# POSIX [[:space:]] character class.
|
|
|
|
#
|
1999-09-29 10:58:43 +00:00
|
|
|
# $FreeBSD$
|
1999-01-18 19:05:27 +00:00
|
|
|
|
|
|
|
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";
|
2000-11-14 21:02:49 +00:00
|
|
|
printf "** Last update: %s\n", datestamp;
|
1999-01-18 19:05:27 +00:00
|
|
|
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
|
|
|
|
{
|
2000-05-26 22:58:10 +00:00
|
|
|
gsub(/\t/, " "); # replace each tab with 4 spaces
|
|
|
|
gsub(/\"/, "\\\""); # escape quotes
|
|
|
|
gsub(/\\[[:space:]]+$/, ""); # toss empty comments
|
1999-01-18 19:05:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# strip out empty lines
|
|
|
|
/^ *$/ \
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# emit / ** lines as multi-line C comments
|
2000-05-26 22:58:10 +00:00
|
|
|
/^\\[[:space:]]\*\*/ \
|
1999-01-18 19:05:27 +00:00
|
|
|
{
|
2000-05-26 22:58:10 +00:00
|
|
|
sub(/^\\[[:space:]]/, "");
|
|
|
|
if (commenting == 0) printf "/*\n";
|
|
|
|
printf "%s\n", $0;
|
1999-01-18 19:05:27 +00:00
|
|
|
commenting = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2000-05-26 22:58:10 +00:00
|
|
|
# strip blank lines
|
|
|
|
/^[[:space:]]*$/ \
|
1999-01-18 19:05:27 +00:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# function to close a comment, used later
|
|
|
|
function end_comments()
|
|
|
|
{
|
|
|
|
commenting = 0;
|
|
|
|
printf "*/\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# pass commented preprocessor directives
|
|
|
|
/^\\[[:space:]]#/ \
|
|
|
|
{
|
|
|
|
if (commenting) end_comments();
|
2000-05-26 22:58:10 +00:00
|
|
|
sub(/^\\[[:space:]]/, "");
|
1999-01-18 19:05:27 +00:00
|
|
|
printf "%s\n", $0;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2000-05-26 22:58:10 +00:00
|
|
|
# toss all other full-line \ comments
|
1999-01-18 19:05:27 +00:00
|
|
|
/^\\/ \
|
|
|
|
{
|
|
|
|
if (commenting) end_comments();
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2000-05-26 22:58:10 +00:00
|
|
|
# lop off trailing \ comments
|
|
|
|
/\\[[:space:]]+/ \
|
|
|
|
{
|
|
|
|
sub(/\\[[:space:]]+.*$/, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
# expunge ( ) comments
|
|
|
|
/[[:space:]]+\([[:space:]][^)]*\)/ \
|
|
|
|
{
|
|
|
|
sub(/[[:space:]]+\([[:space:]][^)]*\)/, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
# remove leading spaces
|
|
|
|
/^[[:space:]]+/ \
|
|
|
|
{
|
|
|
|
sub(/^[[:space:]]+/, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
# removing trailing spaces
|
|
|
|
/[[:space:]]+$/ \
|
|
|
|
{
|
|
|
|
sub(/[[:space:]]+$/, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
# strip out empty lines again (preceding rules may have generated some)
|
|
|
|
/^[[:space:]]*$/ \
|
|
|
|
{
|
|
|
|
if (commenting) end_comments();
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
1999-01-18 19:05:27 +00:00
|
|
|
# emit all other lines as quoted string fragments
|
|
|
|
{
|
|
|
|
if (commenting) end_comments();
|
|
|
|
|
2000-05-26 22:58:10 +00:00
|
|
|
printf " \"%s \"\n", $0;
|
1999-01-18 19:05:27 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
END \
|
|
|
|
{
|
|
|
|
if (commenting) end_comments();
|
|
|
|
printf " \"quit \";\n";
|
|
|
|
printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n";
|
|
|
|
printf "{\n";
|
1999-09-29 10:58:43 +00:00
|
|
|
printf " assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n";
|
1999-01-18 19:05:27 +00:00
|
|
|
printf "}\n";
|
|
|
|
}
|