aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/tads/tads2/tads2.h
blob: 247292984086257a489da527dcde99f5362a46f6 (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
/* 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.
 *
 */

#ifndef GLK_TADS_TADS2
#define GLK_TADS_TADS2

#include "glk/tads/tads2/os.h"
#include "glk/tads/tads2/ler.h"

namespace Glk {
namespace TADS {
namespace TADS2 {

/**
 * map a native character (read externally) into an internal character
 */
#define cmap_n2i(c) (G_cmap_input[(unsigned char)(c)])

/**
 * map an internal character into a native character (for display)
 */
#define cmap_i2n(c) (G_cmap_output[(unsigned char)(c)])

/**
 * the full name (for display purposes) of the loaded character set
 */
#define CMAP_LDESC_MAX_LEN  40

/**
 * Maximum expansion for an HTML entity mapping 
 */
#define CMAP_MAX_ENTITY_EXPANSION  50


/**
 * TADS 2 game interpreter
 */
class TADS2 : public OS {
private:
	// STUBS
	void os_printz(const Common::String &s) {}
	void tio_set_html_expansion(unsigned int html_char_val,
		const char *expansion, size_t expansion_len) {}
private:
	/**
	 * \defgroup cmap
	 * @{
	 */

	/**
	 * flag: true -> a character set has been explicitly loaded, so we
	 * should ignore any game character set setting 
	 */
	bool S_cmap_loaded;

	/**
	 * input-mapping table - for native character 'n', cmap_input[n] yields
	 * the internal character code 
	 */
	unsigned char G_cmap_input[256];

	/**
	 * output-mapping table - for internal character 'n', cmap_output[n]
	 * yields the output character code 
	 */
	unsigned char G_cmap_output[256];

	/**
	 * the ID of the loaded character set
	 */
	char G_cmap_id[5];

	/**
	 * the full name (for display purposes) of the loaded character set
	 */
	char G_cmap_ldesc[CMAP_LDESC_MAX_LEN + 1];

	/**@}*/
private:
	/**
	 * \defgroup trd
	 * @{
	 */

	void trdmain1(errcxdef *errctx);

	/**
	 * printf-style formatting
	 */
	void trdptf(const char *fmt, ...);

	/**@}*/

	/**
	 * \defgroup cmap
	 * @{
	 */

	/**
	 * Initialize the default character mappings.  If no mapping file is to
	 * be read, this function will establish identify mappings that leave
	 * characters untranslated. 
	 */
	void cmap_init_default();

	/**
	 * Load a character map file.  Returns zero on success, non-zero on
	 * failure.  If filename is null, we'll use the default mapping.
	 */
	int cmap_load(const char *filename);

	/**
	 * Turn off character translation.  This overrides any game character
	 * set that we find and simply uses the default translation. 
	 */
	void cmap_override(void);

	/**
	 * Set the game's internal character set.  This should be called when a
	 * game is loaded, and the game specifies an internal character set.  If
	 * there is no character map file explicitly loaded, we will attempt to
	 * load a character mapping file that maps this character set to the
	 * current native character set.  Signals an error on failure.  This
	 * routine will succeed (without doing anything) if a character set has
	 * already been explicitly loaded, since an explicitly-loaded character
	 * set overrides the automatic character set selection that we attempt
	 * when loading a game.
	 * 
	 * argv0 must be provided so that we know where to look for our mapping
	 * file on systems where mapping files are stored in the same directory
	 * as the TADS executables.  
	 */
	void cmap_set_game_charset(errcxdef *errctx, const char *internal_id,
		const char *internal_ldesc, const char *argv0);

	/**
	 * Internal routine to load a character map from a file 
	 */
	int cmap_load_internal(const char *filename);

	/**@}*/
public:
	/**
	 * Constructor
	 */
	TADS2(OSystem *syst, const GlkGameDescription &gameDesc);

	/**
	 * Execute the game
	 */
	virtual void runGame() override;

	/**
	 * Returns the running interpreter type
	 */
	virtual InterpreterType getInterpreterType() const override { return INTERPRETER_TADS2; }
};

typedef TADS2 appctxdef;

} // End of namespace TADS2
} // End of namespace TADS
} // End of namespace Glk

#endif