//#include "Unix.h"
//#include <time.h>
#include "stdafx.h"   //MS Windows
#include "Strawberry.h"

#if !CONSOLE
#include "afxmt.h" //CEvent
//#include "Strawberry.h"

#include "string.h"
#include "commdlg.h"  // WIN16

#include "MainFrm.h"
#include "StrawberryDoc.h"
#include "New_Class.h"

#include "dispdrv.h" //Angel
#include "smapi.h"
#include "mmsystem.h" // winmm.lib
//#include "Windows.h"
//#include "Winbase.h"  // Kernel32.lib
#endif  // !CONSOLE
#if UNIX
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#endif // UNIX 
#if !CONSOLE
#include <winsock.h>
#endif  // !CONSOLE
#if MY_SQL
#include "mysql.h"
#endif // MY_SQL
#include <math.h>

#include "ComSupport/events/comevtclient.h" // Plamen
static ComSupport::CComEvtClient oComEvtClient;
#include "StrawberrySvr.h"

#if PROF
#define NOT_FOR_LIGHT
#else
#define NOT_FOR_LIGHT  if(!(status_fl&512))goto NOT_FOR;
#endif

#define CHECK_TYPE(A,T) if(\
(ObjectStore[ObjectStore[Buda2[Arguments+A]]+4]&ObjectStore[T+5])!=ObjectStore[T+4])\
{error_func3(Arguments,p_line,A,T,0);return(0);}


DWORD new_strlen(DWORD Where)
{
  DWORD i, j;
  BYTE *src = StringStore+Where;
  if (src[0])
  {
    for (i=j=1; src[j]; j++)
      if ((src[j]&0xc0)!=0x80)
        i++;
  }
  else
    i=0;
  return(i);
}
DWORD take_first(DWORD Where, DWORD How)
{
  DWORD i, j;
  BYTE *src = StringStore+Where;
  if (src[0] && How)
  {
    for (i=j=1; 1; j++)
      if (src[j]==0)
        break;
      else if ((src[j]&0xc0)!=0x80)
      {
        if (i==How)
          break;
        i++;
      }
  }
  else
    i=j=0;
  if (i==How)
    return(j);
  else
    return(M1);
}
void error_func3(DWORD Arguments, DWORD p_line, DWORD j, DWORD k, DWORD k2)
{
  DWORD i;

  sprintf(string2,"Runtime Error at step %d:\r\n", 0x10000*lSteps_br+Steps_br-Corection);
  MitiText(string2, &cf_red);
  sprintf(string2,"The argument %d of ", j+1);
  MitiText(string2);
  for (i=sv_c+TT_START-1; i && (i==TT_VAR || // ? i==TT_VAR  when X.run without ()
        (!(Pointers[i]&OBSEG3) || (Program[F_field[D_field[(Pointers[i]&MASKA3)+4]-1]
                  &(M1^(HALF | TP_TEMP_FLAG | OBSEG1 | OBSEG2))]&HALFM)!=p_line)); i--);
  if (i)
    MitiText("the function \"");
  else
  {
    MitiText("the predicate \"");
    for (i=sv_c+TT_START-1; i && (i==TT_VAR || // ?
          (!(Pointers[i]&OBSEG1) || (Program[F_field[D_field[(Pointers[i]&MASKA3)+2]-1]
                   &(M1^(HALF | TP_TEMP_FLAG | OBSEG1 | OBSEG2))]&HALFM)!=p_line)); i--);
  }
  len=0;
  write_p( i, 4, 0);
  MitiText(string2);
  MitiText("\"\r\nis from class \"");
  len=0;
  write_p( ObjectStore[ObjectStore[Buda2[Arguments+j]]+1], 4, 0);
  MitiText(string2);
  if (k2==0)
    MitiText("\" which does not inherit\r\nthe class \"");
  else
    MitiText("\"\r\nwhich does not inherit any of the classes");
  if (k2&HALF)
    MitiText("\r\nwhich are listed in the help like");
  if (k2)
    MitiText(":\r\n\"");
  len=0;
  write_p( ObjectStore[k+1], 4, 0);
  MitiText(string2);
  if (k2)
  {
    MitiText("\" or \"");
    len=0;
    write_p( ObjectStore[(k2&HALFM)+1], 4, 0);
    MitiText(string2);
  }
  MitiText("\".\r\n");
}

#if !CONSOLE
int open_server(int Arguments) // Angele, otvori tuk edin server
{
//the name is in (LPSTR)(StringStore+Buda2[Arguments]
//ObjectStore[ObjectStore_br+7]= pointer to dispach interfase
  COleDispatchDriver Disp;
  CLSID clsid;
  OLECHAR clsidstr[255];
  LPSTR  temp;
  int Disp_res, i;
  COleException Error;

  temp=(LPSTR)(StringStore+Buda2[Arguments]);

  try
  {
		if ((strlen(temp)==38) && (temp[0]=='{') && (temp[37]=='}')) 
		{
			for (i=0;temp[i];i++) clsidstr[i]=temp[i];
			clsidstr[i]=0;
			CLSIDFromString(clsidstr,&clsid);
			Disp_res=Disp.CreateDispatch(clsid,&Error);
		}  
		else
			Disp_res=Disp.CreateDispatch(make_long(StringStore+Buda2[Arguments]),&Error);
	}
	catch(...)
	{
		MitiText("Error: Cannot create Server throws.\r\n", &cf_red);
		return(0);
	}

  if(Disp_res==0)
  {
    MitiText("Cannot open this server.\r\n");
    Error.GetErrorMessage(string3,L_BUFER);
    MitiText(make_utf8(string3));
    sprintf(string2, "Error code:%x\r\n", Error.m_sc);
    MitiText(string2);
    return(0);
  }
  if (Disp.m_lpDispatch==NULL)
  {
    MitiText("No such server.\r\n");
    return(0);
  }      

	ObjectStore[ObjectStore_br+7] = (DWORD)( new COleDispatchDriver(Disp) );
	ObjectStore[ObjectStore_br+8] = M1;
  return(1);
}
void close_server(int k) // Angele, zatvori tuk edin server
{
	if (ObjectStore[k+8]==M2)
	{
    ObjectStore[k+7]=M1;
    return;
	}
	try
	{
		COleDispatchDriver *Disp;
		Disp=(COleDispatchDriver*)ObjectStore[k+7];
		oComEvtClient.DetachEvents(k); // Plamen
		Disp->m_bAutoRelease = TRUE;
		Disp->ReleaseDispatch();
		delete Disp;
	}
	catch(...)
	{
		MitiText("Error: Server throw when was closed.\r\n", &cf_red);
	}
  ObjectStore[k+7]=M1;
}
static DWORD CALLBACK MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
  DWORD i, k, StStr=sv_StStore;
  
  if ((sv_StStore+=cb)>=STRING_STORE && correct_STR_ST() )
  {
    *pcb = 0; // ?
    return 0;
  }
  for(i=0; i<(DWORD)cb; StringStore[StStr++]=pbBuff[i++]);
  if (ch_set)
  {
    StringStore[sv_StStore]=0;
    sv_StStore-=cb;
    sv_StStore+=ChangeCharset(0, ch_set, StringStore+sv_StStore, StringStore+sv_StStore, &k, default_char);
  }
  *pcb = cb;
  return 0;
}
static DWORD CALLBACK StreamInCallbackEd(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
  int i=0;
  char** ppText = (char**) dwCookie;
  char* pText = *ppText;
  for(; i<cb && pText[i]; pbBuff[i]=pText[i], i++);
  *ppText+=i;
  *pcb = i;
  return 0;
}
#endif // !CONSOLE

void close_object(DWORD k)
{
  if (SUBTYPE(ObjectStore[k],CLASS_SYSTEM_FILE))
    fclose((FILE *)ObjectStore[k+2]);
  else if (SUBTYPE(ObjectStore[k],CLASS_SYSTEM_LIST))
  {
    GlobalUnlock((MY_HANDLE)ObjectStore[k+5]);
    GlobalFree((MY_HANDLE)ObjectStore[k+5]);
  }
#if !CONSOLE
  else if (SUBTYPE(ObjectStore[k],C_S_WIN_Embedded))
  {
    CWnd *pWindow=(CWnd*)ObjectStore[k+2];
    close_server(k);
    pWindow->SendMessage(WM_CLOSE);
  }
  else if (SUBTYPE(ObjectStore[k],CLASS_SYSTEM_ActiveX))
    close_server(k);
  else if (SUBTYPE(ObjectStore[k],C_S_WIN))
  {
    CWnd *pWindow=(CWnd*)ObjectStore[k+2];
    if (pWindow==NULL)
      return;
    if (pWindow->IsKindOf(RUNTIME_CLASS(C_FrameWnd)))
    {
      if (((C_FrameWnd*)pWindow)->m_bDialog) // ?
        Wait_d--;
      pWindow->PostMessage(WM_CLOSE);
    }
    else
      pWindow->SendMessage(WM_CLOSE);
  }
  else if (SUBTYPE(ObjectStore[k],CLASS_SYSTEM_DLL)) // Vasko
    AfxFreeLibrary((HINSTANCE)ObjectStore[k+2]);
#endif // !CONSOLE
  else if (SUBTYPE(ObjectStore[k],CLASS_SYSTEM_SOCKET))
#if UNIX
    close(ObjectStore[k+2]);
#else
    closesocket((SOCKET)ObjectStore[k+2]);    
#endif // UNIX
#if MY_SQL
  ///else if (SUBTYPE(ObjectStore[k],CLASS_SYSTEM_MYSQL))
  ///  mysql_close((MYSQL *)(ObjectStore+k+2));    
#endif // MY_SQL
  ObjectStore[k+1]= // size
    ObjectStore[ObjectStore[k]+2]?ObjectStore[ObjectStore[k]+2]:ObjectStore[k+2];
  ObjectStore[k]=0; // dead object
}

DWORD execute(DWORD p_line, DWORD Arguments, DWORD Return)
  {
    DWORD  i, j, t, k, m, n, p;
    char *EnvString;

    my_gl=0;  // move it
    switch (p_line)
    {
     case 0:                       // fail (must to be at case 0)
      return(0);
     case 1:                       // true (must to be at case 1)
      return(1);

#include "cyr_to_lat.h"
#include "Execute.h"

#if !CONSOLE
#include "Graphic.h"
#elif QT_GRAPHIC
#include "Graphic_QT.h"
#endif

     case 203:                     // identity
      Buda1[Return]=Buda1[Arguments];
      Buda2[Return]=Buda2[Arguments];
      return(1);
     case 387:                     // Cut(Depth)
      n=M1;
      if (Buda1[Arguments]==TT_INT)
      {
        k=Buda2[Arguments];
E33:    if ((int)k<0)
        {
          MitiText("Error: The depth for cut must be at least zero!\r\n", &cf_red);
          return(0);
        }
        if (k==0)
          return(1);
        for (m=Stack[stack_br]; --k && m; m=Stack[m]);
        if (m==0)
        {
          MitiText("Error: You cannot cut so deep!\r\n", &cf_red);
          return(0);
        }
        for (m+=n; m<stack_br; Stack[m+=4]|=HALF);
      }
      else if (Buda1[Arguments]==TT_FLOAT)
      {
        float fl=*(float*)&(Buda2[Arguments]);
        k=(DWORD)(int)fl;
        if (fl-(float)k>0.75)
          k++;
        else if (fl-(float)k>0.25)
        {
          k++;
          n=3;
        }
        goto E33;
      }
      return(1);
     case 4:                       // Cut
      for (m=Stack[stack_br]-1; m<stack_br; Stack[m+=4]|=HALF);
      return(1);
     case 125:                      // Terminate
#if !CONSOLE
      if (Buda1[Arguments]==TT_LINK)
      {
        MitiText("Software termination.\r\n");
        return(5);
      }
      else if (Buda1[Arguments]==TT_STR)
        MitiText((LPSTR)(StringStore+Buda2[Arguments]));
      else
      {
        len=0;
        write_p( TT_VAR, 4, Arguments);
        MitiText((LPSTR)string2);
      }
      MitiText("\r\n");
      return(5);
#else
      exit(0);
#endif
     case 7:                       // New line
#if CONSOLE
      printf("\r\n");
#else
      MitiText("\r\n");
#endif // CONSOLE
      return(1);
     case 9:        // Constant
      if (Buda1[Arguments]<TT_USED)
        return(1);  
      else
        return(0);  
     case 10:        // Variable
      if (Buda1[Arguments]==TT_LINK)
        return(1);  
      else
        return(0);
     case 11:        // Number
      if (Buda1[Arguments]==TT_INT || Buda1[Arguments]==TT_FLOAT)
        return(1);  
      else
        return(0);
     case 100:        // is_int
      if (Buda1[Arguments]==TT_INT)
        return(1);  
      else
        return(0);
     case 101:        // is_float
      if (Buda1[Arguments]==TT_FLOAT)
        return(1);  
      else
        return(0);
     case 49:        // is_string
      if (Buda1[Arguments]==TT_STR)
        return(1);  
      else
        return(0);  
     case 50:        // is_object
      if (Buda1[Arguments]==TT_OBJ)
        return(1);  
      else
        return(0);  
     case 12:          // Read 
      gl_read=(Buda1[Arguments+2]==55); // s
#if CONSOLE
      if (Buda1[Arguments+1]==TT_STR)
        printf("%s",(LPSTR)(StringStore+Buda2[Arguments+1])); 
      else if (gl_read)
        printf("Write a string: "); 
      else
        printf("Write a term: "); 
#else
      if (Buda1[Arguments+1]==TT_STR)
        TempStr2=make_long(StringStore+Buda2[Arguments+1]); 
      else if (gl_read)
        TempStr2=_T("Write a string"); 
      else
        TempStr2=_T("Write a term"); 
#endif // CONSOLE
      f_end=i_poin=0;
      string[0]=0;
      for (j=0; !(i=read_n(&k, 0));j++)
      {
        if (j==3)
          break;
        f_end=i_poin=0;
        string[0]=0;
#if CONSOLE
      if (Buda1[Arguments+1]==TT_STR)
        printf("%s",(LPSTR)(StringStore+Buda2[Arguments+1])); 
      else if (gl_read)
        printf("Write a string: "); 
      else
        printf("Write a term: "); 
#else
        string2[strlen(string2)-2]=0;
        gl_read|=2;
#endif // CONSOLE
      }
      if (i)
      {
        if (i!=1)
          return(0); 
        if (k>=MEMORY_c256)
        {
          Buda1[Buda2[Arguments]]=k;
          Buda2[Buda2[Arguments]]=sv_subv;
          for (i=list_br; i; i--, Link[sv_subv++]=buda_br++);
          a1=buda_br;
        }
        else if (k==TT_VAR)
        {
          Buda2[Buda2[Arguments]]=Buda2[buda_br];
          Buda1[Buda2[Arguments]]=Buda1[buda_br];
          Buda1[buda_br]=TT_VAR;
          my_gl=0;
        }
        else
          Buda1[Buda2[Arguments]]=k;
        WILL_CLEAN(Buda2[Arguments]);
        return(1); 
      }
      else
      {
#if TR
        if (my_gl) // ?
          MitiText("System Error! my_gl>0!\r\n");
#endif
        error=0;
        return(0);  
      }
     case 13:        // Write
      if (Buda1[Arguments]==TT_STR)
      {
#if CONSOLE
        printf("%s",(LPSTR)(StringStore+Buda2[Arguments]));
#else
        ChangeCharset(ch_set, 0, StringStore+Buda2[Arguments], (BYTE *)string2, &k, default_char);
        MitiText(string2, 
          (Buda1[Arguments+1]==TT_OBJ && SUBTYPE(ObjectStore[Buda2[Arguments+1]],CLASS_SYSTEM_FONTMASK))
            ?(CHARFORMAT*)(ObjectStore+Buda2[Arguments+1]+2):pFontMask );
#endif // CONSOLE
        return(1);
      }
     case 3:        // Writeq
      len=0;
      write_p( TT_VAR, ((p_line==13)?4:0), Arguments);
#if CONSOLE
      printf("%s",(LPSTR)string2);
#else
      ChangeCharset(ch_set, 0, (BYTE *)string2, (BYTE *)string3, &k, default_char);
      MitiText((LPSTR)string3,
        (p_line==13 && Buda1[Arguments+1]==TT_OBJ
          && SUBTYPE(ObjectStore[Buda2[Arguments+1]],CLASS_SYSTEM_FONTMASK))
          ?(CHARFORMAT*)(ObjectStore+Buda2[Arguments+1]+2):pFontMask );
#endif // CONSOLE
      return(1);
     case 51:        // print term to String
      if (Buda1[Arguments]==TT_STR)
      {
        Buda1[Return]=TT_STR;
        Buda2[Return]=Buda2[Arguments];
        return(1);
      }
     case 381:        // printq
      len=0;
      write_p( TT_VAR, ((p_line==51)?6:2), Arguments);
      Buda1[Return]=TT_STR;
      Buda2[Return]=sv_StStore; // len>0
      strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR)string2);
      if ((sv_StStore+=len+1)>=STRING_STORE && correct_STR_ST() )
      {
FULL:   MessageBoxA(NUL, "The string store is full.", "No Space", MB_OK | MB_ICONSTOP);
        return(3);
      }
      return(1);
     case 240:  // arrayArg
      if (Buda2[Arguments+1]<ObjectStore[Buda2[Arguments]+2])
      {
        Buda1[Return]=ObjectStore[Buda2[Arguments]+6];
        Buda2[Return]=((LPDWORD)ObjectStore[Buda2[Arguments]+4])[Buda2[Arguments+1]];
        return(1);
      }
      else
        return(0);
     case 241:  // arrayArgOut
      if (Buda2[Arguments+1]<ObjectStore[Buda2[Arguments]+2])
      {
        if (the_free_container!=M1)
        {
          i=the_free_container;
          the_free_container=ObjectStore[the_free_container+6];
        }
        else
        {
          i=ObjectStore_br;
          ObjectStore[ObjectStore_br]=CLASS_SYSTEM_CONTAINER;
          if ((ObjectStore_br+=8)>=OBJ_STORE && correct_OBJ_ST() )
            goto FULL2;
        }
        Buda1[Return]=TT_OBJ;
        Buda2[Return]=i;
        ObjectStore[i+1]=M1;  // object name
        ObjectStore[i+2]=M1; // System Name
        ObjectStore[i+3]=M1; // Name
        ObjectStore[i+4]=HALF | QUARTER | 12; // MS type variant (output array)
        ObjectStore[i+5]=M1;
        ObjectStore[i+6]=Buda2[Arguments+1]; // index
        ObjectStore[i+7]=Buda2[Arguments];   // array
        return(1);
      }
      else
        return(0);
     case 230:  // array.
      i=CreateArray(Buda2[Arguments+1]);
      if (Buda1[Arguments]!=TT_LINK)
      {
        if (Pointers[Buda1[Arguments]]&OBSEG5) // constant
        {
          MitiText("Error: This name is already used.\r\n", &cf_red);
          return(0);
        }
        else
        {
          put_in_f(i, Buda1[Arguments], 6, OBSEG5);
          ObjectStore[i+1]=Buda1[Arguments];   // Name
        }
      }
      if (Return!=M1)
      {
        Buda1[Return]=TT_OBJ;
        Buda2[Return]=i;
      }
      if (Buda1[Arguments+2]==TT_LINK)
      {
        ObjectStore[i+6]=TT_INT; // Type
        k=0;
      }
      else
      {
        ObjectStore[i+6]=Buda1[Arguments+2]; // Type
        k=Buda2[Arguments+2];
      }
      {
      DWORD *Temp=(LPDWORD)ObjectStore[i+4];
      for (i=Buda2[Arguments+1]; i--; Temp[i]=k);
      }
      return(1);
     case 217:  // io
      if (the_free_container!=M1)
      {
        i=the_free_container;
        the_free_container=ObjectStore[the_free_container+6];
      }
      else
      {
        i=ObjectStore_br;
        ObjectStore[ObjectStore_br]=CLASS_SYSTEM_CONTAINER;
        if ((ObjectStore_br+=8)>=OBJ_STORE && correct_OBJ_ST() )
          goto FULL2;
      }
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=i;
      ObjectStore[i+1]=M1;  // object name
      ObjectStore[i+2]=M1;  // Name
      ObjectStore[i+3]=M1;  // Name
      if (Buda1[Arguments]==TT_LINK)
      {
        ObjectStore[i+4]=HALF | 12; // io | MS type variant
        ObjectStore[i+5]=Buda1[Buda2[Arguments]]; // Type
        ObjectStore[i+6]=Buda2[Buda2[Arguments]]; // Value
        ObjectStore[i+7]=Buda2[Arguments]; // var for return
      }
      else
      {
        ObjectStore[i+4]=12; // MS type variant
        ObjectStore[i+5]=Buda1[Arguments]; // Type
        ObjectStore[i+6]=Buda2[Arguments]; // Value
        ObjectStore[i+7]=HALF; // var for return
      }
      return(1);
     case 218:  // int2
      m=2; p=TT_INT;
      goto types;
     case 219:  // int4
      m=3; p=TT_INT;
      goto types;
     case 220:  // float4
      m=4; p=TT_FLOAT;
      goto types;
     case 221:  // float8
      m=5; p=TT_FLOAT;
      goto types;
     case 222:  // str
      m=8; p=TT_STR;
      goto types;
     case 223:  // disp_interface
      m=9; p=TT_OBJ;
