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

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

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

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