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

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

1.1       ohara       1: /* -*- mode: C -*- */
1.2     ! ohara       2: /* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.1 2000/10/13 06:05:12 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.1       ohara      55: int main(int argc, char *argv[])
                     56: {
                     57:     OXFILE *oxfp;
1.2     ! ohara      58:        char *port_s = "";
        !            59:        char *xterm =  xterminal();
        !            60:        char *myname = argv[0];
        !            61:        int oxlog = 0;
1.1       ohara      62:     int c;
1.2     ! ohara      63:
        !            64:     while ((c = getopt(argc, argv, "c:p:h:x")) != -1) {
1.1       ohara      65:         switch(c) {
                     66:         case 'h':
                     67:             remote_host = optarg;
                     68:             break;
                     69:         case 'c':
                     70:             password = optarg;
                     71:             break;
                     72:         case 'p':
                     73:             port = atoi(optarg);
1.2     ! ohara      74:                        port_s = optarg;
        !            75:             break;
        !            76:                case 'x':
        !            77:                        if (getenv("DISPLAY") != NULL) {
        !            78:                                oxlog = 1;
        !            79:                        }
1.1       ohara      80:             break;
                     81:         default:
                     82:         }
                     83:     }
                     84:     argc -= optind;
                     85:     argv += optind;
                     86:
1.2     ! ohara      87:        if (oxlog) {
        !            88:                execlp(xterm, xterm, "-e", myname,
        !            89:                           "-h", remote_host, "-p", port_s, "-c", password);
        !            90:        }
1.1       ohara      91:     fprintf(stderr, "start connection!\n");
                     92:     if (strlen(remote_host) == 0 || strlen(password) == 0 || port == 0) {
                     93:         fprintf(stderr, "oxc: invalid arguments.\n");
                     94:                fprintf(stderr, "usage: oxc -p port -h host -c password.\n");
                     95:     }else if ((oxfp = connection()) == NULL) {
                     96:         fprintf(stderr, "oxc: cannot connect.\n");
                     97:     }else {
                     98:                fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd);
                     99:                mathcap_sysinfo_set(20001006, "v2000.10.06", "oxc");
                    100:                sm(oxfp);
                    101:        }
                    102:     return 0;
                    103: }

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