Annotation of OpenXM/src/ox_math/sm_ext.c, Revision 1.7
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
1.7 ! ohara 2: /* $OpenXM: OpenXM/src/ox_math/sm_ext.c,v 1.6 2003/01/15 10:16:10 ohara Exp $ */
1.1 ohara 3:
4: /*
5: Copyright (C) Katsuyoshi OHARA, 2000.
6: Portions copyright 1999 Wolfram Research, Inc.
7:
8: You must see OpenXM/Copyright/Copyright.generic.
9: The MathLink Library is licensed from Wolfram Research Inc..
10: See OpenXM/Copyright/Copyright.mathlink for detail.
11: */
12:
13: #include <stdio.h>
14: #include <stdlib.h>
15: #include <unistd.h>
16: #include <gmp.h>
17: #include <ox_toolkit.h>
18: #include "sm.h"
19:
1.2 ohara 20: static struct { int (*func_ptr)(); int key; } tbl_smcmd[] = {
21: {sm_executeFunction, SM_executeFunction},
22: {sm_executeStringByLocalParser, SM_executeStringByLocalParser},
23: {sm_executeStringByLocalParser, SM_executeStringByLocalParserInBatchMode},
24: {sm_mathcap, SM_mathcap},
25: {sm_set_mathcap, SM_setMathCap},
26: {sm_popString, SM_popString},
27: {sm_popCMO, SM_popCMO},
28: {sm_pops, SM_pops},
29: {shutdown, SM_shutdown},
30: {NULL, NULL}
31: };
32:
33: extern OXFILE *stack_oxfp;
34:
35: int (*sm_search_f(int code))()
36: {
37: int i;
38: for (i=0; tbl_smcmd[i].key != NULL; i++) {
39: if (code == tbl_smcmd[i].key) {
40: return tbl_smcmd[i].func_ptr;
41: }
1.1 ohara 42: }
1.2 ohara 43: return NULL;
1.1 ohara 44: }
45:
46: /* MathLink dependent */
1.2 ohara 47: void sm_popString()
1.1 ohara 48: {
49: char *s;
50: cmo *err;
1.7 ! ohara 51: cmo *m = pop();
1.1 ohara 52: if (m->tag == CMO_STRING) {
1.2 ohara 53: send_ox_cmo(stack_oxfp, m);
1.1 ohara 54: }else if ((s = new_string_set_cmo(m)) != NULL) {
1.2 ohara 55: send_ox_cmo(stack_oxfp, (cmo *)new_cmo_string(s));
1.1 ohara 56: }else {
57: err = make_error_object(SM_popString, m);
1.2 ohara 58: send_ox_cmo(stack_oxfp, err);
1.1 ohara 59: }
60: }
61:
62: int local_execute(char *s)
63: {
1.2 ohara 64: extern int flag_mlo_symbol;
65:
1.1 ohara 66: if(*s == 'i') {
67: switch(s[1]) {
68: case '+':
69: flag_mlo_symbol = FLAG_MLTKSYM_IS_STRING;
70: break;
71: case '-':
72: case '=':
73: default:
74: flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE;
75: }
76: }
77: return 0;
78: }
79:
80: /* The following function is depend on an implementation of a server. */
1.2 ohara 81: void sm_executeStringByLocalParser()
1.1 ohara 82: {
83: cmo* m = pop();
84: char *s = NULL;
85: if (m->tag == CMO_STRING
86: && strlen(s = ((cmo_string *)m)->s) != 0) {
87: if (s[0] == ':') {
88: local_execute(++s);
89: }else {
90: /* for mathematica */
91: /* Sending the string `s' to mathematica for its evaluation. */
92: ml_evaluateStringByLocalParser(s);
1.7 ! ohara 93: m = ml_return();
! 94: push(m);
1.1 ohara 95: }
1.2 ohara 96: }else {
1.7 ! ohara 97: ox_printf(" <%s>", get_symbol_by_tag(m->tag));
1.2 ohara 98: push_error(SM_executeStringByLocalParser, m);
99: }
1.1 ohara 100: }
101:
1.2 ohara 102: void sm_executeFunction()
1.1 ohara 103: {
104: int i, argc;
105: cmo **argv;
106: char* func;
107: cmo* m;
108:
109: if ((m = pop()) == NULL || m->tag != CMO_STRING) {
1.2 ohara 110: push_error(SM_executeFunction, m);
1.1 ohara 111: }
112: func = ((cmo_string *)m)->s;
113:
114: if ((m = pop()) == NULL || m->tag != CMO_INT32) {
1.2 ohara 115: push_error(SM_executeFunction, m);
1.1 ohara 116: }
117:
118: argc = ((cmo_int32 *)m)->i;
119: argv = malloc(argc*sizeof(cmo *));
120: for (i=0; i<argc; i++) {
121: argv[i] = pop();
122: }
123: ml_executeFunction(func, argc, argv);
1.7 ! ohara 124: m = ml_return();
! 125: push(m);
1.1 ohara 126: }
127:
1.2 ohara 128: void sm_mathcap()
1.1 ohara 129: {
1.2 ohara 130: push((cmo *)oxf_cmo_mathcap(stack_oxfp));
1.1 ohara 131: }
132:
1.2 ohara 133: void sm_set_mathcap()
1.1 ohara 134: {
135: cmo_mathcap *m = (cmo_mathcap *)pop();
136: if (m->tag == CMO_MATHCAP) {
1.2 ohara 137: oxf_mathcap_update(stack_oxfp, m);
1.1 ohara 138: }else {
139: push_error(-1, m);
140: /* an error object must be pushed */
141: }
142: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>