Пример #1
0
unsigned char CEgIStream::GetByteSW() {
	unsigned char c = GetByte();

	while ( noErr() && (c == 13 || c == 10 || c == 32 || c == 9) )
		c = GetByte();

	return c;
}
Пример #2
0
unsigned char CEgIStream::PeekByte() {
	register unsigned char c;

	if ( mIsTied ) {
		if ( mPos != 0 )
			c = *((unsigned char*) mNextPtr); }
	else if ( mPos < long(mBufPos + mStrLen) && mPos >= mBufPos )
		c = *((unsigned char*) mNextPtr);
	else if ( noErr() ) {
		fillBuf();
		if ( noErr() )
			c = PeekByte();
		else
			throwErr( cNoErr );
	}

	return c;
}
Пример #3
0
bool CEgIStream::AssertToken( const char* inStr ) {
	char c = GetByteSW();

	// Check first byte
	if ( *inStr != c || ! noErr() )
		return false;
	inStr++;

	// Make sure following bytes in the stream match inStr
	while ( *inStr ) {
		c = GetByte();
		if ( *inStr != c || ! noErr() )
			return false;
		inStr++;
	}

	return true;
}
Пример #4
0
void CEgIStream::ReadNumber( UtilStr& outStr ) {

	outStr.Wipe();
	char c = GetByteSW();

	while ( noErr() && ( c == '.' || (c >= '0' && c <= '9') ) ) {
		outStr.Append( c );
		c = GetByte();
	}
}
Пример #5
0
bool CEgIStream::Read( UtilStr& outStr ) {
	outStr.Wipe();

	unsigned char c = GetByteSW();

	while ( noErr() && c != 13 && c != 9 && c != 32 && c != 10 ) {	// Stop on a CR, LF, TAB, space or error
		outStr.Append( (char) c );
		c = GetByte();
	}
	return c == 13 || c == 10;
}
Пример #6
0
void CEgIStream::Readln() {
	unsigned char p, c = GetByte();

	while ( noErr() && c != 13 && c != 10 ) 		// Stop on a CR or LFor error
		c = GetByte();

	p = PeekByte();
	if ( ( p == 13 && c == 10 ) || ( p == 10 && c == 13 ) )
		GetByte();

}
Пример #7
0
void * makeFunction(char * f)
{
void *M;
   if ((M = malloc(strlen(f)+8)) == NULL) stopErr("makeFunction","malloc");
   sprintf((char*)M,": _f %s ;",f);
   traiteLigne((char*)M,3);
   free(M);
   if (noErr() == 0) {
       M = fctByName("_f");
       return M;
   }
   messErr(48);
   return VIDE;
}
Пример #8
0
void compileFile(char * f)
{
FILE *F;
int i=0;
    if ((F = fopen(f,"r")) != NULL) {
       while (fgets(bufP, LBUF,F)) {
          if (noErr()) {
             printf("In file %s line %d !\n",f,i);
             break;
          }
          traiteLigne(bufP,1);
          i++;
       }
       fclose(F);
    }
}
Пример #9
0
void CEgIStream::Readln( UtilStr* outStr ) {
	unsigned char p, c = GetByte();

	if ( outStr ) {
		outStr -> Wipe();

		while ( noErr() && c != 13 && c != 10 ) {		// Stop on a CR or LF or error
			outStr -> Append( (char) c );
			c = GetByte();
		}

		p = PeekByte();
		if ( ( p == 13 && c == 10 ) || ( p == 10 && c == 13 ) )
			GetByte();
	}
}
Пример #10
0
unsigned char CEgIStream::GetByte() {
	register unsigned char c;

	if ( mIsTied ) {
		if ( mPos != 0 ) {
			c = *((unsigned char*) mNextPtr);
			mNextPtr++;
			mPos++; }
		else
			throwErr( cTiedEOS ); }
	else if ( mPos < long(mBufPos + mStrLen) && mPos >= mBufPos ) {
		c = *((unsigned char*) mNextPtr);
		mNextPtr++;
		mPos++; }
	else if ( noErr() ) {
		fillBuf();
		c = GetByte();
	}

	return c;
}
Пример #11
0
static void traiteLigne(char *b, int Ctx)
{
char *mot, *d, *f, *w;
   /* case of sh command : ! */
   if (*b=='!') {
     runCommandT(b+1);
     return;
   }
   d=b; f=b+strlen(d);
#ifdef DEBUG
     printf("traiteLigne : <%s>\n",d);
#endif
   switch(Ctx) {
     case 1 : /* compileFile */
       D_Trace(" #");
       break;
     case 2 : /* IF_ExecCS */
       D_Trace("# ExecCS:");
       break;
     case 3 : /* makeFunction */
       D_Trace("# makeFunction:");
       break;
     default : /* 0 */
       if (getiFD()) D_Trace(" #");
   }
   D_Tracenl(b);
   while (d<f) {
       if (noErr()) break;
       /* recherche du 1er mot */
       if (stringEnCours) {
         mot = d;
         while (1) {
            if((d = strchr(d,'"')) == NULL) {
               d=mot+strlen(mot);
               break;
            }
            if (*(d-1) == '\\') {
               w = d-1;
               while (*w != '\0') {
                   *w = *(w+1);
                   w++;
               }
               continue;
            }
            d++;
            if (!isSepa(*d,1)) continue;
            break;
         }
       }  else {
         /* on ignore les commentaires */
         if ((mot = strchr(d, (int)'#')) != NULL) {
                *mot = '\0';
                f = mot;
         }
         while (isSepa(*d,0)) d++; /* on avance tant que separateurs */
         mot = d;
         while (!isSepa(*d,1)) d++; /* on avance si nonSepa ET non \0 */
       }
       *d++ = '\0';  /* fin de la commande */
       if (strlen(mot)>0)
          if (traiteMot(mot)) break; /* abort if error */
   }
}
Пример #12
0
int lireLigne(int fd, char *b, char *s, int nc)
/* fd = file descriptor
   b  = adresse du buffer
   nc = nb de caracteres possible (longueur du buffer */
{
char *d, *f, c, c2, c3, *h, *w, *Wl, *rac;
int n, i, l, ls=0, ins=0, ignTild=0, nbT=0, Nc;
unsigned int j;
char bufd[50];
   /* printf("lireLigne ... \n"); */
   d = b;
   f = b+nc;
   while(d<f-ls) {
     if (noErr()) {
         n = -1;
         break;
     }
     /* fprintf(stderr,"d-b=%d ins=%d s=<%s> b=<%s>\n",d-b,ins,s,b); */
     if ((n=read(fd,d,1)) != 1) break;
     c=*d;
     if (ignTild && (c == '~')) {
        ignTild=0; continue;
     }
     if ((c > 31) && (c < 127)) { /* de SPACE a TILDE */
         if (!((FD_IN || iTERM) && ECHOOFF)) {
               printf("%c",c);
               if (ins) {
                  if (ins==2)  /* rewrite */
                     enleve1(s);
                  if(*s =='\0') ins=0;
                  else {
                     printf("%s",s);
                     for (j=0; j<strlen(s); j++) printf("\b");  
                  }
               }
         }
         fflush(stdout);
         d++;
     } else {
         switch (c) {
            /* Ctrl C
            case '\003' : 
              kill(getpid(), SIGINT);
              break; */
            case '\t': /* tab */
              if (d>b) {
                 *d='\0';
                 w=d-1;
                 while ((w>b) && (!(isSepa(*w,1)))) w--;
                 if (isSepa(*w,0)) w++;
                 /* fprintf(stderr,"d-b=%d  w=<%s>\n",d-b,w); */
                 if (strlen(w) > 0) {
                    j=nbLibBegin(w, &rac);
                    /* fprintf(stderr,"j=%d  w=<%s>\n",j,w); */
                    if (j==0) printf("\a");
                    else {
                       if (j==1) {
                          Wl=getLibBegin(w);
                          i=strlen(Wl)-strlen(w);
                          /* fprintf(stderr,"i=%d  Wl=<%s>\n",i,Wl); */
                          if (i>0) {
                             strcpy(w,Wl);
                             printf("%s ",d);
                             d+=i;
                             *d++ = ' ';
                             if (ins) {
                              printf("%s ",s);
                              for (j=0; j<(strlen(s)+1); j++) printf("\b");  
                             }
                          } else { /* XXXX */
                             if (i==0) {
                               printf (" ");
                               *d++ = ' ';
                             }
                          }
                       } else {
                          if (rac != NULL) {
                             i=strlen(rac)-strlen(w);
                             strcpy(w,rac);
                             printf("%s",d);
                             d+=i;
                             if (ins) {
                              printf("%s ",s);
                              for (j=0; j<(strlen(s)+1); j++) printf("\b");  
                             }
                          } else {
                            nbT++;
                            if (nbT>1) {
                               nbT=0;
                               printf("\n");
                               listLibBegin(w);
                               *d='\0';
                               printf("> %s",b);
                               if (ins) {
                                printf("%s ",s);
                                for (j=0; j<(strlen(s)+1); j++) printf("\b");  
                               }
                               fflush(stdout);
                            }
                          }
                       }
                    }
                    fflush(stdout);
                 }
              }
              break;
            case '\177':
              if (d>b) {
                 printf("\b \b");
                 if (ins) {
                  printf("%s ",s);
                  for (j=0; j<(strlen(s)+1); j++) printf("\b");  
                 }
                 fflush(stdout);
                 d--;
              }
              break;
            case '\n':
            case '\r':
              if ((FD_IN || iTERM) && ECHOOFF) printf(".");
              else {
                 printf("\n");
                 if (ins) {
                     if (d+strlen(s) < f) {
                        sprintf(d,"%s",s);
                        d+=strlen(s);
                     } else return(-1);
                 }
              }
              goto finBoucle;
         /* gestion des caracteres speciaux */
            case '\033':   /* ESCAPE */
              ignTild=1;
              Nc=read(fd,&c2,1);
              Nc=read(fd,&c3,1);
              if (c2 == '[') { /* CSI - see XTerm Control Sequences */
                  switch(c3) {
                      case '2' : /* Insert */
                        if (ins) {
                           ins++;
                           if (ins==3) ins=1;
                        }
                        break; 
                      case '3' : /* Suppr */
                        if (ins) {
                           enleve1(s);
                           if(*s =='\0') ins=0;
                           printf("%s \b",s);
                           for (j=0; j<strlen(s); j++) printf("\b");  
                           fflush(stdout);
                        }
                        break; 
                      case 'A' : /* UpArrow */
                      case 'B' : /* DownArrow */
                        ins = 0;
                        /* efface la ligne en cours */
                        l=d-b;
                        for(i=0;i<l;i++) printf("\b \b");
                        fflush(stdout);
                        d=b;
                        *d = '\0';
                        if ((h=getHisto(c3)) != NULL) {
                           strcpy(b,h);
                           d=b+strlen(h);
/*
                           printf("\n%s (iH=%d iHt=%d)\n",h,iH,iHt);
                           *d='\0';
*/
                           printf("%s",b);
                           fflush(stdout);
                        }
                        break; 
                      case 'C' : /* -> */
                        if (ins) {
                           *d = *s;
                           printf("%c",*d++);
                           enleve1(s);
                           if(*s =='\0') ins=0;
                           else {
                              printf("%s",s);
                              for (j=0; j<strlen(s); j++) printf("\b");  
                           }
                           fflush(stdout);
                        }
                        break; 
                      case 'D' : /* <- */
                        if (d>b) {
                           if (ins==0) {
                              ins=1;
                              *d='\0';
                              strcpy(s,d-1);
                           } else insertC(*(d-1),s);
                           d--;
                           printf("\b");
                           fflush(stdout);
                        }
                        break; 
                      case 'H' : /* home : debug terms ON */
                      case '1' : /* home numeric */
                        IFD_DebugTOn();
                        break; 
                      case 'F' : /* end : debug terms OFF */
                      case '4' : /* end numeric */
                        IFD_DebugTOff();
                        break; 
                      default:
                        sprintf(bufd,"# ignore : ESC [ %d (%c) !",(int)c3, c3);
                        D_Tracenl(bufd);
                        *d='\0';
                        /* **************
                        printf("> %s",b);
                        fflush(stdout); */
                  }
              } else {
                 if (c2 == 'O') { /* SS3 - see XTerm Control Sequences */
                    switch(c3) {
                      case 'P' : /* F1 */
                      break; 
                      case 'Q' : /* F2 */
                      break; 
                      case 'R' : /* F3 */
                      break; 
                      case 'S' : /* F4 */
                      break; 
                      case 'H' : /* home : debug terms ON */
                        IFD_DebugTOn();
                        break; 
                      case 'F' : /* end : debug terms OFF */
                        IFD_DebugTOff();
                        break; 
                    }
                 } else {
                  sprintf(bufd,"# ignore : ESC %d %d (%c) !",(int)c2,(int)c3, c3);
                  D_Tracenl(bufd);
                  *d='\0';
                  /* **************
                  printf("> %s",b);
                  fflush(stdout); */
                 }
              }
              break; 
            default :
/*
              printf("\nCar = %d !\n",(int)c);
              *d='\0';
              printf("> %s",b);
              fflush(stdout);
*/
              break; 
         }
     }
     if (ins) ls = strlen(s);
   }
finBoucle:
   /* printf("fin lireLigne!\n"); */
   if ((n<1) && (FD_IN !=0)) {
      closeFD();  /* fichier loader */
      if (ECHOOFF) printf("\n");
      return 0;
   }
   if ((n<1) && iTERM) {
      close(FD_IN);  /* pipe ou autre */
      Nc=dup(iTERM); /* stdin on term */
      iTERM = 0;
      if (ECHOOFF) printf("\n");
      return 0;
   }
   if (d == f) { /* cas du buffer trop petit */
/*   d=b;
     while (*d != '\n') read(fd,d,1);
**** not in raw mode */
#ifdef DEBUG
     printf("lireLigne : erreur !\n");
#endif
     return(-1);
   } 
   *d = '\0';
#ifdef DEBUG
     printf("lireLigne : retour <%s> !\n",b);
#endif
   if (!FD_IN) putHisto(b);
   incFDlig();
   return(strlen(b));
}
Пример #13
0
void CEgErr::throwErr( long inErr ) {

	if ( noErr() || inErr == cNoErr ) {
		mErr = inErr;
	}
}
Пример #14
0
void execCod(void *A)
{
int i,n, ea, Ea, *ai, InDo=0, OnErr=0, mFCTP;
long L, P;
char * C, *D, *F, *W, *S, *ADo_Next, *ADo_Leave;
void * T, *T2;
void (*f)(void);
struct Fct * FR;

    /* printf("pid = %d ITASK=%d FctInTask=%d\n",getpid(),ITASK,FctInTask);*/
    if (FctInTask) {
        if (ITASK==0) {
           if (FctInTask==-1) {
              FctInTask=0; return;
           }
           if (MakeTask(A)) return;
        }
        if (ITASK!=FctInTask) return;
    }
    D_Cod++;
    ai = (int*)A;
    i = *ai++;
    ea = *ai++;
    Ea = *ai;
    if (ea) tellOnErr(A);
    C = (char*)A+(3*sizeof(int));
    D = C;
    F = C+i;
    n = sizeof(T);
    while (C <= F) {
       /* printf("execCod : %s %d - %x : %ld\n",
              codByAddr(A),(int)(C-D),*C,(long)*(C+1));
       */
       if (noErr() && ((C==F) || ((Code)*C != T_ONER)) ) { /* to find onerr: */
          if (ea && (OnErr==0)) {
             C = D+ea;
          }  else {
             printf("Called in %s err=%d i=%d/%d cod=<%x>\n",
                    codByAddr(A),noErr(),(int)(C-D),i,*C);
             break; /* end of while */
          }
       }
       if (C==F) break; /* end of code */
       switch((Code)*C) {
       case T_ONER :
           if (noErr()==0) { /* jmp end: */
               if (Ea) C = D+Ea;
               else C = F; /* to break */
           } else {
             if (OnErr==0) {
                OnErr=1;
                majLastErr(A);
                razErr();
             } else C = F;
           }
           break;
       case T_RET :
           C = F; /* to break */
           break;
       case T_END :
           break; /* nothing */
       case T_JEND :
           if (Ea) C = D+Ea;
           else C = F; /* to break */
           break;
       case T_NUM :
           bcopy((void*)(C+1),(void*)&T,n);
           insertVal(T);
           break;
       case T_CHA :
           bcopy((void*)(C+1),(void*)&W,n);
           putString(W);
           break;
       case T_LIB :
           if (InstallOn) {
              if (InstallOn < 3) {
                 bcopy((void*)(C+1),(void*)&T,n);
                 _MODIF_FCT_INST_(T);
                 _MODIF_FCT_TYP_(1);
              } else {
                 _MODIF_FCT_INST_(VIDE);
                 _MODIF_FCT_TYP_(0);
              }
              InstallOn=0;
           } else {
              bcopy((void*)(C+1),(void*)&f,n);
              f();
              /* free context loops */
              if (Do_Evts) { /* quit or cut */
                 /*printf("execCod T_LIB : Evts %d\n",Do_Evts);*/
                 if (InDo) {
                    if (Do_Evts>0) {
                       C=ADo_Leave;
                       I_DO--;
                       InDo = 0;
                       Do_Evts--;
                    } else {
                       C=ADo_Next;
                       Do_Evts=0;
                    }
                 } else { /* quit */
                    C = F;
                 }
              }
           }
           break;
       case T_FCT :
           if (InstallOn) {
              if (InstallOn < 3) {
                 bcopy((void*)(C+1),(void*)&T,n);
                 T2=fctByCode(T);
                 _MODIF_FCT_INST_(T2);
                 _MODIF_FCT_TYP_(2);
              } else {
                 _MODIF_FCT_INST_(VIDE);
                 _MODIF_FCT_TYP_(0);
              }
              InstallOn=0;
           } else {
              bcopy((void*)(C+1),(void*)&T,n);
              execCod(T);
              /* free context loops */
              if (Do_Evts) { /* quit or cut */
                 /*printf("execCod T_FCT : Evts %d\n",Do_Evts);*/
                 if (InDo) {
                    if (Do_Evts>0) {
                       C=ADo_Leave;
                       I_DO--;
                       InDo = 0;
                       Do_Evts--;
                    } else {
                       C=ADo_Next;
                       Do_Evts=0;
                    }
                 } else { /* quit */
                    C = F;
                 }
              }
           }
           break;
       case T_FCTDS :
       case T_EXEKS :
           if ((S = getString()) != NULL)
              free((void*)S); /* remove the string */
           break;
       case T_FCTD :
           if ((S = getString()) != NULL)
              free((void*)S); /* remove the string */
           if (noErr()) break;
       case T_FCTDW :
       case T_FCTP :
              bcopy((void*)(C+1),(void*)&T,n);
              FR = (struct Fct *)T;
              execCod(FR->c);
              /* free context loops */
              if (Do_Evts) { /* quit or cut */
                 /*printf("execCod T_FCTD : Evts %d\n",Do_Evts);*/
                 if (InDo) {
                    if (Do_Evts>0) {
                       C=ADo_Leave;
                       I_DO--;
                       InDo = 0;
                       Do_Evts--;
                    } else {
                       C=ADo_Next;
                       Do_Evts=0;
                    }
                 } else { /* quit */
                    C = F;
                 }
              }
           if (*C == T_FCTP) {
              if (mFCTP) *C = T_FCTDW;
              else *C = T_FCTD;
           }
           break;
       case T_EXEK :
           if ((S = getString()) != NULL) {
              if (strlen(S)>0) { /* to do with T_FCTD */
                 mFCTP=0;
                 T = makeFunction(S);
                 if (T != VIDE) {
                    bcopy((void*)&T, (void*)(C+1),n);
                    *C = T_FCTP;
                    C -= (n+1);
                    unlinkLastFct();
                    /* upgrading precedent code ? not always ! */
                    if (C >= D) {
                       if (*C == T_CHA) { /* case of a string */
                          *C = T_CHAS;
                          mFCTP=1;
                       }
                       if (*C == T_VAR) { /* case of a variable string */
                          bcopy((void*)(C+1),(void*)&W,n);
                          if (isVarChar(W)) {
                             *C = T_VARS;
                             mFCTP=1;
                          }
                       }
                    }
                 } else /* error in compilation */
                    *C = T_EXEKS;
              }
              free((void*)S); 
           }
           break;
       case T_IF :
           if (!getBool()) {
               bcopy((void*)(C+1),(void*)&L,n);
               C += L;
           }
           break;
       case T_IFN :
           if (getBool()) {
               bcopy((void*)(C+1),(void*)&L,n);
               C += L;
           }
           break;
       case T_DO :
           I_DO++;
           InDo=1;
           /* maj do_adresses */
           W = C + (2*(n+1));
           bcopy((void*)(W+1),(void*)&L,n);
           ADo_Leave=D+L-n-1;
           ADo_Next=ADo_Leave-(2*(n+1));
           /* printf("execCod T_DO : AL= %d AN=%d\n",
                (int)(ADo_Leave-D), (int)(ADo_Next-D));*/
           getParLong(&P);
           D_DO[I_DO] = P;
           getParLong(&P);
           L_DO[I_DO] = P;
           if (P > D_DO[I_DO]) S_DO[I_DO]=0;
           else S_DO[I_DO]=1;
           break;
       case T_DO_I :
           IF_getIndDo(0);
           break;
       case T_DO_J :
           IF_getIndDo(1);
           break;
       case T_DO_K :
           IF_getIndDo(2);
           break;
       case T_IFD :
           if (S_DO[I_DO]) {
             if (D_DO[I_DO] > L_DO[I_DO]) {
               bcopy((void*)(C+1),(void*)&L,n);
               C += L;
             } else {
               I_DO--;
               InDo=0;
             }
           } else {
             if (D_DO[I_DO] < L_DO[I_DO]) {
               bcopy((void*)(C+1),(void*)&L,n);
               C += L;
             } else {
               I_DO--;
               InDo=0;
             }
           }
           break;
       case T_LOOP :
           if (S_DO[I_DO]) D_DO[I_DO]--;
           else D_DO[I_DO]++;
           break;
       case T_PLOO :
           getParLong(&P);
           D_DO[I_DO]+=P;
           break;
       case T_JMP :
           bcopy((void*)(C+1),(void*)&L,n);
           C += L;
           break;
       case T_GOTO :
           bcopy((void*)(C+1),(void*)&L,n);
           C = D + L - n-1;
           break;
       case T_VAR  :
           if (InstallOn) {
              if (InstallOn  == 3) {
                 bcopy((void*)(C+1),(void*)&T,n);
                 _MODIF_FCT_INST_(T);
                 _MODIF_FCT_TYP_(3);
              } else {
                 _MODIF_FCT_INST_(VIDE);
                 _MODIF_FCT_TYP_(0);
              }
              InstallOn=0;
           } else {
              bcopy((void*)(C+1),(void*)&W,n);
              executeVar(W);
              /* free context loops */
              if (Do_Evts) { /* quit or cut */
                 /*printf("execCod T_VAR : Evts %d\n",Do_Evts);*/
                 if (InDo) {
                    if (Do_Evts>0) {
                       C=ADo_Leave;
                       I_DO--;
                       InDo = 0;
                       Do_Evts--;
                    } else {
                       C=ADo_Next;
                       Do_Evts=0;
                    }
                 } else { /* quit */
                    C = F;
                 }
              }
           }
           break;
       case T_BKC :
           bcopy((void*)(C+1),(void*)&W,n);
           execLib(W);
           break;
       case T_BKC1 : /* like makeFct */
           bcopy((void*)(C+1),(void*)&W,n);
           /* try to modify the code */
           if (VARS==2) { /* VARS UP */
              if ((T = varByName(W)) != VIDE) {
                 *C = T_VAR;
              } else {
                 if ((T = fctByName(W)) != VIDE) {
                    *C = T_FCT;
                    FR = (struct Fct *)T;
                    T = FR->c;
                 }
              }
           } else {
              if ((T = fctByName(W)) != VIDE) {
                 *C = T_FCT;
                 FR = (struct Fct *)T;
                 T = FR->c;
              } else {
                 if ((VARS==1) && ((T = varByName(W)) != VIDE)) {
                    *C = T_VAR;
                 }
              }
           }
           if ((Code)*C != T_BKC1) { /* code is updated */
              bcopy((void*)&T, (void*)(C+1),n);
              C-=(n+1);       /* it must be executed */
           }
           break;
       case T_NOP :
       case T_CHAS :
       case T_VARS :
       case T_FCTDWS :
           break;
       default :
           messErr(11);
       }
       C+= n+1;
    }
    D_Cod--;
    if (ea) tellOnErr(VIDE);
}
Пример #15
0
void CEgIStream::Read() {
	unsigned char c = GetByteSW();

	while ( noErr() && c != 13 && c != 9 && c != 32 && c != 10 ) 		// Stop on a CR, LF, space or error
		c = GetByte();
}