Add sj4_ime_convbuf

This commit is contained in:
Nishi 2026-07-02 09:41:03 +09:00
commit 28af75999a
3 changed files with 50 additions and 8 deletions

View file

@ -5,6 +5,10 @@
#include <wchar.h> #include <wchar.h>
#ifdef __cplusplus
extern "C" {
#endif
enum SJ4CHARSET { enum SJ4CHARSET {
SJ4EUCJP = 0, SJ4EUCJP = 0,
SJ4SJIS, 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_to(int type, void* output, const void* input, int len);
int sj4_charset_from(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 #endif

View file

@ -11,6 +11,7 @@ typedef struct sj4ime Sj4Ime;
Sj4Ime* sj4_ime(int charset, const char* dict); Sj4Ime* sj4_ime(int charset, const char* dict);
void sj4_ime_key(Sj4Ime* ime, int key); void sj4_ime_key(Sj4Ime* ime, int key);
void* sj4_ime_convbuf(Sj4Ime* ime);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -18,6 +18,7 @@ struct sj4ime {
u_char romabuf[SJ4BUFSZ]; u_char romabuf[SJ4BUFSZ];
u_char kanabuf[SJ4BUFSZ]; u_char kanabuf[SJ4BUFSZ];
u_char convbuf[SJ4BUFSZ];
}; };
static struct sj4table { static struct sj4table {
@ -78,22 +79,52 @@ static void concat(int charset, u_char* out, u_char* in) {
#endif #endif
} }
static void comp(Sj4Ime* ime) { static void concat_nc(int charset, u_char* out, u_char* in) {
ime->kanabuf[0] = 0; int i, j;
ime->last = 0;
#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)) #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) { void sj4_ime_key(Sj4Ime* ime, int key) {
if(key == '\n') { if(key == '\n') {
comp(ime); comp(ime);
ZEROBUF;
} else if(key == ' ') { } else if(key == ' ') {
reconvert: reconvert:
if((ime->last = b_len(ime->charset, &ime->kouho.buffer)) == 0) { if(b_len(ime->charset, &ime->kouho.buffer) == 0) {
sj4_getkan(ime->lib, ime->kanabuf, strlen(ime->kanabuf), &ime->kouho); ime->last = sj4_getkan(ime->lib, ime->kanabuf, strlen(ime->kanabuf), &ime->kouho);
} else { } else {
if((ime->last = sj4_nextkan(ime->lib)) == 0) { if((ime->last = sj4_nextkan(ime->lib)) == 0) {
ZEROBUF; ZEROBUF;
@ -101,8 +132,6 @@ void sj4_ime_key(Sj4Ime* ime, int key) {
goto reconvert; goto reconvert;
} }
} }
printf("%s\n", ime->kouho.buffer.utf8);
} else if('a' <= tolower(key) && tolower(key) <= 'z') { } else if('a' <= tolower(key) && tolower(key) <= 'z') {
int i; int i;
@ -145,3 +174,7 @@ void sj4_ime_key(Sj4Ime* ime, int key) {
} }
} }
} }
void* sj4_ime_convbuf(Sj4Ime* ime) {
return ime->convbuf;
}