| 1 |
/****************************************************************************** |
| 2 |
* * |
| 3 |
* Copyright (C) 2006-2009 by Tor Andersson, Andrew Plotkin. * |
| 4 |
* * |
| 5 |
* This file is part of Gargoyle. * |
| 6 |
* * |
| 7 |
* Gargoyle is free software; you can redistribute it and/or modify * |
| 8 |
* it under the terms of the GNU General Public License as published by * |
| 9 |
* the Free Software Foundation; either version 2 of the License, or * |
| 10 |
* (at your option) any later version. * |
| 11 |
* * |
| 12 |
* Gargoyle is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU General Public License * |
| 18 |
* along with Gargoyle; if not, write to the Free Software * |
| 19 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
* * |
| 21 |
*****************************************************************************/ |
| 22 |
|
| 23 |
/* cggestal.c: Gestalt functions for Glk API, version 0.7.5. |
| 24 |
Designed by Andrew Plotkin <[email protected]> |
| 25 |
http://www.eblong.com/zarf/glk/index.html |
| 26 |
|
| 27 |
Portions of this file are copyright 1998-2016 by Andrew Plotkin. |
| 28 |
It is distributed under the MIT license; see the "LICENSE" file. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <string.h> |
| 34 |
#include "glk.h" |
| 35 |
#include "garglk.h" |
| 36 |
|
| 37 |
#ifdef GARGLK |
| 38 |
#define TRUE true |
| 39 |
#define FALSE false |
| 40 |
static const bool gli_utf8input = true; |
| 41 |
static const bool gli_utf8output = true; |
| 42 |
#endif |
| 43 |
|
| 44 |
glui32 glk_gestalt(glui32 id, glui32 val) |
| 45 |
{ |
| 46 |
return glk_gestalt_ext(id, val, NULL, 0); |
| 47 |
} |
| 48 |
|
| 49 |
glui32 glk_gestalt_ext(glui32 id, glui32 val, glui32 *arr, |
| 50 |
glui32 arrlen) |
| 51 |
{ |
| 52 |
switch (id) { |
| 53 |
|
| 54 |
case gestalt_Version: |
| 55 |
/* This implements Glk spec version 0.7.6. */ |
| 56 |
return 0x00000706; |
| 57 |
|
| 58 |
case gestalt_LineInput: |
| 59 |
#ifdef GARGLK |
| 60 |
if (val >= 32 && val < 0x10ffff) |
| 61 |
#else |
| 62 |
if (val >= 32 && val < 127) |
| 63 |
#endif |
| 64 |
return TRUE; |
| 65 |
else |
| 66 |
return FALSE; |
| 67 |
|
| 68 |
case gestalt_CharInput: |
| 69 |
if (val >= 32 && val < 127) |
| 70 |
return TRUE; |
| 71 |
else if (val == keycode_Return) |
| 72 |
return TRUE; |
| 73 |
else { |
| 74 |
/* If we're doing UTF-8 input, we can input any Unicode |
| 75 |
character. Except control characters. */ |
| 76 |
if (gli_utf8input) { |
| 77 |
if (val >= 160 && val < 0x200000) |
| 78 |
return TRUE; |
| 79 |
} |
| 80 |
/* If not, we can't accept anything non-ASCII */ |
| 81 |
return FALSE; |
| 82 |
} |
| 83 |
|
| 84 |
case gestalt_CharOutput: |
| 85 |
if (val >= 32 && val < 127) { |
| 86 |
if (arr && arrlen >= 1) |
| 87 |
arr[0] = 1; |
| 88 |
return gestalt_CharOutput_ExactPrint; |
| 89 |
} |
| 90 |
else { |
| 91 |
/* cheaply, we don't do any translation of printed |
| 92 |
characters, so the output is always one character |
| 93 |
even if it's wrong. */ |
| 94 |
if (arr && arrlen >= 1) |
| 95 |
arr[0] = 1; |
| 96 |
/* If we're doing UTF-8 output, we can print any Unicode |
| 97 |
character. Except control characters. */ |
| 98 |
if (gli_utf8output) { |
| 99 |
if (val >= 160 && val < 0x200000) |
| 100 |
return gestalt_CharOutput_ExactPrint; |
| 101 |
} |
| 102 |
return gestalt_CharOutput_CannotPrint; |
| 103 |
} |
| 104 |
|
| 105 |
case gestalt_MouseInput: |
| 106 |
#ifdef GARGLK |
| 107 |
if (val == wintype_TextGrid) |
| 108 |
return TRUE; |
| 109 |
if (val == wintype_Graphics) |
| 110 |
return TRUE; |
| 111 |
#endif |
| 112 |
return FALSE; |
| 113 |
|
| 114 |
case gestalt_Timer: |
| 115 |
#ifdef GARGLK |
| 116 |
return TRUE; |
| 117 |
#else |
| 118 |
return FALSE; |
| 119 |
#endif |
| 120 |
|
| 121 |
case gestalt_Graphics: |
| 122 |
case gestalt_GraphicsTransparency: |
| 123 |
#ifdef GARGLK |
| 124 |
return gli_conf_graphics; |
| 125 |
#endif |
| 126 |
case gestalt_GraphicsCharInput: |
| 127 |
return FALSE; |
| 128 |
|
| 129 |
case gestalt_DrawImage: |
| 130 |
case gestalt_DrawImageScale: |
| 131 |
#ifdef GARGLK |
| 132 |
if (val == wintype_TextBuffer) |
| 133 |
return gli_conf_graphics; |
| 134 |
if (val == wintype_Graphics) |
| 135 |
return gli_conf_graphics; |
| 136 |
#endif |
| 137 |
return FALSE; |
| 138 |
|
| 139 |
case gestalt_Unicode: |
| 140 |
#ifdef GLK_MODULE_UNICODE |
| 141 |
return TRUE; |
| 142 |
#else |
| 143 |
return FALSE; |
| 144 |
#endif /* GLK_MODULE_UNICODE */ |
| 145 |
|
| 146 |
case gestalt_UnicodeNorm: |
| 147 |
#ifdef GLK_MODULE_UNICODE_NORM |
| 148 |
return TRUE; |
| 149 |
#else |
| 150 |
return FALSE; |
| 151 |
#endif /* GLK_MODULE_UNICODE_NORM */ |
| 152 |
|
| 153 |
case gestalt_Sound: |
| 154 |
case gestalt_SoundVolume: |
| 155 |
case gestalt_SoundNotify: |
| 156 |
case gestalt_SoundMusic: |
| 157 |
#ifndef GARGLK |
| 158 |
return FALSE; |
| 159 |
#endif |
| 160 |
case gestalt_Sound2: |
| 161 |
#if defined(GARGLK) && !defined(GARGLK_CONFIG_NO_SOUND) |
| 162 |
return gli_conf_sound; |
| 163 |
#else |
| 164 |
/* Sound2 implies all the above sound options. But for |
| 165 |
cheapglk, they're all false. */ |
| 166 |
return FALSE; |
| 167 |
#endif |
| 168 |
|
| 169 |
case gestalt_LineInputEcho: |
| 170 |
#ifdef GARGLK |
| 171 |
return TRUE; |
| 172 |
#else |
| 173 |
return FALSE; |
| 174 |
#endif |
| 175 |
|
| 176 |
case gestalt_LineTerminators: |
| 177 |
#ifdef GARGLK |
| 178 |
return TRUE; |
| 179 |
#endif |
| 180 |
case gestalt_LineTerminatorKey: |
| 181 |
#ifdef GARGLK |
| 182 |
return gli_window_check_terminator(val); |
| 183 |
#else |
| 184 |
return FALSE; |
| 185 |
#endif |
| 186 |
|
| 187 |
case gestalt_DateTime: |
| 188 |
return TRUE; |
| 189 |
|
| 190 |
case gestalt_ResourceStream: |
| 191 |
#ifdef GARGLK |
| 192 |
return TRUE; |
| 193 |
#else |
| 194 |
return FALSE; |
| 195 |
#endif |
| 196 |
|
| 197 |
#ifdef GARGLK |
| 198 |
case gestalt_Hyperlinks: |
| 199 |
return TRUE; |
| 200 |
case gestalt_HyperlinkInput: |
| 201 |
return TRUE; |
| 202 |
|
| 203 |
case gestalt_GarglkText: |
| 204 |
return TRUE; |
| 205 |
#endif |
| 206 |
|
| 207 |
default: |
| 208 |
return 0; |
| 209 |
|
| 210 |
} |
| 211 |
} |
| 212 |
|