types:Buda1[Return]=TT_OBJ;
      if (Buda1[Arguments]==TT_OBJ && ObjectStore[Buda2[Arguments]]==CLASS_SYSTEM_CONTAINER)
      {
        if (ObjectStore[Buda2[Arguments]+4]!=(HALF | 12))
        {
          MitiText("Error: ", &cf_red);
          MitiText("You can nest modifiers only if the second one is \"io\".\r\nFor example, you can use \"int4(io(X))\" but not \"int4(str(X))\".\r\n");
          return(0);
        }
        if (p!=ObjectStore[Buda2[Arguments]+5])
        {
          MitiText("Error: ", &cf_red);
          MitiText("These types do not fit.\r\n");
          return(0);
        }
        Buda2[Return]=Buda2[Arguments];
        ObjectStore[Buda2[Arguments]+4]=HALF | m;
      }
      else
      {
        if (the_free_container!=M1)
        {
          i=the_free_container;
          the_free_container=ObjectStore[the_free_container+6];
        }
        else
        {
          i=ObjectStore_br;
          ObjectStore[ObjectStore_br]=CLASS_SYSTEM_CONTAINER;
          if ((ObjectStore_br+=8)>=OBJ_STORE && correct_OBJ_ST() )
            goto FULL2;
        }
        Buda2[Return]=i;
        ObjectStore[i+1]=M1;  // object name
        ObjectStore[i+2]=M1;  // Name
        ObjectStore[i+3]=M1;  // Name
        ObjectStore[i+4]=m;   // MS type m
        ObjectStore[i+5]=Buda1[Arguments]; // Type
        ObjectStore[i+6]=Buda2[Arguments]; // Value
        ObjectStore[i+7]=HALF; // var for return
      }
      return(1);
     case 215:  // function = for named variables
      Buda1[Return]=TT_OBJ;
      if (Buda1[Arguments+1]==TT_OBJ && ObjectStore[Buda2[Arguments+1]]==CLASS_SYSTEM_CONTAINER)
      {
        if (ObjectStore[Buda2[Arguments+1]+2]!=M1)
        {
          MitiText("Error: ", &cf_red);
          MitiText("You cannot give two names for one argument.\r\n");
          return(0);
        }
        Buda2[Return]=Buda2[Arguments+1];
        ObjectStore[Buda2[Arguments+1]+2]=Buda1[Arguments]; // Type
        ObjectStore[Buda2[Arguments+1]+3]=Buda2[Arguments]; // Value
      }
      else
      {
        if (the_free_container!=M1)
        {
          i=the_free_container;
          the_free_container=ObjectStore[the_free_container+6];
        }
        else
        {
          i=ObjectStore_br;
          ObjectStore[ObjectStore_br]=CLASS_SYSTEM_CONTAINER;
          if ((ObjectStore_br+=8)>=OBJ_STORE && correct_OBJ_ST() )
            goto FULL2;
        }
        Buda2[Return]=i;
        ObjectStore[i+1]=M1;  // object name
        ObjectStore[i+2]=Buda1[Arguments]; // Type
        ObjectStore[i+3]=Buda2[Arguments]; // Value
        ObjectStore[i+4]=12; // MS type variant
        ObjectStore[i+5]=Buda1[Arguments+1]; // Type
        ObjectStore[i+6]=Buda2[Arguments+1]; // Value
        ObjectStore[i+7]=HALF; // var for return
      }
      return(1);
     case 254:  // split
      {
      char *SplitString=(LPSTR)(StringStore+Buda2[Arguments]),
            SplitBy=StringStore[Buda2[Arguments+1]];

      i=Buda2[Arguments+2];
      for(j=0; SplitString[j]!=0 && i; j++)
        if (SplitString[j]==SplitBy)
          i--;
      if (SplitString[j]==0 && i>0)
        return(0);
      k=j;
      i=sv_StStore;
      for(; SplitString[j]!=0 && SplitString[j]!=SplitBy; StringStore[i++]=SplitString[j++]);
      if (i==sv_StStore)
        Buda2[Return]=0;
      else if (SplitString[j]==0)
        Buda2[Return]=Buda2[Arguments]+k;
      else
      {
        StringStore[i]=0;
        Buda2[Return]=sv_StStore;
        if ((sv_StStore=i+1)>=STRING_STORE && correct_STR_ST() )
          goto FULL;
      }
      Buda1[Return]=TT_STR;
      return(1);
      }
     case 164:        // string_from_ASCII
      if (ch_set)
      {
        if (Buda2[Arguments]>=TT_START)
          return(0);
        Buda1[Return]=TT_STR;
        Buda2[Return]=2*Buda2[Arguments];
        return(1);
      }
#if PROF==0
      else if (!(status_fl&512))
      {
        MitiText("Error: In the Light edition you cannot use string_from_ASCII to create Unicode strings. Do this with another char set or with higher edition.\r\n", &cf_red);
        return(0);
      }
#endif
      else
      {
        k=Buda2[Arguments]; 
        if (k<0x80)
          Buda2[Return] = 2*k;
        else if (k>=0x80000000)
          return(0);
        else
        {
          Buda2[Return]=sv_StStore;
          sv_StStore+=unicodeToUTF8(k, (unsigned char*)(StringStore + sv_StStore));
          StringStore[sv_StStore++] = 0;
          if (sv_StStore>=STRING_STORE && correct_STR_ST() )
            goto FULL;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 182:        // first_ASCII
      if (ch_set)
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]=(BYTE)((LPSTR)(StringStore+Buda2[Arguments]))[0];
        return(1);
      }
#if PROF==0
      else if (!(status_fl&512))
      {
        MitiText("Error: In the Light edition you cannot use first_ASCII on Unicode strings. Do this with another char set or with higher edition.\r\n", &cf_red);
        return(0);
      }
#endif
      else
      {
        BYTE *src = StringStore+Buda2[Arguments];
        if (src[0]<0x80)
          Buda2[Return] = (BYTE)(src[0]);
        else
        {
          if (readUTF8(src, &k)==0) // error
          {
            MitiText("Error: The argument of first_ASCII is not an Unicode string.\r\n", &cf_red);
            return(0);
          }
          Buda2[Return] = k;
        }
        Buda1[Return]=TT_INT;
        return(1);
      }
     case 412:        // max_integer
      Buda1[Return]=TT_INT;
      Buda2[Return]=HALFM;
      return(1);
     case 413:        // min_integer
      Buda1[Return]=TT_INT;
      Buda2[Return]=HALF;
      return(1);
     case 183:        // nl constant
      Buda1[Return]=TT_STR;
      Buda2[Return]=2*'\n';
      return(1);
     case 184:        // pi constant
      Buda1[Return]=TT_FLOAT;
      *(float*)&(Buda2[Return])=(float)3.14159;
      return(1);
     case 214:  // is
      if (Buda1[Arguments]==TT_LINK)
      {
#if TR
        if (Buda1[Buda2[Arguments]]!=TT_VAR) // this is for insurance
          MitiText("Error in is\r\n", &cf_red);
#endif
        j=Buda2[Arguments];
        t=(Buda1[Arguments+1]==TT_LINK)?Buda2[Arguments+1]:(Arguments+1);
        if (j==t)
          return(1);
        if (Buda1[t]>=MEMORY_c256)
        {
          p=i=0;
E34:      buf_7[p++]=i;
          buf_7[p++]=t;
          i=Chfil_v[Buda1[t]-MEMORY_c256];
E35:      for (t=Link[Buda2[t]+ --i]; Buda1[t]==TT_LINK; t=Buda2[t]);   /* if X=f(X) */
          if (t==j)
            return(0);
          else if (Buda1[t]>=MEMORY_c256)
            goto E34;
E36:      if (i)
          {
            t=buf_7[p-1];
            goto E35;
          }
          if (p)
          {
            t=buf_7[--p];
            i=buf_7[--p];
            goto E36;
          }
        }
        Buda1[j]=Buda1[Arguments+1];
        Buda2[j]=Buda2[Arguments+1];
        WILL_CLEAN(j);
        return(1);
      }
      else if (Buda1[Arguments]==Buda1[Arguments+1]
                && (Buda2[Arguments]==Buda2[Arguments+1] || Buda1[Arguments]<TT_VAR
                   || (Buda1[Arguments]>=TT_START && Buda1[Arguments]<MEMORY_c256)))
        return(1);
      else if (Buda1[Arguments]<=TT_OBJ && Buda1[Arguments]>TT_LINK
                 && Buda1[Arguments+1]<=TT_OBJ && Buda1[Arguments+1]>TT_LINK)
        goto E11;
      return(0); // try unification
     case 67:        // copy X<>=Y
      if (Buda1[Arguments]==TT_LINK)
      {
        j=Buda2[Arguments];
        t=(Buda1[Arguments+1]==TT_LINK)?Buda2[Arguments+1]:(Arguments+1);
        if (j==t)
          return(0);  // ?
        if (Buda1[t]>=MEMORY_c256)
        {
          p=i=0;
E34_d:    buf_7[p++]=i;
          buf_7[p++]=t;
          i=Chfil_v[Buda1[t]-MEMORY_c256];
E35_d:    for (t=Link[Buda2[t]+ --i]; Buda1[t]==TT_LINK; t=Buda2[t]);   /* if X=f(X) */
          if (t==j)
            return(0);
          else if (Buda1[t]>=MEMORY_c256)
            goto E34_d;
E36_d:    if (i)
          {
            t=buf_7[p-1];
            goto E35_d;
          }
          if (p)
          {
            t=buf_7[--p];
            i=buf_7[--p];
            goto E36_d;
          }
        }
        Link[sv_subv++]=Buda2[j];
        Link[sv_subv++]=j;
        Link[sv_subv++]=Buda1[j];
        Stack[stack_br+3]|=QUARTER;  // No Cut!
        Buda1[j]=Buda1[Arguments+1];
        Buda2[j]=Buda2[Arguments+1];
        return(1);
      }
      else if (Buda1[Arguments]==TT_OBJ && ObjectStore[Buda2[Arguments]]==CLASS_SYSTEM_CONTAINER)
      {
        if (ObjectStore[Buda2[Arguments]+4]&OBSEG1) // set property
        {
#if !CONSOLE
          i=GetProperty(ObjectStore[Buda2[Arguments]+7], (HALF|ObjectStore[Buda2[Arguments]+6]), 0);
          Link[sv_subv++]=Buda2[0]; // old value
          Link[sv_subv++]=Buda1[0]; // old value type
          Link[sv_subv++]=ObjectStore[Buda2[Arguments]+6]; // property
          Link[sv_subv++]=(QUARTER|ObjectStore[Buda2[Arguments]+7]);  // server
          Buda1[0]=TT_VAR; // Use G_Return
          i=SetProperty(ObjectStore[Buda2[Arguments]+7], ObjectStore[Buda2[Arguments]+6], Arguments+1, p_line);

          ObjectStore[Buda2[Arguments]+6]=the_free_container;
          the_free_container=Buda2[Arguments];
          return(i);
#endif // !CONSOLE        
        }
        else if (Buda1[Arguments+1]==ObjectStore[ObjectStore[Buda2[Arguments]+7]+6])
        {
          Link[sv_subv++]=((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])[ObjectStore[Buda2[Arguments]+6]];// old value
          Link[sv_subv++]=ObjectStore[Buda2[Arguments]+6]; // index
          Link[sv_subv++]=(HALF|ObjectStore[Buda2[Arguments]+7]);

          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=Buda2[Arguments+1];
        }
        else if (ObjectStore[ObjectStore[Buda2[Arguments]+7]+6]==TT_STR)
        {
          Link[sv_subv++]=((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])[ObjectStore[Buda2[Arguments]+6]];// old value
          Link[sv_subv++]=ObjectStore[Buda2[Arguments]+6]; // index
          Link[sv_subv++]=(HALF|ObjectStore[Buda2[Arguments]+7]);

          len=0;
          write_p( TT_VAR, 6, Arguments+1);
          strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR)string2);
          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=sv_StStore; // len>0
          if ((sv_StStore+=len+1)>=STRING_STORE && correct_STR_ST() )
            goto FULL;
        }
        else if (Buda1[Arguments+1]==TT_FLOAT && ObjectStore[ObjectStore[Buda2[Arguments]+7]+6]==TT_INT)
        {
          Link[sv_subv++]=((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])[ObjectStore[Buda2[Arguments]+6]];// old value
          Link[sv_subv++]=ObjectStore[Buda2[Arguments]+6]; // index
          Link[sv_subv++]=(HALF|ObjectStore[Buda2[Arguments]+7]);

          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=(int)(*(float*)&(Buda2[Arguments+1]));
        }
        else if (Buda1[Arguments+1]==TT_INT && ObjectStore[ObjectStore[Buda2[Arguments]+7]+6]==TT_FLOAT)
        {
          Link[sv_subv++]=((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])[ObjectStore[Buda2[Arguments]+6]];// old value
          Link[sv_subv++]=ObjectStore[Buda2[Arguments]+6]; // index
          Link[sv_subv++]=(HALF|ObjectStore[Buda2[Arguments]+7]);

          float fl;
          fl=(float)(int)(Buda2[Arguments+1]);
          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=*(int*)&fl;
        }
        else
        {
          sprintf(string2,"Runtime Error at step %d: ", 0x10000*lSteps_br+Steps_br-Corection);
          MitiText(string2, &cf_red);
          MitiText("Different types in <>=\r\n");
          return(0);
        }
        ObjectStore[Buda2[Arguments]+6]=the_free_container;
        the_free_container=Buda2[Arguments];
        Stack[stack_br+3]|=QUARTER;  // No Cut!
        return(1);
      }
      MitiText("Error in <>= ", &cf_red);
      MitiText("The left argument cannot change its value.\r\n");
      return(0);
     case 68:        // copy X<>=Y
      i=Link[--sv_subv];
      j=Link[--sv_subv];
      if (i&HALF) // array
        ((LPDWORD)ObjectStore[(i&MASKA2)+4])[j]=Link[--sv_subv]; // old value
      else if (i&QUARTER) // property
      {
        Buda1[0]=Link[--sv_subv];
        Buda2[0]=Link[--sv_subv];
        SetProperty((i&MASKA2), j, 0, p_line-1);
        Buda1[0]=TT_VAR; // Use G_Return
      }
      else
      {
        Buda1[j]=i;
        Buda2[j]=Link[--sv_subv];
      }
      return(0);
     case 229:  // :=
      if (Buda1[Arguments]==TT_LINK)
      {
#if TR
        if (Buda1[Buda2[Arguments]]==TT_LINK)
          MitiText("Error in :=", &cf_red);
#endif
        if (Buda1[Arguments+1]>=MEMORY_c256)
        {
          len=0;
          write_p( TT_VAR, 2, Arguments+1);
          i_poin=0;
          f_end=len+3;
          strcpy((LPSTR)(string2+len), " . ");
          string2[f_end]=0;
          strcpy((LPSTR)string, (LPSTR)string2);
          if (read_n(&t, 2)==0)
          {
            MitiText("Error in :=\r\n");
            return(0);
          }
          Buda1[Buda2[Arguments]]=t;
          if (t>=MEMORY_c256)
          {
            buda_br_up+=list_br;
            if (BUDA3_UP<buda_br_up && correct_BUDA_UP() )
            {
              MessageBoxA(NUL,"Variables Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
              return(3);
            }
            Buda2[Buda2[Arguments]]= -buda_br_up;
            for(i=0; i<list_br; i++)
            {
              Buda1[-buda_br_up+i]=Buda1[buda_br+i];
              Buda2[-buda_br_up+i]=Buda2[buda_br+i];
              Buda1[buda_br+i]=TT_VAR;
            }
          }
          return(1);
        }
        Buda1[Buda2[Arguments]]=Buda1[Arguments+1];
        Buda2[Buda2[Arguments]]=Buda2[Arguments+1];
        return(1);
      }
      else if (Buda1[Arguments]==TT_OBJ && ObjectStore[Buda2[Arguments]]==CLASS_SYSTEM_CONTAINER)
      {
        if (ObjectStore[Buda2[Arguments]+4]&OBSEG1) // set property
        {
#if !CONSOLE
          //Angele, setni tuk edno properti
          //StringStore+ObjectStore[Buda2[Arguments]+6] //property
          //ObjectStore[Buda2[Arguments]+7] //server (as object)
          //Buda2[Arguments+1] //value to be set
          //Buda1[Arguments+1] //prolog type to be set, for the moment variant
          
          i=SetProperty(ObjectStore[Buda2[Arguments]+7], ObjectStore[Buda2[Arguments]+6], Arguments+1, p_line);
          ObjectStore[Buda2[Arguments]+6]=the_free_container;
          the_free_container=Buda2[Arguments];
          return(i);
#endif // !CONSOLE        
        }
        else if (Buda1[Arguments+1]==ObjectStore[ObjectStore[Buda2[Arguments]+7]+6])
        {
          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=Buda2[Arguments+1];
        }
        else if (ObjectStore[ObjectStore[Buda2[Arguments]+7]+6]==TT_STR)
        {
          len=0;
          write_p( TT_VAR, 6, Arguments+1);
          strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR)string2);
          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=sv_StStore; // len>0
          if ((sv_StStore+=len+1)>=STRING_STORE && correct_STR_ST() )
            goto FULL;
        }
        else if (Buda1[Arguments+1]==TT_FLOAT && ObjectStore[ObjectStore[Buda2[Arguments]+7]+6]==TT_INT)
        {
          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=(int)(*(float*)&(Buda2[Arguments+1]));
        }
        else if (Buda1[Arguments+1]==TT_INT && ObjectStore[ObjectStore[Buda2[Arguments]+7]+6]==TT_FLOAT)
        {
          float fl;
          fl=(float)(int)(Buda2[Arguments+1]);
          ((LPDWORD)ObjectStore[ObjectStore[Buda2[Arguments]+7]+4])
                 [ObjectStore[Buda2[Arguments]+6]]=*(int*)&fl;
        }
        else
        {
          sprintf(string2,"Runtime Error at step %d: ", 0x10000*lSteps_br+Steps_br-Corection);
          MitiText(string2, &cf_red);
          MitiText("Different types in :=\r\n");
          return(0);
        }
        ObjectStore[Buda2[Arguments]+6]=the_free_container;
        the_free_container=Buda2[Arguments];
        return(1);
      }
      MitiText("Error in := ", &cf_red);
      MitiText("The left argument cannot change its value.\r\n");
      return(0);
     case 90:        // abs
      if (Buda1[Arguments]!=TT_INT)
        goto E2;
      else
        goto E3;
     case 91:        // sign
      if (Buda1[Arguments]==TT_FLOAT)
        Buda2[Return]=(*(float*)&(Buda2[Arguments])<=0)?((*(float*)&(Buda2[Arguments])==0)?0:-1):1;
      else // if (Buda1[Arguments]==TT_INT)
        Buda2[Return]=((int)Buda2[Arguments]<=0)?((Buda2[Arguments]==0)?0:-1):1;
      Buda1[Return]=TT_INT;
      return(1);
     case 24:        // // divide
     case 25:        // mod
     case 89:        // rem
      if (!Buda2[Arguments+1])
      {
        MitiText("You are trying to divide on zero!\r\n");
        return(0);
      }
      if (p_line==24)
        k=(int)Buda2[Arguments]/(int)Buda2[Arguments+1];
      else
      {
        k=(int)Buda2[Arguments]%(int)Buda2[Arguments+1];
        if (p_line==25 && (int)k<0)        // mod
        {
          if ((int)Buda2[Arguments+1]>=0)
            k+=Buda2[Arguments+1];
          else
            k-=Buda2[Arguments+1];
        }
      }
      Buda1[Return]=TT_INT;
      Buda2[Return]=k;
      return(1);
     case 94:        // >> move right
      Buda1[Return]=TT_INT;
      Buda2[Return]=Buda2[Arguments]>>Buda2[Arguments+1];
      return(1);
     case 95:        // << move left
      Buda1[Return]=TT_INT;
      Buda2[Return]=Buda2[Arguments]<<Buda2[Arguments+1];
      return(1);
     case 96:        // /\ AND
      Buda1[Return]=TT_INT;
      Buda2[Return]=Buda2[Arguments]&Buda2[Arguments+1];
      return(1);
     case 97:        // \/ OR
      Buda1[Return]=TT_INT;
      Buda2[Return]=Buda2[Arguments]|Buda2[Arguments+1];
      return(1);
     case 98:        // xor XOR
      Buda1[Return]=TT_INT;
      Buda2[Return]=Buda2[Arguments]^Buda2[Arguments+1];
      return(1);
     case 99:        // \ NOT
      Buda1[Return]=TT_INT;
      Buda2[Return]=~Buda2[Arguments];
      return(1);
     case 117:        // round
     case 118:        // ceiling
     case 119:        // floor
     case 102:        // int
      if (Buda1[Arguments]==TT_FLOAT)
      {
        float fl=*(float*)&(Buda2[Arguments]); 
        k=(DWORD)(int)fl;
        switch (p_line)
        {
         case 117:        // round
          if ((int)k>=0)
          {
            if (fl-(float)k>=0.5)
              k++;
          }
          if ((int)k<=0)
          {
            if ((float)(int)k-fl>=0.5)
              k--;
          }
          break;
         case 118:        // ceiling
          if ((int)k>=0 && fl>(float)k)
            k++;
          break;
         case 119:        // floor
          if ((int)k<=0 && fl<(float)(int)k)
            k--;
        }
      }
      else if (Buda1[Arguments]==TT_INT)
        k=Buda2[Arguments];
      else
        return(0);
      Buda1[Return]=TT_INT;
      Buda2[Return]=k;
      return(1);
     case 21:        // + add
      if (Buda1[Arguments]!=TT_STR)
      {
        if (Buda1[Arguments+1]!=TT_STR)
          goto E6;
      }
      else if (Buda1[Arguments+1]==TT_STR)
      {
        if (Buda2[Arguments]==0)
        {
          Buda2[Return]=Buda2[Arguments+1];
          goto E7;
        }
        else if (Buda2[Arguments+1]==0)
        {
          Buda2[Return]=Buda2[Arguments];
          goto E7;
        }
      }
      k=sv_StStore;
      if (Buda1[Arguments]==TT_STR)
      {
        strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR)(StringStore+Buda2[Arguments]));
        sv_StStore+=strlen((LPSTR)(StringStore+Buda2[Arguments]));
      }
      else if (Buda1[Arguments]==TT_INT)
        sv_StStore+=sprintf((LPSTR)(StringStore+sv_StStore), "%d", (int)Buda2[Arguments]);
      else // Buda1[Arguments]==TT_FLOAT
        sv_StStore+=sprintf((LPSTR)(StringStore+sv_StStore), "%G", *(float*)&(Buda2[Arguments]));
      if (sv_StStore>=STRING_STORE && correct_STR_ST() )
        goto FULL;
      if (Buda1[Arguments+1]==TT_STR)
      {
        strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR)(StringStore+Buda2[Arguments+1]));
        sv_StStore+=strlen((LPSTR)(StringStore+Buda2[Arguments+1]))+1;
      }
      else if (Buda1[Arguments+1]==TT_INT)
        sv_StStore+=1+sprintf((LPSTR)(StringStore+sv_StStore), "%d", (int)Buda2[Arguments+1]);
      else // Buda1[Arguments+1]==TT_FLOAT
        sv_StStore+=1+sprintf((LPSTR)(StringStore+sv_StStore), "%G", *(float*)&(Buda2[Arguments+1]));
      if (sv_StStore>=STRING_STORE && correct_STR_ST() )
        goto FULL;
      Buda2[Return]=k;
