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

Annotation of OpenXM/src/ox_math/math2ox.c, Revision 1.12

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.12    ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/math2ox.c,v 1.11 2000/01/20 15:32:21 ohara Exp $ */
1.11      ohara       3:
                      4: /*
1.12    ! ohara       5:    Copyright (C) Katsuyoshi OHARA, 2000.
        !             6:    Portions copyright 1999 Wolfram Research, Inc.
        !             7:
        !             8:    You must see OpenXM/Copyright/Copyright.generic.
        !             9:    The MathLink Library is licensed from Wolfram Research Inc..
        !            10:    See OpenXM/Copyright/Copyright.mathlink for detail.
1.11      ohara      11: */
1.1       ohara      12:
                     13: #include <sys/types.h>
                     14: #include <sys/stat.h>
                     15: #include <fcntl.h>
                     16:
                     17: #include <stdio.h>
                     18: #include <stdlib.h>
                     19: #include <mathlink.h>
                     20: #include <unistd.h>
                     21: #include <signal.h>
1.7       ohara      22: #include <mathlink.h>
1.1       ohara      23:
                     24: #include "ox.h"
1.3       ohara      25: #include "parse.h"
1.7       ohara      26: #include "serv2.h"
1.1       ohara      27:
                     28: static char *host    = "localhost";
                     29: static char *ctlserv = "ox";
                     30: static char *oxprog  = "ox_sm1";
                     31:
                     32: ox_file_t sv;
1.9       ohara      33: static ox_file_t *svs = NULL;
                     34: static int len_svs = 0;
                     35: static int max_process = 0;
1.1       ohara      36:
1.12    ! ohara      37: /* The following functions are called from Mathematica.
        !            38:    See math2.tm for detail. */
1.9       ohara      39: void OX_get()
1.7       ohara      40: {
1.8       ohara      41:     cmo *c = NULL;
1.7       ohara      42:
1.8       ohara      43:     receive_ox_tag(sv->stream);
                     44:     c = receive_cmo(sv->stream);
1.7       ohara      45: #ifdef DEBUG
1.9       ohara      46:     fprintf(stderr, "ox message is received in OxGet[].\n");
1.8       ohara      47:     print_cmo(c);
                     48:     fflush(stderr);
1.7       ohara      49: #endif
1.9       ohara      50:     send_mlo(c);
                     51:        ml_flush();
1.7       ohara      52: }
                     53:
1.9       ohara      54: int OX_execute_string(const char *str)
1.1       ohara      55: {
1.9       ohara      56:     ox_execute_string(sv, str);
1.1       ohara      57:     return 0;
                     58: }
                     59:
                     60: char *OX_popString()
                     61: {
1.9       ohara      62:     return ox_popString(sv);
1.1       ohara      63: }
                     64:
1.7       ohara      65: void OX_popCMO()
                     66: {
1.9       ohara      67:     cmo *c = ox_pop_cmo(sv);
                     68:     send_mlo(c);
                     69:        ml_flush();
1.7       ohara      70: }
                     71:
1.1       ohara      72: int OX_close()
                     73: {
                     74:     ox_close(sv);
                     75:     return 0;
                     76: }
                     77:
                     78: int OX_reset()
                     79: {
                     80:     ox_reset(sv);
                     81:     return 0;
                     82: }
                     83:
1.12    ! ohara      84: /* Parsing s and sending its cmo to an OX server. */
1.3       ohara      85: int OX_parse(char *s)
                     86: {
                     87:     cmo *m;
1.6       ohara      88:     symbol *symp;
                     89:     int len = strlen(s);
1.10      ohara      90:     init_parser(s);
1.3       ohara      91:
                     92:     if(s != NULL && len > 0 && (m = parse()) != NULL) {
1.6       ohara      93:         if (m->tag == OX_DATA) {
                     94:             send_ox_cmo(sv->stream, ((ox_data *)m)->cmo);
                     95:         }else if (m->tag == OX_COMMAND) {
                     96:             send_ox_command(sv->stream, ((ox_command *)m)->command);
                     97:         }else {
                     98:             send_ox_cmo(sv->stream, m);
                     99:         }
                    100:         return 0;
                    101:     }
1.12    ! ohara     102:     return -1; /* if we failed. */
1.3       ohara     103: }
1.1       ohara     104:
                    105: int OX_start(char* s)
                    106: {
                    107:     if (s != NULL && s[0] != '\0') {
                    108:         oxprog = s;
                    109:     }
1.9       ohara     110:        if (++max_process < len_svs) {
                    111:                sv = ox_start(host, ctlserv, oxprog);
                    112:                fprintf(stderr, "open (%s)\n", "localhost");
                    113:                svs[max_process] = sv;
                    114:                return max_process;
                    115:        }
                    116:        return -1;
1.11      ohara     117: }
                    118:
                    119: int OX_start_remote_ssh(char *s, char *host)
                    120: {
                    121:     if (s != NULL && s[0] != '\0') {
                    122:         oxprog = s;
                    123:     }
                    124:     if (host != NULL || host[0] == '\0') {
                    125:         host = "localhost";
                    126:     }
                    127:        if (++max_process < len_svs) {
                    128:                sv = ox_start_remote_with_ssh(oxprog, host);
                    129:                fprintf(stderr, "open (%s)\n", host);
                    130:                svs[max_process] = sv;
                    131:                return max_process;
                    132:        }
                    133:     return -1;
1.4       ohara     134: }
                    135:
                    136: int OX_start_insecure(char *host, int portCtl, int portDat)
                    137: {
                    138:     if (host != NULL || host[0] == '\0') {
                    139:         host = "localhost";
                    140:     }
1.6       ohara     141:     if (portCtl == 0) {
                    142:         portCtl = 1200;
                    143:     }
                    144:     if (portDat == 0) {
                    145:         portDat = 1300;
                    146:     }
                    147:
                    148:     sv = ox_start_insecure_nonreverse(host, portCtl, portDat);
1.4       ohara     149:     fprintf(stderr, "math2ox :: connect to \"%s\" with (ctl, dat) = (%d, %d)\n", host, portCtl, portDat);
1.7       ohara     150:
1.1       ohara     151:     return 0;
                    152: }
                    153:
                    154: static char *cp_str(char *src)
                    155: {
                    156:     char *dest = malloc(strlen(src)+1);
                    157:     strcpy(dest, src);
                    158:     return dest;
                    159: }
                    160:
                    161: int OX_setClientParam(char *h, char* c, char* p)
                    162: {
                    163:     host    = cp_str(h);
                    164:     ctlserv = cp_str(c);
                    165:     oxprog  = cp_str(p);
                    166:     return 0;
                    167: }
                    168:
                    169: int main(int argc, char *argv[])
                    170: {
1.12    ! ohara     171:     /* setting the OX parser */
1.6       ohara     172:     setflag_parse(PFLAG_ADDREV);
1.9       ohara     173:        len_svs = 20;
                    174:        svs = (ox_file_t *)malloc(sizeof(ox_file_t)*len_svs);
1.8       ohara     175:
1.1       ohara     176:     MLMain(argc, argv);
                    177: }

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