Transition from using Perl to using awk for our text-manipulation

needs.  This removes the dependancy on Perl for the generation of the
loader, allowing the world to be built on a perl-free system.

Submitted by:	Joe Abley <jabley@clear.co.nz>
This commit is contained in:
Mike Smith 1999-01-18 19:05:27 +00:00
parent e2be51399d
commit 378972ac6b
7 changed files with 203 additions and 274 deletions

View File

@ -47,7 +47,7 @@ ${BASE}.sym: ${OBJS} ${LIBSTAND} ${LIBALPHA} ${CRT} vers.o setdef0.o setdef1.o
vers.o ${LIBSTAND} ${LIBALPHA} ${LIBSTAND} >${.OBJDIR}/${BASE}.list
${BASE}.help: help.common help.alpha
perl ${.CURDIR}/../../common/merge_help.pl ${.ALLSRC} > ${.TARGET}
cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET}
beforeinstall:
.if exists(${.OBJDIR}/loader.help)

View File

@ -0,0 +1,101 @@
#!/usr/bin/awk -f
#
# $Id: mergehelp.awk,v 1.3 1999/01/13 20:06:52 jabley Exp $
#
# Merge two boot loader help files for FreeBSD 3.0
# Joe Abley <jabley@patho.gen.nz>
BEGIN \
{
state = 0;
first = 0;
ind = 0;
}
# beginning of first command
/^###/ && (state == 0) \
{
state = 1;
next;
}
# entry header
/^# T[[:graph:]]+ (S[[:graph:]]+ )*D[[:graph:]][[:print:]]*$/ && (state == 1) \
{
match($0, " T[[:graph:]]+");
T = substr($0, RSTART + 2, RLENGTH - 2);
match($0, " S[[:graph:]]+");
S = (RLENGTH == -1) ? "" : substr($0, RSTART + 2, RLENGTH - 2);
match($0, " D[[:graph:]][[:print:]]*$");
D = substr($0, RSTART + 2);
# find a suitable place to store this one...
ind++;
if (ind == 1)
{
first = ind;
help[ind, "T"] = T;
help[ind, "S"] = S;
help[ind, "link"] = -1;
} else {
i = first; j = -1;
while (help[i, "T"] help[i, "S"] < T S)
{
j = i;
i = help[i, "link"];
if (i == -1) break;
}
if (i == -1)
{
help[j, "link"] = ind;
help[ind, "link"] = -1;
} else {
help[ind, "link"] = i;
if (j == -1)
first = ind;
else
help[j, "link"] = ind;
}
}
help[ind, "T"] = T;
help[ind, "S"] = S;
help[ind, "D"] = D;
# set our state
state = 2;
help[ind, "text"] = 0;
next;
}
# end of last command, beginning of next one
/^###/ && (state == 2) \
{
state = 1;
}
(state == 2) \
{
sub("[[:blank:]]+$", "");
if (help[ind, "text"] == 0 && $0 ~ /^[[:blank:]]*$/) next;
help[ind, "text", help[ind, "text"]] = $0;
help[ind, "text"]++;
next;
}
# show them what we have (it's already sorted in help[])
END \
{
node = first;
while (node != -1)
{
printf "################################################################################\n";
printf "# T%s ", help[node, "T"];
if (help[node, "S"] != "") printf "S%s ", help[node, "S"];
printf "D%s\n\n", help[node, "D"];
for (i = 0; i < help[node, "text"]; i++)
printf "%s\n", help[node, "text", i];
node = help[node, "link"];
}
printf "################################################################################\n";
}

View File

