Author: yamamoto
Date: Fri Aug 12 22:03:26 2005
New Revision: 1193

Modified:
   trunk/fep/README.ja
   trunk/fep/uim-fep.c

Log:
 * fep/uim-fep.c (main) : same as r1174


Modified: trunk/fep/README.ja
==============================================================================
--- trunk/fep/README.ja (original)
+++ trunk/fep/README.ja Fri Aug 12 22:03:26 2005
@@ -170,8 +170,8 @@
     backtick���Ȥ����ޤ���
 
     UIM_FEP_SETMODE, UIM_FEP_GETMODE���ͤ�
-    $TMP/uim-fep-setmode-$STY-$WINDOW
-    $TMP/uim-fep-getmode-$STY-$WINDOW
+    $TMP/uim-fep-setmode-$STY-$WINDOW-screen
+    $TMP/uim-fep-getmode-$STY-$WINDOW-screen
     �ˤʤ��ޤ���
     ($TMP�����������Ƥ��ʤ�������/tmp���Ȥ�����)
 

Modified: trunk/fep/uim-fep.c
==============================================================================
--- trunk/fep/uim-fep.c (original)
+++ trunk/fep/uim-fep.c Fri Aug 12 22:03:26 2005
@@ -227,6 +227,7 @@
   const char *tmp_dir;
   const char *sty_str;
   const char *win_str;
+  struct stat stat_buf;
 
   int op;
 
@@ -378,19 +379,44 @@
     tmp_dir = "/tmp";
   }
 
-  if (gnu_screen && (sty_str = getenv("STY")) != NULL && (win_str = 
getenv("WINDOW")) != NULL) {
+  sty_str = getenv("STY");
+  win_str = getenv("WINDOW");
+  if (gnu_screen) {
+    if (!(sty_str != NULL && win_str != NULL)) {
+      puts("STY and WINDOW are not defined");
+      return EXIT_FAILURE;
+    }
     snprintf(s_path_getmode, sizeof(s_path_getmode), 
"%s/uim-fep-getmode-%s-%s", tmp_dir, sty_str, win_str);
     snprintf(s_path_setmode, sizeof(s_path_setmode), 
"%s/uim-fep-setmode-%s-%s", tmp_dir, sty_str, win_str);
+    if (stat(s_path_getmode, &stat_buf) == 0 || stat(s_path_setmode, 
&stat_buf) == 0) {
+      char msg[100];
+      init_sendsocket(sock_path);
+      snprintf(msg, 100, "uim-fep is already running on window %s", win_str);
+      sendline(msg);
+      return EXIT_FAILURE;
+    }
+    snprintf(s_path_getmode, sizeof(s_path_getmode), 
"%s/uim-fep-getmode-%s-%s-screen", tmp_dir, sty_str, win_str);
+    snprintf(s_path_setmode, sizeof(s_path_setmode), 
"%s/uim-fep-setmode-%s-%s-screen", tmp_dir, sty_str, win_str);
   } else {
-    struct stat stat_buf;
-    int file_suffix = 1;
-
-    snprintf(s_path_getmode, sizeof(s_path_getmode), "%s/uim-fep-getmode-%d", 
tmp_dir, getpid());
-    snprintf(s_path_setmode, sizeof(s_path_setmode), "%s/uim-fep-setmode-%d", 
tmp_dir, getpid());
-    while (stat(s_path_getmode, &stat_buf) == 0 && stat(s_path_setmode, 
&stat_buf) == 0) {
-      snprintf(s_path_getmode, sizeof(s_path_getmode), 
"%s/uim-fep-getmode-%d-%d", tmp_dir, getpid(), file_suffix);
-      snprintf(s_path_setmode, sizeof(s_path_setmode), 
"%s/uim-fep-setmode-%d-%d", tmp_dir, getpid(), file_suffix);
-      file_suffix++;
+    if (sty_str != NULL && win_str != NULL) {
+      snprintf(s_path_getmode, sizeof(s_path_getmode), 
"%s/uim-fep-getmode-%s-%s-screen", tmp_dir, sty_str, win_str);
+      snprintf(s_path_setmode, sizeof(s_path_setmode), 
"%s/uim-fep-setmode-%s-%s-screen", tmp_dir, sty_str, win_str);
+      if (stat(s_path_getmode, &stat_buf) == 0 || stat(s_path_setmode, 
&stat_buf) == 0) {
+        printf("uim-fep is already running on window %s as filter\n", win_str);
+        return EXIT_FAILURE;
+      }
+      snprintf(s_path_getmode, sizeof(s_path_getmode), 
"%s/uim-fep-getmode-%s-%s", tmp_dir, sty_str, win_str);
+      snprintf(s_path_setmode, sizeof(s_path_setmode), 
"%s/uim-fep-setmode-%s-%s", tmp_dir, sty_str, win_str);
+    } else {
+      int file_suffix = 1;
+
+      snprintf(s_path_getmode, sizeof(s_path_getmode), 
"%s/uim-fep-getmode-%d", tmp_dir, getpid());
+      snprintf(s_path_setmode, sizeof(s_path_setmode), 
"%s/uim-fep-setmode-%d", tmp_dir, getpid());
+      while (stat(s_path_getmode, &stat_buf) == 0 || stat(s_path_setmode, 
&stat_buf) == 0) {
+        snprintf(s_path_getmode, sizeof(s_path_getmode), 
"%s/uim-fep-getmode-%d-%d", tmp_dir, getpid(), file_suffix);
+        snprintf(s_path_setmode, sizeof(s_path_setmode), 
"%s/uim-fep-setmode-%d-%d", tmp_dir, getpid(), file_suffix);
+        file_suffix++;
+      }
     }
   }
 

Reply via email to