4 cc9bbf61 2020-04-01 op if (pass == "h") {
5 cc9bbf61 2020-04-01 op print "#ifndef OBJECT_H";
6 cc9bbf61 2020-04-01 op print "#define OBJECT_H";
9 cc9bbf61 2020-04-01 op if (pass == "c1") {
10 cc9bbf61 2020-04-01 op print "#include \"adventure.h\"\n";
12 cc9bbf61 2020-04-01 op print "static int always_true(struct object *o) { return 1; }";
15 cc9bbf61 2020-04-01 op if (pass == "c2") {
16 cc9bbf61 2020-04-01 op print "\nstruct object objs[] = {";
21 cc9bbf61 2020-04-01 op output_record(",");
23 cc9bbf61 2020-04-01 op prop["condition"] = "always_true";
24 cc9bbf61 2020-04-01 op prop["description"] = "NULL";
25 cc9bbf61 2020-04-01 op prop["tags"] = "";
26 cc9bbf61 2020-04-01 op prop["location"] = "NULL";
27 cc9bbf61 2020-04-01 op prop["destination"] = "NULL";
28 cc9bbf61 2020-04-01 op prop["prospect"] = "";
29 cc9bbf61 2020-04-01 op prop["details"] = "\"You see nothing special.\"";
30 cc9bbf61 2020-04-01 op prop["contents"] = "\"You see\"";
31 cc9bbf61 2020-04-01 op prop["text_go"] = "\"You can't get any closer than this.\"";
32 cc9bbf61 2020-04-01 op prop["weight"] = "99";
33 cc9bbf61 2020-04-01 op prop["capacity"] = "9999";
34 cc9bbf61 2020-04-01 op prop["health"] = "0";
35 cc9bbf61 2020-04-01 op prop["open"] = "cannot_be_opened";
36 cc9bbf61 2020-04-01 op prop["close"] = "cannot_be_closed";
37 cc9bbf61 2020-04-01 op prop["lock"] = "cannot_be_locked";
38 cc9bbf61 2020-04-01 op prop["unlock"] = "cannot_be_unlocked";
41 cc9bbf61 2020-04-01 op obj && /^[ \t]+[a-z]/ {
44 cc9bbf61 2020-04-01 op if (name in prop) {
45 cc9bbf61 2020-04-01 op prop[name] = $0;
46 cc9bbf61 2020-04-01 op if (/^[ \t]*\{/) {
47 cc9bbf61 2020-04-01 op prop[name] = name count;
48 cc9bbf61 2020-04-01 op if (pass == "c1")
49 cc9bbf61 2020-04-01 op print "static int " prop[name] "(struct object *obj) " $0;
51 cc9bbf61 2020-04-01 op } else if (pass == "c2") {
52 cc9bbf61 2020-04-01 op print "#error \"" FILENAME " line " NR ": unknown attribute '" name "'\"";
56 cc9bbf61 2020-04-01 op !obj && pass == (/^#include/ ? "c1" : "h") {
61 cc9bbf61 2020-04-01 op output_record("\n};");
62 cc9bbf61 2020-04-01 op if (pass == "h") {
64 cc9bbf61 2020-04-01 op print "#define obj_end\t(objs + " count ")";
65 cc9bbf61 2020-04-01 op print "#define valid_obj(obj)\t" \
66 cc9bbf61 2020-04-01 op "((obj) != NULL && (*(obj)->condition)((obj)))";
67 cc9bbf61 2020-04-01 op print "#define foreach_obj(obj)\t" \
68 cc9bbf61 2020-04-01 op "for (obj = objs; obj < obj_end; ++obj) if (valid_obj(obj))";
70 cc9bbf61 2020-04-01 op print "#endif";
74 cc9bbf61 2020-04-01 op function output_record(separator) {
76 cc9bbf61 2020-04-01 op if (pass == "h") {
77 cc9bbf61 2020-04-01 op print "#define " obj "\t(objs + " count ")";
78 cc9bbf61 2020-04-01 op } else if (pass == "c1") {
79 cc9bbf61 2020-04-01 op print "static const char *tags" count "[] = {" prop["tags"] ", NULL};";
80 cc9bbf61 2020-04-01 op } else if (pass == "c2") {
81 cc9bbf61 2020-04-01 op print "\t{\t/* " count " = " obj " */";
82 cc9bbf61 2020-04-01 op print "\t\t" prop["condition"] ",";
83 cc9bbf61 2020-04-01 op print "\t\t" prop["description"] ",";
84 cc9bbf61 2020-04-01 op print "\t\ttags" count ",";
85 cc9bbf61 2020-04-01 op print "\t\t" prop["location"] ",";
86 cc9bbf61 2020-04-01 op print "\t\t" prop["destination"] ",";
87 cc9bbf61 2020-04-01 op print "\t\t" prop[prop["prospect"] ? "prospect" : "destination"] ",";
88 cc9bbf61 2020-04-01 op print "\t\t" prop["details"] ",";
89 cc9bbf61 2020-04-01 op print "\t\t" prop["contents"] ",";
90 cc9bbf61 2020-04-01 op print "\t\t" prop["text_go"] ",";
91 cc9bbf61 2020-04-01 op print "\t\t" prop["weight"] ",";
92 cc9bbf61 2020-04-01 op print "\t\t" prop["capacity"] ",";
93 cc9bbf61 2020-04-01 op print "\t\t" prop["health"] ",";
94 cc9bbf61 2020-04-01 op print "\t\t" prop["open"] ",";
95 cc9bbf61 2020-04-01 op print "\t\t" prop["close"] ",";
96 cc9bbf61 2020-04-01 op print "\t\t" prop["lock"] ",";
97 cc9bbf61 2020-04-01 op print "\t\t" prop["unlock"] ",";
98 cc9bbf61 2020-04-01 op print "\t}" separator;