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 14BEGIN \ 15{ 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"; 24 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"; 30 printf "*/\n"; 31 printf "/*\n"; 32 printf "** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)\n"; 33 printf "** All rights reserved.\n"; 34 printf "**\n"; 35 printf "** Get the latest Ficl release at http://ficl.sourceforge.net\n"; 36 printf "**\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"; 41 printf "**\n"; 42 printf "** L I C E N S E and D I S C L A I M E R\n"; 43 printf "** \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"; 52 printf "**\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"; 64 printf "*/\n"; 65 printf "\n"; 66 printf "\n#include \"ficl.h\"\n"; 67 printf "\nstatic char softWords[] =\n"; 68 printf "#if FICL_WANT_SOFTWORDS\n"; 69 70 commenting = 0; 71} 72 73# some general early substitutions 74{ 75 gsub(/\t/, " "); # replace each tab with 4 spaces 76 gsub(/\"/, "\\\""); # escape quotes 77 gsub(/\\[[:space:]]+$/, ""); # toss empty comments 78} 79 80# strip out empty lines 81/^ *$/ \ 82{ 83 next; 84} 85 86# emit / ** lines as multi-line C comments 87/^\\[[:space:]]\*\*/ \ 88{ 89 sub(/^\\[[:space:]]/, ""); 90 if (commenting == 0) printf "/*\n"; 91 printf "%s\n", $0; 92 commenting = 1; 93 next; 94} 95 96# strip blank lines 97/^[[:space:]]*$/ \ 98{ 99 next; 100} 101 102# function to close a comment, used later 103function end_comments() 104{ 105 commenting = 0; 106 printf "*/\n"; 107} 108 109# pass commented preprocessor directives 110/^\\[[:space:]]#/ \ 111{ 112 if (commenting) end_comments(); 113 sub(/^\\[[:space:]]/, ""); 114 printf "%s\n", $0; 115 next; 116} 117 118# toss all other full-line \ comments 119/^\\/ \ 120{ 121 if (commenting) end_comments(); 122 next; 123} 124 125# lop off trailing \ comments 126/\\[[:space:]]+/ \ 127{ 128 sub(/\\[[:space:]]+.*$/, ""); 129} 130 131# expunge ( ) comments 132/[[:space:]]+\([[:space:]][^)]*\)/ \ 133{ 134 sub(/[[:space:]]+\([[:space:]][^)]*\)/, ""); 135} 136 137# remove leading spaces 138/^[[:space:]]+/ \ 139{ 140 sub(/^[[:space:]]+/, ""); 141} 142 143# removing trailing spaces 144/[[:space:]]+$/ \ 145{ 146 sub(/[[:space:]]+$/, ""); 147} 148 149# strip out empty lines again (preceding rules may have generated some) 150/^[[:space:]]*$/ \ 151{ 152 if (commenting) end_comments(); 153 next; 154} 155 156# emit all other lines as quoted string fragments 157{ 158 if (commenting) end_comments(); 159 160 printf " \"%s \"\n", $0; 161 next; 162} 163 164END \ 165{ 166 if (commenting) end_comments(); 167 printf "#endif /* WANT_SOFTWORDS */\n"; 168 printf " \"quit \";\n"; 169 printf "\n\nvoid ficlCompileSoftCore(FICL_SYSTEM *pSys)\n"; 170 printf "{\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"; 180 printf " return;\n"; 181 printf "}\n"; 182} 183