From owner-freebsd-hackers Mon Jan 11 18:54:15 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id SAA14139 for freebsd-hackers-outgoing; Mon, 11 Jan 1999 18:54:15 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from fep2-orange.clear.net.nz (fep2-orange.clear.net.nz [203.97.32.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA14132 for ; Mon, 11 Jan 1999 18:54:12 -0800 (PST) (envelope-from jabley@buddha.clear.net.nz) Received: from buddha.clear.net.nz (buddha.clear.net.nz [192.168.24.106]) by fep2-orange.clear.net.nz (1.5/1.9) with ESMTP id PAA13108; Tue, 12 Jan 1999 15:53:29 +1300 (NZDT) Received: (from jabley@localhost) by buddha.clear.net.nz (8.9.1/8.9.1) id PAA32924; Tue, 12 Jan 1999 15:53:25 +1300 (NZDT) (envelope-from jabley) Date: Tue, 12 Jan 1999 15:53:25 +1300 From: Joe Abley To: Mike Smith Cc: freebsd-hackers@FreeBSD.ORG, jabley@clear.co.nz Subject: Re: FICL and setting BTX variables Message-ID: <19990112155325.A32880@clear.co.nz> References: <19990111210558.A29444@clear.co.nz> <199901111023.CAA88602@dingo.cdrom.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95i In-Reply-To: <199901111023.CAA88602@dingo.cdrom.com>; from Mike Smith on Mon, Jan 11, 1999 at 02:23:45AM -0800 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, Jan 11, 1999 at 02:23:45AM -0800, Mike Smith wrote: > > > > > > I'm not sure about the whole softwords/help text munging thing. Using > > > Perl scripts is bad for various reasons, but I'm not sure that I want > > > to go to having committed generated files (like the kernel uses) or the > > > other way to compiled special-purpose tools. Anyone handy with awk > > > want to try fixing these - both would probably succumb to the awesome > > > power of awk. > > > > Eh? > > > > If someone needs some awk writing, and can describe clearly what needs > > doing, I'll do it. > > There are two separate tasks, each with their own interesting > requirements. The easiest way to understand them is probably to look > at what the current perl scripts are doing. The first transforms the > Forth softwords files into a large string array, stripping all the > unnecessary bits; that's /sys/boot/ficl/softwords/softcore.pl. > > Run it as per the Makefile to see the output it produces; inferring the > rules from that should be pretty straightforward. Have a look at softcore.awk (below) - I haven't run too much through it, but I think it should work ok. It uses two gawk-specific extensions: + a function, to aid readability, but it's not a biggie and the function calls could certainly be rolled out if they offend anybody + one call to strftime() to generate the "last updated" line in the resulting c fragment header. This could also be made to go away if we don't like gawk-isms. The use of "[[:space:]]" I think is more readable than " " - these character classes are defined in the POSIX standard, but may not exist in other traditional implementations. I like them because hard-coding what a space is on an arbitrary system seems like a bad thing (although I suspect most people agree what a space is, and I had to hard-code the tab handling anyway with \t...) I'll have a look at the second part in a little while. Meanwhile, please point out all the bugs in the first part :) Joe #!/usr/bin/awk -f # Convert forth source files to a giant C string # Joe Abley , 12 January 1999 BEGIN \ { printf "/***************************************************************\n"; printf "** s o f t c o r e . c\n"; printf "** Forth Inspired Command Language -\n"; printf "** Words from CORE set written in FICL\n"; printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n"; printf "** Created: 27 December 1997\n"; printf "** Last update: %s\n", strftime(); printf "***************************************************************/\n"; printf "\n/*\n"; printf "** This file contains definitions that are compiled into the\n"; printf "** system dictionary by the first virtual machine to be created.\n"; printf "** Created automagically by ficl/softwords/softcore.awk\n"; printf "*/\n"; printf "\n#include \"ficl.h\"\n"; printf "\nstatic char softWords[] =\n"; commenting = 0; } # some general early substitutions { gsub("\t", " "); # replace each tab with 4 spaces gsub("\"", "\\\""); # escape quotes gsub("\\\\[[:space:]]+$", ""); # toss empty comments } # strip out empty lines /^ *$/ \ { next; } # emit / ** lines as multi-line C comments /^\\[[:space:]]\*\*/ && (commenting == 0) \ { sub("^\\\\[[:space:]]", ""); printf "/*\n%s\n", $0; commenting = 1; next; } /^\\[[:space:]]\*\*/ \ { sub("^\\\\[[:space:]]", ""); printf "%s\n", $0; next; } # function to close a comment, used later function end_comments() { commenting = 0; printf "*/\n"; } # pass commented preprocessor directives /^\\[[:space:]]#/ \ { if (commenting) end_comments(); sub("^\\\\[[:space:]]", ""); printf "%s\n", $0; next; } # toss all other full-line comments /^\\/ \ { if (commenting) end_comments(); next; } # emit all other lines as quoted string fragments { if (commenting) end_comments(); sub("\\\\[[:space:]]+.*$", ""); # lop off trailing \ comments sub("[[:space:]]+$", ""); # remove trailing spaces printf " \"%s \\n\"\n", $0; next; } END \ { if (commenting) end_comments(); printf " \"quit \";\n"; printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n"; printf "{\n"; printf " assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n"; printf "}\n"; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message