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