[uim-commit] r883 - trunk/fep
yamamoto at freedesktop.org
yamamoto at freedesktop.org
Tue Jun 14 21:52:17 PDT 2005
Author: yamamoto
Date: 2005-06-14 21:52:14 -0700 (Tue, 14 Jun 2005)
New Revision: 883
Modified:
trunk/fep/Makefile.am
trunk/fep/README.ja
trunk/fep/escseq.c
trunk/fep/escseq.h
trunk/fep/uim-fep.c
Log:
* fep/Makefile.am: add README.key
* fep/{uim-fep.c,escseq.c}:
Change behavior of redirection.
Add signal handlers of SIGTSTP and SIGCOUT.
Modified: trunk/fep/Makefile.am
===================================================================
--- trunk/fep/Makefile.am 2005-06-14 21:07:27 UTC (rev 882)
+++ trunk/fep/Makefile.am 2005-06-15 04:52:14 UTC (rev 883)
@@ -1,5 +1,5 @@
-EXTRA_DIST = README.ja
+EXTRA_DIST = README.ja README.key
if UIM_FEP
Modified: trunk/fep/README.ja
===================================================================
--- trunk/fep/README.ja 2005-06-14 21:07:27 UTC (rev 882)
+++ trunk/fep/README.ja 2005-06-15 04:52:14 UTC (rev 883)
@@ -147,7 +147,7 @@
·Ê¿§¤¬¤¢¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ò»È¤¦¤È±¦Ã¼¤ÎÇØ·Ê¿§¤¬¾Ã¤¨¤ë¤³¤È¤¬¤¢
¤ê¤Þ¤¹¡£
- o -S GNU screen¤Ç¥Õ¥£¥ë¥¿¤È¤·¤Æ»È¤¨¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
+ o -S GNU screen¤Ç¥Õ¥£¥ë¥¿¤È¤·¤Æ»È¤¨¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£(GNU screen 4.0.2°Ê¹ß)
Î㤨¤Ð¡¢~/.screenrc¤Ë
bind J exec | uim-fep -S
bind K eval 'exec cat' kill redisplay
@@ -224,6 +224,18 @@
o shift-backspace¤ÏÆþÎϤǤ¤Þ¤»¤ó¡£
+* ¥ê¥À¥¤¥ì¥¯¥È¤ÎÆ°ºî
+ ɸ½à½ÐÎϤΥê¥À¥¤¥ì¥¯¥È¤Ïuim-fep¤È»Ò¥×¥í¥»¥¹(¥·¥§¥ë)¤Î¤¹¤Ù¤Æ¤Î½ÐÎϤòÊѹ¹¤·¤Þ¤¹¡£
+
+ Îã: log¤Ë¤¹¤Ù¤Æ¤Î½ÐÎϤò½ñ¤¹þ¤à(script¥³¥Þ¥ó¥É¤ÈƱ¤¸)
+ $ uim-fep|tee log
+
+ ÆþÎϤΥê¥À¥¤¥ì¥¯¥È¤Ï»Ò¥×¥í¥»¥¹¤Îɸ½àÆþÎϤòÊѹ¹¤·¤Þ¤¹¡£
+
+ Îã: ls¤Î½ÐÎϤòw3m¤Ç¸«¤ë
+ $ ls|uim-fep -e w3m
+
+
* ÌäÂêÅÀ
o ¥×¥ê¥¨¥Ç¥£¥Ã¥ÈÊÔ½¸Ãæ¤ËüËö¤Î¥µ¥¤¥º¤¬Êѹ¹¤µ¤ì¤ë¤Èɽ¼¨¤¬Íð¤ì¤ë¤³¤È¤¬
¤¢¤ê¤Þ¤¹¡£
@@ -245,6 +257,9 @@
* ÍúÎò
+ o 2005/6/15
+ * ¥ê¥À¥¤¥ì¥¯¥È¤ÎÆ°ºî¤òÊѹ¹¤·¤Þ¤·¤¿¡£(¾å¤Î¡Ö¥ê¥À¥¤¥ì¥¯¥È¤ÎÆ°ºî¡×¤ò¸«¤Æ¤¯¤À¤µ¤¤)
+
o 2005/5/16
* -K¥ª¥×¥·¥ç¥ó¤òÄɲä·¤Þ¤·¤¿¡£
Modified: trunk/fep/escseq.c
===================================================================
--- trunk/fep/escseq.c 2005-06-14 21:07:27 UTC (rev 882)
+++ trunk/fep/escseq.c 2005-06-15 04:52:14 UTC (rev 883)
@@ -141,7 +141,6 @@
static void check_escseq(void);
static char *escseq2n(const char *escseq);
static void escseq2n2(const char *escseq, const char **first, const char **second);
-static void fixtty(void);
#ifndef HAVE_CFMAKERAW
static int cfmakeraw(struct termios *termios_p);
#endif
@@ -323,7 +322,7 @@
void quit_escseq(void)
{
- if (s_init == FALSE) {
+ if (!s_init) {
return;
}
put_exit_attribute_mode();
@@ -341,7 +340,7 @@
/*
* üËö¤òraw¥â¡¼¥É¤Ë¤¹¤ë
*/
-static void fixtty(void)
+void fixtty(void)
{
struct point_tag start_cursor;
struct point_tag cursor;
@@ -356,6 +355,12 @@
tios.c_cc[VTIME] = 3;
tcsetattr(g_win_in, TCSANOW, &tios);
+ if (s_init) {
+ s_cursor.row = s_cursor.col = UNDEFINED;
+ /* Á°²ó½ªÎ»»þ¤Î°ÌÃÖ¤ËÌá¤ë */
+ put_restore_cursor();
+ }
+
if (!g_opt.no_report_cursor) {
/* ³«»Ï°ÌÃÖ¤òÊݸ */
start_cursor = get_cursor_position();
@@ -383,23 +388,27 @@
if (g_opt.status_type == LASTLINE) {
write(g_win_out, "\n", strlen("\n"));
}
- s_cursor.row = s_cursor.col = UNDEFINED;
- /* °ÂÁ´¤Ê°ÌÃ֤˰ÜÆ° */
- put_cursor_address(1, 1);
- s_cursor.row = s_cursor.col = UNDEFINED;
- /* ¥«¡¼¥½¥ë°ÌÃÖ¤ò¼èÆÀ */
- cursor = get_cursor_position();
- s_cursor.row = s_cursor.col = UNDEFINED;
- /* ¼èÆÀ¤·¤¿¥«¡¼¥½¥ë°ÌÃ֤˰ÜÆ° */
- put_cursor_address_p(&cursor);
- s_cursor.row = s_cursor.col = UNDEFINED;
- /* Ʊ¤¸¥«¡¼¥½¥ë°ÌÃÖ¤¬ÆÀ¤é¤ì¤ë¤« */
- cursor2 = get_cursor_position();
- /* ÆÀ¤é¤ì¤Ê¤«¤Ã¤¿¤éº¹Ê¬¤òÄ´¤Ù¤ë */
- s_cursor_diff.row = cursor2.row - cursor.row;
- s_cursor_diff.col = cursor2.col - cursor.col;
- start_cursor.row -= s_cursor_diff.row;
- start_cursor.col -= s_cursor_diff.col;
+
+ if (!s_init) {
+ s_cursor.row = s_cursor.col = UNDEFINED;
+ /* °ÂÁ´¤Ê°ÌÃ֤˰ÜÆ° */
+ put_cursor_address(1, 1);
+ s_cursor.row = s_cursor.col = UNDEFINED;
+ /* ¥«¡¼¥½¥ë°ÌÃÖ¤ò¼èÆÀ */
+ cursor = get_cursor_position();
+ s_cursor.row = s_cursor.col = UNDEFINED;
+ /* ¼èÆÀ¤·¤¿¥«¡¼¥½¥ë°ÌÃ֤˰ÜÆ° */
+ put_cursor_address_p(&cursor);
+ s_cursor.row = s_cursor.col = UNDEFINED;
+ /* Ʊ¤¸¥«¡¼¥½¥ë°ÌÃÖ¤¬ÆÀ¤é¤ì¤ë¤« */
+ cursor2 = get_cursor_position();
+ /* ÆÀ¤é¤ì¤Ê¤«¤Ã¤¿¤éº¹Ê¬¤òÄ´¤Ù¤ë */
+ s_cursor_diff.row = cursor2.row - cursor.row;
+ s_cursor_diff.col = cursor2.col - cursor.col;
+ start_cursor.row -= s_cursor_diff.row;
+ start_cursor.col -= s_cursor_diff.col;
+ }
+
if (g_opt.status_type == LASTLINE) {
put_change_scroll_region(0, g_win->ws_row - 1);
}
Modified: trunk/fep/escseq.h
===================================================================
--- trunk/fep/escseq.h 2005-06-14 21:07:27 UTC (rev 882)
+++ trunk/fep/escseq.h 2005-06-15 04:52:14 UTC (rev 883)
@@ -51,6 +51,7 @@
void init_escseq(const struct attribute_tag *attr_uim);
void quit_escseq(void);
+void fixtty(void);
struct point_tag get_cursor_position(void);
void put_move_cur(int from, int to);
void put_cursor_left(int n);
Modified: trunk/fep/uim-fep.c
===================================================================
--- trunk/fep/uim-fep.c 2005-06-14 21:07:27 UTC (rev 882)
+++ trunk/fep/uim-fep.c 2005-06-15 04:52:14 UTC (rev 883)
@@ -149,14 +149,14 @@
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);
-#ifndef HAVE_FORKPTY
-static pid_t forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp);
-#endif
+static pid_t my_forkpty(int *amaster, struct termios *termp, struct winsize *winp);
static void main_loop(void);
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);
@@ -210,7 +210,6 @@
const char **command = malloc(sizeof(const char *) * (argc + 1));
const char *engine;
char *sock_path = NULL; /* Socket for backtick */
- pid_t child;
int gnu_screen = FALSE;
char *env_buf;
struct attribute_tag attr_uim = {
@@ -222,7 +221,6 @@
UNDEFINED /* background */
};
- tcflag_t save_iflag;
int op;
if (getenv("UIM_FEP_PID")) {
@@ -364,11 +362,7 @@
/* 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;
+ g_win_in = open("/dev/tty", O_RDONLY);
}
tcgetattr(g_win_in, &s_save_tios);
@@ -413,10 +407,7 @@
g_win = get_winsize();
if (!gnu_screen && !g_opt.print_key) {
- 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;
+ pid_t child = my_forkpty(&s_master, &s_save_tios, g_win);
if (child < 0) {
perror("fork");
@@ -555,11 +546,49 @@
return UNDEFINED;
}
-#ifndef HAVE_FORKPTY
-static pid_t forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp)
+#if defined(HAVE_FORKPTY)
+static pid_t my_forkpty(int *amaster, struct termios *termp, struct winsize *winp)
{
pid_t pid;
int slave;
+
+ tcflag_t save_iflag = termp->c_iflag;
+ termp->c_iflag &= ~ISTRIP;
+
+ if (openpty(amaster, &slave, NULL, termp, g_win) == -1) {
+ perror("openpty");
+ return -1;
+ }
+
+ termp->c_iflag = save_iflag;
+
+ if ((pid = fork()) < 0) {
+ return -2;
+ }
+ if (pid == 0) {
+ /* »Ò¥×¥í¥»¥¹ */
+ setsid();
+ /* man tty_ioctl */
+ ioctl(slave, TIOCSCTTY, 0);
+
+ close(*amaster);
+ if (g_win_in == STDIN_FILENO) {
+ dup2(slave, STDIN_FILENO);
+ }
+ dup2(slave, STDOUT_FILENO);
+ dup2(slave, STDERR_FILENO);
+ close(slave);
+ return 0;
+ } else {
+ close(slave);
+ return pid;
+ }
+}
+#elif defined(__svr4__)
+static pid_t my_forkpty(int *amaster, struct termios *termp, struct winsize *winp)
+{
+ pid_t pid;
+ int slave;
if ((*amaster = open("/dev/ptmx", O_RDWR)) < 0) {
return -1;
}
@@ -589,7 +618,9 @@
ioctl(slave, TIOCSWINSZ, winp);
}
close(*amaster);
- dup2(slave, STDIN_FILENO);
+ if (g_win_in == STDIN_FILENO) {
+ dup2(slave, STDIN_FILENO);
+ }
dup2(slave, STDOUT_FILENO);
dup2(slave, STDERR_FILENO);
close(slave);
@@ -872,6 +903,12 @@
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)
@@ -883,6 +920,35 @@
done(EXIT_SUCCESS);
}
+static void sigtstp_handler(int sig_no)
+{
+ struct sigaction act;
+ sigset_t mask;
+
+ quit_escseq();
+ put_save_cursor();
+ tcsetattr(g_win_in, TCSAFLUSH, &s_save_tios);
+
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ act.sa_handler = SIG_DFL;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGTSTP);
+ sigprocmask(SIG_UNBLOCK, &mask, NULL);
+
+ sigaction(SIGTSTP, &act, NULL);
+ kill(getpid(), SIGTSTP);
+
+ act.sa_handler = sigtstp_handler;
+ sigaction(SIGTSTP, &act, NULL);
+}
+
+static void sigcont_handler(int sig_no)
+{
+ fixtty();
+}
+
/*
* üËö¤Î¥µ¥¤¥º¤¬ÊѤï¤Ã¤¿¤È¤¤Ë²¾ÁÛüËö¤ÎÂ礤µ¤ò¹ç¤ï¤»¤ë¡£
*/
More information about the uim-commit
mailing list