[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.7

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.7     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/math2ox.c,v 1.6 1999/11/07 12:12:55 ohara Exp $ */
1.1       ohara       3:
                      4: #include <sys/types.h>
                      5: #include <sys/stat.h>
                      6: #include <fcntl.h>
                      7:
                      8: #include <stdio.h>
                      9: #include <stdlib.h>
                     10: #include <mathlink.h>
                     11: #include <unistd.h>
                     12: #include <signal.h>
1.7     ! ohara      13: #include <mathlink.h>
1.1       ohara      14:
                     15: #include "ox.h"
1.3       ohara      16: #include "parse.h"
1.7     ! ohara      17: #include "serv2.h"
1.1       ohara      18:
                     19: static char *host    = "localhost";
                     20: static char *ctlserv = "ox";
                     21: static char *oxprog  = "ox_sm1";
                     22:
                     23: ox_file_t sv;
1.7     ! ohara      24: MLINK lp;
1.1       ohara      25:
                     26: /* Mathematica から直接呼び出される関数の定義. */
                     27: /* 呼び出しの方法は math2ox.tm で定義される.   */
1.7     ! ohara      28: void OX_receive()
        !            29: {
        !            30:        cmo *c = NULL;
        !            31:
        !            32:        receive_ox_tag(sv->stream);
        !            33:        c = receive_cmo(sv->stream);
        !            34: #ifdef DEBUG
        !            35:        fprintf(stderr, "received ox in OxReceive[].\n");
        !            36:        print_cmo(c);
        !            37:        fflush(stderr);
        !            38: #endif
        !            39:        MATH_sendObject(c);
        !            40: }
        !            41:
1.1       ohara      42: int OX_executeStringByLocalParser(const char *str)
                     43: {
                     44:     ox_executeStringByLocalParser(sv, str);
                     45:     return 0;
                     46: }
                     47:
                     48: char *OX_popString()
                     49: {
                     50:     return ox_popString(sv, sv->stream);
                     51: }
                     52:
1.7     ! ohara      53: void OX_popCMO()
        !            54: {
        !            55:     cmo *c = ox_pop_cmo(sv, sv->stream);
        !            56:        MATH_sendObject(c);
        !            57: }
        !            58:
1.1       ohara      59: int OX_close()
                     60: {
                     61:     ox_close(sv);
                     62:     return 0;
                     63: }
                     64:
                     65: int OX_reset()
                     66: {
                     67:     ox_reset(sv);
                     68:     return 0;
                     69: }
                     70:
1.3       ohara      71: /* 文字列 s を parse() にかけて生成された cmo を サーバに送る. */
                     72: int OX_parse(char *s)
                     73: {
                     74:     cmo *m;
1.6       ohara      75:     symbol *symp;
                     76:     int len = strlen(s);
1.3       ohara      77:     setmode_mygetc(s, len);
                     78:
                     79:     if(s != NULL && len > 0 && (m = parse()) != NULL) {
1.6       ohara      80:         if (m->tag == OX_DATA) {
                     81:             send_ox_cmo(sv->stream, ((ox_data *)m)->cmo);
                     82:         }else if (m->tag == OX_COMMAND) {
                     83:             send_ox_command(sv->stream, ((ox_command *)m)->command);
                     84:         }else {
                     85:             send_ox_cmo(sv->stream, m);
                     86:         }
                     87:         return 0;
                     88:     }
                     89:     return -1; /* 失敗した場合 */
1.3       ohara      90: }
1.1       ohara      91:
                     92: int OX_start(char* s)
                     93: {
                     94:     if (s != NULL && s[0] != '\0') {
                     95:         oxprog = s;
                     96:     }
                     97:     sv = ox_start(host, ctlserv, oxprog);
                     98:     fprintf(stderr, "open (%s)\n", "localhost");
1.7     ! ohara      99:        lp = stdlink;
1.4       ohara     100:     return 0;
                    101: }
                    102:
                    103: int OX_start_insecure(char *host, int portCtl, int portDat)
                    104: {
                    105:     if (host != NULL || host[0] == '\0') {
                    106:         host = "localhost";
                    107:     }
1.6       ohara     108:     if (portCtl == 0) {
                    109:         portCtl = 1200;
                    110:     }
                    111:     if (portDat == 0) {
                    112:         portDat = 1300;
                    113:     }
                    114:
                    115:     sv = ox_start_insecure_nonreverse(host, portCtl, portDat);
1.4       ohara     116:     fprintf(stderr, "math2ox :: connect to \"%s\" with (ctl, dat) = (%d, %d)\n", host, portCtl, portDat);
1.7     ! ohara     117:
        !           118:        lp = stdlink;
        !           119:
1.1       ohara     120:     return 0;
                    121: }
                    122:
                    123: static char *cp_str(char *src)
                    124: {
                    125:     char *dest = malloc(strlen(src)+1);
                    126:     strcpy(dest, src);
                    127:     return dest;
                    128: }
                    129:
                    130: int OX_setClientParam(char *h, char* c, char* p)
                    131: {
                    132:     host    = cp_str(h);
                    133:     ctlserv = cp_str(c);
                    134:     oxprog  = cp_str(p);
                    135:     return 0;
                    136: }
                    137:
                    138: int main(int argc, char *argv[])
                    139: {
1.6       ohara     140:     /* 構文解析器の設定 */
                    141:     setflag_parse(PFLAG_ADDREV);
1.3       ohara     142:     setgetc(mygetc);
1.7     ! ohara     143:
1.1       ohara     144:     MLMain(argc, argv);
                    145: }

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