//Reverse all the words in the sentence
void ReverseSentence (char* data) {
  char* begin = data; //points to the start position of the word
  char* end = data; //points to the end position of the word

  if (data == NULL) return;
  while (*end != '\0') { //while the string does not end
    if (*end == ' ') { //have a word
      ReverseWord(begin,end-1);
      end++; //move to the next word
      begin = end;
    } else {
      end++;
    }
  }
  ReverseWord(begin,end-1); //reverse the last word
}
void ReverseString(char* str, int n)
{
	//Reverse the whole string first
	ReverseWord(str,n);
	
	int i = 0;
	int j = 0;
	for(j = 0; j < n+1; j++)
	{
		if(str[j] == ' ' || str[j] == '\0')
		{
			ReverseWord(str+i, j-i);
			while(str[++j] == ' '); // Skip continous white spaces
			i = j;
		}
	}
}
Exemple #3
0
//--------------------------------------------------------------------------//
ULONG _stdcall ICQReadMsg(PICQ_CLIENT client, wchar_t *UIN, wchar_t *msg, _int32* msglen)
//--------------------------------------------------------------------------//
{
	ULONG ret = 0;
	PICQ_MSG_HEADER MsgHdr;
	RAWPKT Pkt;
	USHORT TVL;
	char * data;
	_int32 x, len;

		
	if (client->status == ICQ_CLIENT_STATUS_CONNECTED)
	{
		x = GetFLAP(client->sock, &Pkt, 0);
		if (x == 1)
		{
			MsgHdr = (PICQ_MSG_HEADER)Pkt.Data;
		
			if (MsgHdr->family == HTONS(4) && MsgHdr->subtype == HTONS(7) && MsgHdr->channel == HTONS(1))
			{
				
				data = Pkt.Data + sizeof(ICQ_MSG_HEADER);
				mbstowcs(UIN, data, MsgHdr->namesize);
				UIN[MsgHdr->namesize] = 0x00;
				
				
				data += MsgHdr->namesize;
				TVL = HTONS(*(USHORT*)(data + 2));
				data += 4;
				if (TVL)
				{
					for (x = 0; x <= TVL; x++)
					{
						if (*(USHORT*)data == HTONS(2))
						{
							TVL = HTONS(*(USHORT*)(data + 2));
							data += 4;
							while (TVL)
							{
								len = HTONS(*(USHORT*)(data + 2));
								if (data[0] == 1 && data[1] == 1) // id = 1  ver = 1
								{
									len -= 4;
									
									if (HTONS(*(USHORT*)(data + 4)) == 0002) // Unicode
									{
										ReverseWord(data+8, len);
										my_memcpy(msg,data+8,len);
										if (msglen) *msglen = len  >> 1;
										msg[*msglen]= 0x00;
										ParseHTML(msg);
									}
									
									else // Ansi
									{
										mbstowcs(msg, data+8, len);
										msg[len] = 0x00;
										if (msglen) *msglen = len;
										
									}
									ret = 1;
									break;
								}
								else
								{