4 #include <glib-object.h>
6 #include <glib/gi18n-lib.h>
7 #include "chimara-if.h"
8 #include "chimara-glk.h"
9 #include "chimara-marshallers.h"
14 * @short_description: Widget which plays an interactive fiction game
15 * @stability: Unstable
16 * @include: libchimara/chimara-if.h
18 * The #ChimaraIF widget, given an interactive fiction game file to run, selects
19 * an appropriate interpreter plugin and runs it. Interpreter options are set by
20 * setting properties on the widget.
22 * Using it in a GTK program is similar to using #ChimaraGlk (which see).
23 * Threads must be initialized before using #ChimaraIF and the call to
24 * gtk_main() must be bracketed between gdk_threads_enter() and
25 * gdk_threads_leave(). Use chimara_if_run_game() to start playing an
26 * interactive fiction game.
29 static gboolean supported_formats[CHIMARA_IF_NUM_FORMATS][CHIMARA_IF_NUM_INTERPRETERS] = {
30 /* Frotz Nitfol Glulxe Git */
31 { TRUE, TRUE, FALSE, FALSE }, /* Z5 */
32 { TRUE, TRUE, FALSE, FALSE }, /* Z6 */
33 { TRUE, TRUE, FALSE, FALSE }, /* Z8 */
34 { TRUE, TRUE, FALSE, FALSE }, /* Zblorb */
35 { FALSE, FALSE, TRUE, TRUE }, /* Glulx */
36 { FALSE, FALSE, TRUE, TRUE } /* Gblorb */
38 static gchar *format_names[CHIMARA_IF_NUM_FORMATS] = {
39 N_("Z-code version 5"),
40 N_("Z-code version 6"),
41 N_("Z-code version 8"),
46 static gchar *interpreter_names[CHIMARA_IF_NUM_INTERPRETERS] = {
47 N_("Frotz"), N_("Nitfol"), N_("Glulxe"), N_("Git")
49 static gchar *plugin_names[CHIMARA_IF_NUM_INTERPRETERS] = {
50 "frotz", "nitfol", "glulxe", "git"
53 typedef enum _ChimaraIFFlags {
54 CHIMARA_IF_PIRACY_MODE = 1 << 0,
55 CHIMARA_IF_TANDY_BIT = 1 << 1,
56 CHIMARA_IF_EXPAND_ABBREVIATIONS = 1 << 2,
57 CHIMARA_IF_IGNORE_ERRORS = 1 << 3,
58 CHIMARA_IF_TYPO_CORRECTION = 1 << 4
61 typedef struct _ChimaraIFPrivate {
62 ChimaraIFInterpreter preferred_interpreter[CHIMARA_IF_NUM_FORMATS];
63 ChimaraIFFormat format;
64 ChimaraIFInterpreter interpreter;
66 ChimaraIFZmachineVersion interpreter_number;
68 gboolean random_seed_set;
69 /* Holding buffers for input and response */
74 #define CHIMARA_IF_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), CHIMARA_TYPE_IF, ChimaraIFPrivate))
75 #define CHIMARA_IF_USE_PRIVATE(o, n) ChimaraIFPrivate *n = CHIMARA_IF_PRIVATE(o)
81 PROP_EXPAND_ABBREVIATIONS,
84 PROP_INTERPRETER_NUMBER,
94 static guint chimara_if_signals[LAST_SIGNAL] = { 0 };
96 G_DEFINE_TYPE(ChimaraIF, chimara_if, CHIMARA_TYPE_GLK);
99 chimara_if_waiting(ChimaraGlk *glk)
101 CHIMARA_IF_USE_PRIVATE(glk, priv);
103 gchar *response = g_string_free(priv->response, FALSE);
104 priv->response = g_string_new("");
106 g_signal_emit_by_name(glk, "command", priv->input, response);
114 chimara_if_stopped(ChimaraGlk *glk)
116 CHIMARA_IF_USE_PRIVATE(glk, priv);
118 if(priv->input || priv->response->len > 0)
119 chimara_if_waiting(glk); /* Send one last command signal */
121 priv->format = CHIMARA_IF_FORMAT_NONE;
122 priv->interpreter = CHIMARA_IF_INTERPRETER_NONE;
126 chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, gchar *input)
128 CHIMARA_IF_USE_PRIVATE(glk, priv);
129 g_assert(priv->input == NULL);
130 priv->input = g_strdup(input);
134 chimara_if_text_buffer_output(ChimaraGlk *glk, guint32 win_rock, gchar *output)
136 CHIMARA_IF_USE_PRIVATE(glk, priv);
137 g_string_append(priv->response, output);
141 chimara_if_init(ChimaraIF *self)
143 CHIMARA_IF_USE_PRIVATE(self, priv);
144 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z5] = CHIMARA_IF_INTERPRETER_FROTZ;
145 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z6] = CHIMARA_IF_INTERPRETER_FROTZ;
146 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z8] = CHIMARA_IF_INTERPRETER_FROTZ;
147 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z_BLORB] = CHIMARA_IF_INTERPRETER_FROTZ;
148 priv->preferred_interpreter[CHIMARA_IF_FORMAT_GLULX] = CHIMARA_IF_INTERPRETER_GLULXE;
149 priv->preferred_interpreter[CHIMARA_IF_FORMAT_GLULX_BLORB] = CHIMARA_IF_INTERPRETER_GLULXE;
150 priv->format = CHIMARA_IF_FORMAT_NONE;
151 priv->interpreter = CHIMARA_IF_INTERPRETER_NONE;
152 priv->flags = CHIMARA_IF_TYPO_CORRECTION;
153 priv->interpreter_number = CHIMARA_IF_ZMACHINE_DEFAULT;
154 priv->random_seed_set = FALSE;
156 priv->response = g_string_new("");
158 /* Connect to signals of ChimaraGlk parent */
159 g_signal_connect(self, "stopped", G_CALLBACK(chimara_if_stopped), NULL);
160 g_signal_connect(self, "waiting", G_CALLBACK(chimara_if_waiting), NULL);
161 g_signal_connect(self, "line-input", G_CALLBACK(chimara_if_line_input), NULL);
162 g_signal_connect(self, "text-buffer-output", G_CALLBACK(chimara_if_text_buffer_output), NULL);
165 #define PROCESS_FLAG(flags, flag, val) (flags) = (val)? (flags) | (flag) : (flags) & ~(flag)
168 chimara_if_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
170 CHIMARA_IF_USE_PRIVATE(object, priv);
173 case PROP_PIRACY_MODE:
174 PROCESS_FLAG(priv->flags, CHIMARA_IF_PIRACY_MODE, g_value_get_boolean(value));
175 g_object_notify(object, "piracy-mode");
178 PROCESS_FLAG(priv->flags, CHIMARA_IF_TANDY_BIT, g_value_get_boolean(value));
179 g_object_notify(object, "tandy-bit");
181 case PROP_EXPAND_ABBREVIATIONS:
182 PROCESS_FLAG(priv->flags, CHIMARA_IF_EXPAND_ABBREVIATIONS, g_value_get_boolean(value));
183 g_object_notify(object, "expand-abbreviations");
185 case PROP_IGNORE_ERRORS:
186 PROCESS_FLAG(priv->flags, CHIMARA_IF_IGNORE_ERRORS, g_value_get_boolean(value));
187 g_object_notify(object, "ignore-errors");
189 case PROP_TYPO_CORRECTION:
190 PROCESS_FLAG(priv->flags, CHIMARA_IF_TYPO_CORRECTION, g_value_get_boolean(value));
191 g_object_notify(object, "typo-correction");
193 case PROP_INTERPRETER_NUMBER:
194 priv->interpreter_number = g_value_get_uint(value);
195 g_object_notify(object, "interpreter-number");
197 case PROP_RANDOM_SEED:
198 priv->random_seed = g_value_get_int(value);
199 g_object_notify(object, "random-seed");
201 case PROP_RANDOM_SEED_SET:
202 priv->random_seed_set = g_value_get_boolean(value);
203 g_object_notify(object, "random-seed-set");
206 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
211 chimara_if_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
213 CHIMARA_IF_USE_PRIVATE(object, priv);
216 case PROP_PIRACY_MODE:
217 g_value_set_boolean(value, priv->flags & CHIMARA_IF_PIRACY_MODE);
220 g_value_set_boolean(value, priv->flags & CHIMARA_IF_TANDY_BIT);
222 case PROP_EXPAND_ABBREVIATIONS:
223 g_value_set_boolean(value, priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS);
225 case PROP_IGNORE_ERRORS:
226 g_value_set_boolean(value, priv->flags & CHIMARA_IF_IGNORE_ERRORS);
228 case PROP_TYPO_CORRECTION:
229 g_value_set_boolean(value, priv->flags & CHIMARA_IF_TYPO_CORRECTION);
231 case PROP_INTERPRETER_NUMBER:
232 g_value_set_uint(value, priv->interpreter_number);
234 case PROP_RANDOM_SEED:
235 g_value_set_int(value, priv->random_seed);
237 case PROP_RANDOM_SEED_SET:
238 g_value_set_boolean(value, priv->random_seed_set);
241 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
246 chimara_if_finalize(GObject *object)
248 G_OBJECT_CLASS(chimara_if_parent_class)->finalize(object);
252 chimara_if_command(ChimaraIF *self, gchar *input, gchar *response)
254 /* Default signal handler */
257 /* COMPAT: G_PARAM_STATIC_STRINGS only appeared in GTK 2.13.0 */
258 #ifndef G_PARAM_STATIC_STRINGS
260 /* COMPAT: G_PARAM_STATIC_NAME and friends only appeared in GTK 2.8 */
261 #if GTK_CHECK_VERSION(2,8,0)
262 #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
264 #define G_PARAM_STATIC_STRINGS (0)
270 chimara_if_class_init(ChimaraIFClass *klass)
272 /* Override methods of parent classes */
273 GObjectClass *object_class = G_OBJECT_CLASS(klass);
274 object_class->set_property = chimara_if_set_property;
275 object_class->get_property = chimara_if_get_property;
276 object_class->finalize = chimara_if_finalize;
279 klass->command = chimara_if_command;
281 * ChimaraIF::command:
282 * @self: The widget that received the signal
283 * @input: The command typed into the game
284 * @response: The game's response to the command
286 * Emitted once for each input-response cycle of an interactive fiction
287 * game. Note that games with nontraditional input systems (i.e. not all
288 * taking place in the same text buffer window) may confuse this signal.
290 chimara_if_signals[COMMAND] = g_signal_new("command",
291 G_OBJECT_CLASS_TYPE(klass), 0,
292 G_STRUCT_OFFSET(ChimaraIFClass, command), NULL, NULL,
293 chimara_marshal_VOID__STRING_STRING,
294 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
298 * ChimaraIF:piracy-mode:
300 * The Z-machine specification defines a facility for games to ask the
301 * interpreter they are running on whether this copy of the game is pirated.
302 * How the interpreter is supposed to magically determine that it is running
303 * pirate software is unclear, and so the majority of games and interpreters
304 * ignore this feature. Set this property to %TRUE if you want the
305 * interpreter to pretend it has detected a pirated game.
307 * Only affects Z-machine interpreters.
309 g_object_class_install_property(object_class, PROP_PIRACY_MODE,
310 g_param_spec_boolean("piracy-mode", _("Piracy mode"),
311 _("Pretend the game is pirated"), FALSE,
312 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
314 * ChimaraIF:tandy-bit:
316 * Some early Infocom games were sold by the Tandy Corporation. Setting this
317 * property to %TRUE changes the wording of some Version 3 Infocom games
318 * slightly, so as to be less offensive. See <ulink
319 * url="http://www.ifarchive.org/if-archive/infocom/info/tandy_bits.html">
320 * http://www.ifarchive.org/if-archive/infocom/info/tandy_bits.html</ulink>.
322 * Only affects Z-machine interpreters.
324 g_object_class_install_property(object_class, PROP_TANDY_BIT,
325 g_param_spec_boolean("tandy-bit", _("Tandy bit"),
326 _("Censor certain Infocom games"), FALSE,
327 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
329 * ChimaraIF:expand-abbreviations:
331 * Most Z-machine games, in particular ones compiled with the Inform
332 * library, support the following one-letter abbreviations:
334 * <member>D — Down</member>
335 * <member>E — East</member>
336 * <member>G — aGain</member>
337 * <member>I — Inventory</member>
338 * <member>L — Look</member>
339 * <member>N — North</member>
340 * <member>O — Oops</member>
341 * <member>Q — Quit</member>
342 * <member>S — South</member>
343 * <member>U — Up</member>
344 * <member>W — West</member>
345 * <member>X — eXamine</member>
346 * <member>Y — Yes</member>
347 * <member>Z — wait (ZZZZ...)</member>
349 * Some early Infocom games might not recognize these abbreviations. Setting
350 * this property to %TRUE will cause the interpreter to expand the
351 * abbreviations to the full words before passing the commands on to the
352 * game. Frotz only expands G, X, and Z; Nitfol expands all of the above
353 * plus the following nonstandard ones:
355 * <member>C — Close</member>
356 * <member>K — attacK</member>
357 * <member>P — oPen</member>
358 * <member>R — dRop</member>
359 * <member>T — Take</member>
362 * Only affects Z-machine interpreters. Behaves differently on Frotz and
365 g_object_class_install_property(object_class, PROP_EXPAND_ABBREVIATIONS,
366 g_param_spec_boolean("expand-abbreviations", _("Expand abbreviations"),
367 _("Expand abbreviations such as X for EXAMINE"), FALSE,
368 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
370 * ChimaraIF:ignore-errors:
372 * Setting this property to %TRUE will cause the interpreter to ignore
373 * certain Z-machine runtime errors. Frotz will ignore any fatal errors.
374 * Nitfol by default warns about any shady behavior, and this property will
375 * turn those warnings off.
377 * Only affects Z-machine interpreters. Behaves differently on Frotz and
380 g_object_class_install_property(object_class, PROP_IGNORE_ERRORS,
381 g_param_spec_boolean("ignore-errors", _("Ignore errors"),
382 _("Do not warn the user about Z-machine errors"), FALSE,
383 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
385 * ChimaraIF:typo-correction:
387 * Nitfol has an automatic typo-correction facility, where it searches the
388 * game dictionary for words which differ by one letter from any unknown
389 * input words. Set this property to %FALSE to turn this feature off.
391 * Only affects Nitfol.
393 g_object_class_install_property(object_class, PROP_TYPO_CORRECTION,
394 g_param_spec_boolean("typo-correction", _("Typo correction"),
395 _("Try to remedy typos if the interpreter supports it"), TRUE,
396 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
398 * ChimaraIF:interpreter-number:
400 * Infocom gave each port of their interpreter a different number. The Frotz
401 * and Nitfol plugins can emulate any of these platforms. Some games behave
402 * slightly differently depending on what platform they are on. Set this
403 * property to a #ChimaraIFZmachineVersion value to emulate a certain
406 * Note that Nitfol pretends to be an Apple IIe by default.
408 * Only affects Z-machine interpreters.
410 g_object_class_install_property(object_class, PROP_INTERPRETER_NUMBER,
411 g_param_spec_uint("interpreter-number", _("Interpreter number"),
412 _("Platform the Z-machine should pretend it is running on"),
413 CHIMARA_IF_ZMACHINE_DEFAULT, CHIMARA_IF_ZMACHINE_MAXVAL, CHIMARA_IF_ZMACHINE_DEFAULT,
414 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
416 * ChimaraIF:random-seed:
418 * If the #ChimaraIF:random-seed-set property is %TRUE, then the interpreter
419 * will use the value of this property as a seed for the random number
420 * generator. Use this feature to duplicate sequences of random numbers
423 * Note that the value -1 is a valid random number seed for
424 * Nitfol, whereas it will cause Frotz to pick an arbitrary seed even when
425 * #ChimaraIF:random-seed-set is %TRUE.
427 * Only affects Z-machine interpreters. Behaves slightly differently on
430 g_object_class_install_property(object_class, PROP_RANDOM_SEED,
431 g_param_spec_int("random-seed", _("Random seed"),
432 _("Seed for the random number generator"), G_MININT, G_MAXINT, 0,
433 G_PARAM_READWRITE | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
435 * ChimaraIF:random-seed-set:
437 * Whether to use or ignore the #ChimaraIF:random-seed property.
439 * Only affects Z-machine interpreters.
441 g_object_class_install_property(object_class, PROP_RANDOM_SEED_SET,
442 g_param_spec_boolean("random-seed-set", _("Random seed set"),
443 _("Whether the seed for the random number generator should be set manually"), FALSE,
444 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
447 g_type_class_add_private(klass, sizeof(ChimaraIFPrivate));
450 /* PUBLIC FUNCTIONS */
455 * Creates and initializes a new #ChimaraIF widget.
457 * Return value: a #ChimaraIF widget, with a floating reference.
462 /* This is a library entry point; initialize the library */
464 return GTK_WIDGET(g_object_new(CHIMARA_TYPE_IF, NULL));
468 * chimara_if_set_preferred_interpreter:
469 * @self: A #ChimaraIF widget.
470 * @format: The game format to set the preferred interpreter plugin for.
471 * @interpreter: The preferred interpreter plugin for @format.
473 * The function chimara_if_run_game() picks an appropriate interpreter for the
474 * type of game file it is given. This function sets which interpreter is picked
475 * for a certain game file format. Most formats, notably the Z-machine, have
476 * had many different interpreters written for them over the years, all with
477 * slightly different quirks and capabilities, so there is plenty of choice.
480 chimara_if_set_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format, ChimaraIFInterpreter interpreter)
482 g_return_if_fail(self && CHIMARA_IS_IF(self));
483 g_return_if_fail(format < CHIMARA_IF_NUM_FORMATS);
484 g_return_if_fail(interpreter < CHIMARA_IF_NUM_INTERPRETERS);
486 CHIMARA_IF_USE_PRIVATE(self, priv);
488 if(supported_formats[format][interpreter])
489 priv->preferred_interpreter[format] = interpreter;
491 g_warning("Format '%s' is not supported by interpreter '%s'", format_names[format], interpreter_names[interpreter]);
495 * chimara_if_get_preferred_interpreter:
496 * @self: A #ChimaraIF widget.
497 * @format: The game format to query the preferred interpreter plugin for.
499 * Looks up the preferred interpreter for the game file format @format. See
500 * chimara_if_set_preferred_interpreter().
502 * Returns: a #ChimaraIFInterpreter value representing the preferred interpreter
503 * plugin for @format.
506 chimara_if_get_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format)
508 g_return_val_if_fail(self && CHIMARA_IS_IF(self), -1);
509 g_return_val_if_fail(format < CHIMARA_IF_NUM_FORMATS, -1);
510 CHIMARA_IF_USE_PRIVATE(self, priv);
511 return priv->preferred_interpreter[format];
515 * chimara_if_run_game:
516 * @self: A #ChimaraIF widget.
517 * @gamefile: Path to an interactive fiction game file.
518 * @error: Return location for an error, or %NULL.
520 * Autodetects the type of a game file and runs it using an appropriate
521 * interpreter plugin. If there is more than one interpreter that supports the
522 * file format, the preferred one will be picked, according to
523 * chimara_if_set_preferred_interpreter().
525 * Returns: %TRUE if the game was started successfully, %FALSE if not, in which
526 * case @error is set.
529 chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error)
531 g_return_val_if_fail(self && CHIMARA_IS_IF(self), FALSE);
532 g_return_val_if_fail(gamefile, FALSE);
534 CHIMARA_IF_USE_PRIVATE(self, priv);
536 /* Find out what format the game is */
537 /* TODO: Look inside the file instead of just looking at the extension */
538 ChimaraIFFormat format = CHIMARA_IF_FORMAT_Z5;
539 if(g_str_has_suffix(gamefile, ".z5"))
540 format = CHIMARA_IF_FORMAT_Z5;
541 else if(g_str_has_suffix(gamefile, ".z6"))
542 format = CHIMARA_IF_FORMAT_Z6;
543 else if(g_str_has_suffix(gamefile, ".z8"))
544 format = CHIMARA_IF_FORMAT_Z8;
545 else if(g_str_has_suffix(gamefile, ".zlb") || g_str_has_suffix(gamefile, ".zblorb"))
546 format = CHIMARA_IF_FORMAT_Z_BLORB;
547 else if(g_str_has_suffix(gamefile, ".ulx"))
548 format = CHIMARA_IF_FORMAT_GLULX;
549 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"))
550 format = CHIMARA_IF_FORMAT_GLULX_BLORB;
552 /* Now decide what interpreter to use */
553 ChimaraIFInterpreter interpreter = priv->preferred_interpreter[format];
554 gchar *pluginfile = g_strconcat(plugin_names[interpreter], "." G_MODULE_SUFFIX, NULL);
559 #define LT_OBJDIR ".libs" /* Pre-2.2 libtool, so take a wild guess */
560 #endif /* LT_OBJDIR */
561 /* If there is a plugin in the source tree, use that */
562 pluginpath = g_build_filename(PLUGINSOURCEDIR, plugin_names[interpreter], LT_OBJDIR, pluginfile, NULL);
563 if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) )
567 pluginpath = g_build_filename(PLUGINDIR, pluginfile, NULL);
568 if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) )
572 g_set_error(error, CHIMARA_ERROR, CHIMARA_PLUGIN_NOT_FOUND, _("No appropriate %s interpreter plugin was found"), interpreter_names[interpreter]);
580 /* Decide what arguments to pass to the interpreters; currently only the
581 Z-machine interpreters accept command line arguments other than the game */
583 gchar *terpnumstr = NULL, *randomstr = NULL;
584 args = g_slist_prepend(args, pluginpath);
585 args = g_slist_prepend(args, gamefile);
588 case CHIMARA_IF_INTERPRETER_FROTZ:
589 if(priv->flags & CHIMARA_IF_PIRACY_MODE)
590 args = g_slist_prepend(args, "-P");
591 if(priv->flags & CHIMARA_IF_TANDY_BIT)
592 args = g_slist_prepend(args, "-t");
593 if(priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS)
594 args = g_slist_prepend(args, "-x");
595 if(priv->flags & CHIMARA_IF_IGNORE_ERRORS)
596 args = g_slist_prepend(args, "-i");
597 if(priv->interpreter_number != CHIMARA_IF_ZMACHINE_DEFAULT)
599 terpnumstr = g_strdup_printf("-I%u", priv->interpreter_number);
600 args = g_slist_prepend(args, terpnumstr);
602 if(priv->random_seed_set)
604 randomstr = g_strdup_printf("-s%d", priv->random_seed);
605 args = g_slist_prepend(args, randomstr);
608 case CHIMARA_IF_INTERPRETER_NITFOL:
609 if(priv->flags & CHIMARA_IF_PIRACY_MODE)
610 args = g_slist_prepend(args, "-pirate");
611 if(priv->flags & CHIMARA_IF_TANDY_BIT)
612 args = g_slist_prepend(args, "-tandy");
613 if(!(priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS))
614 args = g_slist_prepend(args, "-no-expand");
615 if(priv->flags & CHIMARA_IF_IGNORE_ERRORS)
616 args = g_slist_prepend(args, "-ignore");
617 if(!(priv->flags & CHIMARA_IF_TYPO_CORRECTION))
618 args = g_slist_prepend(args, "-no-spell");
619 if(priv->interpreter_number != CHIMARA_IF_ZMACHINE_DEFAULT)
621 terpnumstr = g_strdup_printf("-terpnum%u", priv->interpreter_number);
622 args = g_slist_prepend(args, terpnumstr);
624 if(priv->random_seed_set)
626 randomstr = g_strdup_printf("-random%d", priv->random_seed);
627 args = g_slist_prepend(args, randomstr);
634 /* Allocate argv to hold the arguments */
635 int argc = g_slist_length(args);
636 args = g_slist_prepend(args, NULL);
637 char **argv = g_new0(char *, argc + 1);
640 args = g_slist_reverse(args);
643 for(count = 0, ptr = args; ptr; count++, ptr = g_slist_next(ptr))
644 argv[count] = ptr->data;
646 gboolean retval = chimara_glk_run(CHIMARA_GLK(self), pluginpath, argc, argv, error);
654 /* Set current format and interpreter if plugin was started successfully */
657 priv->format = format;
658 priv->interpreter = interpreter;
664 * chimara_if_get_format:
665 * @self: A #ChimaraIF widget.
667 * Returns the file format of the currently running game.
669 * Returns: a #ChimaraIFFormat constant.
672 chimara_if_get_format(ChimaraIF *self)
674 g_return_val_if_fail(self && CHIMARA_IS_IF(self), CHIMARA_IF_FORMAT_NONE);
675 CHIMARA_IF_USE_PRIVATE(self, priv);
680 * chimara_if_get_interpreter:
681 * @self: A #ChimaraIF widget.
683 * Returns the interpreter plugin currently running.
685 * Returns: a #ChimaraIFInterpreter constant.
688 chimara_if_get_interpreter(ChimaraIF *self)
690 g_return_val_if_fail(self && CHIMARA_IS_IF(self), CHIMARA_IF_FORMAT_NONE);
691 CHIMARA_IF_USE_PRIVATE(self, priv);
692 return priv->interpreter;