[BACK]Return to ki.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097

Annotation of OpenXM/src/k097/ki.c, Revision 1.11

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>