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