void inputx_postn_utf8_rate(const char *text, size_t text_len, mame_time rate) { size_t len = 0; unicode_char_t buf[256]; unicode_char_t c; int rc; while(text_len > 0) { if (len == (sizeof(buf) / sizeof(buf[0]))) { inputx_postn(buf, len); len = 0; } rc = uchar_from_utf8(&c, text, text_len); if (rc < 0) { rc = 1; c = INVALID_CHAR; } text += rc; text_len -= rc; buf[len++] = c; } inputx_postn_rate(buf, len, rate); }
void inputx_postn_rate(const unicode_char_t *text, size_t text_len, mame_time rate) { int last_cr = 0; unicode_char_t ch; const char *s; const struct CharInfo *ci; current_rate = rate; if (inputx_can_post()) { while((text_len > 0) && !buffer_full()) { ch = *(text++); text_len--; /* change all eolns to '\r' */ if ((ch != '\n') || !last_cr) { if (ch == '\n') ch = '\r'; else last_cr = (ch == '\r'); if (LOG_INPUTX) logerror("inputx_postn(): code=%i (%s) port=%i ipt->name='%s'\n", (int) ch, charstr(ch), codes[ch].port[0], codes[ch].ipt[0] ? codes[ch].ipt[0]->name : "<null>"); if (can_post_key_directly(ch)) { /* we can post this key in the queue directly */ internal_post_key(ch); } else if (can_post_key_alternate(ch)) { /* we can post this key with an alternate representation */ ci = find_charinfo(ch); assert(ci && ci->alternate); s = ci->alternate; while(*s) { s += uchar_from_utf8(&ch, s, strlen(s)); internal_post_key(ch); } } } else { last_cr = 0; } } } }
static int can_post_key_alternate(unicode_char_t ch) { const char *s; const struct CharInfo *ci; unicode_char_t uchar; int rc; ci = find_charinfo(ch); s = ci ? ci->alternate : NULL; if (!s) return 0; while(*s) { rc = uchar_from_utf8(&uchar, s, strlen(s)); if (rc <= 0) return 0; if (!can_post_key_directly(uchar)) return 0; s += rc; } return 1; }
int core_fgetc(core_file *file) { int result; /* refresh buffer, if necessary */ if (file->back_char_head == file->back_char_tail) { utf16_char utf16_buffer[UTF16_CHAR_MAX]; char utf8_buffer[UTF8_CHAR_MAX]; char default_buffer[16]; unicode_char uchar = (unicode_char) ~0; int readlen, charlen; /* do we need to check the byte order marks? */ if (file->offset == 0) { UINT8 bom[4]; int pos = 0; if (core_fread(file, bom, 4) == 4) { if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf) { file->text_type = TFT_UTF8; pos = 3; } else if (bom[0] == 0x00 && bom[1] == 0x00 && bom[2] == 0xfe && bom[3] == 0xff) { file->text_type = TFT_UTF32BE; pos = 4; } else if (bom[0] == 0xff && bom[1] == 0xfe && bom[2] == 0x00 && bom[3] == 0x00) { file->text_type = TFT_UTF32LE; pos = 4; } else if (bom[0] == 0xfe && bom[1] == 0xff) { file->text_type = TFT_UTF16BE; pos = 2; } else if (bom[0] == 0xff && bom[1] == 0xfe) { file->text_type = TFT_UTF16LE; pos = 2; } else { file->text_type = TFT_OSD; pos = 0; } } core_fseek(file, pos, SEEK_SET); } /* fetch the next character */ switch (file->text_type) { default: case TFT_OSD: readlen = core_fread(file, default_buffer, sizeof(default_buffer)); if (readlen > 0) { charlen = osd_uchar_from_osdchar(&uchar, default_buffer, readlen / sizeof(default_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(default_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF8: readlen = core_fread(file, utf8_buffer, sizeof(utf8_buffer)); if (readlen > 0) { charlen = uchar_from_utf8(&uchar, utf8_buffer, readlen / sizeof(utf8_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(utf8_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF16BE: readlen = core_fread(file, utf16_buffer, sizeof(utf16_buffer)); if (readlen > 0) { charlen = uchar_from_utf16be(&uchar, utf16_buffer, readlen / sizeof(utf16_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(utf16_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF16LE: readlen = core_fread(file, utf16_buffer, sizeof(utf16_buffer)); if (readlen > 0) { charlen = uchar_from_utf16le(&uchar, utf16_buffer, readlen / sizeof(utf16_buffer[0])); core_fseek(file, (INT64) (charlen * sizeof(utf16_buffer[0])) - readlen, SEEK_CUR); } break; case TFT_UTF32BE: if (core_fread(file, &uchar, sizeof(uchar)) == sizeof(uchar)) uchar = BIG_ENDIANIZE_INT32(uchar); break; case TFT_UTF32LE: if (core_fread(file, &uchar, sizeof(uchar)) == sizeof(uchar)) uchar = LITTLE_ENDIANIZE_INT32(uchar); break; } if (uchar != ~0) { /* place the new character in the ring buffer */ file->back_char_head = 0; file->back_char_tail = utf8_from_uchar(file->back_chars, ARRAY_LENGTH(file->back_chars), uchar); /* assert(file->back_char_tail != -1);*/ } } /* now read from the ring buffer */ if (file->back_char_head != file->back_char_tail) { result = file->back_chars[file->back_char_head++]; file->back_char_head %= ARRAY_LENGTH(file->back_chars); } else result = EOF; return result; }