E7:   Buda1[Return]=TT_STR;
      return(1);
     case 103:        // float
     case 104:        // sin
     case 105:        // cos
     case 106:        // tg
     case 107:        // arcsin
     case 108:        // arccos
     case 109:        // arctg
     case 110:        // sinh
     case 111:        // cosh
     case 112:        // tgh
     case 113:        // sqrt
     case 114:        // log
     case 115:        // log10
     case 116:        // exp
      goto E2;// skip the second argument
     case 20:        // - prefix minus
      if (Buda1[Arguments]==TT_INT)
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]= -(int)Buda2[Arguments];
        return(1);
      }
      goto E2;
     case 22:        // - sub
     case 23:        // * multiplide
E6:   if (Buda1[Arguments]!=TT_INT || Buda1[Arguments+1]!=TT_INT)
      {
     case 92:        // pow **
     case 93:        // / divide
        float fl, fl1, fl2;
        if (Buda1[Arguments+1]==TT_FLOAT)
          fl2=*(float*)&(Buda2[Arguments+1]);
        else if (Buda1[Arguments+1]==TT_INT)
          fl2=(float)(int)(Buda2[Arguments+1]);
        else
          return(0);
E2:     if (Buda1[Arguments]==TT_FLOAT)
          fl1=*(float*)&(Buda2[Arguments]);
        else if (Buda1[Arguments]==TT_INT)
          fl1=(float)(int)(Buda2[Arguments]);
        else
          return(0);
        switch (p_line)
        {
         case 20:        // - prefix minus
          fl= -fl1;
          break;
         case 21:        // + add
          fl=fl1+fl2;
          break;
         case 22:
          fl=fl1-fl2;
          break;
         case 23:
          fl=fl1*fl2;
          break;
         case 93:
          if (!fl2)
          {
            MitiText("You are trying to divide on zero!\r\n");
            return(0);
          }
          fl=fl1/fl2;
          break;
         case 90:        // abs
          fl=(float)fabs(fl1);
          break;
         case 92:        // pow **
          fl=(float)pow(fl1, fl2);
          break;
         case 103:        // float
          fl=fl1;
          break;
         case 104:        // sin
          fl=(float)sin(fl1);
          break;
         case 105:        // cos
          fl=(float)cos(fl1);
          break;
         case 106:        // tg
          fl=(float)tan(fl1);
          break;
         case 107:        // arcsin
          fl=(float)asin(fl1);
          break;
         case 108:        // arccos
          fl=(float)acos(fl1);
          break;
         case 109:        // arctg
          fl=(float)atan(fl1);
          break;
         case 110:        // sinh
          fl=(float)sinh(fl1);
          break;
         case 111:        // cosh
          fl=(float)cosh(fl1);
          break;
         case 112:        // tgh
          fl=(float)tanh(fl1);
          break;
         case 113:        // sqrt
          if (fl1<0)
            return(0);
          fl=(float)sqrt(fl1);
          break;
         case 114:        // log
          fl=(float)log(fl1);
          break;
         case 115:        // log10
          fl=(float)log10(fl1);
          break;
         case 116:        // exp
          fl=(float)exp(fl1);
        }
        Buda1[Return]=TT_FLOAT;
        Buda2[Return]= *(int*)&fl;
        return(1);
      }
E3:   switch (p_line)
      {
       case 21:        // + add
        k=Buda2[Arguments]+Buda2[Arguments+1];
        break;
       case 22:
        k=Buda2[Arguments]-Buda2[Arguments+1];
        break;
       case 23:
        k=(int)Buda2[Arguments]*(int)Buda2[Arguments+1];
        break;
       case 90:        // abs
        k=abs((int)Buda2[Arguments]);
      }
      Buda1[Return]=TT_INT;
      Buda2[Return]=k;
      return(1);
     case 26:        // ~ random
      if (Buda2[Arguments]==0)
        return(0);
      Buda1[Return]=TT_INT;
      Buda2[Return]=rand()%Buda2[Arguments];
      return(1);
     case 200:        // start_random_from
      if (Buda1[Arguments]==TT_INT)
        srand(Buda2[Arguments]);
      else  
      {
        long t;
        time( (time_t*)&t);
        srand(t);
      }
      return(1);
     case 359:        // current_time
      Buda1[Return]=TT_INT;
      Buda2[Return]=(DWORD)time(0);
      return(1);
     case 148:        // ==  exactly equal
      if (Buda1[Arguments]==Buda1[Arguments+1] && (Buda2[Arguments]==Buda2[Arguments+1]
       || Buda1[Arguments]<TT_LINK || (Buda1[Arguments]>=TT_START && Buda1[Arguments]<MEMORY_c256)))
        return(1);
      return(0);
     case 149:        // \==  not equal exactly 
      if (Buda1[Arguments]==Buda1[Arguments+1] && (Buda2[Arguments]==Buda2[Arguments+1]
       || Buda1[Arguments]<TT_LINK || (Buda1[Arguments]>=TT_START && Buda1[Arguments]<MEMORY_c256)))
        return(0);
      return(1);
     case 123: // equal(S, S2, no_case)
     case 124: // less_than(S, S2, no_case)
      if (Buda1[Arguments+2]!=Definition[DF_NO_CASE])
        goto E10;
      for (i=Buda2[Arguments], j=Buda2[Arguments+1]; StringStore[i]!=0 && 
       (StringStore[i]==StringStore[j] || ((StringStore[i]<StringStore[j])
       ?(StringStore[i]+32==StringStore[j] && StringStore[i] >= 'A' && StringStore[i] <= 'Z')
       :(StringStore[i]-32==StringStore[j] && StringStore[i] >= 'a' && StringStore[i] <= 'z')));
              i++, j++);
      if ( (p_line==123)?(StringStore[i]==StringStore[j]):(StringStore[i]<StringStore[j]) )
        return(1);
      return(0);
     case 27:        // > bigger_than
     case 28:        // < less_than
     case 29:        // =:= equal_to
     case 134:       // =<
     case 135:       // >=
     case 136:       // =\=
E11:  if (Buda1[Arguments]==TT_STR && Buda1[Arguments+1]==TT_STR)
      {
E10:    for (i=Buda2[Arguments], j=Buda2[Arguments+1];
             StringStore[i]==StringStore[j] && StringStore[i]!=0; i++, j++);
        switch (p_line)
        {
         case 27:        // > bigger_than
          if (StringStore[i]>StringStore[j])
            return(1);
          return(0);
         case 28:        // < less_than
         case 124: // less_than(S, S2, no_case)
          if (StringStore[i]<StringStore[j])
            return(1);
          return(0);
         case 214:       // is
         case 29:        // =:= equal_to
         case 123: // equal(S, S2, no_case)
          if (StringStore[i]==StringStore[j])
            return(1);
          return(0);
         case 134:        // =<
          if (StringStore[i]>StringStore[j])
            return(0);
          return(1);
         case 135:        // >=
          if (StringStore[i]<StringStore[j])
            return(0);
          return(1);
         case 136:        // =\=
          if (StringStore[i]==StringStore[j])
            return(0);
          return(1);
        }
      }
      else if (Buda1[Arguments]==TT_INT && Buda1[Arguments+1]==TT_INT)
      {
        switch (p_line)
        {
         case 27:        // > bigger_than
          if ((int)Buda2[Arguments]>(int)Buda2[Arguments+1])
            return(1);
          return(0);
         case 28:        // < less_than
          if ((int)Buda2[Arguments]<(int)Buda2[Arguments+1])
            return(1);
          return(0);
         case 214:       // is
         case 29:        // =:= equal_to
          if ((int)Buda2[Arguments]==(int)Buda2[Arguments+1])
            return(1);
          return(0);
         case 134:        // =<
          if ((int)Buda2[Arguments]>(int)Buda2[Arguments+1])
            return(0);
          return(1);
         case 135:        // >=
          if ((int)Buda2[Arguments]<(int)Buda2[Arguments+1])
            return(0);
          return(1);
         case 136:        // =\=
          if ((int)Buda2[Arguments]==(int)Buda2[Arguments+1])
            return(0);
          return(1);
        }
      }
      // else if (Buda1[Arguments]==TT_OBJ && Buda1[Arguments+1]==TT_OBJ)
      else // if TT_INT or && TT_FLOAT
      {
        float fl0, fl1;
        if (Buda1[Arguments]==TT_FLOAT)
          fl0=*(float*)&(Buda2[Arguments]);
        else if (Buda1[Arguments]==TT_INT)
          fl0=(float)(int)(Buda2[Arguments]);
        else
          return(0);
        if (Buda1[Arguments+1]==TT_FLOAT)
          fl1=*(float*)&(Buda2[Arguments+1]);
        else if (Buda1[Arguments+1]==TT_INT)
          fl1=(float)(int)(Buda2[Arguments+1]);
        else
          return(0);
        switch (p_line)
        {
         case 27:        // > bigger_than
          if (fl0>fl1)
            return(1);
          return(0);
         case 28:        // < less_than
          if (fl0<fl1)
            return(1);
          return(0);
         case 214:       // is
         case 29:        // =:= equal_to
          if (fl0==fl1)
            return(1);
          return(0);
         case 134:        // =<
          if (fl0>fl1)
            return(0);
          return(1);
         case 135:        // >=
          if (fl0<fl1)
            return(0);
          return(1);
         case 136:        // =\=
          if (fl0==fl1)
            return(0);
          return(1);
        }
      }
     case 43:        // OP - operators - arrity 3
      if (Buda1[Arguments+1]>=MEMORY_c256 || Buda1[Arguments+2]>=MEMORY_c256)
        return(0);  
      Add_op(Buda2[Arguments], Buda1[Arguments+1], Buda1[Arguments+2], Buda1[Arguments+2]);
      if (error)
      {
        error=0;
        return(0);
      }
      return(1);
#if MY_SQL
     case 308:    //mysql_connect
      {
        Buda1[Return]=TT_OBJ;
        Buda2[Return]=ObjectStore_br;
        ObjectStore[ObjectStore_br+1]=M1;  // object name
        ObjectStore[ObjectStore_br]=CLASS_SYSTEM_MYSQL;
        if (!mysql_connect((MYSQL *)(ObjectStore+ObjectStore_br+2), (LPSTR)(StringStore+Buda2[Arguments]), (LPSTR)(StringStore+Buda2[Arguments+1]), (LPSTR)(StringStore+Buda2[Arguments+2])))
        {
          printf("Cannot establish a connection: %s\r\n", mysql_error((MYSQL *)(ObjectStore+ObjectStore_br+2)));
          return(0);
        }
        if ((ObjectStore_br+=2+sizeof(MYSQL)/4)>=OBJ_STORE && correct_OBJ_ST() )
          goto FULL2;
        return(1);
      }
     case 301:    //mysql_select_db
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL)
      if (mysql_select_db((MYSQL *)(ObjectStore+Buda2[Arguments]+2), (LPSTR)(StringStore+Buda2[Arguments+1])))
      {
        printf("Cannot select database: %s\r\n", mysql_error((MYSQL *)(ObjectStore+Buda2[Arguments]+2)));
        return(0);
      }
      return(1);
     case 302:    //mysql_query
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL)
      if (mysql_query((MYSQL *)(ObjectStore+Buda2[Arguments]+2), (LPSTR)(StringStore+Buda2[Arguments+1])))
      {
        printf("Cannot make the query: %s\r\n", mysql_error((MYSQL *)(ObjectStore+Buda2[Arguments]+2)));
        return(0);
      }
      return(1);
     case 303:    //mysql_store_result
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL)
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_MYSQL_RES;
      ObjectStore[ObjectStore_br+2]= (DWORD)
      mysql_store_result((MYSQL *)(ObjectStore+Buda2[Arguments]+2));     
      if (ObjectStore[ObjectStore_br+2]==NUL)
      {
        printf("Cannot store the mysql result: %s\r\n", mysql_error((MYSQL *)(ObjectStore+Buda2[Arguments]+2)));
        return(0);
      }
      if ((ObjectStore_br+=3)>=OBJ_STORE && correct_OBJ_ST() )
        goto FULL2;
      return(1);
     case 304:    //mysql_free_result
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL_RES)
      mysql_free_result((MYSQL_RES *)ObjectStore[Buda2[Arguments]+2]);
      return(1);
     case 305:    //mysql_fetch_row
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL_RES)
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_MYSQL_ROW;
      if ((ObjectStore[ObjectStore_br+2]= 
                      (DWORD) mysql_fetch_row((MYSQL_RES *)ObjectStore[Buda2[Arguments]+2]))){} 
      else
        return(0);     
      if (ObjectStore[ObjectStore_br+2]==NUL)
        return(0);
      if ((ObjectStore_br+=3)>=OBJ_STORE && correct_OBJ_ST() )
        goto FULL2;
      return(1);
     case 306:    // field
     {
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL_ROW)
      i = Buda2[Arguments+1];    
      char *elem = (LPSTR)((MYSQL_ROW)ObjectStore[Buda2[Arguments]+2])[i];
      if (elem == NULL)
        return(0);
      i = sv_StStore;
      for(j = 0; elem[j] != 0; StringStore[i++] = elem[j++]);
      if (i==sv_StStore)
        Buda2[Return]=0;
      else
      {
        StringStore[i++]=0;
        Buda2[Return]=sv_StStore;
        sv_StStore=i;
      }
      Buda1[Return]=TT_STR;
      return(1);
     }
     case 307:    //mysql_num_fields
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL_RES)
      Buda1[Return]=TT_INT;
      Buda2[Return]=mysql_num_fields((MYSQL_RES *)ObjectStore[Buda2[Arguments]+2]);
      return(1);
     case 309: //mysq_eof
      CHECK_TYPE(0,CLASS_SYSTEM_MYSQL_RES)
      if (!mysql_eof((MYSQL_RES *)ObjectStore[Buda2[Arguments]+2])) 
        return(0);
      else
        return(1);
    
#endif // MY_SQL                
     case 44:        // Open file
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_FILE;
      ObjectStore[ObjectStore_br+2]= (DWORD)
      fopen((LPSTR)(StringStore+Buda2[Arguments]), (LPSTR)(StringStore+Buda2[Arguments+1]));
      if (ObjectStore[ObjectStore_br+2]==NUL)
      {
        MitiText("Cannot open this file.\r\n");
        return(0);
      }
      if ((ObjectStore_br+=3)>=OBJ_STORE && correct_OBJ_ST() )
        goto FULL2;
      return(1);
     case 45:        // close
      if (Buda1[Arguments]==TT_LINK)
      {
        if (pMainWindow && pMainWindow!=pMain_Frame)
        {
          k=pMainWindow->GetDlgCtrlID();
          pMainWindow=NULL;
        }
        else if (pMain_Frame)
        {
          k=pMain_Frame->m_Number;
          // not (pMainWindow=pMain_Frame=NULL;) because it can stay open (cansel dialog)
        }
        else
          return(0);
      }
      else
        k=Buda2[Arguments];
      if (ObjectStore[k]==0 || k>=ObjectStore_br)
      {
        sprintf(string2, "The object 0j%d is already closed.\r\n", Buda2[Arguments]);
        MitiText(string2, &cf_red);        
        return(0);
      }
      close_object(k);
      return(1);
     case 256:        // writef
      CHECK_TYPE(0,CLASS_SYSTEM_FILE)
      fprintf((FILE *)ObjectStore[Buda2[Arguments]+2], "%s", (LPSTR)(StringStore+Buda2[Arguments+1]));
      return(1);
     case 257:        // readf
      CHECK_TYPE(0,CLASS_SYSTEM_FILE)
      i=fscanf((FILE *)ObjectStore[Buda2[Arguments]+2], "%s", (LPSTR)(StringStore+sv_StStore));
      if (i==0)
      {
        MitiText("Cannot read from this file.\r\n");
        return(0);
      }
      else if (i==EOF)
        return(0);
      Buda1[Return]=TT_STR;
      Buda2[Return]=sv_StStore;
      i=strlen((LPSTR)(StringStore+sv_StStore));
      if (i)
      {
        sv_StStore+=i+1;
        if (sv_StStore>=STRING_STORE && correct_STR_ST() )
          goto FULL;
        return(1);
      }
      return(0);
     case 261:        // readln
      CHECK_TYPE(0,CLASS_SYSTEM_FILE)
      if(fgets((LPSTR)(StringStore+sv_StStore), 600,(FILE *)ObjectStore[Buda2[Arguments]+2])==NULL)
        return(0);
      Buda1[Return]=TT_STR;
      Buda2[Return]=sv_StStore;
      i=strlen((LPSTR)(StringStore+sv_StStore));
      if (i)
      {
        sv_StStore+=i+1;
        if (sv_StStore>=STRING_STORE && correct_STR_ST() )
          goto FULL;
        return(1);
      }
      return(0);
#if UNIX
     case 354: //ftruncate
      if (truncate((LPSTR)(StringStore+Buda2[Arguments]), Buda2[Arguments+1]))
        return(0);
      return(1);
