Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / boot / ficl / softwords / softcore.awk
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 # $FreeBSD: src/sys/boot/ficl/softwords/softcore.awk,v 1.3.2.2 2001/03/04 04:55:10 obrien Exp $
14 # $DragonFly: src/sys/boot/ficl/softwords/softcore.awk,v 1.2 2003/06/17 04:28:18 dillon Exp $
15
16 BEGIN \
17 {
18   printf "/***************************************************************\n";
19   printf "** s o f t c o r e . c\n";
20   printf "** Forth Inspired Command Language -\n";
21   printf "** Words from CORE set written in FICL\n";
22   printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n";
23   printf "** Created: 27 December 1997\n";
24   printf "** Last update: %s\n", datestamp;
25   printf "***************************************************************/\n";
26   printf "\n/*\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#include \"ficl.h\"\n";
32   printf "\nstatic char softWords[] =\n";
33
34   commenting = 0;
35 }
36
37 # some general early substitutions
38 {
39   gsub(/\t/, "    ");                   # replace each tab with 4 spaces
40   gsub(/\"/, "\\\"");                   # escape quotes
41   gsub(/\\[[:space:]]+$/, "");          # toss empty comments
42 }
43
44 # strip out empty lines
45 /^ *$/ \
46 {
47   next;
48 }
49
50 # emit / ** lines as multi-line C comments
51 /^\\[[:space:]]\*\*/ \
52 {
53   sub(/^\\[[:space:]]/, "");
54   if (commenting == 0) printf "/*\n";
55   printf "%s\n", $0;
56   commenting = 1;
57   next;
58 }
59
60 # strip blank lines
61 /^[[:space:]]*$/ \
62 {
63   next;
64 }
65
66 # function to close a comment, used later
67 function end_comments()
68 {
69   commenting = 0;
70   printf "*/\n";
71 }
72
73 # pass commented preprocessor directives
74 /^\\[[:space:]]#/ \
75 {
76   if (commenting) end_comments();
77   sub(/^\\[[:space:]]/, "");
78   printf "%s\n", $0;
79   next;
80 }
81
82 # toss all other full-line \ comments
83 /^\\/ \
84 {
85   if (commenting) end_comments();
86   next;
87 }
88
89 # lop off trailing \ comments
90 /\\[[:space:]]+/ \
91 {
92   sub(/\\[[:space:]]+.*$/, "");
93 }
94
95 # expunge ( ) comments
96 /[[:space:]]+\([[:space:]][^)]*\)/ \
97 {
98   sub(/[[:space:]]+\([[:space:]][^)]*\)/, "");
99 }
100
101 # remove leading spaces
102 /^[[:space:]]+/ \
103 {
104   sub(/^[[:space:]]+/, "");
105 }
106
107 # removing trailing spaces
108 /[[:space:]]+$/ \
109 {
110   sub(/[[:space:]]+$/, "");
111 }
112
113 # strip out empty lines again (preceding rules may have generated some)
114 /^[[:space:]]*$/ \
115 {
116   if (commenting) end_comments();
117   next;
118 }
119
120 # emit all other lines as quoted string fragments
121 {
122   if (commenting) end_comments();
123
124   printf "    \"%s \"\n", $0;
125   next;
126 }
127
128 END \
129 {
130   if (commenting) end_comments();
131   printf "    \"quit \";\n";
132   printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n";
133   printf "{\n";
134   printf "    assert(ficlExec(pVM, softWords) != VM_ERREXIT);\n";
135   printf "}\n";
136 }