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: chimara/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.
23 static gboolean supported_formats[CHIMARA_IF_NUM_FORMATS][CHIMARA_IF_NUM_INTERPRETERS] = {
24 /* Frotz Nitfol Glulxe Git */
25 { TRUE, TRUE, FALSE, FALSE }, /* Z5 */
26 { TRUE, TRUE, FALSE, FALSE }, /* Z6 */
27 { TRUE, TRUE, FALSE, FALSE }, /* Z8 */
28 { TRUE, TRUE, FALSE, FALSE }, /* Zblorb */
29 { FALSE, FALSE, TRUE, TRUE }, /* Glulx */
30 { FALSE, FALSE, TRUE, TRUE } /* Gblorb */
32 static gchar *format_names[CHIMARA_IF_NUM_FORMATS] = {
33 N_("Z-code version 5"),
34 N_("Z-code version 6"),
35 N_("Z-code version 8"),
40 static gchar *interpreter_names[CHIMARA_IF_NUM_INTERPRETERS] = {
41 N_("Frotz"), N_("Nitfol"), N_("Glulxe"), N_("Git")
43 static gchar *plugin_names[CHIMARA_IF_NUM_INTERPRETERS] = {
44 "frotz", "nitfol", "glulxe", "git"
47 typedef enum _ChimaraIFFlags {
48 CHIMARA_IF_PIRACY_MODE = 1 << 0,
49 CHIMARA_IF_TANDY_BIT = 1 << 1,
50 CHIMARA_IF_EXPAND_ABBREVIATIONS = 1 << 2,
51 CHIMARA_IF_IGNORE_ERRORS = 1 << 3,
52 CHIMARA_IF_TYPO_CORRECTION = 1 << 4
55 typedef struct _ChimaraIFPrivate {
56 ChimaraIFInterpreter preferred_interpreter[CHIMARA_IF_NUM_FORMATS];
57 ChimaraIFFormat format;
58 ChimaraIFInterpreter interpreter;
60 ChimaraIFZmachineVersion interpreter_number;
62 gboolean random_seed_set;
63 /* Holding buffers for input and response */
68 #define CHIMARA_IF_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), CHIMARA_TYPE_IF, ChimaraIFPrivate))
69 #define CHIMARA_IF_USE_PRIVATE(o, n) ChimaraIFPrivate *n = CHIMARA_IF_PRIVATE(o)
75 PROP_EXPAND_ABBREVIATIONS,
78 PROP_INTERPRETER_NUMBER,
88 static guint chimara_if_signals[LAST_SIGNAL] = { 0 };
90 G_DEFINE_TYPE(ChimaraIF, chimara_if, CHIMARA_TYPE_GLK);
93 chimara_if_waiting(ChimaraGlk *glk)
95 CHIMARA_IF_USE_PRIVATE(glk, priv);
97 gchar *response = g_string_free(priv->response, FALSE);
98 priv->response = g_string_new("");
100 g_signal_emit_by_name(glk, "command", priv->input, response);
108 chimara_if_stopped(ChimaraGlk *glk)
110 CHIMARA_IF_USE_PRIVATE(glk, priv);
112 if(priv->input || priv->response->len > 0)
113 chimara_if_waiting(glk); /* Send one last command signal */
115 priv->format = CHIMARA_IF_FORMAT_NONE;
116 priv->interpreter = CHIMARA_IF_INTERPRETER_NONE;
120 chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, gchar *input)
122 CHIMARA_IF_USE_PRIVATE(glk, priv);
123 g_assert(priv->input == NULL);
124 priv->input = g_strdup(input);
128 chimara_if_text_buffer_output(ChimaraGlk *glk, guint32 win_rock, gchar *output)
130 CHIMARA_IF_USE_PRIVATE(glk, priv);
131 g_string_append(priv->response, output);
135 chimara_if_init(ChimaraIF *self)
137 CHIMARA_IF_USE_PRIVATE(self, priv);
138 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z5] = CHIMARA_IF_INTERPRETER_FROTZ;
139 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z6] = CHIMARA_IF_INTERPRETER_FROTZ;
140 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z8] = CHIMARA_IF_INTERPRETER_FROTZ;
141 priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z_BLORB] = CHIMARA_IF_INTERPRETER_FROTZ;
142 priv->preferred_interpreter[CHIMARA_IF_FORMAT_GLULX] = CHIMARA_IF_INTERPRETER_GLULXE;
143 priv->preferred_interpreter[CHIMARA_IF_FORMAT_GLULX_BLORB] = CHIMARA_IF_INTERPRETER_GLULXE;
144 priv->format = CHIMARA_IF_FORMAT_NONE;
145 priv->interpreter = CHIMARA_IF_INTERPRETER_NONE;
146 priv->flags = CHIMARA_IF_TYPO_CORRECTION;
147 priv->interpreter_number = CHIMARA_IF_ZMACHINE_DEFAULT;
148 priv->random_seed_set = FALSE;
150 priv->response = g_string_new("");
152 /* Connect to signals of ChimaraGlk parent */
153 g_signal_connect(self, "stopped", G_CALLBACK(chimara_if_stopped), NULL);
154 g_signal_connect(self, "waiting", G_CALLBACK(chimara_if_waiting), NULL);
155 g_signal_connect(self, "line-input", G_CALLBACK(chimara_if_line_input), NULL);
156 g_signal_connect(self, "text-buffer-output", G_CALLBACK(chimara_if_text_buffer_output), NULL);
159 #define PROCESS_FLAG(flags, flag, val) (flags) = (val)? (flags) | (flag) : (flags) & ~(flag)
162 chimara_if_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
164 CHIMARA_IF_USE_PRIVATE(object, priv);
167 case PROP_PIRACY_MODE:
168 PROCESS_FLAG(priv->flags, CHIMARA_IF_PIRACY_MODE, g_value_get_boolean(value));
169 g_object_notify(object, "piracy-mode");
172 PROCESS_FLAG(priv->flags, CHIMARA_IF_TANDY_BIT, g_value_get_boolean(value));
173 g_object_notify(object, "tandy-bit");
175 case PROP_EXPAND_ABBREVIATIONS:
176 PROCESS_FLAG(priv->flags, CHIMARA_IF_EXPAND_ABBREVIATIONS, g_value_get_boolean(value));
177 g_object_notify(object, "expand-abbreviations");
179 case PROP_IGNORE_ERRORS:
180 PROCESS_FLAG(priv->flags, CHIMARA_IF_IGNORE_ERRORS, g_value_get_boolean(value));
181 g_object_notify(object, "ignore-errors");
183 case PROP_TYPO_CORRECTION:
184 PROCESS_FLAG(priv->flags, CHIMARA_IF_TYPO_CORRECTION, g_value_get_boolean(value));
185 g_object_notify(object, "typo-correction");
187 case PROP_INTERPRETER_NUMBER:
188 priv->interpreter_number = g_value_get_uint(value);
189 g_object_notify(object, "interpreter-number");
191 case PROP_RANDOM_SEED:
192 priv->random_seed = g_value_get_int(value);
193 g_object_notify(object, "random-seed");
195 case PROP_RANDOM_SEED_SET:
196 priv->random_seed_set = g_value_get_boolean(value);
197 g_object_notify(object, "random-seed-set");
200 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
205 chimara_if_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
207 CHIMARA_IF_USE_PRIVATE(object, priv);
210 case PROP_PIRACY_MODE:
211 g_value_set_boolean(value, priv->flags & CHIMARA_IF_PIRACY_MODE);
214 g_value_set_boolean(value, priv->flags & CHIMARA_IF_TANDY_BIT);
216 case PROP_EXPAND_ABBREVIATIONS:
217 g_value_set_boolean(value, priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS);
219 case PROP_IGNORE_ERRORS:
220 g_value_set_boolean(value, priv->flags & CHIMARA_IF_IGNORE_ERRORS);
222 case PROP_TYPO_CORRECTION:
223 g_value_set_boolean(value, priv->flags & CHIMARA_IF_TYPO_CORRECTION);
225 case PROP_INTERPRETER_NUMBER:
226 g_value_set_uint(value, priv->interpreter_number);
228 case PROP_RANDOM_SEED:
229 g_value_set_int(value, priv->random_seed);
231 case PROP_RANDOM_SEED_SET:
232 g_value_set_boolean(value, priv->random_seed_set);
235 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
240 chimara_if_finalize(GObject *object)
242 G_OBJECT_CLASS(chimara_if_parent_class)->finalize(object);
246 chimara_if_command(ChimaraIF *self, gchar *input, gchar *response)
248 /* Default signal handler */
251 /* COMPAT: G_PARAM_STATIC_STRINGS only appeared in GTK 2.13.0 */
252 #ifndef G_PARAM_STATIC_STRINGS
254 /* COMPAT: G_PARAM_STATIC_NAME and friends only appeared in GTK 2.8 */
255 #if GTK_CHECK_VERSION(2,8,0)
256 #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
258 #define G_PARAM_STATIC_STRINGS (0)
264 chimara_if_class_init(ChimaraIFClass *klass)
266 /* Override methods of parent classes */
267 GObjectClass *object_class = G_OBJECT_CLASS(klass);
268 object_class->set_property = chimara_if_set_property;
269 object_class->get_property = chimara_if_get_property;
270 object_class->finalize = chimara_if_finalize;
273 klass->command = chimara_if_command;
275 * ChimaraIF::command:
276 * @self: The widget that received the signal
277 * @input: The command typed into the game
278 * @response: The game's response to the command
280 * Emitted once for each input-response cycle of an interactive fiction
281 * game. Note that games with nontraditional input systems (i.e. not all
282 * taking place in the same text buffer window) may throw this signal for a
285 chimara_if_signals[COMMAND] = g_signal_new("command",
286 G_OBJECT_CLASS_TYPE(klass), 0,
287 G_STRUCT_OFFSET(ChimaraIFClass, command), NULL, NULL,
288 chimara_marshal_VOID__STRING_STRING,
289 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
293 * ChimaraIF:piracy-mode:
295 * The Z-machine specification defines a facility for games to ask the
296 * interpreter they are running on whether this copy of the game is pirated.
297 * How the interpreter is supposed to magically determine that it is running
298 * pirate software is unclear, and so the majority of games and interpreters
299 * ignore this feature. Set this property to %TRUE if you want the
300 * interpreter to pretend it has detected a pirated game.
302 * Only affects Z-machine interpreters.
304 g_object_class_install_property(object_class, PROP_PIRACY_MODE,
305 g_param_spec_boolean("piracy-mode", _("Piracy mode"),
306 _("Pretend the game is pirated"), FALSE,
307 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
309 * ChimaraIF:tandy-bit:
311 * Some early Infocom games were sold by the Tandy Corporation. Setting this
312 * property to %TRUE changes the wording of some Version 3 Infocom games
313 * slightly, so as to be less offensive. See <ulink
314 * url="http://www.ifarchive.org/if-archive/infocom/info/tandy_bits.html">
315 * http://www.ifarchive.org/if-archive/infocom/info/tandy_bits.html</ulink>.
317 * Only affects Z-machine interpreters.
319 g_object_class_install_property(object_class, PROP_TANDY_BIT,
320 g_param_spec_boolean("tandy-bit", _("Tandy bit"),
321 _("Censor certain Infocom games"), FALSE,
322 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
324 * ChimaraIF:expand-abbreviations:
326 * Most Z-machine games, in particular ones compiled with the Inform
327 * library, support the following one-letter abbreviations:
329 * <member>D — Down</member>
330 * <member>E — East</member>
331 * <member>G — aGain</member>
332 * <member>I — Inventory</member>
333 * <member>L — Look</member>
334 * <member>N — North</member>
335 * <member>O — Oops</member>
336 * <member>Q — Quit</member>
337 * <member>S — South</member>
338 * <member>U — Up</member>
339 * <member>W — West</member>
340 * <member>X — eXamine</member>
341 * <member>Y — Yes</member>
342 * <member>Z — wait (ZZZZ...)</member>
344 * Some early Infocom games might not recognize these abbreviations. Setting
345 * this property to %TRUE will cause the interpreter to expand the
346 * abbreviations to the full words before passing the commands on to the
347 * game. Frotz only expands G, X, and Z; Nitfol expands all of the above
348 * plus the following nonstandard ones:
350 * <member>C — Close</member>
351 * <member>K — attacK</member>
352 * <member>P — oPen</member>
353 * <member>R — dRop</member>
354 * <member>T — Take</member>
357 * Only affects Z-machine interpreters. Behaves differently on Frotz and
360 g_object_class_install_property(object_class, PROP_EXPAND_ABBREVIATIONS,
361 g_param_spec_boolean("expand-abbreviations", _("Expand abbreviations"),
362 _("Expand abbreviations such as X for EXAMINE"), FALSE,
363 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
365 * ChimaraIF:ignore-errors:
367 * Setting this property to %TRUE will cause the interpreter to ignore
368 * certain Z-machine runtime errors. Frotz will ignore any fatal errors.
369 * Nitfol by default warns about any shady behavior, and this property will
370 * turn those warnings off.
372 * Only affects Z-machine interpreters. Behaves differently on Frotz and
375 g_object_class_install_property(object_class, PROP_IGNORE_ERRORS,
376 g_param_spec_boolean("ignore-errors", _("Ignore errors"),
377 _("Do not warn the user about Z-machine errors"), FALSE,
378 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
380 * ChimaraIF:typo-correction:
382 * Nitfol has an automatic typo-correction facility, where it searches the
383 * game dictionary for words which differ by one letter from any unknown
384 * input words. Set this property to %FALSE to turn this feature off.
386 * Only affects Nitfol.
388 g_object_class_install_property(object_class, PROP_TYPO_CORRECTION,
389 g_param_spec_boolean("typo-correction", _("Typo correction"),
390 _("Try to remedy typos if the interpreter supports it"), TRUE,
391 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
393 * ChimaraIF:interpreter-number:
395 * Infocom gave each port of their interpreter a different number. The Frotz
396 * and Nitfol plugins can emulate any of these platforms. Some games behave
397 * slightly differently depending on what platform they are on. Set this
398 * property to a #ChimaraIFZmachineVersion value to emulate a certain
401 * Note that Nitfol pretends to be an Apple IIe by default.
403 * Only affects Z-machine interpreters.
405 g_object_class_install_property(object_class, PROP_INTERPRETER_NUMBER,
406 g_param_spec_uint("interpreter-number", _("Interpreter number"),
407 _("Platform the Z-machine should pretend it is running on"),
408 CHIMARA_IF_ZMACHINE_DEFAULT, CHIMARA_IF_ZMACHINE_MAXVAL, CHIMARA_IF_ZMACHINE_DEFAULT,
409 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
411 * ChimaraIF:random-seed:
413 * If the #ChimaraIF:random-seed-set property is %TRUE, then the interpreter
414 * will use the value of this property as a seed for the random number
415 * generator. Use this feature to duplicate sequences of random numbers
418 * Note that the value -1 is a valid random number seed for
419 * Nitfol, whereas it will cause Frotz to pick an arbitrary seed even when
420 * #ChimaraIF:random-seed-set is %TRUE.
422 * Only affects Z-machine interpreters. Behaves slightly differently on
425 g_object_class_install_property(object_class, PROP_RANDOM_SEED,
426 g_param_spec_int("random-seed", _("Random seed"),
427 _("Seed for the random number generator"), G_MININT, G_MAXINT, 0,
428 G_PARAM_READWRITE | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
430 * ChimaraIF:random-seed-set:
432 * Whether to use or ignore the #ChimaraIF:random-seed property.
434 * Only affects Z-machine interpreters.
436 g_object_class_install_property(object_class, PROP_RANDOM_SEED_SET,
437 g_param_spec_boolean("random-seed-set", _("Random seed set"),
438 _("Whether the seed for the random number generator should be set manually"), FALSE,
439 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_LAX_VALIDATION | G_PARAM_STATIC_STRINGS));
442 g_type_class_add_private(klass, sizeof(ChimaraIFPrivate));
445 /* PUBLIC FUNCTIONS */
450 * Creates and initializes a new #ChimaraIF widget.
452 * Return value: a #ChimaraIF widget, with a floating reference.
457 /* This is a library entry point; initialize the library */
459 return GTK_WIDGET(g_object_new(CHIMARA_TYPE_IF, NULL));
463 * chimara_if_set_preferred_interpreter:
464 * @self: A #ChimaraIF widget.
465 * @format: The game format to set the preferred interpreter plugin for.
466 * @interpreter: The preferred interpreter plugin for @format.
468 * The function chimara_if_run_game() picks an appropriate interpreter for the
469 * type of game file it is given. This function sets which interpreter is picked
470 * for a certain game file format. Most formats, notably the Z-machine, have
471 * had many different interpreters written for them over the years, all with
472 * slightly different quirks and capabilities, so there is plenty of choice.
475 chimara_if_set_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format, ChimaraIFInterpreter interpreter)
477 g_return_if_fail(self && CHIMARA_IS_IF(self));
478 g_return_if_fail(format < CHIMARA_IF_NUM_FORMATS);
479 g_return_if_fail(interpreter < CHIMARA_IF_NUM_INTERPRETERS);
481 CHIMARA_IF_USE_PRIVATE(self, priv);
483 if(supported_formats[format][interpreter])
484 priv->preferred_interpreter[format] = interpreter;
486 g_warning("Format '%s' is not supported by interpreter '%s'", format_names[format], interpreter_names[interpreter]);
490 * chimara_if_get_preferred_interpreter:
491 * @self: A #ChimaraIF widget.
492 * @format: The game format to query the preferred interpreter plugin for.
494 * Looks up the preferred interpreter for the game file format @format. See
495 * chimara_if_set_preferred_interpreter().
497 * Returns: a #ChimaraIFInterpreter value representing the preferred interpreter
498 * plugin for @format.
501 chimara_if_get_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format)
503 g_return_val_if_fail(self && CHIMARA_IS_IF(self), -1);
504 g_return_val_if_fail(format < CHIMARA_IF_NUM_FORMATS, -1);
505 CHIMARA_IF_USE_PRIVATE(self, priv);
506 return priv->preferred_interpreter[format];
510 * chimara_if_run_game:
511 * @self: A #ChimaraIF widget.
512 * @gamefile: Path to an interactive fiction game file.
513 * @error: Return location for an error, or %NULL.
515 * Autodetects the type of a game file and runs it using an appropriate
516 * interpreter plugin. If there is more than one interpreter that supports the
517 * file format, the preferred one will be picked, according to
518 * chimara_if_set_preferred_interpreter().
520 * Returns: %TRUE if the game was started successfully, %FALSE if not, in which
521 * case @error is set.
524 chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error)
526 g_return_val_if_fail(self && CHIMARA_IS_IF(self), FALSE);
527 g_return_val_if_fail(gamefile, FALSE);
529 CHIMARA_IF_USE_PRIVATE(self, priv);
531 /* Find out what format the game is */
532 /* TODO: Look inside the file instead of just looking at the extension */
533 ChimaraIFFormat format = CHIMARA_IF_FORMAT_Z5;
534 if(g_str_has_suffix(gamefile, ".z5"))
535 format = CHIMARA_IF_FORMAT_Z5;
536 else if(g_str_has_suffix(gamefile, ".z6"))
537 format = CHIMARA_IF_FORMAT_Z6;
538 else if(g_str_has_suffix(gamefile, ".z8"))
539 format = CHIMARA_IF_FORMAT_Z8;
540 else if(g_str_has_suffix(gamefile, ".zlb") || g_str_has_suffix(gamefile, ".zblorb"))
541 format = CHIMARA_IF_FORMAT_Z_BLORB;
542 else if(g_str_has_suffix(gamefile, ".ulx"))
543 format = CHIMARA_IF_FORMAT_GLULX;
544 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"))
545 format = CHIMARA_IF_FORMAT_GLULX_BLORB;
547 /* Now decide what interpreter to use */
548 ChimaraIFInterpreter interpreter = priv->preferred_interpreter[format];
549 gchar *pluginfile = g_strconcat(plugin_names[interpreter], "." G_MODULE_SUFFIX, NULL);
554 #define LT_OBJDIR ".libs" /* Pre-2.2 libtool, so take a wild guess */
555 #endif /* LT_OBJDIR */
556 /* If there is a plugin in the source tree, use that */
557 pluginpath = g_build_filename(PLUGINSOURCEDIR, plugin_names[interpreter], LT_OBJDIR, pluginfile, NULL);
558 if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) )
562 pluginpath = g_build_filename(PLUGINDIR, pluginfile, NULL);
563 if( !g_file_test(pluginpath, G_FILE_TEST_EXISTS) )
567 g_set_error(error, CHIMARA_ERROR, CHIMARA_PLUGIN_NOT_FOUND, _("No appropriate %s interpreter plugin was found"), interpreter_names[interpreter]);
575 /* Decide what arguments to pass to the interpreters; currently only the
576 Z-machine interpreters accept command line arguments other than the game */
578 gchar *terpnumstr = NULL, *randomstr = NULL;
579 args = g_slist_prepend(args, pluginpath);
580 args = g_slist_prepend(args, gamefile);
583 case CHIMARA_IF_INTERPRETER_FROTZ:
584 if(priv->flags & CHIMARA_IF_PIRACY_MODE)
585 args = g_slist_prepend(args, "-P");
586 if(priv->flags & CHIMARA_IF_TANDY_BIT)
587 args = g_slist_prepend(args, "-t");
588 if(priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS)
589 args = g_slist_prepend(args, "-x");
590 if(priv->flags & CHIMARA_IF_IGNORE_ERRORS)
591 args = g_slist_prepend(args, "-i");
592 if(priv->interpreter_number != CHIMARA_IF_ZMACHINE_DEFAULT)
594 terpnumstr = g_strdup_printf("-I%u", priv->interpreter_number);
595 args = g_slist_prepend(args, terpnumstr);
597 if(priv->random_seed_set)
599 randomstr = g_strdup_printf("-s%d", priv->random_seed);
600 args = g_slist_prepend(args, randomstr);
603 case CHIMARA_IF_INTERPRETER_NITFOL:
604 if(priv->flags & CHIMARA_IF_PIRACY_MODE)
605 args = g_slist_prepend(args, "-pirate");
606 if(priv->flags & CHIMARA_IF_TANDY_BIT)
607 args = g_slist_prepend(args, "-tandy");
608 if(!(priv->flags & CHIMARA_IF_EXPAND_ABBREVIATIONS))
609 args = g_slist_prepend(args, "-no-expand");
610 if(priv->flags & CHIMARA_IF_IGNORE_ERRORS)
611 args = g_slist_prepend(args, "-ignore");
612 if(!(priv->flags & CHIMARA_IF_TYPO_CORRECTION))
613 args = g_slist_prepend(args, "-no-spell");
614 if(priv->interpreter_number != CHIMARA_IF_ZMACHINE_DEFAULT)
616 terpnumstr = g_strdup_printf("-terpnum%u", priv->interpreter_number);
617 args = g_slist_prepend(args, terpnumstr);
619 if(priv->random_seed_set)
621 randomstr = g_strdup_printf("-random%d", priv->random_seed);
622 args = g_slist_prepend(args, randomstr);
629 /* Allocate argv to hold the arguments */
630 int argc = g_slist_length(args);
631 args = g_slist_prepend(args, NULL);
632 char **argv = g_new0(char *, argc + 1);
635 args = g_slist_reverse(args);
638 for(count = 0, ptr = args; ptr; count++, ptr = g_slist_next(ptr))
639 argv[count] = ptr->data;
641 gboolean retval = chimara_glk_run(CHIMARA_GLK(self), pluginpath, argc, argv, error);
649 /* Set current format and interpreter if plugin was started successfully */
652 priv->format = format;
653 priv->interpreter = interpreter;
659 * chimara_if_get_format:
660 * @self: A #ChimaraIF widget.
662 * Returns the file format of the currently running game.
664 * Returns: a #ChimaraIFFormat constant.
667 chimara_if_get_format(ChimaraIF *self)
669 g_return_val_if_fail(self && CHIMARA_IS_IF(self), CHIMARA_IF_FORMAT_NONE);
670 CHIMARA_IF_USE_PRIVATE(self, priv);
675 * chimara_if_get_interpreter:
676 * @self: A #ChimaraIF widget.
678 * Returns the interpreter plugin currently running.
680 * Returns: a #ChimaraIFInterpreter constant.
683 chimara_if_get_interpreter(ChimaraIF *self)
685 g_return_val_if_fail(self && CHIMARA_IS_IF(self), CHIMARA_IF_FORMAT_NONE);
686 CHIMARA_IF_USE_PRIVATE(self, priv);
687 return priv->interpreter;