softcore.awk (51789) | softcore.awk (60962) |
---|---|
1#!/usr/bin/awk -f | 1#!/usr/bin/awk -f |
2# |
|
2# Convert forth source files to a giant C string | 3# Convert forth source files to a giant C string |
4# |
|
3# Joe Abley <jabley@patho.gen.nz>, 12 January 1999 | 5# Joe Abley <jabley@patho.gen.nz>, 12 January 1999 |
4# $FreeBSD: head/sys/boot/ficl/softwords/softcore.awk 51789 1999-09-29 10:58:43Z dcs $ | 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: head/sys/boot/ficl/softwords/softcore.awk 60962 2000-05-26 22:58:10Z dcs $ |
5 6BEGIN \ 7{ 8 printf "/***************************************************************\n"; 9 printf "** s o f t c o r e . c\n"; 10 printf "** Forth Inspired Command Language -\n"; 11 printf "** Words from CORE set written in FICL\n"; 12 printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n"; --- 8 unchanged lines hidden (view full) --- 21 printf "\n#include \"ficl.h\"\n"; 22 printf "\nstatic char softWords[] =\n"; 23 24 commenting = 0; 25} 26 27# some general early substitutions 28{ | 14 15BEGIN \ 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"; --- 8 unchanged lines hidden (view full) --- 30 printf "\n#include \"ficl.h\"\n"; 31 printf "\nstatic char softWords[] =\n"; 32 33 commenting = 0; 34} 35 36# some general early substitutions 37{ |
29 gsub("\t", " "); # replace each tab with 4 spaces 30 gsub("\"", "\\\""); # escape quotes 31 gsub("\\\\[[:space:]]+$", ""); # toss empty comments | 38 gsub(/\t/, " "); # replace each tab with 4 spaces 39 gsub(/\"/, "\\\""); # escape quotes 40 gsub(/\\[[:space:]]+$/, ""); # toss empty comments |
32} 33 34# strip out empty lines 35/^ *$/ \ 36{ 37 next; 38} 39 40# emit / ** lines as multi-line C comments | 41} 42 43# strip out empty lines 44/^ *$/ \ 45{ 46 next; 47} 48 49# emit / ** lines as multi-line C comments |
41/^\\[[:space:]]\*\*/ && (commenting == 0) \ | 50/^\\[[:space:]]\*\*/ \ |
42{ | 51{ |
43 sub("^\\\\[[:space:]]", ""); 44 printf "/*\n%s\n", $0; | 52 sub(/^\\[[:space:]]/, ""); 53 if (commenting == 0) printf "/*\n"; 54 printf "%s\n", $0; |
45 commenting = 1; 46 next; 47} 48 | 55 commenting = 1; 56 next; 57} 58 |
49/^\\[[:space:]]\*\*/ \ | 59# strip blank lines 60/^[[:space:]]*$/ \ |
50{ | 61{ |
51 sub("^\\\\[[:space:]]", ""); 52 printf "%s\n", $0; | |
53 next; 54} 55 56# function to close a comment, used later 57function end_comments() 58{ 59 commenting = 0; 60 printf "*/\n"; 61} 62 63# pass commented preprocessor directives 64/^\\[[:space:]]#/ \ 65{ 66 if (commenting) end_comments(); | 62 next; 63} 64 65# function to close a comment, used later 66function end_comments() 67{ 68 commenting = 0; 69 printf "*/\n"; 70} 71 72# pass commented preprocessor directives 73/^\\[[:space:]]#/ \ 74{ 75 if (commenting) end_comments(); |
67 sub("^\\\\[[:space:]]", ""); | 76 sub(/^\\[[:space:]]/, ""); |
68 printf "%s\n", $0; 69 next; 70} 71 | 77 printf "%s\n", $0; 78 next; 79} 80 |
72# toss all other full-line comments | 81# toss all other full-line \ comments |
73/^\\/ \ 74{ 75 if (commenting) end_comments(); 76 next; 77} 78 | 82/^\\/ \ 83{ 84 if (commenting) end_comments(); 85 next; 86} 87 |
88# lop off trailing \ comments 89/\\[[:space:]]+/ \ 90{ 91 sub(/\\[[:space:]]+.*$/, ""); 92} 93 94# expunge ( ) comments 95/[[:space:]]+\([[:space:]][^)]*\)/ \ 96{ 97 sub(/[[:space:]]+\([[:space:]][^)]*\)/, ""); 98} 99 100# remove leading spaces 101/^[[:space:]]+/ \ 102{ 103 sub(/^[[:space:]]+/, ""); 104} 105 106# removing trailing spaces 107/[[:space:]]+$/ \ 108{ 109 sub(/[[:space:]]+$/, ""); 110} 111 112# strip out empty lines again (preceding rules may have generated some) 113/^[[:space:]]*$/ \ 114{ 115 if (commenting) end_comments(); 116 next; 117} 118 |
|
79# emit all other lines as quoted string fragments 80{ 81 if (commenting) end_comments(); 82 | 119# emit all other lines as quoted string fragments 120{ 121 if (commenting) end_comments(); 122 |
83 sub("\\\\[[:space:]]+.*$", ""); # lop off trailing \ comments 84 sub("[[:space:]]+$", ""); # remove trailing spaces 85 printf " \"%s \\n\"\n", $0; | 123 printf " \"%s \"\n", $0; |
86 next; 87} 88 89END \ 90{ 91 if (commenting) end_comments(); 92 printf " \"quit \";\n"; 93 printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n"; 94 printf "{\n"; 95 printf " assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n"; 96 printf "}\n"; 97} | 124 next; 125} 126 127END \ 128{ 129 if (commenting) end_comments(); 130 printf " \"quit \";\n"; 131 printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n"; 132 printf "{\n"; 133 printf " assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n"; 134 printf "}\n"; 135} |