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 $
14 # $DragonFly: src/sys/boot/ficl/softwords/softcore.awk,v 1.2 2003/06/17 04:28:18 dillon Exp $
18 printf "/***************************************************************\n";
19 printf "** s o f t c o r e . c\n";
20 printf "** Forth Inspired Command Language -\n";
21 printf "** Words from CORE set written in FICL\n";
22 printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n";
23 printf "** Created: 27 December 1997\n";
24 printf "** Last update: %s\n", datestamp;
25 printf "***************************************************************/\n";
27 printf "** This file contains definitions that are compiled into the\n";
28 printf "** system dictionary by the first virtual machine to be created.\n";
29 printf "** Created automagically by ficl/softwords/softcore.awk\n";
31 printf "\n#include \"ficl.h\"\n";
32 printf "\nstatic char softWords[] =\n";
37 # some general early substitutions
39 gsub(/\t/, " "); # replace each tab with 4 spaces
40 gsub(/\"/, "\\\""); # escape quotes
41 gsub(/\\[[:space:]]+$/, ""); # toss empty comments
44 # strip out empty lines
50 # emit / ** lines as multi-line C comments
51 /^\\[[:space:]]\*\*/ \
53 sub(/^\\[[:space:]]/, "");
54 if (commenting == 0) printf "/*\n";
66 # function to close a comment, used later
67 function end_comments()
73 # pass commented preprocessor directives
76 if (commenting) end_comments();
77 sub(/^\\[[:space:]]/, "");
82 # toss all other full-line \ comments
85 if (commenting) end_comments();
89 # lop off trailing \ comments
92 sub(/\\[[:space:]]+.*$/, "");
95 # expunge ( ) comments
96 /[[:space:]]+\([[:space:]][^)]*\)/ \
98 sub(/[[:space:]]+\([[:space:]][^)]*\)/, "");
101 # remove leading spaces
104 sub(/^[[:space:]]+/, "");
107 # removing trailing spaces
110 sub(/[[:space:]]+$/, "");
113 # strip out empty lines again (preceding rules may have generated some)
116 if (commenting) end_comments();
120 # emit all other lines as quoted string fragments
122 if (commenting) end_comments();
124 printf " \"%s \"\n", $0;
130 if (commenting) end_comments();
131 printf " \"quit \";\n";
132 printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n";
134 printf " assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n";