]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/boot/ficl/softwords/softcore.awk
This commit was generated by cvs2svn to compensate for changes in r48907,
[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
5 BEGIN \
6 {
7   printf "/***************************************************************\n";
8   printf "** s o f t c o r e . c\n";
9   printf "** Forth Inspired Command Language -\n";
10   printf "** Words from CORE set written in FICL\n";
11   printf "** Author: John Sadler (john_sadler@alum.mit.edu)\n";
12   printf "** Created: 27 December 1997\n";
13   printf "** Last update: %s\n", strftime();
14   printf "***************************************************************/\n";
15   printf "\n/*\n";
16   printf "** This file contains definitions that are compiled into the\n";
17   printf "** system dictionary by the first virtual machine to be created.\n";
18   printf "** Created automagically by ficl/softwords/softcore.awk\n";
19   printf "*/\n";
20   printf "\n#include \"ficl.h\"\n";
21   printf "\nstatic char softWords[] =\n";
22
23   commenting = 0;
24 }
25
26 # some general early substitutions
27 {
28   gsub("\t", "    ");                   # replace each tab with 4 spaces
29   gsub("\"", "\\\"");                   # escape quotes
30   gsub("\\\\[[:space:]]+$", "");        # toss empty comments
31 }
32
33 # strip out empty lines
34 /^ *$/ \
35 {
36   next;
37 }
38
39 # emit / ** lines as multi-line C comments
40 /^\\[[:space:]]\*\*/ && (commenting == 0) \
41 {
42   sub("^\\\\[[:space:]]", "");
43   printf "/*\n%s\n", $0;
44   commenting = 1;
45   next;
46 }
47
48 /^\\[[:space:]]\*\*/ \
49 {
50   sub("^\\\\[[:space:]]", "");
51   printf "%s\n", $0;
52   next;
53 }
54
55 # function to close a comment, used later
56 function end_comments()
57 {
58   commenting = 0;
59   printf "*/\n";
60 }
61
62 # pass commented preprocessor directives
63 /^\\[[:space:]]#/ \
64 {
65   if (commenting) end_comments();
66   sub("^\\\\[[:space:]]", "");
67   printf "%s\n", $0;
68   next;
69 }
70
71 # toss all other full-line comments
72 /^\\/ \
73 {
74   if (commenting) end_comments();
75   next;
76 }
77
78 # emit all other lines as quoted string fragments
79 {
80   if (commenting) end_comments();
81
82   sub("\\\\[[:space:]]+.*$", "");       # lop off trailing \ comments
83   sub("[[:space:]]+$", "");             # remove trailing spaces
84   printf "    \"%s \\n\"\n", $0;
85   next;
86 }
87
88 END \
89 {
90   if (commenting) end_comments();
91   printf "    \"quit \";\n";
92   printf "\n\nvoid ficlCompileSoftCore(FICL_VM *pVM)\n";
93   printf "{\n";
94   printf "    assert(ficlExec(pVM, softWords, -1) != VM_ERREXIT);\n";
95   printf "}\n";
96 }