Пример #1
0
void initVar(char *Lib)
{
void * M, *L;
struct Var * N;
   if ((M = malloc(sizeof(struct Var))) == NULL) stopErr("initVar","malloc");
   if ((L = malloc(strlen(Lib)+1)) == NULL) stopErr("initVar","malloc");
   strcpy((char*)L,Lib);
   N = (struct Var*)M;
   N->l = (char*)L;
   N->n = stackV;
   N->t = VT_I;
   stackV = M;
}
Пример #2
0
static void addFoncT(char *l, void (*f)(void), short T, short F)
{
char *LMax;
    if (NBFonc >= NBFONC) stopErr("addFonc : NBFONC !",NULL);
    LMax = Libelles + (NBFONC*NBCMOY);
    if (pLibs + strlen(l) + 1 >= LMax) stopErr("addFonc : Libelles !",NULL);
    Fonctions[NBFonc].nam = pLibs;
    Fonctions[NBFonc].typ = T;
    Fonctions[NBFonc].fam = F;
    Fonctions[NBFonc++].fct = f;
    strcpy(pLibs,l);
    pLibs += strlen(l);
    *pLibs++ = '\0';
}
Пример #3
0
void initFct(char *Lib, int typ)
{
void * M, *L;
struct Fct * N;
   if ((M = malloc(sizeof(struct Fct))) == NULL) stopErr("initFct","malloc");
   if ((L = malloc(strlen(Lib)+1)) == NULL) stopErr("initFct","malloc");
   strcpy((char*)L,Lib);
   N = (struct Fct*)M;
   N->l = (char*)L;
   N->n = stackF;
   N->c = VIDE;
   N->typ = typ;
   stackF = M;
}
Пример #4
0
int MakeTask (void * A)
{
int i, n, pid;
char * NF, buf[50];
      i = FctInTask-1;
      if ((pid = fork()) == -1) stopErr("IF_NewTask","fork");
      if (pid == 0) { /* fils */
         ITASK=FctInTask;  /* TASK 0 is the interractive one */
         NF = FicCons(ITASK);
         n = i+1;
         if ((i=open(NF,O_CREAT|O_RDWR|O_TRUNC,0600)) < 0) perror(NF);
         else {
            sprintf(buf,"Task #%d console :\n",n);
            write(i,buf,strlen(buf));
            dup2(i,1);
            dup2(i,2);
            close(i);
            close(0);
         }
      } else {
         TASKp[i] = pid;
         putLong(FctInTask);
         TASKf[i]=A;
         FctInTask=0;
      }
      return(pid);
}
Пример #5
0
void dump_marque(int fd, char C)
{
char b[LMARK+1];
   sprintf(b,"<%c>",C);
   if ((write (fd, (void*)b, LMARK)) != LMARK)
       stopErr("dump","marque");
}
Пример #6
0
void putString(char * S)
{
void * M;
int i;
    i = i_StackC;
    if (i == LSTACKC) stopErr("putString",NULL);
    if ((M = malloc(strlen(S)+1)) == NULL) stopErr("putString","malloc");
#ifdef DEBUG_M
    printf("New String address : %lu \n",(unsigned long)M);
#endif
    strcpy((char*)M,S);
    if (fctEnCours) makeFct(T_CHA,M);
    else {
      stackC[i++] = (char*)M;
      _MODIF_i_StackC_(i);
    }
}
Пример #7
0
void restore_marque(int fd, char C)
{
char b[LMARK+1];
   /* printf("Restore %c ! \n", C); */
   if ((read(fd, (void*)b, LMARK)) == LMARK)
       if (b[1] == C) return;
   stopErr("restore","marque");
}
Пример #8
0
Файл: mth.c Проект: pfoubet/Nife
void TH_create(void) /* create current thread variables */
{
void * M;
struct TH_Base * A;
    pthread_once(&k_Init, make_keys);
    if ((M = pthread_getspecific(k_Base)) == NULL) {
        if ((M=malloc(sizeof(struct TH_Base)))==NULL)
            stopErr("TH_create","malloc");
        pthread_setspecific(k_Base, M);
        /* initialisation */
        A = (struct TH_Base *)M;
        A->stk_N = VIDE;
        A->Fct_Inst = VIDE;
        A->netKEY = 0;
        A->NbLig = 10;
        A->NbTab = 6;
        A->Vars = 1;
        A->FcType = 0;
        A->EchoOff = 0;
        A->Double = 0;
        A->ModePr = 0;
        A->Run = 1;
        A->WaitPid = 0;
        A->fctEnC = 0;
        A->strEnC = 0;
        A->inSonP = 0;
        A->i_stkL = 0;
        A->i_stkC = 0;
        A->Fd_In = 0;
        A->i_Ts = 0;
        pthread_setspecific(k_StkN, (void*)&(A->stk_N));
        pthread_setspecific(k_FIns, (void*)&(A->Fct_Inst));
        pthread_setspecific(k_NetK, (void*)&(A->netKEY));
        pthread_setspecific(k_NLig, (void*)&(A->NbLig));
        pthread_setspecific(k_NTab, (void*)&(A->NbTab));
        pthread_setspecific(k_Vars, (void*)&(A->Vars));
        pthread_setspecific(k_FTyp, (void*)&(A->FcType));
        pthread_setspecific(k_Echo, (void*)&(A->EchoOff));
        pthread_setspecific(k_Doub, (void*)&(A->Double));
        pthread_setspecific(k_modPr, (void*)&(A->ModePr));
        pthread_setspecific(k_StkL, (void*)(A->stk_L));
        pthread_setspecific(k_iStL, (void*)&(A->i_stkL));
        pthread_setspecific(k_StkC, (void*)(A->stk_C));
        pthread_setspecific(k_iStC, (void*)&(A->i_stkC));
        pthread_setspecific(k_FdIn, (void*)&(A->Fd_In));
        pthread_setspecific(k_iTs, (void*)&(A->i_Ts));
        pthread_setspecific(k_bufC, (void*)(A->BufC));
        pthread_setspecific(k_bufP, (void*)(A->BufP));
        pthread_setspecific(k_bufP2, (void*)(A->BufP2));
        pthread_setspecific(k_trSu, (void*)(A->trSuite));
        pthread_setspecific(k_Run, (void*)&(A->Run));
        pthread_setspecific(k_WPid, (void*)&(A->WaitPid));
        pthread_setspecific(k_fEnC, (void*)&(A->fctEnC));
        pthread_setspecific(k_sEnC, (void*)&(A->strEnC));
        pthread_setspecific(k_inSP, (void*)&(A->inSonP));
        pthread_setspecific(k_EnvI, (void*)&(A->Env_Int));
    }
}
Пример #9
0
char * DumpRest_ext(char * L)
{
void * M;
char *F;
   if ((M = malloc(strlen(L)+5)) == NULL) stopErr("DumpRest_ext","malloc");
   F = (char*)M;
   sprintf(F,"%s.nblf",L);
   return F;
}
Пример #10
0
char * restore_eltC(int fd)
{
uint32_t l;
void * M;
    read(fd, (void*)&l, sizeof(l));
    if ((M = malloc(l+1)) == NULL) stopErr("restore_eltC","malloc");
    read(fd, M, l+1);
    return (char*)M;
}
Пример #11
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;
}
Пример #12
0
void IF_new_stackC(void)
{
  if (G_i_TStackC == LSTACKS) {
       messErr(60); return;
  }
  G_TiStackC[G_i_TStackC] = i_StackC;
  G_TStackC[G_i_TStackC++] = stackC;
  stackC = G_TStackC[G_i_TStackC];
  i_StackC = G_TiStackC[G_i_TStackC];
  if (stackC == (char **)0) {
     if ((stackC = (char**)malloc(sizeof(char**)*LSTACKC)) == NULL)
          stopErr("IF_new_stackC","malloc");
     i_StackC=0;
  }
}
Пример #13
0
void IF_finFct(void)
{
void * M;
struct Fct * F;
int i,l, *ea, *Ea;
   if ((M = malloc((3*sizeof(int))+i_cod)) == NULL)
                                       stopErr("IF_finFct","malloc");
   ea = (int*)M;
   *ea++ = i_cod;
   *ea=0;
   Ea=ea+1;
   *Ea=0;
   /* on remplace tous les MYSELF */
   l = sizeof(M);
   for (i=0; i<i_cod; i+=(l+1)) {
      if (cod[i]==T_MYSF) {
            cod[i] = T_FCT;
            bcopy((void*)&M,(void*)&cod[i+1],l);
      } else  {
         if (cod[i]==T_ONER) {
            if (*ea==0) *ea = i;
            else {
               messErr(46);
               return;
            }
         } else {
            if (cod[i]==T_END) {
               if (*Ea==0) *Ea = i;
               else {
                  messErr(47);
                  return;
               }
            }
         }
      }
   }
   bcopy((void*)cod,(void*)((char*)M+(3*sizeof(int))),i_cod);
   F=putCodeFct(M);
   if (F->typ) {
      F->typ=2;
      addFonU(F->l,M);
   }
   /* printf("Total Fct : %d + %d !\n",i_cod,(3*sizeof(int))); */
   _MODIF_fctEnCours_(0);
}
Пример #14
0
static int triList(short F)
{
void * M;
char * T;
int i,j, NbF;
   if (ListFonc != (char**)NULL) free((void*)ListFonc);
   if ((M = malloc(sizeof(char*)* NBFonc)) == NULL) stopErr("triList","malloc");
   ListFonc = (char**)M;
   j=0;
   for(i=0;i<NBFonc;i++) {
      if (Fonctions[i].fam & F) ListFonc[j++]=Fonctions[i].nam;
   }
   NbF = j;
   for(i=0; i<NbF-1; i++) /* avant NbF-2 */
      for(j=i+1; j<NbF; j++)
        if(strcmp(ListFonc[j],ListFonc[i]) < 0) {
          T=ListFonc[i]; ListFonc[i]=ListFonc[j]; ListFonc[j]=T;
        }
   return NbF;
}
Пример #15
0
void addFD(int fd, char*S)
{
void *M;
    iFD++;
    /* printf("addFD iFD=%d\n",iFD); */
    if (iFD == FDMAX) {
       iFD--;
       messErr(45);
       return;
    }
    _MODIF_FD_IN_(fd);
    FD_T[iFD]=fd;
    FD_L[iFD]=0;
    if ((M = malloc(strlen(S)+1)) == NULL) stopErr("addFD","malloc");
#ifdef DEBUG_M
    printf("New String address : %lu \n",(unsigned long)M);
#endif
    strcpy((char*)M,S);
    FD_N[iFD]=M;
}
Пример #16
0
void suiteBackC1(char *S)
{
void * M;
    dropTrSuite();
    if (strlen(S) > LDFLT) {
        messErr(9);
        return;
    }
    if (S[strlen(S)-1] != '`') {
        messErr(44);
        return;
    }
    S[strlen(S)-1] = '\0';
    if ((M = malloc(strlen(S)+1)) == NULL) stopErr("suiteBackC1","malloc");
#ifdef DEBUG_M
    printf("New String address : %lu \n",(unsigned long)M);
#endif
    strcpy((char*)M,S);
    if (fctEnCours) makeFct(T_BKC1,M);
    else messErr(13);
}
Пример #17
0
static void IF_catC_i(int i)
{
char * S1, * S2, *S;
int l, I;
    I = i_StackC;
    if (I>1) {
       S1 = stackC[I-2];
       S2 = stackC[I-1];
       l = strlen(S1) + strlen(S2) + i + 1;
       if ((S = (char*)malloc(l+1)) == NULL) stopErr("IF_catC_i","malloc");
       strcpy(S,S1);
       if (i) strcat(S, " ");
       strcat(S,S2);
       IF_dropC();
       IF_dropC();
       I = i_StackC;
       stackC[I++]=S;
       _MODIF_i_StackC_(I);
    } 
    else messErr(19);
}