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

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

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