@ -1,182 +0,0 @@
#!/usr/bin/perl
#
# Copyright (c) 1998 Nick Hibma
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
#
# Reads all the files mentioned on the command line (or stdin) and combines
# them into one.
#
# The files must have the following format:
#
# ######################### (line is ignored)
# # Ttopic Dhello world (short description)
# This is the long description and can span
# multiple lines and empty
#
# ones.
# ########################### (this line is again ignored)
# # Ttopic Ssubtopic Dagain a short description
# a subtopic is a topic that will connected under the subtree of
# topic.
# Declaration of constants
#
$SOD = 'D'; # Start of description character
$SLABEL = '_sdescr'; # Short description label
$LLABEL = '_ldescr'; # Long description label
# Global variables
#
# Read the command line parameters
#
while ( $arg = shift @ARGV ) {
if ( $arg eq '-h' ) {
die "$0 [-h] [files ...]\nno filenames or '-' as a filename reads stdin\n";
} else {
push @files, $arg;
}
}
# No files to process? Read STDIN
#
push @files, '-' # no files found? Process STDIN
if $#files == -1;
# Perform processing on each file
#
foreach $filename ( @files ) {
if ( $filename eq '-' ) {
$file = STDIN;
} else {
die "Could not open file $filename, $!"
unless open FILE, $filename;
}
# Process one file and add it to the hash
#
&add_file(FILE);
}
# Print the results of our processing
#
&print_topic($topics, '#'x80 . "\n# ");
print '#'x80 . "\n";
#require 'z39.50/PerlieZ/debug.pm';
#debug::Dump($topics, '$topics');
# Make like a tree and leave.
#
exit 0;
sub add_file {
my ($file) = @_;
# process a file and add it to the hash
$line = <$file>;
while ( !eof($file) ) {
if ( $line =~ s/^#\s+// ) {
# the line contains a number of parts (separated by whitespace):
# (Cl+ )+ Dd+
# C is a character not equal to D
# l+ is a word without spaces
# (Cl+ )+ is a list of words preceded by C and separated by spaces
# d+ is a description (can contain spaces)
# D is the character in $SOD
#
# we split it into multiple l+ parts and one d+ part
# after that we insert the d+ part at the right point in the tree
# (after reading also the long descrescription in the next lines)
@ar = ();
while ( $line =~ s/^([^$SOD]\S+)\s+//o ) {
$label = $1;
$label .= ' ' # avoid conflicts with hash labels
if $label eq $SLABEL or $label eq $LLABEL;
push @ar, $label;
}
$sdescr = $line; # short descr. is rest of line
my $ldescr = ''; # read the long description
$line = <$file>;
while ( !eof($file) and $line !~ m/^#/ ) {
$ldescr .= $line;
$line = <$file>;
}
$topics = &add_to_hash($topics, $sdescr, $ldescr, @ar);
} else {
$line = <$file>;
}
}
}
sub add_to_hash {
my ($hash, $sdescr, $ldescr, @ar) = @_;
# bit more complicated than usual, because we want to insert
# value into an existing tree if possible, or otherwise build it.
# Probably could be done with references as well, but this seems neater.
if ( $#ar == -1 ) {
# Create a new leaf (reference to descriptions hash)
return {$SLABEL=>$sdescr, $LLABEL=>$ldescr};
} else {
# Add subtree to node and if node does not exist, create an empty one
# (reference to a hash of subnodes)
$hash = {} # create a new ref to hash on the fly
if !$hash;
my $label = shift @ar; # next label in tree to be used
$hash->{$label} = &add_to_hash($hash->{$label}, $sdescr, $ldescr, @ar);
return $hash;
}
}
sub print_topic {
my ($topic, $preprint) = @_;
# print out a topic and its subtopics recursively
# preprint is the string before the current subtopic hash
# and is the same for all the subtopics in the current hash
if ( $topic->{$SLABEL} or $topic->{$LLABEL} ) {
# leaf found
print $preprint . "$topic->{$SLABEL}$topic->{$LLABEL}";
}
# iterate over all the subtopics
my ($label);
foreach $label ( sort keys %{ $topic } ) {
next
if $label eq $SLABEL or $label eq $LLABEL;
&print_topic($topic->{$label}, $preprint . $label . ' ');
}
}

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.5 1998/11/05 07:27:55 jkh Exp $
# $Id: Makefile,v 1.6 1998/11/05 08:39:42 jkh Exp $
#
LIB= ficl
NOPROFILE= yes
@ -16,8 +16,8 @@ SOFTWORDS= softcore.fr jhlocal.fr marker.fr
.PATH: ${.CURDIR}/softwords
CFLAGS+= -I${.CURDIR}
softcore.c: ${SOFTWORDS} softcore.pl
(cd ${.CURDIR}/softwords; perl softcore.pl ${SOFTWORDS}) > ${.TARGET}
softcore.c: ${SOFTWORDS} softcore.awk
(cd ${.CURDIR}/softwords; cat ${SOFTWORDS} | awk -f softcore.awk) > ${.TARGET}
.include <bsd.lib.mk>

View File

@ -0,0 +1,96 @@
#!/usr/bin/awk -f
# Convert forth source files to a giant C string
# Joe Abley <jabley@patho.gen.nz>, 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";
}

View File

@ -1,86 +0,0 @@
#!/usr/bin/perl
# Convert forth source files to a giant C string
$now = localtime;
print <<EOF
/*******************************************************************
** s o f t c o r e . c
** Forth Inspired Command Language -
** Words from CORE set written in FICL
** Author: John Sadler (john_sadler\@alum.mit.edu)
** Created: 27 December 1997
** Last update: $now
*******************************************************************/
/*
** This file contains definitions that are compiled into the
** system dictionary by the first virtual machine to be created.
** Created automagically by ficl/softwords/softcore.pl
*/
#include "ficl.h"
static char softWords[] =
EOF
;
$commenting = 0;
while (<>) {
s"\n$""; # remove EOL
s"\t" "g; # replace each tab with 4 spaces
s/\"/\\\"/g; # escape quotes
next if /^\s*\\\s*$/;# toss empty comments
next if /^\s*$/; # toss empty lines
if (/^\\\s\*\*/) { # emit / ** lines as C comments
s"^\\ "";
if ($commenting == 0) {
print "/*\n";
}
$commenting = 1;
print "$_\n";
next;
}
if ($commenting == 1) {
print "*/\n";
}
$commenting = 0;
if (/^\\\s#/) { # pass commented preprocessor directives
s"^\\ "";
print "$_\n";
next;
}
next if /^\s*\\ /; # toss all other comments
s"\\\s+.*$"" ; # lop off trailing \ comments
s"\s+$" "; # remove trailing space
#
# emit all other lines as quoted string fragments
#
$out = " \"" . $_ . " \\n\"";
print "$out\n";
}
if ($commenting == 1) {
print "*/\n";
}
print <<EOF
"quit ";
void ficlCompileSoftCore(FICL_VM *pVM)
{
assert(ficlExec(pVM, softWords) != VM_ERREXIT);
}
EOF
;

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.26 1999/01/10 20:20:27 msmith Exp $
# $Id: Makefile,v 1.27 1999/01/11 05:52:28 msmith Exp $
BASE= loader
PROG= ${BASE}
@ -79,7 +79,7 @@ ${BASE}.bin: ${BASE}.sym
strip ${.TARGET}
${BASE}.help: help.common help.i386
perl ${.CURDIR}/../../common/merge_help.pl ${.ALLSRC} > ${.TARGET}
cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET}
beforeinstall:
.if exists(${DESTDIR}/boot/loader)