=================================================================== RCS file: /home/cvs/OpenXM/src/oxc/oxc.c,v retrieving revision 1.4 retrieving revision 1.8 diff -u -p -r1.4 -r1.8 --- OpenXM/src/oxc/oxc.c 2000/11/28 04:02:56 1.4 +++ OpenXM/src/oxc/oxc.c 2000/12/14 03:14:01 1.8 @@ -1,5 +1,5 @@ /* -*- mode: C -*- */ -/* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.3 2000/11/18 06:03:42 ohara Exp $ */ +/* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.7 2000/12/14 01:35:58 ohara Exp $ */ #include #include @@ -25,13 +25,12 @@ int oxf_connect_dup(char *remote, short port) int lf_oxc_open_main(char *cmd, short port) { - int pid = 0; - if (cmd != NULL && (pid = fork()) == 0) { + 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); } - fprintf(stderr, "oxc: cannnot oxc_open(%s, %d).\n", cmd, port); return pid; /* if error, pid == 0 */ } @@ -48,27 +47,36 @@ OXFILE *connection() /* xterm, kterm, rxvt, gnome-terminal, ... */ static char *xterminal() { - char *e = getenv("OpenXM_XTERM"); - return (e != NULL)? e: "xterm"; + char *e = getenv("OpenXM_XTERM"); + return (e != NULL)? e: "xterm"; } static int basic0[] = { - CMO_ERROR2, - CMO_NULL, - CMO_INT32, - CMO_DATUM, - CMO_STRING, - CMO_MATHCAP, - CMO_LIST, - 0}; + CMO_ERROR2, + CMO_NULL, + CMO_INT32, + CMO_DATUM, + CMO_STRING, + CMO_MATHCAP, + CMO_LIST, + 0 +}; +/* We assume that data has the following format: + LENGTH hostname '\0' port '\0' password '\0' + where LENGTH is an integer with network byte order and its value + equals to the sum of the length of three data above. +*/ + +void pipe_read_info(char **hostname, int *port, char **password); + int main(int argc, char *argv[]) { OXFILE *oxfp; - char *port_s = ""; - char *xterm = xterminal(); - char *myname = argv[0]; - int oxlog = 0; + char *port_s = ""; + char *xterm = xterminal(); + char *myname = argv[0]; + int oxlog = 0; int c; while ((c = getopt(argc, argv, "c:p:h:x")) != -1) { @@ -78,15 +86,16 @@ int main(int argc, char *argv[]) break; case 'c': password = optarg; + break; case 'p': port = atoi(optarg); - port_s = optarg; + port_s = optarg; break; - case 'x': - if (getenv("DISPLAY") != NULL) { - oxlog = 1; - } + case 'x': + if (getenv("DISPLAY") != NULL) { + oxlog = 1; + } break; default: } @@ -94,20 +103,24 @@ int main(int argc, char *argv[]) argc -= optind; argv += optind; - if (oxlog) { - execlp(xterm, xterm, "-e", myname, - "-h", remote_host, "-p", port_s, "-c", password); - } + if (strlen(remote_host) == 0) { + pipe_read_info(&remote_host, &port, &password); + port_s = malloc(32); + sprintf(port_s, "%d", port); + } + if (oxlog) { + execlp(xterm, xterm, "-e", myname, + "-h", remote_host, "-p", port_s, "-c", password, NULL); + fprintf(stderr, "oxc:: cannot exec \"%s oxc ...\"\n", xterm); + } + fprintf(stderr, "start connection!\n"); - if (strlen(remote_host) == 0 || strlen(password) == 0 || port == 0) { - fprintf(stderr, "oxc: invalid arguments.\n"); - fprintf(stderr, "usage: oxc -p port -h host -c password.\n"); - }else if ((oxfp = connection()) == NULL) { + if ((oxfp = connection()) == NULL) { fprintf(stderr, "oxc: cannot connect.\n"); }else { - fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd); - mathcap_init(20001006, "v2000.10.06", "oxc", basic0, NULL); - sm(oxfp); - } + fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd); + mathcap_init(20001006, "v2000.10.06", "oxc", basic0, NULL); + sm(oxfp); + } return 0; }