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

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

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

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