static char *convertUTF(char *l) { char *p, *n, *r; unsigned char c, d; if ( ! (r = (char *) malloc(strlen(l)))) usage(ERR_ALLOC); p = l; n = r; while ( *p != '\r' ) { c = *p; if ( c >= 0x90 ) { if ( (c & 0xfc) != 0xc0 ) { /* Character that quite probably can't * be translated to the Palm-Charset, * so just leave an ? for now */ *n = '?'; p++; if ( c < 0xc0 ) usage(ERR_UTF); if ( c > 0xe0 ) p++; if ( c > 0xf0 ) p++; if ( c > 0xf8 ) p++; if ( c > 0xfc ) p++; if ( c > 0xfe ) p++; } else { c &= 0x03; c <<= 6; p++; d = *p; if ( (d & 0xc0) != 0x80 ) usage(ERR_UTF); d &= 0x3f; *n = c | d; } } else *n = *p; p++; n++; } *n = '\0'; return r; }