#endif // UNIX
     case 265:        // set_file_pos
      CHECK_TYPE(0,CLASS_SYSTEM_FILE)
      if (Buda1[Arguments+2]==Definition[DF_BEGIN])
        i=SEEK_SET;
      else if (Buda1[Arguments+2]==Definition[DF_END])
        i=SEEK_END;
      else if (Buda1[Arguments+2]==Definition[DF_CURRENT])
        i=SEEK_CUR;
      else
        return(0);
      if (fseek((FILE *)ObjectStore[Buda2[Arguments]+2], Buda2[Arguments+1], i))
        return(0);
      return(1);
     case 266:        // get_file_pos
      CHECK_TYPE(0,CLASS_SYSTEM_FILE)
      if (Buda1[Arguments+1]==Definition[DF_BEGIN])
        Buda2[Return]=ftell((FILE *)ObjectStore[Buda2[Arguments]+2]);
      else if (Buda1[Arguments+1]==Definition[DF_END])
      {
        i=ftell((FILE *)ObjectStore[Buda2[Arguments]+2]);
        fseek((FILE *)ObjectStore[Buda2[Arguments]+2], 0, SEEK_END);
        Buda2[Return]=i-ftell((FILE *)ObjectStore[Buda2[Arguments]+2]);
        fseek((FILE *)ObjectStore[Buda2[Arguments]+2], i, SEEK_SET);
      }
      else if (Buda1[Arguments+1]==Definition[DF_CURRENT])
        Buda2[Return]=0;
      else
        return(0);
      Buda1[Return]=TT_INT;
      return(1);
     case 46:         // get from file
      CHECK_TYPE(0,CLASS_SYSTEM_FILE)
      if (Buda1[Arguments+1]==48)       // l
      {
        DWORD get_buf;       // becouse of WIN16
        i=fread(&get_buf, 4, 1, (FILE *)ObjectStore[Buda2[Arguments]+2]);
        Buda2[Return]=get_buf;
      }  
      else if (Buda1[Arguments+1]==55)  // s
      {
        WORD get_buf;       // becouse of WIN16
        i=fread(&get_buf, 2, 1, (FILE *)ObjectStore[Buda2[Arguments]+2]);
        Buda2[Return]=get_buf;
      }  
      else
      {
        BYTE get_buf;
        i=fread(&get_buf, 1, 1, (FILE *)ObjectStore[Buda2[Arguments]+2]);
        Buda2[Return]=get_buf;
      }
      if (i)
      {
        Buda1[Return]=TT_INT;
        return(1);
      }
      else
        return(0);
     case 47:         // put in file
      CHECK_TYPE(1,CLASS_SYSTEM_FILE)
      if (Buda1[Arguments+2]==48)       // l
      { 
        DWORD get_buf;
        get_buf=Buda2[Arguments];
        fwrite(&get_buf, 4, 1, (FILE *)ObjectStore[Buda2[Arguments+1]+2]);
      }  
      else if (Buda1[Arguments+2]==55)  // s
      { 
        WORD get_buf;
        get_buf=(WORD)Buda2[Arguments];
        fwrite(&get_buf, 2, 1, (FILE *)ObjectStore[Buda2[Arguments+1]+2]);
      }  
      else
      { 
        BYTE get_buf;
        get_buf=(BYTE)Buda2[Arguments];
        fwrite(&get_buf, 1, 1, (FILE *)ObjectStore[Buda2[Arguments+1]+2]);
      }   
      return(1);
     case 262:        // feof
      CHECK_TYPE(0,CLASS_SYSTEM_FILE)
      if (feof((FILE *)ObjectStore[Buda2[Arguments]+2]))
        return(1);
      else
        return(0);
     case 207:        // ### load_string - deleted
      strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR)Buda2[Arguments]);
      Buda1[Return]=TT_STR;
      Buda2[Return]=sv_StStore;
      sv_StStore+=strlen((LPSTR)(StringStore+sv_StStore))+1;
      if (sv_StStore>=STRING_STORE && correct_STR_ST() )
        goto FULL;
      return(1);
