Add sj4_ime_convbuf
This commit is contained in:
parent
54f9cd26d2
commit
28af75999a
3 changed files with 50 additions and 8 deletions
|
|
@ -5,6 +5,10 @@
|
|||
|
||||
#include <wchar.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum SJ4CHARSET {
|
||||
SJ4EUCJP = 0,
|
||||
SJ4SJIS,
|
||||
|
|
@ -22,4 +26,8 @@ int sj4_to_utf16(u_char* out, const u_char* in, int len);
|
|||
int sj4_charset_to(int type, void* output, const void* input, int len);
|
||||
int sj4_charset_from(int type, void* output, const void* input, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ typedef struct sj4ime Sj4Ime;
|
|||
|
||||
Sj4Ime* sj4_ime(int charset, const char* dict);
|
||||
void sj4_ime_key(Sj4Ime* ime, int key);
|
||||
void* sj4_ime_convbuf(Sj4Ime* ime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ struct sj4ime {
|
|||
|
||||
u_char romabuf[SJ4BUFSZ];
|
||||
u_char kanabuf[SJ4BUFSZ];
|
||||
u_char convbuf[SJ4BUFSZ];
|
||||
};
|
||||
|
||||
static struct sj4table {
|
||||
|
|
@ -78,22 +79,52 @@ static void concat(int charset, u_char* out, u_char* in) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void comp(Sj4Ime* ime) {
|
||||
ime->kanabuf[0] = 0;
|
||||
ime->last = 0;
|
||||
static void concat_nc(int charset, u_char* out, u_char* in) {
|
||||
int i, j;
|
||||
|
||||
#ifdef UCS
|
||||
if(charset == SJ4UTF16) {
|
||||
wchar_t* w_out = (wchar_t*)out;
|
||||
|
||||
i = w_len(w_out);
|
||||
j = w_len((wchar_t*)in);
|
||||
|
||||
memcpy(w_out + i, in, j * sizeof(wchar_t));
|
||||
w_out[i + j] = 0;
|
||||
} else
|
||||
#else
|
||||
{
|
||||
i = strlen(out);
|
||||
j = strlen(in);
|
||||
|
||||
memcpy(out + i, in, j);
|
||||
out[i + j] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#define ZEROBUF memset(&ime->kouho.buffer, 0, sizeof(ime->kouho.buffer))
|
||||
|
||||
static void comp(Sj4Ime* ime) {
|
||||
if(ime->last == 0) {
|
||||
concat_nc(ime->charset, ime->convbuf, ime->kanabuf);
|
||||
} else {
|
||||
concat_nc(ime->charset, ime->convbuf, ime->kouho.buffer.raw);
|
||||
}
|
||||
printf("%s\n", ime->convbuf);
|
||||
|
||||
ime->kanabuf[0] = 0;
|
||||
ime->last = 0;
|
||||
ZEROBUF;
|
||||
}
|
||||
|
||||
void sj4_ime_key(Sj4Ime* ime, int key) {
|
||||
if(key == '\n') {
|
||||
comp(ime);
|
||||
|
||||
ZEROBUF;
|
||||
} else if(key == ' ') {
|
||||
reconvert:
|
||||
if((ime->last = b_len(ime->charset, &ime->kouho.buffer)) == 0) {
|
||||
sj4_getkan(ime->lib, ime->kanabuf, strlen(ime->kanabuf), &ime->kouho);
|
||||
if(b_len(ime->charset, &ime->kouho.buffer) == 0) {
|
||||
ime->last = sj4_getkan(ime->lib, ime->kanabuf, strlen(ime->kanabuf), &ime->kouho);
|
||||
} else {
|
||||
if((ime->last = sj4_nextkan(ime->lib)) == 0) {
|
||||
ZEROBUF;
|
||||
|
|
@ -101,8 +132,6 @@ void sj4_ime_key(Sj4Ime* ime, int key) {
|
|||
goto reconvert;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s\n", ime->kouho.buffer.utf8);
|
||||
} else if('a' <= tolower(key) && tolower(key) <= 'z') {
|
||||
int i;
|
||||
|
||||
|
|
@ -145,3 +174,7 @@ void sj4_ime_key(Sj4Ime* ime, int key) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void* sj4_ime_convbuf(Sj4Ime* ime) {
|
||||
return ime->convbuf;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue