=================================================================== RCS file: /home/cvs/OpenXM/src/oxc/oxc.c,v retrieving revision 1.7 retrieving revision 1.15.2.1 diff -u -p -r1.7 -r1.15.2.1 --- OpenXM/src/oxc/oxc.c 2000/12/14 01:35:58 1.7 +++ OpenXM/src/oxc/oxc.c 2005/10/12 10:43:32 1.15.2.1 @@ -1,9 +1,10 @@ /* -*- mode: C -*- */ -/* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.6 2000/12/03 14:32:40 ohara Exp $ */ +/* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.15 2005/10/12 10:37:24 takayama Exp $ */ #include #include #include +#include #include #include "mysocket.h" #include "ox_toolkit.h" @@ -16,52 +17,116 @@ static char *password = ""; int oxf_connect_dup(char *remote, short port) { - int fd = mysocketOpen(remote, port); - /* Here do we need to confirm? */ - dup2(fd, 3); - dup2(fd, 4); /* is it necessary? maybe fd == 4. */ - return fd; + int fd = mysocketOpen(remote, port); + /* Here do we need to confirm? */ + dup2(fd, 3); + dup2(fd, 4); /* is it necessary? maybe fd == 4. */ + return fd; } int lf_oxc_open_main(char *cmd, short port) { - pid_t pid; - if ((pid = fork()) == 0) { - oxf_connect_dup(remote_host, port); - fprintf(stderr, "oxc: oxc_open(%s, %d)\n", cmd, port); - execlp(cmd, cmd, NULL); - } - return pid; /* if error, pid == 0 */ + pid_t pid; + if ((pid = fork()) == 0) { + oxf_connect_dup(remote_host, port); + ox_printf("oxc: oxc_open(%s, %d)\n", cmd, port); + execlp(cmd, cmd, NULL); + } + return pid; /* if error, pid == 0 */ } +#define MAX_RETRY 2000 + OXFILE *connection() { - OXFILE *oxfp = oxf_connect_active(remote_host, port); - if (oxfp != NULL) { - oxf_confirm_server(oxfp, password); - oxf_determine_byteorder_server(oxfp); + OXFILE *oxfp; + int counter = MAX_RETRY; + while((oxfp = oxf_connect_active(remote_host, port)) == NULL) { + if (--counter > 0) { + usleep(100); /* spends 100 micro seconds */ + }else { + ox_printf("oxc: cannot connect.\n"); + return NULL; } - return oxfp; + } + oxf_confirm_server(oxfp, password); + oxf_determine_byteorder_server(oxfp); + return oxfp; } -/* xterm, kterm, rxvt, gnome-terminal, ... */ -static char *xterminal() +__inline__ +static char *sskip(char *s) { - char *e = getenv("OpenXM_XTERM"); - return (e != NULL)? e: "xterm"; + while (isspace(*s)) { + s++; + } + return s; } -static int basic0[] = { - CMO_ERROR2, - CMO_NULL, - CMO_INT32, - CMO_DATUM, - CMO_STRING, - CMO_MATHCAP, - CMO_LIST, - 0 -}; +__inline__ +static char *wskip(char *s) +{ + while (!isspace(*s) && *s != '\0') { + s++; + } + return s; +} +static int wc(char *s) +{ + int n = 0; + s = sskip(s); + while(*s != '\0') { + s = wskip(s); + s = sskip(s); + n++; + } + return n; +} + +static void word(char *str, int argc, char *argv[]) +{ + int i; + char *s = strcpy(malloc(strlen(str)+1), str); + for(i=0; ifd); - mathcap_init(20001006, "v2000.10.06", "oxc", basic0, NULL); - sm(oxfp); - } - return 0; + if (strlen(remote_host) == 0) { + pipe_read_info(&remote_host, &port, &password); + port_s = malloc(32); + sprintf(port_s, "%d", port); + } + if (oxlog) { + char *common_args[] = {"-e", myname, "-d", delay_s, + "-h", remote_host, "-p", port_s, "-c", + password, NULL}; + char **args = makeargs(common_args); + execvp(args[0], args); + } + + ox_printf("start connection!\n"); + usleep(delay); + if ((oxfp = connection()) != NULL) { + ox_printf("oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd); + mathcap_init("v2000.10.06", "oxc"); + sm(oxfp); + } + return 0; }