version 1.16, 2000/10/10 19:58:30 |
version 1.18, 2000/12/03 15:19:23 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_math/serv2.c,v 1.15 2000/03/10 12:45:48 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_math/serv2.c,v 1.17 2000/11/28 20:16:03 ohara Exp $ */ |
|
|
/* |
/* |
Copyright (C) Katsuyoshi OHARA, 2000. |
Copyright (C) Katsuyoshi OHARA, 2000. |
|
|
extern int flag_mlo_symbol; |
extern int flag_mlo_symbol; |
|
|
/* MathLink independent */ |
/* MathLink independent */ |
#define INIT_S_SIZE 2048 |
|
#define EXT_S_SIZE 2048 |
|
|
|
static int stack_size = 0; |
|
static int stack_pointer = 0; |
|
static cmo **stack = NULL; |
static cmo **stack = NULL; |
|
static int stack_size = 0; |
|
static int stack_ptr = 0; |
|
OXFILE *stack_oxfp = NULL; |
|
|
int initialize_stack() |
#define DIFFERENCE_OF_STACK 1024 |
{ |
|
stack_pointer = 0; |
|
stack_size = INIT_S_SIZE; |
|
stack = malloc(stack_size*sizeof(cmo*)); |
|
} |
|
|
|
static int extend_stack() |
static void stack_extend() |
{ |
{ |
int size2 = stack_size + EXT_S_SIZE; |
int newsize = stack_size + DIFFERENCE_OF_STACK; |
cmo **stack2 = malloc(size2*sizeof(cmo*)); |
cmo **newstack = (cmo **)malloc(sizeof(cmo *)*newsize); |
memcpy(stack2, stack, stack_size*sizeof(cmo *)); |
if (stack != NULL) { |
free(stack); |
memcpy(newstack, stack, sizeof(cmo *)*stack_size); |
stack = stack2; |
free(stack); |
stack_size = size2; |
} |
|
stack_size = newsize; |
|
stack = newstack; |
} |
} |
|
|
int push(cmo* m) |
int push(cmo* m) |
|
|
fprintf(stderr, "ox_math:: a %s was pushed.\n", symbol_get_key(symp)); |
fprintf(stderr, "ox_math:: a %s was pushed.\n", symbol_get_key(symp)); |
} |
} |
#endif |
#endif |
stack[stack_pointer] = m; |
if (stack_ptr >= stack_size) { |
stack_pointer++; |
stack_extend(); |
if (stack_pointer >= stack_size) { |
|
extend_stack(); |
|
} |
} |
|
stack[stack_ptr] = m; |
|
stack_ptr++; |
} |
} |
|
|
/* if the stack is empty, then pop() returns (CMO_NULL). */ |
/* if the stack is empty, then pop() returns (CMO_NULL). */ |
cmo* pop() |
cmo* pop() |
{ |
{ |
if (stack_pointer > 0) { |
if (stack_ptr > 0) { |
stack_pointer--; |
return stack[--stack_ptr]; |
return stack[stack_pointer]; |
|
} |
} |
return new_cmo_null(); |
return new_cmo_null(); |
} |
} |
|
|
void pops(int n) |
void pops(int n) |
{ |
{ |
stack_pointer -= n; |
stack_ptr -= n; |
if (stack_pointer < 0) { |
if (stack_ptr < 0) { |
stack_pointer = 0; |
stack_ptr = 0; |
} |
} |
} |
} |
|
|
|
void push_error(int errcode, cmo* pushback) |
|
{ |
|
return push((cmo *)make_error_object(errcode, pushback)); |
|
} |
|
|
/* |
/* |
if error occurs, then a sm_*() function returns non-zero and |
if error occurs, then a sm_*() function returns non-zero and |
an error obect is set by a function which calls sm_*(). |
an error obect is set by a function which calls sm_*(). |
Line 173 int sm_executeStringByLocalParser(OXFILE* oxfp) |
|
Line 172 int sm_executeStringByLocalParser(OXFILE* oxfp) |
|
/* for mathematica */ |
/* for mathematica */ |
/* Sending the string `s' to mathematica for its evaluation. */ |
/* Sending the string `s' to mathematica for its evaluation. */ |
ml_evaluateStringByLocalParser(s); |
ml_evaluateStringByLocalParser(s); |
ml_select(); |
ml_select(); |
push(receive_mlo()); |
push(receive_mlo()); |
} |
} |
return 0; |
return 0; |
Line 207 int sm_executeFunction(OXFILE* oxfp) |
|
Line 206 int sm_executeFunction(OXFILE* oxfp) |
|
argv[i] = pop(); |
argv[i] = pop(); |
} |
} |
ml_executeFunction(func, argc, argv); |
ml_executeFunction(func, argc, argv); |
ml_select(); |
ml_select(); |
push(receive_mlo()); |
push(receive_mlo()); |
return 0; |
return 0; |
} |
} |
|
|
#define VERSION 0x11121400 |
|
#define ID_STRING "1999/12/14 15:25:00" |
|
|
|
int sm_mathcap(OXFILE* oxfp) |
int sm_mathcap(OXFILE* oxfp) |
{ |
{ |
mathcap_sysinfo_set(VERSION, ID_STRING, "ox_math"); |
push((cmo *)oxf_cmo_mathcap(oxfp)); |
push(mathcap_get()); |
|
return 0; |
return 0; |
|
} |
|
|
|
void sm_set_mathcap(OXFILE *oxfp) |
|
{ |
|
cmo_mathcap *m = (cmo_mathcap *)pop(); |
|
if (m->tag == CMO_MATHCAP) { |
|
oxf_mathcap_update(oxfp, m); |
|
}else { |
|
push_error(-1, m); |
|
/* an error object must be pushed */ |
|
} |
} |
} |
|
|
int receive_sm_command(OXFILE* oxfp) |
int receive_sm_command(OXFILE* oxfp) |