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