Mercurial > hg > RemoteEditor > vim7
changeset 26:7101f8c1fa21
*** empty log message ***
author | kono |
---|---|
date | Sun, 26 Oct 2008 21:45:13 +0900 |
parents | 2d27043cb96b |
children | a01d8d9b2a58 |
files | src/REPNOTE.txt src/reditor.c src/reditor.h |
diffstat | 3 files changed, 121 insertions(+), 168 deletions(-) [+] |
line wrap: on
line diff
--- a/src/REPNOTE.txt Sun Oct 26 17:39:37 2008 +0900 +++ b/src/REPNOTE.txt Sun Oct 26 21:45:13 2008 +0900 @@ -1,3 +1,8 @@ +Sun Oct 26 21:45:49 JST 2008 + +なんか、でたらめな感じ... そもそも、コマンドがちゃんと +読めてない? + Sun Sep 7 20:18:14 JST 2008 ml_replace
--- a/src/reditor.c Sun Oct 26 17:39:37 2008 +0900 +++ b/src/reditor.c Sun Oct 26 21:45:13 2008 +0900 @@ -45,6 +45,8 @@ static Session* find_session_by_buf(BUFTYPE *buf); static Session* find_session_by_name(char *name); static char* get_fullpath(Session *session); +static Session * get_waiting_session(int sid, char *text) ; +static void set_waiting_session(Session *session); static int writen(int fd, char *textbuf, unsigned int len); @@ -77,16 +79,13 @@ static int rep_exe_pkt(rep_cmd *command, char *pkt); static int rep_exe_pktlist(rep_cmdlist *cmdlist); -static int rep_recv_cmds(int fd, rep_cmdlist *smcmdlist,rep_cmdlist *txtcmdlist); +static int rep_recv_cmds(int fd, rep_cmdlist *txtcmdlist); static int rep_send_cmds(int fd, rep_cmdlist *cmdlist); static int rep_send_cmd( int fd, rep_cmd *cur); -static int append_newline_sep_text(Session *sn, char *text); /* g_rep has an all information of Remote Editor */ -rep_T g_rep; - - +static rep_T g_rep; /* * Wrapper for vim @@ -193,12 +192,10 @@ BUFTYPE *buf; // buf is curbuf long lnum; { -// return ml_get(lnum); return (char*)ml_get_buf(buf, lnum, FALSE); } /* 編集中のバッファの行の挿入 */ -/* "text" does NOT need to be allocated */ static int append_memline_wrp(lnum, text) long lnum; @@ -325,17 +322,18 @@ char def_hostname[] = "localhost"; // 現在編集対象のバッファはセッションに加える? - g_rep.shead = NULL; //make_session(); - g_rep.slineup = NULL; + g_rep.shead = NULL; g_rep.cursession = NULL; g_rep.servername = NULL; - g_rep.waiting_session_name = NULL; + g_rep.waiting_session = NULL; g_rep.smfd = -1; g_rep.eid = 0; g_rep.seqno = 0; + g_rep.prevSeq = 0; + g_rep.syncMode = 0; g_rep.permit = FALSE; @@ -433,6 +431,7 @@ sn->sid = 0; sn->permit = FALSE; sn->prevline = -1; + sn->del_cmd = 0; return sn; } @@ -501,6 +500,20 @@ return; } +static Session * +get_waiting_session(int sid, char *text) { + rep_T *rep = get_rep(); + Session *session = rep->waiting_session; + if (session==NULL) return session; + rep->waiting_session = session->next; + session->sid = sid; + if (text!=0) { + // set session name to the buffer + update_screen_now_wrp(); + } + return session; +} + static Session* set_cursession(sn) Session *sn; @@ -523,10 +536,6 @@ Session *cursn = NULL; rep_T *rep = get_rep(); - if (rep->slineup && rep->slineup->sid == id) { - return rep->slineup; - } - for (cursn = rep->shead; cursn; cursn = cursn->next) { if (cursn->sid == id) { return cursn; @@ -545,8 +554,6 @@ if (buf == NULL) return NULL; - if(rep->slineup->buf == buf) - return rep->slineup; for (cursn = rep->shead; cursn; cursn = cursn->next) { if (cursn->buf == buf) break; } @@ -576,11 +583,27 @@ return get_fullpath_wrp(buf); } +static Session * +append_session(Session *s1,Session *s2) +{ + Session *s3=s1; + if (s1==NULL) return s2; + while(s1->next) s1 = s1->next; + s1->next = s2; + return s3; +} + +static void +set_waiting_session(Session *session) +{ + rep_T *rep = get_rep(); + rep->waiting_session = append_session(rep->waiting_session,session); +} /* End Session */ -int -rep_join() +static int +rep_join_put(int cmd) { int sock; rep_T *rep; @@ -597,8 +620,18 @@ rep->smfd = sock; rep->permit = TRUE; + + /* get current buffer name */ + char *sname; + if ((sname = get_fullpath(rep->cursession)) == NULL) { + sname =NO_NAME; /* the buffer has not name */ + } + BUFTYPE *buf = get_curbuf_wrp(); + Session *session = make_session(sname,buf); + set_waiting_session(session); + - add_cmd_to_list(&cmdlist, make_cmd(SMCMD_JOIN, 0, rep->eid, rep->seqno++, 0, "")); + add_cmd_to_list(&cmdlist, make_cmd(cmd, 0, rep->eid, rep->seqno++, 0, "")); rep_send_cmds(sock, &cmdlist); free_cmdlist(&cmdlist); @@ -607,47 +640,17 @@ } +int rep_join() +{ + return rep_join_put(SMCMD_JOIN); +} + int rep_put() { - int sock; - rep_T *rep = get_rep(); - rep_cmdlist cmdlist = {NULL, 0}; - int len; - char *sname; - - if ((sock = rep_connect(NULL)) < 0) { - return FALSE; - } - if (rep->smfd > 0) { - close(rep->smfd); - } - - rep->smfd = sock; - rep->permit = TRUE; - - /* get current buffer name */ - if ((sname = get_fullpath(rep->cursession)) == NULL) { - sname = NO_NAME; /* the buffer has not name */ - } - - if (rep->waiting_session_name) { - rep_free(rep->waiting_session_name); - } - len = strlen(sname) +1; - rep->waiting_session_name = (char *)malloc(len); - memcpy(rep->waiting_session_name, sname, len); - - add_cmd_to_list(&cmdlist, make_cmd(SMCMD_PUT, 0, rep->eid, rep->seqno++, 0, sname)); - - rep_send_cmds(rep->smfd, &cmdlist); - - free_cmdlist(&cmdlist); - - return TRUE; + return rep_join_put(SMCMD_PUT); } - int rep_remove() { @@ -735,7 +738,7 @@ char *packet; unsigned int len = 0; - if (text) len = strlen(text);// + 1; /* for include '\0' */ + if (text) len = strlen(text); if ((packet = (char *)malloc(REP_HEADER_SIZE+len)) == NULL) { return(NULL); @@ -1064,38 +1067,15 @@ switch (cmd) { case SMCMD_JOIN_ACK: - /* show session lineup */ - if (rep->slineup) { - free_session(rep->slineup); - } - rep->slineup = make_session(SLINEUP_NAME, make_new_buf_wrp(SLINEUP_NAME)); - append_newline_sep_text(rep->slineup, text); - - rep->slineup->sid = sid; - set_cursession(rep->slineup); + session = get_waiting_session(sid,text); + set_cursession(session); rep_start_create_cmds(); - update_screen_now_wrp(); - rep->eid = eid; break; + case SMCMD_PUT_ACK: /* Enter Session */ - - if (text) { // text is error message. - e_msg_wrp(text); - return FALSE; - } - - /* Use wating_session_name for assign session id */ - if ((session = find_session_by_name(rep->waiting_session_name)) == NULL) { - if (rep->waiting_session_name) { - rep_free(rep->waiting_session_name); - rep->waiting_session_name = NULL; - } - return FALSE; - } - session->sid = sid; - + session = get_waiting_session(sid,text); /* set session to cursession */ set_cursession(session); rep_start_create_cmds(); @@ -1104,14 +1084,17 @@ append_memline_wrp(lnum, text); if (eid!=MERGE_EID) addNop(session, rep); forwardCommand(rep,command); + if (eid!=MERGE_EID) update_screen_now_wrp(); break; case REPCMD_DELETE: delete_memline_wrp(lnum); + if (eid!=MERGE_EID) update_screen_now_wrp(); case REPCMD_NOP: if (eid!=MERGE_EID) addNop(session, rep); forwardCommand(rep,command); break; case SMCMD_SYNC: + rep->syncMode = 1; break; case SMCMD_QUIT: forwardCommand(rep,command); @@ -1120,6 +1103,7 @@ break; case SMCMD_END_MERGE: rep->prevSeq = rep->seqno; + update_screen_now_wrp(); default: break; } @@ -1174,9 +1158,8 @@ static int -rep_recv_cmds(fd, smcmdlist, txtcmdlist) +rep_recv_cmds(fd, txtcmdlist) int fd; - rep_cmdlist *smcmdlist; rep_cmdlist *txtcmdlist; { unsigned int cmd; @@ -1220,12 +1203,7 @@ text[textsize] = 0; } - if (cmd == REPCMD_DELETE || - cmd == REPCMD_DELETE ) { - add_cmd_to_list(txtcmdlist, make_cmd(cmd, sid, eid, seq, lnum, text)); - } else { - add_cmd_to_list(smcmdlist, make_cmd(cmd, sid, eid, seq, lnum, text)); - } + add_cmd_to_list(txtcmdlist, make_cmd(cmd, sid, eid, seq, lnum, text)); return(TRUE); } @@ -1286,19 +1264,16 @@ fd_set *efds_p; // include a error fd { rep_T *rep_p; - rep_cmdlist smcmdlist = {NULL,0}; rep_cmdlist txtcmdlist = {NULL,0}; rep_p = get_rep(); if ((rep_p->smfd > 0) && (FD_ISSET(rep_p->smfd, rfds_p))) { - if (rep_recv_cmds(rep_p->smfd, &(smcmdlist), &(txtcmdlist)) == FALSE) { + if (rep_recv_cmds(rep_p->smfd, &(txtcmdlist)) == FALSE) { close(rep_p->smfd); rep_p->smfd = -1; } else { rep_exe_pktlist(&txtcmdlist); free_cmdlist(&(txtcmdlist)); - rep_exe_pktlist( &smcmdlist); - free_cmdlist(&(smcmdlist)); } } @@ -1331,7 +1306,14 @@ return(max_fds); } - +void +rep_close(int i) +{ + rep_T *rep_p; + + rep_p = get_rep(); + +} /* * read などで待つ場合に、この関数で REP 関連のデータをチェックする @@ -1351,45 +1333,45 @@ zerotime.tv_sec = 0; zerotime.tv_usec = 0; - if (fd < 0) return(FALSE); + if (fd < 0) return FALSE; + + /* select の中で modify されてるので、初期化 */ + tv.tv_sec = 0; + tv.tv_usec = 100000; + FD_ZERO(&rfds_p); + FD_ZERO(&efds_p); + + FD_SET(fd,&rfds_p); + + max_fds = rep_fd_set(&rfds_p, &efds_p, max_fds); - while (1) { - /* select の中で modify されてるので、初期化 */ - tv.tv_sec = 0; - tv.tv_usec = 100000; - FD_ZERO(&rfds_p); - FD_ZERO(&efds_p); + if ((sk = select(max_fds+1, &rfds_p, NULL, &efds_p, &tv)) < 0) { + if (errno == EBADF){ + int i; + for(i = 0;i < max_fds;i++){ + fd_set suspect; + FD_ZERO(&suspect); + if (FD_ISSET(i, &rfds_p)){ + FD_SET(i, &suspect); + if (select(max_fds, &suspect, NULL, NULL, &zerotime) == FAIL){ + FD_CLR(i, &rfds_p); + rep_close(i); + // we have to something to prevent to write to this + // port... + return(TRUE); + } + FD_CLR(i, &suspect); + } + } + } else { + e_msg_wrp("rep_select(): ERROR"); + return(FALSE); + } - FD_SET(fd,&rfds_p); - - max_fds = rep_fd_set(&rfds_p, &efds_p, max_fds); + } - if ((sk = select(max_fds+1, &rfds_p, NULL, &efds_p, &tv)) < 0) { - if (errno == EBADF){ - int i; - for(i = 0;i < max_fds;i++){ - fd_set suspect; - FD_ZERO(&suspect); - if (FD_ISSET(i, &rfds_p)){ - FD_SET(i, &suspect); - if (select(max_fds, &suspect, NULL, NULL, &zerotime) == FAIL){ - FD_CLR(i, &rfds_p); - // we have to something to prevent to write to this - // port... - return(TRUE); - } - FD_CLR(i, &suspect); - } - } - } else { - e_msg_wrp("rep_select(): ERROR"); - return(FALSE); - } - - } - - if (rep_fd_check(fd, &rfds_p, &efds_p)) return(TRUE); - } + if (rep_fd_check(fd, &rfds_p, &efds_p)) return TRUE; + return FALSE; } void @@ -1399,7 +1381,6 @@ rep_p = get_rep(); if (rep_p->shead) free_session_list(rep_p->shead); // cursession is freed - if (rep_p->slineup) free_session(rep_p->slineup); if (rep_p->servername) free_wrp(rep_p->servername); if (rep_p->smfd > 0) close(rep_p->smfd); @@ -1409,36 +1390,6 @@ } -/* append newline separated text to session buf */ -static int -append_newline_sep_text(sn, text) - Session *sn; - char *text; -{ - char *str; - char *cur; - Session *oldsn; - - /* - *"append_memline()" is available "curbuf" only - * thus, we must set buffer to "curbuf" - */ - oldsn = set_cursession(sn); - - for (str = cur = text; cur && *cur ; str = cur) { - cur = strchr(str, '\n'); - if (cur) { - *cur = '\0'; - cur++; - } - - append_memline_wrp(1, str); - } - - set_cursession(oldsn); - - return TRUE; -} extern void pcmd(cmd_p)
--- a/src/reditor.h Sun Oct 26 17:39:37 2008 +0900 +++ b/src/reditor.h Sun Oct 26 21:45:13 2008 +0900 @@ -59,7 +59,6 @@ #define REP_IGNORE 0 #define REP_AVAIL 1 -#define SLINEUP_NAME "SessionLineup" #define NO_NAME "NO_NAME" /* has not name like scratch */ #define SESSION_MAX 50 @@ -105,8 +104,6 @@ unsigned int sid; unsigned int smfd; - unsigned int rfd; - unsigned int sfd; char *sname; rep_cmdlist new_cmdlist; /* my REP command list */ @@ -121,18 +118,18 @@ typedef struct rep { Session *shead; // linked list of session - Session *slineup; // buffer of session lineup Session *cursession; BUFTYPE *scratch_buf; char *servername; - char *waiting_session_name; + Session *waiting_session; int eid; /* editor id */ int seqno; /* sequence number of REP command*/ int prevSeq; /* sequence number of last merged command */ + int syncMode; int smfd; /* socket connected to SessionManager */