59 |
59 |
60 void ScriptReader::BeginParse (ObjWriter* w) { |
60 void ScriptReader::BeginParse (ObjWriter* w) { |
61 while (Next()) { |
61 while (Next()) { |
62 // printf ("got token %s\n", token.chars()); |
62 // printf ("got token %s\n", token.chars()); |
63 if (!token.compare ("#include")) { |
63 if (!token.compare ("#include")) { |
64 str filepath = MustGetString (); |
64 MustString (); |
65 |
65 |
66 // First ensure that the file can be opened |
66 // First ensure that the file can be opened |
67 FILE* newfile = fopen (filepath.chars(), "r"); |
67 FILE* newfile = fopen (token.chars(), "r"); |
68 if (!newfile) |
68 if (!newfile) |
69 ParserError ("couldn't open included file `%s`!", filepath.chars()); |
69 ParserError ("couldn't open included file `%s`!", token.chars()); |
70 fclose (newfile); |
70 fclose (newfile); |
71 ScriptReader* newreader = new ScriptReader (filepath.chars()); |
71 ScriptReader* newreader = new ScriptReader (token.chars()); |
72 newreader->BeginParse (w); |
72 newreader->BeginParse (w); |
73 } else if (!token.compare ("state")) { |
73 } else if (!token.compare ("state")) { |
74 MUST_TOPLEVEL |
74 MUST_TOPLEVEL |
75 |
75 |
76 str statename = MustGetString (); |
76 MustString (); |
77 |
77 |
78 // State name must be a word. |
78 // State name must be a word. |
79 if (statename.first (" ") != statename.len()) |
79 if (token.first (" ") != token.len()) |
80 ParserError ("state name must be a single word! got `%s`", (char*)statename); |
80 ParserError ("state name must be a single word! got `%s`", token.chars()); |
81 |
81 |
82 // Must end in a colon |
82 // Must end in a colon |
83 MustNext (":"); |
83 MustNext (":"); |
84 |
84 |
85 w->Write (DH_STATENAME); |
85 w->Write (DH_STATENAME); |
86 w->Write (statename.len()); |
86 w->Write (token.len()); |
87 w->WriteString (statename); |
87 w->WriteString (token); |
88 w->Write (DH_STATEIDX); |
88 w->Write (DH_STATEIDX); |
89 w->Write (g_NumStates); |
89 w->Write (g_NumStates); |
90 |
90 |
91 g_NumStates++; |
91 g_NumStates++; |
92 g_CurState = statename; |
92 g_CurState = token; |
93 } else if (!token.compare ("event")) { |
93 } else if (!token.compare ("event")) { |
94 MUST_TOPLEVEL |
94 MUST_TOPLEVEL |
95 |
95 |
96 // Event definition |
96 // Event definition |
97 str evname = MustGetString (); |
97 MustString (); |
98 |
98 |
99 EventDef* e = FindEventByName (evname); |
99 EventDef* e = FindEventByName (token); |
100 if (!e) |
100 if (!e) |
101 ParserError ("bad event! got `%s`\n", evname.chars()); |
101 ParserError ("bad event! got `%s`\n", token.chars()); |
102 |
102 |
103 MustNext ("{"); |
103 MustNext ("{"); |
104 |
104 |
105 g_CurMode = MODE_EVENT; |
105 g_CurMode = MODE_EVENT; |
106 |
106 |