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.
16 printf "/*******************************************************************\n";
17 printf "** s o f t c o r e . c\n";
18 printf "** Forth Inspired Command Language -\n";
19 printf "** Words from CORE set written in FICL\n";
20 printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n";
21 printf "** Created: 27 December 1997\n";
22 printf "** Last update: %s\n", datestamp
;
23 printf "*******************************************************************/\n";
25 printf "** DO NOT EDIT THIS FILE -- it is generated by softwords/softcore.awk\n";
26 printf "** Make changes to the .fr files in ficl/softwords instead.\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";
32 printf "** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)\n";
33 printf "** All rights reserved.\n";
35 printf "** Get the latest Ficl release at http://ficl.sourceforge.net\n";
37 printf "** I am interested in hearing from anyone who uses ficl. If you have\n";
38 printf "** a problem, a success story, a defect, an enhancement request, or\n";
39 printf "** if you would like to contribute to the ficl release, please send\n";
40 printf "** contact me by email at the address above.\n";
42 printf "** L I C E N S E and D I S C L A I M E R\n";
44 printf "** Redistribution and use in source and binary forms, with or without\n";
45 printf "** modification, are permitted provided that the following conditions\n";
46 printf "** are met:\n";
47 printf "** 1. Redistributions of source code must retain the above copyright\n";
48 printf "** notice, this list of conditions and the following disclaimer.\n";
49 printf "** 2. Redistributions in binary form must reproduce the above copyright\n";
50 printf "** notice, this list of conditions and the following disclaimer in the\n";
51 printf "** documentation and/or other materials provided with the distribution.\n";
53 printf "** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n";
54 printf "** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n";
55 printf "** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n";
56 printf "** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n";
57 printf "** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n";
58 printf "** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n";
59 printf "** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n";
60 printf "** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n";
61 printf "** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n";
62 printf "** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n";
63 printf "** SUCH DAMAGE.\n";
66 printf "\n#include \"ficl.h\"\n";
67 printf "\nstatic char softWords[] =\n";
68 printf "#if FICL_WANT_SOFTWORDS\n";
73 # some general early substitutions
75 gsub(/\t/, " "); # replace each tab with 4 spaces
76 gsub(/\"/, "\\\""); # escape quotes
77 gsub(/\\[[:space
:]]+$
/, ""); # toss empty comments
80 # strip out empty lines
86 # emit / ** lines as multi-line C comments
87 /^
\\[[:space
:]]\
*\
*/ \
89 sub(/^
\\[[:space
:]]/, "");
90 if (commenting ==
0) printf "/*\n";
102 # function to close a comment, used later
103 function end_comments
()
109 # pass commented preprocessor directives
112 if (commenting
) end_comments
();
113 sub(/^
\\[[:space
:]]/, "");
118 # toss all other full-line \ comments
121 if (commenting
) end_comments
();
125 # lop off trailing \ comments
128 sub(/\\[[:space
:]]+.
*$
/, "");
131 # expunge ( ) comments
132 /[[:space
:]]+\
([[:space
:]][^
)]*\
)/ \
134 sub(/[[:space
:]]+\
([[:space
:]][^
)]*\
)/, "");
137 # remove leading spaces
140 sub(/^
[[:space
:]]+/, "");
143 # removing trailing spaces
146 sub(/[[:space
:]]+$
/, "");
149 # strip out empty lines again (preceding rules may have generated some)
152 if (commenting
) end_comments
();
156 # emit all other lines as quoted string fragments
158 if (commenting
) end_comments
();
160 printf " \"%s \"\n", $
0;
166 if (commenting
) end_comments
();
167 printf "#endif /* WANT_SOFTWORDS */\n";
168 printf " \"quit \";\n";
169 printf "\n\nvoid ficlCompileSoftCore(FICL_SYSTEM *pSys)\n";
171 printf " FICL_VM *pVM = pSys->vmList;\n";
172 printf " CELL id = pVM->sourceID;\n";
173 printf " int ret = sizeof (softWords);\n";
174 printf " assert(pVM);\n";
175 printf " pVM->sourceID.i = -1;\n";
176 printf " ret = ficlExec(pVM, softWords);\n";
177 printf " pVM->sourceID = id;\n";
178 printf " if (ret == VM_ERREXIT)\n";
179 printf " assert(FALSE);\n";