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

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

1.1       ohara       1: /* -*- mode: C -*- */
1.10    ! ohara       2: /* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.9 2000/12/15 03:34:43 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:
1.10    ! ohara      37: #define MAX_RETRY  2000
        !            38:
1.1       ohara      39: OXFILE *connection()
                     40: {
1.10    ! ohara      41:     OXFILE *oxfp;
        !            42:     int counter = MAX_RETRY;
        !            43:     while((oxfp = oxf_connect_active(remote_host, port)) == NULL) {
        !            44:         if (--counter > 0) {
        !            45:             usleep(100); /* spends 100 micro seconds */
        !            46:         }else {
        !            47:             fprintf(stderr, "oxc: cannot connect.\n");
        !            48:             return NULL;
        !            49:         }
1.1       ohara      50:     }
1.10    ! ohara      51:     oxf_confirm_server(oxfp, password);
        !            52:     oxf_determine_byteorder_server(oxfp);
1.1       ohara      53:     return oxfp;
                     54: }
                     55:
1.2       ohara      56: /* xterm, kterm, rxvt, gnome-terminal, ... */
                     57: static char *xterminal()
                     58: {
1.6       ohara      59:     char *e = getenv("OpenXM_XTERM");
                     60:     return (e != NULL)? e: "xterm";
1.2       ohara      61: }
                     62:
1.4       ohara      63: static int basic0[] =  {
1.6       ohara      64:     CMO_ERROR2,
                     65:     CMO_NULL,
                     66:     CMO_INT32,
                     67:     CMO_DATUM,
                     68:     CMO_STRING,
                     69:     CMO_MATHCAP,
                     70:     CMO_LIST,
                     71:     0
1.5       ohara      72: };
                     73:
                     74: /* We assume that data has the following format:
                     75:    LENGTH hostname '\0' port '\0' password '\0'
                     76:    where LENGTH is an integer with network byte order and its value
                     77:    equals to the sum of the length of three data above.
                     78: */
                     79:
                     80: void pipe_read_info(char **hostname, int *port, char **password);
1.4       ohara      81:
1.1       ohara      82: int main(int argc, char *argv[])
                     83: {
                     84:     OXFILE *oxfp;
1.6       ohara      85:     char *port_s = "";
                     86:     char *xterm =  xterminal();
                     87:     char *myname = argv[0];
                     88:     int oxlog = 0;
1.1       ohara      89:     int c;
1.10    ! ohara      90:     int delay = 0;
        !            91:     char *delay_s = "0";
1.2       ohara      92:
1.9       ohara      93:     while ((c = getopt(argc, argv, "d:c:p:h:x")) != -1) {
1.1       ohara      94:         switch(c) {
                     95:         case 'h':
                     96:             remote_host = optarg;
                     97:             break;
                     98:         case 'c':
                     99:             password = optarg;
1.6       ohara     100:
1.1       ohara     101:             break;
                    102:         case 'p':
                    103:             port = atoi(optarg);
1.6       ohara     104:             port_s = optarg;
1.2       ohara     105:             break;
1.6       ohara     106:         case 'x':
                    107:             if (getenv("DISPLAY") != NULL) {
                    108:                 oxlog = 1;
                    109:             }
1.1       ohara     110:             break;
1.10    ! ohara     111:         case 'd':
        !           112:             delay_s = optarg;
        !           113:             delay = atoi(optarg);
        !           114:             break;
1.1       ohara     115:         default:
                    116:         }
                    117:     }
                    118:     argc -= optind;
                    119:     argv += optind;
                    120:
1.5       ohara     121:     if (strlen(remote_host) == 0) {
1.6       ohara     122:         pipe_read_info(&remote_host, &port, &password);
                    123:         port_s = malloc(32);
                    124:         sprintf(port_s, "%d", port);
                    125:     }
                    126:     if (oxlog) {
1.9       ohara     127:         execlp(xterm, xterm, "-e", myname, "-d", delay_s,
1.8       ohara     128:                "-h", remote_host, "-p", port_s, "-c", password, NULL);
1.6       ohara     129:     }
1.5       ohara     130:
1.1       ohara     131:     fprintf(stderr, "start connection!\n");
1.10    ! ohara     132:     usleep(delay);
        !           133:     if ((oxfp = connection()) != NULL) {
1.6       ohara     134:         fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd);
                    135:         mathcap_init(20001006, "v2000.10.06", "oxc", basic0, NULL);
                    136:         sm(oxfp);
                    137:     }
1.1       ohara     138:     return 0;
                    139: }

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