Ejemplo n.º 1
0
//---------------------------------------------------------------------------
void __fastcall TTcpSrvForm::ProcessData(TTcpSrvClient *Client)
{
    int           I;
    TTcpSrvClient *AClient;

    // We could replace all those CompareText with a table lookup 
    if (CompareText(Client->RcvdLine, "exit") == 0)
        // We can't call Client.Close here because we will immediately
        // reenter DataAvailable event handler with same line because
        // a line is removed from buffer AFTER it has been processed.
        // Using CloseDelayed will delay Close until we are out of
        // current event handler.
        Client->CloseDelayed();
    else if (CompareText(Client->RcvdLine, "time") == 0)
        // Send server date and time to client
        Client->SendStr(DateTimeToStr(Now()) + "\r\n");
    else if (CompareText(Client->RcvdLine, "who") == 0) {
        // Send client list to client
        Client->SendStr("There are " + IntToStr(WSocketServer1->ClientCount) +
                        " connected users:\r\n");
        for (I = WSocketServer1->ClientCount - 1; I >= 0; I--) {
            AClient = (TTcpSrvClient *)(WSocketServer1->Client[I]);
            Client->SendStr(AClient->PeerAddr + ":" + AClient->PeerPort + " " +
                           DateTimeToStr(AClient->ConnectTime) + "\r\n");
        }
    }
    else if (CompareText(Client->RcvdLine, "exception") == 0)
        // This will trigger a background exception for client
        PostMessage(Client->Handle, WM_TRIGGER_EXCEPTION, 0, 0);
    else
        Client->SendStr("Unknown command: '" + Client->RcvdLine + "'\r\n");
}
Ejemplo n.º 2
0
wxString FindDiskFileCaseInsensitive(wxString const & Filename)
{
	wxString result = "";
	wxString ShortFilename;
	wxString CurDir;
	wxDir dir;
	CurDir = ExtractFilePath(Filename);
	wxArrayString FileList;
	dir.GetAllFiles(CurDir, &FileList, GetAllFilesMask(), wxDIR_DEFAULT);

	for (size_t i = 0; i < FileList.GetCount(); i++)
	{
		ShortFilename = ExtractFileName(Filename);
		if (CompareText(FileList[i], ShortFilename) == 0)
		{
			if (CompareStr(FileList[i], ShortFilename) == 0)
			{
				// fits exactly
				result = Filename;
				break;
			}
			// fits case insensitive
			result = CurDir + FileList[i];
			// search further
		}
	}
	return result;
}
Ejemplo n.º 3
0
//---------------------------------------------------------------------------
void TChatRoomUsers::AddUser(String UserName, String SessionId)
{
  TChatRoomUser User ;

  if (UserName == EmptyStr || ChatRoomUsersDestroyed)
    return;

  System::TMonitor::Enter(FUsers);
  try
  {
    for (int i = 0; i < FUsers->Count; i++)
    {
      //if you found a user with the specified name, update his session ID and exit
      if (CompareText(((TChatRoomUser *)FUsers->Items[i])->Name, UserName) == 0)
      {
        User.SessionId = SessionId;
        return;
      }
    }

    //if no user with the name was found, add a new one
    TChatRoomUser *User = new TChatRoomUser();
    User->Name = UserName;
    User->SessionId = SessionId;

    FUsers->Add(User);

    NotifyUserChange(UserName, True);
  }
  __finally
  {
    System::TMonitor::Exit(FUsers);
    NotifyUI();
  }
}
Ejemplo n.º 4
0
//---------------------------------------------------------------------------
void TChatRoomUsers::RemoveUser(String UserName)
{
  int i;
  TChatRoomUser *User;

  if (UserName == EmptyStr || ChatRoomUsersDestroyed)
    return;

  System::TMonitor::Enter(FUsers);
  try
  {
    for (i = 0; i < FUsers->Count; i++)
    {
      User = (TChatRoomUser *)FUsers->Items[i];
      //remove user if the name matches and exit
      if (CompareText(User->Name, UserName) == 0)
      {
        FUsers->Remove(User);
        delete User;
        NotifyUserChange(UserName, False);
        return;
      }
    }
  }
  __finally
  {
    System::TMonitor::Exit(FUsers);
    NotifyUI();
  }
}
Ejemplo n.º 5
0
Field_Info __fastcall TSaveObj::AssignFieldVal(TDataSet* ADS,AnsiString FieldName)
{
     Variant V;
     Field_Info tmp;
     //{todo xieren}日志型的未考虑,或其没考虑的请在此修改
     for (int i=0;i<ADS->FieldCount ;i++)
     {  
        if (CompareText(ADS->Fields->Fields[i]->FieldName,FieldName) ==0)
        {
             V = ADS->Fields->Fields[i]->Value;
             if ((! VarIsNull(V)) &&
                (!VarIsEmpty(V)))
             {                  
                  tmp.FieldName = FieldName;
                  tmp.FieldValue = V;
                  if ((ADS->Fields->Fields[i]->DataType == ftFMTBcd) ||
                     (ADS->Fields->Fields[i]->DataType == ftFloat) ||
                     (ADS->Fields->Fields[i]->DataType == ftBCD) )
                       tmp.FieldType = ftFloat;
                  else if (ADS->Fields->Fields[i]->DataType == ftDateTime)
                       tmp.FieldType = ftDateTime;
                  else
                       tmp.FieldType = ftString;  
                  break;
             }
        }

     }
     return tmp;
}
Ejemplo n.º 6
0
/* ------------------------------------------------------------------------------
 function CompareFileExt(const Filename, Ext: string;
 CaseSensitive: boolean): integer;
 ------------------------------------------------------------------------------ */
