3 # Convert forth source files to a giant C string
5 # Joe Abley <jabley@patho.gen.nz>, 12 January 1999
7 # 02-oct-1999: Cleaned up awk slightly; added some additional logic
8 # suggested by dcs to compress the stored forth program.
10 # Note! This script uses strftime() which is a gawk-ism, and the
11 # POSIX [[:space:]] character class.
13 # $FreeBSD: src/sys/boot/ficl/softwords/softcore.awk,v 1.3.2.2 2001/03/04 04:55:10 obrien Exp $
17 printf "/***************************************************************\n";
18 printf "** s o f t c o r e . c\n";
19 printf "** Forth Inspired Command Language -\n";
20 printf "** Words from CORE set written in FICL\n";
21 printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n";
22 printf "** Created: 27 December 1997\n";
23 printf "** Last update: %s\n", datestamp;
24 printf "***************************************************************/\n";
26 printf "** This file contains definitions that are compiled into the\n";
27 printf "** system dictionary by the first virtual machine to be created.\n";
28 printf "** Created automagically by ficl/softwords/softcore.awk\n";
30 printf "\n#include \"ficl.h\"\n";
31 printf "\nstatic char softWords[] =\n";
36 # some general early substitutions
38 gsub(/\t/, " "); # replace each tab with 4 spaces
39 gsub(/\"/, "\\\""); # escape quotes
40 gsub(/\\[[:space:]]+$/, ""); # toss empty comments
43 # strip out empty lines
49 # emit / ** lines as multi-line C comments
50 /^\\[[:space:]]\*\*/ \
52 sub(/^\\[[:space:]]/, "");
53 if (commenting == 0) printf "/*\n";
65 # function to close a comment, used later
66 function end_comments()
72 # pass commented preprocessor directives
75 if (commenting) end_comments();
76 sub(/^\\[[:space:]]/, "");
81 # toss all other full-line \ comments
84 if (commenting) end_comments();
88 # lop off trailing \ comments
91 sub(/\\[[:space:]]+.*$/, "");
94 # expunge ( ) comments
95 /[[:space:]]+\([[:space:]][^)]*\)/ \
97 sub(/[[:space:]]+\([[:space:]][^)]*\)/, "");
100 # remove leading spaces
103 sub(/^[[:space:]]+/, "");
106 # removing trailing spaces
109 sub(/[[:space:]]+$/, "");
112 # strip out empty lines again (preceding rules may have generated some)
115 if (commenting) end_comments();
119 # emit all other lines as quoted string fragments
121 if (commenting) end_comments();
123 printf " \"%s \"\n", $0;
129 if (commenting) end_comments();
130 printf " \"quit \";\n";
131 printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n";
133 printf " assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n";