summaryrefslogtreecommitdiff
path: root/editors/tamago/files/patch-egg-wnn.el
blob: c6e7061711ecc89bccb6dd532ebaeee51e5e40f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
--- egg/wnn.el.orig	2015-01-31 19:24:09.000000000 +0900
+++ egg/wnn.el	2015-01-31 19:55:02.000000000 +0900
@@ -82,6 +82,10 @@
 			     (const wnn-uniq)
 			     (const wnn-uniq-kanji)))
 
+(defcustom egg-wnn-helper-path "egg-helper"
+  "path of wnn unix domain connection helper program"
+  :group 'wnn :type 'file)
+
 (defcustom wnn-jserver nil
   "jserver hostname list.  Use N-th port, if hostname is followed
 by ':' and digit N."
@@ -99,11 +103,21 @@
  by ':' and digit N."
   :group 'wnn :type '(repeat string))
 
+(setq wnn-jserverenv "JSERVER")
+(setq wnn-cserverenv "CSERVER")
+(setq wnn-tserverenv "TSERVER")
+(setq wnn-kserverenv "KSERVER")
+
 (defcustom wnn-jport 22273 "jserver port number" :group 'wnn :type 'integer)
 (defcustom wnn-cport 22289 "cserver port number" :group 'wnn :type 'integer)
 (defcustom wnn-tport 22321 "tserver port number" :group 'wnn :type 'integer)
 (defcustom wnn-kport 22305 "kserver port number" :group 'wnn :type 'integer)
 