#if UNIX && PROF
     case 258:    //socket
     {
      int sock,port;
      struct sockaddr_in servername;
      struct hostent *hostinfo;
      char *ServerHost=(LPSTR)(StringStore+Buda2[Arguments]);
      port=Buda2[Arguments+1];
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      if ((ObjectStore_br+8)>=OBJ_STORE && correct_OBJ_ST() )
      {
        MessageBoxA(NUL,"Object Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
        return(3);
      }
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_SOCKET;
      sock=socket(PF_INET,SOCK_STREAM,0);
      if (sock<0)
      {
        printf("Error: socket (client)\n");
        return(0);
      }
      servername.sin_family=AF_INET;
      servername.sin_port=htons(port);
      hostinfo=gethostbyname(ServerHost);
      if (hostinfo==NUL) printf("Error: Unknown host %s.\n",ServerHost);
      else servername.sin_addr=*(struct in_addr*)hostinfo->h_addr;
      if (0>connect (sock,(struct sockaddr*)&servername,sizeof(servername)))
      {
        printf("Errot: connect (client)\n");
        return(0);
      }
      ObjectStore[ObjectStore_br+2]= (DWORD)sock;
      ObjectStore_br+=8;
      return(1);
     }
     case 259:       // write_sock
     {
      CHECK_TYPE(0,CLASS_SYSTEM_SOCKET)
      j=write(ObjectStore[Buda2[Arguments]+2], (LPSTR)(StringStore+Buda2[Arguments+1]), strlen((LPSTR)(StringStore+Buda2[Arguments+1])));
      if (j<0)
      {
        printf("Errot: writing in socket\n");
        return(0);
      }
      return(1);
     }
     case 260:       // read_sock
      CHECK_TYPE(0,CLASS_SYSTEM_SOCKET)
      if (Buda1[Arguments+1]==TT_LINK)
      {
        k=0;
        while (1)
        {
          if ((sv_StStore + k)>=STRING_STORE && correct_STR_ST() )
            goto FULL;

          j=read(ObjectStore[Buda2[Arguments]+2],(StringStore+sv_StStore+k),1000);
          if (j<=0)
            break;
          k+=j;
        }
        Buda1[Return]=TT_STR;
        Buda2[Return]=sv_StStore;
        StringStore[sv_StStore+k]=0;
        sv_StStore+=k+1;
      }
      else
      {
        if (sv_StStore + (int)Buda2[Arguments+1] >= STRING_STORE && correct_STR_ST() )
            goto FULL;
        j=read(ObjectStore[Buda2[Arguments]+2],(StringStore+sv_StStore),(int)Buda2[Arguments+1]);
        if (j <= 0) return(0);
        Buda1[Return]=TT_STR;
        Buda2[Return]=sv_StStore;
        StringStore[sv_StStore+j]=0;
        sv_StStore+=j+1;
      }
      return(1);
     case 350:    //server_socket
     {
      int sock,port;
      struct sockaddr_in servername;
      char *ServerHost=(LPSTR)(StringStore+Buda2[Arguments]);
      struct hostent *hostinfo;
      port=Buda2[Arguments+1];
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      if ((ObjectStore_br+8)>=OBJ_STORE && correct_OBJ_ST() )
      {
        MessageBoxA(NUL,"Object Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
        return(3);
      }
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_SOCKET;
      sock=socket(PF_INET,SOCK_STREAM,0);
      if (sock<0)
      {
        printf("Error: socket (client)\n");
        return(0);
      }
      servername.sin_family=AF_INET;
      servername.sin_port=htons(port);
      hostinfo=gethostbyname(ServerHost);
      if (hostinfo==NUL) printf("Error: Unknown host %s.\n",ServerHost);
      else servername.sin_addr=*(struct in_addr*)hostinfo->h_addr;
      if (0>bind(sock, (struct sockaddr*)&servername, sizeof(servername)))
      {
        printf("Error: binding server \n");
        return(0);
      }
      if (0 > listen(sock, 5)) {
        printf("Error listening ");
        return(0);
        }
      ObjectStore[ObjectStore_br+2]= (DWORD)sock;
      ObjectStore_br+=8;
      return(1);
     }
     case 351:       // get_client (UNIX)
     {
      CHECK_TYPE(0,CLASS_SYSTEM_SOCKET)
      int client;    
      struct sockaddr_in servername;
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      if ((ObjectStore_br+8)>=OBJ_STORE && correct_OBJ_ST() )
      {
        MessageBoxA(NUL,"Object Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
        return(3);
      }
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_SOCKET;
      while (!(client = accept(ObjectStore[Buda2[Arguments]+2], (struct sockaddr*)&servername, (socklen_t *)sizeof(servername))));
      ObjectStore[ObjectStore_br+2]= (DWORD)client;
      ObjectStore_br+=8;
      return(1);
     }
#endif // UNIX && PROF
#if !CONSOLE
     case 258:    //socket
     {
      SOCKET sock;
      int port;
      WORD wVersionRequested;
      WSADATA wsaData;
      int err;
      struct sockaddr_in servername;
      struct hostent *hostinfo;
      char *ServerHost=(LPSTR)(StringStore+Buda2[Arguments]);
      int ip1, ip2, ip3, ip4, flag = 0;

      wVersionRequested = MAKEWORD( 1, 1 ); 
      err = WSAStartup( wVersionRequested, &wsaData );
      port=Buda2[Arguments+1];
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      if ((ObjectStore_br+8)>=OBJ_STORE && correct_OBJ_ST() )
      {
        MessageBoxA(NUL,"Object Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
        return(3);
      }
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_SOCKET;
      if ((sock=socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
      {
        printf("Error: socket (client)\n");
        return(0);
      }
      servername.sin_family=AF_INET;
      servername.sin_port=htons(port);
      i=sscanf(ServerHost, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4);
      if (i==4 && ip1 < 255 && ip1 > 0 && ip2 < 255 && ip2 >= 0 && ip3 < 255 && ip3 >= 0 && ip4 < 255 && ip4 >= 0)
      {
        servername.sin_addr.s_addr = inet_addr(ServerHost);
        hostinfo=gethostbyaddr((char *) &((LPSOCKADDR_IN)&servername)->sin_addr.s_addr, 4, PF_INET);
        flag = 1;
      }
      else 
        hostinfo=gethostbyname(ServerHost);

      if (hostinfo==NUL) 
        if (flag) 
        {
          printf("Error: Unknown host %s.\n",ServerHost);
          return(0);
        }
      else
        servername.sin_addr=*(struct in_addr*)hostinfo->h_addr;
      if (0>connect (sock,(struct sockaddr*)&servername,sizeof(servername)))
      {
        printf("Error: connect (client)\n");
        return(0);
      }
      ObjectStore[ObjectStore_br+2]= (DWORD)sock;
      ObjectStore_br+=8;
      return(1);
     }
     case 259:       // write_sock
     {
      CHECK_TYPE(0,CLASS_SYSTEM_SOCKET)
      j=send((SOCKET)ObjectStore[Buda2[Arguments]+2], (LPSTR)(StringStore+Buda2[Arguments+1]), strlen((LPSTR)(StringStore+Buda2[Arguments+1])),0);
      if (j<0)
      {
        printf("Error: writing in socket\n");
        return(0);
      }
      return(1);
     }
     case 260:       // read_sock
      CHECK_TYPE(0,CLASS_SYSTEM_SOCKET)
      k=0;
      while (1)
      {
        j=recv((SOCKET)ObjectStore[Buda2[Arguments]+2],(char *)(StringStore+sv_StStore+k),1000,0);
        if (j<=0)
          break;
        k+=j;
      }
      Buda1[Return]=TT_STR;
      Buda2[Return]=sv_StStore;
      StringStore[sv_StStore+k]=0;
      sv_StStore+=k+1;
      return(1);
     case 350:    //server_socket
     {
      SOCKET sock,port;
      SOCKADDR_IN servername;
      char *ServerHost=(LPSTR)(StringStore+Buda2[Arguments]);
      WORD wVersionRequested;
      WSADATA wsaData;
      int err;
      wVersionRequested = MAKEWORD( 1, 1 ); 
      err = WSAStartup( wVersionRequested, &wsaData );
      port=Buda2[Arguments+1];
      Buda1[Return]=TT_OBJ;
      Buda2[Return]=ObjectStore_br;
      ObjectStore[ObjectStore_br+1]=M1;  // object name
      if ((ObjectStore_br+8)>=OBJ_STORE && correct_OBJ_ST())
      {
        MessageBoxA(NUL,"Object Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
        return(3);
      }
      ObjectStore[ObjectStore_br]=CLASS_SYSTEM_SOCKET;
      sock=socket(AF_INET,SOCK_STREAM,0);
      if (sock<0)
      {
        printf("Error: socket (client)\n");
        return(0);
      }
      servername.sin_family = AF_INET;
      servername.sin_addr.s_addr = 0;
      servername.sin_port = htons(port);

      if (0!=bind(sock, (LPSOCKADDR)&servername, sizeof(servername)))
      {
        printf("Error: binding server \n");
        return(0);
      }
      if (0 > listen(sock, 5)) {
            printf("Error listening ");
            return(0);
      }
      ObjectStore[ObjectStore_br+2]= (DWORD)sock;
      ObjectStore_br+=8;
      return(1);
     }
     case 351:       // get_client (Windows)
     {
      CHECK_TYPE(0,CLASS_SYSTEM_SOCKET)
      SOCKET client;    
      SOCKADDR_IN servername;
      FD_SET fd = {1, (SOCKET)ObjectStore[Buda2[Arguments]+2]};
      TIMEVAL tv = {0, 0};
      
      if (select(32, &fd, NULL, NULL, &tv) == 1)
      {
        client = accept((SOCKET)ObjectStore[Buda2[Arguments]+2], (LPSOCKADDR)&servername, NULL);
        Buda1[Return]=TT_OBJ;
        Buda2[Return]=ObjectStore_br;
        ObjectStore[ObjectStore_br+1]=M1;  // object name
        if ((ObjectStore_br+8)>=OBJ_STORE && correct_OBJ_ST() )
        {
          MessageBoxA(NUL,"Object Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
          return(3);
        }
        ObjectStore[ObjectStore_br]=CLASS_SYSTEM_SOCKET;
        ObjectStore[ObjectStore_br+2]= (DWORD)client;
        ObjectStore_br+=8;
        return(1);
      }
      return(0);
     }
#endif // !CONSOLE
     case 300:    // get_program_argument
     {
#if UNIX
      i = Buda2[Arguments];
      if (++i >= numberArgs)
        return(0);

      char *elem = arguments[i];
      i = sv_StStore;
      for(j = 0; elem[j] != 0; StringStore[i++] = elem[j++]);
      if (i==sv_StStore)
        Buda2[Return]=0;
      else
      {
        StringStore[i++]=0;
        Buda2[Return]=sv_StStore;
        sv_StStore=i;
      }
      Buda1[Return]=TT_STR;
      return(1);
#endif // UNIX
     }
     case 352:    //read_con
      j = 0;
      i = getchar();
      while(i != (char)'\n')
      {
        (StringStore+sv_StStore)[j++] = (char) i;
        i = getchar();
      }    
      Buda1[Return]=TT_STR;
      Buda2[Return]=sv_StStore;
      sv_StStore+=strlen((LPSTR)(StringStore+sv_StStore))+1;
      return(1);
     case 126:        // not_deeper_than(Deep)
      if ((int)Buda2[Arguments]<=0)
        return(0);
      if (stack_br+4+4*Buda2[Arguments]>=STACK2)
        correct_Stack();
      m=STACK2;
      STACK2=stack_br+4+4*Buda2[Arguments];
      if (!(pInfo2->m_Settings&4)) // Stack is Full as Fail
      {
        m|=HALF;
        pInfo2->m_Settings|=4;
      }
      Link[sv_subv++]=m;
      Stack[stack_br+3]|=QUARTER;  // No Cut!
      return(1);
     case 127:        // not_deeper_than(Deep)
      STACK2=Link[--sv_subv];
      if (STACK2&HALF)
      {  
        pInfo2->m_Settings&=M1^4;
        STACK2&=HALFM;
      }
      return(0);
     case 52:        // scan from String to term
      strcpy((LPSTR)string, (LPSTR)(StringStore+Buda2[Arguments]));
      len=strlen((LPSTR)string);
      i_poin=0;
      f_end=len+3;
      strcpy((LPSTR)(string+len), " . ");
      if (read_n(&k, 2))
      {
        if (k>=MEMORY_c256)
        {
          Buda1[Return]=k;
          Buda2[Return]=sv_subv;
          for (i=list_br; i; i--, Link[sv_subv++]=buda_br++);
          a1=buda_br;
        }
        else if (k==TT_VAR)
        {
          Buda2[Return]=Buda2[buda_br];
          Buda1[Return]=Buda1[buda_br];
          Buda1[buda_br]=TT_VAR;
        }
        else
          Buda1[Return]=k;
        return(1); 
      }
      error=0;
      return(0);
     case 63:        // for - step==1
      if (Buda1[Arguments+3]==TT_LINK)
      {
        Buda1[Arguments+3]=TT_INT;
        Buda2[Arguments+3]=1;
      }
      if (((int)Buda2[Arguments+3]>0)?((int)Buda2[Arguments+1]>(int)Buda2[Arguments+2]):
                                      ((int)Buda2[Arguments+1]<(int)Buda2[Arguments+2]))
        return(0);
      Buda1[Buda2[Arguments]]=TT_INT;  // temp
      Buda2[Buda2[Arguments]]=Buda2[Arguments+1];
      return(1);
     case 64:        // for (tail pointer is to himself)
      Buda2[Buda2[Arguments]]+=Buda2[Arguments+3];
      if (Buda1[Buda2[Arguments]]!=TT_INT
       || (((int)Buda2[Arguments+3]>0)?((int)Buda2[Buda2[Arguments]]>(int)Buda2[Arguments+2]):
                                       ((int)Buda2[Buda2[Arguments]]<(int)Buda2[Arguments+2])) )
      {
        Buda1[Buda2[Arguments]]=TT_VAR;
        return(0);
      }
      else
        return(1);
     case 137:  // rgb(Color, R, G, B) predicate
      if (Buda1[Arguments]==TT_INT) 
      {
        if (Buda1[Arguments+1]==TT_LINK && Buda1[Arguments+2]==TT_LINK && Buda1[Arguments+3]==TT_LINK)
        {
          Buda1[Buda2[Arguments+1]]=Buda1[Buda2[Arguments+2]]=Buda1[Buda2[Arguments+3]]=TT_INT;
          Buda2[Buda2[Arguments+1]]=Buda2[Arguments]&0xff;
          Buda2[Buda2[Arguments+2]]=(Buda2[Arguments]&0xff00) >> 8;
          Buda2[Buda2[Arguments+3]]=(Buda2[Arguments]&0xff0000) >> 16;
          WILL_CLEAN(Buda2[Arguments+1]);
          WILL_CLEAN(Buda2[Arguments+2]);
          WILL_CLEAN(Buda2[Arguments+3]);
          return(1);
        }
        else if (Buda1[Arguments+1]==TT_INT && Buda1[Arguments+2]==TT_INT && Buda1[Arguments+3]==TT_INT
          && Buda2[Arguments+1]==(Buda2[Arguments]&0xff)
           && Buda2[Arguments+2]==((Buda2[Arguments]&0xff00) >> 8)
            && Buda2[Arguments+3]==((Buda2[Arguments]&0xff0000) >> 16) )
          return(1);
      }
      else if (Buda1[Arguments+1]==TT_INT && Buda1[Arguments+2]==TT_INT && Buda1[Arguments+3]==TT_INT
                && Buda2[Arguments+1]<256 && Buda2[Arguments+2]<256 && Buda2[Arguments+3]<256)
      {
        Buda1[Arguments]=TT_INT;
        Buda2[Arguments]=RGB(Buda2[Arguments+1], Buda2[Arguments+2], Buda2[Arguments+3]);
        WILL_CLEAN(Buda2[Arguments]);
        return(1);    
      }
      return(0);
     case 76:  // rgb(R, G, B) function
      if (Buda2[Arguments]<256 && Buda2[Arguments+1]<256 && Buda2[Arguments+2]<256)
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]=RGB(Buda2[Arguments], Buda2[Arguments+1], Buda2[Arguments+2]);
        return(1);    
      }
      return(0);
     case 388:        // sub_string(Sub, S, Start, Length)
     case 389:        // sub_string_no
     case 390:        // string_end
     case 391:        // string_end_no
#if PROF==0
      if (ch_set==0 && !(status_fl&512))
      {
        MitiText("Error: In the Light edition you cannot use sub_string and string_end for Unicode strings. Do this with another char set or with higher edition.\r\n", &cf_red);
        return(0);
      }
#endif
      if (Buda1[Arguments]==TT_STR) // Find
      {
        if (Buda1[Arguments+2]==TT_INT) // check
        {
E5:       if (ch_set)
          {
            for (i=Buda2[Arguments+1], p=0; StringStore[i] && p<Buda2[Arguments+2]; i++, p++);
            if (p!=Buda2[Arguments+2])
              p=M1;
          }
          else
            p=take_first(Buda2[Arguments+1], Buda2[Arguments+2]);
          if (p==M1) // Start>strlen(S)
          {
            Link[sv_subv++]=0; // thats it
            return(0);
          }
          if (p_line&1)
            for (i=Buda2[Arguments+1]+p, j=Buda2[Arguments]; StringStore[j] && 
            (StringStore[i]==StringStore[j] || ((StringStore[i]<StringStore[j])
            ?(StringStore[i]+32==StringStore[j] && StringStore[i] >= 'A' && StringStore[i] <= 'Z')
            :(StringStore[i]-32==StringStore[j] && StringStore[i] >= 'a' && StringStore[i] <= 'z')));
                    i++, j++);
          else
            for (i=Buda2[Arguments+1]+p, j=Buda2[Arguments];
              StringStore[j] && StringStore[j]==StringStore[i]; i++, j++);
          if (StringStore[j]!=0 || (p_line>389 && StringStore[i]!=0))
          {
            Link[sv_subv++]=0; // thats it
            return(0);
          }
          n=ch_set?(j-Buda2[Arguments]):new_strlen(Buda2[Arguments]);
          if (Buda1[Arguments+3]==TT_LINK)
          {
            Link[sv_subv++]=0; // thats it
            Buda1[Buda2[Arguments+3]]=TT_INT;
            Buda2[Buda2[Arguments+3]]=n;
            WILL_CLEAN(Buda2[Arguments+3]);
            return(1);
          }
          else if (Buda1[Arguments+3]==TT_INT && Buda2[Arguments+3]==n)
          {
            Link[sv_subv++]=0; // thats it
            return(1);
          }
        }
        else // all  (Buda1[Arguments+2]==TT_LINK)
        {
          n=Buda2[Arguments+1]; p=0;
          if (ch_set)
            k=strlen((LPSTR)(StringStore + (t=Buda2[Arguments]) ));
          else
            k=new_strlen(t=Buda2[Arguments]);
          if (Buda1[Arguments+3]==TT_LINK && Buda2[Arguments+2]==Buda2[Arguments+3]) // , K, K),
          {
            Buda2[Arguments+2]=k;
            goto E5;
          }
          do
          {
            if (ch_set==0)
              for ( ; (StringStore[n]&0xc0)==0x80; n++);
            if (p_line&1)
              for (i=n, j=t; StringStore[j] && 
              (StringStore[i]==StringStore[j] || ((StringStore[i]<StringStore[j])
              ?(StringStore[i]+32==StringStore[j] && StringStore[i] >= 'A' && StringStore[i] <= 'Z')
              :(StringStore[i]-32==StringStore[j] && StringStore[i] >= 'a' && StringStore[i] <= 'z')));
                      i++, j++);
            else
              for (i=n, j=t; StringStore[j] && StringStore[j]==StringStore[i]; i++, j++);
            if (StringStore[j]==0 && (p_line<=389 || StringStore[i]==0))
            {
              Link[sv_subv++]=p; // from where
              Link[sv_subv++]=n-Buda2[Arguments+1]; // from where
              if (Buda1[Arguments+3]==TT_LINK)
              {
                Link[sv_subv++]=2+(ch_set==0); // found it + free Length
                Buda1[Buda2[Arguments+3]]=TT_INT;
                Buda2[Buda2[Arguments+3]]=k;
                WILL_CLEAN(Buda2[Arguments+3]);
              }
              else if (Buda1[Arguments+3]==TT_INT && Buda2[Arguments+3]==k)
                Link[sv_subv++]=4+(ch_set==0); // found it
              else
              {
                Link[--sv_subv-1]=0; // thats it
                return(0);
              }
              Buda1[Buda2[Arguments+2]]=TT_INT;
              Buda2[Buda2[Arguments+2]]=p; // from where
              WILL_CLEAN(Buda2[Arguments+2]);
              return(1);
            }
            p++;
          }
          while (StringStore[n++]!=0);
        }
        Link[sv_subv++]=0; // thats it
        return(0);
      }
      else // Take substring (Buda1[Arguments]==TT_LINK)
      {
        if (ch_set)
          k=strlen((LPSTR)(StringStore+Buda2[Arguments+1]));
        else
          k=new_strlen(Buda2[Arguments+1]);
        if (Buda1[Arguments+2]==TT_INT)
        {
          if (Buda1[Arguments+3]==TT_INT)
          {
            if (k==Buda2[Arguments+2]+Buda2[Arguments+3])
            {
              Link[sv_subv++]=0; // thats it
              Buda1[Buda2[Arguments]]=TT_STR;
              p=ch_set?Buda2[Arguments+2]:take_first(Buda2[Arguments+1], Buda2[Arguments+2]);
              Buda2[Buda2[Arguments]]=Buda2[Arguments+1]+p;
              WILL_CLEAN(Buda2[Arguments]);
              return(1);
            }
            else if (k<Buda2[Arguments+2]+Buda2[Arguments+3] || p_line>389)
            {
              Link[sv_subv++]=0; // thats it
              return(0);
            }
            if (ch_set)
              for (i=Buda2[Arguments+1]+Buda2[Arguments+2], j=0; 
                     j<Buda2[Arguments+3]; StringStore[sv_StStore+j]=StringStore[i], i++, j++);
            else
            {
              p=take_first(Buda2[Arguments+1], Buda2[Arguments+2]);
              for (i=Buda2[Arguments+1]+p, j=n=0; 1; StringStore[sv_StStore+j]=StringStore[i], i++, j++)
                if ((StringStore[i]&0xc0)!=0x80)
                {
                  if (n>=Buda2[Arguments+3])
                    break;
                  n++;
                }
            }
            if (sv_StStore+j>=STRING_STORE && correct_STR_ST() )
              goto FULL;
            Link[sv_subv++]=0; // thats it
            Buda1[Buda2[Arguments]]=TT_STR;
            Buda2[Buda2[Arguments]]=sv_StStore;
            WILL_CLEAN(Buda2[Arguments]);
            sv_StStore+=j;
            StringStore[sv_StStore++]=0;
            return(1);
          }
          else // (Buda1[Arguments+3]==TT_LINK)
          {
            if (k<Buda2[Arguments+2])
            {
              Link[sv_subv++]=0; // thats it
              return(0);
            }
            Buda1[Buda2[Arguments]]=TT_STR;
            p=ch_set?Buda2[Arguments+2]:take_first(Buda2[Arguments+1], Buda2[Arguments+2]);
            Buda2[Buda2[Arguments]]=Buda2[Arguments+1]+p;
            Buda1[Buda2[Arguments+3]]=TT_INT;
            Buda2[Buda2[Arguments+3]]=k-Buda2[Arguments+2];
            if (p_line>389)  // end
              Link[sv_subv++]=0; // thats it
            else if (ch_set)
            {
              Link[sv_subv++]=k-Buda2[Arguments+2];
              Link[sv_subv++]=6; // for Length
            }
            else
            {
              Link[sv_subv++]=p;
              Link[sv_subv++]=k-Buda2[Arguments+2];
              Link[sv_subv++]=7; // for Length
            }
            WILL_CLEAN(Buda2[Arguments]);
            WILL_CLEAN(Buda2[Arguments+3]);
            return(1);
          }
        }
        else // (Buda1[Arguments+2]==TT_LINK)
        {
          if (Buda1[Arguments+3]==TT_INT)
          {
            if (k<Buda2[Arguments+3])
            {
              Link[sv_subv++]=0; // thats it
              return(0);
            }
            Buda1[Buda2[Arguments]]=TT_STR;
            p=ch_set?(k-Buda2[Arguments+3]):take_first(Buda2[Arguments+1], k-Buda2[Arguments+3]);
            Buda2[Buda2[Arguments]]=Buda2[Arguments+1]+p;
            Buda1[Buda2[Arguments+2]]=TT_INT;
            Link[sv_subv++]=Buda2[Buda2[Arguments+2]]=k-Buda2[Arguments+3];
            if (p_line>389)  // end
              Link[sv_subv-1]=0; // thats it
            else
              Link[sv_subv++]=8+(ch_set==0); // for Start
            WILL_CLEAN(Buda2[Arguments]);
            WILL_CLEAN(Buda2[Arguments+2]);
            return(1);
          }
          else // (Buda1[Arguments+3]==TT_LINK)
          {
            Link[sv_subv++]=k;
            Buda1[Buda2[Arguments]]=TT_STR;
            Link[sv_subv++]=Buda2[Buda2[Arguments]]=Buda2[Arguments+1];
            Buda1[Buda2[Arguments+2]]=TT_INT;
            Link[sv_subv++]=Buda2[Buda2[Arguments+2]]=0;
            Buda1[Buda2[Arguments+3]]=TT_INT;
            Link[sv_subv++]=Buda2[Buda2[Arguments+3]]=k;
            Link[sv_subv++]=10+(ch_set==0); // for Start and Length
            WILL_CLEAN(Buda2[Arguments]);
            WILL_CLEAN(Buda2[Arguments+2]);
            WILL_CLEAN(Buda2[Arguments+3]);
            return(1);
          }
        }
      }
     case 392:        // sub_string (tail pointer is to himself)
     case 393:        // sub_string_no
     case 394:        // string_end
     case 395:        // string_end_no
#if PROF==0
      if (ch_set==0 && !(status_fl&512))
        return(0);
#endif
      switch(Link[sv_subv-1])
      {
       case 0: // thats it
        sv_subv--;
        return(0);
       case 2: // found it + free Length
       case 3: // found it + free Length  (Unicode)
       case 4: // found it
       case 5: // found it                (Unicode)
        n=Buda2[Arguments+1]+Link[sv_subv-2];
        t=Buda2[Arguments];
        while (StringStore[n++]!=0)
        {
          if (Link[sv_subv-1]&1)
            for ( ; (StringStore[n]&0xc0)==0x80; n++);
          Link[sv_subv-3]++;
          if (p_line&1)
            for (i=n, j=t; StringStore[j] && 
            (StringStore[i]==StringStore[j] || ((StringStore[i]<StringStore[j])
            ?(StringStore[i]+32==StringStore[j] && StringStore[i] >= 'A' && StringStore[i] <= 'Z')
            :(StringStore[i]-32==StringStore[j] && StringStore[i] >= 'a' && StringStore[i] <= 'z')));
                    i++, j++);
          else
            for (i=n, j=t; StringStore[j] && StringStore[j]==StringStore[i]; i++, j++);
          if (StringStore[j]==0)
          {
            Buda1[Buda2[Arguments+2]]=TT_INT;
            Buda2[Buda2[Arguments+2]]=Link[sv_subv-3];
            Link[sv_subv-2]=n-Buda2[Arguments+1]; // from where
            if (Link[sv_subv-1]<4)
            {
              Buda1[Buda2[Arguments+3]]=TT_INT;
              Buda2[Buda2[Arguments+3]]=(Link[sv_subv-1]&1)?new_strlen(Buda2[Arguments]):(j-t);
              WILL_CLEAN(Buda2[Arguments+3]);
            }
            WILL_CLEAN(Buda2[Arguments+2]);
            return(1);
          }
        }
        sv_subv-=3;
        return(0);
       case 6: // for Length
       case 7: // for Length (Unicode)
        n=Link[sv_subv-2]--;
        if (n-->0)
        {
          Buda1[Buda2[Arguments+3]]=TT_INT;
          Buda2[Buda2[Arguments+3]]=n;
          Buda1[Buda2[Arguments]]=TT_STR;
          if (n==0)
            Buda2[Buda2[Arguments]]=0;
          else
          {
            if (Link[sv_subv-1]==7)
            {
              for (i=Buda2[Arguments+1]+Link[sv_subv-3], j=t=0; 1; StringStore[sv_StStore+j]=StringStore[i], i++, j++)
                if ((StringStore[i]&0xc0)!=0x80)
                {
                  if (t>=n)
                    break;
                  t++;
                }
            }
            else
              for (i=Buda2[Arguments+1]+Buda2[Arguments+2], j=0; j<n; StringStore[sv_StStore+j]=StringStore[i], i++, j++);
            if (sv_StStore+j>=STRING_STORE && correct_STR_ST() )
              goto FULL;
            Buda2[Buda2[Arguments]]=sv_StStore;
            sv_StStore+=j;
            StringStore[sv_StStore++]=0;
          }
          WILL_CLEAN(Buda2[Arguments]);
          WILL_CLEAN(Buda2[Arguments+3]);
          return(1);
        }
        sv_subv-=2;
        if (Link[sv_subv-1]==7)
          sv_subv--;
        return(0);
       case 8: // for Start
       case 9: // for Start (Unicode)
        k=Link[sv_subv-2]--;
        if (k-->0)
        {
          Buda1[Buda2[Arguments+2]]=TT_INT;
          Buda2[Buda2[Arguments+2]]=k;
          Buda1[Buda2[Arguments]]=TT_STR;
          if (Buda2[Arguments+3]==0)
            Buda2[Buda2[Arguments]]=0;
          else
          {
            if (Link[sv_subv-1]==9)
            {
              p=take_first(Buda2[Arguments+1], k);
              for (i=Buda2[Arguments+1]+p, j=t=0; 1; StringStore[sv_StStore+j]=StringStore[i], i++, j++)
                if ((StringStore[i]&0xc0)!=0x80)
                {
                  if (t>=Buda2[Arguments+3])
                    break;
                  t++;
                }
            }
            else
              for (i=Buda2[Arguments+1]+k, j=0; j<Buda2[Arguments+3]; StringStore[sv_StStore+j]=StringStore[i], i++, j++);
            if (sv_StStore+j>=STRING_STORE && correct_STR_ST() )
              goto FULL;
            Buda2[Buda2[Arguments]]=sv_StStore;
            sv_StStore+=j;
            StringStore[sv_StStore++]=0;
          }
          WILL_CLEAN(Buda2[Arguments]);
          WILL_CLEAN(Buda2[Arguments+2]);
          return(1);
        }
        sv_subv-=2;
        return(0);
       case 10: // for Start and Length
       case 11: // for Start and Length (Unicode)
        if (Link[sv_subv-2]-->0)
        {
          if (Link[sv_subv-1]==11)
            Link[sv_subv-4]+=take_first(Link[sv_subv-4], 1);
          else
            Link[sv_subv-4]++;
          Link[sv_subv-3]++;
        }
        else if (p_line<=393 && Link[sv_subv-5]-->0)
        {
          Link[sv_subv-2]=k=Link[sv_subv-5];
          Link[sv_subv-3]=0;
          if (k==0)
            Link[sv_subv-4]=0;
          else
          {
            if (Link[sv_subv-1]==11)
            {
              for (i=Buda2[Arguments+1], j=t=0; 1; StringStore[sv_StStore+j]=StringStore[i], i++, j++)
                if ((StringStore[i]&0xc0)!=0x80)
                {
                  if (t>=k)
                    break;
                  t++;
                }
            }
            else
              for (i=Buda2[Arguments+1], j=0; j<k; StringStore[sv_StStore+j]=StringStore[i], i++, j++);
            if (sv_StStore+j>=STRING_STORE && correct_STR_ST() )
              goto FULL;
            Link[sv_subv-4]=sv_StStore;
            sv_StStore+=j;
            StringStore[sv_StStore++]=0;
          }
        }
        else
        {
          sv_subv-=5;
          return(0);
        }
        Buda1[Buda2[Arguments]]=TT_STR;
        Buda2[Buda2[Arguments]]=Link[sv_subv-4];
        Buda1[Buda2[Arguments+2]]=TT_INT;
        Buda2[Buda2[Arguments+2]]=Link[sv_subv-3];
        Buda1[Buda2[Arguments+3]]=TT_INT;
        Buda2[Buda2[Arguments+3]]=Link[sv_subv-2];
        WILL_CLEAN(Buda2[Arguments]);
        WILL_CLEAN(Buda2[Arguments+2]);
        WILL_CLEAN(Buda2[Arguments+3]);
        return(1);
      }
      return(0); // for bugs protection
     case 122: // str_length(S)
      if (ch_set)
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]=strlen((LPSTR)(StringStore+Buda2[Arguments]));
        return(1);
      }
#if PROF==0
      else if (!(status_fl&512))
      {
        MitiText("Error: In the Light edition you cannot use str_length for Unicode strings. Do this with another char set or with higher edition.\r\n", &cf_red);
        return(0);
      }
#endif
      else
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]=new_strlen(Buda2[Arguments]);
        return(1);
      }
     case 239:        // on_the_last_step
      if (Buda1[Arguments]!=37)  // a - any
      {
        i=Link[(j=Ekler[Stack[stack_br-1]&MASKA2])+3];  // durty_br
        do
        {
          k=Link[j+2]; // > 0 or ==0
          n=Link[j+1];
          if (Buda1[Arguments]==55)  // s - similar
          {
            for (j-=3*(Link[j+3]-i); i>k; i--)
              if (Buda1[Link[j-=3]]!=TT_LINK || Buda1[Buda2[Link[j]]]<TT_VAR || Buda1[Buda2[Link[j]]]>TT_OBJ)
                return(0);
          }
          else  // e - exactly
          {
            for (j-=3*(Link[j+3]-i); i>k; i--)
              if (Buda1[Link[j-=3]]!=TT_LINK || Buda1[Buda2[Link[j]]]!=TT_VAR)
                return(0);
          }
        }
        while (j=n);
      }
      Buda1[Return]=TT_INT;
      Buda2[Return]=Link[Ekler[Stack[stack_br-1]&MASKA2]]-program_br2;
      return(1);
     case 267:        // the_head_of
      k=Buda2[Arguments]+program_br2;
      if ((Prog_fild[Program[k]+1]&OBSEG1) || k>=program_br || (k<program_br2 && k>=program_br1) || Program[k]&HALF)
        return(0);
      Buda1[Buda2[Arguments+1]]=Prog_fild[Program[k]];
      if (Buda1[Buda2[Arguments+1]]>=MEMORY_c256)
      {
        Buda2[Buda2[Arguments+1]]=sv_subv;
        for (i=Chfil_v[Buda1[Buda2[Arguments+1]]-MEMORY_c256]; i; i--, Link[sv_subv++]=buda_br++, my_gl++);
        a1=buda_br;
      }
      WILL_CLEAN(Buda2[Arguments+1]);
      return(1);
     case 268:        // set_at
     case 269:        // retract_at
      my_gl2=Buda2[Arguments]+program_br2;
      if (my_gl2>=program_br || (my_gl2<program_br2 && my_gl2>=program_br1))
        return(0);
      if (Pointers[k=Prog_fild[Program[my_gl2]]]&HALF)
      {
        if (D_field[Pointers[k]&MASKA3]==my_gl2)
        {
          if (ProgTail[my_gl2]==M1 || ProgTail[my_gl2]==my_gl2)
          {
            D_field[Pointers[k]&MASKA3]=M1;
            Pointers[k]&=HALFM;
            Unregister(k, HALF);
          }
          else
            D_field[Pointers[k]&MASKA3]=ProgTail[my_gl2];
        }
        else
        {
          for (i=D_field[Pointers[k]&MASKA3]; ProgTail[i]!=my_gl2; i=ProgTail[i]);
          if (ProgTail[my_gl2]==my_gl2)
            ProgTail[i]=M1;
          else
            ProgTail[i]=ProgTail[my_gl2];
        }
        Prog_fild[Program[my_gl2]+1]|=OBSEG1;
      }
      if (p_line==269)
        return(1);
      len=0;
      write_p( TT_VAR, 0, Arguments+1);
      i_poin=0;
      f_end=len+3;
      strcpy((LPSTR)(string2+len), " . ");
      string2[f_end]=0;
      strcpy((LPSTR)string, (LPSTR)string2);
      j=read_n(&t, 10);
      if (j==1)
      {
        i=my_gl2;
        Prog_Obj[i]=Prog_Obj[program_br]; // for assert_a
        Program[i]=t;
        assert(i, 1);
        j=Prog_fild[Program[i]];
        if (Pointers[j] & HALF)
        {
          for (t=D_field[Pointers[j] & MASKA3]; ProgTail[t]!=M1 && ProgTail[t]<i; t=ProgTail[t])
            if (ProgTail[t]==t)
            {
              MitiText("Error: Unreachable clause (after :--).\r\n", &cf_red);
              return(0);
            }
          ProgTail[i]=ProgTail[t];
          ProgTail[t]=i;
        }
        else 
        {
          if (registrate(j, HALF) != j)
            MitiText("It can't be. Diferent2a\r\n");
          put_in_f(i, j, 0, HALF);
          ProgTail[i]=M1;
        }
        for(i=0; i<list_br; Buda1[buda_br+i++]=TT_VAR); //temp
        return(1);
      }
      else
      {
        for(i=0; i<list_br; Buda1[buda_br+i++]=TT_VAR); //temp
        return(0);
      }
     case 270:        // modify_at
      m=Buda2[Arguments]+program_br2;
      if (m>=program_br || (m<program_br2 && m>=program_br1)
           || !(Prog_fild[Program[m]+1]&HALF)
             || Buda1[Arguments+2]>TT_OBJ || Buda1[Arguments+2]<TT_LINK)
        return(0);
      k=Prog_fild[j=Prog_fild[Program[m]+1]&MASKA1];
      do
      {
        if (k==Buda2[Arguments+1])
        {
          Prog_fild[j+1]=Buda1[Arguments+2];
          Prog_fild[j+2]=Buda2[Arguments+2];
          return(1);
        }
        k=Prog_fild[j+=3];
      }
      while (k!=M1);
      return(0);
     case 54:        // Assert
     case 55:        // in Text
     case 56:        // Assert_a
     case 57:        // Assert_a in Text
      if (p_line>55 && program_br1==program_br2)
      {
        MitiText("Error: Asserta - fails.\r\n", &cf_red);
        return(0);
      }
      len=0;
      write_p( TT_VAR, 0, Arguments);
      i_poin=0;
      f_end=len+3;
      strcpy((LPSTR)(string2+len), " .\n");
      string2[f_end]=0;
      strcpy((LPSTR)string, (LPSTR)string2);
      j=read_n(&t, 10);
      if (j)
      {
#if !CONSOLE
        if ((p_line&1) && pActive)
        {
          int cNumber;

          if (p_line==55)
          {
            cNumber=Program2[program_br];
            Program2[program_br+1]=cNumber+strlen((LPSTR)string);
          }
          else
          {
            cNumber=0;
            i=strlen((LPSTR)string);
            Program2[--program_br2]=0;
            for(j=program_br2; j<program_br; Program2[++j]+=i);
          }
          pActiveCtrl->SetSel( cNumber, cNumber);
          //SendMessage (hwndTemp, EM_SCROLLCARET, 0, 0);
          pActiveCtrl->ReplaceSel(make_long((BYTE *)string), TRUE); //? TRUE or FALSE
        }
        else
#endif // !CONSOLE
        if (p_line<56)
          Program2[program_br+1]=Program2[program_br];
        else
          Program2[--program_br2]=0;
        if (p_line<56 && program_br>=PROGRAM_L && correct_PROG_L() )
        {
          MitiText("Program is too long!\r\n");
          return(0);
        }
        i=(p_line>55)?program_br2:program_br;
        Prog_Obj[i]=Prog_Obj[program_br]; // for assert_a
        Program[i]=t;
        assert(i, p_line>55);
        j=Prog_fild[Program[i]];
        if (Pointers[j] & HALF)
        {
          if (p_line>55)
          {
            ProgTail[i]=D_field[Pointers[j] & MASKA3];
            D_field[Pointers[j] & MASKA3]=i;
          }
          else
          {
            for (t=D_field[Pointers[j] & MASKA3]; ProgTail[t]!=M1; t=ProgTail[t])
              if (ProgTail[t]==t)
              {
                MitiText("Error: Unreachable clause (after :--).\r\n", &cf_red);
                return(0);
              }
            ProgTail[t]=program_br;
            ProgTail[program_br++]=M1;
          }
        }
        else 
        {
          if (registrate(j, HALF) != j)
            MitiText("It can't be. Diferent2b\r\n");
          put_in_f(i, j, 0, HALF);
          if (p_line>55)
            ProgTail[program_br2]=M1;
          else
            ProgTail[program_br++]=M1;
        }
        for(i=0; i<list_br; Buda1[buda_br+i++]=TT_VAR); //temp
        return(1);
      }
      else
      {
        for(i=0; i<list_br; Buda1[buda_br+i++]=TT_VAR); //temp
        return(0);
      }
     case 58:         // retract
     case 59:         // retract_in
      m=STACK2;
      STACK2=stack_br;
      a1=buda_br;
      Buda1[buda_br]=TT_LINK;
      Buda2[buda_br++]=Arguments;  // acsiom
      Stack[stack_br]|=HALF;
      Ekler[++ekler_br]=4*FIRST_ROWS-8; // 8
      Stack[stack_br+3]=ekler_br;
      my_gl2=FIRST_ROWS-2;
      status_fl|=32;
      j=call(3);
      status_fl^=32;
      STACK2=m;
      if (j==0)
      {
        Buda1[--buda_br]=TT_VAR;
        Stack[stack_br]&=HALFM;
        ekler_br=--Stack[stack_br+3];
        return(0); // for Retractall will be 1
      }
      Stack[stack_br-=4]&=HALFM;
      if (j>1)
#if CONSOLE
        return(j);
#else
        pMainFrame->PostMessage(WM_USER+1, j, 0); // OnEnd
#endif // CONSOLE
      if (D_field[Pointers[k=Prog_fild[Program[my_gl2]]]&MASKA3]==my_gl2)
      {
        if (ProgTail[my_gl2]==M1 || ProgTail[my_gl2]==my_gl2)
        {
          D_field[Pointers[k]&MASKA3]=M1;
          Pointers[k]&=HALFM;
          Unregister(k, HALF);
        }
        else
          D_field[Pointers[k]&MASKA3]=ProgTail[my_gl2];
      }
      else
      {
        for (i=D_field[Pointers[k]&MASKA3]; ProgTail[i]!=my_gl2; i=ProgTail[i]);
        if (ProgTail[my_gl2]==my_gl2)
          ProgTail[i]=M1;
        else
          ProgTail[i]=ProgTail[my_gl2];
      }
#if 0 // Soskov bug
      if (my_gl2==program_br-1)
      {
        i=my_gl2;
        k=Program[program_br2];
        do
        {
          program_br--;
          if (Program[i]>k)
            p_fild_br=Program[i--];
          else
          {
            while (Prog_fild[Program[--i]+1]&OBSEG1)
              program_br--;
            break;
          }
        }
        while (Prog_fild[Program[i]+1]&OBSEG1);
      }
      else if (my_gl2==program_br2)
      {
        i=my_gl2;
        k=Program[program_br-1];
        do
        {
          program_br2++;
          if (Program[i]>k)
            p_fild_br=Program[i++];
          else
          {
            while (Prog_fild[Program[++i]+1]&OBSEG1)
              program_br2++;
            break;
          }
        }
        while (Prog_fild[Program[i]+1]&OBSEG1);
      }
      else
#endif // Soskov bug
        Prog_fild[Program[my_gl2]+1]|=OBSEG1;
      //ProgTail[my_gl2]=M1; //bug correction
      j=Ekler[ekler_br];
      ekler_br=--Stack[stack_br+3];
      i=Link[j+3];  // durty_br
      do
      {
        k=Link[j+2]; // > 0 or ==0
        n=Link[j+1];
        for (j-=3*(Link[j+3]-i); i>k; i--, Buda1[Link[j-=3]]=TT_VAR);
      }
      while (j=n);
      buda_br=Link[Stack[Stack[stack_br+4]+2]-Stack[stack_br+5]];
      if (Prog_fild[Program[my_gl2]+1]&HALF)// clean standard types by the head
        for (p=Link[--sv_subv]; p; p--, Buda1[Link[--sv_subv]]=TT_VAR);
      sv_subv=Stack[stack_br+2]-1;  // +1-2
      Buda1[buda_br--]=TT_VAR; // for X:-X.
      Buda1[buda_br]=TT_VAR;
#if !CONSOLE
      if (p_line==59 && my_gl2>=program_br2 && pActive)
      {
        pActiveCtrl->SetSel( Program2[my_gl2], Program2[my_gl2+1]);
        //SendMessage (hwndTemp, EM_SCROLLCARET, 0, 0);
        pActiveCtrl->ReplaceSel( _T(""), TRUE); //? TRUE or FALSE
        i=Program2[my_gl2+1]-Program2[my_gl2];
        for(j=my_gl2; j<program_br; Program2[++j]-=i);
      }
#endif // !CONSOLE
      return(1);

#if 0  // garbichka colektion
          if (garbage_br++>GARBAGE_cl && (stack_br<600 || garbage_br>GARBAGE_cl2))
          {
            for (i=stack_br-4; i>2; i-=7)
            {
              for (j=(Stack[i]&HALFM)+1, n=0;  j>0; )
                if (Program[--j]==Definition[DF_Cherga])          // [#]
                  n++;
              Stack[i]-=n;
            }
            for (j=3, n=0;  j<program_br; j++)
            {
              if (Program[j]==Definition[DF_Cherga])
                n++;
              else
              {
                Program[j-n]=Program[j];
              }
            }
            program_br-=n;
            garbage_br=0;
          }
#endif  // garbichka colektion

     case 151:        // chronometer_steps
     {
      static DWORD IntSteps=0;
        
      i=0x10000*lSteps_br+Steps_br-Corection;
      if (Return==M1)
      {
        Buda1[Buda2[Arguments]]=TT_INT;
        Buda2[Buda2[Arguments]]=i-IntSteps;
        WILL_CLEAN(Buda2[Arguments]);
      }
      else
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]=i-IntSteps;
      }
      IntSteps=i;
      return(1);
     }
