[uim-commit] r810 - trunk/fep
yamamoto at freedesktop.org
yamamoto at freedesktop.org
Thu Mar 24 06:25:37 PST 2005
Author: yamamoto
Date: 2005-03-24 06:25:15 -0800 (Thu, 24 Mar 2005)
New Revision: 810
Modified:
trunk/fep/callbacks.c
trunk/fep/escseq.c
trunk/fep/str.c
trunk/fep/uim-fep.c
trunk/fep/uim-fep.h
Log:
fix some bugs
Modified: trunk/fep/callbacks.c
===================================================================
--- trunk/fep/callbacks.c 2005-03-23 12:01:07 UTC (rev 809)
+++ trunk/fep/callbacks.c 2005-03-24 14:25:15 UTC (rev 810)
@@ -566,7 +566,10 @@
/* ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Ï¤Ê¤· */
index_width = UNDEFINED;
- cand_width = s_max_width - strlen(" ");
+ if (cand_width > s_max_width) {
+ cand_width = s_max_width;
+ }
+ cand_width -= strlen(" ");
cand_width = strhead(cand_str, cand_width);
if (cand_width <= cand_label_width + strlen(":")) {
cand_width = 1;
Modified: trunk/fep/escseq.c
===================================================================
--- trunk/fep/escseq.c 2005-03-23 12:01:07 UTC (rev 809)
+++ trunk/fep/escseq.c 2005-03-24 14:25:15 UTC (rev 810)
@@ -266,7 +266,7 @@
return NULL;
}
n2 = n += 2;
- while (isdigit(n2[0])) {
+ while (isdigit((unsigned char)n2[0])) {
n2++;
}
if (n2[0] == 'm') {
@@ -296,7 +296,7 @@
return;
}
n2 = n += 2;
- while (isdigit(n2[0])) {
+ while (isdigit((unsigned char)n2[0])) {
n2++;
}
if (n2[0] == ';') {
@@ -307,7 +307,7 @@
return;
}
n = ++n2;
- while (isdigit(n2[0])) {
+ while (isdigit((unsigned char)n2[0])) {
n2++;
}
if (n2[0] == 'm') {
@@ -487,96 +487,67 @@
*/
struct point_tag get_cursor_position(void)
{
- char ibuf[100];
- char *ibuf_offset;
- ssize_t len;
- char *escseq = NULL;
- int loop_count = 0;
- char *unget_buf = NULL;
- char *unget_buf2 = NULL;
- int buf_size = 0;
- int offset = 0;
+ char ibuf[BUFSIZ];
+ ssize_t len = 0;
+ char *escseq = ibuf - 1;
+ int loop_count;
+
+ assert(!s_no_report_cursor);
+
if (s_cursor.row != UNDEFINED) {
return s_cursor;
}
+
write(g_win_out, "\033[6n", strlen("\033[6n"));
- do {
- /* 10²ó¥ë¡¼¥×¤·¤Æ¤â¤À¤á¤À¤Ã¤¿¤é½ªÎ» */
- if (loop_count++ >= 10) {
- break;
+ for (loop_count = 0; loop_count < 10; loop_count++) {
+ char *next_escseq;
+ len += read_stdin(ibuf + len, sizeof(ibuf) - len);
+ ibuf[len] = '\0';
+
+ debug2(("get = \""));
+ debug_write2(ibuf, len);
+ debug2(("\"\n"));
+
+ if (escseq != ibuf - 1) {
+ escseq--;
}
- ibuf_offset = ibuf + offset;
- len = read_stdin(ibuf_offset, sizeof(ibuf) - offset);
- if (len <= 0) {
- continue;
- }
- ibuf_offset[len] = '\0';
- debug2(("get = %s\n", ibuf));
- escseq = strstr(ibuf, "\033");
- if (escseq != NULL) {
+ while ((next_escseq = memchr(escseq + 1, ESCAPE_CODE, len - (escseq - ibuf) - 1)) != NULL) {
int n;
- unget_buf2 = malloc(offset + len);
- /* unget_buf2[0] == 'R' */
- n = sscanf(escseq, "\033[%d;%d%s", &(s_cursor.row), &(s_cursor.col), unget_buf2);
- if (n < 3) {
- /* ESC¤Ï¤¢¤ë¤¬, ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤È¤·¤Æ¤ÏÉÔ½½Ê¬ */
- offset += len;
- s_cursor.row = s_cursor.col = UNDEFINED;
- } else {
- char *R = strchr(escseq, 'R');
- /* R¤Ïɬ¤º¤¢¤ë */
- assert(R != NULL);
- /* R¤Î¼¡¤Ëʸ»ú¤¬¤¢¤ë¤« */
- if (R[1] != '\0') {
- strcpy(unget_buf2, R + 1);
- } else {
- free(unget_buf2);
- unget_buf2 = NULL;
+ char R;
+ escseq = next_escseq;
+ n = sscanf(escseq, "\033[%d;%d%c", &(s_cursor.row), &(s_cursor.col), &R);
+ if (n == 3 && R == 'R') {
+ char *next_to_R = strchr(escseq, 'R') + 1;
+ /* ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤ÎÁ°¤Ëʸ»úÎ󤬤¢¤ë¤« */
+ if (escseq > ibuf) {
+ unget_stdin(ibuf, escseq - ibuf);
}
- }
- } else {
- offset += len;
- }
- } while (s_cursor.row == UNDEFINED);
- /* ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤ÎÁ°¤Ëʸ»úÎ󤬤¢¤ë¤« */
- if (escseq > ibuf) {
- unget_buf = malloc(escseq - ibuf);
- memcpy(unget_buf, ibuf, escseq - ibuf);
- buf_size += (escseq - ibuf);
- }
+ /* ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤Î¸å¤Îʸ»úÎó */
+ unget_stdin(next_to_R, len - (next_to_R - ibuf));
- /* ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤Î¸å¤Ëʸ»úÎ󤬤¢¤ë¤« */
- if (unget_buf2 != NULL) {
- int buf_size2 = strlen(unget_buf2);
- unget_buf = realloc(unget_buf, buf_size + buf_size2);
- memcpy(unget_buf + buf_size, unget_buf2, buf_size2);
- buf_size += buf_size2;
- free(unget_buf2);
- }
+ s_cursor.row--;
+ s_cursor.col--;
+ s_cursor.row -= s_cursor_diff.row;
+ s_cursor.col -= s_cursor_diff.col;
- if (buf_size > 0) {
- unget_stdin(unget_buf, buf_size);
- free(unget_buf);
- }
+ /* GNU screen ¤Ç¤Ï¤³¤¦¤Ê¤ë¤³¤È¤¬¤¢¤ë */
+ if (s_cursor.col > g_win->ws_col - 1) {
+ put_crlf();
+ }
+ debug(("<get row = %d col = %d>", s_cursor.row, s_cursor.col));
+ return s_cursor;
- if (s_cursor.row == UNDEFINED) {
- /* ¼ºÇÔ */
- /* s_cursor.row = s_cursor.col = 0; */
- return s_cursor;
+ } else {
+ /* ESC¤Ï¤¢¤ë¤¬, ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤È¤·¤Æ¤ÏÉÔ½½Ê¬ */
+ s_cursor.row = s_cursor.col = UNDEFINED;
+ }
+ }
}
- s_cursor.row--;
- s_cursor.col--;
- s_cursor.row -= s_cursor_diff.row;
- s_cursor.col -= s_cursor_diff.col;
-
- /* GNU screen ¤Ç¤Ï¤³¤¦¤Ê¤ë¤³¤È¤¬¤¢¤ë */
- if (s_cursor.col > g_win->ws_col - 1) {
- put_crlf();
- }
- debug(("<get row = %d col = %d>", s_cursor.row, s_cursor.col));
+ unget_stdin(ibuf, len);
+ /* ¼ºÇÔ */
return s_cursor;
}
@@ -766,10 +737,10 @@
params[0] = 0;
str++;
- while (isdigit(str[0]) || str[0] == ';') {
- if (isdigit(str[0])) {
+ while (isdigit((unsigned char)str[0]) || str[0] == ';') {
+ if (isdigit((unsigned char)str[0])) {
int n = 0;
- while (isdigit(str[0])) {
+ while (isdigit((unsigned char)str[0])) {
n = n * 10 + str[0] - '0';
str++;
}
@@ -1080,7 +1051,7 @@
for (i = 0, j = 0; escseq[i] != '\0';) {
if (escseq[i] == '$' && escseq[i + 1] == '<') {
int i2 = i + 1;
- while (isdigit(escseq[++i2]));
+ while (isdigit((unsigned char)escseq[++i2]));
if (escseq[i2] == '>') {
i = i2 + 1;
if (escseq[i] == '\0') {
Modified: trunk/fep/str.c
===================================================================
--- trunk/fep/str.c 2005-03-23 12:01:07 UTC (rev 809)
+++ trunk/fep/str.c 2005-03-24 14:25:15 UTC (rev 810)
@@ -174,7 +174,7 @@
{
int width = 0;
for (; *str != '\0'; str++) {
- if (isascii(*str)) {
+ if (isascii((unsigned char)*str)) {
width++;
} else {
if (s_utf8) {
@@ -265,7 +265,7 @@
}
for (; *str != '\0'; str++) {
- if (isascii(*str)) {
+ if (isascii((unsigned char)*str)) {
char_width = 1;
char_byte = 1;
} else {
@@ -369,7 +369,7 @@
}
for (; *str != '\0'; str++) {
- if (isascii(*str)) {
+ if (isascii((unsigned char)*str)) {
char_width = 1;
char_byte = 1;
} else {
@@ -461,7 +461,7 @@
static int rval[2];
for (; *str != '\0'; str++) {
- if (isascii(*str)) {
+ if (isascii((unsigned char)*str)) {
char_width = 1;
char_byte = 1;
} else {
@@ -559,7 +559,7 @@
static int rval[2];
for (; *str != '\0'; str++) {
- if (isascii(*str)) {
+ if (isascii((unsigned char)*str)) {
char_width = 1;
char_byte = 1;
} else {
Modified: trunk/fep/uim-fep.c
===================================================================
--- trunk/fep/uim-fep.c 2005-03-23 12:01:07 UTC (rev 809)
+++ trunk/fep/uim-fep.c 2005-03-24 14:25:15 UTC (rev 810)
@@ -646,11 +646,11 @@
close(s_setmode_fd);
s_setmode_fd = open(s_path_setmode, O_RDONLY | O_NONBLOCK);
}
- for (end = len - 1; end >= 0 && !isdigit(buf[end]); --end);
+ for (end = len - 1; end >= 0 && !isdigit((unsigned char)buf[end]); --end);
/* ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤òÊÔ½¸Ãæ¤Ç¤Ê¤±¤ì¤Ð¥â¡¼¥É¤òÊѹ¹¤¹¤ë */
if (end >= 0 && !g_start_preedit) {
int mode;
- for (start = end; start > 0 && isdigit(buf[start - 1]); --start);
+ for (start = end; start > 0 && isdigit((unsigned char)buf[start - 1]); --start);
buf[end + 1] = '\0';
mode = atoi(&buf[start]);
if (mode != uim_get_current_mode(s_context)) {
@@ -693,8 +693,10 @@
if (key == UKey_Escape) {
if (i + 1 < len) {
/* Alt+¥¡¼ */
- key_state = UMod_Alt;
- continue;
+ if (key_state != UMod_Alt) {
+ key_state = UMod_Alt;
+ continue;
+ }
} else if (s_timeout > 0) {
struct timeval t;
FD_ZERO(&fds);
@@ -1004,16 +1006,25 @@
}
#if defined(DEBUG) && DEBUG > 1
+static FILE *_log = NULL;
void _debug(const char *fmt, ...)
{
- static FILE *log = NULL;
va_list ap;
- if (log == NULL) {
- log = fopen("uim-fep-log", "w");
+ if (_log == NULL) {
+ _log = fopen("uim-fep-log", "w");
}
va_start(ap, fmt);
- vfprintf(log, fmt, ap);
+ vfprintf(_log, fmt, ap);
va_end(ap);
- fflush(log);
+ fflush(_log);
}
+
+void _debug_write(const char *str, int len)
+{
+ if (_log == NULL) {
+ _log = fopen("uim-fep-log", "w");
+ }
+ fwrite(str, 1, len, _log);
+ fflush(_log);
+}
#endif
Modified: trunk/fep/uim-fep.h
===================================================================
--- trunk/fep/uim-fep.h 2005-03-23 12:01:07 UTC (rev 809)
+++ trunk/fep/uim-fep.h 2005-03-24 14:25:15 UTC (rev 810)
@@ -62,16 +62,22 @@
#if DEBUG > 2
#define debug2(arg) _debug arg
#define debug(arg) _debug arg
+#define debug_write2(str, len) _debug_write(str, len)
+#define debug_write(str, len) _debug_write(str, len)
void _debug(const char *fmt, ...);
#elif DEBUG == 2
#define debug2(arg)
#define debug(arg) _debug arg
+#define debug_write2(str, len)
+#define debug_write(str, len) _debug_write(str, len)
void _debug(const char *fmt, ...);
#else
#define debug2(arg)
#define debug(arg)
+#define debug_write2(str, len)
+#define debug_write(str, len)
#endif
#define return_if_fail(arg) if (!(arg)) { printf("assertion failed %s %d", __FILE__, __LINE__); return; }
@@ -79,6 +85,8 @@
#else
#define debug2(arg)
#define debug(arg)
+#define debug_write2(str, len)
+#define debug_write(str, len)
#define return_if_fail(arg) if (!(arg)) { return; }
#endif
More information about the Uim-commit
mailing list