Mercurial > hg > RemoteEditor > emacs
changeset 66:d3088b01c363
*** empty log message ***
author | gongo |
---|---|
date | Fri, 12 Sep 2008 14:19:36 +0900 |
parents | dfa3a81d3cde |
children | 90e10010a4f3 |
files | ChangeLog line-merge.el redit_client.pl translate.el |
diffstat | 4 files changed, 10 insertions(+), 426 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Aug 29 23:28:24 2008 +0900 +++ b/ChangeLog Fri Sep 12 14:19:36 2008 +0900 @@ -1,3 +1,9 @@ +2008-09-12 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> + + * cvs-rm: line-merge.el translate.el redit_client.pl + 現在の ver には要らないので削除。 + 今後、参考として使うなら、以降の cvs-tag には残ってるのでそこから。 + 2008-08-29 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> * test: SessionManager GUI 版 @@ -36,13 +42,13 @@ 2008-08-28 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> - * tag v20080828-2 + * cvs-tag: v20080828-2 現在使ってない関数を抹殺したver いずれ必要になるとは思うが、今は見づらくなるので消去。 - 後ほど必要になったら、下の tag で取ってこればおk。 + 後ほど必要になったら、下の cvs-tag で取ってこればおk。 - * tag v20080828-1 + * cvs-tag: v20080828-1 現在使ってない関数をコメントで残しているver * redit-client-sm.el (redit-client-process-filter) @@ -757,7 +763,7 @@ editor側では select 要らないってことで。 これで、editor側で必要なのは join, put, quit, その他編集コマンド。 - * add: translate.el + * cvs-add: translate.el translate のテストルーチン。使い方は M-x load-file RET [translate.el]
--- a/line-merge.el Fri Aug 29 23:28:24 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -;; -;; USER -;; | i | r | d -;; ---|-------------------- -;;T i | 0\+1 | 0\+1 | 0\+1 -;;O ---|-------------------- -;;K r | +1\0 | 0\X | i\X -;;E ---|-------------------- -;;N d | +1\0 | X\i | X\X -;; -(defun dequeue-all (queue) - "clean queue" - (while (Queue-front queue) - (dequeue queue))) - -(defun redit-line-translate-out (cque rque) - "redit line translate for output" - (let ((cc) (rc) (xcc) (xrc) (ccc) (crc) (cignore 0) (rignore 0)) - (setq xcc 0) - (setq xrc 0) - (setq cignore 0) - (setq rignore 0) - (while cque - (setq cc (car cque)) - (while rque - (setq rc (car rque)) -;;-------- translation ------------ - - (if (< (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (- xrc 1))) - (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq xrc (- xrc 1)))) - - (if (> (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq xcc (- xcc 1)))) - - (if (= (+ (redit-get-line cc) xcc) (+ (redit-get-line rc) xrc)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command rc) (string-to-number redit-replace-command)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (+ xrc 1))) - (if (= (redit-get-command cc) (string-to-number redit-replace-command)) (setq cignore 1)) - (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq crc redit-write-command) (setq cignore 1)))) - - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (+ (redit-get-line rc) 1))) - (if (= (redit-get-command cc) (string-to-number redit-replace-command)) (setq cignore 1)) - (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq cignore 1) (setq rignore 1))) - -;;-------- translation ------------ - - (setq rque (cdr rque))) ;; while rque - - ;;ignore - (if (= cignore 1) - ;;xxx - (setq cignore 0)) - (if (= rignore 1) - ;;xxx - (setq cignore 0)) - -;;-------- add after que ------------ - (enqueue after-CQ (concat (format "%2d%2d%9d" (redit-get-command cc) (redit-get-uid cc) (+ (redit-get-line cc) xcc)) (redit-get-text cc))) -;;-------- add after que ------------ - - (setq cque (cdr cque))) ;; while cque - ) ;; let -) ;;defun - -(defun redit-line-translate-in (cque rque) - "redit line translate for input" - (let ((cc) (rc) (xcc) (xrc) (ccc) (crc) (cignore 0) (rignore 0)) - (setq xcc 0) - (setq xrc 0) - (setq cignore 0) - (setq rignore 0) - (while rque - (setq rc (car rque)) - (setq cignore 0) - (setq rignore 0) - (while cque - (setq cc (car cque)) -;;-------- translation ------------ - - (if (and (= cignore 1) (= rignore 1)) - (if (< (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq xcc (- xcc 1)))) - - (if (> (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xrc (- xrc 1))) - (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) (setq xrc (+ xrc 1)))) - - (if (= (+ (redit-get-line rc) xrc) (+ (redit-get-line cc) xcc)) - (if (= (redit-get-command cc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command cc) (string-to-number redit-replace-command)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ xcc 1))) - (if (= (redit-get-command rc) (string-to-number redit-replace-command)) (setq cignore 1)) - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq crc redit-write-command) (setq cignore 1)))) - (if (= (redit-get-command cc) (string-to-number redit-delete-line-command)) - (if (= (redit-get-command rc) (string-to-number redit-write-command)) (setq xcc (+ (redit-get-line cc) 1))) - (if (= (redit-get-command rc) (string-to-number redit-replace-command)) (setq crc redit-write-command) (setq cignore 1)) - (if (= (redit-get-command rc) (string-to-number redit-delete-line-command)) (setq cignore 1) (setq rignore 1)))) - -;;-------- translation ------------ - - (setq cque (cdr cque))) ;; while rque - - ;;ignore - (if (= cignore 1) - ;;xxx - (setq cignore 0)) - (if (= rignore 1) - ;;xxx - (setq rignore 0)) - -;;-------- add after que ------------ - (enqueue after-RQ (concat (format "%2d%2d%9d" (redit-get-command rc) (redit-get-uid rc) (+ (redit-get-line rc) xrc)) (redit-get-text rc))) -;;-------- add after que ------------ - - (setq rque (cdr rque))) ;; while cque - ) ;; let -) ;;defun
--- a/redit_client.pl Fri Aug 29 23:28:24 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -#!/usr/bin/perl -w - -#use strict; - -use IO::Select; -use IO::Socket; -use Encode; -use lib '/Users/gongo/src/cr/REP_project/session'; -use Rep; -use NKF; - -if ($ARGV[0] eq "") { - print "Usage: $0 SERVER_NAME\n"; - exit; -} - -# Rep.pm ˰ư -sub HEADER_TOKEN_SIZ {10}; -sub EMACS_HEADER_SIZ {60}; -sub HEADER_CMD_POS {0}; -sub HEADER_SID_POS {1}; -sub HEADER_EID_POS {2}; -sub HEADER_SEQNO_POS {3}; -sub HEADER_LINENO_POS {4}; -sub HEADER_TEXTSIZ_POS {5}; - -my $peer_addr = $ARGV[0]; -my $peer_port = "8765"; -my $TIMEOUT = 0; - -# connect to the session manager -$sock = new IO::Socket::INET(PeerAddr => $peer_addr, - PeerPort => $peer_port, - Proto => 'tcp') or die("Cannot open socket : $!\n"); - -my $myeid = ""; -my $mysid = ""; -my $ack; -my $packet; - -my $sm_selector = new IO::Select($sock) or die "Cannot select socket : $!\n"; -my $stdin_selector = new IO::Select(\*STDIN) or die "Cannot select stdin : $!\n"; - -while(1){ - # message from remote editor client (STDIN) - if ($stdin_selector->can_read($TIMEOUT)) { - my $buffer = <STDIN>; - # TODO : - my $packet = &make_packet_from_emacs($buffer); - $sock->write($packet,length($packet)); - &debug_msg("send message is : ||" . $buffer . "||\n"); - } - - # message from session manager - if ($sm_selector->can_read($TIMEOUT)) { - my $sm_message = &read_and_unpack($sock); - - if($sm_message->{'cmd'} == SMCMD_JOIN_ACK){ - $myeid = $sm_message->{'eid'}; - &debug_msg("myeid is : " . $myeid . "\n"); - } - - if($sm_message->{'cmd'} == SMCMD_PUT_ACK){ - $mysid = $sm_message->{'sid'}; - &debug_msg("mysid is : " . $mysid . "\n"); - } - - if ($sm_message->{'eid'} != $myeid - or $sm_message->{'cmd'} == SMCMD_JOIN_ACK - or $sm_message->{'cmd'} == SMCMD_PUT_ACK - or $sm_message->{'cmd'} == SMCMD_SELECT_ACK) { - - my $text = nkf("-eW", $sm_message->{'text'}); - # $text =~ s/\n//g; - # ХȿǤϤʤʸ - my $textsiz = length(decode('euc-jp', $text)); - - my $output = sprintf("%10d%10d%10d%10d%10d%10d" . - $text, - $sm_message->{'cmd'}, - $sm_message->{'sid'}, - $sm_message->{'eid'}, - $sm_message->{'seqno'}, - $sm_message->{'lineno'}, - $textsiz - ); - syswrite(STDOUT,$output,length($output)); - &debug_msg("recv messageleng: ||" . length($output) . "||\n"); - &debug_msg("recv message is : ||" . $output . "||\n"); - } else { - &debug_msg("chop cmd : " . $sm_message->{'cmd'} . "\n"); - &debug_msg("chop eid : " . $sm_message->{'eid'} . "\n"); - } - } - -} - -sub make_packet_from_emacs { - # FIXME - my $buffer = shift; - my $text = substr($buffer,&EMACS_HEADER_SIZ); - $text =~ s/\x92//g; - $text = nkf("-w", $text); - &debug_msg("text = " .$text. "\n"); - return &make_packet( - &get_header_token($buffer, HEADER_CMD_POS), - &get_header_token($buffer, HEADER_SID_POS), - &get_header_token($buffer, HEADER_EID_POS), - &get_header_token($buffer, HEADER_SEQNO_POS), - &get_header_token($buffer, HEADER_LINENO_POS), - #$substr($buffer,&EMACS_HEADER_SIZ) - $text - ); -} - -sub get_header_token { - my $buffer = shift; - my $pos = shift; - - return int(substr($buffer, &HEADER_TOKEN_SIZ * $pos, &HEADER_TOKEN_SIZ)); -} - -sub debug_msg { - my $msg = shift; - open(DEBUG,">> debug.txt"); - print DEBUG "eid $myeid : " . $msg; - close(DEBUG); -}
--- a/translate.el Fri Aug 29 23:28:24 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -(eval-when-compile (require 'cl)) - -(load-file "redit.el") - -(defstruct Queue (front nil) (rear nil)) - -(defvar lc-queue nil - "local command queue.") - -(defvar rc-queue nil - "remote command queue.") - -(defvar cmd-array nil - "") - -(setq lc-queue (make-Queue)) -(setq rc-queue (make-Queue)) - -;; i,r,d Ϥ뤿 -;; ᤦǤʤ -(setq cmd-array [6 9 13]) - -;; return 0 or 1 or 2 -;; cmd-array ǻȤޤ -(defun random3 () - (let (rd) - (setq rd (random)) - (setq rd (if (< rd 0) (* rd -1) rd )) - (setq rd (% rd 3)))) - -;; @param queue REPcommand queue -;; @param item REPcommand -(defun enqueue (queue item) - (let ((new-cell (list item))) - (if (Queue-front queue) - ;; ǽ - (setf (cdr (Queue-rear queue)) new-cell) - ;; 塼϶ξ - (setf (Queue-front queue) new-cell)) - (setf (Queue-rear queue) new-cell))) - -;; @param queue REPcommand queue -;; @return REPcommand -(defun dequeue (queue) - (if (Queue-front queue) - (prog1 - (pop (Queue-front queue)) - (unless (Queue-front queue) - ;; queue is empty - (setf (Queue-rear queue) nil))))) - -(defun redit-pack-int-loop (num count) - (if (> count 0) - (concat - (redit-pack-int-loop (/ num 256) (- count 1)) - (char-to-string (% num 256))))) - -(defun redit-pack-int (num) - (redit-pack-int-loop num 4)) - -(defun redit-pack (cmd sid eid seq lno siz) - (concat - (redit-pack-int cmd) (redit-pack-int sid) (redit-pack-int eid) - (redit-pack-int seq) (redit-pack-int lno) (redit-pack-int siz))) - -(defun unpack-int (pkt byte) - (let (num) - (setq num (* byte 4)) - (string-to-char (substring pkt (- num 1) num)))) - -;; @param rcmd REPcommand queue of Remote Host -;; @param lcmd REPcommand queue of Local Host -;; -;; by kent -;; -;; ӻ˹ֹ椬ŤʤäȤνϰʲɽ -;; ʤ٤ƥȤĤ褦ˤƤ롣 -;; 0 -- ʤˤ⤷ʤ -;; +1 -- ֹ +1 -;; INS -- ޥ id 'REPCMD_INSERT' ˤ롣 -;; NOP -- ޥɤNOP(⤷ʤ)ˤ롣 -;; ?* -- TOKENMaster̤äƤʤ -;; REMOTE -;; | i | r | d -;; ---|------------------ -;; U i | +1* | +1 | +1 -;; S ---|------------------ -;; E r | 0 | NOP*| NOP -;; R ---|------------------ -;; d | 0 | INS | NOP -;; -;; @exec Ͼɽ̤ message ǽϡ -;; -(defun translate (rcmd lcmd) - (let - ((rc (rep-get-command-from-pkt rcmd)) - (lc (rep-get-command-from-pkt lcmd)) - (rlno (rep-get-line-number-from-pkt rcmd)) - (llno (rep-get-line-number-from-pkt lcmd))) - - (if (= rlno llno) - ;;(progn - (cond ((= lc redit-insert-command) - ;; local REPcommand is insert - (cond ((= rc redit-insert-command) - ;; remote REPcommand is insert - (message "local=i, remote=i lineno++ *") - ) - ((= rc redit-replace-command) - ;; remote REPcommand is replace - (message "local=i, remote=r lineno++") - ) - ((= rc redit-delete-line-command) - ;; remote REPcommand is delete - (message "local=i, remote=d lineno++") - )) - ) - ((= lc redit-replace-command) - ;; local REPcommand is replace - (cond ((= rc redit-insert-command) - ;; remote REPcommand is insert - (message "local=r, remote=i 0") - ) - ((= rc redit-replace-command) - ;; remote REPcommand is replace - (message "local=r, remote=r cmd = NOP *") - ) - ((= rc redit-delete-line-command) - ;; remote REPcommand is delete - (message "local=r, remote=d cmd = NOP") - )) - ) - ((= lc redit-delete-line-command) - ;; local REPcommand is delete - (cond ((= rc redit-insert-command) - ;; remote REPcommand is insert - (message "local=d, remote=i 0") - ) - ((= rc redit-replace-command) - ;; remote REPcommand is replace - (message "local=d, remote=r cmd = insert") - ) - ((= rc redit-delete-line-command) - ;; remote REPcommand is delete - (message "local=d, remote=d cmd = nop") - )) - ) - )) - )) - -;; rcmd[0] <> lcmd[0] -;; rcmd[1] <> lcmd[1] -;; rcmd[2] <> lcmd[2] -;; .... -;; äƴǡqueue command translate ƥȥ롼 -(defun translate-test () - (interactive) - (let (num Rcmd Lcmd) - (setq num 0) - (while (< num 30) - (setq Rcmd (concat - (redit-pack - (aref cmd-array (random3)) 0 0 0 31 0))) - (setq Lcmd (concat - (redit-pack - (aref cmd-array (random3)) 0 0 0 31 0))) - (enqueue rc-queue Rcmd) - (enqueue lc-queue Lcmd) - (setq num (+ num 1))) - (while (> num 0) - (translate (dequeue rc-queue) (dequeue lc-queue)) - (setq num (- num 1))))) \ No newline at end of file