Annotation of OpenXM/src/k097/sm1sm.c, Revision 1.6
1.6 ! takayama 1: /* $OpenXM: OpenXM/src/k097/sm1sm.c,v 1.5 2020/10/07 23:53:25 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. */
1.6 ! takayama 34: return 0;
1.1 takayama 35: }
36: void Sm1_pops(void) {
37: char data[100];
38: sprintf(data," 1 1 3 -1 roll { pop pop } for ");
39: KSexecuteString(data);
40: }
41: int Sm1_executeStringByLocalParser(void) {
42: int i;
43: char *s;
44: s = Sm1_popString();
45: if (s == NULL) {
46: printf("NULL argument for executeString.\n");
47: return(-1);
48: }else{
49: if (OXprintMessage) fprintf(stderr,"KSexecuteString(%s)\n",s);
50: i = KSexecuteString(s);
51: return(i);
52: }
53: }
54: char *Sm1_popString(void) {
55: char *KSpopString();
56: KSexecuteString(" toString ");
57: return(KSpopString());
58: }
59:
60:
61: int Sm1_setName(void)
62: {
63: char *s;
1.2 takayama 64: struct object ob = OINIT;
1.1 takayama 65: s = Sm1_popString();
66: if (s == NULL) {
67: printf("NULL argument for setName.\n");
68: return(-1);
69: }else{
70: ob = KSpop();
71: printf("/%s tag=%d def\n",s,ob.tag);
72: KputUserDictionary(s,ob);
73: return(0);
74: }
75: }
76:
77: int Sm1_evalName(void)
78: {
79: char *s;
1.2 takayama 80: struct object ob = OINIT;
1.1 takayama 81: s = Sm1_popString();
82: if (s == NULL) {
83: printf("NULL argument for evalName.\n");
84: return(-1);
85: }else{
86: ob = KfindUserDictionary(s);
87: if (ob.tag == -1) {
88: printf("findUserDictionary(%s)--> tag=%d Not found.\n",s,ob.tag);
89: return(-1);
90: }
91: printf("findUserDictionary(%s)--> tag=%d\n",s,ob.tag);
92: KSpush(ob);
93: return(0);
94: }
95: }
96:
97: int Sm1_pushCMO(ox_stream fp)
98: {
99: return(Kan_pushCMOFromStream(fp));
100: }
101: int Sm1_popCMO(ox_stream fp,int serial)
102: {
103: return(Kan_popCMOToStream(fp,serial));
104: }
105:
106: int Sm1_pushError2(int serial, int no, char *s)
107: {
1.2 takayama 108: struct object ob = OINIT;
1.1 takayama 109: ob = KnewErrorPacket(serial,no,s);
110: KSpush(ob);
1.6 ! takayama 111: return 0;
1.1 takayama 112: }
113:
114: char *Sm1_popErrorMessage(char *s) {
115: char *e;
116: char *a;
117: extern int ErrorMessageMode;
118: /* Set ErrorMessageMode = 2 to use this function. */
119: if (ErrorMessageMode != 2) return(s);
120: e = popErrorStackByString();
121: if (e == NULL ) {
122: a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+80));
123: if (a == NULL) {
124: fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
125: exit(10);
126: }
127: strcpy(a,s); strcat(a,"No error message on the error stack.");
128: return(a);
129: }else{
130: a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+strlen(e)+2));
131: if (a == NULL) {
132: fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
133: exit(10);
134: }
135: strcpy(a,s); strcat(a,e);
136: return(a);
137: }
138: }
139:
140: void Sm1_getsp(void) {
141: KSpush(KpoInteger(KSstackPointer()));
142: }
143:
144: void Sm1_dupErrors(void) {
145: KSpush(KSdupErrors());
146: }
147:
148: void Sm1_pushCMOtag(int serial) {
1.2 takayama 149: struct object obj = OINIT;
1.1 takayama 150: int t;
151: obj = KSpeek(0);
152: t = KgetCmoTagOfObject(obj);
153: if (t != -1) {
154: KSpush(KpoInteger(t));
155: }else{
156: Sm1_pushError2(serial,-1,"The top object on the server stack cannot be translated to cmo.");
157: }
158: }
159:
160:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>