Toevoegen van de sources die ik vorige keer vergeten was, en nog wat
[projects/chimara/chimara.git] / src / gestalt.c
1 #include "glk.h"
2
3 /* Version of the Glk specification implemented by this library */
4 #define MAJOR_VERSION 0
5 #define MINOR_VERSION 7
6 #define SUB_VERSION   0
7
8 /**
9  * glk_gestalt:
10  * @sel: A selector, representing which capability to request information 
11  * about.
12  * @val: Extra information, depending on the value of @sel.
13  *
14  * Calls the gestalt system to request information about selector @sel, without
15  * passing an array to store extra information in (see glk_gestalt_ext()).
16  *
17  * Returns: an integer, depending on what selector was called.
18  */
19 glui32
20 glk_gestalt(glui32 sel, glui32 val)
21 {
22         return glk_gestalt_ext(sel, val, NULL, 0);
23 }
24
25 /**
26  * glk_gestalt_ext:
27  * @sel: A selector, representing which capability to request information
28  * about.
29  * @val: Extra information, depending on the value of @sel.
30  * @arr: Location of an array to store extra information in, or #NULL.
31  * @arrlen: Length of @arr, or 0 if @arr is #NULL.
32  *
33  * Calls the gestalt system to request information about selector @sel,
34  * possibly returning information in @arr.
35  *
36  * Returns: an integer, depending on what selector was called.
37  */
38 glui32
39 glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen)
40 {
41         switch(sel)
42         {
43                 /* Version number */
44                 case gestalt_Version:
45                         return MAJOR_VERSION << 16 + MINOR_VERSION << 8 + SUB_VERSION;
46                 
47                 /* Which characters can we print? */    
48                 case gestalt_CharOutput:
49                         /* All characters are printed as one character, in any case */
50                         if(arr && arrlen > 0)
51                                 *arr = 1;
52                         /* Cannot print control chars except \n, or chars > 255 */
53                         if( (val < 32 && val != 10) || (val >= 127 && val <= 159) || (val > 255) )
54                                 return gestalt_CharOutput_CannotPrint;
55                         /* Can print all other Latin-1 characters */
56                         return gestalt_CharOutput_ExactPrint;
57                         
58                 /* Selector not supported */    
59                 default:
60                         return 0;
61         }
62 }
63