[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.5

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.5     ! ohara       2: /* $OpenXM: OpenXM/src/ox_math/sm_ext.c,v 1.4 2003/01/13 12:04:53 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 <mathlink.h>
                     18: #include <ox_toolkit.h>
                     19: #include "sm.h"
                     20:
1.2       ohara      21: static struct { int (*func_ptr)(); int key; } tbl_smcmd[] = {
                     22:     {sm_executeFunction, SM_executeFunction},
                     23:     {sm_executeStringByLocalParser, SM_executeStringByLocalParser},
                     24:     {sm_executeStringByLocalParser, SM_executeStringByLocalParserInBatchMode},
                     25:     {sm_mathcap,         SM_mathcap},
                     26:     {sm_set_mathcap,     SM_setMathCap},
                     27:     {sm_popString,       SM_popString},
                     28:     {sm_popCMO,          SM_popCMO},
                     29:     {sm_pops,            SM_pops},
                     30:        {shutdown,           SM_shutdown},
                     31:     {NULL, NULL}
                     32: };
                     33:
                     34: extern OXFILE *stack_oxfp;
                     35:
                     36: int (*sm_search_f(int code))()
                     37: {
                     38:     int i;
                     39:     for (i=0; tbl_smcmd[i].key != NULL; i++) {
                     40:         if (code == tbl_smcmd[i].key) {
                     41:             return tbl_smcmd[i].func_ptr;
                     42:         }
1.1       ohara      43:     }
1.2       ohara      44:     return NULL;
1.1       ohara      45: }
                     46:
                     47: /* MathLink dependent */
1.2       ohara      48: void sm_popString()
1.1       ohara      49: {
                     50:     char *s;
                     51:     cmo *err;
                     52:     cmo *m;
                     53:
1.4       ohara      54:     ox_printf("ox_math:: opecode = SM_popString.\n");
1.1       ohara      55:     m = pop();
                     56:     if (m->tag == CMO_STRING) {
1.2       ohara      57:         send_ox_cmo(stack_oxfp, m);
1.1       ohara      58:     }else if ((s = new_string_set_cmo(m)) != NULL) {
1.2       ohara      59:         send_ox_cmo(stack_oxfp, (cmo *)new_cmo_string(s));
1.1       ohara      60:     }else {
                     61:         err = make_error_object(SM_popString, m);
1.2       ohara      62:         send_ox_cmo(stack_oxfp, err);
1.1       ohara      63:     }
                     64: }
                     65:
                     66: int local_execute(char *s)
                     67: {
1.2       ohara      68:     extern int flag_mlo_symbol;
                     69:
1.1       ohara      70:     if(*s == 'i') {
                     71:         switch(s[1]) {
                     72:         case '+':
                     73:             flag_mlo_symbol = FLAG_MLTKSYM_IS_STRING;
                     74:             break;
                     75:         case '-':
                     76:         case '=':
                     77:         default:
                     78:             flag_mlo_symbol = FLAG_MLTKSYM_IS_INDETERMINATE;
                     79:         }
                     80:     }
                     81:     return 0;
                     82: }
                     83:
                     84: /* The following function is depend on an implementation of a server. */
1.2       ohara      85: void sm_executeStringByLocalParser()
1.1       ohara      86: {
                     87:     symbol_t symp;
                     88:     cmo* m = pop();
                     89:     char *s = NULL;
                     90:
1.4       ohara      91:     ox_printf("ox_math:: opecode = SM_executeStringByLocalParser.\n");
1.1       ohara      92:     if (m->tag == CMO_STRING
                     93:         && strlen(s = ((cmo_string *)m)->s) != 0) {
                     94:         if (s[0] == ':') {
                     95:             local_execute(++s);
                     96:         }else {
                     97:             /* for mathematica */
                     98:             /* Sending the string `s' to mathematica for its evaluation. */
                     99:             ml_evaluateStringByLocalParser(s);
1.5     ! ohara     100:             push(ml_returnvalue());
1.1       ohara     101:         }
1.2       ohara     102:     }else {
1.1       ohara     103: #ifdef DEBUG
1.2       ohara     104:                symp = lookup_by_tag(m->tag);
1.4       ohara     105:                ox_printf("ox_math:: error. the top of stack is %s.\n", symbol_get_key(symp));
1.1       ohara     106: #endif
1.2       ohara     107:                push_error(SM_executeStringByLocalParser, m);
                    108:        }
1.1       ohara     109: }
                    110:
1.2       ohara     111: void sm_executeFunction()
1.1       ohara     112: {
                    113:     int i, argc;
                    114:     cmo **argv;
                    115:     char* func;
                    116:     cmo* m;
                    117:
                    118:     if ((m = pop()) == NULL || m->tag != CMO_STRING) {
1.2       ohara     119:         push_error(SM_executeFunction, m);
1.1       ohara     120:     }
                    121:     func = ((cmo_string *)m)->s;
                    122:
                    123:     if ((m = pop()) == NULL || m->tag != CMO_INT32) {
1.2       ohara     124:         push_error(SM_executeFunction, m);
1.1       ohara     125:     }
                    126:
                    127:     argc = ((cmo_int32 *)m)->i;
                    128:     argv = malloc(argc*sizeof(cmo *));
                    129:     for (i=0; i<argc; i++) {
                    130:         argv[i] = pop();
                    131:     }
                    132:     ml_executeFunction(func, argc, argv);
1.5     ! ohara     133:     push(ml_returnvalue());
1.1       ohara     134: }
                    135:
1.2       ohara     136: void sm_mathcap()
1.1       ohara     137: {
1.2       ohara     138:     push((cmo *)oxf_cmo_mathcap(stack_oxfp));
1.1       ohara     139: }
                    140:
1.2       ohara     141: void sm_set_mathcap()
1.1       ohara     142: {
                    143:     cmo_mathcap *m = (cmo_mathcap *)pop();
                    144:     if (m->tag == CMO_MATHCAP) {
1.2       ohara     145:         oxf_mathcap_update(stack_oxfp, m);
1.1       ohara     146:     }else {
                    147:         push_error(-1, m);
                    148:         /* an error object must be pushed */
                    149:     }
                    150: }
                    151:

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