Annotation of OpenXM/src/k097/sm1sm.c, Revision 1.5
1.5 ! takayama 1: /* $OpenXM: OpenXM/src/k097/sm1sm.c,v 1.4 2015/10/10 11:29:46 takayama Exp $ */
1.1 takayama 2: /* This is imported from kxx/sm1stackmachine.c */
3: #include <stdio.h>
4: #include <setjmp.h>
1.3 takayama 5: #include <string.h>
1.4 takayama 6: #include <stdlib.h>
1.1 takayama 7: #include "../kxx/ox_kan.h"
8: #include "../kxx/serversm.h"
1.5 ! takayama 9: #include "ox_k0.h"
! 10:
1.1 takayama 11: extern int OXprintMessage;
12:
13: /* server stack machine */
14:
15:
16: void *Sm1_mathcap() {
17: int n,i;
18: struct mathCap *mathcap;
19: mathcap = KSmathCapByStruct();
20: return((void *)mathcap);
21: }
22:
23: int Sm1_setMathCap(ox_stream os) {
24: /* Set the mathcap data of the client in the server. */
25: /* sm1 <====== ox_sm1 mathcap is set in ox_stream = FILE2 * */
26: /* The mathcap data is on the stack. */
1.2 takayama 27: struct object ob = OINIT;
28: struct object ob2 = OINIT;
1.1 takayama 29: int n,i;
30: ob = KSpop();
31: KSpush(ob); KSexecuteString(" (mathcap data is ) message message ");
32: Kan_setMathCapToStream(os,ob);
33: /* set the math cap data associated to the ox_stream. */
34: }
35: void Sm1_pops(void) {
36: char data[100];
37: sprintf(data," 1 1 3 -1 roll { pop pop } for ");
38: KSexecuteString(data);
39: }
40: int Sm1_executeStringByLocalParser(void) {
41: int i;
42: char *s;
43: s = Sm1_popString();
44: if (s == NULL) {
45: printf("NULL argument for executeString.\n");
46: return(-1);
47: }else{
48: if (OXprintMessage) fprintf(stderr,"KSexecuteString(%s)\n",s);
49: i = KSexecuteString(s);
50: return(i);
51: }
52: }
53: char *Sm1_popString(void) {
54: char *KSpopString();
55: KSexecuteString(" toString ");
56: return(KSpopString());
57: }
58:
59:
60: int Sm1_setName(void)
61: {
62: char *s;
1.2 takayama 63: struct object ob = OINIT;
1.1 takayama 64: s = Sm1_popString();
65: if (s == NULL) {
66: printf("NULL argument for setName.\n");
67: return(-1);
68: }else{
69: ob = KSpop();
70: printf("/%s tag=%d def\n",s,ob.tag);
71: KputUserDictionary(s,ob);
72: return(0);
73: }
74: }
75:
76: int Sm1_evalName(void)
77: {
78: char *s;
1.2 takayama 79: struct object ob = OINIT;
1.1 takayama 80: s = Sm1_popString();
81: if (s == NULL) {
82: printf("NULL argument for evalName.\n");
83: return(-1);
84: }else{
85: ob = KfindUserDictionary(s);
86: if (ob.tag == -1) {
87: printf("findUserDictionary(%s)--> tag=%d Not found.\n",s,ob.tag);
88: return(-1);
89: }
90: printf("findUserDictionary(%s)--> tag=%d\n",s,ob.tag);
91: KSpush(ob);
92: return(0);
93: }
94: }
95:
96: int Sm1_pushCMO(ox_stream fp)
97: {
98: return(Kan_pushCMOFromStream(fp));
99: }
100: int Sm1_popCMO(ox_stream fp,int serial)
101: {
102: return(Kan_popCMOToStream(fp,serial));
103: }
104:
105: int Sm1_pushError2(int serial, int no, char *s)
106: {
1.2 takayama 107: struct object ob = OINIT;
1.1 takayama 108: ob = KnewErrorPacket(serial,no,s);
109: KSpush(ob);
110: }
111:
112: char *Sm1_popErrorMessage(char *s) {
113: char *e;
114: char *a;
115: extern int ErrorMessageMode;
116: /* Set ErrorMessageMode = 2 to use this function. */
117: if (ErrorMessageMode != 2) return(s);
118: e = popErrorStackByString();
119: if (e == NULL ) {
120: a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+80));
121: if (a == NULL) {
122: fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
123: exit(10);
124: }
125: strcpy(a,s); strcat(a,"No error message on the error stack.");
126: return(a);
127: }else{
128: a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+strlen(e)+2));
129: if (a == NULL) {
130: fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
131: exit(10);
132: }
133: strcpy(a,s); strcat(a,e);
134: return(a);
135: }
136: }
137:
138: void Sm1_getsp(void) {
139: KSpush(KpoInteger(KSstackPointer()));
140: }
141:
142: void Sm1_dupErrors(void) {
143: KSpush(KSdupErrors());
144: }
145:
146: void Sm1_pushCMOtag(int serial) {
1.2 takayama 147: struct object obj = OINIT;
1.1 takayama 148: int t;
149: obj = KSpeek(0);
150: t = KgetCmoTagOfObject(obj);
151: if (t != -1) {
152: KSpush(KpoInteger(t));
153: }else{
154: Sm1_pushError2(serial,-1,"The top object on the server stack cannot be translated to cmo.");
155: }
156: }
157:
158:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>