Glk: How to implement stream?

I’m trying to fix the stream functions in Zag, but I have a problem with the unicode support. In Andrew Plotkin’s test files he’s freely mixing calls to unicode and non-unicode functions. I’m not sure, how to implement this in Java. For example the function get_char has to read a single byte character, but the get_char_uni function has to read a two-byte character, but only if it is not an ASCII character. Then it is supposed to work like get_char. How am I supposed to know, if the next character in a stream is unicode or not?

You can look at the C implementation in cheapglk. It’s messy but not complicated.

get_char and get_char_uni treat the stream the same way. The only difference is that get_char won’t return a character beyond 255. If the character it gets off the stream is higher, get_char returns ‘?’ instead.

The mechanics of reading a character off the stream depend on whether the stream was opened as unicode, and whether it was opened as binary or text.

The current recommendation (hasn’t been published in the spec yet, but it will be): see … ec-changes

Thanks for the quick reply. That’s immensely helpful. And it makes things much easier.