Gargoyle Extensions

Gargoyle Extensions — Gargoyle extensions to Glk

Functions

Types and Values

Includes

#include <libchimara/glk.h>
#include <libchimara/garglk.h>

Description

This section describes various extensions to Glk that were written for the popular interpreter Gargoyle by Tor Andersson (now maintained by Ben Cressey).

These functions mostly serve to close the gap between Glk's input/output capabilities and what some interpreters expect. For example, garglk_set_zcolors() displays the colors defined in the Z-machine standard, and garglk_set_story_name() can be used to give the host program a hint about what to display in the title bar of its window.

Functions

garglk_fileref_get_name ()

char *
garglk_fileref_get_name (frefid_t fref);

Gets the actual disk filename that fref refers to, in the platform's native filename encoding. The string is owned by fref and must not be changed or freed.

Parameters

fref

A file reference.

 

Returns

a string in filename encoding.


garglk_set_program_name ()

void
garglk_set_program_name (const char *name);

This function is used to let the library know the name of the currently running Glk program, in case it wants to display this information somewhere — for example, in the title bar of a window. A typical use of this function would be:

1
garglk_set_program_name("SuperGlkFrotz 0.1");

Parameters

name

Name of the Glk program that is running.

 

garglk_set_program_info ()

void
garglk_set_program_info (const char *info);

This function is used to provide the library with additional information about the currently running Glk program, in case it wants to display this information somewhere — for example, in an About box. A typical use of this function would be:

1
2
3
4
5
garglk_set_program_info("SuperGlkFrotz, version 0.1\n"
    "Original Frotz by Stefan Jokisch\n"
    "Unix port by Jim Dunleavy and David Griffith\n"
    "Glk port by Tor Andersson\n"
    "Animation, networking, and evil AI by Sven Metcalfe");

Parameters

info

Information about the Glk program that is running.

 

garglk_set_story_name ()

void
garglk_set_story_name (const char *name);

If the Glk program running is an interactive fiction interpreter, then this function can be used to let the library know the name of the story currently loaded in the interpreter, in case it wants to display this information anywhere — for example, in the title bar of a window. A typical use of this function would be:

1
garglk_set_story_name("Lighan Ses Lion, el Zarf");

Parameters

name

Name of the story that the Glk program is currently interpreting.

 

garglk_set_story_title ()

void
garglk_set_story_title (const char *title);

This function is a hint to the library to put title in the title bar of the window that the Glk program is running in. It overrides garglk_set_program_name() and garglk_set_story_name(), if they were displayed in the title bar, although they may still be displayed somewhere else.

This function is not currently implemented.

Parameters

title

Title bar text for the currently running story.

 

garglk_unput_string ()

void
garglk_unput_string (char *str);

Removes str from the end of the current stream, if indeed it is there. The stream's write count is decreased accordingly, and the stream's echo stream is also modified, if it has one.

This function is not currently implemented.

Parameters

str

a null-terminated string.

 

garglk_unput_string_uni ()

void
garglk_unput_string_uni (glui32 *str);

Like garglk_unput_string(), but for Unicode streams.

This function is not currently implemented.

Parameters

str

a zero-terminated array of Unicode code points.

 

garglk_set_zcolors ()

void
garglk_set_zcolors (glui32 fg,
                    glui32 bg);

Glk works with styles, not specific colors. This is not quite compatible with the Z-machine, so this Glk extension implements Z-machine style colors.

This function changes the foreground color of the current stream to fg and the background color to bg . fg and bg are encoded the same way as described in stylehint_TextColor.

Parameters

fg

a 24-bit foreground color.

 

bg

a 24-bit background color.

 

garglk_set_zcolors_stream ()

void
garglk_set_zcolors_stream (strid_t str,
                           glui32 fg,
                           glui32 bg);

This function changes the foreground color of str to fg and the background color to bg . fg and bg are encoded the same way as described in stylehint_TextColor. See garglk_set_zcolors() for more information.

Parameters

str

a stream.

 

fg

a 24-bit foreground color.

 

bg

a 24-bit background color.

 

garglk_set_reversevideo ()

void
garglk_set_reversevideo (glui32 reverse);

If reverse is not zero, uses the foreground color of the current stream as its background and vice versa. If reverse is zero, changes the colors of the current stream back to normal.

Parameters

reverse

nonzero for reverse colors, zero for normal colors.

 

garglk_set_reversevideo_stream ()

void
garglk_set_reversevideo_stream (strid_t str,
                                glui32 reverse);

If reverse is not zero, uses the foreground color of str as its background and vice versa. If reverse is zero, changes the colors of str back to normal.

Parameters

str

a stream.

 

reverse

nonzero for reverse colors, zero for normal colors.

 

Types and Values

GARGLK

#define GARGLK 1

To test at compile time whether the Gargoyle extensions are available, you can perform a preprocessor test for the existence of GARGLK. If this macro is defined, then so are all the Gargoyle extensions. If not, not.

Chimara

Currently, in Chimara, the functions are defined, but a few of them (garglk_unput_string() and garglk_unput_string_uni()) are not implemented. You can call them, but they will have no effect except to print a warning to the console.


zcolor_Current

#define zcolor_Current       (-2)

Z-machine color constant representing the current color.


zcolor_Default

#define zcolor_Default       (-1)

Z-machine color constant representing the default color.


zcolor_Cursor

#define zcolor_Cursor        (-3)

Z-machine color constant representing the color at the current position of the cursor.

Passing this constant to garglk_set_zcolors() or garglk_set_zcolors_stream() is not currently implemented.


zcolor_Transparent

#define zcolor_Transparent   (-4)

Z-machine color constant representing no color, i.e. transparency.

Passing this constant to garglk_set_zcolors() or garglk_set_zcolors_stream() is not currently implemented.


keycode_Erase

#define keycode_Erase    (0xffffef7f)

Since keycode_Delete represents either the Delete or Backspace key, Gargoyle defines a separate constant keycode_Erase to represent only the Delete key. In character input, Delete is still reported as keycode_Delete, but the two are distinguished in glk_set_terminators_line_event().


keycode_MouseWheelUp

#define keycode_MouseWheelUp        (0xffffeffe)

This key code represents the mouse wheel scrolling up in a window. It is never used in Chimara.


keycode_MouseWheelDown

#define keycode_MouseWheelDown      (0xffffefff)

This key code represents the mouse wheel scrolling down in a window. It is never used in Chimara.