41
|
1 ;; send.pl のパス。
|
42
|
2 (defconst redit-test-client-program "/home/gongo/REP_project/emacs/test/packet/redit-test-packet-send.pl")
|
41
|
3
|
|
4 ;; プロセス変数
|
|
5 (defvar redit-test-client-process nil)
|
|
6
|
|
7
|
|
8 (defun redit-test-unpack-int-loop (pkt pos count)
|
|
9 (if (> count 1)
|
|
10 (+
|
|
11 (* (redit-test-unpack-int-loop pkt (- pos 1) (- count 1)) 256)
|
|
12 (string-to-char (substring pkt (- pos 1) pos)))
|
|
13 0
|
|
14 ))
|
|
15
|
|
16 (defun redit-test-unpack-int (pkt pos)
|
|
17 (redit-test-unpack-int-loop pkt (* pos 4) 4))
|
|
18
|
|
19 (defun rep-test-get-command-from-pkt (pkt)
|
|
20 (redit-test-unpack-int pkt 1))
|
|
21 (defun rep-test-get-session-id-from-pkt (pkt)
|
|
22 (redit-test-unpack-int pkt 2))
|
|
23 (defun rep-test-get-editor-id-from-pkt (pkt)
|
|
24 (redit-test-unpack-int pkt 3))
|
|
25 (defun rep-test-get-sequence-id-from-pkt (pkt)
|
|
26 (redit-test-unpack-int pkt 4))
|
|
27 (defun rep-test-get-line-number-from-pkt (pkt)
|
|
28 (redit-test-unpack-int pkt 5))
|
|
29 (defun rep-test-get-text-size-from-pkt (pkt)
|
|
30 (redit-test-unpack-int pkt 6))
|
|
31
|
|
32
|
|
33 ;; process (send.pl) を起動する。
|
|
34 ;; send.pl がパケットを送るトリガー(?)として
|
|
35 ;; 文字列を送信する(標準入力)。
|
|
36 (defun redit-test-start ()
|
|
37 (interactive)
|
|
38 (setq redit-test-client-process
|
|
39 (start-process "reditclient" nil redit-test-client-program))
|
|
40 (set-process-filter redit-test-client-process
|
|
41 'redit-test-client-process-filter)
|
|
42 (set-process-coding-system redit-test-client-process
|
|
43 'binary 'binary)
|
|
44
|
|
45 (process-send-string redit-test-client-process "a"))
|
|
46
|
|
47 ;; process を終了する。
|
|
48 (defun redit-test-stop ()
|
|
49 (interactive)
|
|
50 (if (not (eq (process-status redit-test-client-process) 'exit))
|
|
51 (kill-process redit-test-client-process)))
|
|
52
|
|
53 ;; process の restart。
|
|
54 (defun redit-test-restart ()
|
|
55 (interactive)
|
|
56 (redit-test-stop)
|
|
57 (redit-test-start))
|
|
58
|
|
59 ;; process からのパケットを受け取る。
|
|
60 ;; パケットは REPcommand。
|
|
61 ;; バイトデータと、unpack して取得した値を出力する
|
|
62 (defun redit-test-client-process-filter (proc string)
|
|
63 (let ((cmd (rep-test-get-command-from-pkt string))
|
|
64 (sid (rep-test-get-session-id-from-pkt string))
|
|
65 (eid (rep-test-get-editor-id-from-pkt string))
|
|
66 (seq (rep-test-get-sequence-id-from-pkt string))
|
|
67 (lno (rep-test-get-line-number-from-pkt string))
|
|
68 (siz (rep-test-get-text-size-from-pkt string)))
|
|
69
|
|
70 (message (concat string "\n"))
|
|
71 (message (concat (number-to-string cmd) " "
|
|
72 (number-to-string sid) " "
|
|
73 (number-to-string eid) " "
|
|
74 (number-to-string seq) " "
|
|
75 (number-to-string lno) " "
|
|
76 (number-to-string siz)
|
|
77 "\n"))
|
|
78 )) |