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

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

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