4 #include <glib-object.h>
6 #include <glib/gi18n-lib.h>
7 #include "chimara-if.h"
8 #include "chimara-glk.h"
9 #include "chimara-glk-private.h"
10 #include "chimara-marshallers.h"
15 * @short_description: Widget which plays an interactive fiction game
16 * @stability: Unstable
17 * @include: libchimara/chimara-if.h
19 * The #ChimaraIF widget, given an interactive fiction game file to run, selects
20 * an appropriate interpreter plugin and runs it. Interpreter options are set by
21 * setting properties on the widget.
23 * Using it in a GTK program is similar to using #ChimaraGlk (which see).
24 * Threads must be initialized before using #ChimaraIF and the call to
25 * gtk_main() must be bracketed between gdk_threads_enter() and
26 * gdk_threads_leave(). Use chimara_if_run_game() to start playing an
27 * interactive fiction game.
30 static gboolean supported_formats[CHIMARA_IF_NUM_FORMATS][CHIMARA_IF_NUM_INTERPRETERS] = {
31 /* Frotz Nitfol Glulxe Git */
32 { TRUE, TRUE, FALSE, FALSE }, /* Z5 */
33 { TRUE, TRUE, FALSE, FALSE }, /* Z6 */
34 { TRUE, TRUE, FALSE, FALSE }, /* Z8 */
35 { TRUE, TRUE, FALSE, FALSE }, /* Zblorb */
36 { FALSE, FALSE, TRUE, TRUE }, /* Glulx */
37 { FALSE, FALSE, TRUE, TRUE } /* Gblorb */
39 static gchar *format_names[CHIMARA_IF_NUM_FORMATS] = {
40 N_("Z-code version 5"),
41 N_("Z-code version 6"),
42 N_("Z-code version 8"),
47 static gchar *interpreter_names[CHIMARA_IF_NUM_INTERPRETERS] = {
48 N_("Frotz"), N_("Nitfol"), N_("Glulxe"), N_("Git")
50 static gchar *plugin_names[CHIMARA_IF_NUM_INTERPRETERS] = {
51 "frotz", "nitfol", "glulxe", "git"
54 typedef enum _ChimaraIFFlags {
55 CHIMARA_IF_PIRACY_MODE = 1 << 0,
56 CHIMARA_IF_TANDY_BIT = 1 << 1,
57 CHIMARA_IF_EXPAND_ABBREVIATIONS = 1 << 2,
58 CHIMARA_IF_IGNORE_ERRORS = 1 << 3,
59 CHIMARA_IF_TYPO_CORRECTION = 1 << 4
62 typedef struct _ChimaraIFPrivate {
63 ChimaraIFInterpreter preferred_interpreter[CHIMARA_IF_NUM_FORMATS];
64 ChimaraIFFormat format;
65 ChimaraIFInterpreter interpreter;
67 ChimaraIFZmachineVersion interpreter_number;
69 gboolean random_seed_set;
70 /* Holding buffers for input and response */
75 #define CHIMARA_IF_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), CHIMARA_TYPE_IF, ChimaraIFPrivate))
76 #define CHIMARA_IF_USE_PRIVATE(o, n) ChimaraIFPrivate *n = CHIMARA_IF_PRIVATE(o)
82 PROP_EXPAND_ABBREVIATIONS,
85 PROP_INTERPRETER_NUMBER,
95 static guint chimara_if_signals[LAST_SIGNAL] = { 0 };
97 G_DEFINE_TYPE(ChimaraIF, chimara_if, CHIMARA_TYPE_GLK);
100 chimara_if_waiting(ChimaraGlk *glk)
102 CHIMARA_IF_USE_PRIVATE(glk, priv);
104 gchar *response = g_string_free(priv->response, FALSE);
105 priv->response = g_string_new("");
107 g_signal_emit_by_name(glk, "command", priv->input, response);
115 chimara_if_stopped(ChimaraGlk *glk)
117 CHIMARA_IF_USE_PRIVATE(glk, priv);
119 if(priv->input || priv->response->len > 0)
120 chimara_if_waiting(glk); /* Send one last command signal */
122 priv->format = CHIMARA_IF_FORMAT_NONE;
123 priv->interpreter = CHIMARA_IF_INTERPRETER_NONE;
127 chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, gchar *input)
129 CHIMARA_IF_USE_PRIVATE(glk, priv);
130 g_assert(priv->input == NULL);
131 priv->input = g_strdup(input);
135 chimara_if_text_buffer_output(ChimaraGlk *glk, guint32 win_rock, gchar *output)
137 CHIMARA_IF_USE_PRIVATE(glk, priv);
138 g_string_append(priv->response, output);
142 chimara_if_init(ChimaraIF *self)
144 CHIMARA_IF_USE_PRIVATE(self, priv);
145 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z5] = CHIMARA_IF_INTERPRETER_FROTZ;
146 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z6] = CHIMARA_IF_INTERPRETER_FROTZ;
147 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z8] = CHIMARA_IF_INTERPRETER_FROTZ;
148 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z_BLORB] = CHIMARA_IF_INTERPRETER_FROTZ;
149 priv->preferred_interpreter[CHIMARA_IF_FORMAT_GLULX] = CHIMARA_IF_INTERPRETER_GLULXE;
150 priv->preferred_interpreter[CHIMARA_IF_FORMAT_GLULX_BLORB] = CHIMARA_IF_INTERPRETER_GLULXE;
151 priv->format = CHIMARA_IF_FORMAT_NONE;
152 priv->interpreter = CHIMARA_IF_INTERPRETER_NONE;
153 priv->flags = CHIMARA_IF_TYPO_CORRECTION;
154 priv->interpreter_number = CHIMARA_IF_ZMACHINE_DEFAULT;
155 priv->random_seed_set = FALSE;
157 priv->response = g_string_new("");
159 /* Connect to signals of ChimaraGlk parent */
160 g_signal_connect(self, "stopped", G_CALLBACK(chimara_if_stopped), NULL);
161 g_signal_connect(self, "waiting", G_CALLBACK(chimara_if_waiting), NULL);
162 g_signal_connect(self, "line-input", G_CALLBACK(chimara_if_line_input), NULL);
163 g_signal_connect(self, "text-buffer-output", G_CALLBACK(chimara_if_text_buffer_output), NULL);
166 #define PROCESS_FLAG(flags, flag, val) (flags) = (val)? (flags) | (flag) : (flags) & ~(flag)
169 chimara_if_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
171 CHIMARA_IF_USE_PRIVATE(object, priv);
174 case PROP_PIRACY_MODE:
175 PROCESS_FLAG(priv->flags, CHIMARA_IF_PIRACY_MODE, g_value_get_boolean(value));
176 g_object_notify(object, "piracy-mode");
179 PROCESS_FLAG(priv->flags, CHIMARA_IF_TANDY_BIT, g_value_get_boolean(value));
180 g_object_notify(object, "tandy-bit");
182 case PROP_EXPAND_ABBREVIATIONS:
183 PROCESS_FLAG(priv->flags, CHIMARA_IF_EXPAND_ABBREVIATIONS, g_value_get_boolean(value));
184 g_object_notify(object, "expand-abbreviations");
186 case PROP_IGNORE_ERRORS:
187 PROCESS_FLAG(priv->flags, CHIMARA_IF_IGNORE_ERRORS, g_value_get_boolean(value));
188 g_object_notify(object, "ignore-errors");
190 case PROP_TYPO_CORRECTION:
191 PROCESS_FLAG(priv->flags, CHIMARA_IF_TYPO_CORRECTION, g_value_get_boolean(value));
192 g_object_notify(object, "typo-correction");
194 case PROP_INTERPRETER_NUMBER:
195 priv->interpreter_number = g_value_get_uint(value);
196 g_object_notify(object, "interpreter-number");
198 case PROP_RANDOM_SEED:
199 priv->random_seed = g_value_get_int(value);
200 g_object_notify(object, "random-seed");
202 case PROP_RANDOM_SEED_SET:
203 priv->random_seed_set = g_value_get_boolean(value);
204 g_object_notify(object, "random-seed-set");
207 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
212 chimara_if_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
214 CHIMARA_IF_USE_PRIVATE(object, priv);
217 case PROP_PIRACY_MODE:
218 g_value_set_boolean(value, priv->flags & CHIMARA_IF_PIRACY_MODE);
221 g_value_set_boolean(value, priv->flags & CHIMARA_IF_TANDY_BIT);
223 case PROP_EXPAND_ABBREVIATIONS:
224 g_value_set_boolean(value, priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS);
226 case PROP_IGNORE_ERRORS:
227 g_value_set_boolean(value, priv->flags & CHIMARA_IF_IGNORE_ERRORS);
229 case PROP_TYPO_CORRECTION:
230 g_value_set_boolean(value, priv->flags & CHIMARA_IF_TYPO_CORRECTION);
232 case PROP_INTERPRETER_NUMBER:
233 g_value_set_uint(value, priv->interpreter_number);
235 case PROP_RANDOM_SEED:
236 g_value_set_int(value, priv->random_seed);
238 case PROP_RANDOM_SEED_SET:
239 g_value_set_boolean(value, priv->random_seed_set);
242 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
247 chimara_if_finalize(GObject *object)
249 G_OBJECT_CLASS(chimara_if_parent_class)->finalize(object);
253 chimara_if_command(ChimaraIF *self, gchar *input, gchar *response)
255 /* Default signal handler */
258 /* COMPAT: G_PARAM_STATIC_STRINGS only appeared in GTK 2.13.0 */
259 #ifndef G_PARAM_STATIC_STRINGS
261 /* COMPAT: G_PARAM_STATIC_NAME and friends only appeared in GTK 2.8 */
262 #if GTK_CHECK_VERSION(2,8,0)
263 #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
265 #define G_PARAM_STATIC_STRINGS (0)
271 chimara_if_class_init(ChimaraIFClass *klass)
273 /* Override methods of parent classes */
274 GObjectClass *object_class = G_OBJECT_CLASS(klass);
275 object_class->set_property = chimara_if_set_property;
276 object_class->get_property = chimara_if_get_property;
277 object_class->finalize = chimara_if_finalize;
280 klass->command = chimara_if_command;
282 * ChimaraIF::command:
283 * @self: The widget that received the signal
284 * @input: The command typed into the game, or %NULL
285 * @response: The game's response to the command
287 * Emitted once for each input-response cycle of an interactive fiction
288 * game. Note that games with nontraditional input systems (i.e. not all
289 * taking place in the same text buffer window) may confuse this signal.
291 * It may happen that @input is %NULL, in which case @response is not due to
292 * a user command, but contains the text printed at the beginning of the
293 * game, up until the first prompt.
295 chimara_if_signals[COMMAND] = g_signal_new("command",
296 G_OBJECT_CLASS_TYPE(klass), 0,
297 G_STRUCT_OFFSET(ChimaraIFClass, command), NULL, NULL,
298 _chimara_marshal_VOID__STRING_STRING,
299 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
303 * ChimaraIF:piracy-mode:
305 * The Z-machine specification defines a facility for games to ask the
306 * interpreter they are running on whether this copy of the game is pirated.
307 * How the interpreter is supposed to magically determine that it is running
308 * pirate software is unclear, and so the majority of games and interpreters
309 * ignore this feature. Set this property to %TRUE if you want the
310 * interpreter to pretend it has detected a pirated game.
312 * Only affects Z-machine interpreters.
314 g_object_class_install_property(object_class, PROP_PIRACY_MODE,
315 g_param_spec_boolean("piracy-mode", _("Piracy mode"),
316 _("Pretend the game is pirated"), FALSE,
317 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
319 * ChimaraIF:tandy-bit:
321 * Some early Infocom games were sold by the Tandy Corporation. Setting this
322 * property to %TRUE changes the wording of some Version 3 Infocom games
323 * slightly, so as to be less offensive. See <ulink
324 * url="http://www.ifarchive.org/if-archive/infocom/info/tandy_bits.html">
325 * http://www.ifarchive.org/if-archive/infocom/info/tandy_bits.html</ulink>.
327 * Only affects Z-machine interpreters.
329 g_object_class_install_property(object_class, PROP_TANDY_BIT,
330 g_param_spec_boolean("tandy-bit", _("Tandy bit"),
331 _("Censor certain Infocom games"), FALSE,
332 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
334 * ChimaraIF:expand-abbreviations:
336 * Most Z-machine games, in particular ones compiled with the Inform
337 * library, support the following one-letter abbreviations:
339 * <member>D — Down</member>
340 * <member>E — East</member>
341 * <member>G — aGain</member>
342 * <member>I — Inventory</member>
343 * <member>L — Look</member>
344 * <member>N — North</member>
345 * <member>O — Oops</member>
346 * <member>Q — Quit</member>
347 * <member>S — South</member>
348 * <member>U — Up</member>
349 * <member>W — West</member>
350 * <member>X — eXamine</member>
351 * <member>Y — Yes</member>
352 * <member>Z — wait (ZZZZ...)</member>
354 * Some early Infocom games might not recognize these abbreviations. Setting
355 * this property to %TRUE will cause the interpreter to expand the
356 * abbreviations to the full words before passing the commands on to the
357 * game. Frotz only expands G, X, and Z; Nitfol expands all of the above
358 * plus the following nonstandard ones:
360 * <member>C — Close</member>
361 * <member>K — attacK</member>
362 * <member>P — oPen</member>
363 * <member>R — dRop</member>
364 * <member>T — Take</member>
367 * Only affects Z-machine interpreters. Behaves differently on Frotz and
370 g_object_class_install_property(object_class, PROP_EXPAND_ABBREVIATIONS,
371 g_param_spec_boolean("expand-abbreviations", _("Expand abbreviations"),
372 _("Expand abbreviations such as X for EXAMINE"), FALSE,
373 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
375 * ChimaraIF:ignore-errors:
377 * Setting this property to %TRUE will cause the interpreter to ignore
378 * certain Z-machine runtime errors. Frotz will ignore any fatal errors.
379 * Nitfol by default warns about any shady behavior, and this property will
380 * turn those warnings off.
382 * Only affects Z-machine interpreters. Behaves differently on Frotz and
385 g_object_class_install_property(object_class, PROP_IGNORE_ERRORS,
386 g_param_spec_boolean("ignore-errors", _("Ignore errors"),
387 _("Do not warn the user about Z-machine errors"), FALSE,
388 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
390 * ChimaraIF:typo-correction:
392 * Nitfol has an automatic typo-correction facility, where it searches the
393 * game dictionary for words which differ by one letter from any unknown
394 * input words. Set this property to %FALSE to turn this feature off.
396 * Only affects Nitfol.
398 g_object_class_install_property(object_class, PROP_TYPO_CORRECTION,
399 g_param_spec_boolean("typo-correction", _("Typo correction"),
400 _("Try to remedy typos if the interpreter supports it"), TRUE,
401 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
403 * ChimaraIF:interpreter-number:
405 * Infocom gave each port of their interpreter a different number. The Frotz
406 * and Nitfol plugins can emulate any of these platforms. Some games behave
407 * slightly differently depending on what platform they are on. Set this
408 * property to a #ChimaraIFZmachineVersion value to emulate a certain
411 * Note that Nitfol pretends to be an Apple IIe by default.
413 * Only affects Z-machine interpreters.
415 g_object_class_install_property(object_class, PROP_INTERPRETER_NUMBER,
416 g_param_spec_uint("interpreter-number", _("Interpreter number"),
417 _("Platform the Z-machine should pretend it is running on"),
418 CHIMARA_IF_ZMACHINE_DEFAULT, CHIMARA_IF_ZMACHINE_MAXVAL, CHIMARA_IF_ZMACHINE_DEFAULT,
419 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
421 * ChimaraIF:random-seed:
423 * If the #ChimaraIF:random-seed-set property is %TRUE, then the interpreter
424 * will use the value of this property as a seed for the random number
425 * generator. Use this feature to duplicate sequences of random numbers
428 * Note that the value -1 is a valid random number seed for
429 * Nitfol, whereas it will cause Frotz to pick an arbitrary seed even when
430 * #ChimaraIF:random-seed-set is %TRUE.
432 * Only affects Z-machine interpreters. Behaves slightly differently on
435 g_object_class_install_property(object_class, PROP_RANDOM_SEED,
436 g_param_spec_int("random-seed", _("Random seed"),
437 _("Seed for the random number generator"), G_MININT, G_MAXINT, 0,
438 G_PARAM_READWRITE | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
440 * ChimaraIF:random-seed-set:
442 * Whether to use or ignore the #ChimaraIF:random-seed property.
444 * Only affects Z-machine interpreters.
446 g_object_class_install_property(object_class, PROP_RANDOM_SEED_SET,
447 g_param_spec_boolean("random-seed-set", _("Random seed set"),
448 _("Whether the seed for the random number generator should be set manually"), FALSE,
449 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
452 g_type_class_add_private(klass, sizeof(ChimaraIFPrivate));
455 /* PUBLIC FUNCTIONS */
460 * Creates and initializes a new #ChimaraIF widget.
462 * Return value: a #ChimaraIF widget, with a floating reference.
467 /* This is a library entry point; initialize the library */
469 return GTK_WIDGET(g_object_new(CHIMARA_TYPE_IF, NULL));
473 * chimara_if_set_preferred_interpreter:
474 * @self: A #ChimaraIF widget.
475 * @format: The game format to set the preferred interpreter plugin for.
476 * @interpreter: The preferred interpreter plugin for @format.
478 * The function chimara_if_run_game() picks an appropriate interpreter for the
479 * type of game file it is given. This function sets which interpreter is picked
480 * for a certain game file format. Most formats, notably the Z-machine, have
481 * had many different interpreters written for them over the years, all with
482 * slightly different quirks and capabilities, so there is plenty of choice.
485 chimara_if_set_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format, ChimaraIFInterpreter interpreter)
487 g_return_if_fail(self && CHIMARA_IS_IF(self));
488 g_return_if_fail(format < CHIMARA_IF_NUM_FORMATS);
489 g_return_if_fail(interpreter < CHIMARA_IF_NUM_INTERPRETERS);
491 CHIMARA_IF_USE_PRIVATE(self, priv);
493 if(supported_formats[format][interpreter])
494 priv->preferred_interpreter[format] = interpreter;
496 g_warning("Format '%s' is not supported by interpreter '%s'", format_names[format], interpreter_names[interpreter]);
500 * chimara_if_get_preferred_interpreter:
501 * @self: A #ChimaraIF widget.
502 * @format: The game format to query the preferred interpreter plugin for.
504 * Looks up the preferred interpreter for the game file format @format. See
505 * chimara_if_set_preferred_interpreter().
507 * Returns: a #ChimaraIFInterpreter value representing the preferred interpreter
508 * plugin for @format.
511 chimara_if_get_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format)
513 g_return_val_if_fail(self && CHIMARA_IS_IF(self), -1);
514 g_return_val_if_fail(format < CHIMARA_IF_NUM_FORMATS, -1);
515 CHIMARA_IF_USE_PRIVATE(self, priv);
516 return priv->preferred_interpreter[format];
520 * chimara_if_run_game:
521 * @self: A #ChimaraIF widget.
522 * @gamefile: Path to an interactive fiction game file.
523 * @error: Return location for an error, or %NULL.
525 * Autodetects the type of a game file and runs it using an appropriate
526 * interpreter plugin. If there is more than one interpreter that supports the
527 * file format, the preferred one will be picked, according to
528 * chimara_if_set_preferred_interpreter().
530 * Returns: %TRUE if the game was started successfully, %FALSE if not, in which
531 * case @error is set.
534 chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error)
536 g_return_val_if_fail(self && CHIMARA_IS_IF(self), FALSE);
537 g_return_val_if_fail(gamefile, FALSE);
539 CHIMARA_IF_USE_PRIVATE(self, priv);
541 /* Find out what format the game is */
542 /* TODO: Look inside the file instead of just looking at the extension */
543 ChimaraIFFormat format = CHIMARA_IF_FORMAT_Z5;
544 if(g_str_has_suffix(gamefile, ".z5"))
545 format = CHIMARA_IF_FORMAT_Z5;
546 else if(g_str_has_suffix(gamefile, ".z6"))
547 format = CHIMARA_IF_FORMAT_Z6;
548 else if(g_str_has_suffix(gamefile, ".z8"))
549 format = CHIMARA_IF_FORMAT_Z8;
550 else if(g_str_has_suffix(gamefile, ".zlb") || g_str_has_suffix(gamefile, ".zblorb"))
551 format = CHIMARA_IF_FORMAT_Z_BLORB;
552 else if(g_str_has_suffix(gamefile, ".ulx"))
553 format = CHIMARA_IF_FORMAT_GLULX;
554 else if(g_str_has_suffix(gamefile, ".blb") || g_str_has_suffix(gamefile, ".blorb") || g_str_has_suffix(gamefile, ".glb") || g_str_has_suffix(gamefile, ".gblorb"))
555 format = CHIMARA_IF_FORMAT_GLULX_BLORB;
557 /* Now decide what interpreter to use */
558 ChimaraIFInterpreter interpreter = priv->preferred_interpreter[format];
559 gchar *pluginfile = g_strconcat(plugin_names[interpreter], "." G_MODULE_SUFFIX, NULL);
564 #define LT_OBJDIR ".libs" /* Pre-2.2 libtool, so take a wild guess */
565 #endif /* LT_OBJDIR */
566 /* If there is a plugin in the source tree, use that */
567 pluginpath = g_build_filename(PLUGINSOURCEDIR, plugin_names[interpreter], LT_OBJDIR, pluginfile, NULL);
568 if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) )
572 pluginpath = g_build_filename(PLUGINDIR, pluginfile, NULL);
573 if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) )
577 g_set_error(error, CHIMARA_ERROR, CHIMARA_PLUGIN_NOT_FOUND, _("No appropriate %s interpreter plugin was found"), interpreter_names[interpreter]);
585 /* Decide what arguments to pass to the interpreters; currently only the
586 Z-machine interpreters accept command line arguments other than the game */
588 gchar *terpnumstr = NULL, *randomstr = NULL;
589 args = g_slist_prepend(args, pluginpath);
590 args = g_slist_prepend(args, gamefile);
593 case CHIMARA_IF_INTERPRETER_FROTZ:
594 if(priv->flags & CHIMARA_IF_PIRACY_MODE)
595 args = g_slist_prepend(args, "-P");
596 if(priv->flags & CHIMARA_IF_TANDY_BIT)
597 args = g_slist_prepend(args, "-t");
598 if(priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS)
599 args = g_slist_prepend(args, "-x");
600 if(priv->flags & CHIMARA_IF_IGNORE_ERRORS)
601 args = g_slist_prepend(args, "-i");
602 if(priv->interpreter_number != CHIMARA_IF_ZMACHINE_DEFAULT)
604 terpnumstr = g_strdup_printf("-I%u", priv->interpreter_number);
605 args = g_slist_prepend(args, terpnumstr);
607 if(priv->random_seed_set)
609 randomstr = g_strdup_printf("-s%d", priv->random_seed);
610 args = g_slist_prepend(args, randomstr);
613 case CHIMARA_IF_INTERPRETER_NITFOL:
614 if(priv->flags & CHIMARA_IF_PIRACY_MODE)
615 args = g_slist_prepend(args, "-pirate");
616 if(priv->flags & CHIMARA_IF_TANDY_BIT)
617 args = g_slist_prepend(args, "-tandy");
618 if(!(priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS))
619 args = g_slist_prepend(args, "-no-expand");
620 if(priv->flags & CHIMARA_IF_IGNORE_ERRORS)
621 args = g_slist_prepend(args, "-ignore");
622 if(!(priv->flags & CHIMARA_IF_TYPO_CORRECTION))
623 args = g_slist_prepend(args, "-no-spell");
624 if(priv->interpreter_number != CHIMARA_IF_ZMACHINE_DEFAULT)
626 terpnumstr = g_strdup_printf("-terpnum%u", priv->interpreter_number);
627 args = g_slist_prepend(args, terpnumstr);
629 if(priv->random_seed_set)
631 randomstr = g_strdup_printf("-random%d", priv->random_seed);
632 args = g_slist_prepend(args, randomstr);
639 /* Allocate argv to hold the arguments */
640 int argc = g_slist_length(args);
641 args = g_slist_prepend(args, NULL);
642 char **argv = g_new0(char *, argc + 1);
645 args = g_slist_reverse(args);
648 for(count = 0, ptr = args; ptr; count++, ptr = g_slist_next(ptr))
649 argv[count] = ptr->data;
651 /* Set the story name */
652 /* We peek into ChimaraGlk's private data here, because GObject has no
653 equivalent to "protected" */
654 CHIMARA_GLK_USE_PRIVATE(self, glk_priv);
655 glk_priv->story_name = g_path_get_basename(gamefile);
656 g_object_notify(G_OBJECT(self), "story-name");
658 gboolean retval = chimara_glk_run(CHIMARA_GLK(self), pluginpath, argc, argv, error);
666 /* Set current format and interpreter if plugin was started successfully */
669 priv->format = format;
670 priv->interpreter = interpreter;
676 * chimara_if_get_format:
677 * @self: A #ChimaraIF widget.
679 * Returns the file format of the currently running game.
681 * Returns: a #ChimaraIFFormat constant.
684 chimara_if_get_format(ChimaraIF *self)
686 g_return_val_if_fail(self && CHIMARA_IS_IF(self), CHIMARA_IF_FORMAT_NONE);
687 CHIMARA_IF_USE_PRIVATE(self, priv);
692 * chimara_if_get_interpreter:
693 * @self: A #ChimaraIF widget.
695 * Returns the interpreter plugin currently running.
697 * Returns: a #ChimaraIFInterpreter constant.
700 chimara_if_get_interpreter(ChimaraIF *self)
702 g_return_val_if_fail(self && CHIMARA_IS_IF(self), CHIMARA_IF_FORMAT_NONE);
703 CHIMARA_IF_USE_PRIVATE(self, priv);
704 return priv->interpreter;