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