]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/boot/ficl/softwords/softcore.awk
This commit was generated by cvs2svn to compensate for changes in r54820,
[FreeBSD/FreeBSD.git] / sys / boot / ficl / softwords / softcore.awk
1 #!/usr/bin/awk -f
2 # Convert forth source files to a giant C string
3 # Joe Abley <jabley@patho.gen.nz>, 12 January 1999
4 # $FreeBSD$
5
6 BEGIN \
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";
13   printf "** Created: 27 December 1997\n";
14   printf "** Last update: %s\n", strftime();
15   printf "***************************************************************/\n";
16   printf "\n/*\n";
17   printf "** This file contains definitions that are compiled into the\n";
18   printf "** system dictionary by the first virtual machine to be created.\n";
19   printf "** Created automagically by ficl/softwords/softcore.awk\n";
20   printf "*/\n";
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 {
29   gsub("\t", "    ");                   # replace each tab with 4 spaces
30   gsub("\"", "\\\"");                   # escape quotes
31   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 /^\\[[:space:]]\*\*/ && (commenting == 0) \
42 {
43   sub("^\\\\[[:space:]]", "");
44   printf "/*\n%s\n", $0;
45   commenting = 1;
46   next;
47 }
48
49 /^\\[[:space:]]\*\*/ \
50 {
51   sub("^\\\\[[:space:]]", "");
52   printf "%s\n", $0;
53   next;
54 }
55
56 # function to close a comment, used later
57 function end_comments()
58 {
59   commenting = 0;
60   printf "*/\n";
61 }
62
63 # pass commented preprocessor directives
64 /^\\[[:space:]]#/ \
65 {
66   if (commenting) end_comments();
67   sub("^\\\\[[:space:]]", "");
68   printf "%s\n", $0;
69   next;
70 }
71
72 # toss all other full-line comments
73 /^\\/ \
74 {
75   if (commenting) end_comments();
76   next;
77 }
78
79 # emit all other lines as quoted string fragments
80 {
81   if (commenting) end_comments();
82
83   sub("\\\\[[:space:]]+.*$", "");       # lop off trailing \ comments
84   sub("[[:space:]]+$", "");             # remove trailing spaces
85   printf "    \"%s \\n\"\n", $0;
86   next;
87 }
88
89 END \
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 }