/*
 * The RISC OS Latin-1 alphabet against Unicode, both ways.
 *   Copyright RISC OS Developments 2019+, credited to the RISC OS One Project.
 *
 * SMB1 carried names as bytes and a RISC OS machine could put its own
 * bytes on the wire unaltered.  SMB2 carries them as UTF-16, so every
 * name has to be converted, and the conversion is not the identity: the
 * range &80-&9F, which in Latin-1 proper is a block of control codes, is
 * where RISC OS keeps the Euro sign, the W and Y circumflexes, the
 * quotation marks, the dashes and the ligatures.  Treating a name as
 * Latin-1 leaves all thirty-two of those wrong in both directions.
 */

#ifndef _ALPHABET_
#define _ALPHABET_

/*
    A RISC OS character as its Unicode code point.  Every character in the
    alphabet has one; the six positions RISC OS leaves undefined give
    U+FFFD, which is what a server will show for them.
*/
unsigned int AlphabetToUnicode(unsigned int ch);

/*
    A Unicode code point as a RISC OS character, or 0 where the alphabet
    has no such character - which includes every code point above U+00FF
    that is not one of the thirty-two, and the C1 controls U+0080-U+009F,
    whose byte values RISC OS uses for something else entirely.
*/
unsigned int AlphabetFromUnicode(unsigned int u);

/*
    How long one escape is: a marker and four hexadecimal digits.
*/
#define ALPHABET_ESCAPE_LEN (5)

int AlphabetEscape(unsigned int u, char *out);
/*
    Write one UTF-16 unit the alphabet cannot hold as "$ABCD" - five
    characters, no terminator - and say how many that was.

    The marker is a dollar because the layer above swaps a server's dollar
    for a RISC OS "<", so this reaches the user as "<ABCD" and travels back
    through that layer unaltered.
*/

int AlphabetUnescape(const char *s, unsigned int *u);
/*
    Read one back.  Returns the number of characters consumed, or 0 if what
    is there is not an escape, in which case nothing is written.
*/

int AlphabetIsHex(int c);
/*
    Whether one character could be part of an escape's four digits.  For
    deciding whether a dollar that is really a dollar has to be written out
    as an escape itself to avoid being read back as one.
*/

#endif
