aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/jacl/types.h
blob: 3cfb2afde00e8f589c0b9d0db04ad4cdae1ff80e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "glk/jacl/constants.h"
#include "common/file.h"

namespace Glk {
namespace JACL {

#define DIR_SEPARATOR '/'
#define DATA_DIR "data/"
#define TEMP_DIR "temp/"
#define INCLUDE_DIR "include/"

// THIS STRUCTURE CONTAINS ALL THE INFORMATION THAT NEEDS TO BE
// SAVED IN ORDER TO CALL parse() RECURSIVELY
struct proxy_type {
	int             object_pointers[4];             // NOUN1 -> NOUN4
	int             integer[MAX_WORDS];             // THE COMANDS INTEGERS
	char            text[MAX_WORDS][256];           // THE COMANDS STRINGS
	char            command[MAX_WORDS][256];        // THE WHOLE COMMAND
	int             object_list[4][MAX_OBJECTS];    // THE RESOLVED OBJECTS
	int             list_size[4];                   // THE SIZE OF THE ABOVE LISTS
	int             max_size[4];                    // THE LAST USED INDEX OF THE ABOVE LISTS
	int             start_of_this_command;          // PREPARSE STATE
	int             start_of_last_command;          // PREPARSE STATE
	int             integercount;                   // THE NUMBER OF INTEGERS SAVED
	int             textcount;                      // THE NUMBER OF STRINGS SAVED
	int             commandcount;                   // THE NUMBER OF WORDS IN COMMAND
	int             last_exact;                     // WORD POINTER FOR MATCH
	int             after_from;                     // WORD POINTER FOR FROM WORD
};

struct stack_type {
	Common::SeekableReadStream *infile;
	Common::WriteStream *outfile;
	int             arguments[MAX_WORDS];
	char            str_arguments[MAX_WORDS][256];
	char            text_buffer[1024];
	char            called_name[1024];
	char            override[84];
	char            scope_criterion[24];
	char            default_function[84];
	char            *word[MAX_WORDS];
	int             quoted[MAX_WORDS];
	int             wp;
	int             argcount;
	int             *loop_integer;
	int             *select_integer;
	int             criterion_value;
	int             criterion_type;
	int             criterion_negate;
	int             current_level;
	int             execution_level;
#ifdef GLK
	int             top_of_loop;
	int         top_of_select;
	int         top_of_while;
	int         top_of_iterate;
	int         top_of_update;
	int         top_of_do_loop;
	int          address;
#else
	long            top_of_loop;
	long            top_of_select;
	long            top_of_while;
	long            top_of_iterate;
	long            top_of_update;
	long            top_of_do_loop;
	long            address;
#endif
	struct function_type *function;
};

struct object_type {
	char            label[44];
	char            article[12];
	char            definite[12];
	struct          name_type *first_name;
	struct          name_type *first_plural;
	char            inventory[44];
	char            described[84];
	int             user_attributes;
	int             user_attributes_backup;
	int             attributes;
	int             attributes_backup;
	int             integer[16];
	int             integer_backup[16];
	int             nosave;
};

struct integer_type {
	char            name[44];
	int             value;
	int             value_backup;
	struct integer_type *next_integer;
};

struct cinteger_type {
	char            name[44];
	int             value;
	struct cinteger_type *next_cinteger;
};

struct attribute_type {
	char            name[44];
	int             value;
	struct attribute_type *next_attribute;
};

struct string_type {
	char            name[44];
	char            value[256];
	struct string_type *next_string;
};

struct function_type {
	char            name[84];
#ifdef GLK
	glui32          position;
#else
	long            position;
#endif

	int             self;
	int             call_count;
	int             call_count_backup;
	struct function_type *next_function;
};

struct command_type {
	char            word[44];
	struct command_type *next;
};

#ifdef GLK
struct window_type {
	char            name[44];
	winid_t         glk_window;
	glui32          glk_type;
	struct window_type *next_window;
};
#endif

struct word_type {
	char            word[44];
	struct word_type *first_child;
	struct word_type *next_sibling;
};

struct synonym_type {
	char            original[44];
	char            standard[44];
	struct synonym_type *next_synonym;
};

struct name_type {
	char            name[44];
	struct name_type *next_name;
};

struct filter_type {
	char            word[44];
	struct filter_type *next_filter;
};

#ifndef GLK
struct parameter_type {
	char            name[44];
	char            container[44];
	int             low;
	int             high;
	struct parameter_type *next_parameter;
};
#endif

class File : public Common::File {
public:
	static File *openForReading(const Common::String &name) {
		File *f = new File();
		if (f->open(name))
			return f;

		delete f;
		return nullptr;
	}

	static Common::WriteStream *openForWriting(const Common::String &name) {
		Common::DumpFile *df = new Common::DumpFile();
		if (df->open(name))
			return df;

		delete df;
		return nullptr;
	}
public:
	File() : Common::File() {}
	File(const Common::String &name) {
		Common::File::open(name);
		assert(isOpen());
	}
};

} // End of namespace JACL
} // End of namespace Glk