#if CONSOLE
     case 61:        // chronometer
     {
      static long IntTime1=0;
      long IntTime2;
        
      time( &IntTime2);
      if (Return==M1)
      {
        Buda1[Buda2[Arguments]]=TT_INT;
        Buda2[Buda2[Arguments]]=1000*(IntTime2-IntTime1);
        WILL_CLEAN(Buda2[Arguments]);
      }
      else
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]=1000*(IntTime2-IntTime1);
      }
      IntTime1=IntTime2;
      return(1);
     }
#else
     case 61:        // chronometer
     {
      SYSTEMTIME LokTime;
      static DWORD IntTime1=0;
      DWORD IntTime2;
        
      GetLocalTime(&LokTime);
      IntTime2=3600000*LokTime.wHour + 60000*LokTime.wMinute
                   + 1000*LokTime.wSecond + LokTime.wMilliseconds;
      if (IntTime2>=IntTime1)
        k=IntTime2-IntTime1;
      else
        k=86400000+IntTime2-IntTime1; // 24*3600 sec
      if (Return==M1)
      {
        Buda1[Buda2[Arguments]]=TT_INT;
        Buda2[Buda2[Arguments]]=k;
        WILL_CLEAN(Buda2[Arguments]);
      }
      else
      {
        Buda1[Return]=TT_INT;
        Buda2[Return]=k;
      }
      IntTime1=IntTime2;
      return(1);
     }
#endif // CONSOLE
     case 87:        // Get time
     {
      time_t time_T=Buda2[Arguments];
      struct tm *LocTime;

      if (Buda1[Arguments+1]!=TT_INT)
        LocTime = localtime(&time_T);
      else if (Buda1[Arguments+2]==TT_INT && Buda2[Arguments+2]==1)
      {  
        time_T+=Buda2[Arguments+1] + 5*3600; //+timezone;
        LocTime = localtime(&time_T);
      }
      else
      {  
        time_T+=Buda2[Arguments+1];
        LocTime = gmtime(&time_T);
      }

      if ( (Buda1[Arguments+3]==TT_INT && Buda2[Arguments+3]!=LocTime->tm_hour)
          || (Buda1[Arguments+4]==TT_INT && Buda2[Arguments+4]!=LocTime->tm_min)
            || (Buda1[Arguments+5]==TT_INT && Buda2[Arguments+5]!=LocTime->tm_sec) )
        return(0);
      if (Buda1[Arguments+3]==TT_LINK)
      {
        Buda1[Buda2[Arguments+3]]=TT_INT;
        Buda2[Buda2[Arguments+3]]=LocTime->tm_hour;
        WILL_CLEAN(Buda2[Arguments+3]);
      }
      if (Buda1[Arguments+4]==TT_LINK)
      {
        Buda1[Buda2[Arguments+4]]=TT_INT;
        Buda2[Buda2[Arguments+4]]=LocTime->tm_min;
        WILL_CLEAN(Buda2[Arguments+4]);
      }
      if (Buda1[Arguments+5]==TT_LINK)
      {
        Buda1[Buda2[Arguments+5]]=TT_INT;
        Buda2[Buda2[Arguments+5]]=LocTime->tm_sec;
        WILL_CLEAN(Buda2[Arguments+5]);
      }
      return(1);
     }
     case 88:        // Get date
     {
      time_t time_T=Buda2[Arguments];
      struct tm *LocTime;

      if (Buda1[Arguments+1]!=TT_INT)
        LocTime = localtime(&time_T);
      else if (Buda1[Arguments+2]==TT_INT && Buda2[Arguments+2]==1)
      {  
        time_T+=Buda2[Arguments+1] + 5*3600; //+timezone;
        LocTime = localtime(&time_T);
      }
      else
      {  
        time_T+=Buda2[Arguments+1];
        LocTime = gmtime(&time_T);
      }

      if ( (Buda1[Arguments+3]==TT_INT && Buda2[Arguments+3]!=(LocTime->tm_mday))
          || (Buda1[Arguments+4]==TT_INT && Buda2[Arguments+4]!=(LocTime->tm_mon+1))
            || (Buda1[Arguments+5]==TT_INT && Buda2[Arguments+5]!=(LocTime->tm_year+1900)) )
        return(0);
      if (Buda1[Arguments+3]==TT_LINK)
      {
        Buda1[Buda2[Arguments+3]]=TT_INT;
        Buda2[Buda2[Arguments+3]]=LocTime->tm_mday;
        WILL_CLEAN(Buda2[Arguments+3]);
      }
      if (Buda1[Arguments+4]==TT_LINK)
      {
        Buda1[Buda2[Arguments+4]]=TT_INT;
        Buda2[Buda2[Arguments+4]]=LocTime->tm_mon+1;
        WILL_CLEAN(Buda2[Arguments+4]);
      }
      if (Buda1[Arguments+5]==TT_LINK)
      {
        Buda1[Buda2[Arguments+5]]=TT_INT;
        Buda2[Buda2[Arguments+5]]=LocTime->tm_year+1900;
        WILL_CLEAN(Buda2[Arguments+5]);
      }
      return(1);
     }
#if 0
     case 87:        // Get time
     {
      SYSTEMTIME LokTime;
        
      GetLocalTime(&LokTime);
      if ( (Buda1[Arguments]==TT_INT && Buda2[Arguments]!=LokTime.wHour)
          || (Buda1[Arguments+1]==TT_INT && Buda2[Arguments+1]!=LokTime.wMinute)
            || (Buda1[Arguments+2]==TT_INT && Buda2[Arguments+2]!=LokTime.wSecond)
              || (Buda1[Arguments+3]==TT_INT && Buda2[Arguments+3]!=LokTime.wMilliseconds) )
        return(0);
      if (Buda1[Arguments]==TT_LINK)
      {
        Buda1[Buda2[Arguments]]=TT_INT;
        Buda2[Buda2[Arguments]]=LokTime.wHour;
        WILL_CLEAN(Buda2[Arguments]);
      }
      if (Buda1[Arguments+1]==TT_LINK)
      {
        Buda1[Buda2[Arguments+1]]=TT_INT;
        Buda2[Buda2[Arguments+1]]=LokTime.wMinute;
        WILL_CLEAN(Buda2[Arguments+1]);
      }
      if (Buda1[Arguments+2]==TT_LINK)
      {
        Buda1[Buda2[Arguments+2]]=TT_INT;
        Buda2[Buda2[Arguments+2]]=LokTime.wSecond;
        WILL_CLEAN(Buda2[Arguments+2]);
      }
      if (Buda1[Arguments+3]==TT_LINK)
      {
        Buda1[Buda2[Arguments+3]]=TT_INT;
        Buda2[Buda2[Arguments+3]]=LokTime.wMilliseconds;
        WILL_CLEAN(Buda2[Arguments+3]);
      }
      return(1);
     }
#endif // if 0
     case 353:  // replace
      {
      char *ReplaceIn=(LPSTR)(StringStore+Buda2[Arguments]),
           *ReplaceWhat=(LPSTR)(StringStore+Buda2[Arguments+1]),
           *ReplaceWith=(LPSTR)(StringStore+Buda2[Arguments+2]),
           *pCh;

      Buda1[Return]=TT_STR;
      if ((pCh=strstr(ReplaceIn, ReplaceWhat))==NULL)
      {
        Buda2[Return]=Buda2[Arguments];
        return(1);
      }
      i=sv_StStore;
      do
      {
          j = pCh - ReplaceIn;
          for(k=0; k<j; StringStore[i++]=ReplaceIn[k++]);
        for(k=0; ReplaceWith[k]!=0; StringStore[i++]=ReplaceWith[k++]);
        ReplaceIn += (j + strlen(ReplaceWhat));
      }
      while((pCh=strstr(ReplaceIn, ReplaceWhat)) != NULL);
      for(j=0; ReplaceIn[j]!=0; StringStore[i++]=ReplaceIn[j++]);
      if (i==sv_StStore)
        Buda2[Return]=0;
      else
      {
        StringStore[i++]=0;
        Buda2[Return]=sv_StStore;
        if ((sv_StStore=i)>=STRING_STORE && correct_STR_ST() )
          goto FULL;
      }
      return(1);
      }
