Annotation of OpenXM/src/k097/ki.c, Revision 1.10
1.10 ! takayama 1: /* $OpenXM: OpenXM/src/k097/ki.c,v 1.9 2015/10/10 11:29:46 takayama Exp $ */
1.1 maekawa 2: /* ki.c ( kx interpreter ) */
3:
4: #include <stdio.h>
5: #include "datatype.h"
6: #include "stackm.h"
7: #include "extern.h"
8: #include "extern2.h"
9: #include "lookup.h"
10: #include "matrix.h"
11: #include "gradedset.h"
12: #include <setjmp.h>
13: #include <signal.h>
1.9 takayama 14: #include <string.h>
15: #include <stdlib.h>
1.10 ! takayama 16: #include "mysig.h"
1.1 maekawa 17:
18: char *getLOAD_K_PATH(); /* from d.h */
19:
1.4 takayama 20: #if defined(__CYGWIN__)
21: #define JMP_BUF sigjmp_buf
22: #define SETJMP(env) sigsetjmp(env,1)
23: #define LONGJMP(env,p) siglongjmp(env,p)
24: #else
25: #define JMP_BUF jmp_buf
26: #define SETJMP(env) setjmp(env)
27: #define LONGJMP(env,p) longjmp(env,p)
28: #endif
29:
1.1 maekawa 30: #ifdef CALLASIR
31: #include "ak0.h"
32: #endif
33:
1.4 takayama 34: extern JMP_BUF KCenvOfParser;
1.1 maekawa 35:
36: char Ktmp[10240];
37: int Ksize = 10240;
38: char *Kbuff = Ktmp;
39: int Kpt = 0;
40: int DebugCompiler = 0; /* 0: , 1: Displays sendKan[ .... ] */
41: int K00_verbose = 0;
42:
43: extern int DebugMode;
44:
45: sendKan(int p) {
46: static int n = 2;
47: extern int Interactive;
1.7 takayama 48: struct object obj = OINIT;
1.1 maekawa 49: int result;
1.6 takayama 50: extern int InSendmsg2;
1.10 ! takayama 51: mysignal(SIGINT,SIG_IGN); /* Don't jump to ctrlC(). */
1.8 takayama 52: if (p == 10) {printf("In(%d)= ",n++); return 0;}
1.1 maekawa 53: if (p == 0 && DebugCompiler) printf("sendKan[%s]\n",Kbuff);
54: /* printf("sendKan[%s]\n",Kbuff); */
55: if (strlen(Kbuff) != 0) {
1.10 ! takayama 56: mysignal(SIGINT,SIG_DFL);
1.1 maekawa 57: result = KSexecuteString(Kbuff);
58: /* fprintf(stderr,"r=%d ",result); */
1.10 ! takayama 59: mysignal(SIGINT,SIG_IGN); /* Reset SIGINT. Don't jump to ctrlC(). */
1.1 maekawa 60: }
61: /* fprintf(stderr,"r=%d ",result); */
62: if (result == -1) {
1.6 takayama 63: K00recoverFromError(); InSendmsg2 = 0;
1.1 maekawa 64: fprintf(stderr,"--- Engine error or interrupt : ");
65: if (DebugMode) {
1.10 ! takayama 66: mysignal(SIGINT,SIG_DFL);
1.1 maekawa 67: KSexecuteString("db.DebugStack setstack ");
1.10 ! takayama 68: mysignal(SIGINT,SIG_IGN); /* Reset SIGINT. Don't jump to ctrlC(). */
1.1 maekawa 69: obj = KSpop();
1.10 ! takayama 70: mysignal(SIGINT,SIG_DFL);
1.1 maekawa 71: KSexecuteString("stdstack ");
1.10 ! takayama 72: mysignal(SIGINT,SIG_IGN); /* Reset SIGINT. Don't jump to ctrlC(). */
1.1 maekawa 73: if (obj.tag == Sdollar) {
74: fprintf(stderr,"%s\n",obj.lc.str);
75: fprintf(stderr,"\n");
76: }else{
77: fprintf(stderr,"The error occured on the top level.\n");
78: }
79: fprintf(stderr,"Type in Cleards() to exit the debug mode and Where() to see the stack trace.\n");
80: }
81: }
82: #define AFO
83: #ifdef AFO
1.4 takayama 84: if (SETJMP(KCenvOfParser)) {
1.6 takayama 85: InSendmsg2=0;
1.1 maekawa 86: fprintf(stderr,"Error: Goto the top level.\n");
87: parseAfile(stdin);
88: KCparse();
89: /* Call KCparse() recursively when there is error. */
90: /* This is the easiest way to handle errors. */
91: /* However, it should be rewrited in a future. */
92: }else{ /* fprintf(stderr,"setjmp\n"); */ }
93: #endif
1.3 takayama 94: if (p == 0 && Interactive) printf("In(%d)= ",n++);
1.1 maekawa 95: Kpt=0; Kbuff[0] = '\0';
96: }
97:
98:
99: void pkkan(s)
100: char *s;
101: {
102: char *t;
103: if (strlen(s)+Kpt >= Ksize) {
104: Ksize = Ksize*2;
105: t = (char *)GC_malloc(sizeof(char)*Ksize);
1.5 ohara 106: if (t == (char *)NULL) { fprintf(stderr,"No memory."); exit(1);}
1.1 maekawa 107: strcpy(t,Kbuff); Kbuff = t;
108: }
109: strcpy(&(Kbuff[Kpt]),s);
110: Kpt += strlen(s);
111: }
112:
113: void pkdebug(char *s0,char *s1, char *s2,char *s3) {
114: if (DebugMode) {
115: pkkan(" db.DebugStack setstack $");
116: pkkan(s0); pkkan(s1); pkkan(s2); pkkan(s3);
117: pkkan("$ stdstack \n");
118: }
119: }
120:
121: void pkdebug2(void) {
122: if (DebugMode) {
123: pkkan(" db.DebugStack setstack pop stdstack \n");
124: }
125: }
126:
127:
128: void *mymalloc(int n)
129: {
130: return((void *)GC_malloc(n));
131: }
132:
133: execFile(char *s)
134: {
135: FILE *fp;
136: #define TMP_SIZE 1024
137: char tmp[TMP_SIZE+1];
138: char tname[1024];
139: char tname2[1024];
140: char tname3[1024];
141: char tname4[1024];
142: int c;
143: if ((fp = fopen(s,"r")) == (FILE *) NULL) {
144: strcpy(tname,LOAD_SM1_PATH2);
145: strcat(tname,s);
146: strcpy(tname2,tname);
147: if ((fp = fopen(tname,"r")) == (FILE *) NULL) {
148: strcpy(tname,getLOAD_K_PATH());
149: strcat(tname,s);
150: strcpy(tname3,tname);
151: if ((fp = fopen(tname,"r")) == (FILE *) NULL) {
152: strcpy(tname,LOAD_K_PATH);
153: strcat(tname,s);
154: strcpy(tname4,tname);
155: if ((fp = fopen(tname,"r")) == (FILE *) NULL) {
156: strcpy(tname,getLOAD_K_PATH());
157: strcat(tname,"../kan96xx/Kan/");
158: strcat(tname,s);
159: if ((fp = fopen(tname,"r")) == (FILE *) NULL) {
160: fprintf(stderr,"Fatal error: Cannot open the system macro %s in %s, %s, %s nor %s.\n",
161: s,tname2,tname3,tname4,tname);
162: exit(11);
1.8 takayama 163: return 0;
1.1 maekawa 164: }
165: }
166: }
167: }
168: }
169: /* printf("Reading\n"); fflush(stdout); */
170: while (fgets(tmp,TMP_SIZE,fp) != NULL) {
171: pkkan(tmp);
172: }
173: /* printf("Done.\n"); fflush(stdout); */
174: sendKan(1);
175: /* printf("sendKan, done.\n"); fflush(stdout); */
176: }
177:
178: /*Tag: yychar = YYEMPTY; Put the following line in simple.tab.c */
179: /* It makes segmentation fault. */
180: /*
181: #include <setjmp.h>
182: extern jmp_buf KCenvOfParser;
183: if (setjmp(KCenvOfParser)) {
184: parseAfile(stdin);
185: fprintf(stderr,"Error: Goto the top level.\n");
186: }else{ }
187: */
188:
189:
190: void testNewFunction(objectp op)
191: {
192: fprintf(stderr,"This is testNewFunction of NOT CALLASIR.\n");
193: if (op->tag != Sstring) {
194: fprintf(stderr,"The argument must be given as an argment of load.\n");
195: return;
196: }
197: fprintf(stderr,"Now execute .. <<%s>> \n",op->lc.str);
198: parseAstring(op->lc.str);
199: fprintf(stderr,"\nDone.\n");
200: }
201:
202:
203:
204:
205:
206:
207:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>