version 1.7, 1999/11/07 12:12:56 |
version 1.9, 1999/11/19 20:51:36 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_math/serv2.c,v 1.6 1999/11/06 21:39:37 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_math/serv2.c,v 1.8 1999/11/18 21:56:44 ohara Exp $ */ |
|
|
/* Open Mathematica サーバ */ |
/* Open Mathematica サーバ */ |
/* ファイルディスクリプタ 3, 4 は open されていると仮定して動作する. */ |
/* ファイルディスクリプタ 3, 4 は open されていると仮定して動作する. */ |
|
|
#include "parse.h" |
#include "parse.h" |
#include "serv2.h" |
#include "serv2.h" |
|
|
|
#define FLAG_MLTKSYM_IS_INDETERMINATE 0 |
|
#define FLAG_MLTKSYM_IS_STRING 1 |
|
|
|
int flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE; |
|
|
#define ERROR_ID_UNKNOWN_SM 10 |
#define ERROR_ID_UNKNOWN_SM 10 |
#define ERROR_ID_FAILURE_MLINK 11 |
#define ERROR_ID_FAILURE_MLINK 11 |
|
|
Line 88 cmo *receive_mlo_symbol() |
|
Line 93 cmo *receive_mlo_symbol() |
|
cmo *ob; |
cmo *ob; |
char *s; |
char *s; |
|
|
fprintf(stderr, "--debug: MLO == MLTKSYM.\n"); |
fprintf(stderr, "--debug: MLO == MLTKSYM"); |
MLGetSymbol(lp, &s); |
MLGetSymbol(lp, &s); |
fprintf(stderr, "--debug: Symbol \"%s\".\n", s); |
fprintf(stderr, ": Symbol = \"%s\".\n", s); |
|
|
ob = new_cmo_indeterminate(new_cmo_string(s)); |
if(flag_mlo_symbol == FLAG_MLTKSYM_IS_INDETERMINATE) { |
|
ob = new_cmo_indeterminate(new_cmo_string(s)); |
|
}else { |
|
ob = new_cmo_string(s); |
|
} |
MLDisownString(lp, s); |
MLDisownString(lp, s); |
return ob; |
return ob; |
} |
} |
Line 168 int send_mlo_string(cmo *m) |
|
Line 176 int send_mlo_string(cmo *m) |
|
{ |
{ |
char *s = ((cmo_string *)m)->s; |
char *s = ((cmo_string *)m)->s; |
MLPutString(lp, s); |
MLPutString(lp, s); |
fprintf(stderr, "ox_math:: put %s.", s); |
|
} |
} |
|
|
int send_mlo_zz(cmo *m) |
int send_mlo_zz(cmo *m) |
Line 177 int send_mlo_zz(cmo *m) |
|
Line 184 int send_mlo_zz(cmo *m) |
|
MLPutFunction(lp, "ToExpression", 1); |
MLPutFunction(lp, "ToExpression", 1); |
s = convert_cmo_to_string(m); |
s = convert_cmo_to_string(m); |
MLPutString(lp, s); |
MLPutString(lp, s); |
fprintf(stderr, "put %s.", s); |
|
} |
} |
|
|
int send_mlo_list(cmo *c) |
int send_mlo_list(cmo *c) |
Line 186 int send_mlo_list(cmo *c) |
|
Line 192 int send_mlo_list(cmo *c) |
|
cell *cp = ((cmo_list *)c)->head; |
cell *cp = ((cmo_list *)c)->head; |
int len = length_cmo_list((cmo_list *)c); |
int len = length_cmo_list((cmo_list *)c); |
|
|
fprintf(stderr, "ox_math:: put List with %d args.\n", len); |
|
MLPutFunction(lp, "List", len); |
MLPutFunction(lp, "List", len); |
while(cp->next != NULL) { |
while(cp->next != NULL) { |
send_mlo(cp->cmo); |
send_mlo(cp->cmo); |
Line 207 int send_mlo(cmo *m) |
|
Line 212 int send_mlo(cmo *m) |
|
case CMO_INT32: |
case CMO_INT32: |
send_mlo_int32(m); |
send_mlo_int32(m); |
break; |
break; |
|
case CMO_ZERO: |
|
case CMO_NULL: |
|
send_mlo_int32(new_cmo_int32(0)); |
|
break; |
case CMO_STRING: |
case CMO_STRING: |
send_mlo_string(m); |
send_mlo_string(m); |
break; |
break; |
case CMO_LIST: |
case CMO_LIST: |
send_mlo_list(m); |
send_mlo_list(m); |
break; |
break; |
|
case CMO_MATHCAP: |
|
send_mlo(((cmo_mathcap *)m)->ob); |
|
break; |
|
case CMO_ZZ: |
|
send_mlo_zz(m); |
|
break; |
default: |
default: |
MLPutFunction(lp, "ToExpression", 1); |
MLPutFunction(lp, "ToExpression", 1); |
s = convert_cmo_to_string(m); |
s = convert_cmo_to_string(m); |
MLPutString(lp, s); |
MLPutString(lp, s); |
fprintf(stderr, "put %s.", s); |
|
break; |
break; |
} |
} |
} |
} |
Line 341 int sm_popString(int fd_write) |
|
Line 355 int sm_popString(int fd_write) |
|
|
|
int local_execute(char *s) |
int local_execute(char *s) |
{ |
{ |
|
if(*s == 'i') { |
|
switch(s[1]) { |
|
case '+': |
|
flag_mlo_symbol = FLAG_MLTKSYM_IS_STRING; |
|
break; |
|
case '-': |
|
case '=': |
|
default: |
|
flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE; |
|
} |
|
} |
return 0; |
return 0; |
} |
} |
|
|
Line 357 int sm_executeStringByLocalParser(int fd_write) |
|
Line 382 int sm_executeStringByLocalParser(int fd_write) |
|
if (m->tag == CMO_STRING |
if (m->tag == CMO_STRING |
&& strlen(s = ((cmo_string *)m)->s) != 0) { |
&& strlen(s = ((cmo_string *)m)->s) != 0) { |
if (s[0] == ':') { |
if (s[0] == ':') { |
local_execute(s); |
local_execute(++s); |
}else { |
}else { |
/* for mathematica */ |
/* for mathematica */ |
/* mathematica に文字列を送って評価させる */ |
/* mathematica に文字列を送って評価させる */ |
Line 420 int receive_sm_command(int fd_read) |
|
Line 445 int receive_sm_command(int fd_read) |
|
int execute_sm_command(int fd_write, int code) |
int execute_sm_command(int fd_write, int code) |
{ |
{ |
int err = 0; |
int err = 0; |
|
#ifdef DEBUG |
|
symbol *sp = lookup_by_tag(code); |
|
fprintf(stderr, "ox_math:: %s received.\n", sp->key); |
|
#endif |
|
|
switch(code) { |
switch(code) { |
case SM_popCMO: |
case SM_popCMO: |
Line 442 int execute_sm_command(int fd_write, int code) |
|
Line 471 int execute_sm_command(int fd_write, int code) |
|
break; |
break; |
case SM_setMathCap: |
case SM_setMathCap: |
pop(); /* 無視する */ |
pop(); /* 無視する */ |
|
break; |
|
case SM_shutdown: |
|
shutdown(); |
break; |
break; |
default: |
default: |
fprintf(stderr, "unknown command: %d.\n", code); |
fprintf(stderr, "unknown command: %d.\n", code); |