diff options
author | dcs <dcs@FreeBSD.org> | 2000-05-26 22:58:10 +0000 |
---|---|---|
committer | dcs <dcs@FreeBSD.org> | 2000-05-26 22:58:10 +0000 |
commit | 50900cd7f67cc1915b894a9632b3a53b0e36c424 (patch) | |
tree | 287266c3896e6330b8009f01cb5f100b116f3738 /sys/boot/ficl/softwords | |
parent | fe693a0d08f8552099d72e5328c6dce58e9f7635 (diff) | |
download | FreeBSD-src-50900cd7f67cc1915b894a9632b3a53b0e36c424.zip FreeBSD-src-50900cd7f67cc1915b894a9632b3a53b0e36c424.tar.gz |
Strip spaces and comments more agressively.
Diffstat (limited to 'sys/boot/ficl/softwords')
-rw-r--r-- | sys/boot/ficl/softwords/softcore.awk | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/sys/boot/ficl/softwords/softcore.awk b/sys/boot/ficl/softwords/softcore.awk index f882a56..7faa146 100644 --- a/sys/boot/ficl/softwords/softcore.awk +++ b/sys/boot/ficl/softwords/softcore.awk @@ -1,6 +1,15 @@ #!/usr/bin/awk -f +# # Convert forth source files to a giant C string +# # Joe Abley <jabley@patho.gen.nz>, 12 January 1999 +# +# 02-oct-1999: Cleaned up awk slightly; added some additional logic +# suggested by dcs to compress the stored forth program. +# +# Note! This script uses strftime() which is a gawk-ism, and the +# POSIX [[:space:]] character class. +# # $FreeBSD$ BEGIN \ @@ -26,9 +35,9 @@ BEGIN \ # some general early substitutions { - gsub("\t", " "); # replace each tab with 4 spaces - gsub("\"", "\\\""); # escape quotes - gsub("\\\\[[:space:]]+$", ""); # toss empty comments + gsub(/\t/, " "); # replace each tab with 4 spaces + gsub(/\"/, "\\\""); # escape quotes + gsub(/\\[[:space:]]+$/, ""); # toss empty comments } # strip out empty lines @@ -38,18 +47,18 @@ BEGIN \ } # emit / ** lines as multi-line C comments -/^\\[[:space:]]\*\*/ && (commenting == 0) \ +/^\\[[:space:]]\*\*/ \ { - sub("^\\\\[[:space:]]", ""); - printf "/*\n%s\n", $0; + sub(/^\\[[:space:]]/, ""); + if (commenting == 0) printf "/*\n"; + printf "%s\n", $0; commenting = 1; next; } -/^\\[[:space:]]\*\*/ \ +# strip blank lines +/^[[:space:]]*$/ \ { - sub("^\\\\[[:space:]]", ""); - printf "%s\n", $0; next; } @@ -64,25 +73,54 @@ function end_comments() /^\\[[:space:]]#/ \ { if (commenting) end_comments(); - sub("^\\\\[[:space:]]", ""); + sub(/^\\[[:space:]]/, ""); printf "%s\n", $0; next; } -# toss all other full-line comments +# toss all other full-line \ comments /^\\/ \ { if (commenting) end_comments(); next; } +# lop off trailing \ comments +/\\[[:space:]]+/ \ +{ + sub(/\\[[:space:]]+.*$/, ""); +} + +# expunge ( ) comments +/[[:space:]]+\([[:space:]][^)]*\)/ \ +{ + sub(/[[:space:]]+\([[:space:]][^)]*\)/, ""); +} + +# remove leading spaces +/^[[:space:]]+/ \ +{ + sub(/^[[:space:]]+/, ""); +} + +# removing trailing spaces +/[[:space:]]+$/ \ +{ + sub(/[[:space:]]+$/, ""); +} + +# strip out empty lines again (preceding rules may have generated some) +/^[[:space:]]*$/ \ +{ + 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; + printf " \"%s \"\n", $0; next; } |