-
Notifications
You must be signed in to change notification settings - Fork 11
/
gtgestal.c
142 lines (120 loc) · 4.2 KB
/
gtgestal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* gtgestal.c: The Gestalt system
for GlkTerm, curses.h implementation of the Glk API.
Designed by Andrew Plotkin <[email protected]>
http://www.eblong.com/zarf/glk/index.html
*/
#include "gtoption.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "glk.h"
#include "glkterm.h"
glui32 glk_gestalt(glui32 id, glui32 val)
{
return glk_gestalt_ext(id, val, NULL, 0);
}
glui32 glk_gestalt_ext(glui32 id, glui32 val, glui32 *arr, glui32 arrlen)
{
int ix;
switch (id) {
case gestalt_Version:
/* This implements Glk spec version 0.7.4. */
return 0x00000704;
case gestalt_LineInput:
if ((val >= 0 && val < 32) || val == '\177') {
/* Control characters never appear in line input. */
return FALSE;
}
if (val >= 32 && val < 256) {
return char_typable_table[val];
}
return FALSE;
case gestalt_CharInput:
if (val >= 0 && val < 256) {
return char_typable_table[val];
}
if (val <= 0xFFFFFFFF && val > (0xFFFFFFFF - keycode_MAXVAL)) {
/* Special key code. We conservatively declare that only the
arrow keys, return, del/backspace, and escape can be
typed. Function keys might work, but we can't be
sure they're there. */
if (val == keycode_Left || val == keycode_Right
|| val == keycode_Up || val == keycode_Down
|| val == keycode_Return || val == keycode_Delete
|| val == keycode_Escape)
return TRUE;
else
return FALSE;
}
return FALSE;
case gestalt_CharOutput:
if (char_printable_table[(unsigned char)val]) {
if (arr && arrlen >= 1)
arr[0] = 1;
return gestalt_CharOutput_ExactPrint;
}
else {
char *altstr = gli_ascii_equivalent((unsigned char)val);
ix = strlen(altstr);
if (arr && arrlen >= 1)
arr[0] = ix;
if (ix == 4 && altstr[0] == '\\') {
/* It's a four-character octal code, "\177". */
return gestalt_CharOutput_CannotPrint;
}
else {
/* It's some string from char_A0_FF_to_ascii() in
gtmisc.c. */
return gestalt_CharOutput_ApproxPrint;
}
}
case gestalt_MouseInput:
return FALSE;
case gestalt_Timer:
#ifdef OPT_TIMED_INPUT
return TRUE;
#else /* !OPT_TIMED_INPUT */
return FALSE;
#endif /* OPT_TIMED_INPUT */
case gestalt_Graphics:
case gestalt_GraphicsTransparency:
return FALSE;
case gestalt_DrawImage:
return FALSE;
case gestalt_Unicode:
#ifdef GLK_MODULE_UNICODE
return TRUE;
#else
return FALSE;
#endif /* GLK_MODULE_UNICODE */
case gestalt_UnicodeNorm:
#ifdef GLK_MODULE_UNICODE_NORM
return TRUE;
#else
return FALSE;
#endif /* GLK_MODULE_UNICODE_NORM */
case gestalt_Sound:
case gestalt_SoundVolume:
case gestalt_SoundNotify:
case gestalt_SoundMusic:
return FALSE;
case gestalt_LineInputEcho:
return TRUE;
case gestalt_LineTerminators:
return TRUE;
case gestalt_LineTerminatorKey:
/* GlkTerm never uses the escape or function keys for anything,
so we'll allow them to be line terminators. */
if (val == keycode_Escape)
return TRUE;
if (val >= keycode_Func12 && val <= keycode_Func1)
return TRUE;
return FALSE;
case gestalt_DateTime:
return TRUE;
case gestalt_ResourceStream:
return TRUE;
default:
return 0;
}
}