Annotation of OpenXM/src/kxx/sm1stackmachine.c, Revision 1.5
1.1 maekawa 1: #include <stdio.h>
2: #include <setjmp.h>
3: #include "ox_kan.h"
4: #include "serversm.h"
5: extern int OXprintMessage;
1.5 ! takayama 6: extern char *MsgStackTrace;
! 7: extern char *MsgSourceTrace;
1.1 maekawa 8:
9: /* server stack machine */
10:
11: int Sm1_start(int argc, char *fnames[],char *myname) {
12: int i;
13: char cmd[4092];
14: extern int ErrorMessageMode;
15: extern char *VersionString;
16: extern int CmoClientMode;
17: CmoClientMode = 0;
18: KSstart();
19: fprintf(stderr,"sm1 version : %s\n",VersionString);
20: fprintf(stderr,"sm1 url : http://www.math.kobe-u.ac.jp/KAN\n");
21: fprintf(stderr,"name = %s\n",myname);
22:
23: /* Initialize for ox_sm1 */
24: ErrorMessageMode = 2;
25: KSexecuteString(" [ [(Strict) 1] system_variable ] pop ");
26:
27: /* Write a system start-up script here. */
28: KSexecuteString(" [(cmoLispLike) 1] extension pop ");
29:
30: /* if argc > 0, execute the system startup files fnames and
31: set oxSystemName to myname. */
32: if (argc > 0) {
33: for (i=0; i<argc; i++) {
34: /* load files from the search path */
35: if (strlen(fnames[i]) > 1024) {
1.3 takayama 36: fprintf(stderr,"Too long name for sm1 library file to load.\n");
37: exit(10);
1.1 maekawa 38: }
39: sprintf(cmd," [(parse) (%s) pushfile ] extension pop ",fnames[i]);
40: KSexecuteString(cmd);
41: }
42: sprintf(cmd," [(cmoOxSystem) (ox_sm1_%s) ] extension pop ",myname);
43: KSexecuteString(cmd);
44: }
45: KSexecuteString(" (---------------------------------------------------) message ");
46: KSexecuteString(" [(flush)] extension pop ");
47:
48: return(0);
49: }
50:
51: void *Sm1_mathcap() {
52: int n,i;
53: struct mathCap *mathcap;
54: mathcap = KSmathCapByStruct();
55: return((void *)mathcap);
56: }
57:
58: int Sm1_setMathCap(ox_stream os) {
59: /* Set the mathcap data of the client in the server. */
60: /* sm1 <====== ox_sm1 mathcap is set in ox_stream = FILE2 * */
61: /* The mathcap data is on the stack. */
1.4 takayama 62: struct object ob = OINIT;
63: struct object ob2 = OINIT;
1.1 maekawa 64: int n,i;
65: ob = KSpop();
66: KSpush(ob); KSexecuteString(" (mathcap data is ) message message ");
67: Kan_setMathCapToStream(os,ob);
68: /* set the math cap data associated to the ox_stream. */
69: }
70: void Sm1_pops(void) {
71: char data[100];
72: sprintf(data," 1 1 3 -1 roll { pop pop } for ");
73: KSexecuteString(data);
74: }
75: int Sm1_executeStringByLocalParser(void) {
76: int i;
77: char *s;
78: s = Sm1_popString();
79: if (s == NULL) {
80: printf("NULL argument for executeString.\n");
81: return(-1);
82: }else{
83: if (OXprintMessage) fprintf(stderr,"KSexecuteString(%s)\n",s);
84: i = KSexecuteString(s);
85: return(i);
86: }
87: }
88: char *Sm1_popString(void) {
89: char *KSpopString();
90: KSexecuteString(" toString ");
91: return(KSpopString());
92: }
93:
94:
95: int Sm1_setName(void)
96: {
97: char *s;
1.4 takayama 98: struct object ob = OINIT;
1.1 maekawa 99: s = Sm1_popString();
100: if (s == NULL) {
101: printf("NULL argument for setName.\n");
102: return(-1);
103: }else{
104: ob = KSpop();
105: printf("/%s tag=%d def\n",s,ob.tag);
106: KputUserDictionary(s,ob);
107: return(0);
108: }
109: }
110:
111: int Sm1_evalName(void)
112: {
113: char *s;
1.4 takayama 114: struct object ob = OINIT;
1.1 maekawa 115: s = Sm1_popString();
116: if (s == NULL) {
117: printf("NULL argument for evalName.\n");
118: return(-1);
119: }else{
120: ob = KfindUserDictionary(s);
121: if (ob.tag == -1) {
122: printf("findUserDictionary(%s)--> tag=%d Not found.\n",s,ob.tag);
123: return(-1);
124: }
125: printf("findUserDictionary(%s)--> tag=%d\n",s,ob.tag);
126: KSpush(ob);
127: return(0);
128: }
129: }
130:
131: int Sm1_pushCMO(ox_stream fp)
132: {
133: return(Kan_pushCMOFromStream(fp));
134: }
135: int Sm1_popCMO(ox_stream fp,int serial)
136: {
137: return(Kan_popCMOToStream(fp,serial));
138: }
139:
140: int Sm1_pushError2(int serial, int no, char *s)
141: {
1.4 takayama 142: struct object ob = OINIT;
1.5 ! takayama 143: char *ss;
! 144: char *error_message="<ox103:error_message>";
! 145: char *message="<ox103:message>";
! 146: char *stack_trace="<ox103:stack_trace>";
! 147: char *source_trace="<ox103:source_trace>";
! 148: char *error_message2="</ox103:error_message>";
! 149: char *message2="</ox103:message>";
! 150: char *stack_trace2="</ox103:stack_trace>";
! 151: char *source_trace2="</ox103:source_trace>";
! 152: ss = (char *) sGC_malloc(strlen(s)+strlen(MsgStackTrace)+
! 153: strlen(MsgSourceTrace)+
! 154: strlen(error_message)+strlen(error_message2)+
! 155: strlen(message)+strlen(message2)+
! 156: strlen(stack_trace)+strlen(stack_trace2)+
! 157: strlen(source_trace)+strlen(source_trace2)+2);
! 158:
! 159: strcat(ss,error_message);
! 160: strcat(ss,message);
! 161: strcat(ss,s);
! 162: strcat(ss,message2);
! 163: if (MsgStackTrace != NULL) {
! 164: strcat(ss,stack_trace);
! 165: strcat(ss,MsgStackTrace);
! 166: strcat(ss,stack_trace2);
! 167: }
! 168: if (MsgSourceTrace != NULL) {
! 169: strcat(ss,source_trace);
! 170: strcat(ss,MsgSourceTrace);
! 171: strcat(ss,source_trace2);
! 172: }
! 173: strcat(ss,error_message2);
! 174: ob = KnewErrorPacket(serial,no,ss);
1.1 maekawa 175: KSpush(ob);
176: }
177:
178: char *Sm1_popErrorMessage(char *s) {
179: char *e;
180: char *a;
181: extern int ErrorMessageMode;
182: /* Set ErrorMessageMode = 2 to use this function. */
183: if (ErrorMessageMode != 2) return(s);
184: e = popErrorStackByString();
185: if (e == NULL ) {
186: a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+80));
187: if (a == NULL) {
188: fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
189: exit(10);
190: }
191: strcpy(a,s); strcat(a,"No error message on the error stack.");
192: return(a);
193: }else{
194: a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+strlen(e)+2));
195: if (a == NULL) {
196: fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
197: exit(10);
198: }
199: strcpy(a,s); strcat(a,e);
200: return(a);
201: }
202: }
203:
204: void Sm1_getsp(void) {
205: KSpush(KpoInteger(KSstackPointer()));
206: }
207:
208: void Sm1_dupErrors(void) {
209: KSpush(KSdupErrors());
210: }
211:
1.2 takayama 212: void Sm1_pushCMOtag(int serial) {
1.4 takayama 213: struct object obj = OINIT;
1.2 takayama 214: int t;
215: obj = KSpeek(0);
216: t = KgetCmoTagOfObject(obj);
217: if (t != -1) {
1.3 takayama 218: KSpush(KpoInteger(t));
1.2 takayama 219: }else{
1.3 takayama 220: Sm1_pushError2(serial,-1,"The top object on the server stack cannot be translated to cmo.");
1.2 takayama 221: }
222: }
1.1 maekawa 223:
224:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>