[BACK]Return to oxc.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / oxc

Annotation of OpenXM/src/oxc/oxc.c, Revision 1.7

1.1       ohara       1: /* -*- mode: C -*- */
1.7     ! ohara       2: /* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.6 2000/12/03 14:32:40 ohara Exp $ */
1.1       ohara       3:
                      4: #include <stdio.h>
                      5: #include <stdlib.h>
                      6: #include <unistd.h>
                      7: #include <string.h>
                      8: #include "mysocket.h"
                      9: #include "ox_toolkit.h"
                     10: #include "sm.h"
                     11:
                     12: /* oxc -c password -p port -h hostname */
                     13: static char *remote_host = "";
                     14: static short port = 0;
                     15: static char *password = "";
                     16:
                     17: int oxf_connect_dup(char *remote, short port)
                     18: {
                     19:     int fd = mysocketOpen(remote, port);
                     20:     /* Here do we need to confirm? */
                     21:     dup2(fd, 3);
                     22:     dup2(fd, 4); /* is it necessary? maybe fd == 4. */
                     23:     return fd;
                     24: }
                     25:
                     26: int lf_oxc_open_main(char *cmd, short port)
                     27: {
1.7     ! ohara      28:     pid_t pid;
        !            29:     if ((pid = fork()) == 0) {
1.1       ohara      30:         oxf_connect_dup(remote_host, port);
                     31:         fprintf(stderr, "oxc: oxc_open(%s, %d)\n", cmd, port);
                     32:         execlp(cmd, cmd, NULL);
                     33:     }
                     34:     return pid; /* if error, pid == 0 */
                     35: }
                     36:
                     37: OXFILE *connection()
                     38: {
                     39:     OXFILE *oxfp = oxf_connect_active(remote_host, port);
                     40:     if (oxfp != NULL) {
                     41:         oxf_confirm_server(oxfp, password);
                     42:         oxf_determine_byteorder_server(oxfp);
                     43:     }
                     44:     return oxfp;
                     45: }
                     46:
1.2       ohara      47: /* xterm, kterm, rxvt, gnome-terminal, ... */
                     48: static char *xterminal()
                     49: {
1.6       ohara      50:     char *e = getenv("OpenXM_XTERM");
                     51:     return (e != NULL)? e: "xterm";
1.2       ohara      52: }
                     53:
1.4       ohara      54: static int basic0[] =  {
1.6       ohara      55:     CMO_ERROR2,
                     56:     CMO_NULL,
                     57:     CMO_INT32,
                     58:     CMO_DATUM,
                     59:     CMO_STRING,
                     60:     CMO_MATHCAP,
                     61:     CMO_LIST,
                     62:     0
1.5       ohara      63: };
                     64:
                     65: /* We assume that data has the following format:
                     66:    LENGTH hostname '\0' port '\0' password '\0'
                     67:    where LENGTH is an integer with network byte order and its value
                     68:    equals to the sum of the length of three data above.
                     69: */
                     70:
                     71: void pipe_read_info(char **hostname, int *port, char **password);
1.4       ohara      72:
1.1       ohara      73: int main(int argc, char *argv[])
                     74: {
                     75:     OXFILE *oxfp;
1.6       ohara      76:     char *port_s = "";
                     77:     char *xterm =  xterminal();
                     78:     char *myname = argv[0];
                     79:     int oxlog = 0;
1.1       ohara      80:     int c;
1.2       ohara      81:
                     82:     while ((c = getopt(argc, argv, "c:p:h:x")) != -1) {
1.1       ohara      83:         switch(c) {
                     84:         case 'h':
                     85:             remote_host = optarg;
                     86:             break;
                     87:         case 'c':
                     88:             password = optarg;
1.6       ohara      89:
1.1       ohara      90:             break;
                     91:         case 'p':
                     92:             port = atoi(optarg);
1.6       ohara      93:             port_s = optarg;
1.2       ohara      94:             break;
1.6       ohara      95:         case 'x':
                     96:             if (getenv("DISPLAY") != NULL) {
                     97:                 oxlog = 1;
                     98:             }
1.1       ohara      99:             break;
                    100:         default:
                    101:         }
                    102:     }
                    103:     argc -= optind;
                    104:     argv += optind;
                    105:
1.5       ohara     106:     if (strlen(remote_host) == 0) {
1.6       ohara     107:         pipe_read_info(&remote_host, &port, &password);
                    108:         port_s = malloc(32);
                    109:         sprintf(port_s, "%d", port);
                    110:     }
                    111:     if (oxlog) {
                    112:         execlp(xterm, xterm, "-e", myname,
                    113:                "-h", remote_host, "-p", port_s, "-c", password);
                    114:     }
1.5       ohara     115:
1.1       ohara     116:     fprintf(stderr, "start connection!\n");
1.6       ohara     117:     if ((oxfp = connection()) == NULL) {
1.1       ohara     118:         fprintf(stderr, "oxc: cannot connect.\n");
                    119:     }else {
1.6       ohara     120:         fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd);
                    121:         mathcap_init(20001006, "v2000.10.06", "oxc", basic0, NULL);
                    122:         sm(oxfp);
                    123:     }
1.1       ohara     124:     return 0;
                    125: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>