#include "Mra.h"
#include "MraRTFMsg.h"
#define COLORTABLE_COUNT 8
#define RTF_COLORTBLCOLOURS "\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;\\red255\\green0\\blue255;\\red255\\green255\\blue0;\\red0\\green255\\blue255;\\red0\\green0\\blue0;\\red255\\green255\\blue255;"
static const LPSTR lpszColours[COLORTABLE_COUNT]=
{
"red",
"green",
"blue",
"magenta",
"yellow",
"cyan",
"black",
"white"
};
#define CRLF "\r\n"
#define PAR "\\par "
#define BB_COLOR_TAG "[color="
#define SIMBOLS_COUNT 19
static const LPSTR lpszSimbols[SIMBOLS_COUNT]=
{
"\r\n",
"\\",
"{",
"}",
"[b]",
"[/b]",
"[u]",
"[/u]",
"[i]",
"[/i]",
"[/color]",
"[color=red]",
"[color=green]",
"[color=blue]",
"[color=magenta]",
"[color=yellow]",
"[color=cyan]",
"[color=black]",
"[color=white]",
};
static const SIZE_T dwcSimbolsCount[SIMBOLS_COUNT]=
{
2,
1,
1,
1,
3,
4,
3,
4,
3,
4,
8,
11,
13,
12,
15,
14,
12,
13,
13,
};
static const LPSTR lpszRTFTags[SIMBOLS_COUNT]=
{
"\\par",
"\\\\",
"\\{",
"\\}",
"{\\b ",
"}",
"{\\ul ",
"}",
"{\\i ",
"}",
"}",
"{\\cf2 ",
"{\\cf3 ",
"{\\cf4 ",
"{\\cf5 ",
"{\\cf6 ",
"{\\cf7 ",
"{\\cf8 ",
"{\\cf9 ",
};
static const SIZE_T dwcRTFTagsCount[SIMBOLS_COUNT]=
{
4,
2,
2,
2,
4,
1,
5,
1,
4,
1,
1,
6,
6,
6,
6,
6,
6,
6,
6,
};
DWORD MraTextToRTFData(LPSTR lpszMessage,SIZE_T dwMessageSize,LPSTR lpszMessageConverted,SIZE_T dwMessageConvertedBuffSize,SIZE_T *pdwMessageConvertedSize);
BOOL MraIsMessageFlashAnimation(LPWSTR lpwszMessage,SIZE_T dwMessageSize)
{
BOOL bRet=FALSE;
LPWSTR lpwszFounded;
dwMessageSize*=sizeof(WCHAR);
lpwszFounded=(LPWSTR)MemoryFind(0,lpwszMessage,dwMessageSize,L"id=flas",28);
if (lpwszFounded)
{
if (MemoryFind(((lpwszFounded-lpwszMessage)+32),lpwszMessage,dwMessageSize,L"'",18)) bRet=TRUE;
}
return(bRet);
}
DWORD MraTextToRTFData(LPSTR lpszMessage,SIZE_T dwMessageSize,LPSTR lpszMessageConverted,SIZE_T dwMessageConvertedBuffSize,SIZE_T *pdwMessageConvertedSize)
{
DWORD dwRetErrorCode=NO_ERROR;
if (lpszMessage && dwMessageSize && lpszMessageConverted && dwMessageConvertedBuffSize)
{
BYTE tm,bCurByte;
LPSTR lpszMessageConvertedCur,lpszMessageConvertedMax;
SIZE_T i;
lpszMessageConvertedCur=lpszMessageConverted;
lpszMessageConvertedMax=(lpszMessageConverted+dwMessageConvertedBuffSize);
for(i=0;(i3);i++)
{
//lpszMessageConvertedCur+=mir_snprintf(lpszMessageConvertedCur,8,"\\'%x",(*((BYTE*)lpszMessage+i)));
(*((WORD*)lpszMessageConvertedCur))=(*((WORD*)"\\'"));
bCurByte=(*((BYTE*)lpszMessage+i));
tm=(bCurByte>>4)&0xf;
lpszMessageConvertedCur[2]=(tm>9)? ('a'+tm-10):('0'+tm);
tm=bCurByte&0xf;
lpszMessageConvertedCur[3]=(tm>9)? ('a'+tm-10):('0'+tm);
lpszMessageConvertedCur+=4;
(*((BYTE*)lpszMessageConvertedCur))=0;
}
if (pdwMessageConvertedSize) (*pdwMessageConvertedSize)=(lpszMessageConvertedCur-lpszMessageConverted);
}else{
if (pdwMessageConvertedSize) (*pdwMessageConvertedSize)=0;
dwRetErrorCode=ERROR_INVALID_HANDLE;
}
return(dwRetErrorCode);
}
DWORD MraSybolsToRTFTags(DWORD dwFlags,LPSTR lpszMessage,SIZE_T dwMessageSize,LPSTR lpszMessageConverted,SIZE_T dwMessageConvertedBuffSize,SIZE_T *pdwMessageConvertedSize)
{
DWORD dwRetErrorCode=NO_ERROR;
LPSTR lpszFounded[SIMBOLS_COUNT],lpszMessageConvertedCur,lpszMessageCur,lpszMessageCurPrev,lpszMessageConvertedMax;
SIZE_T i,dwFirstFoundedIndex=0,dwFoundedCount=0,dwMemPartToCopy;
#ifdef _DEBUG //check table
for(i=0;i(lpszMessageConvertedCur+(dwMemPartToCopy+dwcRTFTagsCount[dwFirstFoundedIndex])))
{
//memmove(lpszMessageConvertedCur,lpszMessageCurPrev,dwMemPartToCopy);lpszMessageConvertedCur+=dwMemPartToCopy;
MraTextToRTFData(lpszMessageCurPrev,dwMemPartToCopy,lpszMessageConvertedCur,(lpszMessageConvertedMax-lpszMessageConvertedCur),&i);lpszMessageConvertedCur+=i;
memmove(lpszMessageConvertedCur,lpszRTFTags[dwFirstFoundedIndex],dwcRTFTagsCount[dwFirstFoundedIndex]);lpszMessageConvertedCur+=dwcRTFTagsCount[dwFirstFoundedIndex];
lpszMessageCurPrev=(lpszFounded[dwFirstFoundedIndex]+dwcSimbolsCount[dwFirstFoundedIndex]);
for(i=0;i=(lpszMessageRTFCur+sizeof(PAR)+sizeof(CRLF)+2))
{
memmove(lpszMessageRTFCur,PAR,sizeof(PAR));lpszMessageRTFCur+=(sizeof(PAR)-1);
memmove(lpszMessageRTFCur,CRLF,sizeof(CRLF));lpszMessageRTFCur+=(sizeof(CRLF)-1);
memmove(lpszMessageRTFCur,"}",2);lpszMessageRTFCur+=2;
if (pdwMessageRTFSize) (*pdwMessageRTFSize)=(lpszMessageRTFCur-lpszMessageRTF);
DebugPrintCRLFA(lpszMessageRTF);
dwRetErrorCode=NO_ERROR;
}else{
if (pdwMessageRTFSize) (*pdwMessageRTFSize)=dwMessageRTFBuffSize+1024;
dwRetErrorCode=ERROR_BUFFER_OVERFLOW;
DebugBreak();
}
}
MEMFREE(lpszMessage);
}
}else{
if (pdwMessageRTFSize) (*pdwMessageRTFSize)=dwMessageSize;
dwRetErrorCode=ERROR_BUFFER_OVERFLOW;
DebugBreak();
}
}else{
dwRetErrorCode=ERROR_INVALID_HANDLE;
}
return(dwRetErrorCode);
}