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

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.4     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/math2ox.c,v 1.3 1999/11/04 17:53:04 ohara Exp $ */
1.1       ohara       3: /* $Id: math2ox.c,v 1.3 1999/10/13 07:38:23 ohara Exp $ */
                      4:
                      5: #include <sys/types.h>
                      6: #include <sys/stat.h>
                      7: #include <fcntl.h>
                      8:
                      9: #include <stdio.h>
                     10: #include <stdlib.h>
                     11: #include <mathlink.h>
                     12: #include <unistd.h>
                     13: #include <signal.h>
                     14:
                     15: #include "ox.h"
1.3       ohara      16: #include "parse.h"
1.1       ohara      17:
                     18: static char *host    = "localhost";
                     19: static char *ctlserv = "ox";
                     20: static char *oxprog  = "ox_sm1";
                     21:
                     22: ox_file_t sv;
                     23:
                     24: /* Mathematica から直接呼び出される関数の定義. */
                     25: /* 呼び出しの方法は math2ox.tm で定義される.   */
                     26: int OX_executeStringByLocalParser(const char *str)
                     27: {
                     28:     ox_executeStringByLocalParser(sv, str);
                     29:     return 0;
                     30: }
                     31:
                     32: char *OX_popString()
                     33: {
                     34:     return ox_popString(sv, sv->stream);
                     35: }
                     36:
                     37: int OX_close()
                     38: {
                     39:     ox_close(sv);
                     40:     return 0;
                     41: }
                     42:
                     43: int OX_reset()
                     44: {
                     45:     ox_reset(sv);
                     46:     return 0;
                     47: }
                     48:
1.3       ohara      49: /* 文字列 s を parse() にかけて生成された cmo を サーバに送る. */
                     50: /* s は "...\n" の形でなければならない(??). */
                     51: int OX_parse(char *s)
                     52: {
                     53:     cmo *m;
                     54:        int len = strlen(s);
                     55:     setmode_mygetc(s, len);
                     56:
                     57:     if(s != NULL && len > 0 && (m = parse()) != NULL) {
                     58:                /* 本来 m->tag のチェックをして CMO であることを
                     59:            確かめなければならない. */
                     60:                send_ox_cmo(sv->stream, m);
                     61:                return 0;
                     62:        }
                     63:        return -1; /* 失敗した場合 */
                     64: }
1.1       ohara      65:
                     66: int OX_start(char* s)
                     67: {
                     68:     if (s != NULL && s[0] != '\0') {
                     69:         oxprog = s;
                     70:     }
                     71:     sv = ox_start(host, ctlserv, oxprog);
                     72:     fprintf(stderr, "open (%s)\n", "localhost");
1.4     ! ohara      73:     return 0;
        !            74: }
        !            75:
        !            76: int OX_start_insecure(char *host, int portCtl, int portDat)
        !            77: {
        !            78:     if (host != NULL || host[0] == '\0') {
        !            79:         host = "localhost";
        !            80:     }
        !            81:        if (portCtl == 0) {
        !            82:                portCtl = 1200;
        !            83:        }
        !            84:        if (portDat == 0) {
        !            85:                portDat = 1300;
        !            86:        }
        !            87:
        !            88:        sv = ox_start_insecure_nonreverse(host, portCtl, portDat);
        !            89:     fprintf(stderr, "math2ox :: connect to \"%s\" with (ctl, dat) = (%d, %d)\n", host, portCtl, portDat);
1.1       ohara      90:     return 0;
                     91: }
                     92:
                     93: static char *cp_str(char *src)
                     94: {
                     95:     char *dest = malloc(strlen(src)+1);
                     96:     strcpy(dest, src);
                     97:     return dest;
                     98: }
                     99:
                    100: int OX_setClientParam(char *h, char* c, char* p)
                    101: {
                    102:     host    = cp_str(h);
                    103:     ctlserv = cp_str(c);
                    104:     oxprog  = cp_str(p);
                    105:     return 0;
                    106: }
                    107:
                    108: int main(int argc, char *argv[])
                    109: {
1.3       ohara     110:        /* 構文解析器の設定 */
                    111:        setflag_parse(PFLAG_ADDREV);
                    112:     setgetc(mygetc);
                    113:
1.1       ohara     114:     MLMain(argc, argv);
                    115: }

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