home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 52 / af052sub.adf / lyr-o-mat.lha / Lyr-O-Mat / Source / Source.lha / words_replace.c < prev    next >
C/C++ Source or Header  |  1993-04-23  |  2KB  |  88 lines

  1.  
  2. #include "words.h"
  3.  
  4.  
  5. void ReplaceLine()
  6. {
  7.  long   count;
  8.  UBYTE *p;
  9.  ULONG  level = 8;
  10.  ULONG  end   = FALSE;
  11.  while((level--) && (!end))
  12.  {
  13.   count = 0L;
  14.   p = winfo.nach;
  15.   while(*p)
  16.   {
  17.    if(*p == '>')
  18.    {
  19.     count++;
  20.    }
  21.    p++;
  22.   }
  23.   if(count)
  24.   {
  25.    while(count)
  26.    {
  27.     ReplaceLineA(winfo.nach);
  28.     --count;
  29.    }
  30.   }
  31.   else end = TRUE;
  32.  }
  33. }
  34.  
  35. void ReplaceLineA(UBYTE *von)
  36. {
  37.  UBYTE *tline;
  38.  long len;
  39.  struct classnode *cl,*cl1;
  40.  ULONG  word;
  41.  UBYTE *rep;
  42.  UBYTE *orig = von;
  43.  while(*orig)
  44.  {
  45.   if(*orig == '>')  /* prefix found */
  46.   {
  47.    cl1  = NULL;
  48.    cl = (struct classnode *)winfo.class.lh_Head;
  49.    while(cl->cl_Node.ln_Succ != NULL)
  50.    {
  51.     if((*(orig + 1) == *(cl->cl_Node.ln_Name)) && (*(orig + 2) == *(cl->cl_Node.ln_Name + 1)))
  52.     {
  53.      if(!strncmp(orig + 1,cl->cl_Node.ln_Name,(long)strlen(cl->cl_Node.ln_Name)))
  54.      {
  55.       cl1 = cl;
  56.       break;
  57.      }
  58.     }
  59.     cl = (struct classnode *)cl->cl_Node.ln_Succ;
  60.    }
  61.    if(cl1)    /* cmd found */
  62.    {
  63.     word = (ULONG)RangeRand(cl1->cl_NumWords);
  64.     rep =  (NumToNode(&cl->cl_Words,word))->ln_Name;
  65.     len = (long)(orig - von);
  66.     if(len >= 0)
  67.     {
  68.      if(tline = (UBYTE *)calloc(1,strlen(von) + strlen(cl->cl_Node.ln_Name) + strlen(rep) + 2L))
  69.      {
  70.       memcpy(tline,von,len);
  71.       strcat(tline,rep);
  72.       strcat(tline,von + len + strlen(cl->cl_Node.ln_Name) + 1);
  73.       if(winfo.nach)
  74.       {
  75.        free(winfo.nach);
  76.        winfo.nach = strdup(tline);
  77.       }
  78.       free(tline);
  79.       return;
  80.      }
  81.     }
  82.    }
  83.   }
  84.   orig++;
  85.  }
  86. }
  87.  
  88.