[uim-commit] r627 - trunk/fep
yamamoto at freedesktop.org
yamamoto at freedesktop.org
Fri Feb 11 05:09:08 PST 2005
Author: yamamoto
Date: 2005-02-11 05:07:45 -0800 (Fri, 11 Feb 2005)
New Revision: 627
Modified:
trunk/fep/README.ja
trunk/fep/callbacks.c
trunk/fep/draw.c
trunk/fep/draw.h
trunk/fep/escseq.c
trunk/fep/escseq.h
trunk/fep/key.c
trunk/fep/key.h
trunk/fep/read.c
trunk/fep/str.c
trunk/fep/str.h
trunk/fep/udsock.c
trunk/fep/uim-fep-tick.c
trunk/fep/uim-fep.c
trunk/fep/uim-fep.h
Log:
* fep/ add -S option
Modified: trunk/fep/README.ja
===================================================================
--- trunk/fep/README.ja 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/README.ja 2005-02-11 13:07:45 UTC (rev 627)
@@ -147,6 +147,15 @@
·Ê¿§¤¬¤¢¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò»È¤¦¤È±¦Ã¼¤ÎÇØ·Ê¿§¤¬¾Ã¤¨¤ë¤³¤È¤¬¤¢
¤ê¤Þ¤¹¡£
+ o -S GNU screen¤Ç¥Õ¥£¥ë¥¿¤È¤·¤Æ»È¤¨¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
+ Î㤨¤Ð¡¢~/.screenrc¤Ë
+ bind J exec | uim-fep -S
+ bind K eval 'exec cat' kill redisplay
+ ¤³¤Î¤è¤¦¤Ë½ñ¤±¤Ð¡¢C-a J¤Çuim-fep¤ò¥Õ¥£¥ë¥¿¤È¤·¤Æµ¯Æ°¤·¡¢C-a K
+ ¤Ç½ªÎ»¤Ç¤¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
+ -S¥ª¥×¥·¥ç¥ó¤òÉÕ¤±¤ë¤È¡¢-s¥ª¥×¥·¥ç¥ó¤Ë¤«¤«¤ï¤é¤º¥â¡¼¥Éɽ¼¨¤Ë¤Ï
+ backtick¤¬»È¤ï¤ì¤Þ¤¹¡£
+
o -e command arg1 arg2 ...
µ¯Æ°¤¹¤ë¥³¥Þ¥ó¥É¤ò»ØÄꤷ¤Þ¤¹¡£¤³¤Î¥ª¥×¥·¥ç¥ó°Ê¹ß¤Î°ú¿ô¤Ï
command¤ËÅϤµ¤ì¤Þ¤¹¡£
@@ -263,6 +272,9 @@
* ÍúÎò
+ o 2005/2/11
+ * -S¥ª¥×¥·¥ç¥ó¤òÄɲä·¤Þ¤·¤¿¡£
+
o 2004/8/9 0.4.1
* ¥×¥ê¥¨¥Ç¥£¥Ã¥ÈÉÁ²è¤ÎÁ°¸å¤Ç¿§¤òÊݸ¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤·¤¿¡£
Modified: trunk/fep/callbacks.c
===================================================================
--- trunk/fep/callbacks.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/callbacks.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -34,19 +34,19 @@
/*
* uim¤Î¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef DEBUG
#define NDEBUG
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_ASSERT_H
+#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
#include "uim-fep.h"
@@ -146,7 +146,7 @@
int press_key(int key, int key_state)
{
int raw;
-#if DEBUG > 2
+#if defined DEBUG && DEBUG > 2
if (32 <= key && key <= 127) {
debug2(("press key = %c key_state = %d\n", key, key_state));
} else {
Modified: trunk/fep/draw.c
===================================================================
--- trunk/fep/draw.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/draw.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -34,19 +34,19 @@
/*
* ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤ä¥¹¥Æ¡¼¥¿¥¹¥é¥¤¥ó¤òÉÁ²è¤¹¤ë
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
-#if HAVE_ASSERT_H
+#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
@@ -94,6 +94,7 @@
/* üËö¥µ¥¤¥º¤¬ÊÑ´¹¤·¤¿¤È¤TRUE */
static int s_winch = FALSE;
static int s_on_the_spot = FALSE;
+static int s_gnu_screen = FALSE;
static void init_backtick(void);
static void update_backtick(void);
@@ -118,11 +119,11 @@
static int width2lineno_char(int width);
static int width2lineno_col(int width);
-#if DEBUG > 2
+#if defined(DEBUG) && DEBUG > 2
static void print_preedit(struct preedit_tag *p);
#endif
-void init_draw(uim_context context, int on_the_spot, int status_type, int master, const char *path_getmode)
+void init_draw(uim_context context, int on_the_spot, int status_type, int gnu_screen, int master, const char *path_getmode)
{
s_context = context;
s_status_type = status_type;
@@ -130,6 +131,7 @@
s_path_getmode = path_getmode;
s_preedit = create_preedit();
s_on_the_spot = on_the_spot;
+ s_gnu_screen = gnu_screen;
if (s_status_type == BACKTICK) {
init_backtick();
draw_statusline_no_restore();
@@ -214,7 +216,13 @@
/* ¥×¥ê¥¨¥Ç¥£¥Ã¥È¤ò¾Ã¤¹É¬Íפ¬¤¢¤ë¤« */
if (prev_preedit->width > 0) {
put_cursor_invisible();
- erase_preedit();
+ if (s_gnu_screen) {
+ put_cursor_left(prev_preedit->cursor);
+ put_erase(prev_preedit->width);
+ put_cursor_left(prev_preedit->width);
+ } else {
+ erase_preedit();
+ }
end_preedit();
}
write(s_master, commit_str, strlen(commit_str));
@@ -230,7 +238,7 @@
end_preedit();
}
}
- } else {
+ } else { /* if (g_commit) */
if (s_preedit->width > 0) {
/* ¥³¥ß¥Ã¥È¤µ¤ì¤¿¤È¤¤Ë¥×¥ê¥¨¥Ç¥£¥Ã¥È¤¬¤¢¤Ã¤¿¤Î¤Ç¡¤¸å¤«¤é½ÐÎϤ¹
* ¤ë¤¿¤á¤Ë¥×¥ê¥¨¥Ç¥£¥Ã¥È¤òÊݸ¤¹¤ë */
@@ -254,6 +262,11 @@
{
if (!g_start_preedit) {
debug2(("start_preedit()\n"));
+ g_start_preedit = TRUE;
+ if (s_gnu_screen) {
+ return;
+ }
+
s_head = get_cursor_position();
if (s_head.col == g_win->ws_col - 1) {
s_head.col = 0;
@@ -267,7 +280,6 @@
s_line2width = malloc(sizeof(int));
s_line2width[0] = s_head.col;
s_preedit_lines = 1;
- g_start_preedit = TRUE;
}
}
@@ -277,8 +289,13 @@
*/
static void end_preedit(void)
{
+ debug2(("end_preedit()\n"));
assert(g_start_preedit);
g_start_preedit = FALSE;
+ if (s_gnu_screen) {
+ return;
+ }
+
put_cursor_address_p(&s_head);
s_preedit_lines = 0;
if (s_line2width != NULL) {
@@ -289,7 +306,6 @@
free(s_prev_line2width);
s_prev_line2width = NULL;
}
- debug2(("end_preedit()\n"));
}
/*
@@ -640,30 +656,53 @@
/* preedit == prev_preedit¤Î¤È¤¤Ï¡¢¥«¡¼¥½¥ë¤Î°ÜÆ°¤À¤± */
if (eq_width == preedit->width && eq_width == prev_preedit->width && eq_width > 0) {
- goto_char(preedit->cursor);
+ if (s_gnu_screen) {
+ put_move_cur(prev_preedit->cursor, preedit->cursor);
+ } else {
+ goto_char(preedit->cursor);
+ }
return;
}
- set_line2width(preedit);
+ if (!s_gnu_screen) {
+ set_line2width(preedit);
+ }
/* ½ÐÎϤ¹¤ë°ÌÃ֤˰ÜÆ° */
- goto_col(eq_width);
+ if (s_gnu_screen) {
+ put_move_cur(prev_preedit->cursor, eq_width);
+ } else {
+ goto_col(eq_width);
+ }
/* Îΰ褬ÊѤï¤Ã¤Æ¤¤¤Ê¤¤¤Î¤ÇÊѹ¹Éôʬ¤À¤±¾å½ñ¤ */
- if (is_eq_region()) {
+ if ((s_gnu_screen && preedit->width == prev_preedit->width) || (!s_gnu_screen && is_eq_region())) {
int eq_width_rev = compare_preedit_rev(preedit, prev_preedit);
debug2(("eq_width_rev = %d\n", eq_width_rev));
draw_subpreedit(preedit, eq_width, preedit->width - eq_width_rev);
- goto_char(preedit->cursor);
+ if (s_gnu_screen) {
+ put_move_cur(preedit->width - eq_width_rev, preedit->cursor);
+ } else {
+ goto_char(preedit->cursor);
+ }
return;
}
draw_subpreedit(preedit, eq_width, preedit->width);
- erase_prev_preedit();
+ if (s_gnu_screen) {
+ if (preedit->width > prev_preedit->width) {
+ put_cursor_left(preedit->width - preedit->cursor);
+ } else {
+ put_erase(prev_preedit->width - preedit->width);
+ put_cursor_left(prev_preedit->width - preedit->cursor);
+ }
+ } else {
+ erase_prev_preedit();
+ /* ¥«¡¼¥½¥ë¤Î°ÌÃ֤˰ÜÆ° */
+ goto_char(preedit->cursor);
+ }
- /* ¥«¡¼¥½¥ë¤Î°ÌÃ֤˰ÜÆ° */
- goto_char(preedit->cursor);
}
static int is_eq_region(void)
@@ -721,7 +760,12 @@
char *seg_str = p->pseg[i].str;
int seg_w = strwidth(seg_str);
if (w + seg_w <= width) {
- draw_pseg(&(p->pseg[i]), start + w);
+ if (s_gnu_screen) {
+ change_attr(p->pseg[i].attr);
+ put_uim_str(seg_str);
+ } else {
+ draw_pseg(&(p->pseg[i]), start + w);
+ }
w += seg_w;
if (w == width) {
break;
@@ -731,7 +775,12 @@
int byte = byte_width[0];
int save_char = seg_str[byte];
seg_str[byte] = '\0';
- draw_pseg(&(p->pseg[i]), start + w);
+ if (s_gnu_screen) {
+ change_attr(p->pseg[i].attr);
+ put_uim_str(seg_str);
+ } else {
+ draw_pseg(&(p->pseg[i]), start + w);
+ }
seg_str[byte] = save_char;
w += byte_width[1];
break;
@@ -1087,7 +1136,7 @@
s_winch = TRUE;
}
-#if DEBUG > 2
+#if defined(DEBUG) && DEBUG > 2
static void print_preedit(struct preedit_tag *p)
{
int i;
Modified: trunk/fep/draw.h
===================================================================
--- trunk/fep/draw.h 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/draw.h 2005-02-11 13:07:45 UTC (rev 627)
@@ -34,9 +34,7 @@
#ifndef DRAW_H
#define DRAW_H
-#if HAVE_UIM_UIM_H
#include <uim/uim.h>
-#endif
#define FORCE -1
#define CLEAR -2
@@ -46,7 +44,7 @@
extern int g_start_preedit;
extern int g_commit;
-void init_draw(uim_context context, int on_the_spot, int status_type, int master, const char *path_getmode);
+void init_draw(uim_context context, int on_the_spot, int status_type, int gnu_screen, int master, const char *path_getmode);
void draw(void);
void draw_statusline_restore(void);
void draw_statusline_no_restore(void);
Modified: trunk/fep/escseq.c
===================================================================
--- trunk/fep/escseq.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/escseq.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -31,32 +31,32 @@
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef DEBUG
#define NDEBUG
#endif
#include <stdio.h>
-#if HAVE_CURSES_H
+#ifdef HAVE_CURSES_H
#include <curses.h>
#endif
-#if HAVE_TERM_H
+#ifdef HAVE_TERM_H
#include <term.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_ASSERT_H
+#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
-#if HAVE_CTYPE_H
+#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
@@ -66,10 +66,14 @@
#include "str.h"
#include "read.h"
+#define my_putp(str) tputs(str, 1, my_putchar);
+
/* ¥«¡¼¥½¥ë¤ò¾Ã¤¹¤« */
static int s_use_civis = FALSE;
/* ¥¹¥Æ¡¼¥¿¥¹¥é¥¤¥ó¤Î¼ïÎà */
static int s_status_type;
+/* GNU screen ¥â¡¼¥É¤« */
+static int s_gnu_screen;
/* ½é´ü²½¤·¤¿¤éTRUE */
static int s_init = FALSE;
/* ¸½ºß¤Î¥«¡¼¥½¥ë°ÌÃÖ */
@@ -143,25 +147,27 @@
static char *escseq2n(const char *escseq);
static void escseq2n2(const char *escseq, const char **first, const char **second);
static const char *attr2escseq(const struct attribute_tag *attr);
-static void set_attr(const char *str);
+static void set_attr(const char *str, int len);
static void put_enter_uim_mode(void);
static void put_exit_uim_mode(void);
+static int my_putchar(int c);
#ifndef HAVE_CFMAKERAW
static int cfmakeraw(struct termios *termios_p);
#endif
-#if DEBUG > 1
+#if defined(DEBUG) && DEBUG > 1
static void print_attr(struct attribute_tag *attr);
#endif
/*
* termcap/terminfo¤Î¥¨¥ó¥È¥ê¤¬¤¢¤ë¤«³Îǧ¤¹¤ë
*/
-void init_escseq(int use_civis, int use_ins_del, int status_type, const struct attribute_tag *attr_uim)
+void init_escseq(int use_civis, int use_ins_del, int status_type, int gnu_screen, const struct attribute_tag *attr_uim)
{
s_use_civis = use_civis;
s_status_type = status_type;
s_attr_uim = *attr_uim;
+ s_gnu_screen = gnu_screen;
if (enter_underline_mode == NULL) {
printf("enter_underline_mode is not available\n");
@@ -197,6 +203,16 @@
done(EXIT_FAILURE);
}
}
+ if (s_gnu_screen) {
+ if (cursor_left == NULL) {
+ printf("cursor_left is not available\n");
+ done(EXIT_FAILURE);
+ }
+ if (cursor_right == NULL) {
+ printf("cursor_right is not available\n");
+ done(EXIT_FAILURE);
+ }
+ }
if (use_ins_del) {
if (parm_ich == NULL) {
printf("parm_ich is not available\n");
@@ -303,7 +319,7 @@
put_save_cursor();
put_change_scroll_region(0, g_win->ws_row);
put_goto_lastline(0);
- putp(clr_eol);
+ my_putp(clr_eol);
put_restore_cursor();
}
put_restore_cursor();
@@ -320,13 +336,18 @@
struct point_tag cursor2;
static struct termios tios;
- tcgetattr(STDIN_FILENO, &tios);
+ tcgetattr(g_win_in, &tios);
cfmakeraw(&tios);
/* read_stdin¤¬Ìá¤ë¤Þ¤Ç¤ËÆɤޤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤ºÇ¾®¤Îʸ»ú¿ô */
tios.c_cc[VMIN] = 0;
/* read_stdin¤¬Ìá¤ë¤Þ¤Ç¤Î¥¿¥¤¥à¥¢¥¦¥È 0.1ÉÃñ°Ì */
tios.c_cc[VTIME] = 3;
- tcsetattr(STDIN_FILENO, TCSANOW, &tios);
+ tcsetattr(g_win_in, TCSANOW, &tios);
+
+ if (s_gnu_screen) {
+ return;
+ }
+
/* ³«»Ï°ÌÃÖ¤òÊݸ */
start_cursor = get_cursor_position();
if (start_cursor.row == UNDEFINED) {
@@ -336,7 +357,7 @@
put_cursor_invisible();
/* ºÇ²¼¹Ô¤«¤é³«»Ï¤·¤¿¤È¤¤Î¤¿¤á¤Ë¥¹¥¯¥í¡¼¥ë */
if (s_status_type == LASTLINE) {
- putchar('\n');
+ write(g_win_out, "\n", strlen("\n"));
}
/* °ÂÁ´¤Ê°ÌÃ֤˰ÜÆ° */
put_cursor_address(1, 1);
@@ -377,6 +398,33 @@
}
#endif
+void put_move_cur(int from, int to)
+{
+ if (to < from) {
+ put_cursor_left(from - to);
+ } else if (from < to) {
+ put_cursor_right(to - from);
+ }
+}
+
+void put_cursor_left(int n)
+{
+ int i;
+ debug(("<left %d>", n));
+ for (i = 0; i < n; i++) {
+ my_putp(cursor_left);
+ }
+}
+
+void put_cursor_right(int n)
+{
+ int i;
+ debug(("<right %d>", n));
+ for (i = 0; i < n; i++) {
+ my_putp(cursor_right);
+ }
+}
+
/*
* ¥«¡¼¥½¥ë°ÌÃÖ¤òÊݸ¤¹¤ë
*/
@@ -420,7 +468,7 @@
if (s_cursor.row != UNDEFINED) {
return s_cursor;
}
- printf("\033[6n");
+ write(g_win_out, "\033[6n", strlen("\033[6n"));
do {
/* 10²ó¥ë¡¼¥×¤·¤Æ¤â¤À¤á¤À¤Ã¤¿¤é½ªÎ» */
@@ -493,7 +541,7 @@
s_cursor.row -= s_cursor_diff.row;
s_cursor.col -= s_cursor_diff.col;
- /* screen¤Ç¤Ï¤³¤¦¤Ê¤ë¤³¤È¤¬¤¢¤ë */
+ /* GNU screen ¤Ç¤Ï¤³¤¦¤Ê¤ë¤³¤È¤¬¤¢¤ë */
if (s_cursor.col > g_win->ws_col - 1) {
put_crlf();
}
@@ -508,7 +556,7 @@
{
if (s_use_civis && !s_cursor_invisible && cursor_invisible != NULL && cursor_normal != NULL) {
s_cursor_invisible = TRUE;
- putp(cursor_invisible);
+ my_putp(cursor_invisible);
debug(("<invis>"));
}
}
@@ -520,7 +568,7 @@
{
if (s_cursor_invisible) {
s_cursor_invisible = FALSE;
- putp(cursor_normal);
+ my_putp(cursor_normal);
debug(("<norm>"));
}
}
@@ -533,7 +581,7 @@
put_enter_uim_mode();
if (!s_attr.underline) {
s_attr.underline = TRUE;
- putp(enter_underline_mode);
+ my_putp(enter_underline_mode);
debug(("<{_>"));
}
}
@@ -551,7 +599,7 @@
}
put_exit_attribute_mode();
if (s_enter_uim_mode != NULL) {
- putp(s_enter_uim_mode);
+ my_putp(s_enter_uim_mode);
debug(("%s", s_enter_uim_mode));
}
/* debug(("<_}>")); */
@@ -566,7 +614,7 @@
put_enter_uim_mode();
if (!s_attr.standout) {
s_attr.standout = TRUE;
- putp(enter_standout_mode);
+ my_putp(enter_standout_mode);
debug(("<{r>"));
}
}
@@ -584,7 +632,7 @@
}
put_exit_attribute_mode();
if (s_enter_uim_mode != NULL) {
- putp(s_enter_uim_mode);
+ my_putp(s_enter_uim_mode);
debug(("%s", s_enter_uim_mode));
debug(("<{uim>"));
}
@@ -599,7 +647,7 @@
void put_exit_attribute_mode(void)
{
s_attr = s_attr_none;
- putp(exit_attribute_mode);
+ my_putp(exit_attribute_mode);
debug(("<a}>"));
}
@@ -641,7 +689,7 @@
escseq = attr2escseq(&attr);
}
if (escseq != NULL) {
- putp(escseq);
+ my_putp(escseq);
debug(("change_attr %s\n", escseq));
}
}
@@ -740,28 +788,38 @@
/*
* str¤«¤é°À¤òÊѹ¹¤¹¤ë¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤òõ¤¹
+ * len > 0
*/
-static void set_attr(const char *str)
+static void set_attr(const char *str, int len)
{
/* ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤Î³«»Ï */
const char *start;
const char *free_str = NULL;
/* TRUE¤Î¤È¤free_str¤òfree¤¹¤ëɬÍפ¬¤¢¤ë */
int must_free = FALSE;
+ const char *end = str + len;
/* Á°²ó¤ÎÅÓÃæ¤Î¥Ð¥Ã¥Õ¥¡¤¬¤¢¤ë¤« */
if (s_escseq_buf != NULL) {
const char *tmp_str = str;
+ /* s_escseq_buf ¤Ë¤Ï'\0'¤Ï´Þ¤Þ¤ì¤Ê¤¤ */
+ int escseq_buf_len = strlen(s_escseq_buf);
must_free = TRUE;
- free_str = str = malloc(strlen(s_escseq_buf) + strlen(tmp_str) + 1);
- sprintf((char *)str, "%s%s", s_escseq_buf, tmp_str);
+ free_str = str = malloc(escseq_buf_len + len + 1);
+ memcpy((char *)str, s_escseq_buf, escseq_buf_len);
+ memcpy((char *)str + escseq_buf_len, tmp_str, len);
+ ((char *)str)[escseq_buf_len + len] = '\0';
free(s_escseq_buf);
s_escseq_buf = NULL;
+ end = str + escseq_buf_len + len;
}
- while ((start = str = strstr(str, "\033")) != NULL) {
+ while ((start = str = memchr(str, ESCAPE_CODE, end - str)) != NULL) {
str++;
- if (str[0] == '\0') {
- s_escseq_buf = strdup(start);
+ if (str == end) {
+ int escseq_buf_len = end - start;
+ s_escseq_buf = malloc(escseq_buf_len + 1);
+ memcpy(s_escseq_buf, start, escseq_buf_len);
+ s_escseq_buf[escseq_buf_len] = '\0';
}
else if (str[0] == '[') {
@@ -788,8 +846,11 @@
}
}
- if (str[0] == '\0') {
- s_escseq_buf = strdup(start);
+ if (str == end) {
+ int escseq_buf_len = end - start;
+ s_escseq_buf = malloc(escseq_buf_len + 1);
+ memcpy(s_escseq_buf, start, escseq_buf_len);
+ s_escseq_buf[escseq_buf_len] = '\0';
}
else if (str[0] == 'm') {
@@ -842,6 +903,7 @@
*/
void put_cursor_address(int row, int col)
{
+ const char *tmp;
if (row >= g_win->ws_row) {
row = g_win->ws_row - 1;
}
@@ -849,7 +911,8 @@
if (row == s_cursor.row && col == s_cursor.col && col < g_win->ws_col - 2) {
return;
}
- putp(tparm(cursor_address, row, col));
+ tmp = tparm(cursor_address, row, col);
+ my_putp(tmp);
s_cursor.row = row;
s_cursor.col = col;
debug(("<go %d %d>", row, col));
@@ -865,10 +928,12 @@
*/
void put_insert(int n)
{
+ const char *tmp;
if (n <= 0) {
return;
}
- putp(tparm(parm_ich, n));
+ tmp = tparm(parm_ich, n);
+ my_putp(tmp);
debug(("<ins %d>", n));
}
@@ -877,6 +942,7 @@
*/
void put_delete(int n)
{
+ const char *tmp;
if (n <= 0) {
return;
}
@@ -884,7 +950,8 @@
put_exit_underline_mode();
put_exit_standout_mode();
}
- putp(tparm(parm_dch, n));
+ tmp = tparm(parm_dch, n);
+ my_putp(tmp);
debug(("<del %d>", n));
}
@@ -893,7 +960,7 @@
*/
void put_crlf(void)
{
- printf("\r\n");
+ write(g_win_out, "\r\n", strlen("\r\n"));
s_cursor.col = 0;
s_cursor.row++;
if (s_cursor.row >= g_win->ws_row) {
@@ -907,11 +974,13 @@
*/
void put_goto_lastline(int col)
{
+ const char *tmp;
int row = g_win->ws_row;
if (row == s_cursor.row && col == s_cursor.col) {
return;
}
- putp(tparm(cursor_address, row, col));
+ tmp = tparm(cursor_address, row, col);
+ my_putp(tmp);
s_cursor.row = row;
s_cursor.col = col;
debug(("<go %d %d>", row, col));
@@ -954,7 +1023,7 @@
put_exit_standout_mode();
put_exit_underline_mode();
}
- putp(clr_eol);
+ my_putp(clr_eol);
debug(("<clear>"));
}
@@ -963,7 +1032,8 @@
*/
void put_change_scroll_region(int start, int end)
{
- putp(tparm(change_scroll_region, start, end));
+ const char *tmp = tparm(change_scroll_region, start, end);
+ my_putp(tmp);
s_cursor.row = s_cursor.col = 0;
debug(("<region %d %d>", start, end));
}
@@ -985,7 +1055,7 @@
put_enter_uim_mode();
s_cursor.col += strwidth(str);
assert(s_cursor.col <= g_win->ws_col);
- printf("%s", str);
+ write(g_win_out, str, strlen(str));
debug(("<put_uim_str \"%s\">", str));
}
@@ -1005,14 +1075,14 @@
* pty¤«¤é¤Î½ÐÎÏstr¤òüËö¤Ë½ÐÎϤ¹¤ë
* ¥¨¥¹¥±¡¼¥×¥·¡¼¥±¥ó¥¹¤ò´Þ¤à¾ì¹ç¤¬¤¢¤ë
*/
-void put_pty_str(const char *str)
+void put_pty_str(const char *str, int len)
{
- if (str[0] == '\0') {
+ if (len == 0) {
return;
}
put_exit_uim_mode();
- printf("%s", str);
- set_attr(str);
+ write(g_win_out, str, len);
+ set_attr(str, len);
g_commit = FALSE;
s_cursor.row = s_cursor.col = UNDEFINED;
debug(("<put_pty_str \"%s\">", str));
@@ -1056,7 +1126,13 @@
s_cursor.row = s_cursor.col = UNDEFINED;
}
-#if DEBUG > 1
+static int my_putchar(int c)
+{
+ write(g_win_out, &c, 1);
+ return c;
+}
+
+#if defined(DEBUG) && DEBUG > 1
static void print_attr(struct attribute_tag *attr)
{
debug(("underline = %d standout = %d bold = %d blink = %d fore = %d back = %d\n",
Modified: trunk/fep/escseq.h
===================================================================
--- trunk/fep/escseq.h 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/escseq.h 2005-02-11 13:07:45 UTC (rev 627)
@@ -49,9 +49,12 @@
};
-void init_escseq(int use_civis, int use_ins_del, int status_type, const struct attribute_tag *attr_uim);
+void init_escseq(int use_civis, int use_ins_del, int status_type, int gnu_screen, const struct attribute_tag *attr_uim);
void quit_escseq(void);
struct point_tag get_cursor_position(void);
+void put_move_cur(int from, int to);
+void put_cursor_left(int n);
+void put_cursor_right(int n);
void put_save_cursor(void);
void put_restore_cursor(void);
void put_cursor_invisible(void);
@@ -72,7 +75,7 @@
void put_change_scroll_region(int start, int end);
void put_uim_str(const char *str);
void put_uim_str_len(const char *str, int len);
-void put_pty_str(const char *str);
+void put_pty_str(const char *str, int len);
char *cut_padding(const char *escseq);
void escseq_winch(void);
#endif
Modified: trunk/fep/key.c
===================================================================
--- trunk/fep/key.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/key.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -31,7 +31,7 @@
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef DEBUG
@@ -40,19 +40,20 @@
#include <uim/uim.h>
-#if HAVE_CURSES_H
+#ifdef HAVE_CURSES_H
#include <curses.h>
#endif
-#if HAVE_TERM_H
+#ifdef HAVE_TERM_H
#include <term.h>
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_ASSERT_H
+#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
#include "key.h"
+#include "uim-fep.h"
#define _KEY_UP "\033[A"
#define _KEY_DOWN "\033[B"
Modified: trunk/fep/key.h
===================================================================
--- trunk/fep/key.h 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/key.h 2005-02-11 13:07:45 UTC (rev 627)
@@ -33,7 +33,6 @@
#ifndef KEY_H
#define KEY_H
-#define ESCAPE_CODE 27
int tty2key(char key);
int tty2key_state(char key);
int *escape_sequence2key(const char *str);
Modified: trunk/fep/read.c
===================================================================
--- trunk/fep/read.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/read.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -31,33 +31,33 @@
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef DEBUG
#define NDEBUG
#endif
-#if HAVE_SYS_TIME_H
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "uim-fep.h"
#include "read.h"
-char *unget_buf = NULL;
-int buf_size = 0;
+static char *s_unget_buf = NULL;
+static int s_buf_size = 0;
/*
* select
@@ -65,9 +65,9 @@
*/
int my_select(int n, fd_set *readfds, struct timeval *timeout)
{
- if (buf_size > 0) {
+ if (s_buf_size > 0) {
FD_ZERO(readfds);
- FD_SET(STDIN_FILENO, readfds);
+ FD_SET(g_win_in, readfds);
return 1;
}
return select(n, readfds, NULL, NULL, timeout);
@@ -79,20 +79,20 @@
*/
ssize_t read_stdin(void *buf, int count)
{
- if (buf_size > 0) {
- if (buf_size > count) {
- memcpy(buf, unget_buf, count);
- buf_size -= count;
- memmove(unget_buf, unget_buf + count, buf_size);
+ if (s_buf_size > 0) {
+ if (s_buf_size > count) {
+ memcpy(buf, s_unget_buf, count);
+ s_buf_size -= count;
+ memmove(s_unget_buf, s_unget_buf + count, s_buf_size);
return count;
} else {
- int rval = buf_size;
- memcpy(buf, unget_buf, buf_size);
- buf_size = 0;
+ int rval = s_buf_size;
+ memcpy(buf, s_unget_buf, s_buf_size);
+ s_buf_size = 0;
return rval;
}
}
- return read(STDIN_FILENO, buf, count);
+ return read(g_win_in, buf, count);
}
/*
@@ -103,8 +103,8 @@
if (count <= 0) {
return;
}
- debug(("unget count = %d buf_size = %d\n", count, buf_size));
- unget_buf = realloc(unget_buf, buf_size + count);
- memcpy(unget_buf + buf_size, str, count);
- buf_size += count;
+ debug(("unget count = %d s_buf_size = %d\n", count, s_buf_size));
+ s_unget_buf = realloc(s_unget_buf, s_buf_size + count);
+ memcpy(s_unget_buf + s_buf_size, str, count);
+ s_buf_size += count;
}
Modified: trunk/fep/str.c
===================================================================
--- trunk/fep/str.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/str.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -31,32 +31,32 @@
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#ifndef DEBUG
#define NDEBUG
#endif
-#if HAVE_ASSERT_H
+#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
-#if HAVE_LOCALE_H
+#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
-#if HAVE_WCHAR_H
+#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_STRINGS_H
+#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
-#if HAVE_CTYPE_H
+#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "uim-fep.h"
@@ -614,10 +614,11 @@
* needle¤¬¶õʸ»úÎó¤Î¾ì¹ç¤ÏNULL¤òÊÖ¤¹
* needle¤¬NULL¤Î¤È¤¤ÏNULL¤òÊÖ¤¹
*/
-char *rstrstr(char *haystack, const char *needle)
+char *rstrstr_len(const char *haystack, const char *needle, int haystack_len)
{
- char *str = NULL;
+ const char *str = NULL;
int needle_len;
+ const char *new_haystack = haystack;
assert(haystack != NULL);
if (needle == NULL) {
return NULL;
@@ -626,13 +627,42 @@
if (needle_len <= 0) {
return NULL;
}
- while ((haystack = strstr(haystack, needle)) != NULL) {
- haystack += needle_len;
- str = haystack;
+ while ((new_haystack = strstr_len(haystack, needle, haystack_len)) != NULL) {
+ new_haystack += needle_len;
+ haystack_len -= (new_haystack - haystack);
+ str = haystack = new_haystack;
}
- return str;
+ return (char *)str;
}
+/*
+ * haystack¤Ë'\0'¤¬´Þ¤Þ¤ì¤Æ¤â¤è¤¤strstr
+ * haystack¤ÎŤµ¤Ïhaystack_len
+ * haystack¤Èneedle¤ÏNULL¤Ç¤Ê¤¤
+ * needle¤¬""¤Î¤È¤¤Ïhaystack¤òÊÖ¤¹
+ */
+char *strstr_len(const char *haystack, const char *needle, int haystack_len)
+{
+ int needle_len;
+ int i, j;
+
+ assert(haystack != NULL && needle != NULL);
+
+ needle_len = strlen(needle);
+
+ for (i = 0; i < haystack_len - needle_len + 1; i++) {
+ for (j = 0; j < needle_len; j++) {
+ if (haystack[i + j] != needle[j]) {
+ break;
+ }
+ }
+ if (j == needle_len) {
+ return (char *)haystack + i;
+ }
+ }
+ return NULL;
+}
+
static int min(int a, int b)
{
return a < b ? a : b;
Modified: trunk/fep/str.h
===================================================================
--- trunk/fep/str.h 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/str.h 2005-02-11 13:07:45 UTC (rev 627)
@@ -43,7 +43,8 @@
int *width2byte(const char *str, int n);
int *width2byte2(const char *str, int n);
int strhead(char *str, int n);
-char *rstrstr(char *haystack, const char *needle);
+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.c
===================================================================
--- trunk/fep/udsock.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/udsock.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -31,29 +31,29 @@
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
-#if HAVE_SYS_SOCKET_H
+#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
-#if HAVE_SYS_UN_H
+#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
-#if HAVE_PWD_H
+#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
Modified: trunk/fep/uim-fep-tick.c
===================================================================
--- trunk/fep/uim-fep-tick.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/uim-fep-tick.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -31,17 +31,17 @@
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "udsock.h"
Modified: trunk/fep/uim-fep.c
===================================================================
--- trunk/fep/uim-fep.c 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/uim-fep.c 2005-02-11 13:07:45 UTC (rev 627)
@@ -31,78 +31,76 @@
*/
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef DEBUG
#define NDEBUG
#endif
#include <stdio.h>
-#if HAVE_ASSERT_H
+#ifdef HAVE_ASSERT_H
#include <assert.h>
#endif
-#if HAVE_UNISTD_H
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_SYS_TYPES_H
+#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
-#if HAVE_SIGNAL_H
+#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
-#if HAVE_UIM_UIM_H
#include <uim/uim.h>
-#endif
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
#include <string.h>
#endif
-#if HAVE_STRINGS_H
+#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
-#if HAVE_CURSES_H
+#ifdef HAVE_CURSES_H
#include <curses.h>
#endif
-#if HAVE_TERM_H
+#ifdef HAVE_TERM_H
#include <term.h>
#endif
-#if HAVE_STDARG_H
+#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
-#if HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
-#if HAVE_PWD_H
+#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
-#if HAVE_FCNTL_H
+#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#if HAVE_CTYPE_H
+#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif
-#if HAVE_SYS_STAT_H
+#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
-#if HAVE_SYS_TIME_H
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
-#if HAVE_STROPTS_H
+#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif
-#if HAVE_SYS_PARAM_H
+#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
-#if HAVE_PTY_H
+#ifdef HAVE_PTY_H
#include <pty.h>
#endif
-#if HAVE_UTIL_H
+#ifdef HAVE_UTIL_H
#include <util.h>
#endif
-#if HAVE_LIBUTIL_H
+#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#endif
@@ -123,8 +121,11 @@
static uim_context s_context;
/* ¥¹¥Æ¡¼¥¿¥¹¥é¥¤¥ó¤Î¼ïÎà */
static int s_status_type = DEFAULT_STATUS;
+static int s_gnu_screen = FALSE;
/* µ¿»÷üËö¤Îmaster¤Î¥Õ¥¡¥¤¥ëµ½Ò»Ò */
static int s_master;
+int g_win_in = STDIN_FILENO;
+int g_win_out = STDOUT_FILENO;
/* µ¯Æ°»þ¤ÎüËö¾õÂÖ */
static struct termios s_save_tios;
#ifndef MAXPATHLEN
@@ -135,7 +136,7 @@
static int s_setmode_fd = -1;
static int s_timeout = 0;
-static void init_agent(const char *engine, const char *enc);
+static void init_agent(const char *engine);
static const char *get_default_im_name(void);
static int make_color_escseq(const char *instr, struct attribute_tag *attr);
static int colorname2n(const char *name);
@@ -143,7 +144,7 @@
static pid_t forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp);
#endif
static void main_loop(void);
-static void recover_loop();
+static void recover_loop(void);
static struct winsize *get_winsize(void);
static void set_signal_handler(void);
static void recover(int sig_no);
@@ -157,9 +158,8 @@
/*
* uim¤ò½é´ü²½¤¹¤ë
* engine ÊÑ´¹¥¨¥ó¥¸¥ó¤Î̾Á°
- * enc ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
*/
-static void init_agent(const char *engine, const char *enc)
+static void init_agent(const char *engine)
{
int nr;
int i;
@@ -219,62 +219,11 @@
tcflag_t save_iflag;
int op;
- /* exit if stdin is redirected */
- if (!(isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))) {
- FILE *tty;
- if ((tty = fopen("/dev/tty", "w")) != NULL) {
- fprintf(tty, "stdin or stdout is not a terminal\n");
- }
- return EXIT_FAILURE;
- }
-
if (getenv("UIM_FEP_PID")) {
puts("uim-fep is already running");
return EXIT_FAILURE;
}
- init_str();
-
- tcgetattr(STDIN_FILENO, &s_save_tios);
- setupterm(NULL, STDOUT_FILENO, NULL);
-
- if (getenv("TMP")) {
- struct passwd *pw = getpwuid(getuid());
- /* Generate get mode filepath */
- snprintf(s_path_getmode, sizeof(s_path_getmode), "%s/uim-fep-%s-%d-getmode", getenv("TMP"), pw->pw_name, getpid());
- /* Generate set mode filepath */
- snprintf(s_path_setmode, sizeof(s_path_setmode), "%s/uim-fep-%s-%d-setmode", getenv("TMP"), pw->pw_name, getpid());
- } else {
- struct passwd *pw = getpwuid(getuid());
- /* Generate get mode filepath */
- snprintf(s_path_getmode, sizeof(s_path_getmode), "/tmp/uim-fep-%s-%d-getmode", pw->pw_name, getpid());
- /* Generate set mode filepath */
- snprintf(s_path_setmode, sizeof(s_path_setmode), "/tmp/uim-fep-%s-%d-setmode", pw->pw_name, getpid());
- }
-
- env_buf = malloc(30);
- snprintf(env_buf, 30, "UIM_FEP_PID=%d", getpid());
- putenv(env_buf);
-
- if (fopen(s_path_getmode, "wt") != NULL) {
- unlink(s_path_getmode);
- env_buf = malloc(strlen("UIM_FEP_GETMODE=") + strlen(s_path_getmode) + 1);
- sprintf(env_buf, "UIM_FEP_GETMODE=%s", s_path_getmode);
- putenv(env_buf);
- } else {
- s_path_getmode[0] = '\0';
- }
-
- if (mkfifo(s_path_setmode, 0600) != -1) {
- unlink(s_path_setmode);
- env_buf = malloc(strlen("UIM_FEP_SETMODE=") + strlen(s_path_setmode) + 1);
- sprintf(env_buf, "UIM_FEP_SETMODE=%s", s_path_setmode);
- putenv(env_buf);
- } else {
- s_path_setmode[0] = '\0';
- s_setmode_fd = -1;
- }
-
if ((command[0] = getenv("SHELL")) == NULL || *command[0] == '\0') {
struct passwd *pw;
if ((pw = getpwuid(getuid())) == NULL || *(command[0] = pw->pw_shell) == '\0') {
@@ -285,7 +234,7 @@
engine = get_default_im_name();
- while ((op = getopt(argc, argv, "e:s:u:b:w:t:C:ciovh")) != -1) {
+ while ((op = getopt(argc, argv, "e:s:u:b:w:t:C:Sciovh")) != -1) {
int i;
switch (op) {
case 'e':
@@ -314,6 +263,10 @@
}
break;
+ case 'S':
+ s_gnu_screen = TRUE;
+ break;
+
case 'u':
engine = optarg;
break;
@@ -377,37 +330,96 @@
return EXIT_FAILURE;
}
- g_win = get_winsize();
- save_iflag = s_save_tios.c_iflag;
- s_save_tios.c_iflag &= ~ISTRIP;
- child = forkpty(&s_master, NULL, &s_save_tios, g_win);
- s_save_tios.c_iflag = save_iflag;
+ if (s_gnu_screen) {
+ s_status_type = BACKTICK;
+ s_master = PROC_FILENO;
+ g_win_in = WIN_IN_FILENO;
+ g_win_out = WIN_OUT_FILENO;
+ }
- if (child < 0) {
- perror("fork");
+ /* exit if stdin is redirected */
+ if (!isatty(g_win_in)) {
+ FILE *tty;
+ if ((tty = fopen("/dev/tty", "w")) != NULL) {
+ fprintf(tty, "stdin is not a terminal\n");
+ }
return EXIT_FAILURE;
}
- if (child == 0) {
- /* »Ò¥×¥í¥»¥¹ */
- execvp(command[0], (char *const *)command);
- perror(command[0]);
- done(EXIT_FAILURE);
+
+ init_str();
+
+ tcgetattr(g_win_in, &s_save_tios);
+ setupterm(NULL, g_win_out, NULL);
+
+ if (getenv("TMP")) {
+ struct passwd *pw = getpwuid(getuid());
+ /* Generate get mode filepath */
+ snprintf(s_path_getmode, sizeof(s_path_getmode), "%s/uim-fep-%s-%d-getmode", getenv("TMP"), pw->pw_name, getpid());
+ /* Generate set mode filepath */
+ snprintf(s_path_setmode, sizeof(s_path_setmode), "%s/uim-fep-%s-%d-setmode", getenv("TMP"), pw->pw_name, getpid());
+ } else {
+ struct passwd *pw = getpwuid(getuid());
+ /* Generate get mode filepath */
+ snprintf(s_path_getmode, sizeof(s_path_getmode), "/tmp/uim-fep-%s-%d-getmode", pw->pw_name, getpid());
+ /* Generate set mode filepath */
+ snprintf(s_path_setmode, sizeof(s_path_setmode), "/tmp/uim-fep-%s-%d-setmode", pw->pw_name, getpid());
}
+ env_buf = malloc(30);
+ snprintf(env_buf, 30, "UIM_FEP_PID=%d", getpid());
+ putenv(env_buf);
+
+ if (fopen(s_path_getmode, "wt") != NULL) {
+ unlink(s_path_getmode);
+ env_buf = malloc(strlen("UIM_FEP_GETMODE=") + strlen(s_path_getmode) + 1);
+ sprintf(env_buf, "UIM_FEP_GETMODE=%s", s_path_getmode);
+ putenv(env_buf);
+ } else {
+ s_path_getmode[0] = '\0';
+ }
+
+ if (mkfifo(s_path_setmode, 0600) != -1) {
+ unlink(s_path_setmode);
+ env_buf = malloc(strlen("UIM_FEP_SETMODE=") + strlen(s_path_setmode) + 1);
+ sprintf(env_buf, "UIM_FEP_SETMODE=%s", s_path_setmode);
+ putenv(env_buf);
+ } else {
+ s_path_setmode[0] = '\0';
+ s_setmode_fd = -1;
+ }
+
+ g_win = get_winsize();
+ if (!s_gnu_screen) {
+ save_iflag = s_save_tios.c_iflag;
+ s_save_tios.c_iflag &= ~ISTRIP;
+ child = forkpty(&s_master, NULL, &s_save_tios, g_win);
+ s_save_tios.c_iflag = save_iflag;
+
+ if (child < 0) {
+ perror("fork");
+ return EXIT_FAILURE;
+ }
+ if (child == 0) {
+ /* »Ò¥×¥í¥»¥¹ */
+ execvp(command[0], (char *const *)command);
+ perror(command[0]);
+ done(EXIT_FAILURE);
+ }
+ }
+
free(command);
if (s_status_type == BACKTICK && statusline_width > CANDSIZE / 2) {
statusline_width = CANDSIZE / 2;
}
- setbuf(stdout, NULL);
if (s_status_type == BACKTICK) {
init_sendsocket(sock_path);
}
- init_agent(engine, get_enc());
+ init_agent(engine);
init_callbacks(s_context, s_status_type, cursor_no_reverse, statusline_width);
- init_draw(s_context, on_the_spot, s_status_type, s_master, s_path_getmode);
- init_escseq(use_civis, on_the_spot, s_status_type, &attr_uim);
+ init_draw(s_context, on_the_spot, s_status_type, s_gnu_screen, s_master, s_path_getmode);
+ init_escseq(use_civis, on_the_spot, s_status_type, s_gnu_screen, &attr_uim);
set_signal_handler();
if (s_path_setmode[0] != '\0' && mkfifo(s_path_setmode, 0600) != -1) {
@@ -561,16 +573,31 @@
char buf[BUFSIZE];
ssize_t len;
fd_set fds;
- int nfd = (s_master > s_setmode_fd ? s_master : s_setmode_fd) + 1;
+ int nfd;
char *_clear_screen = cut_padding(clear_screen);
char *_clr_eos = cut_padding(clr_eos);
+ if (g_win_in > s_master) {
+ if (g_win_in > s_setmode_fd) {
+ nfd = g_win_in;
+ } else {
+ nfd = s_setmode_fd;
+ }
+ } else {
+ if (s_master > s_setmode_fd) {
+ nfd = s_master;
+ } else {
+ nfd = s_setmode_fd;
+ }
+ }
+ nfd++;
+
while (TRUE) {
/* ¥³¥ß¥Ã¥È¤µ¤ì¤¿¤È¤¤Ë¥×¥ê¥¨¥Ç¥£¥Ã¥È¤¬¤¢¤ë¤« */
if (is_commit_and_preedit()) {
struct timeval t;
FD_ZERO(&fds);
- FD_SET(STDIN_FILENO, &fds);
+ FD_SET(g_win_in, &fds);
FD_SET(s_master, &fds);
if (s_setmode_fd > 0) {
FD_SET(s_setmode_fd, &fds);
@@ -585,7 +612,7 @@
}
}
FD_ZERO(&fds);
- FD_SET(STDIN_FILENO, &fds);
+ FD_SET(g_win_in, &fds);
FD_SET(s_master, &fds);
if (s_setmode_fd > 0) {
FD_SET(s_setmode_fd, &fds);
@@ -599,7 +626,7 @@
/* ¥â¡¼¥É¤òÊѹ¹¤¹¤ë */
if (s_setmode_fd > 0 && FD_ISSET(s_setmode_fd, &fds)) {
int start, end;
- if ((len = read(s_setmode_fd, buf, sizeof(buf))) <= 0) {
+ if ((len = read(s_setmode_fd, buf, sizeof(buf) - 1)) <= 0) {
debug2(("pipe closed\n"));
close(s_setmode_fd);
s_setmode_fd = open(s_path_setmode, O_RDONLY | O_NONBLOCK);
@@ -622,14 +649,14 @@
/* ¥¡¼¥Ü¡¼¥É(stdin)¤«¤é¤ÎÆþÎÏ */
- if (FD_ISSET(STDIN_FILENO, &fds)) {
+ if (FD_ISSET(g_win_in, &fds)) {
int i;
int key;
int key_state = 0;
int key_len;
int raw;
- if ((len = read_stdin(buf, sizeof(buf))) <= 0) {
+ if ((len = read_stdin(buf, sizeof(buf) - 1)) <= 0) {
/* ¤³¤³¤Ë¤Ï¤³¤Ê¤¤¤È»×¤¦ */
return;
}
@@ -656,11 +683,11 @@
} else if (s_timeout > 0) {
struct timeval t;
FD_ZERO(&fds);
- FD_SET(STDIN_FILENO, &fds);
+ FD_SET(g_win_in, &fds);
t.tv_sec = 0;
t.tv_usec = s_timeout;
if (my_select(nfd, &fds, &t) > 0) {
- len += read_stdin(buf + len, sizeof(buf) - len);
+ len += read_stdin(buf + len, sizeof(buf) - len - 1);
buf[len] = '\0';
debug(("read_again \"%s\"\n", buf));
i--;
@@ -691,41 +718,31 @@
/* input from pty (child process) */
if (FD_ISSET(s_master, &fds)) {
- char *str1;
- char *str2;
- if ((len = read(s_master, buf, sizeof(buf))) <= 0) {
+ if ((len = read(s_master, buf, sizeof(buf) - 1)) <= 0) {
/* »Ò¥×¥í¥»¥¹¤¬½ªÎ»¤·¤¿ */
return;
}
buf[len] = '\0';
- /* if (g_start_preedit) { */
- /* ¥×¥ê¥¨¥Ç¥£¥Ã¥ÈÊÔ½¸Ãæ */
- /* put_exit_standout_mode(); */
- /* put_exit_underline_mode(); */
- /* } */
-
/* ¥¯¥ê¥¢¤µ¤ì¤¿»þ¤Ë¥â¡¼¥É¤òºÆÉÁ²è¤¹¤ë */
if (s_status_type == LASTLINE) {
- str1 = rstrstr(buf, _clear_screen);
- str2 = rstrstr(buf, _clr_eos);
+ char *str1 = rstrstr_len(buf, _clear_screen, len);
+ char *str2 = rstrstr_len(buf, _clr_eos, len);
if (str1 != NULL || str2 != NULL) {
- char save_char;
+ int str1_len;
if (str2 > str1) {
str1 = str2;
}
+ str1_len = len - (str1 - buf);
/* str1¤Ïclear_screen¤«clr_eos¤Î¼¡¤Îʸ»úÎó¤ò»Ø¤·¤Æ¤¤¤ë */
- save_char = str1[0];
- str1[0] = '\0';
- put_pty_str(buf);
- str1[0] = save_char;
+ put_pty_str(buf, len - str1_len);
draw_statusline_force_restore();
- put_pty_str(str1);
+ put_pty_str(str1, str1_len);
} else {
- put_pty_str(buf);
+ put_pty_str(buf, len);
}
} else {
- put_pty_str(buf);
+ put_pty_str(buf, len);
}
}
}
@@ -742,14 +759,14 @@
while (TRUE) {
FD_ZERO(&fds);
- FD_SET(STDIN_FILENO, &fds);
+ FD_SET(g_win_in, &fds);
FD_SET(s_master, &fds);
if (select(s_master + 1, &fds, NULL, NULL, NULL) <= 0) {
/* signal¤Ç³ä¤ê¹þ¤Þ¤ì¤¿¤È¤¤Ë¤¯¤ë¡£select¤ÎÊÖ¤êÃͤÏ-1¤Çerrno==EINTR */
continue;
}
- if (FD_ISSET(STDIN_FILENO, &fds)) {
- if ((len = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {
+ if (FD_ISSET(g_win_in, &fds)) {
+ if ((len = read(g_win_in, buf, sizeof(buf))) <= 0) {
/* ¤³¤³¤Ë¤Ï¤³¤Ê¤¤¤È»×¤¦ */
return;
}
@@ -760,8 +777,7 @@
/* »Ò¥×¥í¥»¥¹¤¬½ªÎ»¤·¤¿ */
return;
}
- buf[len] = '\0';
- printf("%s", buf);
+ write(g_win_out, buf, len);
}
}
}
@@ -773,7 +789,7 @@
static struct winsize *get_winsize(void)
{
struct winsize *win = malloc(sizeof(struct winsize));
- ioctl(STDIN_FILENO, TIOCGWINSZ, win);
+ ioctl(g_win_in, TIOCGWINSZ, win);
if (s_status_type == LASTLINE) {
win->ws_row--;
}
@@ -860,7 +876,7 @@
if (s_status_type == BACKTICK) {
clear_backtick();
}
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &s_save_tios);
+ tcsetattr(g_win_in, TCSAFLUSH, &s_save_tios);
if (s_setmode_fd > 0) {
close(s_setmode_fd);
}
@@ -917,7 +933,8 @@
"-C [<foreground color>]:[<background color>]\n"
"-c reverse cursor\n"
"-i use cursor_invisible(civis)\n"
- "-o on the spot\n",
+ "-o on the spot\n"
+ "-S GNU screen mode\n",
getenv("SHELL") != NULL ? getenv("SHELL") : "/bin/sh",
"-h display this help\n"
"-v display version\n"
@@ -972,7 +989,7 @@
printf("uim-fep %s\n", PACKAGE_VERSION);
}
-#if DEBUG > 1
+#if defined(DEBUG) && DEBUG > 1
void _debug(const char *fmt, ...)
{
static FILE *log = NULL;
Modified: trunk/fep/uim-fep.h
===================================================================
--- trunk/fep/uim-fep.h 2005-02-11 12:02:43 UTC (rev 626)
+++ trunk/fep/uim-fep.h 2005-02-11 13:07:45 UTC (rev 627)
@@ -34,10 +34,10 @@
#ifndef UIM_FEP_H
#define UIM_FEP_H
-#if HAVE_SYS_IOCTL_H
+#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
-#if HAVE_TERMIOS_H
+#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
@@ -47,26 +47,38 @@
#define LASTLINE 3
#define BACKTICK 4
#define UNDEFINED -1729
+#define ESCAPE_CODE 27
+#define WIN_OUT_FILENO STDOUT_FILENO
+#define WIN_IN_FILENO STDOUT_FILENO
+#define PROC_FILENO STDIN_FILENO
+extern int g_win_in;
+extern int g_win_out;
extern struct winsize *g_win;
void done(int exit_value);
-#if DEBUG > 1
+#ifdef DEBUG
+
+#if DEBUG > 2
+#define debug2(arg) _debug arg
#define debug(arg) _debug arg
void _debug(const char *fmt, ...);
-#else
-#define debug(arg)
-#endif
-#if DEBUG > 2
-#define debug2(arg) _debug arg
+#elif DEBUG == 2
+#define debug2(arg)
+#define debug(arg) _debug arg
+
+void _debug(const char *fmt, ...);
#else
#define debug2(arg)
+#define debug(arg)
#endif
-#ifdef DEBUG
#define return_if_fail(arg) if (!(arg)) { printf("assertion failed %s %d", __FILE__, __LINE__); return; }
+
#else
+#define debug2(arg)
+#define debug(arg)
#define return_if_fail(arg) if (!(arg)) { return; }
#endif
More information about the Uim-commit
mailing list