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.
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 "** DO NOT EDIT THIS FILE -- it is generated by softwords/softcore.awk\n";
27 printf "** Make changes to the .fr files in ficl/softwords instead.\n";
28 printf "** This file contains definitions that are compiled into the\n";
29 printf "** system dictionary by the first virtual machine to be created.\n";
30 printf "** Created automagically by ficl/softwords/softcore.awk\n";
33 printf "** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)\n";
34 printf "** All rights reserved.\n";
36 printf "** Get the latest Ficl release at http://ficl.sourceforge.net\n";
38 printf "** I am interested in hearing from anyone who uses ficl. If you have\n";
39 printf "** a problem, a success story, a defect, an enhancement request, or\n";
40 printf "** if you would like to contribute to the ficl release, please send\n";
41 printf "** contact me by email at the address above.\n";
43 printf "** L I C E N S E and D I S C L A I M E R\n";
45 printf "** Redistribution and use in source and binary forms, with or without\n";
46 printf "** modification, are permitted provided that the following conditions\n";
47 printf "** are met:\n";
48 printf "** 1. Redistributions of source code must retain the above copyright\n";
49 printf "** notice, this list of conditions and the following disclaimer.\n";
50 printf "** 2. Redistributions in binary form must reproduce the above copyright\n";
51 printf "** notice, this list of conditions and the following disclaimer in the\n";
52 printf "** documentation and/or other materials provided with the distribution.\n";
54 printf "** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n";
55 printf "** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n";
56 printf "** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n";
57 printf "** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n";
58 printf "** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n";
59 printf "** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n";
60 printf "** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n";
61 printf "** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n";
62 printf "** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n";
63 printf "** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n";
64 printf "** SUCH DAMAGE.\n";
67 printf "\n#include \"ficl.h\"\n";
68 printf "\nstatic char softWords[] =\n";
69 printf "#if FICL_WANT_SOFTWORDS\n";
74 # some general early substitutions
76 gsub(/\t/, " "); # replace each tab with 4 spaces
77 gsub(/\"/, "\\\""); # escape quotes
78 gsub(/\\[[:space:]]+$/, ""); # toss empty comments
81 # strip out empty lines
87 # emit / ** lines as multi-line C comments
88 /^\\[[:space:]]\*\*/ \
90 sub(/^\\[[:space:]]/, "");
91 if (commenting == 0) printf "/*\n";
103 # function to close a comment, used later
104 function end_comments()
110 # pass commented preprocessor directives
113 if (commenting) end_comments();
114 sub(/^\\[[:space:]]/, "");
119 # toss all other full-line \ comments
122 if (commenting) end_comments();
126 # lop off trailing \ comments
129 sub(/\\[[:space:]]+.*$/, "");
132 # expunge ( ) comments
133 /[[:space:]]+\([[:space:]][^)]*\)/ \
135 sub(/[[:space:]]+\([[:space:]][^)]*\)/, "");
138 # remove leading spaces
141 sub(/^[[:space:]]+/, "");
144 # removing trailing spaces
147 sub(/[[:space:]]+$/, "");
150 # strip out empty lines again (preceding rules may have generated some)
153 if (commenting) end_comments();
157 # emit all other lines as quoted string fragments
159 if (commenting) end_comments();
161 printf " \"%s \"\n", $0;
167 if (commenting) end_comments();
168 printf "#endif /* WANT_SOFTWORDS */\n";
169 printf " \"quit \";\n";
170 printf "\n\nvoid ficlCompileSoftCore(FICL_SYSTEM *pSys)\n";
172 printf " FICL_VM *pVM = pSys->vmList;\n";
173 printf " CELL id = pVM->sourceID;\n";
174 printf " int ret = sizeof (softWords);\n";
175 printf " assert(pVM);\n";
176 printf " pVM->sourceID.i = -1;\n";
177 printf " ret = ficlExec(pVM, softWords);\n";
178 printf " pVM->sourceID = id;\n";
179 printf " if (ret == VM_ERREXIT)\n";
180 printf " assert(FALSE);\n";