int CompareFileExt(wxString const & Filename, wxString const & Ext,
  bool CaseSensitive)
{
	wxString FileExt = ExtractFileExt(Filename);
	if (CaseSensitive)
		return CompareStr(FileExt, Ext);
	else
		return CompareText(FileExt, Ext);
}
Ejemplo n.º 7
0
//---------------------------------------------------------------------------
void __fastcall TUserListForm::ListViewCompare(TObject *Sender,
      TListItem *Item1, TListItem *Item2, int Data, int &Compare)
{
    /* Decimal compare */
    if (ColumnToSort == 0 || ColumnToSort==3 || ColumnToSort==4
    || ColumnToSort == 12   /* logons */
    || ColumnToSort == 13   /* First On */
    || ColumnToSort == 14   /* Last On */
    ) {
        int num1, num2;

        if(ColumnToSort==0) {
            num1=Item1->Caption.ToIntDef(0);
            num2=Item2->Caption.ToIntDef(0);
        } else if(ColumnToSort>12) {    /* Date */
            int ix = ColumnToSort - 1;
            num1=dstrtounix(&MainForm->cfg
                ,Item1->SubItems->Strings[ix].c_str());
            num2=dstrtounix(&MainForm->cfg
                ,Item2->SubItems->Strings[ix].c_str());
        } else {
            int ix = ColumnToSort - 1;
            num1=Item1->SubItems->Strings[ix].ToIntDef(0);
            num2=Item2->SubItems->Strings[ix].ToIntDef(0);
        }
        if(SortBackwards)
            Compare=(num2-num1);
        else
            Compare=(num1-num2);
    } else {
        int ix = ColumnToSort - 1;
        if(SortBackwards)
            Compare = CompareText(Item2->SubItems->Strings[ix]
                ,Item1->SubItems->Strings[ix]);
        else
            Compare = CompareText(Item1->SubItems->Strings[ix]
                ,Item2->SubItems->Strings[ix]);
    }
}
Ejemplo n.º 8
0
Variant __fastcall TSaveObj::GetFieldValue(TDataSet* ADS,AnsiString FieldName)
{
   Variant tmp = Null;
   for (int i=0;i<=ADS->FieldCount-1;i++)
   {
     if (CompareText(ADS->Fields->Fields[i]->FieldName,FieldName) == 0)
     {
         tmp = ADS->Fields->Fields[i]->Value;
         break;
     }
   }
   return tmp;
}
Ejemplo n.º 9
0
/* static */ int
XSLT_Sort::Compare (unsigned index1, unsigned index2, const OpString *textkeys, double *numberkeys, XSLT_SortState* sortstate)
{
  int result;

  if (textkeys) // (datatype == DATATYPE_TEXT)
    result = CompareText (textkeys[index1], textkeys[index2], sortstate->caseorder );
  else
    result = CompareNumber (numberkeys[index1], numberkeys[index2]);

  if (result == 0)
    sortstate->has_equal = TRUE;

  if (sortstate->order == ORDER_ASCENDING)
    return result;
  else
    return -result;
}
Ejemplo n.º 10
0
//---------------------------------------------------------------------------
bool TChatRoomUsers::UserExists(String UserName)
{
  int i;
  TChatRoomUser *User ;

  if (UserName == EmptyStr || ChatRoomUsersDestroyed)
    return false;

  System::TMonitor::Enter(FUsers);
  try
  {
    for (i = 0; i < FUsers->Count; i++)
    {
      User = (TChatRoomUser *)FUsers->Items[i];
      if (CompareText(User->Name, UserName) == 0)
        return true;
    }
  }
  __finally
  {
    System::TMonitor::Exit(FUsers);
  }
  return false;
}
Ejemplo n.º 11
0
static int mac_sort_tbl_compare(const void* s1, const void* s2)
{
	return CompareText((Ptr) s1, (Ptr) s2, 1, 1, itl2Handle);
}
Ejemplo n.º 12
0
Boolean AEComparisons::CompareTexts(DescType oper, const AEDesc *desc1, const AEDesc *desc2)
{
	Boolean	result = false;
	
	short	compareResult;
	Handle  lhsHandle = 0, rhsHandle = 0;
	char  	*lhs;
	char  	*rhs;
	long		lhsSize;
	long		rhsSize;
	
	// FIXME:  this can leak lhsHandle if second conversion fails.
	if (DescToTextHandle(desc1, &lhsHandle) != noErr || DescToTextHandle(desc2, &rhsHandle) != noErr)
	    goto fail;
	
	lhsSize = GetHandleSize(lhsHandle);
	HLock(lhsHandle);
	lhs = *(lhsHandle);
	
	rhsSize = GetHandleSize(rhsHandle);
	HLock(rhsHandle);
	rhs = *(rhsHandle);

	compareResult = ::CompareText(lhs, rhs, lhsSize, rhsSize, nil);

	switch (oper) 
	{
		case kAEEquals:
			result = (compareResult == 0);
			break;
		
		case kAELessThan:
			result = (compareResult < 0);
			break;
		
		case kAELessThanEquals:
			result = (compareResult <= 0);
			break;
		
		case kAEGreaterThan:
			result = (compareResult > 0);
			break;
		
		case kAEGreaterThanEquals:
			result = (compareResult >= 0);
			break;
		
		case kAEBeginsWith:
			if (rhsSize > lhsSize)
			{
				result = false;
			}
			else
			{
				// compare only the number of characters in rhs
				// begin comparing at the beginning of lhs
				compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil);
				result = (compareResult == 0);
			}
			break;
			
		case kAEEndsWith:
			if (rhsSize > lhsSize)
			{
				result = false;
			}
			else
			{
				// compare only the number of characters in rhs
				// begin comparing rhsSize characters from the end of lhs
				// start 
				
				lhs += (lhsSize - rhsSize);
				compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil);
				result = (compareResult == 0);
			}
			break;

		case kAEContains:
			// Here I use an inefficient search strategy, but we're dealing with small amounts
			// of text and by using CompareText(), we're doing the same style of comparison
			// as in the other cases above.
			
			result = false;
			while (lhsSize >= rhsSize)
			{
				compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil);
				if (compareResult == 0)
				{
					result = true;
					break;
				}
				lhs++;
				lhsSize--;
			}
			break;

		default:
			ThrowOSErr(errAEBadTestKey);
	}

