[BACK]Return to sm_ext.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_math

Annotation of OpenXM/src/ox_math/sm_ext.c, Revision 1.6

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.6     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/sm_ext.c,v 1.5 2003/01/15 05:08: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;
                     51:     cmo *m;
                     52:
1.4       ohara      53:     ox_printf("ox_math:: opecode = SM_popString.\n");
1.1       ohara      54:     m = pop();
                     55:     if (m->tag == CMO_STRING) {
1.2       ohara      56:         send_ox_cmo(stack_oxfp, m);
1.1       ohara      57:     }else if ((s = new_string_set_cmo(m)) != NULL) {
1.2       ohara      58:         send_ox_cmo(stack_oxfp, (cmo *)new_cmo_string(s));
1.1       ohara      59:     }else {
                     60:         err = make_error_object(SM_popString, m);
1.2       ohara      61:         send_ox_cmo(stack_oxfp, err);
1.1       ohara      62:     }
                     63: }
                     64:
                     65: int local_execute(char *s)
                     66: {
1.2       ohara      67:     extern int flag_mlo_symbol;
                     68:
1.1       ohara      69:     if(*s == 'i') {
                     70:         switch(s[1]) {
                     71:         case '+':
                     72:             flag_mlo_symbol = FLAG_MLTKSYM_IS_STRING;
                     73:             break;
                     74:         case '-':
                     75:         case '=':
                     76:         default:
                     77:             flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE;
                     78:         }
                     79:     }
                     80:     return 0;
                     81: }
                     82:
                     83: /* The following function is depend on an implementation of a server. */
1.2       ohara      84: void sm_executeStringByLocalParser()
1.1       ohara      85: {
                     86:     symbol_t symp;
                     87:     cmo* m = pop();
                     88:     char *s = NULL;
                     89:
1.4       ohara      90:     ox_printf("ox_math:: opecode = SM_executeStringByLocalParser.\n");
1.1       ohara      91:     if (m->tag == CMO_STRING
                     92:         && strlen(s = ((cmo_string *)m)->s) != 0) {
                     93:         if (s[0] == ':') {
                     94:             local_execute(++s);
                     95:         }else {
                     96:             /* for mathematica */
                     97:             /* Sending the string `s' to mathematica for its evaluation. */
                     98:             ml_evaluateStringByLocalParser(s);
1.6     ! ohara      99:             push(ml_return());
1.1       ohara     100:         }
1.2       ohara     101:     }else {
1.1       ohara     102: #ifdef DEBUG
1.2       ohara     103:                symp = lookup_by_tag(m->tag);
1.4       ohara     104:                ox_printf("ox_math:: error. the top of stack is %s.\n", symbol_get_key(symp));
1.1       ohara     105: #endif
1.2       ohara     106:                push_error(SM_executeStringByLocalParser, m);
                    107:        }
1.1       ohara     108: }
                    109:
1.2       ohara     110: void sm_executeFunction()
1.1       ohara     111: {
                    112:     int i, argc;
                    113:     cmo **argv;
                    114:     char* func;
                    115:     cmo* m;
                    116:
                    117:     if ((m = pop()) == NULL || m->tag != CMO_STRING) {
1.2       ohara     118:         push_error(SM_executeFunction, m);
1.1       ohara     119:     }
                    120:     func = ((cmo_string *)m)->s;
                    121:
                    122:     if ((m = pop()) == NULL || m->tag != CMO_INT32) {
1.2       ohara     123:         push_error(SM_executeFunction, m);
1.1       ohara     124:     }
                    125:
                    126:     argc = ((cmo_int32 *)m)->i;
                    127:     argv = malloc(argc*sizeof(cmo *));
                    128:     for (i=0; i<argc; i++) {
                    129:         argv[i] = pop();
                    130:     }
                    131:     ml_executeFunction(func, argc, argv);
1.6     ! ohara     132:     push(ml_return());
1.1       ohara     133: }
                    134:
1.2       ohara     135: void sm_mathcap()
1.1       ohara     136: {
1.2       ohara     137:     push((cmo *)oxf_cmo_mathcap(stack_oxfp));
1.1       ohara     138: }
                    139:
1.2       ohara     140: void sm_set_mathcap()
1.1       ohara     141: {
                    142:     cmo_mathcap *m = (cmo_mathcap *)pop();
                    143:     if (m->tag == CMO_MATHCAP) {
1.2       ohara     144:         oxf_mathcap_update(stack_oxfp, m);
1.1       ohara     145:     }else {
                    146:         push_error(-1, m);
                    147:         /* an error object must be pushed */
                    148:     }
                    149: }
                    150:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>