]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/boot/ficl/softwords/softcore.awk
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / boot / ficl / softwords / softcore.awk
1 #!/usr/bin/awk -f
2 #
3 # Convert forth source files to a giant C string
4 #
5 # Joe Abley <jabley@patho.gen.nz>, 12 January 1999
6 #
7 # 02-oct-1999:  Cleaned up awk slightly; added some additional logic
8 #               suggested by dcs to compress the stored forth program.
9 #
10 # Note! This script uses strftime() which is a gawk-ism, and the
11 # POSIX [[:space:]] character class.
12 #
13 # $FreeBSD$
14
15 BEGIN \
16 {
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";
25   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";
31   printf "*/\n";
32   printf "/*\n";
33   printf "** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)\n";
34   printf "** All rights reserved.\n";
35   printf "**\n";
36   printf "** Get the latest Ficl release at http://ficl.sourceforge.net\n";
37   printf "**\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";
42   printf "**\n";
43   printf "** L I C E N S E  and  D I S C L A I M E R\n";
44   printf "** \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";
53   printf "**\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";
65   printf "*/\n";
66   printf "\n";
67   printf "\n#include \"ficl.h\"\n";
68   printf "\nstatic char softWords[] =\n";
69   printf "#if FICL_WANT_SOFTWORDS\n";
70
71   commenting = 0;
72 }
73
74 # some general early substitutions
75 {
76   gsub(/\t/, "    ");                   # replace each tab with 4 spaces
77   gsub(/\"/, "\\\"");                   # escape quotes
78   gsub(/\\[[:space:]]+$/, "");          # toss empty comments
79 }
80
81 # strip out empty lines
82 /^ *$/ \
83 {
84   next;
85 }
86
87 # emit / ** lines as multi-line C comments
88 /^\\[[:space:]]\*\*/ \
89 {
90   sub(/^\\[[:space:]]/, "");
91   if (commenting == 0) printf "/*\n";
92   printf "%s\n", $0;
93   commenting = 1;
94   next;
95 }
96
97 # strip blank lines
98 /^[[:space:]]*$/ \
99 {
100   next;
101 }
102
103 # function to close a comment, used later
104 function end_comments()
105 {
106   commenting = 0;
107   printf "*/\n";
108 }
109
110 # pass commented preprocessor directives
111 /^\\[[:space:]]#/ \
112 {
113   if (commenting) end_comments();
114   sub(/^\\[[:space:]]/, "");
115   printf "%s\n", $0;
116   next;
117 }
118
119 # toss all other full-line \ comments
120 /^\\/ \
121 {
122   if (commenting) end_comments();
123   next;
124 }
125
126 # lop off trailing \ comments
127 /\\[[:space:]]+/ \
128 {
129   sub(/\\[[:space:]]+.*$/, "");
130 }
131
132 # expunge ( ) comments
133 /[[:space:]]+\([[:space:]][^)]*\)/ \
134 {
135   sub(/[[:space:]]+\([[:space:]][^)]*\)/, "");
136 }
137
138 # remove leading spaces
139 /^[[:space:]]+/ \
140 {
141   sub(/^[[:space:]]+/, "");
142 }
143
144 # removing trailing spaces
145 /[[:space:]]+$/ \
146 {
147   sub(/[[:space:]]+$/, "");
148 }
149
150 # strip out empty lines again (preceding rules may have generated some)
151 /^[[:space:]]*$/ \
152 {
153   if (commenting) end_comments();
154   next;
155 }
156
157 # emit all other lines as quoted string fragments
158 {
159   if (commenting) end_comments();
160
161   printf "    \"%s \"\n", $0;
162   next;
163 }
164
165 END \
166 {
167   if (commenting) end_comments();
168   printf "#endif /* WANT_SOFTWORDS */\n";
169   printf "    \"quit \";\n";
170   printf "\n\nvoid ficlCompileSoftCore(FICL_SYSTEM *pSys)\n";
171   printf "{\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";
181   printf "    return;\n";
182   printf "}\n";
183 }