3fd18ca0f55778eb8c719b9a28fc5bcc2bd337b8
[rodin/chimara.git] / libchimara / doc.c
1 /*
2  * doc.c - Contains the short and long descriptions of all the documentation
3  *         sections in the Glk spec, as well as the GtkDoc comments for symbols
4  *         defined only in glk.h.
5  */
6
7 /**
8  * SECTION:glk-exiting
9  * @short_description: How to terminate a Glk program cleanly
10  * @include: libchimara/glk.h
11  *
12  * A Glk program usually ends when the end of the glk_main() function is 
13  * reached. You can also terminate it earlier.
14  */ 
15
16 /**
17  * SECTION:glk-interrupt
18  * @short_description: Specifying an interrupt handler for cleaning up critical
19  * resources
20  * @include: libchimara/glk.h
21  *
22  * Most platforms have some provision for interrupting a program —
23  * <keycombo action="simul"><keycap function="command">command</keycap>
24  * <keycap>period</keycap></keycombo> on the Macintosh, <keycombo 
25  * action="simul"><keycap function="control">control</keycap><keycap>C</keycap>
26  * </keycombo> in Unix, possibly a window manager item, or other possibilities.
27  * This can happen at any time, including while execution is nested inside one 
28  * of your own functions, or inside a Glk library function.
29  *
30  * If you need to clean up critical resources, you can specify an interrupt
31  * handler function.
32  */
33
34 /**
35  * SECTION:glk-tick
36  * @short_description: Yielding time to the operating system
37  * @include: libchimara/glk.h
38  *
39  * Many platforms have some annoying thing that has to be done every so often,
40  * or the gnurrs come from the voodvork out and eat your computer.
41  * 
42  * Well, not really. But you should call glk_tick() every so often, just in
43  * case. It may be necessary to yield time to other applications in a
44  * cooperative-multitasking OS, or to check for player interrupts in an infinite
45  * loop.
46  */
47
48 /**
49  * SECTION:glk-types
50  * @short_description: Basic types used in Glk
51  * @include: libchimara/glk.h
52  *
53  * For simplicity, all the arguments used in Glk calls are of a very few types.
54  * <variablelist>
55  *  <varlistentry>
56  *    <term>32-bit unsigned integer</term>
57  *    <listitem><para>Unsigned integers are used wherever possible, which is
58  *    nearly everywhere. This type is called #glui32.</para></listitem>
59  *  </varlistentry>
60  *  <varlistentry>
61  *    <term>32-bit signed integer</term>
62  *    <listitem><para>This type is called #glsi32. Rarely used.</para>
63  *    </listitem>
64  *  </varlistentry>
65  *  <varlistentry>
66  *    <term>References to library objects</term>
67  *    <listitem><para>These are pointers to opaque C structures; each library
68  *    will use different structures, so you can not and should not try to
69  *    manipulate their contents. See <link 
70  *    linkend="chimara-Opaque-Objects">Opaque Objects</link>.</para></listitem>
71  *  </varlistentry>
72  *  <varlistentry>
73  *    <term>Pointer to one of the above types</term>
74  *    <listitem><para>Pointer to a structure which consists entirely of the
75  *    above types.</para></listitem>
76  *  </varlistentry>
77  *  <varlistentry>
78  *    <term><type>unsigned char</type></term> 
79  *    <listitem><para>This is used only for Latin-1 text characters; see 
80  *    <link linkend="chimara-Character-Encoding">Character Encoding</link>.
81  *    </para></listitem>
82  *  </varlistentry>
83  *  <varlistentry>
84  *    <term>Pointer to <type>char</type></term> 
85  *    <listitem><para>Sometimes this means a null-terminated string; sometimes
86  *    an unterminated buffer, with length as a separate #glui32 argument. The
87  *    documentation says which.</para></listitem>
88  *  </varlistentry>
89  *  <varlistentry>
90  *    <term>Pointer to <type>void</type></term> 
91  *    <listitem><para>When nothing else will do.</para></listitem>
92  *  </varlistentry>
93  * </variablelist>
94  */
95
96 /**
97  * SECTION:glk-opaque-objects
98  * @short_description: Complex objects in Glk
99  * @include: libchimara/glk.h
100  *
101  * Glk keeps track of a few classes of special objects. These are opaque to your
102  * program; you always refer to them using pointers to opaque C structures.
103  * 
104  * Currently, these classes are:
105  * <variablelist>
106  *  <varlistentry>
107  *    <term>Windows</term>
108  *    <listitem><para>Screen panels, used to input or output information.
109  *    </para></listitem>
110  *  </varlistentry>
111  *  <varlistentry>
112  *    <term>Streams</term>
113  *    <listitem><para>Data streams, to which you can input or output text.
114  *    </para>
115  *    <note><para>There are file streams and window streams, since you can
116  *    output data to windows or files.</para></note>
117  *    </listitem>
118  *  </varlistentry>
119  *  <varlistentry>
120  *    <term>File references</term>
121  *    <listitem><para>Pointers to files in permanent storage.</para>
122  *    <note><para>In Unix a file reference is a pathname; on the Mac, an
123  *    <type>FSSpec</type>. Actually there's a little more information included,
124  *    such as file type and whether it is a text or binary file.</para></note>
125  *    </listitem>
126  *  </varlistentry>
127  *  <varlistentry>
128  *    <term>Sound channels</term>
129  *    <listitem><para>Audio output channels.</para>
130  *    <note><para>Not all Glk libraries support sound.</para></note>
131  *    </listitem>
132  *  </varlistentry>
133  * </variablelist>
134  *
135  * <note><para>
136  * Note that there may be more object classes in future versions of the Glk API.
137  * </para></note>
138  * 
139  * When you create one of these objects, it is always possible that the creation
140  * will fail (due to lack of memory, or some other OS error.) When this happens,
141  * the allocation function will return %NULL (0) instead of a valid pointer. You
142  * should always test for this possibility.
143  * 
144  * %NULL is never the identifier of any object (window, stream, file reference,
145  * or sound channel). The value %NULL is often used to indicate <quote>no
146  * object</quote> or <quote>nothing</quote>, but it is not a valid reference. If
147  * a Glk function takes an object reference as an argument, it is illegal to
148  * pass in %NULL unless the function definition says otherwise.
149  * 
150  * The <filename class="headerfile">glk.h</filename> file defines types
151  * #winid_t, #strid_t, #frefid_t, #schanid_t to store references. These are
152  * pointers to struct #glk_window_struct, #glk_stream_struct, 
153  * #glk_fileref_struct, and #glk_schannel_struct respectively. It is, of course,
154  * illegal to pass one kind of pointer to a function which expects another.
155  * 
156  * <note><para>
157  * This is how you deal with opaque objects from a C program. If you are using
158  * Glk through a virtual machine, matters will probably be different. Opaque
159  * objects may be represented as integers, or as VM objects of some sort.
160  * </para></note></para>
161  * <refsect2 id="chimara-Rocks"><!-- Indeed it does. -->
162  * <title>Rocks</title>
163  * <para>
164  * Every one of these objects (window, stream, file reference, or sound channel)
165  * has a <quote>rock</quote> value. This is simply a 32-bit integer value which
166  * you provide, for your own purposes, when you create the object.
167  * </para>
168  * <note><para>The library &mdash; so to speak &mdash; stuffs this value under a
169  * rock for safe-keeping, and gives it back to you when you ask for it.
170  * </para></note>
171  * <note><para>If you don't know what to use the rocks for, provide 0 and forget
172  * about it.</para></note>
173  * </refsect2>
174  * <refsect2 id="chimara-Iterating-Through-Opaque-Objects">
175  * <title>Iteration Through Opaque Objects</title>
176  * <para>
177  * For each class of opaque objects, there is an iterate function, which you can
178  * use to obtain a list of all existing objects of that class. It takes the form
179  * |[
180  * CLASSid_t glk_CLASS_iterate(CLASSid_t obj, glui32 *rockptr);
181  * ]|
182  * ...where <code><replaceable>CLASS</replaceable></code> represents one of the
183  * opaque object classes. 
184  * </para>
185  * <note><para>
186  *   So, at the current time, these are the functions glk_window_iterate(),
187  *   glk_stream_iterate(), glk_fileref_iterate(), and glk_schannel_iterate().  
188  *   There may be more classes in future versions of the spec; they all behave
189  *   the same.
190  * </para></note>
191  * <para>
192  * Calling <code>glk_<replaceable>CLASS</replaceable>_iterate(%NULL, r)</code>
193  * returns the first object; calling 
194  * <code>glk_<replaceable>CLASS</replaceable>_iterate(obj, r)</code> returns
195  * the next object, until there aren't any more, at which time it returns %NULL.
196  * </para>
197  * <para>
198  * The @rockptr argument is a pointer to a location; whenever  
199  * <code>glk_<replaceable>CLASS</replaceable>_iterate()</code> returns an
200  * object, the object's rock is stored in the location <code>(*@rockptr)</code>.
201  * If you don't want the rocks to be returned, you may set @rockptr to %NULL.
202  * </para>
203  * <para>
204  * You usually use this as follows:
205  * |[
206  * obj = glk_CLASS_iterate(NULL, NULL);
207  * while (obj) {
208  *    /* ...do something with obj... *<!-- -->/
209  *    obj = glk_CLASS_iterate(obj, NULL);
210  * }
211  * ]|
212  * </para>
213  * <para>
214  * If you create or destroy objects inside this loop, obviously, the results are
215  * unpredictable. However it is always legal to call 
216  * <code>glk_<replaceable>CLASS</replaceable>_iterate(obj, r)</code> as long as
217  * @obj is a valid object id, or %NULL.
218  * </para>
219  * <para>
220  * The order in which objects are returned is entirely arbitrary. The library
221  * may even rearrange the order every time you create or destroy an object of
222  * the given class. As long as you do not create or destroy any object, the rule
223  * is that <code>glk_<replaceable>CLASS</replaceable>_iterate(obj, r)</code> has
224  * a fixed result, and iterating through the results as above will list every
225  * object exactly once. 
226  * </para>
227  * </refsect2>
228  */
229
230 /**
231  * SECTION:glk-gestalt
232  * @short_description: Testing Glk's capabilities
233  * @include: libchimara/glk.h
234  *
235  * The <quote>gestalt</quote> mechanism (cheerfully stolen from the Mac OS) is a
236  * system by which the Glk API can be upgraded without making your life
237  * impossible. New capabilities (graphics, sound, or so on) can be added without
238  * changing the basic specification. The system also allows for 
239  * <quote>optional</quote> capabilities &mdash; those which not all Glk library
240  * implementations will support &mdash; and allows you to check for their
241  * presence without trying to infer them from a version number.
242  * 
243  * The basic idea is that you can request information about the capabilities of
244  * the API, by calling the gestalt functions.
245  */
246
247 /**
248  * SECTION:glk-character-input
249  * @short_description: Waiting for a single keystroke
250  * @include: libchimara/glk.h
251  *
252  * You can request that the player hit a single key. See <link 
253  * linkend="chimara-Character-Input-Events">Character Input Events</link>.
254  * 
255  * If you use the basic text API, the character code which is returned can be
256  * any value from 0 to 255. The printable character codes have already been
257  * described. The remaining codes are typically control codes: <keycombo  
258  * action="simul"><keycap function="control">control</keycap>
259  * <keycap>A</keycap></keycombo> to <keycombo action="simul"><keycap 
260  * function="control">control</keycap><keycap>Z</keycap></keycombo> and a few
261  * others.
262  * 
263  * There are also a number of special codes, representing special keyboard
264  * keys, which can be returned from a char-input event. These are represented
265  * as 32-bit integers, starting with 4294967295 (0xFFFFFFFF) and working down.
266  * The special key codes are defined in the <filename 
267  * class="headerfile">glk.h</filename> file. They include one code for <keycap
268  * function="enter">return</keycap> or <keycap function="enter">enter</keycap>,
269  * one for <keycap function="delete">delete</keycap> or <keycap
270  * function="backspace">backspace</keycap>, twelve function keys, and one code
271  * for any key which has no Latin-1 or special code. The full list of key codes
272  * is included below.
273  * 
274  * Various implementations of Glk will vary widely in which characters the
275  * player can enter. The most obvious limitation is that some characters are
276  * mapped to others. For example, most keyboards return a <keycombo
277  * action="simul"><keycap function="control">control</keycap><keycap>I</keycap>
278  * </keycombo> code when the <keycap function="tab">tab</keycap> key is
279  * pressed. The Glk library, if it can recognize this at all, will generate a
280  * <keysym>%keycode_Tab</keysym> event (value 0xFFFFFFF7) when this occurs.
281  * Therefore, for these keyboards, no keyboard key will generate a <keycombo
282  * action="simul"><keycap function="control">control</keycap><keycap>I</keycap>
283  * </keycombo> event (value 9.) The Glk library will probably map many of the
284  * control codes to the other special keycodes.
285  * 
286  * <note><para>
287  *   On the other hand, the library may be very clever and discriminate between
288  *   <keycap>tab</keycap> and <keycombo action="simul"><keycap
289  *   function="control">control</keycap><keycap>I</keycap></keycombo>. This is
290  *   legal. The idea is, however, that if your program asks the player to
291  *   <quote><computeroutput>press the <keycap function="tab">tab</keycap>
292  *   key</computeroutput></quote>, you should check for a 
293  *   <keysym>%keycode_Tab</keysym> event as opposed to a <keycombo 
294  *   action="simul"><keycap function="control">control</keycap>
295  *   <keycap>I</keycap></keycombo> event.
296  * </para></note>
297  * 
298  * Some characters may not be enterable simply because they do not exist.
299  * 
300  * <note><para>
301  *   Not all keyboards have a <keycap function="home">home</keycap> or <keycap
302  *   function="end">end</keycap> key. A pen-based platform may not recognize
303  *   any control characters at all.
304  * </para></note>
305  * 
306  * Some characters may not be enterable because they are reserved for the
307  * purposes of the interface. For example, the Mac Glk library reserves the 
308  * <keycap function="tab">tab</keycap> key for switching between different Glk
309  * windows. Therefore, on the Mac, the library will never generate a
310  * <keysym>%keycode_Tab</keysym> event or a <keycombo action="simul">
311  * <keycap function="control">control</keycap><keycap>I</keycap></keycombo>
312  * event.
313  * 
314  * <note><para>
315  *   Note that the linefeed or <keycombo action="simul"><keycap  
316  *   function="control">control</keycap><keycap>J</keycap></keycombo> 
317  *   character, which is the only printable control character, is probably not
318  *   typable. This is because, in most libraries, it will be converted to
319  *   <keysym>%keycode_Return</keysym>. Again, you should check for
320  *   <keysym>%keycode_Return</keysym> if your program asks the player to 
321  *   <quote><computeroutput>press the <keycap function="enter">return</keycap>
322  *   key</computeroutput></quote>.
323  * </para></note>
324  * 
325  * <note><para>
326  *   The <keycap function="delete">delete</keycap> and <keycap
327  *   function="backspace">backspace</keycap> keys are merged into a single
328  *   keycode because they have such an astonishing history of being confused in
329  *   the first place... this spec formally waives any desire to define the
330  *   difference. Of course, a library is free to distinguish <keycap
331  *   function="delete">delete</keycap> and <keycap
332  *   function="backspace">backspace</keycap> during line input. This is when it
333  *   matters most; conflating the two during character input should not be a
334  *   large problem.
335  * </para></note>
336  *
337  * You can test for this by using the %gestalt_CharInput selector.
338  * 
339  * <note><para>
340  *   Glk porters take note: it is not a goal to be able to generate every
341  *   single possible key event. If the library says that it can generate a
342  *   particular keycode, then game programmers will assume that it is
343  *   available, and ask players to use it. If a <keysym>%keycode_Home</keysym>
344  *   event can only be generated by typing <keycombo action="seq"><keycap
345  *   function="escape">escape</keycap><keycombo action="simul"><keycap
346  *   function="control">control</keycap><keycap>A</keycap></keycombo>
347  *   </keycombo>, and the player does not know this, the player will be lost
348  *   when the game says <quote><computeroutput>Press the <keycap
349  *   function="home">home</keycap> key to see the next 
350  *   hint.</computeroutput></quote> It is better for the library to say that it
351  *   cannot generate a <keysym>%keycode_Home</keysym> event; that way the game
352  *   can detect the situation and ask the user to type <keycap>H</keycap>
353  *   instead.
354  * </para>
355  * <para>
356  *   Of course, it is better not to rely on obscure keys in any case. The arrow
357  *   keys and <keycap function="enter">return</keycap> are nearly certain to be
358  *   available; the others are of gradually decreasing reliability, and you
359  *   (the game programmer) should not depend on them. You must be certain to
360  *   check for the ones you want to use, including the arrow keys and <keycap
361  *   function="enter">return</keycap>, and be prepared to use different keys in
362  *   your interface if %gestalt_CharInput says they are not available.
363  * </para></note>
364  */
365
366 /**
367  * SECTION:glk-case
368  * @short_description: Changing the case of strings
369  * @include: libchimara/glk.h
370  *
371  * Glk has functions to manipulate the case of both Latin-1 and Unicode strings.
372  * One Latin-1 lowercase character corresponds to one uppercase character, and
373  * vice versa, so the Latin-1 functions act on single characters. The Unicode
374  * functions act on whole strings, since the length of the string may change.
375  */
376
377 /**
378  * SECTION:glk-window-opening
379  * @short_description: Creating new windows and closing them
380  * @include: libchimara/glk.h
381  *
382  * You can open a new window using glk_window_open() and close it again using
383  * glk_window_close().
384  */
385
386 /**
387  * SECTION:glk-window-constraints
388  * @short_description: Manipulating the size of a window
389  * @include: libchimara/glk.h
390  *
391  * There are library functions to change and to measure the size of a window.
392  */
393
394 /**
395  * SECTION:glk-window-types
396  * @short_description: Blank, pair, text grid, text buffer, and graphics windows
397  * @include: libchimara/glk.h
398  * 
399  * A technical description of all the window types, and exactly how they behave.
400  */
401
402 /**
403  * SECTION:glk-echo-streams
404  * @short_description: Creating a copy of a window's output
405  * @include: libchimara/glk.h
406  *
407  * Every window has an associated window stream; you print to the window by
408  * printing to this stream. However, it is possible to attach a second stream to
409  * a window. Any text printed to the window is also echoed to this second
410  * stream, which is called the window's <quote>echo stream.</quote>
411  * 
412  * Effectively, any call to glk_put_char() (or the other output commands) which
413  * is directed to the window's window stream, is replicated to the window's echo
414  * stream. This also goes for the style commands such as glk_set_style().
415  * 
416  * Note that the echoing is one-way. You can still print text directly to the
417  * echo stream, and it will go wherever the stream is bound, but it does not
418  * back up and appear in the window. 
419  *
420  * An echo stream can be of any type, even another window's window stream.
421  * 
422  * <note><para>
423  *   This would be somewhat silly, since it would mean that any text printed to
424  *   the window would be duplicated in another window. More commonly, you would
425  *   set a window's echo stream to be a file stream, in order to create a
426  *   transcript file from that window.
427  * </para></note>
428  *
429  * A window can only have one echo stream. But a single stream can be the echo
430  * stream of any number of windows, sequentially or simultaneously.
431  *
432  * If a window is closed, its echo stream remains open; it is not automatically
433  * closed. 
434  *
435  * <note><para>
436  *   Do not confuse the window's window stream with its echo stream. The window
437  *   stream is <quote>owned</quote> by the window, and dies with it. The echo
438  *   stream is merely temporarily associated with the window.
439  * </para></note>
440  * 
441  * If a stream is closed, and it is the echo stream of one or more windows,
442  * those windows are reset to not echo anymore. (So then calling
443  * glk_window_get_echo_stream() on them will return %NULL.) 
444  */
445
446 /**
447  * SECTION:glk-window-other
448  * @short_description: Miscellaneous functions for windows
449  * @include: libchimara/glk.h
450  *
451  * This section contains functions for windows that don't fit anywhere else.
452  */
453
454 /**
455  * SECTION:glk-events
456  * @short_description: Waiting for events
457  * @include: libchimara/glk.h
458  *
459  * As described in <link linkend="chimara-Your-Programs-Main-Function">Your
460  * Program's Main Function</link>, all player input is handed to your program by
461  * the glk_select() call, in the form of events. You should write at least one
462  * event loop to retrieve these events.
463  */
464
465 /**
466  * SECTION:glk-character-input-events
467  * @short_description: Events representing a single keystroke
468  * @include: libchimara/glk.h
469  *
470  * You can request character input from text buffer and text grid windows. See 
471  * %evtype_CharInput. There are separate functions for requesting Latin-1 input
472  * and Unicode input; see %gestalt_Unicode.
473  */
474
475 /**
476  * SECTION:glk-line-input-events
477  * @short_description: Events representing a line of user input
478  * @include: libchimara/glk.h
479  *
480  * You can request line input from text buffer and text grid windows. See
481  * %evtype_LineInput. There are separate functions for requesting Latin-1 input
482  * and Unicode input; see %gestalt_Unicode.
483  */
484
485 /**
486  * SECTION:glk-mouse-events
487  * @short_description: Events representing a mouse click
488  * @include: libchimara/glk.h
489  *
490  * On some platforms, Glk can recognize when the mouse (or other pointer) is 
491  * used to select a spot in a window. You can request mouse input only in text 
492  * grid windows and graphics windows.
493  * 
494  * A window can have mouse input and character/line input pending at the same
495  * time.
496  * 
497  * If the player clicks in a window which has a mouse input event pending,
498  * glk_select() will return an event whose type is %evtype_MouseInput. Again,
499  * once this happens, the request is complete, and you must request another if
500  * you want further mouse input.
501  * 
502  * In the event structure, @win tells what window the event came from.
503  * 
504  * In a text grid window, the @val1 and @val2 fields are the x and y coordinates
505  * of the character that was clicked on. 
506  * <note><para>So @val1 is the column, and @val2 is the row.</para></note>
507  * The top leftmost character is considered to be (0,0).
508  * 
509  * In a graphics window, they are the x and y coordinates of the pixel that was
510  * clicked on. Again, the top left corner of the window is (0,0).
511  * 
512  * <note><para>
513  *   Most mouse-based idioms define standard functions for mouse hits in text
514  *   windows &mdash; typically selecting or copying text. It is up to the
515  *   library to separate this from Glk mouse input. The library may choose to
516  *   select text when it is clicked normally, and cause Glk mouse events when
517  *   text is control-clicked. Or the other way around. Or it may be the
518  *   difference between clicking and double-clicking. Or the library may
519  *   reserve a particular mouse button, on a multi-button mouse. It may even
520  *   specify a keyboard key to be the "mouse button", referring to wherever the
521  *   mouse cursor is when the key is hit. Or some even more esoteric positioning
522  *   system. You need only know that the user can do it, or not.
523  * </para></note> 
524  * <note><para>
525  *   However, since different platforms will handle this issue differently, you
526  *   should be careful how you instruct the player in your program. Do not tell
527  *   the player to <quote>double-click</quote>, <quote>right-click</quote>, or
528  *   <quote>control-click</quote> in a window. The preferred term is <quote>to
529  *   touch the window</quote>, or a spot in the window.
530  * </para></note>
531  * <note><para>
532  *   Goofy, but preferred.
533  * </para></note>
534  */
535
536 /**
537  * SECTION:glk-timer-events
538  * @short_description: Events sent at fixed intervals
539  * @include: libchimara/glk.h
540  *
541  * You can request that an event be sent at fixed intervals, regardless of what
542  * the player does. Unlike input events, timer events can be tested for with
543  * glk_select_poll() as well as glk_select().
544  *
545  * It is possible that the library does not support timer events. You can check
546  * this with the %gestalt_Timer selector.
547  */
548  
549 /**
550  * SECTION:glk-streams
551  * @short_description: Input and output abstractions
552  * @include: libchimara/glk.h
553  *
554  * All character output in Glk is done through streams. Every window has an
555  * output stream associated with it. You can also write to files on disk; every
556  * open file is represented by an output stream as well.
557  *
558  * There are also input streams; these are used for reading from files on disk.
559  * It is possible for a stream to be both an input and an output stream. 
560  *
561  * <note><para>
562  *   Player input is done through line and character input events, not streams.
563  *   This is a small inelegance in theory. In practice, player input is slow and
564  *   things can interrupt it, whereas file input is immediate. If a network
565  *   extension to Glk were proposed, it would probably use events and not
566  *   streams, since network communication is not immediate.
567  * </para></note>
568  *
569  * It is also possible to create a stream that reads or writes to a buffer in
570  * memory.
571  * 
572  * Finally, there may be platform-specific types of streams, which are created
573  * before your program starts running. 
574  *
575  * <note><para>
576  *   For example, a program running under Unix may have access to standard input
577  *   as a stream, even though there is no Glk call to explicitly open standard
578  *   input. On the Mac, data in a Mac resource may be available through a
579  *   resource-reading stream.
580  * </para></note>
581  *
582  * You do not need to worry about the origin of such streams; just read or write
583  * them as usual. For information about how platform-specific streams come to
584  * be, see <link linkend="chimara-Startup-Options">Startup Options</link>.
585  * 
586  * A stream is opened with a particular file mode, see the 
587  * <code>filemode_</code> constants below.
588  *
589  * For information on opening streams, see the discussion of each specific type
590  * of stream in <link linkend="chimara-The-Types-of-Streams">The Types of
591  * Streams</link>. Remember that it is always possible that opening a stream
592  * will fail, in which case the creation function will return %NULL.
593  * 
594  * Each stream remembers two character counts, the number of characters printed
595  * to and read from that stream. The write-count is exactly one per 
596  * glk_put_char() call; it is figured before any platform-dependent character
597  * cookery. 
598  *
599  * <note><para>
600  *   For example, if a newline character is converted to 
601  *   linefeed-plus-carriage-return, the stream's count still only goes up by
602  *   one; similarly if an accented character is displayed as two characters.
603  * </para></note>
604  * 
605  * The read-count is exactly one per glk_get_char_stream() call, as long as the
606  * call returns an actual character (as opposed to an end-of-file token.) 
607  *
608  * Glk has a notion of the <quote>current (output) stream</quote>. If you print
609  * text without specifying a stream, it goes to the current output stream. The
610  * current output stream may be %NULL, meaning that there isn't one. It is
611  * illegal to print text to stream %NULL, or to print to the current stream when
612  * there isn't one.
613  *
614  * If the stream which is the current stream is closed, the current stream
615  * becomes %NULL. 
616  */
617  
618 /**
619  * SECTION:glk-print
620  * @short_description: Printing to streams
621  * @include: libchimara/glk.h
622  *
623  * You can print Latin-1 and Unicode characters, null-terminated strings, or
624  * buffers to any stream. The characters will be converted into the appropriate
625  * format for that stream.
626  */
627  
628 /**
629  * SECTION:glk-read
630  * @short_description: Reading from streams
631  * @include: libchimara/glk.h
632  *
633  * You can read Latin-1 or Unicode characters, buffers, or whole lines from any
634  * stream. The characters will be converted into the form in which you request
635  * them.
636  */
637  
638 /**
639  * SECTION:glk-closing-streams
640  * @short_description: Closing streams and retrieving their character counts
641  * @include: libchimara/glk.h
642  *
643  * When you close a Glk stream, you have the opportunity to examine the
644  * character counts &mdash; the number of characters written to or read from the
645  * stream.
646  */
647
648 /**
649  * SECTION:glk-stream-positions
650  * @short_description: Moving the read/write mark
651  * @include: libchimara/glk.h
652  *
653  * You can set the position of the read/write mark in a stream.
654  *
655  * <note><para>
656  *   Which makes one wonder why they're called <quote>streams</quote> in the
657  *   first place. Oh well.
658  * </para></note>
659  */
660
661 /**
662  * SECTION:glk-styles
663  * @short_description: Changing the appearance of printed text
664  * @include: libchimara/glk.h
665  *
666  * You can send style-changing commands to an output stream. After a style
667  * change, new text which is printed to that stream will be given the new style,
668  * whatever that means for the stream in question. For a window stream, the text
669  * will appear in that style. For a memory stream, style changes have no effect.
670  * For a file stream, if the machine supports styled text files, the styles may
671  * be written to the file; more likely the style changes will have no effect.
672  * 
673  * Styles are exclusive. A character is shown with exactly one style, not a 
674  * subset of the possible styles.
675  *
676  * <note><para>
677  *  Note that every stream and window has its own idea of the <quote>current 
678  *  style.</quote> Sending a style command to one window or stream does not
679  *  affect any others.
680  * </para></note>
681  * <note><para>
682  *  Except for a window's echo stream; see <link 
683  *  linkend="chimara-Echo-Streams">Echo Streams</link>.
684  * </para></note>
685  * 
686  * The styles are intended to distinguish meaning and use, not formatting. There
687  * is no standard definition of what each style will look like. That is left up
688  * to the Glk library, which will choose an appearance appropriate for the
689  * platform's interface and the player's preferences.
690  * 
691  * There are currently eleven styles defined. More may be defined in the future.
692  * 
693  * Styles may be distinguished on screen by font, size, color, indentation,
694  * justification, and other attributes. Note that some attributes (notably
695  * justification and indentation) apply to entire paragraphs. If possible and
696  * relevant, you should apply a style to an entire paragraph &mdash; call 
697  * glk_set_style() immediately after printing the newline at the beginning of
698  * the text, and do the same at the end.
699  * 
700  * <note><para>
701  *  For example, %style_Header may well be centered text. If you print 
702  *  <quote>Welcome to Victim (a short interactive mystery)</quote>, and only the
703  *  word <quote>Victim</quote> is in the %style_Header, the center-justification
704  *  attribute will be lost. Similarly, a block quote is usually indented on both
705  *  sides, but indentation is only meaningful when applied to an entire line or
706  *  paragraph, so block quotes should take up an entire paragraph. Contrariwise,
707  *  %style_Emphasized need not be used on an entire paragraph. It is often used
708  *  for single emphasized words in normal text, so you can expect that it will
709  *  appear properly that way; it will be displayed in italics or underlining, 
710  *  not center-justified or indented.
711  * </para></note> 
712  * 
713  * <note><para>
714  *  Yes, this is all a matter of mutual agreement between game authors and game
715  *  players. It's not fixed by this specification. That's natural language for
716  *  you.
717  * </para></note>
718  */
719
720 /**
721  * SECTION:glk-stylehints
722  * @short_description: Setting style hints
723  * @include: libchimara/glk.h
724  *
725  * There are no guarantees of how styles will look, but you can make 
726  * suggestions.
727  *
728  * Initially, no hints are set for any window type or style. Note that having no
729  * hint set is not the same as setting a hint with value 0.
730  * 
731  * These functions do <emphasis>not</emphasis> affect 
732  * <emphasis>existing</emphasis> windows. They affect the windows which you
733  * create subsequently. If you want to set hints for all your game windows, call
734  * glk_stylehint_set() before you start creating windows. If you want different
735  * hints for different windows, change the hints before creating each window.
736  * 
737  * <note><para>
738  *  This policy makes life easier for the interpreter. It knows everything about
739  *  a particular window's appearance when the window is created, and it doesn't
740  *  have to change it while the window exists.
741  * </para></note>
742  * 
743  * Hints are hints. The interpreter may ignore them, or give the player a choice
744  * about whether to accept them. Also, it is never necessary to set hints. You
745  * don't have to suggest that %style_Preformatted be fixed-width, or 
746  * %style_Emphasized be boldface or italic; they will have appropriate defaults.
747  * Hints are for situations when you want to <emphasis>change</emphasis> the 
748  * appearance of a style from what it would ordinarily be. The most common case
749  * when this is appropriate is for the styles %style_User1 and %style_User2.
750  * 
751  * There are currently ten style hints defined. More may be defined in the 
752  * future. 
753  * 
754  * Again, when passing a style hint to a Glk function, any value is actually 
755  * legal. If the interpreter does not recognize the stylehint value, it will 
756  * ignore it. 
757  * <note><para>
758  *  This policy allows for the future definition of style hints without breaking
759  *  old Glk libraries.
760  * </para></note> 
761  */
762
763 /**
764  * SECTION:glk-style-measure
765  * @short_description: Finding out how the library displays your style hints
766  * @include: libchimara/glk.h
767  *
768  * You can suggest the appearance of a window's style before the window is
769  * created; after the window is created, you can test the style's actual
770  * appearance. These functions do not test the style hints; they test the
771  * attribute of the style as it appears to the player.
772  *
773  * Note that although you cannot change the appearance of a window's styles
774  * after the window is created, the library can. A platform may support dynamic
775  * preferences, which allow the player to change text formatting while your
776  * program is running.
777  * <note><para>
778  *   Changes that affect window size (such as font size changes) will be
779  *   signalled by an %evtype_Arrange event. However, more subtle changes (such
780  *   as text color differences) are not signalled. If you test the appearance of
781  *   styles at the beginning of your program, you must keep in mind the
782  *   possibility that the player will change them later.
783  * </para></note>
784  */
785
786 /**
787  * SECTION:glk-stream-types
788  * @short_description: Window, memory, and file streams
789  * @include: libchimara/glk.h
790  *
791  * <refsect2 id="chimara-Window-Streams"><title>Window Streams</title>
792  * <para>
793  * Every window has an output stream associated with it. This is created
794  * automatically, with %filemode_Write, when you open the window. You get it
795  * with glk_window_get_stream().
796  * 
797  * A window stream cannot be closed with glk_stream_close(). It is closed
798  * automatically when you close its window with glk_window_close().
799  * 
800  * Only printable characters (including newline) may be printed to a window
801  * stream. See <link linkend="chimara-Character-Encoding">Character 
802  * Encoding</link>.
803  * </para>
804  * </refsect2>
805  * <refsect2 id="chimara-Memory-Streams"><title>Memory Streams</title>
806  * <para>
807  * You can open a stream which reads from or writes to a space in memory. See
808  * glk_stream_open_memory() and glk_stream_open_memory_uni(). When opening a
809  * memory stream, you specify a buffer to which the stream's output will be
810  * written, and its length @buflen.
811  *
812  * When outputting, if more than @buflen characters are written to the stream,
813  * all of them beyond the buffer length will be thrown away, so as not to
814  * overwrite the buffer. (The character count of the stream will still be
815  * maintained correctly. That is, it will count the number of characters written
816  * into the stream, not the number that fit into the buffer.)
817  *
818  * If the buffer is %NULL, or for that matter if @buflen is zero, then 
819  * <emphasis>everything</emphasis> written to the stream is thrown away. This
820  * may be useful if you are interested in the character count.
821  *
822  * When inputting, if more than @buflen characters are read from the stream, the
823  * stream will start returning -1 (signalling end-of-file.) If the buffer is 
824  * %NULL, the stream will always return end-of-file.
825  *
826  * The data is written to the buffer exactly as it was passed to the printing
827  * functions (glk_put_char(), etc.); input functions will read the data exactly
828  * as it exists in memory. No platform-dependent cookery will be done on it.
829  *
830  * <note><para>
831  *   You can write a disk file in text mode, but a memory stream is effectively
832  *   always in binary mode.
833  * </para></note>
834  * 
835  * Whether reading or writing, the contents of the buffer are undefined until
836  * the stream is closed. The library may store the data there as it is written,
837  * or deposit it all in a lump when the stream is closed. It is illegal to
838  * change the contents of the buffer while the stream is open.
839  * </para>
840  * </refsect2>
841  * <refsect2 id="chimara-File-Streams"><title>File Streams</title>
842  * <para>
843  * You can open a stream which reads from or writes to a disk file. See 
844  * glk_stream_open_file() and glk_stream_open_file_uni().
845  *
846  * The file may be written in text or binary mode; this is determined by the
847  * file reference you open the stream with. Similarly, platform-dependent
848  * attributes such as file type are determined by the file reference. See <link
849  * linkend="chimara-File-References">File References</link>.
850  * </para>
851  * </refsect2>
852  */
853  
854 /**
855  * SECTION:glk-stream-other
856  * @short_description: Miscellaneous functions for streams
857  * @include: libchimara/glk.h
858  *
859  * This section includes functions for streams that don't fit anywhere else.
860  */
861
862 /**
863  * SECTION:glk-fileref
864  * @short_description: A platform-independent way to refer to disk files
865  * @include: libchimara/glk.h
866  *
867  * You deal with disk files using file references. Each fileref is an opaque C
868  * structure pointer; see <link linkend="chimara-Opaque-Objects">Opaque 
869  * Objects</link>.
870  * 
871  * A file reference contains platform-specific information about the name and
872  * location of the file, and possibly its type, if the platform has a notion of
873  * file type. It also includes a flag indication whether the file is a text file
874  * or binary file. 
875  *
876  * <note><para>
877  *   Note that this is different from the standard C I/O library, in which you
878  *   specify text or binary mode when the file is opened.
879  * </para></note>
880  * 
881  * A fileref does not have to refer to a file which actually exists. You can
882  * create a fileref for a nonexistent file, and then open it in write mode to
883  * create a new file.
884  * 
885  * You always provide a usage argument when you create a fileref. The usage is a
886  * mask of constants (see below) to indicate the file type and the mode (text or
887  * binary.) These values are used when you create a new file, and also to filter
888  * file lists when the player is selecting a file to load. 
889  * 
890  * In general, you should use text mode if the player expects to read the file
891  * with a platform-native text editor; you should use binary mode if the file is
892  * to be read back by your program, or if the data must be stored exactly. Text
893  * mode is appropriate for %fileusage_Transcript; binary mode is appropriate for
894  * %fileusage_SavedGame and probably for %fileusage_InputRecord. %fileusage_Data
895  * files may be text or binary, depending on what you use them for. 
896  */
897  
898 /**
899  * SECTION:glk-fileref-types
900  * @short_description: Four different ways to create a file reference
901  * @include: libchimara/glk.h
902  *
903  * There are four different functions for creating a fileref, depending on how
904  * you wish to specify it. Remember that it is always possible that a fileref
905  * creation will fail and return %NULL.
906  */
907  
908 /**
909  * SECTION:glk-fileref-other
910  * @short_description: Miscellaneous functions for file references
911  * @include: libchimara/glk.h
912  *
913  * This section includes functions for file references that don't fit anywhere
914  * else.
915  */
916
917 /**
918  * SECTION:glk-image-resources
919  * @short_description: Graphics in Glk
920  * @include: libchimara/glk.h
921  *
922  * In accordance with this modern age, Glk provides for a modicum of graphical
923  * flair. It does not attempt to be a complete graphical toolkit. Those already
924  * exist. Glk strikes the usual uncomfortable balance between power, 
925  * portability, and ease of implementation: commands for arranging pre-supplied
926  * images on the screen and intermixed with text.
927  * 
928  * Graphics is an optional capability in Glk; not all libraries support 
929  * graphics. This should not be a surprise.
930  * 
931  * Most of the graphics commands in Glk deal with image resources. Your program
932  * does not have to worry about how images are stored. Everything is a resource,
933  * and a resource is referred to by an integer identifier. You may, for example,
934  * call a function to display image number 17. The format, loading, and 
935  * displaying of that image is entirely up to the Glk library for the platform
936  * in question.
937  * 
938  * Of course, it is also desirable to have a platform-independent way to store
939  * sounds and images. Blorb is the official resource-storage format of Glk. A
940  * Glk library does not have to understand Blorb, but it is more likely to
941  * understand Blorb than any other format.
942  *
943  * <note><para>
944  *   Glk does not specify the exact format of images, but Blorb does. Images in 
945  *   a Blorb archive must be PNG or JPEG files. More formats may be added if 
946  *   real-world experience shows it to be desirable. However, that is in the 
947  *   domain of the Blorb specification. The Glk spec, and Glk programming, will
948  *   not change.
949  * </para></note>
950  * 
951  * At present, images can only be drawn in graphics windows and text buffer 
952  * windows. In fact, a library may not implement both of these possibilities.
953  * You should test each with the %gestalt_DrawImage selector if you plan to use
954  * it. See <link linkend="chimara-Testing-for-Graphics-Capabilities">Testing for
955  * Graphics Capabilities</link>. 
956  */
957
958 /**
959  * SECTION:glk-graphics-windows
960  * @short_description: Drawing graphics in graphics windows
961  * @include: libchimara/glk.h
962  *
963  * A graphics window is a rectangular canvas of pixels, upon which you can draw
964  * images. The contents are entirely under your control. You can draw as many
965  * images as you like, at any positions &mdash; overlapping if you like. If the
966  * window is resized, you are responsible for redrawing everything. See <link
967  * linkend="wintype-Graphics">Graphics Windows</link>.
968  * 
969  * <note><para>
970  *   Note that graphics windows do not support a full set of object-drawing 
971  *   commands, nor can you draw text in them. That may be available in a future 
972  *   Glk extension. For now, it seems reasonable to limit the task to a single 
973  *   primitive, the drawing of a raster image. And then there's the ability to
974  *   fill a rectangle with a solid color &mdash; a small extension, and 
975  *   hopefully no additional work for the library, since it can already clear 
976  *   with arbitrary background colors. In fact, if glk_window_fill_rect() did 
977  *   not exist, an author could invent it &mdash; by briefly setting the
978  *   background color, erasing a rectangle, and restoring.
979  * </para></note>
980  * 
981  * If you call glk_image_draw() or glk_image_draw_scaled() in a graphics window,
982  * @val1 and @val2 are interpreted as X and Y coordinates. The image will be 
983  * drawn with its upper left corner at this position.
984  * 
985  * It is legitimate for part of the image to fall outside the window; the excess
986  * is not drawn. Note that these are signed arguments, so you can draw an image
987  * which falls outside the left or top edge of the window, as well as the right
988  * or bottom.
989  * 
990  * There are a few other commands which apply to graphics windows.
991  */
992
993 /**
994  * SECTION:glk-graphics-text
995  * @short_description: Drawing graphics inside or beside text
996  * @include: libchimara/glk.h
997  *
998  * A text buffer is a linear text stream. You can draw images in-line with this
999  * text. If you are familiar with HTML, you already understand this model. You
1000  * draw images with flags indicating alignment. The library takes care of
1001  * scrolling, resizing, and reformatting text buffer windows.
1002  *
1003  * If you call glk_image_draw() or glk_image_draw_scaled() in a text buffer
1004  * window, @val1 gives the image alignment. The @val2 argument is currently
1005  * unused, and should always be zero.
1006  *
1007  * The two <quote>margin</quote> alignments require some care. To allow proper 
1008  * positioning, images using %imagealign_MarginLeft and %imagealign_MarginRight 
1009  * must be placed at the beginning of a line. That is, you may only call 
1010  * glk_image_draw() (with these two alignments) in a window, if you have just 
1011  * printed a newline to the window's stream, or if the window is entirely empty.
1012  * If you margin-align an image in a line where text has already appeared, no 
1013  * image will appear at all.
1014  * 
1015  * Inline-aligned images count as <quote>text</quote> for the purpose of this 
1016  * rule.
1017  * 
1018  * You may have images in both margins at the same time.
1019  * 
1020  * It is also legal to have more than one image in the same margin (left or 
1021  * right.) However, this is not recommended. It is difficult to predict how text
1022  * will wrap in that situation, and libraries may err on the side of 
1023  * conservatism. 
1024  */
1025
1026 /**
1027  * SECTION:glk-graphics-testing
1028  * @short_description: Checking whether the library supports graphics
1029  * @include: libchimara/glk.h
1030  *
1031  * Before calling Glk graphics functions, you should use the gestalt selector
1032  * %gestalt_Graphics. To test for additional capabilities, you can also use the
1033  * %gestalt_DrawImage and %gestalt_GraphicsTransparency selectors.
1034  */
1035
1036 /**
1037  * SECTION:glk-sound-channels
1038  * @short_description: Creating new sound channels and closing them
1039  * @include: libchimara/glk.h
1040  */
1041
1042 /**
1043  * SECTION:glk-playing-sounds
1044  * @short_description: Producing noise
1045  * @include: libchimara/glk.h
1046  */
1047
1048 /**
1049  * SECTION:glk-sound-other
1050  * @short_description: Miscellaneous functions for sound channels
1051  * @include: libchimara/glk.h
1052  */
1053
1054 /**
1055  * SECTION:glk-sound-testing
1056  * @short_description: Checking whether the library supports sound
1057  * @include: libchimara/glk.h
1058  *
1059  * Before calling Glk sound functions, you should use the %gestalt_Sound
1060  * selector. To test for additional capabilities, you can use the 
1061  * %gestalt_SoundMusic, %gestalt_SoundVolume, and %gestalt_SoundNotify 
1062  * selectors.
1063  */
1064
1065 /**
1066  * SECTION:glk-creating-hyperlinks
1067  * @short_description: Printing text as a hyperlink
1068  * @include: libchimara/glk.h
1069  *
1070  * Some games may wish to mark up text in their windows with hyperlinks, which
1071  * can be selected by the player &mdash; most likely by mouse click. Glk allows
1072  * this in a manner similar to the way text styles are set.
1073  *
1074  * Hyperlinks are an optional capability in Glk.
1075  */
1076
1077 /**
1078  * SECTION:glk-accepting-hyperlinks
1079  * @short_description: Generating and catching hyperlink navigation events
1080  * @include: libchimara/glk.h
1081  */
1082
1083 /**
1084  * SECTION:glk-hyperlinks-testing
1085  * @short_description: Checking whether the library supports hyperlinks
1086  * @include: libchimara/glk.h
1087  *
1088  * Before calling Glk hyperlink functions, you should use the gestalt selectors
1089  * %gestalt_Hyperlinks and %gestalt_HyperlinkInput.
1090  */
1091  
1092 /**
1093  * SECTION:dispatch-interrogating
1094  * @short_description: Finding out what functions the Glk library exports
1095  * @include: libchimara/glk.h, libchimara/gi_dispa.h
1096  *
1097  * These are the ancilliary functions that let you enumerate.
1098  */
1099  
1100 /**
1101  * SECTION:dispatch-dispatching
1102  * @short_description: Dispatching the call to the Glk library
1103  * @include: libchimara/glk.h, libchimara/gi_dispa.h
1104  */
1105  
1106 /**
1107  * SECTION:dispatch-prototypes
1108  * @short_description: Querying Glk function prototypes
1109  * @include: libchimara/glk.h, libchimara/gi_dispa.h
1110  *
1111  * There are many possible ways to set up a #gluniversal_t array, and it's
1112  * illegal to call gidispatch_call() with an array which doesn't match the
1113  * function. Furthermore, some references are passed in, some passed out, and
1114  * some both. How do you know how to handle the argument list?
1115  * 
1116  * One possibility is to recognize each function selector, and set up the
1117  * arguments appropriately. However, this entails writing special code for each
1118  * Glk function; which is exactly what we don't want to do.
1119  * 
1120  * Instead, you can call gidispatch_prototype(). 
1121  */
1122
1123 /**
1124  * SECTION:dispatch-library-functions
1125  * @short_description: Platform-dependent dispatch layer functions
1126  * @include: libchimara/glk.h, libchimara/gi_dispa.h
1127  *
1128  * Ideally, the three layers &mdash; program, dispatch layer, Glk library
1129  * &mdash; would be completely modular; each would refer only to the layers
1130  * beneath it. Sadly, there are a few places where the library must notify the
1131  * program that something has happened. Worse, these situations are only
1132  * relevant to programs which use the dispatch layer, and then only some of
1133  * those.
1134  * 
1135  * Since C is uncomfortable with the concept of calling functions which may not
1136  * exist, Glk handles this with call-back function pointers. The program can
1137  * pass callbacks in to the library; if it does, the library will call them, and
1138  * if not, the library doesn't try.
1139  * 
1140  * These callbacks are optional, in the sense that the program may or may not
1141  * set them. However, any library which wants to interoperate with the dispatch
1142  * layer must <emphasis>allow</emphasis> the program to set them; it is the
1143  * program's choice. The library does this by implementing
1144  * <code>set_registry functions</code> &mdash; the functions to which the
1145  * program passes its callbacks.
1146  * 
1147  * <note><para>
1148  *   Even though these callbacks and the functions to set them are declared in
1149  *   <filename class="headerfile">gi_dispa.h</filename>, they are not defined in
1150  *   <filename>gi_dispa.c</filename>. The dispatch layer merely coordinates
1151  *   them. The program defines the callback functions; the library calls them.
1152  * </para></note>
1153  */
1154
1155 /** 
1156  * SECTION:blorb-program
1157  * @short_description: How to use the Blorb layer in your program
1158  * @include: libchimara/glk.h, libchimara/gi_blorb.h
1159  *
1160  * If you wish your program to load its resources from a Blorb file, you need to
1161  * find and open that file in your startup code. (See <link 
1162  * linkend="chimara-Startup-Options">Startup Options</link>.) Each platform will
1163  * have appropriate functions available for finding startup data. Be sure to
1164  * open the file in binary mode, not text mode. Once you have opened the file as
1165  * a Glk stream, pass it to giblorb_set_resource_map().
1166  *
1167  * If you do not call giblorb_set_resource_map() in your startup code, or if it
1168  * fails, the library is left to its own devices for finding resources. Some
1169  * libraries may try to load resources from individual files &mdash; 
1170  * <filename>PIC1</filename>, <filename>PIC2</filename>, 
1171  * <filename>PIC3</filename>, and so on. (See the Blorb specification for more 
1172  * on this approach.) Other libraries will not have any other loading mechanism
1173  * at all; no resources will be available. 
1174  */
1175
1176 /**
1177  * SECTION:blorb-layer
1178  * @short_description: The platform-independent functions in the Blorb layer
1179  * @include: libchimara/glk.h, libchimara/gi_blorb.h
1180  *
1181  * These are the functions which are implemented in 
1182  * <filename>gi_blorb.c</filename>. They will be compiled into the library, but
1183  * they are the same on every platform. In general, only the library needs to
1184  * call these functions. The Glk program should allow the library to do all the
1185  * resource handling.
1186  */ 
1187  
1188 /** 
1189  * SECTION:blorb-errors
1190  * @short_description: Error codes returned by the Blorb layer functions
1191  * @include: libchimara/glk.h, libchimara/gi_blorb.h
1192  *
1193  * All Blorb layer functions, including giblorb_set_resource_map(), return the
1194  * following error codes.
1195  */
1196
1197 /**
1198  * SECTION:glkext-startup
1199  * @short_description: Parsing startup options
1200  * @include: libchimara/glk.h, libchimara/glkstart.h
1201  *
1202  * This section describes an extension to Glk for parsing command-line startup
1203  * options. It was written by Andrew Plotkin for the Glk libraries CheapGlk and
1204  * GlkTerm. 
1205  *
1206  * When you compile a Glk program, you may define a function called 
1207  * <function>glkunix_startup_code&lpar;&rpar;</function>, and an array 
1208  * <code>glkunix_arguments[]</code>. These set up various Unix-specific options
1209  * used by the Glk library. There is a sample 
1210  * <quote><filename>glkstart.c</filename></quote> file included in this package;
1211  * you should modify it to your needs.
1212  * 
1213  * |[ extern glkunix_argumentlist_t glkunix_arguments[]; ]|
1214  *  
1215  * The <code>glkunix_arguments[]</code> array is a list of command-line 
1216  * arguments that your program can accept. The library will sort these out of 
1217  * the command line and pass them on to your code.
1218  */
1219
1220 /**
1221  * SECTION:glkext-unix
1222  * @short_description: Unix-specific functions
1223  * @include: libchimara/glk.h, libchimara/glkstart.h
1224  *
1225  * This section describes an extension to Glk for various Unix functions. It was
1226  * written by Andrew Plotkin for the Glk libraries CheapGlk and GlkTerm.
1227  *
1228  * You can put other startup code in glkunix_startup_code(). This should
1229  * generally be limited to finding and opening data files. There are a few Unix
1230  * Glk library functions which are convenient for this purpose.
1231  */
1232  
1233 /*---------------- TYPES AND CONSTANTS FROM GLK.H ----------------------------*/
1234
1235 /**
1236  * glui32:
1237  *
1238  * A 32-bit unsigned integer type, used wherever possible in Glk.
1239  */
1240  
1241 /**
1242  * glsi32:
1243  *
1244  * A 32-bit signed integer type, rarely used.
1245  */
1246
1247 /**
1248  * GLK_MODULE_UNICODE:
1249  *
1250  * If this preprocessor symbol is defined, so are all the Unicode functions and
1251  * constants (see %gestalt_Unicode). If not, not.
1252  */
1253
1254 /**
1255  * GLK_MODULE_IMAGE:
1256  *
1257  * If you are writing a C program, there is an additional complication. A
1258  * library which does not support graphics may not implement the graphics
1259  * functions at all. Even if you put gestalt tests around your graphics calls,
1260  * you may get link-time errors. If the <filename
1261  * class="headerfile">glk.h</filename> file is so old that it does not declare
1262  * the graphics functions and constants, you may even get compile-time errors.
1263  *
1264  * To avoid this, you can perform a preprocessor test for the existence of
1265  * %GLK_MODULE_IMAGE. If this is defined, so are all the functions and constants
1266  * described in this section. If not, not.
1267  *
1268  * <note><para>
1269  *   To be extremely specific, there are two ways this can happen. If the 
1270  *   <filename class="headerfile">glk.h</filename> file that comes with the
1271  *   library is too old to have the graphics declarations in it, it will of
1272  *   course lack %GLK_MODULE_IMAGE as well. If the <filename 
1273  *   class="headerfile">glk.h</filename> file is recent, but the library is old,
1274  *   the definition of %GLK_MODULE_IMAGE should be removed from <filename 
1275  *   class="headerfile">glk.h</filename>, to avoid link errors. This is not a
1276  *   great solution. A better one is for the library to implement the graphics
1277  *   functions as stubs that do nothing (or cause run-time errors). Since no
1278  *   program will call the stubs without testing %gestalt_Graphics, this is
1279  *   sufficient.
1280  * </para></note>
1281  */
1282
1283 /**
1284  * GLK_MODULE_SOUND:
1285  *
1286  * If you are writing a C program, there is an additional complication. A 
1287  * library which does not support sound may not implement the sound functions at
1288  * all. Even if you put gestalt tests around your sound calls, you may get 
1289  * link-time errors. If the <filename class="headerfile">glk.h</filename> file 
1290  * is so old that it does not declare the sound functions and constants, you may
1291  * even get compile-time errors.
1292  * 
1293  * To avoid this, you can perform a preprocessor test for the existence of
1294  * %GLK_MODULE_SOUND. If this is defined, so are all the functions and constants
1295  * described in this section. If not, not.
1296  */ 
1297  
1298 /**
1299  * GLK_MODULE_HYPERLINKS:
1300  * 
1301  * If you are writing a C program, you can perform a preprocessor test for the
1302  * existence of %GLK_MODULE_HYPERLINKS. If this is defined, so are all the
1303  * functions and constants described in this section. If not, not.
1304  */
1305
1306 /**
1307  * winid_t:
1308  *
1309  * Opaque structure representing a Glk window. It has no user-accessible 
1310  * members.
1311  */
1312  
1313 /**
1314  * strid_t:
1315  *
1316  * Opaque structure representing an input or output stream. It has no
1317  * user-accessible members.
1318  */
1319  
1320 /**
1321  * frefid_t:
1322  * 
1323  * Opaque structure representing a file reference. It has no user-accessible
1324  * members.
1325  */
1326
1327 /**
1328  * schanid_t:
1329  * 
1330  * Opaque structure representing a sound channel. It has no user-accessible
1331  * members.
1332  */
1333   
1334 /**
1335  * gestalt_Version:
1336  *
1337  * For an example of the gestalt mechanism, consider the selector
1338  * %gestalt_Version. If you do
1339  * |[
1340  * glui32 res;
1341  * res = glk_gestalt(gestalt_Version, 0);
1342  * ]|
1343  * <code>res</code> will be set to a 32-bit number which encodes the version of
1344  * the Glk spec which the library implements. The upper 16 bits stores the major
1345  * version number; the next 8 bits stores the minor version number; the low 8 
1346  * bits stores an even more minor version number, if any.
1347  *
1348  * <note><para>
1349  *   So the version number 78.2.11 would be encoded as 0x004E020B.
1350  * </para></note>
1351  *
1352  * The current Glk specification version is 0.7.0, so this selector will return
1353  * 0x00000700.
1354  *
1355  * |[
1356  * glui32 res;
1357  * res = glk_gestalt_ext(gestalt_Version, 0, NULL, 0);
1358  * ]|
1359  * does exactly the same thing. Note that, in either case, the second argument 
1360  * is not used; so you should always pass 0 to avoid future surprises.
1361  */
1362
1363 /**
1364  * gestalt_CharInput:
1365  *
1366  * If you set <code>ch</code> to a character code, or a special code (from
1367  * 0xFFFFFFFF down), and call
1368  * |[
1369  * glui32 res;
1370  * res = glk_gestalt(gestalt_CharInput, ch);
1371  * ]|
1372  * then <code>res</code> will be %TRUE (1) if that character can be typed by
1373  * the player in character input, and %FALSE (0) if not. See <link
1374  * linkend="chimara-Character-Input">Character Input</link>.
1375  */
1376
1377 /**
1378  * gestalt_LineInput:
1379  *
1380  * If you set <code>ch</code> to a character code, and call
1381  * |[
1382  * glui32 res;
1383  * res = glk_gestalt(gestalt_LineInput, ch);
1384  * ]|
1385  * then <code>res</code> will be %TRUE (1) if that character can be typed by the
1386  * player in line input, and %FALSE (0) if not. Note that if <code>ch</code> is 
1387  * a nonprintable Latin-1 character (0 to 31, 127 to 159), then this is 
1388  * guaranteed to return %FALSE. See <link linkend="chimara-Line-Input">Line
1389  * Input</link>.
1390  */
1391
1392 /**
1393  * gestalt_CharOutput:
1394  *
1395  * If you set <code>ch</code> to a character code (Latin-1 or higher), and call
1396  * |[
1397  * glui32 res, len;
1398  * res = glk_gestalt_ext(gestalt_CharOutput, ch, &amp;len, 1);
1399  * ]|
1400  * then <code>res</code> will be one of %gestalt_CharOutput_CannotPrint,
1401  * %gestalt_CharOutput_ExactPrint, or %gestalt_CharOutput_ApproxPrint (see 
1402  * below.)
1403  * 
1404  * In all cases, <code>len</code> (the #glui32 value pointed at by the third
1405  * argument) will be the number of actual glyphs which will be used to represent
1406  * the character. In the case of %gestalt_CharOutput_ExactPrint, this will 
1407  * always be 1; for %gestalt_CharOutput_CannotPrint, it may be 0 (nothing 
1408  * printed) or higher; for %gestalt_CharOutput_ApproxPrint, it may be 1 or 
1409  * higher. This information may be useful when printing text in a fixed-width 
1410  * font.
1411  *
1412  * <note><para>
1413  *   As described in <link linkend="chimara-Other-API-Conventions">Other API
1414  *   Conventions</link>, you may skip this information by passing %NULL as the
1415  *   third argument in glk_gestalt_ext(), or by calling glk_gestalt() instead.
1416  * </para></note>
1417  *
1418  * This selector will always return %gestalt_CharOutput_CannotPrint if 
1419  * <code>ch</code> is an unprintable eight-bit character (0 to 9, 11 to 31, 127 
1420  * to 159.)
1421  *
1422  * <note><para>
1423  *   Make sure you do not get confused by signed byte values. If you set a
1424  *   <quote><type>char</type></quote> variable <code>ch</code> to 0xFE, the 
1425  *   small-thorn character (&thorn;), and then call
1426  *   |[ res = glk_gestalt(gestalt_CharOutput, ch); ]|
1427  *   then (by the definition of C/C++) <code>ch</code> will be sign-extended to
1428  *   0xFFFFFFFE, which is not a legitimate character, even in Unicode. You 
1429  *   should write
1430  *   |[ res = glk_gestalt(gestalt_CharOutput, (unsigned char)ch); ]|
1431  *   instead.
1432  * </para></note>
1433  * <note><para>
1434  *   Unicode includes the concept of non-spacing or combining characters, which 
1435  *   do not represent glyphs; and double-width characters, whose glyphs take up
1436  *   two spaces in a fixed-width font. Future versions of this spec may 
1437  *   recognize these concepts by returning a <code>len</code> of 0 or 2 when
1438  *   %gestalt_CharOutput_ExactPrint is used. For the moment, we are adhering to 
1439  *   a policy of <quote>simple stuff first</quote>.
1440  * </para></note>
1441  */
1442  
1443 /**
1444  * gestalt_CharOutput_CannotPrint:
1445  *
1446  * When the %gestalt_CharOutput selector returns this for a character, the
1447  * character cannot be meaningfully printed. If you try, the player may see
1448  * nothing, or may see a placeholder.
1449  */
1450
1451 /**
1452  * gestalt_CharOutput_ApproxPrint:
1453  *
1454  * When the %gestalt_CharOutput selector returns this for a character, the 
1455  * library will print some approximation of the character. It will be more or 
1456  * less right, but it may not be precise, and it may not be distinguishable from
1457  * other, similar characters. (Examples: 
1458  * <quote><computeroutput>ae</computeroutput></quote> for the one-character
1459  * <quote>&aelig;</quote> ligature, 
1460  * <quote><computeroutput>e</computeroutput></quote> for 
1461  * <quote>&egrave;</quote>, <quote><computeroutput>|</computeroutput></quote> 
1462  * for a broken vertical bar (&brvbar;).)
1463  */
1464  
1465 /**
1466  * gestalt_CharOutput_ExactPrint:
1467  *
1468  * When the %gestalt_CharOutput selector returns this for a character, the
1469  * character will be printed exactly as defined.
1470  */
1471
1472 /**
1473  * gestalt_MouseInput:
1474  *
1475  * You can test whether mouse input is supported with the %gestalt_MouseInput 
1476  * selector.
1477  * |[ res = glk_gestalt(gestalt_MouseInput, windowtype); ]|
1478  * This will return %TRUE (1) if windows of the given type support mouse input.
1479  * If this returns %FALSE (0), it is still legal to call
1480  * glk_request_mouse_event(), but it will have no effect, and you will never get
1481  * mouse events.
1482  */ 
1483  
1484 /**
1485  * gestalt_Timer:
1486  *
1487  * You can test whether the library supports timer events:
1488  * |[ res = glk_gestalt(gestalt_Timer, 0); ]|
1489  * This returns 1 if timer events are supported, and 0 if they are not.
1490  */
1491
1492 /**
1493  * gestalt_Graphics:
1494  * 
1495  * Before calling Glk graphics functions, you should use the following gestalt
1496  * selector:
1497  * |[
1498  * glui32 res;
1499  * res = glk_gestalt(gestalt_Graphics, 0);
1500  * ]|
1501  * This returns 1 if the overall suite of graphics functions is available. This
1502  * includes glk_image_draw(), glk_image_draw_scaled(), glk_image_get_info(),
1503  * glk_window_erase_rect(), glk_window_fill_rect(),
1504  * glk_window_set_background_color(), and glk_window_flow_break(). It also
1505  * includes the capability to create graphics windows.
1506  * 
1507  * If this selector returns 0, you should not try to call these functions. They
1508  * may have no effect, or they may cause a run-time error. If you try to create
1509  * a graphics window, you will get %NULL. 
1510  */
1511
1512 /**
1513  * gestalt_DrawImage:
1514  * 
1515  * This selector returns 1 if images can be drawn in windows of the given type. 
1516  * If it returns 0, glk_image_draw() will fail and return %FALSE. You should 
1517  * test %wintype_Graphics and %wintype_TextBuffer separately, since libraries 
1518  * may implement both, neither, or only one.  
1519  */
1520
1521 /**
1522  * gestalt_Sound:
1523  *
1524  * You can test whether the library supports sound: 
1525  * |[
1526  * glui32 res;
1527  * res = glk_gestalt(gestalt_Sound, 0);
1528  * ]|
1529  * This returns 1 if the overall suite of sound functions is available. This 
1530  * includes glk_schannel_create(), glk_schannel_destroy(), 
1531  * glk_schannel_iterate(), glk_schannel_get_rock(), glk_schannel_play(),
1532  * glk_schannel_play_ext(), glk_schannel_stop(), glk_schannel_set_volume(), and
1533  * glk_sound_load_hint().
1534  *
1535  * If this selector returns 0, you should not try to call these functions. They 
1536  * may have no effect, or they may cause a run-time error. 
1537  */
1538
1539 /**
1540  * gestalt_SoundVolume:
1541  *
1542  * You can test whether the library supports setting the volume of sound 
1543  * channels: 
1544  * |[
1545  * glui32 res;
1546  * res = glk_gestalt(gestalt_SoundVolume, 0);
1547  * ]|
1548  * This selector returns 1 if the glk_schannel_set_volume() function works. If 
1549  * it returns zero, glk_schannel_set_volume() has no effect.     
1550  */
1551
1552 /**
1553  * gestalt_SoundNotify:
1554  *
1555  * You can test whether the library supports sound notification events:
1556  * |[
1557  * glui32 res;
1558  * res = glk_gestalt(gestalt_SoundNotify, 0);
1559  * ]| 
1560  * This selector returns 1 if the library supports sound notification events. If
1561  * it returns zero, you will never get such events. 
1562  */
1563
1564 /**
1565  * gestalt_Hyperlinks:
1566  *
1567  * You can test whether the library supports hyperlinks:
1568  * |[ 
1569  * glui32 res;
1570  * res = glk_gestalt(gestalt_Hyperlinks, 0); 
1571  * ]|
1572  * This returns 1 if the overall suite of hyperlinks functions is available.
1573  * This includes glk_set_hyperlink(), glk_set_hyperlink_stream(),
1574  * glk_request_hyperlink_event(), glk_cancel_hyperlink_event().
1575  *
1576  * If this selector returns 0, you should not try to call these functions. They
1577  * may have no effect, or they may cause a run-time error.
1578  */
1579
1580 /**
1581  * gestalt_HyperlinkInput:
1582  *
1583  * You can test whether hyperlinks are supported with the 
1584  * %gestalt_HyperlinkInput selector:
1585  * |[ res = glk_gestalt(gestalt_HyperlinkInput, windowtype); ]|
1586  * This will return %TRUE (1) if windows of the given type support hyperlinks.
1587  * If this returns %FALSE (0), it is still legal to call glk_set_hyperlink() and
1588  * glk_request_hyperlink_event(), but they will have no effect, and you will
1589  * never get hyperlink events.
1590  */
1591
1592 /** 
1593  * gestalt_SoundMusic:
1594  *
1595  * You can test whether music resources are supported:
1596  * |[ res = glk_gestalt(gestalt_SoundMusic, 0); ]|
1597  * This returns 1 if the library is capable of playing music sound resources. If 
1598  * it returns 0, only sampled sounds can be played.
1599  * <note><para>
1600  *   <quote>Music sound resources</quote> means MOD songs &mdash; the only music
1601  *   format that Blorb currently supports. The presence of this selector is, of 
1602  *   course, an ugly hack. It is a concession to the current state of the Glk 
1603  *   libraries, some of which can handle AIFF but not MOD sounds.
1604  * </para></note>
1605  */ 
1606   
1607 /**
1608  * gestalt_GraphicsTransparency:
1609  *
1610  * This returns 1 if images with alpha channels can actually be drawn with the
1611  * appropriate degree of transparency. If it returns 0, the alpha channel is
1612  * ignored; fully transparent areas will be drawn in an implementation-defined
1613  * color.
1614  * <note><para>
1615  *   The JPEG format does not support transparency or alpha channels; the PNG 
1616  *   format does.
1617  * </para></note>
1618  */
1619
1620 /**
1621  * gestalt_Unicode:
1622  *
1623  * The basic text functions will be available in every Glk library. The Unicode
1624  * functions may or may not be available. Before calling them, you should use
1625  * the following gestalt selector:
1626  * |[
1627  * glui32 res;
1628  * res = glk_gestalt(gestalt_Unicode, 0);
1629  * ]|
1630  * 
1631  * This returns 1 if the Unicode functions are available. If it returns 0, you
1632  * should not try to call them. They may print nothing, print gibberish, or
1633  * cause a run-time error. The Unicode functions include
1634  * glk_buffer_to_lower_case_uni(), glk_buffer_to_upper_case_uni(),  
1635  * glk_buffer_to_title_case_uni(), glk_put_char_uni(), glk_put_string_uni(),
1636  * glk_put_buffer_uni(), glk_put_char_stream_uni(), glk_put_string_stream_uni(),
1637  * glk_put_buffer_stream_uni(), glk_get_char_stream_uni(),
1638  * glk_get_buffer_stream_uni(), glk_get_line_stream_uni(),
1639  * glk_request_char_event_uni(), glk_request_line_event_uni(),
1640  * glk_stream_open_file_uni(), glk_stream_open_memory_uni().
1641  * 
1642  * If you are writing a C program, there is an additional complication. A
1643  * library which does not support Unicode may not implement the Unicode
1644  * functions at all. Even if you put gestalt tests around your Unicode calls,
1645  * you may get link-time errors. If the 
1646  * <filename class="headerfile">glk.h</filename> file is so old that it does not
1647  * declare the Unicode functions and constants, you may even get compile-time
1648  * errors.
1649  * 
1650  * To avoid this, you can perform a preprocessor test for the existence of
1651  * #GLK_MODULE_UNICODE. 
1652  */
1653  
1654 /**
1655  * evtype_None:
1656  *
1657  * No event. This is a placeholder, and glk_select() never returns it.
1658  */
1659
1660 /**
1661  * evtype_Timer:
1662  *
1663  * An event that repeats at fixed intervals. See <link 
1664  * linkend="chimara-Timer-Events">Timer Events</link>.
1665  */
1666  
1667 /**
1668  * evtype_CharInput:
1669  *
1670  * A keystroke event in a window. See <link 
1671  * linkend="chimara-Character-Input-Events">Character Input Events</link>.
1672  *
1673  * If a window has a pending request for character input, and the player hits a
1674  * key in that window, glk_select() will return an event whose type is
1675  * %evtype_CharInput. Once this happens, the request is complete; it is no 
1676  * longer pending. You must call glk_request_char_event() or
1677  * glk_request_char_event_uni() if you want another character from that window.
1678  * 
1679  * In the event structure, @win tells what window the event came from. @val1 
1680  * tells what character was entered; this will be a character code, or a special
1681  * keycode. (See <link linkend="chimara-Character-Input">Character 
1682  * Input</link>.) If you called glk_request_char_event(), @val1 will be in 
1683  * 0..255, or else a special keycode. In any case, @val2 will be 0.
1684  */
1685
1686 /**
1687  * evtype_LineInput:
1688  *
1689  * A full line of input completed in a window. See <link 
1690  * linkend="chimara-Line-Input-Events">Line Input Events</link>.
1691  *
1692  * If a window has a pending request for line input, and the player hits
1693  * <keycap>enter</keycap> in that window (or whatever action is appropriate to
1694  * enter his input), glk_select() will return an event whose type is
1695  * %evtype_LineInput. Once this happens, the request is complete; it is no 
1696  * longer pending. You must call glk_request_line_event() if you want another 
1697  * line of text from that window.
1698  * 
1699  * In the event structure, @win tells what window the event came from. @val1 
1700  * tells how many characters were entered. @val2 will be 0. The characters
1701  * themselves are stored in the buffer specified in the original
1702  * glk_request_line_event() or glk_request_line_event_uni() call. 
1703  *
1704  * <note><para>There is no null terminator stored in the buffer.</para></note>
1705  * 
1706  * It is illegal to print anything to a window which has line input pending. 
1707  *
1708  * <note><para>
1709  *   This is because the window may be displaying and editing the player's 
1710  *   input, and printing anything would make life unnecessarily complicated for
1711  *   the library.
1712  * </para></note>
1713  */
1714
1715 /**
1716  * evtype_MouseInput:
1717  *
1718  * A mouse click in a window. See <link 
1719  * linkend="chimara-Mouse-Input-Events">Mouse Input Events</link>.
1720  */
1721  
1722 /**
1723  * evtype_Arrange:
1724  *
1725  * An event signalling that the sizes of some windows have changed. 
1726  * 
1727  * Some platforms allow the player to resize the Glk window during play. This 
1728  * will naturally change the sizes of your windows. If this occurs, then
1729  * immediately after all the rearrangement, glk_select() will return an event
1730  * whose type is %evtype_Arrange. You can use this notification to redisplay the
1731  * contents of a graphics or text grid window whose size has changed.
1732  *
1733  * <note><para>
1734  *   The display of a text buffer window is entirely up to the library, so you
1735  *   don't need to worry about those.
1736  * </para></note>
1737  * 
1738  * In the event structure, @win will be %NULL if all windows are affected. If 
1739  * only some windows are affected, @win will refer to a window which contains 
1740  * all the affected windows. @val1 and @val2 will be 0.
1741  *
1742  * <note><para>
1743  *   You can always play it safe, ignore @win, and redraw every graphics and 
1744  *   text grid window.
1745  * </para></note>
1746  *
1747  * An arrangement event is guaranteed to occur whenever the player causes any
1748  * window to change size, as measured by its own metric. 
1749  *
1750  * <note><para>
1751  *   Size changes caused by you &mdash; for example, if you open, close, or 
1752  *   resize a window &mdash; do not trigger arrangement events. You must be 
1753  *   aware of the effects of your window management, and redraw the windows that
1754  *   you affect.
1755  * </para></note>
1756  * 
1757  * <note><para>
1758  *   It is possible that several different player actions can cause windows to
1759  *   change size. For example, if the player changes the screen resolution, an
1760  *   arrangement event might be triggered. This might also happen if the player
1761  *   changes his display font to a different size; the windows would then be
1762  *   different <quote>sizes</quote> in the metric of rows and columns, which is
1763  *   the important metric and the only one you have access to.
1764  * </para></note>
1765  * 
1766  * Arrangement events, like timer events, can be returned by glk_select_poll().
1767  * But this will not occur on all platforms. You must be ready to receive an
1768  * arrangement event when you call glk_select_poll(), but it is possible that it
1769  * will not arrive until the next time you call glk_select(). 
1770  *
1771  * <note><para>
1772  *   This is because on some platforms, window resizing is handled as part of
1773  *   player input; on others, it can be triggered by an external process such as 
1774  *   a window manager.
1775  * </para></note>
1776  */
1777
1778 /**
1779  * evtype_Redraw:
1780  *
1781  * An event signalling that graphics windows must be redrawn.
1782  *
1783  * On platforms that support graphics, it is possible that the contents of a
1784  * graphics window will be lost, and have to be redrawn from scratch. If this
1785  * occurs, then glk_select() will return an event whose type is %evtype_Redraw.
1786  *
1787  * In the event structure, @win will be %NULL if all windows are affected. If 
1788  * only some windows are affected, @win will refer to a window which contains 
1789  * all the affected windows. @val1 and @val2 will be 0.
1790  *
1791  * <note><para>
1792  *   You can always play it safe, ignore @win, and redraw every graphics window.
1793  * </para></note>
1794  *
1795  * Affected windows are already cleared to their background color when you 
1796  * receive the redraw event.
1797  * 
1798  * Redraw events can be returned by glk_select_poll(). But, like arrangement
1799  * events, this is platform-dependent. See %evtype_Arrange.
1800  *
1801  * For more about redraw events and how they affect graphics windows, see <link
1802  * linkend="wintype-Graphics">Graphics Windows</link>.
1803  */
1804
1805 /**
1806  * evtype_SoundNotify:
1807  *
1808  * On platforms that support sound, you can request to receive an 
1809  * %evtype_SoundNotify event when a sound finishes playing. See <link
1810  * linkend="chimara-Playing-Sounds">Playing Sounds</link>.
1811  */
1812  
1813 /**
1814  * evtype_Hyperlink:
1815  * 
1816  * On platforms that support hyperlinks, you can request to receive an
1817  * %evtype_Hyperlink event when the player selects a link. See <link
1818  * linkend="chimara-Accepting-Hyperlink-Events">Accepting Hyperlink 
1819  * Events</link>.
1820  */
1821
1822 /**
1823  * event_t:
1824  * @type: the event type
1825  * @win: the window that spawned the event, or %NULL
1826  * @val1: information, the meaning of which depends on the type of event
1827  * @val2: more information, the meaning of which depends on the type of event
1828  *
1829  * The event structure is self-explanatory. @type is the event type. The window
1830  * that spawned the event, if relevant, is in @win. The remaining fields contain
1831  * more information specific to the event.
1832  *
1833  * The event types are described below. Note that %evtype_None is zero, and the
1834  * other values are positive. Negative event types (0x80000000 to 0xFFFFFFFF) 
1835  * are reserved for implementation-defined events. 
1836  */
1837
1838 /**
1839  * keycode_Unknown:
1840  *
1841  * Represents any key that has no Latin-1 or special code.
1842  */
1843
1844 /**
1845  * keycode_Left:
1846  *
1847  * Represents the <keycap function="left">left arrow</keycap> key.
1848  */
1849  
1850 /**
1851  * keycode_Right:
1852  *
1853  * Represents the <keycap function="right">right arrow</keycap> key.
1854  */
1855  
1856 /**
1857  * keycode_Up:
1858  *
1859  * Represents the <keycap function="up">up arrow</keycap> key.
1860  */
1861  
1862 /**
1863  * keycode_Down:
1864  *
1865  * Represents the <keycap function="down">down arrow</keycap> key.
1866  */
1867  
1868 /**
1869  * keycode_Return:
1870  *
1871  * Represents the <keycap function="enter">return</keycap> or <keycap 
1872  * function="enter">enter</keycap> keys.
1873  */
1874
1875 /**
1876  * keycode_Delete:
1877  *
1878  * Represents the <keycap function="delete">delete</keycap> or <keycap
1879  * function="backspace">backspace</keycap> keys.
1880  */
1881  
1882 /**
1883  * keycode_Escape:
1884  *
1885  * Represents the <keycap function="escape">escape</keycap> key.
1886  */
1887  
1888 /**
1889  * keycode_Tab:
1890  *
1891  * Represents the <keycap function="tab">tab</keycap> key.
1892  */
1893
1894 /**
1895  * keycode_PageUp:
1896  *
1897  * Represents the <keycap function="pageup">page up</keycap> key.
1898  */
1899
1900 /**
1901  * keycode_PageDown:
1902  *
1903  * Represents the <keycap function="pagedown">page down</keycap> key.
1904  */
1905
1906 /**
1907  * keycode_Home:
1908  *
1909  * Represents the <keycap function="home">home</keycap> key.
1910  */
1911  
1912 /**
1913  * keycode_End:
1914  *
1915  * Represents the <keycap function="end">end</keycap> key.
1916  */
1917
1918 /**
1919  * keycode_Func1:
1920  *
1921  * Represents the <keycap>F1</keycap> key.
1922  */
1923  
1924 /**
1925  * keycode_Func2:
1926  *
1927  * Represents the <keycap>F2</keycap> key.
1928  */
1929
1930 /**
1931  * keycode_Func3:
1932  *
1933  * Represents the <keycap>F3</keycap> key.
1934  */
1935
1936 /**
1937  * keycode_Func4:
1938  *
1939  * Represents the <keycap>F4</keycap> key.
1940  */
1941
1942 /**
1943  * keycode_Func5:
1944  *
1945  * Represents the <keycap>F5</keycap> key.
1946  */
1947  
1948 /**
1949  * keycode_Func6:
1950  *
1951  * Represents the <keycap>F6</keycap> key.
1952  */
1953
1954 /**
1955  * keycode_Func7:
1956  *
1957  * Represents the <keycap>F7</keycap> key.
1958  */
1959
1960 /**
1961  * keycode_Func8:
1962  *
1963  * Represents the <keycap>F8</keycap> key.
1964  */
1965
1966 /**
1967  * keycode_Func9:
1968  *
1969  * Represents the <keycap>F9</keycap> key.
1970  */
1971
1972 /**
1973  * keycode_Func10:
1974  *
1975  * Represents the <keycap>F10</keycap> key.
1976  */
1977
1978 /**
1979  * keycode_Func11:
1980  *
1981  * Represents the <keycap>F11</keycap> key.
1982  */
1983
1984 /**
1985  * keycode_Func12:
1986  *
1987  * Represents the <keycap>F12</keycap> key.
1988  */
1989
1990 /**
1991  * style_Normal: 
1992  *
1993  * The style of normal or body text. A new window or stream always starts with
1994  * %style_Normal as the current style.
1995  */
1996
1997 /**
1998  * style_Emphasized: 
1999  *
2000  * Text which is emphasized.
2001  */
2002
2003 /**
2004  * style_Preformatted: 
2005  *
2006  * Text which has a particular arrangement of characters.
2007  * <note><para>
2008  *  This style, unlike the others, does have a standard appearance; it will 
2009  *  always be a fixed-width font. This is a concession to practicality. Games 
2010  *  often want to display maps or diagrams using character graphics, and this is
2011  *  the style for that.
2012  * </para></note>
2013  */
2014  
2015 /**
2016  * style_Header: 
2017  * 
2018  * Text which introduces a large section. This is suitable for the title of an 
2019  * entire game, or a major division such as a chapter.
2020  */
2021
2022 /**
2023  * style_Subheader: 
2024  * 
2025  * Text which introduces a smaller section within a large section. 
2026  * <note><para>
2027  *  In a Colossal-Cave-style game, this is suitable for the name of a room (when
2028  *  the player looks around.)
2029  * </para></note>
2030  */
2031
2032 /**
2033  * style_Alert: 
2034  *
2035  * Text which warns of a dangerous condition, or one which the player should pay
2036  * attention to.
2037  */
2038
2039 /**
2040  * style_Note: 
2041  *
2042  * Text which notifies of an interesting condition.
2043  * <note><para>
2044  *  This is suitable for noting that the player's score has changed.
2045  * </para></note>
2046  */
2047
2048 /**
2049  * style_BlockQuote: 
2050  *
2051  * Text which forms a quotation or otherwise abstracted text.
2052  */
2053
2054 /**
2055  * style_Input: 
2056  *
2057  * Text which the player has entered. You should generally not use this style at
2058  * all; the library uses it for text which is typed during a line-input request.
2059  * One case when it is appropriate for you to use %style_Input is when you are 
2060  * simulating player input by reading commands from a text file.
2061  */
2062
2063 /**
2064  * style_User1: 
2065  * 
2066  * This style has no particular semantic meaning. You may define a meaning 
2067  * relevant to your own work, and use it as you see fit.
2068  */
2069
2070 /**
2071  * style_User2: 
2072  *
2073  * Another style available for your use. 
2074  */
2075
2076 /**
2077  * stream_result_t:
2078  * @readcount: Number of characters read from the stream.
2079  * @writecount: Number of characters printed to the stream, including ones that
2080  * were thrown away.
2081  *
2082  * If you are interested in the character counts of a stream (see <link
2083  * linkend="chimara-Streams">Streams</link>), then you can pass a pointer to
2084  * #stream_result_t as an argument of glk_stream_close() or glk_window_close().
2085  * The structure will be filled with the stream's final character counts.
2086  */
2087
2088 /**
2089  * wintype_AllTypes:
2090  *
2091  * A constant representing all window types, which may be used as the @wintype
2092  * argument in glk_stylehint_set().
2093  */
2094
2095 /** 
2096  * wintype_Pair:
2097  * 
2098  * A pair window is completely filled by the two windows it contains. It
2099  * supports no input and no output, and it has no size.
2100  * 
2101  * You cannot directly create a pair window; one is automatically created
2102  * every time you split a window with glk_window_open(). Pair windows are
2103  * always created with a rock value of 0.
2104  * 
2105  * You can close a pair window with glk_window_close(); this also closes every
2106  * window contained within the pair window.
2107  * 
2108  * It is legal to split a pair window when you call glk_window_open().
2109  */
2110  
2111 /**
2112  * wintype_Blank:
2113  * 
2114  * A blank window is always blank. It supports no input and no output. (You
2115  * can call glk_window_get_stream() on it, as you can with any window, but
2116  * printing to the resulting stream has no effect.) A blank window has no
2117  * size; glk_window_get_size() will return (0,0), and it is illegal to set a
2118  * window split with a fixed size in the measurement system of a blank window.
2119  * 
2120  * <note><para>
2121  *   A blank window is not the same as there being no windows. When Glk starts
2122  *   up, there are no windows at all, not even a window of the blank type.
2123  * </para></note>
2124  */
2125  
2126 /**
2127  * wintype_TextBuffer: 
2128  *
2129  * A text buffer window contains a linear stream of text. It supports output;
2130  * when you print to it, the new text is added to the end. There is no way for
2131  * you to affect text which has already been printed. There are no guarantees
2132  * about how much text the window keeps; old text may be stored forever, so
2133  * that the user can scroll back to it, or it may be thrown away as soon as it
2134  * scrolls out of the window. 
2135  * 
2136  * <note><para>
2137  *   Therefore, there may or may not be a player-controllable scroll bar or
2138  *   other scrolling widget.
2139  * </para></note>
2140  * 
2141  * The display of the text in a text buffer is up to the library. Lines will
2142  * probably not be broken in the middles of words &mdash; but if they are, the
2143  * library is not doing anything illegal, only ugly. Text selection and copying
2144  * to a clipboard, if available, are handled however is best on the player's
2145  * machine. Paragraphs (as defined by newline characters in the output) may be
2146  * indented. 
2147  * 
2148  * <note><para>
2149  *   You should not, in general, fake this by printing spaces before each
2150  *   paragraph of prose text. Let the library and player preferences handle
2151  *   that. Special cases (like indented lists) are of course up to you.
2152  * </para></note>
2153  * 
2154  * When a text buffer is cleared (with glk_window_clear()), the library will do
2155  * something appropriate; the details may vary. It may clear the window, with
2156  * later text appearing at the top &mdash; or the bottom. It may simply print
2157  * enough blank lines to scroll the current text out of the window. It may
2158  * display a distinctive page-break symbol or divider.
2159  * 
2160  * The size of a text buffer window is necessarily imprecise. Calling
2161  * glk_window_get_size() will return the number of rows and columns that would
2162  * be available <emphasis>if</emphasis> the window was filled with 
2163  * <quote>0</quote> (zero) characters in the <quote>normal</quote> font.
2164  * However, the window may use a non-fixed-width font, so that number of
2165  * characters in a line could vary. The window might even support 
2166  * variable-height text (say, if the player is using large text for emphasis);
2167  * that would make the number of lines in the window vary as well.
2168  * 
2169  * Similarly, when you set a fixed-size split in the measurement system of a
2170  * text buffer, you are setting a window which can handle a fixed number of rows
2171  * (or columns) of <quote>0</quote> characters. The number of rows (or
2172  * characters) that will actually be displayed depends on font variances.
2173  * 
2174  * A text buffer window supports both character and line input, but not mouse
2175  * input.
2176  * 
2177  * In character input, there will be some visible signal that the window is
2178  * waiting for a keystroke. (Typically, a cursor at the end of the text.) When
2179  * the player hits a key in that window, an event is generated, but the key is
2180  * <emphasis>not</emphasis> printed in the window.
2181  * 
2182  * In line input, again, there will be some visible signal. It is most common
2183  * for the player to compose input in the window itself, at the end of the text.
2184  * (This is how IF story input usually looks.) But it's not strictly required.
2185  * An alternative approach is the way MUD clients usually work: there is a
2186  * dedicated one-line input window, outside of Glk's window space, and the user
2187  * composes input there.
2188  * 
2189  * <note><para>
2190  *   If this approach is used, there will still be some way to handle input from
2191  *   two windows at once. It is the library's responsibility to make this
2192  *   available to the player. You only need request line input and  wait for the
2193  *   result.
2194  * </para></note>
2195  * 
2196  * When the player finishes his line of input, the library will display the
2197  * input text at the end of the buffer text (if it wasn't there already.) It
2198  * will be followed by a newline, so that the next text you print will start a
2199  * new line (paragraph) after the input.
2200  * 
2201  * If you call glk_cancel_line_event(), the same thing happens; whatever text
2202  * the user was composing is visible at the end of the buffer text, followed by
2203  * a newline.
2204  */
2205  
2206 /**
2207  * wintype_TextGrid: 
2208  * 
2209  * A text grid contains a rectangular array of characters, in a fixed-width
2210  * font. Its size is the number of columns and rows of the array.
2211  * 
2212  * A text grid window supports output. It maintains knowledge of an output
2213  * cursor position. When the window is opened, it is filled with blanks (space
2214  * characters), and the output cursor starts in the top left corner &mdash;
2215  * character (0,0). If the window is cleared with glk_window_clear(), the window
2216  * is filled with blanks again, and the cursor returns to the top left corner.
2217  * 
2218  * When you print, the characters of the output are laid into the array in
2219  * order, left to right and top to bottom. When the cursor reaches the end of a
2220  * line, it goes to the beginning of the next line. The library makes no attempt
2221  * to wrap lines at word breaks.
2222  * 
2223  * <note><para>
2224  *   Note that printing fancy characters may cause the cursor to advance more
2225  *   than one position per character. (For example, the <quote>&aelig;</quote>
2226  *   ligature may print as two characters.) See <link 
2227  *   linkend="chimara-Output">Output</link>, for how to test this situation.
2228  * </para></note>
2229  * 
2230  * You can set the cursor position with glk_window_move_cursor().
2231  * 
2232  * When a text grid window is resized smaller, the bottom or right area is
2233  * thrown away, but the remaining area stays unchanged. When it is resized
2234  * larger, the new bottom or right area is filled with blanks.
2235  * 
2236  * <note><para>
2237  *   You may wish to watch for %evtype_Arrange events, and clear-and-redraw your
2238  *   text grid windows when you see them change size.
2239  * </para></note>
2240  * 
2241  * Text grid window support character and line input, as well as mouse input (if
2242  * a mouse is available.)
2243  * 
2244  * Mouse input returns the position of the character that was touched, from
2245  * (0,0) to 
2246  * <inlineequation>
2247  *   <alt>(width-1,height-1)</alt>
2248  *   <mathphrase>(width - 1, height - 1)</mathphrase>
2249  * </inlineequation>
2250  * .
2251  * 
2252  * Character input is as described in the previous section.
2253  * 
2254  * Line input is slightly different; it is guaranteed to take place in the
2255  * window, at the output cursor position. The player can compose input only to
2256  * the right edge of the window; therefore, the maximum input length is
2257  * <inlineequation>
2258  *   <alt>(windowwidth - 1 - cursorposition)</alt>
2259  *   <mathphrase>(windowwidth - 1 - cursorposition)</mathphrase>
2260  * </inlineequation>
2261  * . If the maxlen argument of glk_request_line_event() is smaller than this,
2262  * the library will not allow the input cursor to go more than maxlen characters
2263  * past its start point. 
2264  * 
2265  * <note><para>
2266  *   This allows you to enter text in a fixed-width field, without the player
2267  *   being able to overwrite other parts of the window.
2268  * </para></note>
2269  * 
2270  * When the player finishes his line of input, it will remain visible in the
2271  * window, and the output cursor will be positioned at the beginning of the 
2272  * <emphasis>next</emphasis> row. Again, if you glk_cancel_line_event(), the
2273  * same thing happens.
2274  */
2275  
2276 /**
2277  * wintype_Graphics: 
2278  * 
2279  * A graphics window contains a rectangular array of pixels. Its size is the
2280  * number of columns and rows of the array.
2281  * 
2282  * Each graphics window has a background color, which is initially white. You
2283  * can change this; see <link 
2284  * linkend="chimara-Graphics-in-Graphics-Windows">Graphics in Graphics 
2285  * Windows</link>.
2286  * 
2287  * When a text grid window is resized smaller, the bottom or right area is
2288  * thrown away, but the remaining area stays unchanged. When it is resized
2289  * larger, the new bottom or right area is filled with the background color.
2290  * 
2291  * <note><para>
2292  *   You may wish to watch for %evtype_Arrange events, and clear-and-redraw your
2293  *   graphics windows when you see them change size.
2294  * </para></note>
2295  * 
2296  * In some libraries, you can receive a graphics-redraw event (%evtype_Redraw)
2297  * at any time. This signifies that the window in question has been cleared to
2298  * its background color, and must be redrawn. If you create any graphics
2299  * windows, you <emphasis>must</emphasis> handle these events.
2300  * 
2301  * <note><para>
2302  *   Redraw events can be triggered when a Glk window is uncovered or made
2303  *   visible by the platform's window manager. On the other hand, some Glk
2304  *   libraries handle these problem automatically &mdash; for example, with a
2305  *   backing store &mdash; and do not send you redraw events. On the third hand,
2306  *   the backing store may be discarded if memory is low, or for other reasons
2307  *   &mdash; perhaps the screen's color depth has changed. So redraw events are
2308  *   always a possibility, even in clever libraries. This is why you must be
2309  *   prepared to handle them.
2310  * 
2311  *   However, you will not receive a redraw event when you create a graphics
2312  *   window. It is assumed that you will do the initial drawing of your own
2313  *   accord. You also do not get redraw events when a graphics window is
2314  *   enlarged. If you ordered the enlargement, you already know about it; if the
2315  *   player is responsible, you receive a window-arrangement event, which covers
2316  *   the situation.
2317  * </para></note>
2318  * 
2319  * For a description of the drawing functions that apply to graphics windows,
2320  * see <link linkend="chimara-Graphics-in-Graphics-Windows">Graphics in Graphics
2321  * Windows</link>.
2322  * 
2323  * Graphics windows support no text input or output.
2324  * 
2325  * Not all libraries support graphics windows. You can test whether Glk graphics
2326  * are available using the gestalt system. In a C program, you can also test
2327  * whether the graphics functions are defined at compile-time. See <link 
2328  * linkend="chimara-Testing-for-Graphics-Capabilities">Testing for Graphics
2329  * Capabilities</link>. 
2330  *
2331  * <note><para>
2332  *   As with all windows, you should also test for %NULL when you create a
2333  *   graphics window.
2334  * </para></note>
2335  */
2336  
2337 /**
2338  * winmethod_Left:
2339  *
2340  * When calling glk_window_open() with this @method, the new window will be 
2341  * to the left of the old one which was split.
2342  */
2343
2344 /**
2345  * winmethod_Right:
2346  *
2347  * When calling glk_window_open() with this @method, the new window will be 
2348  * to the right of the old one which was split.
2349  */
2350
2351 /**
2352  * winmethod_Above:
2353  *
2354  * When calling glk_window_open() with this @method, the new window will be 
2355  * above the old one which was split.
2356  */
2357  
2358 /**
2359  * winmethod_Below:
2360  *
2361  * When calling glk_window_open() with this @method, the new window will be 
2362  * below the old one which was split.
2363  */
2364  
2365 /**
2366  * winmethod_Fixed:
2367  *
2368  * When calling glk_window_open() with this @method, the new window will be 
2369  * a fixed size. (See glk_window_open()).
2370  */
2371
2372 /**
2373  * winmethod_Proportional:
2374  *
2375  * When calling glk_window_open() with this @method, the new window will be 
2376  * a given proportion of the old window's size. (See glk_window_open()).
2377  */
2378  
2379 /** 
2380  * fileusage_Data: 
2381  *
2382  * Any other kind of file (preferences, statistics, arbitrary data.) 
2383  */
2384
2385 /**
2386  * fileusage_SavedGame: 
2387  * 
2388  * A file which stores game state.
2389  */
2390
2391 /**
2392  * fileusage_Transcript: 
2393  * 
2394  * A file which contains a stream of text from the game (often an echo stream
2395  * from a window.)
2396  */
2397  
2398 /** 
2399  * fileusage_InputRecord: 
2400  * 
2401  * A file which records player input.
2402  */
2403
2404 /** 
2405  * fileusage_TextMode: 
2406  *
2407  * The file contents will be transformed to a platform-native text file as they
2408  * are written out. Newlines may be converted to linefeeds or 
2409  * linefeed-plus-carriage-return combinations; Latin-1 characters may be
2410  * converted to native character codes. When reading a file in text mode, native
2411  * line breaks will be converted back to newline (0x0A) characters, and native
2412  * character codes may be converted to Latin-1. 
2413  *
2414  * <note><para>
2415  *   Line breaks will always be converted; other conversions are more
2416  *   questionable. If you write out a file in text mode, and then read it back
2417  *   in text mode, high-bit characters (128 to 255) may be transformed or lost.
2418  * </para></note>
2419  * <note><title>Chimara</title>
2420  * <para>
2421  * Text mode files in Chimara are in UTF-8, which is GTK+'s native file
2422  * encoding.
2423  * </para></note>
2424  */
2425
2426 /**
2427  * fileusage_BinaryMode: 
2428  *
2429  * The file contents will be stored exactly as they are written, and read back
2430  * in the same way. The resulting file may not be viewable on platform-native
2431  * text file viewers.
2432  */
2433
2434 /**
2435  * fileusage_TypeMask:
2436  *
2437  * Bitwise AND this value with a file usage argument to find whether the file
2438  * type is %fileusage_SavedGame, %fileusage_Transcript, %fileusage_InputRecord,
2439  * or %fileusage_Data.
2440  */
2441
2442 /**
2443  * filemode_Write: 
2444  *
2445  * An output stream.
2446  *
2447  * <note><para>
2448  *   Corresponds to mode <code>"w"</code> in the stdio library, using fopen().
2449  * </para></note>
2450  */
2451
2452 /** 
2453  * filemode_Read: 
2454  *
2455  * An input stream.
2456  *
2457  * <note><para>
2458  *   Corresponds to mode <code>"r"</code> in the stdio library, using fopen().
2459  * </para></note>
2460  */
2461
2462 /**
2463  * filemode_ReadWrite: 
2464  *
2465  * Both an input and an output stream.
2466  *
2467  * <note><para>
2468  *   Corresponds to mode <code>"r+"</code> in the stdio library, using fopen().
2469  * </para></note>
2470  */
2471
2472 /**
2473  * filemode_WriteAppend: 
2474  *
2475  * An output stream, but the data will added to the end of whatever already
2476  * existed in the destination, instead of replacing it. 
2477  *
2478  * <note><para>
2479  *   Corresponds to mode <code>"a"</code> in the stdio library, using fopen().
2480  * </para></note>
2481  */
2482  
2483 /**
2484  * seekmode_Start:
2485  *
2486  * In glk_stream_set_position(), signifies that @pos is counted in characters
2487  * after the beginning of the file.
2488  */
2489  
2490 /**
2491  * seekmode_Current: 
2492  *
2493  * In glk_stream_set_position(), signifies that @pos is counted in characters
2494  * after the current position (moving backwards if @pos is negative.)
2495  */
2496
2497 /** 
2498  * seekmode_End: 
2499  *
2500  * In glk_stream_set_position(), signifies that @pos is counted in characters
2501  * after the end of the file. (@pos should always be zero or negative, so that
2502  * this will move backwards to a  position within the file.
2503  */
2504
2505 /**
2506  * stylehint_Indentation: 
2507  *
2508  * How much to indent lines of text in the given style. May be a negative 
2509  * number, to shift the text out (left) instead of in (right). The exact metric
2510  * isn't precisely specified; you can assume that +1 is the smallest indentation
2511  * possible which is clearly visible to the player.
2512  */
2513
2514 /**
2515  * stylehint_ParaIndentation: 
2516  *
2517  * How much to indent the first line of each paragraph. This is in addition to 
2518  * the indentation specified by %stylehint_Indentation. This too may be 
2519  * negative, and is measured in the same units as %stylehint_Indentation.
2520  */
2521
2522 /**
2523  * stylehint_Justification: 
2524  *
2525  * The value of this hint must be one of the constants 
2526  * %stylehint_just_LeftFlush, %stylehint_just_LeftRight (full justification), 
2527  * %stylehint_just_Centered, or %stylehint_just_RightFlush.
2528  */
2529
2530 /** 
2531  * stylehint_Size: 
2532  *
2533  * How much to increase or decrease the font size. This is relative; 0 means the
2534  * interpreter's default font size will be used, positive numbers increase it, 
2535  * and negative numbers decrease it. Again, +1 is the smallest size increase 
2536  * which is easily visible. 
2537  * <note><para>
2538  *  The amount of this increase may not be constant. +1 might increase an 
2539  *  8-point font to 9-point, but a 16-point font to 18-point.
2540  * </para></note>
2541  */
2542
2543 /**
2544  * stylehint_Weight: 
2545  *
2546  * The value of this hint must be 1 for heavy-weight fonts (boldface), 0 for 
2547  * normal weight, and -1 for light-weight fonts.
2548  */
2549
2550 /**
2551  * stylehint_Oblique: 
2552  *
2553  * The value of this hint must be 1 for oblique fonts (italic), or 0 for normal
2554  * angle.
2555  */
2556  
2557 /** 
2558  * stylehint_Proportional: 
2559  * 
2560  * The value of this hint must be 1 for proportional-width fonts, or 0 for 
2561  * fixed-width.
2562  */
2563
2564 /**
2565  * stylehint_TextColor: 
2566  * 
2567  * The foreground color of the text. This is encoded in the 32-bit hint value: 
2568  * the top 8 bits must be zero, the next 8 bits are the red value, the next 8 
2569  * bits are the green value, and the bottom 8 bits are the blue value. Color 
2570  * values range from 0 to 255. 
2571  * <note><para>
2572  *   So 0x00000000 is black, 0x00FFFFFF is white, and 0x00FF0000 is bright red.
2573  * </para></note>
2574  */
2575  
2576 /** 
2577  * stylehint_BackColor: 
2578  *
2579  * The background color behind the text. This is encoded the same way as 
2580  * %stylehint_TextColor.
2581  */
2582  
2583 /** 
2584  * stylehint_ReverseColor: 
2585  *
2586  * The value of this hint must be 0 for normal printing (%stylehint_TextColor on 
2587  * %stylehint_BackColor), or 1 for reverse printing (%stylehint_BackColor on 
2588  * %stylehint_TextColor). 
2589  * <note><para>
2590  *  Some libraries may support this hint but not the %stylehint_TextColor and 
2591  *  %stylehint_BackColor hints. Other libraries may take the opposite tack; 
2592  *  others may support both, or neither.
2593  * </para></note>
2594  */
2595  
2596 /**
2597  * stylehint_just_LeftFlush:
2598  *
2599  * A value for %stylehint_Justification representing left-justified text.
2600  */ 
2601  
2602 /**
2603  * stylehint_just_LeftRight:
2604  *
2605  * A value for %stylehint_Justification representing fully justified text.
2606  */ 
2607  
2608 /**
2609  * stylehint_just_Centered:
2610  *
2611  * A value for %stylehint_Justification representing centered text.
2612  */ 
2613  
2614 /**
2615  * stylehint_just_RightFlush:
2616  *
2617  * A value for %stylehint_Justification representing right-justified text.
2618  */
2619
2620 /**
2621  * imagealign_InlineUp:
2622  *
2623  * The image appears at the current point in the text, sticking up. That is, the
2624  * bottom edge of the image is aligned with the baseline of the line of text.
2625  */
2626
2627 /**
2628  * imagealign_InlineDown:
2629  *
2630  * The image appears at the current point, and the top edge is aligned with the
2631  * top of the line of text.
2632  */
2633
2634 /**
2635  * imagealign_InlineCenter:
2636  *
2637  * The image appears at the current point, and it is centered between the top
2638  * and baseline of the line of text. If the image is taller than the line of
2639  * text, it will stick up and down equally.
2640  */
2641
2642 /**
2643  * imagealign_MarginLeft:
2644  * 
2645  * The image appears in the left margin. Subsequent text will be displayed to
2646  * the right of the image, and will flow around it &mdash; that is, it will be
2647  * left-indented for as many lines as it takes to pass the image.
2648  *
2649  * <warning><para>Margin images are not implemented yet.</para></warning>
2650  */
2651
2652 /**
2653  * imagealign_MarginRight:
2654  *
2655  * The image appears in the right margin, and subsequent text will flow around
2656  * it on the left.
2657  *
2658  * <warning><para>Margin images are not implemented yet.</para></warning>
2659  */
2660  
2661 /*---------- TYPES, FUNCTIONS AND CONSTANTS FROM GI_DISPA.H ------------------*/
2662
2663 /**
2664  * gidispatch_count_classes:
2665  * 
2666  * Returns the number of opaque object classes used by the library. You will
2667  * need to know this if you want to keep track of opaque objects as they are
2668  * created; see <link linkend="gidispatch-set-object-registry">Opaque Object
2669  * Registry</link>.
2670  * 
2671  * As of Glk API 0.7.0, there are four classes: windows, streams, filerefs, and
2672  * sound channels (numbered 0, 1, 2, and 3 respectively.)
2673  *
2674  * Returns: Number of opaque object classes used by the library.
2675  */
2676  
2677 /**
2678  * gidispatch_count_intconst:
2679  *
2680  * Returns the number of integer constants exported by the library.
2681  *
2682  * Returns: Number of integer constants exported by the library.
2683  */
2684  
2685 /**
2686  * gidispatch_get_intconst:
2687  * @index: Unique integer index of the integer constant.
2688  *
2689  * Returns a structure describing an integer constant which the library exports.
2690  * These are, roughly, all the constants defined in the <filename
2691  * class="headerfile">glk.h</filename> file. @index can range from 0 to
2692  * <inlineequation><mathphrase>N - 1</mathphrase><alt>N - 
2693  * 1</alt></inlineequation>, where N is the value returned by 
2694  * gidispatch_count_intconst().
2695  *
2696  * Returns: A #gidispatch_intconst_t structure describing the integer constant.
2697  */
2698
2699 /**
2700  * gidispatch_intconst_t:
2701  * @name: Symbolic name of the integer constant.
2702  * @val: Value of the integer constant.
2703  *
2704  * This structure simply contains a string and a value. The string is a
2705  * symbolic name of the value, and can be re-exported to anyone interested in
2706  * using Glk constants.
2707  */
2708  
2709 /**
2710  * gidispatch_count_functions:
2711  *
2712  * Returns the number of functions exported by the library.
2713  *
2714  * Returns: Number of functions exported by the library.
2715  */
2716  
2717 /**
2718  * gidispatch_get_function:
2719  * @index: Unique integer index of the function.
2720  *
2721  * Returns a structure describing a Glk function. @index can range from 0 to
2722  * <inlineequation><mathphrase>N - 1</mathphrase><alt>N - 
2723  * 1</alt></inlineequation>, where N is the value returned by 
2724  * gidispatch_count_functions().
2725  *
2726  * Returns: A #gidispatch_function_t structure describing the function.
2727  */
2728  
2729 /**
2730  * gidispatch_function_t:
2731  * @id: Dispatch selector of the function.
2732  * @fnptr: Pointer to the function.
2733  * @name: Name of the function, without the <code>glk_</code> prefix.
2734  *
2735  * The @id field is a selector &mdash; a numeric constant used to refer to the
2736  * function in question. @name is the function name, as it is given in the
2737  * <filename class="headerfile">glk.h</filename> file, but without the 
2738  * <quote><code>glk_</code></quote> prefix. And @fnptr is the address of the
2739  * function itself.
2740  *
2741  * <note><para>
2742  *   This is included because it might be useful, but it is not recommended. To
2743  *   call an arbitrary Glk function, you should use gidispatch_call().
2744  * </para></note>
2745  *
2746  * See <link linkend="chimara-Table-of-Selectors">Table of Selectors</link> for
2747  * the selector definitions. See <link 
2748  * linkend="chimara-Dispatching">Dispatching</link> for more about calling Glk
2749  * functions by selector.
2750  */
2751  
2752 /**
2753  * gidispatch_get_function_by_id:
2754  * @id: A selector.
2755  *
2756  * Returns a structure describing the Glk function with selector @id. If there 
2757  * is no such function in the library, this returns %NULL.
2758  *
2759  * Returns: a #gidispatch_function_t structure, or %NULL.
2760  */
2761  
2762 /**
2763  * gidispatch_call:
2764  * @funcnum: Selector of the function to call.
2765  * @numargs: Length of @arglist.
2766  * @arglist: List of arguments to pass to the function.
2767  *
2768  * @funcnum is the function number to invoke; see <link 
2769  * linkend="chimara-Table-of-Selectors">Table of Selectors</link>. @arglist is
2770  * the list of arguments, and @numargs is the length of the list.
2771  * 
2772  * The arguments are all stored as #gluniversal_t objects. 
2773  * </para><refsect3 id="chimara-Basic-Types"><title>Basic Types</title><para>
2774  * Numeric arguments are passed in the obvious way &mdash; one argument per
2775  * #gluniversal_t, with the @uint or @sint field set to the numeric value.
2776  * Characters and strings are also passed in this way &mdash; #char<!---->s in
2777  * the @uch, @sch, or @ch fields (depending on whether the #char is signed) and
2778  * strings in the @charstr field. Opaque objects (windows, streams, etc) are
2779  * passed in the @opaqueref field (which is <code>void*</code>, in order to
2780  * handle all opaque pointer types.)
2781  * 
2782  * However, pointers (other than C strings), arrays, and structures complicate
2783  * life. So do return values.
2784  * </para></refsect3>
2785  * <refsect3 id="chimara-References"><title>References</title><para>
2786  * A reference to a numeric type or object reference &mdash; that is,
2787  * <code>#glui32*</code>, <code>#winid_t*</code>, and so on &mdash; takes
2788  * <emphasis>one or two</emphasis> #gluniversal_t objects. The first is a flag
2789  * indicating whether the reference argument is %NULL or not. The @ptrflag field
2790  * of this #gluniversal_t should be %FALSE if the reference is %NULL, and %TRUE
2791  * otherwise. If %FALSE, that is the end of the argument; you should not use a
2792  * #gluniversal_t to explicitly store the %NULL reference. If the flag is %TRUE,
2793  * you must then put a #gluniversal_t storing the base type of the reference.
2794  *
2795  * For example, consider a hypothetical function, with selector 
2796  * <code>0xABCD</code>:
2797  * |[ 
2798  * void glk_glomp(glui32 num, winid_t win, glui32 *numref, strid_t *strref);
2799  * ]|
2800  * ...and the calls:
2801  * |[
2802  * glui32 value;
2803  * winid_t mainwin;
2804  * strid_t gamefile;
2805  * glk_glomp(5, mainwin, &value, &gamefile);
2806  * ]|
2807  *
2808  * To perform this through gidispatch_call(), you would do the following:
2809  * |[
2810  * gluniversal_t arglist[6];
2811  * arglist[0].uint = 5;
2812  * arglist[1].opaqueref = mainwin;
2813  * arglist[2].ptrflag = TRUE;
2814  * arglist[3].uint = value;
2815  * arglist[4].ptrflag = TRUE;
2816  * arglist[5].opaqueref = gamefile;
2817  * gidispatch_call(0xABCD, 6, arglist);
2818  * value = arglist[3].uint;
2819  * gamefile = arglist[5].opaqueref;
2820  * ]|
2821  * 
2822  * Note that you copy the value of the reference arguments into and out of
2823  * @arglist. Of course, it may be that 
2824  * <function>glk_glomp&lpar;&rpar;</function> only uses these as pass-out
2825  * references or pass-in references; if so, you could skip copying in or out.
2826  *
2827  * For further examples:
2828  * |[
2829  * glk_glomp(7, mainwin, NULL, NULL);
2830  * ...or...
2831  * gluniversal_t arglist[4];
2832  * arglist[0].uint = 7;
2833  * arglist[1].opaqueref = mainwin;
2834  * arglist[2].ptrflag = FALSE;
2835  * arglist[3].ptrflag = FALSE;
2836  * gidispatch_call(0xABCD, 4, arglist);
2837  * ]|
2838  *
2839  * |[
2840  * glk_glomp(13, NULL, NULL, &gamefile);
2841  * ...or...
2842  * gluniversal_t arglist[5];
2843  * arglist[0].uint = 13;
2844  * arglist[1].opaqueref = NULL;
2845  * arglist[2].ptrflag = FALSE;
2846  * arglist[3].ptrflag = TRUE;
2847  * arglist[4].opaqueref = gamefile;
2848  * gidispatch_call(0xABCD, 5, arglist);
2849  * gamefile = arglist[4].opaqueref;
2850  * ]|
2851  *
2852  * |[
2853  * glk_glomp(17, NULL, &value, NULL);
2854  * ...or...
2855  * gluniversal_t arglist[5];
2856  * arglist[0].uint = 17;
2857  * arglist[1].opaqueref = NULL;
2858  * arglist[2].ptrflag = TRUE;
2859  * arglist[3].uint = value;
2860  * arglist[4].ptrflag = FALSE;
2861  * gidispatch_call(0xABCD, 5, arglist);
2862  * value = arglist[3].uint;
2863  * ]|
2864  * 
2865  * As you see, the length of @arglist depends on how many of the reference
2866  * arguments are %NULL.
2867  * </para></refsect3>
2868  * <refsect3 id="chimara-Structures"><title>Structures</title><para>
2869  * A structure pointer is represented by a single @ptrflag, possibly followed by
2870  * a sequence of #gluniversal_t objects (one for each field of the structure.)
2871  * Again, if the structure pointer is non-%NULL, the @ptrflag should be %TRUE
2872  * and be followed by values; if not, the @ptrflag should be %NULL and stands
2873  * alone.
2874  * 
2875  * For example, the function glk_select() can be invoked as follows:
2876  * |[
2877  * event_t ev;
2878  * gluniversal_t arglist[5];
2879  * arglist[0].ptrflag = TRUE;
2880  * gidispatch_call(0x00C0, 5, arglist);
2881  * ev.type = arglist[1].uint;
2882  * ev.win = arglist[2].opaqueref;
2883  * ev.val1 = arglist[3].uint;
2884  * ev.val2 = arglist[4].uint;
2885  * ]|
2886  * 
2887  * Since the structure passed to glk_select() is a pass-out reference (the entry
2888  * values are ignored), you don't need to fill in <code>arglist[1..4]</code>
2889  * before calling gidispatch_call().
2890  * 
2891  * <note><para>
2892  *   Theoretically, you would invoke <code>#glk_select(%NULL)</code> by setting'
2893  *   <code>arglist[0].ptrflag</code> to %FALSE, and using a one-element @arglist
2894  *   instead of five-element. But it's illegal to pass %NULL to glk_select(). So
2895  *   you cannot actually do this.
2896  * </para></note></para></refsect3>
2897  * <refsect3 id="chimara-Arrays"><title>Arrays</title><para>
2898  * In the Glk API, an array argument is always followed by a numeric argument
2899  * giving the array's length. These two C arguments are a single logical
2900  * argument, which is represented by <emphasis>one or three</emphasis>
2901  * #gluniversal_t objects. The first is a @ptrflag, indicating whether the
2902  * argument is %NULL or not. The second is a pointer, stored in the @array
2903  * field. The third is the array length, stored in the @uint field. And again,
2904  * if the @ptrflag is %NULL, the following two are omitted.
2905  * 
2906  * For example, the function glk_put_buffer() can be invoked as follows:
2907  * |[
2908  * char buf[64];
2909  * glui32 len = 64;
2910  * glk_put_buffer(buf, len);
2911  * ...or...
2912  * gluniversal_t arglist[3];
2913  * arglist[0].ptrflag = TRUE;
2914  * arglist[1].array = buf;
2915  * arglist[2].uint = len;
2916  * gidispatch_call(0x0084, 3, arglist);
2917  * ]|
2918  * 
2919  * Since you are passing a C char array to gidispatch_call(), the contents will
2920  * be read directly from that. There is no need to copy data into @arglist, as
2921  * you would for a basic type.
2922  * 
2923  * If you are implementing a VM whose native representation of char arrays is
2924  * more complex, you will have to do more work. You should allocate a C char
2925  * array, copy your characters into it, make the call, and then free the array.
2926  *
2927  * <note><para>
2928  *   glk_put_buffer() does not modify the array passed to it, so there is no
2929  *   need to copy the characters out.
2930  * </para></note></para></refsect3>
2931  * <refsect3 id="chimara-Return-Values"><title>Return Values</title><para>
2932  * The return value of a function is not treated specially. It is simply
2933  * considered to be a pass-out reference argument which may not be %NULL. It
2934  * comes after all the other arguments of the function.
2935  * 
2936  * For example, the function glk_window_get_rock() can be invoked as follows:
2937  * |[
2938  * glui32 rock;
2939  * winid_t win;
2940  * rock = glk_window_get_rock(win);
2941  * ...or...
2942  * gluniversal_t arglist[3];
2943  * arglist[0].opaqueref = win;
2944  * arglist[1].ptrflag = TRUE;
2945  * gidispatch_call(0x0021, 3, arglist);
2946  * rock = arglist[2].uint;
2947  * ]|
2948  * </para></refsect3><para>
2949  */
2950
2951 /**
2952  * gluniversal_t:
2953  * @uint: Stores a #glui32.
2954  * @sint: Stores a #glsi32.
2955  * @opaqueref: Stores a #winid_t, #strid_t, #frefid_t, or #schanid_t.
2956  * @uch: Stores an #unsigned #char.
2957  * @sch: Stores a #signed #char.
2958  * @ch: Stores a #char with the default signedness.
2959  * @charstr: Stores a null-terminated string.
2960  * @unicharstr: Stores a zero-terminated string of #glui32 values representing
2961  * Unicode characters.
2962  * @array: Stores a pointer to an array, and should be followed by another 
2963  * #gluniversal_t with the array length stored in the @uint member.
2964  * @ptrflag: If %FALSE, represents an opaque reference or array that is %NULL,
2965  * in which case it represents the entire argument. If %TRUE, should be followed
2966  * by another #gluniversal_t with the pointer in its @opaqueref or @array field.
2967  *
2968  * This is a union, encompassing all the types that can be passed to Glk
2969  * functions.
2970  */
2971  
2972 /**
2973  * gidispatch_prototype:
2974  * @funcnum: A selector for the function to be queried.
2975  *
2976  * This returns a string which encodes the proper argument list for the given
2977  * function. If there is no such function in the library, this returns %NULL.
2978  * 
2979  * The prototype string for the <function>glk_glomp&lpar;&rpar;</function> 
2980  * function described above would be: <code>"4IuQa&amp;Iu&amp;Qb:"</code>. The 
2981  * <code>"4"</code> is the number of arguments (including the return value, if 
2982  * there is one, which in this case there isn't.) <code>"Iu"</code> denotes an 
2983  * unsigned integer; <code>"Qa"</code> is an opaque object of class 0 (window).
2984  * <code>"&amp;Iu"</code> is a <emphasis>reference</emphasis> to an unsigned
2985  * integer, and <code>"&amp;Qb"</code> is a reference to a stream. The colon at
2986  * the end terminates the argument list; the return value would follow it, if
2987  * there was one.
2988  * 
2989  * Note that the initial number (<code>"4"</code> in this case) is the number of
2990  * logical arguments, not the number of #gluniversal_t objects which will be
2991  * passed to gidispatch_call(). The <function>glk_glomp&lpar;&rpar;</function> 
2992  * call uses anywhere from four to six #gluniversal_t objects, as demonstrated 
2993  * above.
2994  * 
2995  * The basic type codes:
2996  * <variablelist>
2997  * <varlistentry>
2998  *   <term><code>Iu, Is</code></term>
2999  *   <listitem><para>Unsigned and signed 32-bit integer.</para></listitem>
3000  * </varlistentry>
3001  * <varlistentry>
3002  *   <term><code>Cn, Cu, Cs</code></term>
3003  *   <listitem><para>Character, #unsigned #char, and #signed #char.</para>
3004  *     <note><para>Of course <code>Cn</code> will be the same as either 
3005  *     <code>Cu</code> or <code>Cs</code>, depending on the platform. For this
3006  *     reason, Glk avoids using it, but it is included here for completeness.
3007  *     </para></note>
3008  *   </listitem>
3009  * </varlistentry>
3010  * <varlistentry>
3011  *   <term><code>S</code></term>
3012  *   <listitem><para>A C-style string (null-terminated array of #char). In Glk,
3013  *   strings are always treated as read-only and used immediately; the library
3014  *   does not retain a reference to a string between Glk calls. A Glk call that
3015  *   wants to use writable char arrays will use an array type 
3016  *   (<code>"&num;C"</code>), not string (<code>"S"</code>).</para></listitem>
3017  * </varlistentry>
3018  * <varlistentry>
3019  *   <term><code>U</code></term>
3020  *   <listitem><para>A zero-terminated array of 32-bit integers. This is
3021  *   primarily intended as a Unicode equivalent of <code>"S"</code>. Like 
3022  *   <code>"S"</code> strings, <code>"U"</code> strings are read-only and used
3023  *   immediately. A Glk call that wants to use writable Unicode arrays will use
3024  *   an array type (<code>"&num;Iu"</code>) instead of <code>"U"</code>.</para>
3025  *   </listitem>
3026  * </varlistentry>
3027  * <varlistentry>
3028  *   <term><code>F</code></term>
3029  *   <listitem><para>A floating-point value. Glk does not currently use
3030  *   floating-point values, but we might as well define a code for them.</para>
3031  *   </listitem>
3032  * </varlistentry>
3033  * <varlistentry>
3034  *   <term><code>Qa, Qb, Qc...</code></term>
3035  *   <listitem><para>A reference to an opaque object. The second letter
3036  *   determines which class is involved. (The number of classes can be gleaned
3037  *   from gidispatch_count_classes(); see <link 
3038  *   linkend="chimara-Interrogating-the-Interface">Interrogating the
3039  *   Interface</link>).</para>
3040  *   <note><para>
3041  *     If Glk expands to have more than 26 classes, we'll think of something.
3042  *   </para></note></listitem>
3043  * </varlistentry>
3044  * </variablelist>
3045  * Any type code can be prefixed with one or more of the following characters
3046  * (order does not matter):
3047  * <variablelist>
3048  * <varlistentry>
3049  *   <term><code>&amp;</code></term>
3050  *   <listitem><para>A reference to the type; or, if you like, a variable passed
3051  *   by reference. The reference is passed both in and out, so you must copy the
3052  *   value in before calling gidispatch_call() and copy it out afterward.</para>
3053  *   </listitem>
3054  * </varlistentry>
3055  * <varlistentry>
3056  *   <term><code>&lt;</code></term>
3057  *   <listitem><para>A reference which is pass-out only. The initial value is
3058  *   ignored, so you only need copy out the value after the call.</para>
3059  *   </listitem>
3060  * </varlistentry>
3061  * <varlistentry>
3062  *   <term><code>&gt;</code></term>
3063  *   <listitem><para>A reference which is pass-in only.</para>
3064  *   <note><para>
3065  *     This is not generally used for simple types, but is useful for structures
3066  *     and arrays.
3067  *   </para></note></listitem>
3068  * </varlistentry>
3069  * <varlistentry>
3070  *   <term><code>+</code></term>
3071  *   <listitem><para>Combined with <code>"&"</code>, <code>"&lt;"</code>, or 
3072  *   <code>"&gt;"</code>, indicates that a valid reference is mandatory; %NULL
3073  *   cannot be passed.</para>
3074  *   <note><para>
3075  *     Note that even though the @ptrflag #gluniversal_t for a <code>"+"</code>
3076  *     reference is always %TRUE, it cannot be omitted.
3077  *   </para></note></listitem>
3078  * </varlistentry>
3079  * <varlistentry>
3080  *   <term><code>:</code></term>
3081  *   <listitem><para>The colon separates the arguments from the return value, or
3082  *   terminates the string if there is no return value. Since return values are
3083  *   always non-%NULL pass-out references, you may treat <code>":"</code> as
3084  *   equivalent to <code>"&lt;+"</code>. The colon is never combined with any
3085  *   other prefix character.</para></listitem>
3086  * </varlistentry>
3087  * <varlistentry>
3088  *   <term><code>[...]</code></term>
3089  *   <listitem><para>Combined with <code>"&amp;"</code>, <code>"&lt;"</code>, or 
3090  *   <code>"&gt;"</code>, indicates a structure reference. Between the brackets
3091  *   is a complete argument list encoding string, including the number of
3092  *   arguments.</para>
3093  *   <note><para>
3094  *     For example, the prototype string for glk_select() is
3095  *     <code>"1&lt;+[4IuQaIuIu]:"</code> &mdash; one argument, which is a
3096  *     pass-out non-%NULL reference to a structure, which contains four
3097  *     arguments.
3098  *   </para></note>
3099  *   <para>Currently, structures in Glk contain only basic types.</para>
3100  *   </listitem>
3101  * </varlistentry>
3102  * <varlistentry>
3103  *   <term><code>&num;</code></term>
3104  *   <listitem><para>Combined with <code>"&amp;"</code>, <code>"&lt;"</code>, or 
3105  *   <code>"&gt;"</code>, indicates an array reference. As described above, this
3106  *   encompasses up to three #gluniversal_t objects &mdash; @ptrflag, pointer,
3107  *   and integer length.</para>
3108  *   <note><para>
3109  *     Depending on the design of your program, you may wish to pass a pointer
3110  *     directly to your program's memory, or allocate an array and copy the
3111  *     contents in and out. See <link linkend="chimara-Arrays">Arrays</link>.
3112  *   </para></note></listitem>
3113  * </varlistentry>
3114  * <varlistentry>
3115  *   <term><code>!</code></term>
3116  *   <listitem><para>Combined with <code>"&num;"</code>, indicates that the
3117  *   array is retained by the library. The library will keep a reference to the
3118  *   array; the contents are undefined until further notice. You should not use
3119  *   or copy the contents of the array out after the call, even for 
3120  *   <code>"&amp;&num;!"</code> or <code>"&lt;&num;!"</code> arrays. Instead, do
3121  *   it when the library releases the array.</para>
3122  *   <note><para>
3123  *     For example, glk_stream_open_memory() retains the array that you pass it,
3124  *     and releases it when the stream is closed. The library can notify you
3125  *     automatically when arrays are retained and released; see <link
3126  *     linkend="gidispatch-set-retained-registry">Retained Array
3127  *     Registry</link>.
3128  *   </para></note></listitem>
3129  * </varlistentry>
3130  * </variablelist>
3131  *
3132  * Returns: A string which encodes the prototype of the specified Glk function.
3133  */
3134
3135 /**
3136  * gidisp_Class_Window:
3137  *
3138  * Represents a #winid_t opaque object.
3139  */
3140  
3141 /**
3142  * gidisp_Class_Stream:
3143  *
3144  * Represents a #strid_t opaque object.
3145  */
3146  
3147 /**
3148  * gidisp_Class_Fileref:
3149  *
3150  * Represents a #frefid_t opaque object.
3151  */
3152
3153 /**
3154  * gidisp_Class_Schannel:
3155  * 
3156  * Represents a #schanid_t opaque object.
3157  */
3158
3159 /**
3160  * gidispatch_rock_t:
3161  * @num: Space for storing an integer.
3162  * @ptr: Space for storing a pointer.
3163  *
3164  * You can store any value you want in this object; return it from your object
3165  * registry and retained array registry callbacks, and the library will stash it
3166  * away. You can retrieve it with gidispatch_get_objrock().
3167  */ 
3168
3169 /*---------- TYPES, FUNCTIONS AND CONSTANTS FROM GI_BLORB.H ------------------*/
3170  
3171 /**
3172  * giblorb_err_t: 
3173  *
3174  * An integer type that can hold the Blorb error codes.
3175  */ 
3176  
3177 /**
3178  * giblorb_err_None:
3179  *
3180  * No error.
3181  */
3182  
3183 /**
3184  * giblorb_err_CompileTime: 
3185  *
3186  * Something is compiled wrong in the Blorb layer.
3187  */
3188  
3189 /**
3190  * giblorb_err_Alloc: 
3191  *
3192  * Memory could not be allocated.
3193  * <note><title>Chimara</title>
3194  * <para>
3195  *  The Blorb layer in the Chimara library should not return this error code;
3196  *  instead, the program aborts if memory allocation fails, in keeping with
3197  *  GLib practices.
3198  * </para></note> 
3199  */
3200  
3201 /**
3202  * giblorb_err_Read: 
3203  *
3204  * Data could not be read from the file.
3205  */
3206
3207 /** 
3208  * giblorb_err_NotAMap:
3209  *
3210  * The map parameter is invalid.
3211  */
3212
3213 /** 
3214  * giblorb_err_Format:
3215  *
3216  * The Blorb file is corrupted or invalid.
3217  */
3218  
3219 /**
3220  * giblorb_err_NotFound:
3221  *
3222  * The requested data could not be found.
3223  */
3224
3225 /**
3226  * giblorb_method_DontLoad:
3227  *
3228  * Pass this to giblorb_load_chunk_by_type(), giblorb_load_chunk_by_number(), or
3229  * giblorb_load_resource() to obtain information about a chunk without actually
3230  * loading it.
3231  */
3232
3233 /**
3234  * giblorb_method_Memory:
3235  *
3236  * Pass this to giblorb_load_chunk_by_type(), giblorb_load_chunk_by_number(), or
3237  * giblorb_load_resource() to load a chunk into memory.
3238  */
3239
3240 /**
3241  * giblorb_method_FilePos:
3242  *
3243  * Pass this to giblorb_load_chunk_by_type(), giblorb_load_chunk_by_number(), or
3244  * giblorb_load_resource() to get the position in the Blorb file at which the
3245  * chunk data starts.
3246  */
3247
3248 /**
3249  * giblorb_ID_Snd:
3250  *
3251  * Resource usage constant representing a sound file.
3252  */
3253
3254 /**
3255  * giblorb_ID_Exec:
3256  *
3257  * Resource usage constant representing an executable program.
3258  */
3259  
3260 /**
3261  * giblorb_ID_Pict:
3262  *
3263  * Resource usage constant representing an image file.
3264  */
3265
3266 /**
3267  * giblorb_ID_Copyright:
3268  *
3269  * Resource usage constant representing the copyright message (date and holder, 
3270  * without the actual copyright symbol). There should only be one such chunk per
3271  * file.
3272  */
3273
3274 /**
3275  * giblorb_ID_AUTH:
3276  *
3277  * Resource usage constant representing the name of the author or creator of the
3278  * file. This could be a login name on multi-user systems, for example. There
3279  * should only be one such chunk per file.
3280  */
3281  
3282 /**
3283  * giblorb_ID_ANNO:
3284  *
3285  * Resource usage constant representing any textual annotation that the user or 
3286  * writing program sees fit to include.
3287  */ 
3288  
3289 /**
3290  * giblorb_map_t:
3291  *
3292  * Holds the complete description of an open Blorb file. This type is opaque for
3293  * normal interpreter use.
3294  */
3295  
3296 /**
3297  * giblorb_result_t:
3298  * @chunknum: The chunk number (for use in giblorb_unload_chunk(), etc.)
3299  * @data: A union containing a pointer to the data @ptr (if you used 
3300  * %giblorb_method_Memory) and the position in the file @startpos (if you used 
3301  * %giblorb_method_FilePos)
3302  * @length: The length of the data
3303  * @chunktype: The type of the chunk.
3304  *
3305  * Holds information about a chunk loaded from a Blorb file, and the method of
3306  * accessing the chunk data. See giblorb_load_chunk_by_type() and
3307  * giblorb_load_chunk_by_number(). 
3308  */
3309  
3310 /**
3311  * giblorb_create_map:
3312  * @file: An input stream pointing to a Blorb file.
3313  * @newmap: Return location for a Blorb resource map.
3314  *
3315  * Reads Blorb data out of a Glk stream. It does not load every resource at 
3316  * once; instead, it creates a map in memory which makes it easy to find 
3317  * resources. A pointer to the map is stored in @newmap. This is an opaque 
3318  * object; you pass it to the other Blorb-layer functions.
3319  *
3320  * Returns: a Blorb error code. 
3321  */
3322  
3323 /**
3324  * giblorb_destroy_map: 
3325  * @map: A Blorb resource map to deallocate.
3326  *
3327  * Deallocates @map and all associated memory. This does 
3328  * <emphasis>not</emphasis> close the original stream.
3329  *
3330  * Returns: a Blorb error code. 
3331  */
3332
3333 /**
3334  * giblorb_load_chunk_by_type:
3335  * @map: The Blorb resource map to load a chunk from.
3336  * @method: The loading method to use, one of %giblorb_method_DontLoad, 
3337  * %giblorb_method_Memory, or %giblorb_method_FilePos.
3338  * @res: Return location for the result.
3339  * @chunktype: The type of chunk to load.
3340  * @count: The chunk number of type @chunktype to load.
3341  *
3342  * Loads a chunk of a given type. The @count parameter distinguishes between 
3343  * chunks of the same type. If @count is zero, the first chunk of that type is 
3344  * loaded, and so on.
3345  * 
3346  * To load a chunk of an IFF FORM type (such as AIFF), you should pass in the 
3347  * form type, rather than FORM.
3348  * <note><para>
3349  *  This introduces a slight ambiguity &mdash; you cannot distiguish between a 
3350  *  FORM AIFF chunk and a non-FORM chunk of type AIFF. However, the latter is 
3351  *  almost certainly a mistake.
3352  * </para></note> 
3353  * 
3354  * The returned data is written into @res, according to @method.
3355  * 
3356  * The <structfield>chunknum</structfield> field is filled in with the number of
3357  * the chunk. (This value can then be passed to giblorb_load_chunk_by_number() 
3358  * or giblorb_unload_chunk().) The <structfield>length</structfield> field is 
3359  * filled in with the length of the chunk in bytes. The 
3360  * <structfield>chunktype</structfield> field is the chunk's type, which of 
3361  * course will be the type you asked for.
3362  * 
3363  * If you specify %giblorb_method_DontLoad, no data is actually loaded in. You
3364  * can use this if you are only interested in whether a chunk exists, or in the
3365  * <structfield>chunknum</structfield> and <structfield>length</structfield> 
3366  * parameters.
3367  * 
3368  * If you specify %giblorb_method_FilePos, 
3369  * <structfield>data.startpos</structfield> is filled in with the file position
3370  * of the chunk data. You can use glk_stream_set_position() to read the data 
3371  * from the stream.
3372  * 
3373  * If you specify %giblorb_method_Memory, <structfield>data.ptr</structfield> is
3374  * filled with a pointer to allocated memory containing the chunk data. This 
3375  * memory is owned by the map, not you. If you load the chunk more than once 
3376  * with %giblorb_method_Memory, the Blorb layer is smart enough to keep just one
3377  * copy in memory. You should not deallocate this memory yourself; call 
3378  * giblorb_unload_chunk() instead.
3379  *
3380  * Returns: a Blorb error code.
3381  */
3382
3383 /** 
3384  * giblorb_load_chunk_by_number:
3385  * @map: The Blorb resource map to load a chunk from.
3386  * @method: The loading method to use, one of %giblorb_method_DontLoad, 
3387  * %giblorb_method_Memory, or %giblorb_method_FilePos.
3388  * @res: Return location for the result.
3389  * @chunknum: The chunk number to load.
3390  *
3391  * This is similar to giblorb_load_chunk_by_type(), but it loads a chunk with a
3392  * given chunk number. The type of the chunk can be found in the 
3393  * <structfield>chunktype</structfield> field of #giblorb_result_t. You can get
3394  * the chunk number from the <structfield>chunknum</structfield> field, after 
3395  * calling one of the other load functions.
3396  *
3397  * Returns: a Blorb error code. 
3398  */
3399
3400 /**
3401  * giblorb_unload_chunk:
3402  * @map: The Blorb resource map to unload a chunk from.
3403  * @chunknum: The chunk number to unload.
3404  *
3405  * Frees the chunk data allocated by %giblorb_method_Memory. If the given chunk
3406  * has never been loaded into memory, this has no effect. 
3407  *
3408  * Returns: a Blorb error code.
3409  */
3410
3411 /**
3412  * giblorb_load_resource:
3413  * @map: The Blorb resource map to load a resource from.
3414  * @method: The loading method to use, one of %giblorb_method_DontLoad, 
3415  * %giblorb_method_Memory, or %giblorb_method_FilePos.
3416  * @res: Return location for the result.
3417  * @usage: The type of data resource to load.
3418  * @resnum: The resource number to load.
3419  *
3420  * Loads a resource, given its usage and resource number. Currently, the three
3421  * usage values are %giblorb_ID_Pict (images), %giblorb_ID_Snd (sounds), and
3422  * %giblorb_ID_Exec (executable program). See the Blorb specification for more
3423  * information about the types of data that can be stored for these usages.
3424  * 
3425  * Note that a resource number is not the same as a chunk number. The resource
3426  * number is the sound or image number specified by a Glk program. Chunk number
3427  * is arbitrary, since chunks in a Blorb file can be in any order. To find the
3428  * chunk number of a given resource, call giblorb_load_resource() and look in
3429  * <structfield>res.chunknum</structfield>.
3430  *
3431  * Returns: a Blorb error code.
3432  */
3433
3434 /**
3435  * giblorb_count_resources:
3436  * @map: The Blorb resource map in which to count the resources.
3437  * @usage: The type of data resource to count.
3438  * @num: Return location for the number of chunks of @usage.
3439  * @min: Return location for the lowest resource number of @usage.
3440  * @max: Return location for the highest resource number of @usage.
3441  *
3442  * Counts the number of chunks with a given usage (image, sound, or executable.)
3443  * The total number of chunks of that usage is stored in @num. The lowest and 
3444  * highest resource number of that usage are stored in @min and @max. You can
3445  * leave any of the three pointers %NULL if you don't care about that
3446  * information. 
3447  *
3448  * Returns: a Blorb error code.
3449  */
3450
3451 /*--------------------TYPES AND CONSTANTS FROM GLKSTART.H---------------------*/
3452
3453 /**
3454  * glkunix_argumentlist_t:
3455  * @name: the option as it would appear on the command line (including the 
3456  * leading dash, if any.) 
3457  * @desc: a description of the argument; this is used when the library is 
3458  * printing a list of options.
3459  * @argtype: one of the <code>glkunix_arg_</code> constants.
3460  * 
3461  * <variablelist>
3462  * <varlistentry>
3463  *  <term>%glkunix_arg_NoValue</term>
3464  *  <listitem><para>The argument appears by itself.</para></listitem>
3465  * </varlistentry>
3466  * <varlistentry>
3467  *  <term>%glkunix_arg_ValueFollows</term>
3468  *  <listitem><para>The argument must be followed by another argument (the 
3469  *  value).</para></listitem>
3470  * </varlistentry>
3471  * <varlistentry>
3472  *  <term>%glkunix_arg_ValueCanFollow</term> 
3473  *  <listitem><para>The argument may be followed by a value, optionally. (If the
3474  *  next argument starts with a dash, it is taken to be a new argument, not the 
3475  *  value of this one.)</para></listitem>
3476  * </varlistentry>
3477  * <varlistentry>
3478  *  <term>%glkunix_arg_NumberValue</term>
3479  *  <listitem><para>The argument must be followed by a number, which may be the 
3480  *  next argument or part of this one. (That is, either <quote><code>-width 
3481  *  20</code></quote> or <quote><code>-width20</code></quote> will be accepted.)
3482  *  </para></listitem>
3483  * </varlistentry>
3484  * <varlistentry> 
3485  *  <term>%glkunix_arg_End</term>
3486  *  <listitem><para>The <code>glkunix_arguments[]</code> array must be 
3487  *  terminated with an entry containing this value.</para></listitem>
3488  * </varlistentry>
3489  * </variablelist>
3490  * 
3491  * To accept arbitrary arguments which lack dashes, specify a name of 
3492  * <code>""</code> and an argtype of %glkunix_arg_ValueFollows.
3493  *
3494  * If you don't care about command-line arguments, you must still define an
3495  * empty arguments list, as follows:
3496  * |[
3497  * glkunix_argumentlist_t glkunix_arguments[] = {
3498  *     { NULL, glkunix_arg_End, NULL }
3499  * };
3500  * ]|
3501  * 
3502  * Here is a more complete sample list:
3503  * |[
3504  * glkunix_argumentlist_t glkunix_arguments[] = {
3505  *     { "", glkunix_arg_ValueFollows, "filename: The game file to load." },
3506  *     { "-hum", glkunix_arg_ValueFollows, "-hum NUM: Hum some NUM." },
3507  *     { "-bom", glkunix_arg_ValueCanFollow, "-bom [ NUM ]: Do a bom (on
3508  *       the NUM, if given)." },
3509  *     { "-goo", glkunix_arg_NoValue, "-goo: Find goo." },
3510  *     { "-wob", glkunix_arg_NumberValue, "-wob NUM: Wob NUM times." },
3511  *     { NULL, glkunix_arg_End, NULL }
3512  * };
3513  * ]|
3514  * This would match the arguments <quote><code>thingfile -goo -wob8 -bom -hum 
3515  * song</code></quote>.
3516  *
3517  * After the library parses the command line, it does various occult rituals of
3518  * initialization, and then calls glkunix_startup_code().
3519  *
3520  * |[ int glkunix_startup_code(glkunix_startup_t *data); ]|
3521  *
3522  * This should return %TRUE if everything initializes properly. If it returns
3523  * %FALSE, the library will shut down without ever calling your glk_main() 
3524  * function.
3525  */
3526
3527 /**
3528  * glkunix_startup_t: 
3529  * @argc: The number of arguments in @argv.
3530  * @argv: Strings representing command line arguments.
3531  * 
3532  * The fields are a standard Unix <code>(argc, argv)</code> list, which contain
3533  * the arguments you requested from the command line. In deference to custom,
3534  * <code>argv[0]</code> is always the program name.
3535  */
3536
3537 /**
3538  * glkunix_arg_End:
3539  *
3540  * Terminates a list of #glkunix_argumentlist_t.
3541  */
3542  
3543 /**
3544  * glkunix_arg_ValueFollows:
3545  *
3546  * Indicates an argument which must be followed by a value, as the next 
3547  * argument.
3548  */
3549
3550 /** 
3551  * glkunix_arg_NoValue:
3552  *
3553  * Indicates an argument which occurs by itself, without a value.
3554  */
3555  
3556 /**
3557  * glkunix_arg_ValueCanFollow:
3558  *
3559  * Indicates an argument which may be followed by a value, or may occur by 
3560  * itself.
3561  */
3562  
3563 /**
3564  * glkunix_arg_NumberValue:
3565  *
3566  * Indicates an argument which must be followed by a numerical value, either as 
3567  * the next argument or tacked onto the end of this argument.
3568  */