[uim-commit] r1432 - trunk/fep
yamamoto at freedesktop.org
yamamoto at freedesktop.org
Mon Sep 5 10:57:34 PDT 2005
Author: yamamoto
Date: 2005-09-05 10:57:31 -0700 (Mon, 05 Sep 2005)
New Revision: 1432
Modified:
trunk/fep/callbacks.c
trunk/fep/callbacks.h
trunk/fep/draw.c
trunk/fep/draw.h
trunk/fep/escseq.h
trunk/fep/helper.c
trunk/fep/helper.h
trunk/fep/key.h
trunk/fep/read.c
trunk/fep/read.h
trunk/fep/str.h
trunk/fep/udsock.h
trunk/fep/uim-fep-tick.c
trunk/fep/uim-fep.c
trunk/fep/uim-fep.h
Log:
* fep/uim-fep.c
- (reset_signal_handler): New function to reset signal settings.
- (main_loop, signal_handler): Handle signals safely.
* fep/read.c
- (my_pselect): New function.
* fep/callbacks.c
- (set_candidate): Renamed from get_candidate.
- (get_mode_str): Return current IM name and current mode name.
- (prop_list_update_cb): Moved from helper.c.
Parse helper message to get labels.
- (prop_label_update_cb): Moved from helper.c.
* fep/helper.c
- (helper_handler): Convert encoding of commit_string from specified
charset.
Modified: trunk/fep/callbacks.c
===================================================================
--- trunk/fep/callbacks.c 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/callbacks.c 2005-09-05 17:57:31 UTC (rev 1432)
@@ -52,6 +52,9 @@
#include "uim-fep.h"
#include "str.h"
#include "callbacks.h"
+#include "helper.h"
+#include <uim/uim-im-switcher.h>
+#include <uim/uim-helper.h>
/* ¥¹¥Æ¡¼¥¿¥¹¥é¥¤¥ó¤ÎºÇÂçÉý */
static int s_max_width;
@@ -62,6 +65,7 @@
static char *s_index_str;
static struct preedit_tag *s_preedit;
static int s_mode;
+static char *s_label_str;
static char *s_nokori_str;
static int s_start_callbacks = FALSE;
@@ -73,12 +77,14 @@
static void pushback_cb(void *ptr, int attr, const char *str);
static void update_cb(void *ptr);
static void mode_update_cb(void *ptr, int mode);
+static void prop_list_update_cb(void *ptr, const char *str);
+static void prop_label_update_cb(void *ptr, const char *str);
static struct preedit_tag *dup_preedit(struct preedit_tag *p);
static void make_page_strs(void);
static int numwidth(int n);
static int index2page(int index);
static void reset_candidate(void);
-static void get_candidate(void);
+static void set_candidate(void);
struct candidate_tag {
/* ¸õÊä¤Î¿ô */
@@ -128,21 +134,22 @@
s_candidate_col = UNDEFINED;
s_index_str = strdup("");
s_mode = uim_get_current_mode(g_context);
+ s_label_str = strdup("");
s_preedit = create_preedit();
uim_set_preedit_cb(g_context, clear_cb, pushback_cb, update_cb);
uim_set_mode_cb(g_context, mode_update_cb);
+ uim_set_prop_list_update_cb(g_context, prop_list_update_cb);
+ uim_set_prop_label_update_cb(g_context, prop_label_update_cb);
if (g_opt.status_type != NONE) {
uim_set_candidate_selector_cb(g_context, activate_cb, select_cb, shift_page_cb, deactivate_cb);
}
if (g_opt.ddskk) {
- void *cd;
- const char *nokori_str = "»Ä¤ê";
const char *enc;
if (uim_iconv->is_convertible(enc = get_enc(), "EUC-JP")) {
- cd = uim_iconv->create(enc, "EUC-JP");
- s_nokori_str = uim_iconv->convert(cd, nokori_str);
+ void *cd = uim_iconv->create(enc, "EUC-JP");
+ s_nokori_str = uim_iconv->convert(cd, "»Ä¤ê");
if (cd) {
uim_iconv->release(cd);
}
@@ -170,6 +177,9 @@
}
+/*
+ * ̾Á°¤¬Ê¶¤é¤ï¤·¤¤¤¬¡¢uim¦¤«¤éÉÁ²è¤òÍ׵ᤵ¤ì¤¿¤é¸Æ¤Ö¡£
+ */
void start_callbacks(void)
{
if (s_start_callbacks) {
@@ -178,24 +188,6 @@
s_start_callbacks = TRUE;
debug2(("\n\nstart_callbacks()\n"));
- if (s_commit_str != NULL) {
- free(s_commit_str);
- }
- s_commit_str = strdup("");
- if (s_candidate_str != NULL) {
- free(s_candidate_str);
- s_candidate_str = NULL;
- }
- if (s_index_str != NULL) {
- free(s_index_str);
- s_index_str = NULL;
- }
- if (s_statusline_str != NULL) {
- free(s_statusline_str);
- s_statusline_str = NULL;
- }
- s_candidate_col = UNDEFINED;
- s_mode = uim_get_current_mode(g_context);
}
/*
@@ -214,10 +206,15 @@
if (s_preedit->cursor == UNDEFINED) {
s_preedit->cursor = s_preedit->width;
}
+
+ free(s_statusline_str);
+ free(s_candidate_str);
+ free(s_index_str);
+
if (s_candidate.nr != UNDEFINED) {
s_statusline_str = strdup(s_candidate.page_strs[s_candidate.page]);
if (s_candidate.index != UNDEFINED) {
- get_candidate();
+ set_candidate();
} else {
s_candidate_str = strdup("");
s_candidate_col = UNDEFINED;
@@ -239,7 +236,13 @@
*/
char *get_commit_str(void)
{
- return strdup(s_commit_str);
+ char *return_value = strdup(s_commit_str);
+
+ assert(!s_start_callbacks);
+
+ free(s_commit_str);
+ s_commit_str = strdup("");
+ return return_value;
}
/*
@@ -248,6 +251,7 @@
*/
char *get_statusline_str(void)
{
+ assert(!s_start_callbacks);
return strdup(s_statusline_str);
}
@@ -257,6 +261,7 @@
*/
char *get_candidate_str(void)
{
+ assert(!s_start_callbacks);
return strdup(s_candidate_str);
}
@@ -266,6 +271,7 @@
*/
int get_candidate_col(void)
{
+ assert(!s_start_callbacks);
return s_candidate_col;
}
@@ -275,6 +281,7 @@
*/
char *get_index_str(void)
{
+ assert(!s_start_callbacks);
return strdup(s_index_str);
}
@@ -284,6 +291,8 @@
*/
int get_index_col(void)
{
+ assert(!s_start_callbacks);
+
if (s_candidate.index != UNDEFINED) {
return s_candidate.index_col[s_candidate.page];
}
@@ -296,6 +305,7 @@
*/
struct preedit_tag *get_preedit(void)
{
+ assert(!s_start_callbacks);
return dup_preedit(s_preedit);
}
@@ -304,6 +314,7 @@
*/
int get_mode(void)
{
+ assert(!s_start_callbacks);
return s_mode;
}
@@ -313,10 +324,17 @@
*/
char *get_mode_str(void)
{
- char *mode_str = (char *)uim_get_mode_name(g_context, s_mode);
- mode_str = strdup(mode_str != NULL ? mode_str : "");
- strhead(mode_str, s_max_width);
- return mode_str;
+ char *str;
+ char *im_str = (char *)uim_get_current_im_name(g_context);
+
+ assert(!s_start_callbacks);
+
+ im_str = im_str != NULL ? im_str : "";
+ str = malloc(strlen(im_str) + strlen(s_label_str) + strlen("[]") + 1);
+ sprintf(str, "%s[%s]", im_str, s_label_str);
+ strhead(str, s_max_width);
+
+ return str;
}
/*
@@ -347,6 +365,9 @@
debug2(("select_cb(index = %d)\n", index));
return_if_fail(s_candidate.nr != UNDEFINED);
return_if_fail(0 <= index && index < s_candidate.nr);
+ if (s_candidate.index == index) {
+ return;
+ }
start_callbacks();
s_candidate.index = index;
s_candidate.page = index2page(index);
@@ -391,6 +412,9 @@
{
debug2(("commit_cb(commit_str = \"%s\")\n", commit_str));
return_if_fail(commit_str != NULL);
+ if (strlen(commit_str) == 0) {
+ return;
+ }
start_callbacks();
s_commit_str = realloc(s_commit_str, strlen(s_commit_str) + strlen(commit_str) + 1);
strcat(s_commit_str, commit_str);
@@ -415,10 +439,18 @@
{
int width;
static int cursor = FALSE;
+
debug2(("pushback_cb(attr = %d str = \"%s\")\n", attr, str));
+
return_if_fail(str && s_preedit != NULL);
+
+ width = strwidth(str);
+
+ if (width == 0 && (attr & UPreeditAttr_Cursor) == 0) {
+ return;
+ }
+
start_callbacks();
- width = strwidth(str);
/* UPreeditAttr_Cursor¤Î¤È¤¤Ë¶õʸ»úÎó¤È¤Ï¸Â¤é¤Ê¤¤ */
if (attr & UPreeditAttr_Cursor) {
/* skk¤Î¼½ñÅÐÏ¿¤Ï¥«¡¼¥½¥ë¤¬2²Õ½ê¤¢¤ë */
@@ -476,10 +508,137 @@
static void mode_update_cb(void *ptr, int mode)
{
debug2(("mode_update_cb(mode = %d)\n", mode));
+
+ if (s_mode == mode) {
+ return;
+ }
+
start_callbacks();
s_mode = mode;
}
+static void prop_list_update_cb(void *ptr, const char *str)
+{
+ char *line;
+ int error = TRUE; /* str ¤¬ "" ¤Î¤È¤¤Ïerror¤Ë¤¹¤ë*/
+ char *labels = strdup("");
+ char *dup_str;
+
+ const char *enc;
+ char *message_buf;
+
+ debug(("prop_list_update_cb\n"));
+ debug2(("str = %s", str));
+
+ dup_str = line = strdup(str);
+
+ while (line[0] != '\0') {
+ int i;
+ char *tab;
+ char *eol;
+ char *label;
+ int label_width;
+ int max_label_width = 0;
+
+ error = TRUE;
+
+ /* branch = "branch\t" iconic_label "\t" buttontooltip_string "\n" */
+ if (!str_has_prefix(line, "branch\t")) {
+ break;
+ }
+ label = line + strlen("branch\t");
+
+ if ((tab = strchr(label, '\t')) == NULL) {
+ break;
+ }
+ *tab = '\0';
+
+ if ((eol = strchr(tab + 1, '\n')) == NULL) {
+ break;
+ }
+ line = eol + 1;
+
+ while (str_has_prefix(line, "leaf\t")) {
+ char *leaf_label = line + strlen("leaf\t");
+
+ tab = line + strlen("leaf");
+
+ /* leaf = "leaf\t" iconic_label "\t" menulabel_string "\t" menutooltip_string "\t" menucommand_name "\t" flag "\n" */
+ for (i = 0; i < 4; i++) {
+ if ((tab = strchr(tab + 1, '\t')) == NULL) {
+ goto loop_end;
+ }
+ *tab = '\0';
+ }
+ if ((eol = strchr(tab + 1, '\n')) == NULL) {
+ goto loop_end;
+ }
+ line = eol + 1;
+
+ error = FALSE;
+
+ label_width = strlen(leaf_label);
+ if (label_width > max_label_width) {
+ max_label_width = label_width;
+ }
+ }
+
+ label_width = strwidth(label);
+ labels = realloc(labels, strlen(labels) + strlen(label) + (max_label_width - label_width) + 1);
+ for (i = 0; i < (max_label_width - label_width); i++) {
+ strcat(labels, " ");
+ }
+ strcat(labels, label);
+ }
+
+loop_end:
+
+ free(dup_str);
+
+ if (error) {
+ free(labels);
+ } else {
+ if (strcmp(s_label_str, labels) != 0) {
+ start_callbacks();
+ free(s_label_str);
+ s_label_str = labels;
+ } else {
+ free(labels);
+ }
+ }
+
+ if (!g_focus_in) {
+ return;
+ }
+
+ enc = get_enc();
+ message_buf = malloc(strlen("prop_list_update\ncharset=") + strlen(enc) + strlen("\n") + strlen(str) + 1);
+ sprintf(message_buf, "prop_list_update\ncharset=%s\n%s", enc, str);
+ uim_helper_send_message(g_helper_fd, message_buf);
+ free(message_buf);
+ debug(("prop_list_update_cb send message\n"));
+}
+
+static void prop_label_update_cb(void *ptr, const char *str)
+{
+ const char *enc;
+ char *message_buf;
+
+ debug(("prop_label_update_cb\n"));
+ debug2(("str = %s", str));
+
+ if (!g_focus_in) {
+ return;
+ }
+
+ enc = get_enc();
+ message_buf = malloc(strlen("prop_label_update\ncharset=") + strlen(enc) + strlen("\n") + strlen(str) + 1);
+ sprintf(message_buf, "prop_label_update\ncharset=%s\n%s", enc, str);
+ uim_helper_send_message(g_helper_fd, message_buf);
+ free(message_buf);
+ debug(("prop_label_update_cb send message\n"));
+}
+
/*
* ¿·¤·¤¤¥×¥ê¥¨¥Ç¥£¥Ã¥È¤òºî¤ê¡¤¥Ý¥¤¥ó¥¿¤òÊÖ¤¹
*/
@@ -715,6 +874,7 @@
if (s_candidate.nr == UNDEFINED) {
return;
}
+
if (s_candidate.page_strs != NULL) {
int i;
for (i = 0; i < s_candidate.nr_pages; i++) {
@@ -745,7 +905,7 @@
/*
* s_candidate_col¤Ès_candidate_str¤Ès_index_str¤òÀßÄꤹ¤ë
*/
-static void get_candidate(void)
+static void set_candidate(void)
{
uim_candidate cand;
int cand_width;
@@ -799,42 +959,36 @@
void callbacks_winch(void)
{
+ start_callbacks();
+
s_max_width = g_win->ws_col;
if (g_opt.statusline_width != UNDEFINED && g_opt.statusline_width <= s_max_width) {
s_max_width = g_opt.statusline_width;
}
- if (s_candidate.nr != UNDEFINED) {
- if (s_candidate.page_strs != NULL) {
- int i;
- for (i = 0; i < s_candidate.nr_pages; i++) {
- free(s_candidate.page_strs[i]);
- }
- free(s_candidate.page_strs);
- s_candidate.page_strs = NULL;
+
+ if (s_candidate.nr == UNDEFINED) {
+ return;
+ }
+
+ /* ¸õÊä°ìÍ÷¤òɽ¼¨Ãæ */
+ if (s_candidate.page_strs != NULL) {
+ int i;
+ for (i = 0; i < s_candidate.nr_pages; i++) {
+ free(s_candidate.page_strs[i]);
}
- if (s_candidate.page2index != NULL) {
- free(s_candidate.page2index);
- s_candidate.page2index = NULL;
- }
- if (s_candidate.index_col != NULL) {
- free(s_candidate.index_col);
- s_candidate.index_col = NULL;
- }
- make_page_strs();
- if (s_statusline_str != NULL) {
- free(s_statusline_str);
- }
- if (s_candidate_str != NULL) {
- free(s_candidate_str);
- }
- s_statusline_str = strdup(s_candidate.page_strs[s_candidate.page]);
- if (s_candidate.index != UNDEFINED) {
- get_candidate();
- } else {
- s_candidate_str = strdup("");
- s_candidate_col = UNDEFINED;
- }
+ free(s_candidate.page_strs);
+ s_candidate.page_strs = NULL;
}
+ if (s_candidate.page2index != NULL) {
+ free(s_candidate.page2index);
+ s_candidate.page2index = NULL;
+ }
+ if (s_candidate.index_col != NULL) {
+ free(s_candidate.index_col);
+ s_candidate.index_col = NULL;
+ }
+
+ make_page_strs();
}
void callbacks_set_mode(int mode)
Modified: trunk/fep/callbacks.h
===================================================================
--- trunk/fep/callbacks.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/callbacks.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -34,8 +34,6 @@
#ifndef CALLBACKS_H
#define CALLBACKS_H
-#include <uim/uim.h>
-
struct preedit_tag {
/* ʸ»úÎó¤ÎÉý */
int width;
Modified: trunk/fep/draw.c
===================================================================
--- trunk/fep/draw.c 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/draw.c 2005-09-05 17:57:31 UTC (rev 1432)
@@ -151,8 +151,9 @@
/*
* ¥×¥ê¥¨¥Ç¥£¥Ã¥È¡¤¥¹¥Æ¡¼¥¿¥¹¥é¥¤¥ó¤òÉÁ²è¤¹¤ë
+ * ÉÁ¼Ì¤¹¤ëɬÍפ¬¤Ê¤¤¾ì¹ç¤ÏFALSE¤òÊÖ¤¹
*/
-void draw(void)
+int draw(void)
{
char *commit_str;
@@ -161,22 +162,26 @@
int i;
if (!end_callbacks()) {
- return;
+ return FALSE;
}
- /* üËö¥µ¥¤¥º¤¬Êѹ¹¤µ¤ì¤¿¤È¤¤Ïs_head¤òÊѹ¹¤¹¤ë */
+ prev_preedit = s_preedit;
+ s_preedit = get_preedit();
+ commit_str = get_commit_str();
+
+ /* üËö¥µ¥¤¥º¤¬Êѹ¹¤µ¤ì¤¿¤È¤¤Ïs_head¤òÊѹ¹¤·¡¢Á°¤Îpreedit¤¬¤Ê¤«¤Ã¤¿¤³¤È¤Ë¤¹¤ë */
if (s_winch && g_start_preedit) {
if (g_opt.no_report_cursor) {
s_preedit->cursor = 0;
} else {
s_head = get_cursor_position();
}
+ end_preedit();
+ free_preedit(prev_preedit);
+ prev_preedit = create_preedit();
}
+ s_winch = FALSE;
- prev_preedit = s_preedit;
- s_preedit = get_preedit();
- commit_str = get_commit_str();
-
debug2(("draw()\n"));
debug2(("commit_str = \"%s\"\n", commit_str));
debug2(("preedit->width = %d\n", s_preedit->width));
@@ -234,9 +239,9 @@
free_preedit(prev_preedit);
free(commit_str);
put_cursor_normal();
- s_winch = FALSE;
debug2(("\ndraw end\n"));
+ return TRUE;
}
/*
@@ -510,20 +515,57 @@
if (g_opt.status_type != NONE && statusline_str[0] == '\0') {
if (g_opt.status_type == LASTLINE) {
+ int mode_str_width = strwidth(mode_str);
+
+ statusline_str_width = mode_str_width;
+
if (restore) {
put_save_cursor();
}
put_cursor_invisible();
- put_goto_lastline(0);
- put_uim_str(mode_str, UPreeditAttr_None);
- statusline_str_width = strwidth(mode_str);
- if (draw_background) {
- put_clear_to_end_of_line(g_win->ws_col - statusline_str_width);
- } else if (statusline_str_width < prev_statusline_str_width) {
- put_clear_to_end_of_line(prev_statusline_str_width - statusline_str_width);
+
+ /* draw_background ¤Ê¤é¤Ð force ¤Ç¤¢¤ë */
+ /* ÏÀÍýŪ¤Ë¤Ï´Ø·¸¤Ê¤¤¤¬¤½¤Î¤è¤¦¤Ê»È¤ï¤ìÊý¤·¤«¤·¤Æ¤¤¤Ê¤¤ */
+ assert(!draw_background || force);
+
+ if (force) {
+ put_goto_lastline(0);
+ put_uim_str(mode_str, UPreeditAttr_None);
+
+ if (draw_background) {
+ put_clear_to_end_of_line(g_win->ws_col - statusline_str_width);
+ } else if (statusline_str_width < prev_statusline_str_width) {
+ put_clear_to_end_of_line(prev_statusline_str_width - statusline_str_width);
+ }
+
+ } else {
+ /* !force ¤Ê¤Î¤Ç prev_statusline_str_width ¤Ï¥â¡¼¥Éɽ¼¨¤ÎŤµ¤Ç¤¢¤ë */
+ int eq_width = compare_str(mode_str, prev_mode_str);
+ int eq_byte = width2byte(mode_str, eq_width)[0];
+ int prev_mode_str_width = strwidth(prev_mode_str);
+
+ put_goto_lastline(eq_width);
+ if (mode_str_width == prev_mode_str_width) {
+ int eq_width_rev = compare_str_rev(mode_str, prev_mode_str);
+
+ if (eq_width_rev > 0) {
+ int draw_byte = width2byte(mode_str + eq_byte, mode_str_width - eq_width - eq_width_rev)[0];
+ put_uim_str_len(mode_str + eq_byte, UPreeditAttr_None, draw_byte);
+
+ } else {
+ put_uim_str(mode_str + eq_byte, UPreeditAttr_None);
+ }
+
+ } else {
+ put_uim_str(mode_str + eq_byte, UPreeditAttr_None);
+ if (statusline_str_width < prev_statusline_str_width) {
+ put_clear_to_end_of_line(prev_statusline_str_width - statusline_str_width);
+ }
+ }
}
+
} else if (g_opt.status_type == BACKTICK) {
- strncpy(s_modebuf, mode_str, MODESIZE - 1);
+ strncpy(s_modebuf, mode_str, sizeof(s_modebuf) - 1);
}
}
}
@@ -608,7 +650,7 @@
int eq_width;
/* üËö¥µ¥¤¥º¤¬Êѹ¹¤µ¤ì¤¿¤È¤¤Ïprev_preedit¤Ï̵»ë¤¹¤ë */
- eq_width = s_winch ? 0 : compare_preedit(preedit, prev_preedit);
+ eq_width = compare_preedit(preedit, prev_preedit);
#if DEBUG > 2
debug2(("\neq_width = %d\n", eq_width));
@@ -1087,9 +1129,23 @@
/*
* üËö¥µ¥¤¥º¤¬Êѹ¹¤µ¤ì¤¿¤È¤¤Ë¸Æ¤Ö
*/
-void draw_winch(void)
+void draw_winch(struct winsize *prev_win)
{
s_winch = TRUE;
+ if (g_opt.status_type == LASTLINE) {
+ put_save_cursor();
+ put_cursor_invisible();
+ put_change_scroll_region(0, g_win->ws_row - 1);
+ if (g_win->ws_row > prev_win->ws_row) {
+ struct winsize save_win = *g_win;
+ *g_win = *prev_win;
+ clear_lastline();
+ *g_win = save_win;
+ }
+ draw_statusline_force_no_restore();
+ put_restore_cursor();
+ put_cursor_normal();
+ }
}
#if defined(DEBUG) && DEBUG > 2
Modified: trunk/fep/draw.h
===================================================================
--- trunk/fep/draw.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/draw.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -34,19 +34,21 @@
#ifndef DRAW_H
#define DRAW_H
-#include <uim/uim.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
-#define FORCE -1
-#define CLEAR -2
#define CANDSIZE 500
-#include "callbacks.h"
extern int g_start_preedit;
extern int g_commit;
void init_draw(int master, const char *path_getmode);
void update_backtick(void);
-void draw(void);
+int draw(void);
void draw_statusline_restore(void);
void draw_statusline_force_no_restore(void);
void draw_statusline_force_restore(void);
@@ -54,8 +56,6 @@
void clear_backtick(void);
int is_commit_and_preedit(void);
void draw_commit_and_preedit(void);
-void draw_winch(void);
+void draw_winch(struct winsize *prevwin);
-
#endif
-
Modified: trunk/fep/escseq.h
===================================================================
--- trunk/fep/escseq.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/escseq.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -48,7 +48,6 @@
int background;
};
-
void init_escseq(const struct attribute_tag *attr_uim);
void quit_escseq(void);
void fixtty(void);
@@ -77,4 +76,5 @@
void put_pty_str(const char *str, int len);
char *cut_padding(const char *escseq);
void escseq_winch(void);
+
#endif
Modified: trunk/fep/helper.c
===================================================================
--- trunk/fep/helper.c 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/helper.c 2005-09-05 17:57:31 UTC (rev 1432)
@@ -57,14 +57,10 @@
static void helper_disconnected_cb(void);
static void helper_handler_change_im(const char *str);
static void send_im_list(void);
-static void prop_list_update_cb(void *ptr, const char *str);
-static void prop_label_update_cb(void *ptr, const char *str);
void init_helper(void)
{
g_helper_fd = uim_helper_init_client_fd(helper_disconnected_cb);
- uim_set_prop_list_update_cb(g_context, prop_list_update_cb);
- uim_set_prop_label_update_cb(g_context, prop_label_update_cb);
}
void quit_helper(void)
@@ -80,7 +76,6 @@
g_helper_fd = -1;
}
-#define str_has_prefix(str, prefix) (strncmp((str), (prefix), strlen((prefix))) == 0)
void helper_handler(void)
{
char *message;
@@ -139,10 +134,29 @@
char *eol;
debug(("commit_string\n"));
if ((eol = strchr(message, '\n')) != NULL) {
- char *commit_string = eol + 1;
- if ((eol = strchr(commit_string, '\n')) != NULL) {
- *eol = '\0';
- commit_cb(NULL, commit_string);
+ char *charset = eol + 1;
+
+ if (str_has_prefix(charset, "charset=")) {
+ charset += strlen("charset=");
+ if ((eol = strchr(charset, '\n')) != NULL) {
+ char *commit_string = eol + 1;
+
+ *eol = '\0';
+ if ((eol = strchr(commit_string, '\n')) != NULL) {
+ const char *commit_enc;
+
+ *eol = '\0';
+ if (uim_iconv->is_convertible(commit_enc = get_enc(), charset)) {
+ void *cd = uim_iconv->create(commit_enc, charset);
+ commit_string = uim_iconv->convert(cd, commit_string);
+ commit_cb(NULL, commit_string);
+ free(commit_string);
+ if (cd) {
+ uim_iconv->release(cd);
+ }
+ }
+ }
+ }
}
}
@@ -202,51 +216,12 @@
message = realloc(message, strlen(message) + strlen(im_str) + 1);
strcat(message, im_str);
+ free(im_str);
}
uim_helper_send_message(g_helper_fd, message);
free(message);
}
-static void prop_list_update_cb(void *ptr, const char *str)
-{
- const char *enc;
- char *message_buf;
-
- debug(("prop_list_update_cb\n"));
- debug2(("str = %s", str));
-
- if (!g_focus_in) {
- return;
- }
-
- enc = get_enc();
- message_buf = malloc(strlen("prop_list_update\ncharset=") + strlen(enc) + strlen("\n") + strlen(str) + 1);
- sprintf(message_buf, "prop_list_update\ncharset=%s\n%s", enc, str);
- uim_helper_send_message(g_helper_fd, message_buf);
- free(message_buf);
- debug(("prop_list_update_cb send message\n"));
-}
-
-static void prop_label_update_cb(void *ptr, const char *str)
-{
- const char *enc;
- char *message_buf;
-
- debug(("prop_label_update_cb\n"));
- debug2(("str = %s", str));
-
- if (!g_focus_in) {
- return;
- }
-
- enc = get_enc();
- message_buf = malloc(strlen("prop_label_update\ncharset=") + strlen(enc) + strlen("\n") + strlen(str) + 1);
- sprintf(message_buf, "prop_label_update\ncharset=%s\n%s", enc, str);
- uim_helper_send_message(g_helper_fd, message_buf);
- free(message_buf);
- debug(("prop_label_update_cb send message\n"));
-}
-
void focus_in(void)
{
g_focus_in = TRUE;
Modified: trunk/fep/helper.h
===================================================================
--- trunk/fep/helper.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/helper.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -34,6 +34,8 @@
#ifndef HELPER_H
#define HELPER_H
+#define str_has_prefix(str, prefix) (strncmp((str), (prefix), strlen((prefix))) == 0)
+
extern int g_focus_in;
extern int g_helper_fd;
Modified: trunk/fep/key.h
===================================================================
--- trunk/fep/key.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/key.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -33,10 +33,10 @@
#ifndef KEY_H
#define KEY_H
+
int tty2key(char key);
int tty2key_state(char key);
int *escape_sequence2key(const char *str, int str_len);
void print_key(int key, int key_state);
#endif
-
Modified: trunk/fep/read.c
===================================================================
--- trunk/fep/read.c 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/read.c 2005-09-05 17:57:31 UTC (rev 1432)
@@ -37,9 +37,6 @@
#ifndef DEBUG
#define NDEBUG
#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -59,6 +56,12 @@
static char *s_unget_buf = NULL;
static int s_buf_size = 0;
+
+#ifndef HAVE_PSELECT
+static int pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+ const struct timespec *timeout, const sigset_t *sigmask);
+#endif
+
/*
* select
* unget¤¬¤¢¤ë¤È¤¤Ïselect¤ò¸Æ¤Ð¤Ê¤¤.
@@ -74,6 +77,20 @@
}
/*
+ * pselect
+ * unget¤¬¤¢¤ë¤È¤¤Ïpselect¤ò¸Æ¤Ð¤Ê¤¤.
+ */
+int my_pselect(int n, fd_set *readfds, const sigset_t *sigmask)
+{
+ if (s_buf_size > 0) {
+ FD_ZERO(readfds);
+ FD_SET(g_win_in, readfds);
+ return 1;
+ }
+ return pselect(n, readfds, NULL, NULL, NULL, sigmask);
+}
+
+/*
* stdin¤òread¤¹¤ë
* unget¤¬¤¢¤ë¤È¤¤Ï¤½¤ì¤òÊÖ¤¹
*/
@@ -108,3 +125,18 @@
memcpy(s_unget_buf + s_buf_size, str, count);
s_buf_size += count;
}
+
+#ifndef HAVE_PSELECT
+static int pselect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+ const struct timespec *timeout, const sigset_t *sigmask)
+{
+ int ret;
+ sigset_t orig_sigmask;
+
+ sigprocmask(SIG_SETMASK, sigmask, &orig_sigmask);
+ /* timeout ¤Ï»È¤ï¤Ê¤¤ */
+ ret = select(n, readfds, writefds, exceptfds, NULL);
+ sigprocmask(SIG_SETMASK, &orig_sigmask, NULL);
+ return ret;
+}
+#endif
Modified: trunk/fep/read.h
===================================================================
--- trunk/fep/read.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/read.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -33,16 +33,23 @@
#ifndef READ_H
#define READ_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+
int my_select(int n, fd_set *readfds, struct timeval *timeout);
+int my_pselect(int n, fd_set *readfds, const sigset_t *sigmask);
ssize_t read_stdin(void *buf, int count);
void unget_stdin(const char *str, int count);
-
#endif
-
Modified: trunk/fep/str.h
===================================================================
--- trunk/fep/str.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/str.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -33,6 +33,7 @@
#ifndef STR_H
#define STR_H
+
void init_str(void);
const char *get_enc(void);
int compare_str(char *str1, char *str2);
@@ -46,5 +47,5 @@
char *rstrstr_len(const char *haystack, const char *needle, int haystack_len);
char *strstr_len(const char *haystack, const char *needle, int haystack_len);
char *tab2space(const char *tabstr);
+
#endif
-
Modified: trunk/fep/udsock.h
===================================================================
--- trunk/fep/udsock.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/udsock.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -33,9 +33,11 @@
#ifndef UDSOCK_H
#define UDSOCK_H
+
#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 100
#endif
+
const char *usersockname(const char *file);
void init_sendsocket(const char *sock_path);
void sendline(const char *buf);
@@ -44,4 +46,3 @@
void close_socket(void);
#endif
-
Modified: trunk/fep/uim-fep-tick.c
===================================================================
--- trunk/fep/uim-fep-tick.c 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/uim-fep-tick.c 2005-09-05 17:57:31 UTC (rev 1432)
@@ -55,8 +55,8 @@
static void version(void);
int main(int argc, char **argv)
{
- char *buf = malloc(BUFSIZE + 1);
- char *prev_buf = malloc(BUFSIZE + 1);
+ char buf[BUFSIZE + 1];
+ char prev_buf[BUFSIZE + 1];
const char *sock_path = NULL;
int op;
Modified: trunk/fep/uim-fep.c
===================================================================
--- trunk/fep/uim-fep.c 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/uim-fep.c 2005-09-05 17:57:31 UTC (rev 1432)
@@ -59,6 +59,7 @@
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
+/* solaris¤Ç¤Ï term.h¤ÎÁ°¤Ëcurses.h¤¬É¬Í× */
#ifdef HAVE_CURSES_H
#include <curses.h>
#endif
@@ -147,7 +148,19 @@
static char s_path_setmode[MAXPATHLEN];
static char s_path_getmode[MAXPATHLEN];
static int s_setmode_fd = -1;
+#ifndef HAVE_SIG_ATOMIC_T
+typedef int sig_atomic_t;
+#endif
+static volatile sig_atomic_t s_signal_flag;
+static sigset_t s_orig_sigmask;
+#define SIG_FLAG_DONE 1
+#define SIG_FLAG_RECOVER (1 << 1)
+#define SIG_FLAG_WINCH (1 << 2)
+#define SIG_FLAG_USR1 (1 << 3)
+#define SIG_FLAG_USR2 (1 << 4)
+#define SIG_FLAG_TSTP (1 << 5)
+
static void init_uim(const char *engine);
static const char *get_default_im_name(void);
static int make_color_escseq(const char *instr, struct attribute_tag *attr);
@@ -157,12 +170,13 @@
static void recover_loop(void);
static struct winsize *get_winsize(void);
static void set_signal_handler(void);
-static void recover(int sig_no);
-static void sigtstp_handler(int sig_no);
-static void sigcont_handler(int sig_no);
-static void sigwinch_handler(int sig_no);
-static void sigusr1_handler(int sig_no);
-static void sigusr2_handler(int sig_no);
+static void reset_signal_handler(void);
+static void signal_handler(int sig_no);
+static void recover(void);
+static void sigtstp_handler(void);
+static void sigwinch_handler(void);
+static void sigusr1_handler(void);
+static void sigusr2_handler(void);
static void usage(void);
static void version(void);
@@ -504,6 +518,7 @@
}
init_helper();
init_callbacks();
+ focus_in();
init_draw(s_master, s_path_getmode);
init_escseq(&attr_uim);
set_signal_handler();
@@ -746,6 +761,7 @@
debug2(("<end draw_commit_and_preedit>"));
}
}
+
FD_ZERO(&fds);
FD_SET(g_win_in, &fds);
FD_SET(s_master, &fds);
@@ -755,15 +771,41 @@
if (g_helper_fd >= 0) {
FD_SET(g_helper_fd, &fds);
}
- if (my_select(nfd, &fds, NULL) <= 0) {
+
+ if (my_pselect(nfd, &fds, &s_orig_sigmask) <= 0) {
/* signal¤Ç³ä¤ê¹þ¤Þ¤ì¤¿¤È¤¤Ë¤¯¤ë¡£select¤ÎÊÖ¤êÃͤÏ-1¤Çerrno==EINTR */
+ debug(("signal flag = %x\n", s_signal_flag));
+ if ((s_signal_flag & SIG_FLAG_DONE ) != 0) {
+ s_signal_flag &= ~SIG_FLAG_DONE;
+ done(1);
+ }
+ if ((s_signal_flag & SIG_FLAG_RECOVER) != 0) {
+ s_signal_flag &= ~SIG_FLAG_RECOVER;
+ recover();
+ }
+ if ((s_signal_flag & SIG_FLAG_WINCH ) != 0) {
+ s_signal_flag &= ~SIG_FLAG_WINCH;
+ sigwinch_handler();
+ }
+ if ((s_signal_flag & SIG_FLAG_USR1 ) != 0) {
+ s_signal_flag &= ~SIG_FLAG_USR1;
+ sigusr1_handler();
+ }
+ if ((s_signal_flag & SIG_FLAG_USR2 ) != 0) {
+ s_signal_flag &= ~SIG_FLAG_USR2;
+ sigusr2_handler();
+ }
+ if ((s_signal_flag & SIG_FLAG_TSTP ) != 0) {
+ s_signal_flag &= ~SIG_FLAG_TSTP;
+ sigtstp_handler();
+ }
continue;
}
-
/* ¥â¡¼¥É¤òÊѹ¹¤¹¤ë */
if (s_setmode_fd >= 0 && FD_ISSET(s_setmode_fd, &fds)) {
int start, end;
+
#ifdef __CYGWIN32__
if ((len = read(s_setmode_fd, buf, sizeof(buf) - 1)) <= 0) {
debug2(("pipe closed\n"));
@@ -773,10 +815,12 @@
#else
len = read(s_setmode_fd, buf, sizeof(buf) - 1);
#endif
+
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((unsigned char)buf[start - 1]); --start);
buf[end + 1] = '\0';
mode = atoi(&buf[start]);
@@ -859,9 +903,10 @@
print_key(key, key_state);
} else {
int raw = press_key(key, key_state);
- draw();
- if (g_opt.status_type == BACKTICK) {
- update_backtick();
+ if (!draw()) {
+ if (g_opt.status_type == BACKTICK) {
+ update_backtick();
+ }
}
if (raw && !g_start_preedit) {
if (key_state & UMod_Alt) {
@@ -974,41 +1019,87 @@
static void set_signal_handler(void)
{
struct sigaction act;
+ sigset_t sigmask;
+
+ sigemptyset(&sigmask);
+ sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGTERM);
+ sigaddset(&sigmask, SIGQUIT);
+ sigaddset(&sigmask, SIGINT);
+ sigaddset(&sigmask, SIGWINCH);
+ sigaddset(&sigmask, SIGUSR1);
+ sigaddset(&sigmask, SIGUSR2);
+ sigaddset(&sigmask, SIGTSTP);
+ sigaddset(&sigmask, SIGCONT);
+ sigprocmask(SIG_BLOCK, &sigmask, &s_orig_sigmask);
+
/* ¥·¥°¥Ê¥ë¤ò¥Ö¥í¥Ã¥¯¤·¤Ê¤¤ */
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
/* ¥·¥¹¥Æ¥à¥³¡¼¥ë¤òºÆ¼Â¹Ô¤¹¤ë(¼ÂÁõ°Í¸) */
/* act.sa_flags = SA_RESTART; */
- act.sa_handler = done;
+ act.sa_handler = signal_handler;
sigaction(SIGHUP, &act, NULL);
sigaction(SIGTERM, &act, NULL);
-
- /* act.sa_handler = reload_uim; */
sigaction(SIGQUIT, &act, NULL);
-
- act.sa_handler = recover;
sigaction(SIGINT, &act, NULL);
+ sigaction(SIGWINCH, &act, NULL);
+ sigaction(SIGUSR1, &act, NULL);
+ sigaction(SIGUSR2, &act, NULL);
+ sigaction(SIGTSTP, &act, NULL);
+ sigaction(SIGCONT, &act, NULL);
+}
+static void reset_signal_handler(void)
+{
+ struct sigaction act;
- act.sa_handler = sigwinch_handler;
+ sigprocmask(SIG_SETMASK, &s_orig_sigmask, NULL);
+
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ act.sa_handler = SIG_DFL;
+ sigaction(SIGHUP, &act, NULL);
+ sigaction(SIGTERM, &act, NULL);
+ sigaction(SIGQUIT, &act, NULL);
+ sigaction(SIGINT, &act, NULL);
sigaction(SIGWINCH, &act, NULL);
-
- act.sa_handler = sigusr1_handler;
sigaction(SIGUSR1, &act, NULL);
-
- act.sa_handler = sigusr2_handler;
sigaction(SIGUSR2, &act, NULL);
-
- act.sa_handler = sigtstp_handler;
sigaction(SIGTSTP, &act, NULL);
-
- act.sa_handler = sigcont_handler;
sigaction(SIGCONT, &act, NULL);
}
-static void recover(int sig_no)
+static void signal_handler(int sig_no)
{
+ switch (sig_no) {
+ case SIGHUP:
+ case SIGTERM:
+ case SIGQUIT:
+ s_signal_flag |= SIG_FLAG_DONE;
+ break;
+ case SIGINT:
+ s_signal_flag |= SIG_FLAG_RECOVER;
+ break;
+ case SIGWINCH:
+ s_signal_flag |= SIG_FLAG_WINCH;
+ break;
+ case SIGUSR1:
+ s_signal_flag |= SIG_FLAG_USR1;
+ break;
+ case SIGUSR2:
+ s_signal_flag |= SIG_FLAG_USR2;
+ break;
+ case SIGTSTP:
+ s_signal_flag |= SIG_FLAG_TSTP;
+ break;
+ }
+}
+
+static void recover(void)
+{
+ reset_signal_handler();
put_exit_attribute_mode();
put_restore_cursor();
put_cursor_normal();
@@ -1016,10 +1107,13 @@
done(EXIT_SUCCESS);
}
-static void sigtstp_handler(int sig_no)
+/*
+ * µÙ»ß¥·¥°¥Ê¥ë
+ */
+static void sigtstp_handler(void)
{
struct sigaction act;
- sigset_t mask;
+ sigset_t sigmask;
quit_escseq();
put_save_cursor();
@@ -1028,48 +1122,38 @@
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = SIG_DFL;
+ sigaction(SIGTSTP, &act, NULL);
+ sigaction(SIGCONT, &act, NULL);
- sigemptyset(&mask);
- sigaddset(&mask, SIGTSTP);
- sigprocmask(SIG_UNBLOCK, &mask, NULL);
+ sigemptyset(&sigmask);
+ sigaddset(&sigmask, SIGTSTP);
+ sigaddset(&sigmask, SIGCONT);
+ sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
- sigaction(SIGTSTP, &act, NULL);
kill(getpid(), SIGTSTP);
+
+ sigprocmask(SIG_BLOCK, &sigmask, NULL);
- act.sa_handler = sigtstp_handler;
+ act.sa_handler = signal_handler;
sigaction(SIGTSTP, &act, NULL);
-}
-
-static void sigcont_handler(int sig_no)
-{
+ sigaction(SIGCONT, &act, NULL);
fixtty();
}
/*
* üËö¤Î¥µ¥¤¥º¤¬ÊѤï¤Ã¤¿¤È¤¤Ë²¾ÁÛüËö¤ÎÂ礤µ¤ò¹ç¤ï¤»¤ë¡£
*/
-static void sigwinch_handler(int sig_no)
+static void sigwinch_handler(void)
{
struct winsize *prev_win = g_win;
g_win = get_winsize();
+
debug2(("g_win->ws_row = %d g_win->ws_col = %d\n", g_win->ws_row, g_win->ws_col));
+
escseq_winch();
callbacks_winch();
- draw_winch();
- if (g_opt.status_type == LASTLINE) {
- put_save_cursor();
- put_cursor_invisible();
- if (g_win->ws_row > prev_win->ws_row) {
- struct winsize save_win = *g_win;
- g_win->ws_row = prev_win->ws_row;
- clear_lastline();
- *g_win = save_win;
- }
- draw_statusline_force_no_restore();
- put_change_scroll_region(0, g_win->ws_row - 1);
- put_restore_cursor();
- put_cursor_normal();
- }
+ draw_winch(prev_win);
+
free(prev_win);
ioctl(s_master, TIOCSWINSZ, g_win);
}
@@ -1095,13 +1179,13 @@
exit(exit_value);
}
-static void sigusr1_handler(int sig_no)
+static void sigusr1_handler(void)
{
press_key(UKey_Private1, 0);
draw();
}
-static void sigusr2_handler(int sig_no)
+static void sigusr2_handler(void)
{
press_key(UKey_Private2, 0);
draw();
Modified: trunk/fep/uim-fep.h
===================================================================
--- trunk/fep/uim-fep.h 2005-09-05 14:48:55 UTC (rev 1431)
+++ trunk/fep/uim-fep.h 2005-09-05 17:57:31 UTC (rev 1432)
@@ -40,8 +40,9 @@
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
+/* solaris ¤Çwinsize¤ò»È¤¦¤¿¤á¤ËɬÍ× */
+#ifdef HAVE_CURSES_H
+#include <curses.h>
#endif
#include <uim/uim.h>
More information about the uim-commit
mailing list