Crash bug due to IM fixed, variable name change.
This commit is contained in:
parent
5ad64e56cd
commit
c735e6a6b8
3 changed files with 42 additions and 41 deletions
69
src/im.c
69
src/im.c
|
|
@ -722,7 +722,7 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
|
||||||
case IM_REQ_RESET_SOFT: /* Soft reset */
|
case IM_REQ_RESET_SOFT: /* Soft reset */
|
||||||
im->s[0] = L'\0';
|
im->s[0] = L'\0';
|
||||||
im->buf[0] = L'\0';
|
im->buf[0] = L'\0';
|
||||||
im->discard = 0;
|
im->redraw = 0;
|
||||||
cm.match_count = 0;
|
cm.match_count = 0;
|
||||||
cm.match_is_final = 0;
|
cm.match_is_final = 0;
|
||||||
cm.match_state = &cm.sections[cm.section];
|
cm.match_state = &cm.sections[cm.section];
|
||||||
|
|
@ -748,9 +748,9 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
|
||||||
if(im->request != IM_REQ_TRANSLATE) return 0;
|
if(im->request != IM_REQ_TRANSLATE) return 0;
|
||||||
|
|
||||||
|
|
||||||
/* Discard characters, per instructions */
|
/* Discard redraw characters, so they can be redrawn */
|
||||||
if((int)wcslen(im->s) < im->discard) im->discard = wcslen(im->s);
|
if((int)wcslen(im->s) < im->redraw) im->redraw = wcslen(im->s);
|
||||||
wcs_lshift(im->s, (wcslen(im->s) - im->discard) );
|
wcs_lshift(im->s, (wcslen(im->s) - im->redraw) );
|
||||||
|
|
||||||
|
|
||||||
/* Handle keys */
|
/* Handle keys */
|
||||||
|
|
@ -778,14 +778,14 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Enter finalizes previous discard */
|
/* Enter finalizes previous redraw */
|
||||||
case SDLK_RETURN:
|
case SDLK_RETURN:
|
||||||
if(im->discard <= 0) {
|
if(im->redraw <= 0) {
|
||||||
im->s[0] = L'\r';
|
im->s[0] = L'\r';
|
||||||
im->s[1] = L'\0';
|
im->s[1] = L'\0';
|
||||||
}
|
}
|
||||||
im->buf[0] = L'\0';
|
im->buf[0] = L'\0';
|
||||||
im->discard = 0;
|
im->redraw = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Actual character processing */
|
/* Actual character processing */
|
||||||
|
|
@ -804,7 +804,7 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
|
||||||
wcsncat(im->buf, &u, 1); /* Copy new character */
|
wcsncat(im->buf, &u, 1); /* Copy new character */
|
||||||
|
|
||||||
/* Translate the characters */
|
/* Translate the characters */
|
||||||
im->discard = 0;
|
im->redraw = 0;
|
||||||
while(1) {
|
while(1) {
|
||||||
const wchar_t* us = charmap_search(&cm, im->buf);
|
const wchar_t* us = charmap_search(&cm, im->buf);
|
||||||
#ifdef IM_DEBUG
|
#ifdef IM_DEBUG
|
||||||
|
|
@ -827,7 +827,7 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
|
||||||
}
|
}
|
||||||
/* May need to be overwritten next time */
|
/* May need to be overwritten next time */
|
||||||
else {
|
else {
|
||||||
im->discard += wcslen(us);
|
im->redraw += wcslen(us);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -858,7 +858,7 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
|
||||||
#endif
|
#endif
|
||||||
wcscat(im->s, im->buf);
|
wcscat(im->s, im->buf);
|
||||||
cm.match_is_final = 0;
|
cm.match_is_final = 0;
|
||||||
im->discard += wcslen(im->buf);
|
im->redraw += wcslen(im->buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -876,7 +876,7 @@ static int im_event_ja(IM_DATA* im, SDL_keysym ks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return im->discard;
|
return im->redraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -933,7 +933,7 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
case IM_REQ_RESET_SOFT: /* Soft reset */
|
case IM_REQ_RESET_SOFT: /* Soft reset */
|
||||||
im->s[0] = L'\0';
|
im->s[0] = L'\0';
|
||||||
im->buf[0] = L'\0';
|
im->buf[0] = L'\0';
|
||||||
im->discard = 0;
|
im->redraw = 0;
|
||||||
cm.match_count = 0;
|
cm.match_count = 0;
|
||||||
cm.match_is_final = 0;
|
cm.match_is_final = 0;
|
||||||
cm.match_state = &cm.sections[cm.section];
|
cm.match_state = &cm.sections[cm.section];
|
||||||
|
|
@ -959,9 +959,9 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
if(im->request != IM_REQ_TRANSLATE) return 0;
|
if(im->request != IM_REQ_TRANSLATE) return 0;
|
||||||
|
|
||||||
|
|
||||||
/* Discard characters, per instructions */
|
/* Discard redraw characters, so they can be redrawn */
|
||||||
if((int)wcslen(im->s) < im->discard) im->discard = wcslen(im->s);
|
if((int)wcslen(im->s) < im->redraw) im->redraw = wcslen(im->s);
|
||||||
wcs_lshift(im->s, (wcslen(im->s) - im->discard) );
|
wcs_lshift(im->s, (wcslen(im->s) - im->redraw) );
|
||||||
|
|
||||||
|
|
||||||
/* Handle keys */
|
/* Handle keys */
|
||||||
|
|
@ -992,7 +992,7 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
/* Delete one buffered character */
|
/* Delete one buffered character */
|
||||||
if(wcslen(im->buf) > 0) {
|
if(wcslen(im->buf) > 0) {
|
||||||
wcs_pull(im->buf, 1);
|
wcs_pull(im->buf, 1);
|
||||||
if(im->discard > 0) im->discard--;
|
if(im->redraw > 0) im->redraw--;
|
||||||
ks.unicode = L'\0';
|
ks.unicode = L'\0';
|
||||||
}
|
}
|
||||||
/* continue processing: */
|
/* continue processing: */
|
||||||
|
|
@ -1014,7 +1014,7 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
wcsncat(bp, &u, 1); /* Copy new character */
|
wcsncat(bp, &u, 1); /* Copy new character */
|
||||||
|
|
||||||
/* Translate the characters */
|
/* Translate the characters */
|
||||||
im->discard = 0;
|
im->redraw = 0;
|
||||||
while(1) {
|
while(1) {
|
||||||
const wchar_t* us = charmap_search(&cm, bp);
|
const wchar_t* us = charmap_search(&cm, bp);
|
||||||
#ifdef IM_DEBUG
|
#ifdef IM_DEBUG
|
||||||
|
|
@ -1036,7 +1036,7 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wcscat(im->s, us); /* Output */
|
wcscat(im->s, us); /* Output */
|
||||||
im->discard += wcslen(us); /* May need to re-eval next time */
|
im->redraw += wcslen(us); /* May need to re-eval next time */
|
||||||
bp += cm.match_count; /* Keep buffer data for re-eval*/
|
bp += cm.match_count; /* Keep buffer data for re-eval*/
|
||||||
cm.match_count = 0;
|
cm.match_count = 0;
|
||||||
cm.match_is_final = 0;
|
cm.match_is_final = 0;
|
||||||
|
|
@ -1084,7 +1084,7 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wcscat(im->s, us);
|
wcscat(im->s, us);
|
||||||
im->discard += wcslen(us);
|
im->redraw += wcslen(us);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1115,7 +1115,7 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
#endif
|
#endif
|
||||||
wcscat(im->s, bp);
|
wcscat(im->s, bp);
|
||||||
cm.match_is_final = 0;
|
cm.match_is_final = 0;
|
||||||
im->discard += wcslen(bp);
|
im->redraw += wcslen(bp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1133,7 +1133,7 @@ static int im_event_ko(IM_DATA* im, SDL_keysym ks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return im->discard;
|
return im->redraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1191,12 +1191,17 @@ void im_init(IM_DATA* im, int lang)
|
||||||
/* Setup static globals */
|
/* Setup static globals */
|
||||||
if(!im_initialized) {
|
if(!im_initialized) {
|
||||||
/* ADD NEW LANGUAGE SUPPORT HERE */
|
/* ADD NEW LANGUAGE SUPPORT HERE */
|
||||||
im_event_fns[LANG_JA] = im_event_ja;
|
im_event_fns[LANG_JA] = &im_event_ja;
|
||||||
im_event_fns[LANG_KO] = im_event_ko;
|
im_event_fns[LANG_KO] = &im_event_ko;
|
||||||
|
|
||||||
im_initialized = 1;
|
im_initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
assert(0 <= im->lang && im->lang < NUM_LANGS);
|
||||||
|
if(im_event_fp) printf("Initializing IM for %s...\n", lang_prefixes[im->lang]);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize the individual IM */
|
/* Initialize the individual IM */
|
||||||
im_request(im, IM_REQ_INIT);
|
im_request(im, IM_REQ_INIT);
|
||||||
}
|
}
|
||||||
|
|
@ -1247,8 +1252,8 @@ void im_free(IM_DATA* im)
|
||||||
*/
|
*/
|
||||||
int im_read(IM_DATA* im, SDL_keysym ks)
|
int im_read(IM_DATA* im, SDL_keysym ks)
|
||||||
{
|
{
|
||||||
IM_EVENT_FN* im_event_fp = NULL;
|
IM_EVENT_FN im_event_fp = NULL;
|
||||||
int discard = 0;
|
int redraw = 0;
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if(im->lang < 0 || im->lang >= NUM_LANGS) {
|
if(im->lang < 0 || im->lang >= NUM_LANGS) {
|
||||||
|
|
@ -1257,21 +1262,17 @@ int im_read(IM_DATA* im, SDL_keysym ks)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function pointer to the language-specific im_event_* function */
|
/* Function pointer to the language-specific im_event_* function */
|
||||||
im_event_fp = &im_event_fns[im->lang];
|
im_event_fp = im_event_fns[im->lang];
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
if(im_event_fp) printf("Loading IM for %s...\n", lang_prefixes[im->lang]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Run the language-specific IM or run the default C IM */
|
/* Run the language-specific IM or run the default C IM */
|
||||||
if(im_event_fp) discard = (*im_event_fp)(im, ks);
|
if(im_event_fp) redraw = (*im_event_fp)(im, ks);
|
||||||
else discard = im_event_c(im, ks);
|
else redraw = im_event_c(im, ks);
|
||||||
|
|
||||||
#ifdef IM_DEBUG
|
#ifdef IM_DEBUG
|
||||||
wprintf(L"* [%8ls] [%8ls] %2d %2d (%2d)\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf), im->discard);
|
wprintf(L"* [%8ls] [%8ls] %2d %2d (%2d)\n", im->s, im->buf, wcslen(im->s), wcslen(im->buf), im->redraw);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return discard;
|
return redraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
2
src/im.h
2
src/im.h
|
|
@ -40,7 +40,7 @@ typedef struct IM_DATA {
|
||||||
|
|
||||||
/* For use by language-specific im_event_<lang> calls. PRIVATE! */
|
/* For use by language-specific im_event_<lang> calls. PRIVATE! */
|
||||||
wchar_t buf[8]; /* Buffered characters */
|
wchar_t buf[8]; /* Buffered characters */
|
||||||
int discard; /* Discard parameter */
|
int redraw; /* Redraw this many characters next time */
|
||||||
int request; /* Event request */
|
int request; /* Event request */
|
||||||
} IM_DATA;
|
} IM_DATA;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1823,7 +1823,7 @@ static void mainloop(void)
|
||||||
|
|
||||||
if (cur_tool == TOOL_TEXT && cursor_x != -1 && cursor_y != -1)
|
if (cur_tool == TOOL_TEXT && cursor_x != -1 && cursor_y != -1)
|
||||||
{
|
{
|
||||||
static int discard = 0;
|
static int redraw = 0;
|
||||||
wchar_t* im_cp = im_data.s;
|
wchar_t* im_cp = im_data.s;
|
||||||
|
|
||||||
key_down = key;
|
key_down = key;
|
||||||
|
|
@ -1853,13 +1853,13 @@ static void mainloop(void)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Discard previous # of instructed characters */
|
/* Discard previous # of redraw characters */
|
||||||
if((int)texttool_len <= discard) texttool_len = 0;
|
if((int)texttool_len <= redraw) texttool_len = 0;
|
||||||
else texttool_len -= discard;
|
else texttool_len -= redraw;
|
||||||
texttool_str[texttool_len] = L'\0';
|
texttool_str[texttool_len] = L'\0';
|
||||||
|
|
||||||
/* Read IM, remember how many to discard next iteration */
|
/* Read IM, remember how many to redraw next iteration */
|
||||||
discard = im_read(&im_data, event.key.keysym);
|
redraw = im_read(&im_data, event.key.keysym);
|
||||||
|
|
||||||
/* Queue each character to be displayed */
|
/* Queue each character to be displayed */
|
||||||
while(*im_cp) {
|
while(*im_cp) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue