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 MustNext (); |
64 str filepath = MustGetString (); |
|
65 |
65 // First ensure that the file can be opened |
66 // First ensure that the file can be opened |
66 FILE* newfile = fopen (token.chars(), "r"); |
67 FILE* newfile = fopen (filepath.chars(), "r"); |
67 if (!newfile) |
68 if (!newfile) |
68 ParserError ("couldn't open included file `%s`!", token.chars()); |
69 ParserError ("couldn't open included file `%s`!", filepath.chars()); |
69 fclose (newfile); |
70 fclose (newfile); |
70 ScriptReader* newreader = new ScriptReader (token.chars()); |
71 ScriptReader* newreader = new ScriptReader (filepath.chars()); |
71 newreader->BeginParse (w); |
72 newreader->BeginParse (w); |
72 } else if (!token.compare ("state")) { |
73 } else if (!token.compare ("state")) { |
73 MUST_TOPLEVEL |
74 MUST_TOPLEVEL |
74 |
75 |
75 MustNext (); |
76 str statename = MustGetString (); |
76 |
|
77 str statename = token; |
|
78 |
77 |
79 // State name must be a word. |
78 // State name must be a word. |
80 if (statename.first (" ") != statename.len()) |
79 if (statename.first (" ") != statename.len()) |
81 ParserError ("state name must be a single word! got `%s`", (char*)statename); |
80 ParserError ("state name must be a single word! got `%s`", (char*)statename); |
82 |
81 |
93 g_CurState = statename; |
92 g_CurState = statename; |
94 } else if (!token.compare ("event")) { |
93 } else if (!token.compare ("event")) { |
95 MUST_TOPLEVEL |
94 MUST_TOPLEVEL |
96 |
95 |
97 // Event definition |
96 // Event definition |
98 MustNext (); |
97 str evname = MustGetString (); |
99 |
98 |
100 EventDef* e = FindEventByName (token); |
99 EventDef* e = FindEventByName (evname); |
101 if (!e) |
100 if (!e) |
102 ParserError ("bad event! got `%s`\n", token.chars()); |
101 ParserError ("bad event! got `%s`\n", evname.chars()); |
103 |
102 |
104 MustNext ("{"); |
103 MustNext ("{"); |
105 |
104 |
106 g_CurMode = MODE_EVENT; |
105 g_CurMode = MODE_EVENT; |
107 |
106 |