+(defcustom wnn-judpath "/tmp/jd_sockV4" "jserver unix domain socket name" :group 'wnn :type 'string)
+(defcustom wnn-cudpath "/tmp/cd_sockV4" "cserver unix domain socket name" :group 'wnn :type 'string)
+(defcustom wnn-tudpath "/tmp/td_sockV4" "tserver unix domain socket name" :group 'wnn :type 'string)
+(defcustom wnn-kudpath "/tmp/kd_sockV4" "kserver unix domain socket name" :group 'wnn :type 'string)
+
 (defmacro wnn-backend-plist ()
   ''(egg-initialize-backend        wnn-init
      egg-start-conversion          wnn-start-conversion
@@ -559,11 +573,11 @@
 	  bunsetsu))
 
 (defvar wnn-server-info-list
-  ;; language    server  port      hostname    proc   coding-system
-  '((Japanese    jserver wnn-jport wnn-jserver "Wnn"  (fixed-euc-jp    fixed-euc-jp))
-    (Chinese-GB  cserver wnn-cport wnn-cserver "cWnn" (fixed-euc-py-cn fixed-euc-zy-cn))
-    (Chinese-CNS tserver wnn-tport wnn-tserver "tWnn" (fixed-euc-py-tw fixed-euc-zy-tw))
-    (Korean      kserver wnn-kport wnn-kserver "kWnn" (fixed-euc-kr    fixed-euc-kr))))
+  ;; language    server  port      hostname    unixdomain  serverenv      proc   coding-system
+  '((Japanese    jserver wnn-jport wnn-jserver wnn-judpath wnn-jserverenv "Wnn"  (fixed-euc-jp    fixed-euc-jp))
+    (Chinese-GB  cserver wnn-cport wnn-cserver wnn-cudpath wnn-cserverenv "cWnn" (fixed-euc-py-cn fixed-euc-zy-cn))
+    (Chinese-CNS tserver wnn-tport wnn-tserver wnn-tudpath wnn-tserverenv "tWnn" (fixed-euc-py-tw fixed-euc-zy-tw))
+    (Korean      kserver wnn-kport wnn-kserver wnn-kudpath wnn-kserverenv "kWnn" (fixed-euc-kr    fixed-euc-kr))))
 
 (defsubst wnn-server-get-info (lang)
   (or (assq lang wnn-server-info-list)
@@ -577,12 +591,16 @@
   (symbol-value (nth 2 info)))
 (defsubst wnn-server-hostname (info)
   (symbol-value (nth 3 info)))
+(defsubst wnn-server-udpath-name (info)
+  (symbol-value (nth 4 info)))
+(defsubst wnn-server-env-name (info)
+  (symbol-value (nth 5 info)))
 (defsubst wnn-server-proc-name (info)
-  (nth 4 info))
+  (nth 6 info))
 (defsubst wnn-server-buffer-name (info)
   (concat " *" (wnn-server-proc-name info) "*"))
 (defsubst wnn-server-coding-system (info)
-  (nth 5 info))
+  (nth 7 info))
 
 (defconst wnn-accept-charset-alist
   '((Chinese-CNS ascii chinese-sisheng chinese-cns11643-1 chinese-cns11643-2)))
@@ -1209,9 +1227,11 @@
 	(port (wnn-server-port server-info))
 	(hostname-list (wnn-server-hostname server-info))
 	(proc-name (wnn-server-proc-name server-info))
+	(udpath (wnn-server-udpath-name server-info))
+	(serverenv (wnn-server-env-name server-info))
 	(msg-form "Wnn: connecting to %S at %s...")
 	(user-name (user-login-name))
-	buf hostname myname port-off proc result msg)
+	buf hostname port-off proc result msg)
     (unwind-protect
 	(progn
 	  (setq buf (generate-new-buffer (wnn-server-buffer-name server-info)))
@@ -1225,13 +1245,24 @@
 	      (setq hostname-list (list hostname-list)))
 	  (while (and hostname-list (null proc))
 	    (setq hostname (or (car hostname-list) "")
-		  hostname-list (cdr hostname-list)
-		  myname (if (equal hostname "") "unix" wnn-system-name))
-	    (if (null (string-match ":" hostname))
-		(setq port-off 0)
-	      (setq port-off (string-to-int (substring hostname (match-end 0)))
-		    hostname (substring hostname 0 (match-beginning 0))))
-	    (and (equal hostname "") (setq hostname "localhost"))
+		hostname-list (cdr hostname-list))
+	    (if (or (and (getenv serverenv)
+			 (string-match "^unix$" (getenv serverenv)))
+		    (and (null (getenv serverenv))
+			 (or (equal hostname "")
+			     (string-match "^unix$" hostname))))
+		(progn
+		  (setq hostname "unix"
+			family 'local
+			port udpath))
+	       (progn
+		(setq hostname (or (getenv serverenv) hostname "localhost"))
+		(if (null (string-match ":" hostname))
+		    (setq port-off 0)
+		  (setq port-off (string-to-number (substring hostname (match-end 0)))
+			hostname (substring hostname 0 (match-beginning 0))))
+		(setq family nil)))
+	    (setq host hostname)
 	    (let ((inhibit-quit save-inhibit-quit))
 	      (if (and msg
 		       (null (y-or-n-p (format "%s failed. Try to %s? "
@@ -1241,16 +1272,22 @@
 			      server-type hostname))
 	    (message "%s" msg)
 	    (let ((inhibit-quit save-inhibit-quit))
-	      (condition-case nil
-		  (setq proc (open-network-stream proc-name buf hostname
-						  (+ port port-off)))
-		((error quit))))
-	    (when proc
-	      (process-kill-without-query proc)
+             (if (fboundp 'make-network-process)
+                 (condition-case nil
+                     (setq proc (make-network-process :name proc-name :buffer buf :host host :service port :family family))
+                   ((error quit)))
+               (if (string-match "^unix$" hostname)
+                   (let ((process-connection-type nil))
+                     (setq proc (start-process proc-name buf egg-wnn-helper-path port)))
+                 (condition-case nil
+                     (setq proc (open-network-stream proc-name buf hostname port))
+                   (error quit)))))
+           (when (processp proc)
+	      (set-process-query-on-exit-flag proc nil)
 	      (set-process-coding-system proc 'binary 'binary)
 	      (set-process-sentinel proc 'wnn-comm-sentinel)
 	      (set-marker-insertion-type (process-mark proc) t)
-	      (setq result (wnnrpc-open proc myname user-name))
+	      (setq result (wnnrpc-open proc host user-name))
 	      (when (numberp result)
 		(delete-process proc)
 		(setq proc nil))))