/* -*- mode: C -*- */ /* $OpenXM: OpenXM/src/ox_math/mlo.c,v 1.6 2000/03/10 12:38:46 ohara Exp $ */ /* Copyright (C) Katsuyoshi OHARA, 2000. Portions copyright 1999 Wolfram Research, Inc. You must see OpenXM/Copyright/Copyright.generic. The MathLink Library is licensed from Wolfram Research Inc.. See OpenXM/Copyright/Copyright.mathlink for detail. */ #include #include #include #include #include #include "mlo.h" #include "serv2.h" /* If this flag sets then we identify MLTKSYM to CMO_INDETERMINATE. */ int flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE; /* MLINK is a indentifier of MathLink connection. */ MLINK stdlink; mlo *receive_mlo_zz() { char *s; mlo *m; MLGetString(stdlink, &s); fprintf(stderr, "--debug: MLO == MLTKINT (%s).\n", s); m = (mlo *)new_cmo_zz_set_string(s); MLDisownString(stdlink, s); return m; } mlo *receive_mlo_string() { char *s; mlo *m; MLGetString(stdlink, &s); fprintf(stderr, "--debug: MLO == MLTKSTR (\"%s\").\n", s); m = (cmo *)new_cmo_string(s); MLDisownString(stdlink, s); return m; } cmo *receive_mlo_function() { char *s; cmo *m; cmo *ob; int i,n; MLGetFunction(stdlink, &s, &n); fprintf(stderr, "--debug: MLO == MLTKFUNC (%s[#%d]).\n", s, n); m = new_cmo_list(); append_cmo_list((cmo_list *)m, new_cmo_string(s)); for (i=0; itag == MLO_FUNCTION) { if (strcmp(((mlo_function *)m)->function, "List") == 0) { return convert_mlo_function_list_to_cmo_list(m); } } return m; } #endif mlo_function *new_mlo_function(char *function) { mlo_function *c = malloc(sizeof(mlo_function)); c->tag = MLO_FUNCTION; c->length = 0; c->head->next = NULL; c->function = function; return c; } cmo *receive_mlo_function_newer() { char *s; mlo_function *m; cmo *ob; int i,n; MLGetFunction(stdlink, &s, &n); #ifdef DEBUG fprintf(stderr, "--debug: MLO == MLTKFUNC, (%s[#%d])\n", s, n); #endif m = new_mlo_function(s); for (i=0; ii); } int send_mlo_string(cmo *m) { char *s = ((cmo_string *)m)->s; MLPutString(stdlink, s); } int send_mlo_zz(cmo *m) { char *s; MLPutFunction(stdlink, "ToExpression", 1); s = new_string_set_cmo(m); MLPutString(stdlink, s); } int send_mlo_list(cmo *c) { char *s; cell *cp = ((cmo_list *)c)->head; int len = length_cmo_list((cmo_list *)c); MLPutFunction(stdlink, "List", len); while(cp->next != NULL) { send_mlo(cp->cmo); cp = cp->next; } } int send_mlo(cmo *m) { char *s; switch(m->tag) { case CMO_INT32: send_mlo_int32(m); break; case CMO_ZERO: case CMO_NULL: send_mlo_int32(new_cmo_int32(0)); break; case CMO_STRING: send_mlo_string(m); break; case CMO_LIST: send_mlo_list(m); break; case CMO_MATHCAP: send_mlo(((cmo_mathcap *)m)->ob); break; case CMO_ZZ: send_mlo_zz(m); break; default: MLPutFunction(stdlink, "ToExpression", 1); s = new_string_set_cmo(m); MLPutString(stdlink, s); break; } } int ml_evaluateStringByLocalParser(char *str) { MLPutFunction(stdlink, "ToExpression", 1); MLPutString(stdlink, str); MLEndPacket(stdlink); } int ml_executeFunction(char *function, int argc, cmo *argv[]) { int i; MLPutFunction(stdlink, function, argc); for (i=0; i