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

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

1.1       ohara       1: /* -*- mode: C -*- */
1.9     ! ohara       2: /* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.8 2000/12/14 03:14:01 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.9     ! ohara      81:        int delay = 0;
        !            82:        char *delay_s = "0";
1.2       ohara      83:
1.9     ! ohara      84:     while ((c = getopt(argc, argv, "d:c:p:h:x")) != -1) {
1.1       ohara      85:         switch(c) {
                     86:         case 'h':
                     87:             remote_host = optarg;
                     88:             break;
                     89:         case 'c':
                     90:             password = optarg;
1.6       ohara      91:
1.1       ohara      92:             break;
                     93:         case 'p':
                     94:             port = atoi(optarg);
1.6       ohara      95:             port_s = optarg;
1.2       ohara      96:             break;
1.6       ohara      97:         case 'x':
                     98:             if (getenv("DISPLAY") != NULL) {
                     99:                 oxlog = 1;
                    100:             }
1.1       ohara     101:             break;
1.9     ! ohara     102:                case 'd':
        !           103:                        delay_s = optarg;
        !           104:                        delay = atoi(optarg);
        !           105:                        break;
1.1       ohara     106:         default:
                    107:         }
                    108:     }
                    109:     argc -= optind;
                    110:     argv += optind;
                    111:
1.5       ohara     112:     if (strlen(remote_host) == 0) {
1.6       ohara     113:         pipe_read_info(&remote_host, &port, &password);
                    114:         port_s = malloc(32);
                    115:         sprintf(port_s, "%d", port);
                    116:     }
                    117:     if (oxlog) {
1.9     ! ohara     118:         execlp(xterm, xterm, "-e", myname, "-d", delay_s,
1.8       ohara     119:                "-h", remote_host, "-p", port_s, "-c", password, NULL);
1.6       ohara     120:     }
1.5       ohara     121:
1.1       ohara     122:     fprintf(stderr, "start connection!\n");
1.9     ! ohara     123:        usleep(delay);
1.6       ohara     124:     if ((oxfp = connection()) == NULL) {
1.1       ohara     125:         fprintf(stderr, "oxc: cannot connect.\n");
                    126:     }else {
1.6       ohara     127:         fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd);
                    128:         mathcap_init(20001006, "v2000.10.06", "oxc", basic0, NULL);
                    129:         sm(oxfp);
                    130:     }
1.1       ohara     131:     return 0;
                    132: }

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