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

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

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

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