#if PROF==2
     case 251:  // getenv
      if (Buda1[Arguments]==TT_STR)
      {
#if CONSOLE
        char *EnvString=getenv((LPSTR)(StringStore+Buda2[Arguments]));
        if (EnvString==NUL)
          return(0);
        strcpy((LPSTR)(StringStore+sv_StStore), EnvString);
        i=strlen(EnvString);
#else
        CString EnvString=pInfo2->m_GetMethod;
        i=ChangeCharset(M64_ch, ch_set, (BYTE *)(LPCTSTR)EnvString, StringStore+sv_StStore, &k, default_char);
#endif // CONSOLE
        if (i)
        {
          Buda2[Return]=sv_StStore;
          if ((sv_StStore+=i+1)>=STRING_STORE && correct_STR_ST() )
            goto FULL;
        }
        else
          Buda2[Return]=0;
      }
      else if (Buda1[Arguments]==Definition[DF_POST]) // posted form
      {
#if CONSOLE
        static DWORD posted_form=M1;
        if (posted_form==M1)
        {
          char *cont_len_str = getenv("CONTENT_LENGTH");
          if (cont_len_str == NULL)
            return(0);
          j = atoi(cont_len_str);
          for(i=0; i<j; i++)
            scanf("%c", StringStore+sv_StStore+i);
          StringStore[sv_StStore+i]=0;
#else
        DWORD posted_form=M1;
        if (posted_form==M1)
        {
          i=ChangeCharset(M64_ch, ch_set, (BYTE *)(LPCTSTR)(pInfo2->m_PostMethod), StringStore+sv_StStore, &k, default_char);
#endif // CONSOLE
          if (i)
          {
            Buda2[Return]=posted_form=sv_StStore;
            if ((sv_StStore+=i+1)>=STRING_STORE && correct_STR_ST() )
              goto FULL;
          }
          else
            Buda2[Return]=posted_form=0;
        }
        else
          Buda2[Return]=posted_form;
      }
      else
        return(0);
      Buda1[Return]=TT_STR;
      return(1);
     case 252:  // get_environment_arg
      EnvString=(LPSTR)(StringStore+Buda2[Arguments+1]);
      i=Buda2[Arguments];
      for(j=0; EnvString[j]!=0 && i; j++)
        if (EnvString[j]=='&' || EnvString[j]=='?')
          i--;
      if (EnvString[j]==0)
        return(0);
      goto decode;
     case 253:  // get_html_form
     {
      int symbol;
      char next1,next2;
      EnvString=(LPSTR)(StringStore+Buda2[Arguments+2]);
      if (Buda1[Arguments]==TT_INT)
      {
        i=Buda2[Arguments];
        for(j=0; EnvString[j]!=0 && i; j++)
          if (EnvString[j]=='&' || EnvString[j]=='?')
            i--;
          else if (EnvString[j]==';' && EnvString[j+1]==' ')
          {
            i--;
            j++;
          }  
        if (Buda1[Arguments+1]==TT_STR)
        {
          char *FormName=(LPSTR)(StringStore+Buda2[Arguments+1]);
          for( i=0; FormName[i]!=0; i++, j++)
            if (EnvString[j]!=FormName[i])
              return(0);
          if (EnvString[j++]!='=')
            return(0);
        }
        else
        {
          for( ; EnvString[j]!='=' && EnvString[j]!='&' && EnvString[j]!=0
               && EnvString[j]!='?'&& (EnvString[j]!=';' || EnvString[j+1]!=' '); j++);
          if (EnvString[j++]!='=')
            return(0);
        }
      } 
      else if (Buda1[Arguments+1]==TT_STR)
      {
        char *FormName=(LPSTR)(StringStore+Buda2[Arguments+1]);
        j=0;
        while(1)
        {
          for( i=0; FormName[i]!=0 && EnvString[j]==FormName[i]; i++, j++);
          if (EnvString[j++]=='=' && FormName[i]==0)
            break;
          for( ; EnvString[j]!='&' && EnvString[j]!='?'; j++)
          {
            if (EnvString[j]==';' && EnvString[j+1]==' ')
            {
              j++;
              break;
            }  
            if (EnvString[j]==0)
              return(0);
          }
          j++;
        }
      }
      else
        return(0); // To be continue
decode:
      i=sv_StStore;
      while(EnvString[j]!=0 && EnvString[j]!='&' && EnvString[j]!='?'
                                           && (EnvString[j]!=';' || EnvString[j+1]!=' '))
      {
        if (EnvString[j]!='%' && EnvString[j]!='+')
           StringStore[i++]=EnvString[j++];
        else if (EnvString[j]=='+')
        {
          StringStore[i++]=' ';
          j++;
        }
        else
        {
          next1=EnvString[j+1];
          next2=EnvString[j+2];
          if (next1!=0 && next2!=0)
          {
            if (next1>='A' && next1<='F')
               symbol=16*( (int)next1 - 55);
            else
               symbol=16*( (int)next1 - 48);
            if (next2>='A' && next2<='F')
               symbol+=( (int)next2 - 55);
            else
               symbol+=( (int)next2 - 48);

            StringStore[i++]=(char)symbol;
            j+=3;
          }
          else StringStore[i++]=EnvString[j++];
        }
      }
      if (i==sv_StStore)
        Buda2[Return]=0;
      else
      {
        StringStore[i++]=0;
        Buda2[Return]=sv_StStore;
        if ((sv_StStore=i)>=STRING_STORE && correct_STR_ST() )
          goto FULL;
      }
      Buda1[Return]=TT_STR;
      return(1);
     }
     case 367:            // url_encode
      {
        NOT_FOR_LIGHT
        BYTE *Str = StringStore+Buda2[Arguments];
        int br;
        char tmp[4];

        i = sv_StStore;
        for(br = 0; Str[br] != 0; br++) {
            if ((Str[br] >= 65 && Str[br] <= 90)
                 || (Str[br] >= 97 && Str[br] <= 122) || (Str[br] >= 48 && Str[br] <= 57))
                StringStore[i++] = Str[br];
            else if (Str[br]==32)
                StringStore[i++] = '+';
            else {
                sprintf(tmp, "%%%x", Str[br]);
                if (tmp[1] >= 97 && tmp[2] <= 122)
                    tmp[1] -= 32;
                if (tmp[2] >= 97 && tmp[3] <= 122)
                    tmp[2] -= 32;
                for(j = 0; tmp[j] != 0; StringStore[i++] = tmp[j++]);
            }

            if (i>=STRING_STORE)
            {
              if (correct_STR_ST() )
                goto FULL;
              Str = StringStore+Buda2[Arguments];
            }
        }

        StringStore[i++] = 0;
        Buda2[Return] = sv_StStore;
        sv_StStore = i;
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 370:            // hex_string
      {
        sprintf((LPSTR)(StringStore+sv_StStore), "%x", Buda2[Arguments]);
        Buda1[Return]=TT_STR;
        Buda2[Return] = sv_StStore;
        sv_StStore += strlen((LPSTR)(StringStore+sv_StStore))+1;
        return(1);
      }
     case 371:            // sql_encode
      {
        NOT_FOR_LIGHT
        j=Buda2[Arguments];
        i = sv_StStore;
        for(; StringStore[j] != 0; j++)
        {
          if (StringStore[j]=='\'' || StringStore[j]=='\\')
            StringStore[i++] = '\\';
          StringStore[i++] = StringStore[j];
          if (i>=STRING_STORE && correct_STR_ST())
            goto FULL;
        }
        if (i-sv_StStore==j-Buda2[Arguments])
          Buda2[Return] = Buda2[Arguments]; // OK
        else
        {
          StringStore[i++] = 0;
          Buda2[Return] = sv_StStore;
          sv_StStore = i;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 372:            // lower_case
      {
        int changed=0;

        j=Buda2[Arguments];
        i = sv_StStore;
        for(; StringStore[j] != 0; j++)
        {
          if (StringStore[j] >= 'A' && StringStore[j] <= 'Z')
            StringStore[i++] = StringStore[j]+(changed=32);
          else
            StringStore[i++] = StringStore[j];
          if (i>=STRING_STORE && correct_STR_ST())
            goto FULL;
        }
        if (changed==0)
          Buda2[Return] = Buda2[Arguments]; // OK
        else
        {
          StringStore[i++] = 0;
          Buda2[Return] = sv_StStore;
          sv_StStore = i;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 373:            // upper_case
      {
        int changed=0;

        j=Buda2[Arguments];
        i = sv_StStore;
        for(; StringStore[j] != 0; j++)
        {
          if (StringStore[j] >= 'a' && StringStore[j] <= 'z')
            StringStore[i++] = StringStore[j]-(changed=32);
          else
            StringStore[i++] = StringStore[j];
          if (i>=STRING_STORE && correct_STR_ST())
            goto FULL;
        }
        if (changed==0)
          Buda2[Return] = Buda2[Arguments];
        else
        {
          StringStore[i++] = 0;
          Buda2[Return] = sv_StStore;
          sv_StStore = i;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 374:            // stabilise
      {
        NOT_FOR_LIGHT
        BYTE last=32;

        j=Buda2[Arguments];
        i = sv_StStore;
        for(; StringStore[j] != 0; j++)
        {
          if (StringStore[j]!='\"' && StringStore[j]!='<' && StringStore[j]!='>'
                && (StringStore[j]!=32 || last!=32))
            last=StringStore[i++]=StringStore[j];
          if (i>=STRING_STORE && correct_STR_ST())
            goto FULL;
        }
        if (StringStore[i-1]==32 && i>sv_StStore) // i>sv_StStore for sure
          i--;
        if (i-sv_StStore==j-Buda2[Arguments])
          Buda2[Return] = Buda2[Arguments];
        else
        {
          StringStore[i++] = 0;
          Buda2[Return] = sv_StStore;
          sv_StStore = i;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 375:            // tagless
      {
        NOT_FOR_LIGHT
        j=Buda2[Arguments];
        i = sv_StStore;
        for(; StringStore[j] != 0; j++)
        {
          if (StringStore[j]=='<')
          {
            StringStore[i++]='&';
            StringStore[i++]='l';
            StringStore[i++]='t';
            StringStore[i++]=';';
          }
          else if (StringStore[j]=='>')
          {
            StringStore[i++]='&';
            StringStore[i++]='g';
            StringStore[i++]='t';
            StringStore[i++]=';';
          }
          else if (StringStore[j]=='\n')
          {
            StringStore[i++]='<';
            StringStore[i++]='b';
            StringStore[i++]='r';
            StringStore[i++]='>';
          }
          else if (StringStore[j]=='&')
          {
            StringStore[i++]='&';
            StringStore[i++]='a';
            StringStore[i++]='m';
            StringStore[i++]='p';
            StringStore[i++]=';';
          }
          else
            StringStore[i++] = StringStore[j];
          if (i>=STRING_STORE && correct_STR_ST())
            goto FULL;
        }
        if (i-sv_StStore==j-Buda2[Arguments])
          Buda2[Return] = Buda2[Arguments]; // OK
        else
        {
          StringStore[i++] = 0;
          Buda2[Return] = sv_StStore;
          sv_StStore = i;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 368:  // get_html_multipart_form
      {
        char *FormString=(LPSTR)(StringStore+Buda2[Arguments+2]);
        char *FormName=(LPSTR)(StringStore+Buda2[Arguments+1]);

        if ((sv_StStore+strlen(FormString))>=STRING_STORE)
        {
          if (correct_STR_ST() )
            goto FULL;
          FormString=(LPSTR)(StringStore+Buda2[Arguments+2]);
          FormName=(LPSTR)(StringStore+Buda2[Arguments+1]);
        }

        char numb[200];        // Form ID Number
        char search[600];   // Search FormName

        char *startStr;
        char *endStr;

        i = 0;
        j = 0;
        while(FormString[i] != 10 && FormString[i] != 13 && FormString[i] != 0)
          numb[j++] = FormString[i++];
        numb[j] = 0;

        sprintf(search, "%s\r\nContent-Disposition: form-data; name=\"%s\"", numb, FormName);

        if ((startStr = strstr(FormString, search)) == NULL)
          return(0);

        while(*startStr != 10 || *(startStr+2) != 10) startStr++;
        startStr += 3;

        if ((endStr = strstr(startStr, numb)) == NULL)
          return(0);

        i=sv_StStore;
        while(startStr != endStr && *startStr != 0)
          StringStore[i++]=*(startStr++);

        if (i==sv_StStore)
          Buda2[Return]=0;
        else
        {
          StringStore[i-2]=0;
          Buda2[Return]=sv_StStore;
          sv_StStore=i-1;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 369:  // get_html_file_name
      {
        char *FormString=(LPSTR)(StringStore+Buda2[Arguments+2]);
        char *FormName=(LPSTR)(StringStore+Buda2[Arguments+1]);

        char numb[200];        // Form ID Number
        char search[600];   // Search FormName

        char *startStr;
        char *endStr;

        i = 0;
        j = 0;
        while(FormString[i] != 10 && FormString[i] != 13 && FormString[i] != 0)
          numb[j++] = FormString[i++];
        numb[j] = 0;

        sprintf(search, "%s\r\nContent-Disposition: form-data; name=\"%s\"", numb, FormName);

        if ((startStr = strstr(FormString, search)) == NULL)
          return(0);

        if ((endStr = strstr(startStr, "filename=")) == NULL)
          return(0);

        endStr += 10;
        i=sv_StStore;
        while(*endStr != '"' && *endStr != 0)
          StringStore[i++]=*(endStr++);

        if (i==sv_StStore)
          Buda2[Return]=0;
        else
        {
          StringStore[i++]=0;
          Buda2[Return]=sv_StStore;
          sv_StStore=i;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 263:        // set_content_type
      printf("Content-type:%s\n\n", (LPSTR)(StringStore+Buda2[Arguments]));
      return(1);
     case 264:        // set_cookie
      printf("Set-Cookie:%s; path=%s; expires=%s\n", (LPSTR)(StringStore+Buda2[Arguments]), (LPSTR)(StringStore+Buda2[Arguments+1]), (LPSTR)(StringStore+Buda2[Arguments+2]));
      return(1);
#endif // PROF==2

#if CONSOLE && UNIX && PROF==2
     case 400: // parse_multipart_form (dir, max_len, file_prefix)
      {
        char *DirName=(LPSTR)(StringStore+Buda2[Arguments]);
        int max_len = Buda2[Arguments+1];  
        char *FilePrefix=(LPSTR)(StringStore+Buda2[Arguments+2]);
        // char DirName[1024]="tmp";
        // int max_len = 65535;  
        // char FilePrefix[1024]="101";
        
        FILE *dump = fopen("/home/box2/public_html/dump/form.dat", "w");

        char *cont_len_str = getenv("CONTENT_LENGTH");
        if (cont_len_str == NULL)
          return(0);
        int cont_len = atoi(cont_len_str);
        if (max_len < cont_len || cont_len == 0) 
          return(0);
        
        fprintf(dump, "CONTENT_LENGTH=%d\n", cont_len);

        int query_len = 65535;
        char *query_string = (char *)malloc(query_len * sizeof(char));
        *query_string = '\0';
        ///  free(query_string);

        char boundary[1024];
        char line[65535];
        
        *boundary = '\0';
        *line = '\0';
        
        fgets(boundary, 1024, stdin);
        
        fprintf(dump, "%s", boundary);
        fflush(dump);

        int len = strlen(boundary);
        int read_len = len;
        int line_len = 0;
        boundary[--len] = 0;

        int isFirst = 1;
        char ent[65535]; 
        int fileNumb = 0;

        while(1)
        {
          if (read_len >= cont_len) 
            break;
          char *startStr, *endStr;

          line_len = sp_fgets(line, 65535, stdin);
          read_len += line_len;
          
          fprintf(dump, "%s", line);

        //  fprintf(stdout, "\n\nnew::%s\n", line);
          
          char fieldName[255];
          if ((startStr = strstr(line, "name=\"")) == NULL) 
            return(0);
          if ((endStr = strstr(startStr + 6, "\"")) == NULL) 
            return(0);
          
          j = 0;
          for(i = 6; i < endStr - startStr; i++)
            fieldName[j++] = startStr[i];
          fieldName[j] = 0;

        //  fprintf(stderr, "fieldName=%s", fieldName);

          int isFile = 0;
          int isFileEmpty = 1;
          char fileName[255];
          FILE *fp;
          char filePath[255];
          if ((startStr = strstr(line, "filename=\"")) != NULL)
          {
            if ((endStr = strstr(startStr + 10, "\"")) == NULL) 
              return(0);
            j = 0;
            for(i = 10; i < endStr - startStr; i++)
              fileName[j++] = startStr[i];
            fileName[j] = 0;
            if (j != 0)
              isFileEmpty = 0;

        //    fprintf(stderr, "fileName=%s", fileName);

            isFile = 1;
            sprintf(filePath, "%s/%s%d", DirName, FilePrefix, fileNumb++);

        //    fprintf(stderr, "filePath=%s", filePath);
            
            if (!isFileEmpty)
              if ((fp = fopen(filePath, "w+")) == NULL)
                return(0);
          }
            
          char value[65535];
          char encodedValue[65535];
          *value = 0;
          
          line_len = sp_fgets(line, 65535, stdin);
          read_len += line_len;
          
          fprintf(dump, "%s", line);

          if (isFile && !isFileEmpty && line_len > 5)
          {
            line_len = sp_fgets(line, 65535, stdin);
            read_len += line_len;

            fprintf(dump, "%s", line);
          }
          while(1)
          {
            line_len = sp_fgets(line, 65535, stdin);
            read_len += line_len;
            
            fprintf(dump, "%s", line);
            fflush(dump);

        //    fprintf(stdout, "line-%s-", line);

            if (read_len >= cont_len || line_len == 0 || (startStr = strstr(line, boundary)) != NULL) 
              break;
            
            if (isFile)
            {
              if (!isFileEmpty) 
                sp_fprintf(fp, line, line_len);  
            }
            else
              strcat(value, line);
          }
            
        //  fprintf(stderr, "value=%s", value);
          
          if (isFile)
          {
            if (!isFileEmpty)
              fclose(fp);
            strcpy(value, fileName);

            if (isFirst == 0)
            {
              query_string[query_len++] = '&';
              query_string[query_len] = 0;
            }
            else
              isFirst = 0;

            sprintf(ent, "%s_real=%s", fieldName, filePath);
            strcat(query_string, ent);
            query_len = strlen(query_string);
        //    query_len += strlen(ent);
          }
          else
          {
            int valLen = strlen(value);
            if (valLen < 2)
            valLen = 2;
            value[valLen-2] = 0;
          }
          if (isFirst == 0)
          {
            query_string[query_len++] = '&';
            query_string[query_len] = 0;
          }
          else
            isFirst = 0;
            
          char tmp[4];
          i = 0;
          for(int br = 0; value[br] != 0; br++)
          {
            if ((value[br] >= 65 && value[br] <= 90) || (value[br] >= 97 && value[br] <= 122))
              encodedValue[i++] = value[br];
            else
            {
              sprintf(tmp, "%%%.2x", (value[br] < 0) ? (256 + value[br]) : value[br]);
              if (tmp[1] >= 97 && tmp[1] <= 122)
                tmp[1] -= 32;
              if (tmp[2] >= 97 && tmp[2] <= 122)
                tmp[2] -= 32;
              for(j = 0; tmp[j] != 0; encodedValue[i++] = tmp[j++]);
            }
          }
          encodedValue[i] = 0;

          sprintf(ent, "%s=%s", fieldName, encodedValue);
          strcat(query_string, ent);
          query_len = strlen(query_string);
        //  query_len += strlen(ent) + 1;
            
        }
        fprintf(dump, "READ_LEN=%d", read_len);
        fprintf(dump, "QUERY_STRING=%s", query_string);
        fclose(dump);

      //  fprintf(stderr, "query_string=%s\n", query_string);

        i = sv_StStore;
        for(int br = 0; query_string[br] != 0; br++)
        {
          StringStore[i++] = query_string[br];

          if (i>=STRING_STORE)
            if (correct_STR_ST() )
              goto FULL;
        }
        StringStore[i++] = 0;
        Buda2[Return] = sv_StStore;
        sv_StStore = i;
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 82: //execute.file
      system((LPSTR)(StringStore+Buda2[Arguments]));
      return(1);
     case 403: // execute
      {
        char *proc=(LPSTR)(StringStore+Buda2[Arguments]);
        FILE *pipe=popen(proc, "r");
        if (pipe==NULL)
          return(0);

        i=sv_StStore;
        while(1)
        {
          if (feof(pipe))
            break;
          StringStore[i++] = fgetc(pipe);
        }
        pclose(pipe);
         
        StringStore[i++]=0;
        Buda2[Return]=sv_StStore;
        if ((sv_StStore=i)>=STRING_STORE && correct_STR_ST() )
          goto FULL;
        Buda1[Return]=TT_STR;
        return(1);
      }
#endif // CONSOLE && UNIX && PROF==2
     case 405: // convert_UTF8_to_local
      {
        NOT_FOR_LIGHT
        char *src = (LPSTR)(StringStore+Buda2[Arguments]);

        DWORD type = 0; // 0 - US_ASCII,                        1 - CP_1252 and CP_1251
                      // 2 - CP_1252 and CP_1251 with 0x20AC, 3 - only CP_1252
                      // 4 - only CP_1251                     5 - only CP_1251 with kyrilic

                      // return type:  0  - UTF 8, 1 - CP_1251, 2 - CP_1252 ...
                      //               VAR - US_ASCII,   M1 - UNKNOWN
        DWORD read = 0;
        DWORD code;

        if (Buda1[Arguments+1]!=TT_LINK)
          return(0);

        j = sv_StStore;
        while(*(src + read))
        {
          i = readUTF8((unsigned char*)(src + read), &code);
          if (i == 0)
            goto not_unicode;
          read += i;
          if (code < 0x80)
          {
            StringStore[j++] = (BYTE)code;
            continue;
          }
          switch (type)
          {
           case 0:
           case 1:
           case 2:
            if (code<=0xFF)
            {
              if(code>=0xA0) // code>=0xA0 && code<=0xFF
              {
                StringStore[j++] = (BYTE)code;
                if ((code<0xb2 && ((code>0xa5 && code!=0xa8 && code!=0xaa && code!=0xaf) || code==0xa0 || code==0xa4))
                    || (code>=0xb5 && code<=0xb7) || code==0xbb) // intersection
                {
                  if (type==0)
                    type=1;
                }  
                else
                  type=3;
                continue;
              }
              else
                goto cannot_find;
            }
            else if (code>=0x410 && code<=0x44F)
            {
              StringStore[j++] = (BYTE)(code - 0x350); // -0x410+0xC0
              type=5;
              continue;
            }
            else if ((code<0x2023 && ((code>0x2017 && code!=0x201b && code!=0x201f) || code==0x2013 || code==0x2014))
            || code==0x2026 || code==0x2030 || code==0x2039 || code==0x203a || code==0x20ac || code==0x2122)
            { // intersection
              if (code==0x20ac)
              {
                StringStore[j++] = 0x80;
                type=2;
              }
              else
              {
                for(i = 2; i < 0x20; i++)
                {
                  if (MAP_CP[1][i] == code)
                    break;
                }
                StringStore[j++] = (BYTE)(0x80 + i);
                if (type==0)
                  type=1;
              }
              continue;
            }
            for(i = 3; i < 0x20; i++) // only CP_1252 (the rest)
            {
              if (MAP_CP[1][i] == code)
              {
                StringStore[j++] = (BYTE)(0x80 + i);
                type=3;
                goto new_continue;
              }
            }
            for(i = 0; i < 0x40; i++) // only CP_1251 (the rest)
            {
              if (MAP_CP[0][i] == code)
              {
                if (type == 2)
                  for(t = sv_StStore; t < j; t++)
                    if (StringStore[t]==0x80)
                      StringStore[t]=0x88;
                StringStore[j++] = (BYTE)(0x80 + i);
                type=4;
                goto new_continue;
              }
            }
            goto cannot_find;
           case 3:
            if(code>=0xA0 && code<=0xFF) // only CP_1252
            {
              StringStore[j++] = (BYTE)code;
              continue;
            }
            for(i = 0; i < 0x20; i++) // (the rest)
            {
              if (MAP_CP[1][i] == code)
              {
                StringStore[j++] = (BYTE)(0x80 + i);
                goto new_continue;
              }
            }
            goto cannot_find;
           case 4:
           case 5:
            if(code>=0x410 && code<=0x44F) // only CP_1251
            {
              StringStore[j++] = (BYTE)(code - 0x350); // -0x410+0xC0
              type=5;
              continue;
            }
            for(i = 0; i < 0x40; i++) // (the rest)
            {
              if (MAP_CP[0][i] == code)
              {
                StringStore[j++] = (BYTE)(0x80 + i);
                goto new_continue;
              }
            }
            goto cannot_find;
          }
new_continue:
          ;
        }
        if (type)
          Buda2[Buda2[Arguments+1]]=(type>=4)?1:2;
local_charset:
        Buda1[Return]=TT_STR;
        if (type==0)
          Buda2[Return]=Buda2[Arguments];
        else
        {
          Buda2[Return]=sv_StStore;
          StringStore[j++] = 0;
          sv_StStore = j;
          if (sv_StStore>=STRING_STORE && correct_STR_ST() )
            goto FULL;
          Buda1[Buda2[Arguments+1]]=TT_INT;
          WILL_CLEAN(Buda2[Arguments+1]);
        }
        return(1);
cannot_find:
        if (type<5)
        {
          type=0;
          while (1)
          {
            if (code>0x2dd)
            {
              if (code>=0x385 && code<=0x3ce) // Greek
                type = 3;
              else if (code>=0x5b0 && code<=0x5e4) // Hebrew
                type = 5;
              else if (code>=0x60c && code<=0x6d2) // Arabic
                type = 6;
              else if (code>=0xe01 && code<=0xe5b) // Thai
                type = 9;
            }
            else
            {
              switch (code)
              {
              case 0xc3:  case 0xcc:  case 0xd2:  case 0xe3:  case 0xec:
              case 0xf2:  case 0x11e: case 0x11f: case 0x130: case 0x131:
                type = 4; // Turkish
                break;
              case 0x1a0: case 0x1a1: case 0x1af: case 0x1b0: case 0x300:
              case 0x301: case 0x303: case 0x309: case 0x323: case 0x20ab:
                type = 8; // Vietnamese
                break;
              case 0x100: case 0x101: case 0x112: case 0x113: case 0x116: case 0x117: case 0x122:
              case 0x123: case 0x12a: case 0x12b: case 0x12e: case 0x12f: case 0x136: case 0x137:
              case 0x13b: case 0x13c: case 0x145: case 0x146: case 0x14c: case 0x14d: case 0x156:
              case 0x157: case 0x16a: case 0x16b: case 0x172: case 0x173:
                type = 7; // Baltic
                break;
              case 0xdd:  case 0xfd:  case 0x10e: case 0x10f: case 0x11a: case 0x11b: case 0x139:
              case 0x13a: case 0x13d: case 0x13e: case 0x147: case 0x148: case 0x150: case 0x151:
              case 0x154: case 0x155: case 0x158: case 0x159: case 0x162: case 0x163: case 0x164:
              case 0x165: case 0x16e: case 0x16f: case 0x170: case 0x171: case 0x2d8: case 0x2dd:
                type = 10; // Central European
                break;
              }
            }
            if (type>0)  // try local charset
            {
              if ((StringStore[t=j++] = char_set(code, 0, type))==0)
                goto cannot_find2;
              while(*(src + read))
              {
                i = readUTF8((unsigned char*)(src + read), &code);
                if (i == 0)
                  goto not_unicode;
                read += i;
                if (code < 0x80)
                  StringStore[j++] = (BYTE)code;
                else if ((StringStore[j++] = char_set(code, 0, type))==0)
                  goto cannot_find2;
              }
              for(read=0, k=sv_StStore; k<t; )
              {
                read += readUTF8((unsigned char*)(src + read), &code);
                if (code < 0x80)
                  StringStore[k++] = (BYTE)code;
                else if ((StringStore[k++] = char_set(code, 0, type))==0)
                  goto cannot_find2;
              }
              Buda2[Buda2[Arguments+1]]=type;
              goto local_charset;
            }
            if (src[read]==0)
              break;
            i = readUTF8((unsigned char *)(src + read), &code);
            if (i == 0)
            {
not_unicode:
              type = M1;
              goto not_unicode2;
            }
            read += i; j++;
          }
        }
cannot_find2:
        while(*(src + read))
        {
          i = readUTF8((unsigned char *)(src + read), &code);
          if (i == 0)
            goto not_unicode;
          read += i;
        }
        type = 0; // Unicode
not_unicode2:
        Buda1[Return]=TT_STR;
        Buda2[Return]=Buda2[Arguments];
        Buda1[Buda2[Arguments+1]]=TT_INT;
        Buda2[Buda2[Arguments+1]]=type;
        WILL_CLEAN(Buda2[Arguments+1]);
        return(1);
      }
     case 406: // convert_charset
      {
        NOT_FOR_LIGHT
        BYTE *src = StringStore+Buda2[Arguments];

        DWORD from = Buda2[Arguments+1];
        DWORD to = Buda2[Arguments+2];

        if (from>CHAR_SETS || to>CHAR_SETS)
        {
          MitiText("Error: No such charset.\r\n", &cf_red);
          return(0);
        }
        if (from==to)
        {
          Buda1[Return]=TT_STR;
          Buda2[Return]=Buda2[Arguments];
          return(1);
        }
        i=ChangeCharset(from, to, src, StringStore+sv_StStore, &k, default_char);
        Buda1[Return]=TT_STR;
        if (i)
        {
          Buda2[Return]=sv_StStore;
          if ((sv_StStore+=i+1)>=STRING_STORE && correct_STR_ST() )
            goto FULL;
        }
        else
          Buda2[Return]=0;
        return(1);
      }
     case 407:   // char_set_name
      NOT_FOR_LIGHT
      if (Buda2[Arguments]>CHAR_SETS)
      {
        MitiText("Error: No such charset.\r\n", &cf_red);
        return(0);
      }
      Buda1[Return]=TT_STR;
      Buda2[Return]=sv_StStore;
      if (Buda1[Arguments+1]==55) // s
        strcpy((LPSTR)(StringStore+sv_StStore), Char_Sets_Short[Buda2[Arguments]]);
      else
        strcpy((LPSTR)(StringStore+sv_StStore), Char_Sets[Buda2[Arguments]]);
      if ((sv_StStore+=strlen((LPSTR)(StringStore+sv_StStore))+1)>=STRING_STORE && correct_STR_ST() )
        goto FULL;
      return(1);
     case 120:   // char_set
      NOT_FOR_LIGHT
      if (Buda1[Arguments]==TT_INT)
      {
        if (Buda2[Arguments]>CHAR_SETS)
        {
          MitiText("Error: No such charset.\r\n", &cf_red);
          return(0);
        }
        ch_set=Buda2[Arguments];
      }
      else
      {
        Buda1[Buda2[Arguments]]=TT_INT;
        Buda2[Buda2[Arguments]]=ch_set;
        WILL_CLEAN(Buda2[Arguments]);
      }
      return(1);
     case 360:   // charAt
      if (ch_set)
      {
        if (Buda2[Arguments+1] >= strlen((LPSTR)(StringStore+Buda2[Arguments])))
          return(0);
        Buda1[Return]=TT_STR;
        Buda2[Return] = 2*((BYTE)(((LPSTR)(StringStore+Buda2[Arguments]))[Buda2[Arguments+1]]));
        return(1);
      }
#if PROF==0
      else if (!(status_fl&512))
      {
        MitiText("Error: In the Light edition you cannot use chatAt on Unicode strings. Do this with another char set or with higher edition.\r\n", &cf_red);
        return(0);
      }
#endif
      else
      {
        BYTE *src = StringStore+Buda2[Arguments];
        k=Buda2[Arguments+1]; 
        for (i=j=0; i<k; i++)
        {
          if (src[j]<0x80)
          {
            if (src[j]==0)
              return(0);
            j++;
          }
          else if ((src[j]&0xe0)==0xc0) // 2
            j+=2;
          else if ((src[j]&0xf0)==0xe0) // 3
            j+=3;
          else if ((src[j]&0xf8)==0xf0) // 4
            j+=4;
          else if ((src[j]&0xfc)==0xf8) // 5
            j+=5;
          else if ((src[j]&0xfe)==0xfc) // 6
            j+=6;
          else // error 
          {
er_unicode: MitiText("Error: The argument of charAt is not an Unicode string.\r\n", &cf_red);
            return(0);
          }
        }
        if (src[j]<0x80)
        {
          if (src[j]==0)
            return(0);
          Buda2[Return] = 2*((BYTE)(src[j]));
        }
        else
        {
          if (readUTF8(src + j, &k)==0) // error
            goto er_unicode;
          Buda2[Return]=sv_StStore;
          sv_StStore+=unicodeToUTF8(k, (unsigned char*)(StringStore + sv_StStore));
          StringStore[sv_StStore++] = 0;
          if (sv_StStore>=STRING_STORE && correct_STR_ST() )
            goto FULL;
        }
        Buda1[Return]=TT_STR;
        return(1);
      }
     case 409:   // undef_op
      Delete_op(Buda1[Arguments], Buda2[Arguments], Buda1[Arguments+1], Buda1[Arguments+2], Buda1[Arguments+2]);
      return(1);
     case 410:   // check_op
      if (Pointers[Buda1[Arguments+2]]&OBSEG6)
      {
        i=D_field[(Pointers[Buda1[Arguments+2]]&MASKA3)+7];
        Buda1[Buda2[Arguments]]=Buda1[Buda2[Arguments+1]]=TT_INT;
        Buda2[Buda2[Arguments]]=OpPr[i];
        Buda2[Buda2[Arguments+1]]=OpType[i];
        //Link[sv_subv++]=1; // which is given
        WILL_CLEAN(Buda2[Arguments]);
        WILL_CLEAN(Buda2[Arguments+1]);
        return(1);
      }
      return(0);
     case 411:   // check_op second one
      if (Pointers[Buda1[Arguments+2]]&OBSEG6)
      {
        i=D_field[(Pointers[Buda1[Arguments+2]]&MASKA3)+7];
        if (Oper[i+1]!=Buda1[Arguments+2])
          return(0);
        Buda1[Buda2[Arguments]]=Buda1[Buda2[Arguments+1]]=TT_INT;
        Buda2[Buda2[Arguments]]=OpPr[i+1];
        Buda2[Buda2[Arguments+1]]=OpType[i+1];
        WILL_CLEAN(Buda2[Arguments]);
        WILL_CLEAN(Buda2[Arguments+1]);
        return(1);
      }
      return(0);
#if UNIX
     case 255: // s_mail
      {
        DWORD *Temp=(LPDWORD)ObjectStore[Buda2[Arguments]+4];
	      int args = ObjectStore[Buda2[Arguments]+2];
        if (args<5) // at least 5 arguments
          return(0);
          
        char *ToE=(LPSTR)(StringStore+Temp[0]),
             *FromN=(LPSTR)(StringStore+Temp[1]),
              FromQ[2]="\"",
             *FromE=(LPSTR)(StringStore+Temp[2]),
             *Subj=(LPSTR)(StringStore+Temp[3]),
             *Mail=(LPSTR)(StringStore+Temp[4]),
	           *CType=(args <= 5) ? (LPSTR)"" : (LPSTR)(StringStore+Temp[5]),
             *Header=(args <= 6) ? (LPSTR)"" : (LPSTR)(StringStore+Temp[6]);
        
        char snd_mail[strlen(FromE) + 25];
        sprintf(snd_mail, "/usr/sbin/sendmail -t -f %s", FromE);
        FILE *mail=popen(snd_mail, "w");
        if (mail==NULL)
          return(0);
        for (i=0; FromN[i] && (('a'<=FromN[i] && FromN[i]<='z') || ('A'<=FromN[i] && FromN[i]<='Z') || ('0'<=FromN[i] && FromN[i]<='9') || FromN[i]==' ' || FromN[i]=='-'); i++);
        if (FromN[i]==0 || FromN[i]=='\"')
          FromQ[0]=0;

	      int hasAtt = 0;
	      n = (args >= 9) ? (args-7)/2 : 0;
	      char   *Att[2*n];
	      FILE *fp;
	      for(i=0; i<n; i++)
	      {
          Att[i]   = (LPSTR)(StringStore+Temp[7+2*i]);
          Att[i+n] = (LPSTR)(StringStore+Temp[8+2*i]);

          if (hasAtt == 0 && (fp = fopen(Att[i], "r")) != NULL)
          {
		        fclose(fp);
		        hasAtt = 1;
	        }
	      }
        if (hasAtt == 0)  // s_mail - no att
        {
          fprintf(mail, "From:%s%s%s <%s>\n", FromQ, FromN, FromQ, FromE);
          fprintf(mail, "To:%s\n", ToE);
          fprintf(mail, "Subject:%s\n", Subj);
	        if (Header[0] != 0)
	          fprintf(mail, "%s\n", Header);
	        if (CType[0] == 0)
	          fprintf(mail, "Content-Type: text/plain\n\n");
	        else
	          fprintf(mail, "Content-Type: %s\n\n", CType);
          fprintf(mail, "%s\n", Mail);
          pclose(mail);
        }
        else  // s_mail_att
        {
          char *boundary = "------------SecondBox----A7ABD552C85EA7E7CD";

          fprintf(mail, "MIME-Version: 1.0\n");
          fprintf(mail, "From:%s%s%s <%s>\n", FromQ, FromN, FromQ, FromE);
          fprintf(mail, "To:%s\n", ToE);
          fprintf(mail, "Subject:%s\n", Subj);
	        if (Header[0] != 0)
	          fprintf(mail, "%s\n", Header);
          fprintf(mail, "Content-Type: multipart/mixed;\n");
          fprintf(mail, " boundary=\"%s\"\n\n", boundary);
          fprintf(mail, "This is a multi-part message in MIME format.\n--%s\n", boundary);
	        if (CType[0] == 0)
	          fprintf(mail, "Content-Type: text/plain; charset=us-ascii\n");
	        else
	          //fprintf(mail, "Content-Type: %s; charset=us-ascii\n", CType); // Error! namerena ot Skordev
	          fprintf(mail, "Content-Type: %s\n", CType);
          fprintf(mail, "Content-Transfer-Encoding: 7bit\n\n");
          fprintf(mail, "%s\n", Mail);

          for(int k = 0; k < n; k++)
          {
            FILE *fp = fopen(Att[k], "r");
            if (fp == NULL)
              continue;

            fprintf(mail, "--%s\n", boundary);
            //fprintf(mail, "Content-Type: application/octet-stream;\n name=\"%s\"\nContent-Transfer-Encoding: 7bit\nContent-Disposition: attachment;\n filename=\"%s\"\n\n", Att[k+n], Att[k+n]);
            fprintf(mail, "Content-Type: application/octet-stream;\n name=\"%s\"\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment;\n filename=\"%s\"\n\n", Att[k+n], Att[k+n]);

            unsigned char line[65535];
            unsigned char *enc_line;
            int line_len;
            while(1)
            {
///              line_len = sp_fgets((char *)line, 65535, fp);
              line_len = sp_fgets_fixlen((char *)line, 54, fp);
	            if (line_len > 0)
	            {
		            enc_line = sp_base64_enc(line, line_len);
		            fprintf(mail, "%s\n", enc_line);
		            free(enc_line);
	            }
              if (feof(fp))
		            break;
            }
            fprintf(mail, "\n");
            fclose(fp);
        //    char c;
        //    while(1)
        //    {
        //      c = fgetc(fp);
        //      if (feof(fp))
        //        break;
        //      fprintf(mail, "%c", c);
        //    }
        //    fprintf(mail, "\n");
        //    fclose(fp);
          }
	        fprintf(mail, "%s--\n", boundary);
          pclose(mail);
        }  
        if (ObjectStore[Buda2[Arguments]+6]&HALF) // free the list
        {
          DWORD old;
          if ((old=i=j=the_free_list)!=M1)
            for ( ; ObjectStore[i+3]<ObjectStore[Buda2[Arguments]+3] && (j=ObjectStore[i+6])!=M1; old=i, i=j);
          if (the_free_list==j)
            the_free_list=Buda2[Arguments];
          else
            ObjectStore[old+6]=Buda2[Arguments];
          //ObjectStore[Buda2[Arguments]]=CLASS_FREE_LIST;
          ObjectStore[Buda2[Arguments]+6]=j;
        }
        return(1);
      }
/*
     case 255: // s_mail
      {
      char *To=(LPSTR)(StringStore+Buda2[Arguments]),
           *FromN=(LPSTR)(StringStore+Buda2[Arguments+1]),
           *FromE=(LPSTR)(StringStore+Buda2[Arguments+2]),
           *Subj=(LPSTR)(StringStore+Buda2[Arguments+3]),
           *Mail=(LPSTR)(StringStore+Buda2[Arguments+4]);
        
      char snd_mail[strlen(FromE) + 25];
        sprintf(snd_mail, "/usr/sbin/sendmail -t -f %s", FromE);

        FILE *mail=popen(snd_mail, "w");
        if (mail==NULL)
          return(0);
        fprintf(mail, "From:\"%s\" <%s>\n", FromN, FromE);
        fprintf(mail, "To:%s\n", To);
        fprintf(mail, "Subject:%s\n\n", Subj);
        fprintf(mail, "%s\n", Mail);
        pclose(mail);
        return(1);
      }
*/
      case 402: // s_mail_att (staro, za triene, no dali go njama v Second Box)
      {
        char *To=(LPSTR)(StringStore+Buda2[Arguments]),
        *FromN=(LPSTR)(StringStore+Buda2[Arguments+1]),
        *FromE=(LPSTR)(StringStore+Buda2[Arguments+2]),
        *Subj=(LPSTR)(StringStore+Buda2[Arguments+3]),
        *Mail=(LPSTR)(StringStore+Buda2[Arguments+4]),
          *Att[6];

        Att[0] = (LPSTR)(StringStore+Buda2[Arguments+5]);
        Att[1] = (LPSTR)(StringStore+Buda2[Arguments+6]);
        Att[2] = (LPSTR)(StringStore+Buda2[Arguments+7]);
        Att[3] = (LPSTR)(StringStore+Buda2[Arguments+8]);
        Att[4] = (LPSTR)(StringStore+Buda2[Arguments+9]);
        Att[5] = (LPSTR)(StringStore+Buda2[Arguments+10]);

        char *boundary = "------------CB6D69A7ABD552C85EA7E7CD";

        char snd_mail[strlen(FromE) + 25];
        sprintf(snd_mail, "/usr/sbin/sendmail -t -f %s", FromE);

        FILE *mail=popen(snd_mail, "w");
        if (mail==NULL)
        return(0);

        fprintf(mail, "MIME-Version: 1.0\n");
        fprintf(mail, "From:\"%s\" <%s>\n", FromN, FromE);
        fprintf(mail, "To:%s\n", To);
        fprintf(mail, "Subject:%s\n", Subj);
        fprintf(mail, "Content-Type: multipart/mixed;\n");
        fprintf(mail, " boundary=\"%s\"\n\n", boundary);
        fprintf(mail, "This is a multi-part message in MIME format.\n--%s\n", boundary);
        fprintf(mail, "Content-Type: text/plain; charset=us-ascii\n");
        fprintf(mail, "Content-Transfer-Encoding: 7bit\n\n");
        fprintf(mail, "%s\n", Mail);

        for(int k = 0; k < 3; k++)
        {
          FILE *fp = fopen(Att[k], "r");
          if (fp == NULL)
            continue;

          fprintf(mail, "--%s\n", boundary);
          //fprintf(mail, "Content-Type: application/octet-stream;\n name=\"%s\"\nContent-Transfer-Encoding: 7bit\nContent-Disposition: attachment;\n filename=\"%s\"\n\n", Att[k+3], Att[k+3]);
          fprintf(mail, "Content-Type: application/octet-stream;\n name=\"%s\"\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment;\n filename=\"%s\"\n\n", Att[k+3], Att[k+3]);

          unsigned char line[65535];
          unsigned char *enc_line;
          int line_len;
          while(1)
          {
            line_len = sp_fgets((char *)line, 65535, fp);
            if (feof(fp))
            break;
            enc_line = sp_base64_enc(line, line_len);
            fprintf(mail, "%s", enc_line);
            free(enc_line);
          }
          fprintf(mail, "\n");
          fclose(fp);
      //    char c;
      //    while(1)
      //    {
      //      c = fgetc(fp);
      //      if (feof(fp))
      //        break;
      //      fprintf(mail, "%c", c);
      //    }
      //    fprintf(mail, "\n");
      //    fclose(fp);
        }
        pclose(mail);
        return(1);
      }

#endif // UNIX
#if !CONSOLE 
     case 83: //logon
         {int result;
          result=LogON((LPSTR)(StringStore+Buda2[Arguments]),(LPSTR)(StringStore+Buda2[Arguments+1]));
          if (result==1) return(1);
          else {if (result==MAPI_NOT_INSTALLED)
            MitiText("Windows Messaging System is not installed.\r\nLook in help on logon for more information.\r\n");
          return (0);}
          }
     
     case 84: //logoff
         {int result;
         result=LogOFF();
         if (result==1) return(1);
           else return (0);
          }

     case 85: //send_mail
         {int result;
          result=SendMail((LPSTR)(StringStore+Buda2[Arguments]),(LPSTR)(StringStore+Buda2[Arguments+1]),(LPSTR)(StringStore+Buda2[Arguments+2]));         
          if (result==1) return(1);
           else return (0);
         }
      
     case 86: //read_new_mail
         {int result;
          char From[256];
          char Subj[256];
          char Text[2048];
          
          result=ReadNewMail(From,Subj,Text);

          if (result!=1) return 0;

          Buda1[Buda2[Arguments]]=Buda1[Buda2[Arguments+1]]=Buda1[Buda2[Arguments+2]]=TT_STR;
            
          Buda2[Buda2[Arguments]]=sv_StStore;
          WILL_CLEAN(Buda2[Arguments]);
          strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR) From);
          sv_StStore+=(strlen((LPSTR) From)+1);

          Buda2[Buda2[Arguments+1]]=sv_StStore;
          WILL_CLEAN(Buda2[Arguments+1]);
          strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR) Subj);
          sv_StStore+=(strlen((LPSTR) Subj)+1);

          Buda2[Buda2[Arguments+2]]=sv_StStore;
          WILL_CLEAN(Buda2[Arguments+2]);
          strcpy((LPSTR)(StringStore+sv_StStore), (LPSTR) Text);
          sv_StStore+=(strlen((LPSTR) Text)+1);

          if (sv_StStore>=STRING_STORE && correct_STR_ST() )
            goto FULL;
             return (1); 
         }
#endif // !CONSOLE
     default:
      sprintf(string2, "I don't know this command: %d\r\n", p_line);
      MitiText(string2, &cf_red);        
      return(0);
#if PROF==0
NOT_FOR:
      sprintf(string2, "The command with number %d is not available in the Light edition.\r\n", p_line);
      MitiText(string2, &cf_red);        
      return(0);
#endif
    }  
    return(0);  // if it is rechable
FULL2:
    MessageBoxA(NUL,"Object Store is Full!", "No Space", MB_OK | MB_ICONSTOP);
    return(3);
  }
  