fail:
    if (lhsHandle) DisposeHandle(lhsHandle);
    if (rhsHandle) DisposeHandle(rhsHandle);
	
	return result;
}
Ejemplo n.º 13
0
boost::optional<DualOperatorExpression::Operator> DualOperatorExpression::ParseOperator(
    std::string::const_iterator& it,
    const std::string::const_iterator end
) {
    if(	CompareText(it, end, "+")
      ) {
        return ADD;
    }
    if(	CompareText(it, end, "-")
      ) {
        return SUB;
    }
    if(	CompareText(it, end, "*")
      ) {
        return MUL;
    }
    if(	CompareText(it, end, "/")
      ) {
        return DIV;
    }
    if(	CompareText(it, end, "%")
      ) {
        return MOD;
    }
    if(	CompareText(it, end, "||")
      ) {
        return OR;
    }
    if(	CompareText(it, end, "&&")
      ) {
        return AND;
    }
    if(	CompareText(it, end, "|")
      ) {
        return BIT_OR;
    }
    if(	CompareText(it, end, "&")
      ) {
        return BIT_AND;
    }
    if(	CompareText(it, end, "^")
      ) {
        return POW;
    }
    if(	CompareText(it, end, "==")
      ) {
        return EQ;
    }
    if(	CompareText(it, end, "!=")
      ) {
        return DIFF;
    }
    if(	CompareText(it, end, ">=")
      ) {
        return SUP_EQ;
    }
    if(	CompareText(it, end, ">")
      ) {
        return SUP;
    }
    if(	CompareText(it, end, "<=")
      ) {
        return INF_EQ;
    }
    if(	CompareText(it, end, "<")
      ) {
        return INF;
    }
    return optional<Operator>();
}
Ejemplo n.º 14
0
bool SameText(const char* str1, const char* str2)
{
    return CompareText(str1, str2) == 0;
}