diff options
author | George Hazan <george.hazan@gmail.com> | 2014-12-04 13:40:41 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-12-04 13:40:41 +0000 |
commit | 2eaa3458b74ffdae9c91b4eb6fe84f8145af3fa1 (patch) | |
tree | ba00efa3a61d406348bd7a02b346bb60ef93fc4c | |
parent | f38b1ee1bfca4a60519101c605b8c6025044c86d (diff) |
- bin2hex() instead of manual loops;
- change of icon packets
git-svn-id: http://svn.miranda-ng.org/main/trunk@11239 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | include/m_chat_int.h | 4 | ||||
-rw-r--r-- | plugins/Scriver/src/msglog.cpp | 36 | ||||
-rw-r--r-- | plugins/TabSRMM/src/chat/log.cpp | 120 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msglog.cpp | 61 | ||||
-rw-r--r-- | src/core/stdmsg/src/msglog.cpp | 64 | ||||
-rw-r--r-- | src/modules/chat/chat.h | 4 | ||||
-rw-r--r-- | src/modules/chat/log.cpp | 108 |
7 files changed, 186 insertions, 211 deletions
diff --git a/include/m_chat_int.h b/include/m_chat_int.h index b270cbf4ae..de06d7b744 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -403,8 +403,8 @@ struct CHAT_MANAGER HANDLE hBuildMenuEvent, hSendEvent;
FONTINFO aFonts[OPTIONS_FONTCOUNT];
SESSION_INFO *wndList;
- int *logIconBmpSize;
- PBYTE *pLogIconBmpBits;
+ size_t *logIconBmpSize;
+ char **pLogIconBmpBits;
// user-defined custom callbacks
void (*OnCreateModule)(MODULEINFO*);
diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index f29db42b95..9e1c79da84 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -29,8 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern int RTL_Detect(WCHAR *pszwText);
static int logPixelSY;
-static PBYTE pLogIconBmpBits[3];
-static int logIconBmpSize[SIZEOF(pLogIconBmpBits)];
+static char* pLogIconBmpBits[3];
+static size_t logIconBmpSize[SIZEOF(pLogIconBmpBits)];
static HIMAGELIST g_hImageList;
#define STREAMSTAGE_HEADER 0
@@ -327,7 +327,7 @@ static int AppendUnicodeToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbB }
// mir_free() the return value
-static char *CreateRTFHeader(SrmmWindowData *dat, struct GlobalMessageData *gdat)
+static char* CreateRTFHeader(SrmmWindowData *dat, GlobalMessageData *gdat)
{
HDC hdc = GetDC(NULL);
logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY);
@@ -538,7 +538,7 @@ static void AppendWithCustomLinks(EventData *evt, int style, char *&buffer, size }
//mir_free() the return value
-static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct GlobalMessageData *gdat, struct LogStreamData *streamData)
+static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, GlobalMessageData *gdat, LogStreamData *streamData)
{
int style, showColon = 0;
int isGroupBreak = TRUE;
@@ -738,7 +738,7 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct Glob static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
- struct LogStreamData *dat = (struct LogStreamData *)dwCookie;
+ LogStreamData *dat = (LogStreamData*)dwCookie;
if (dat->buffer == NULL) {
dat->bufferOffset = 0;
@@ -796,10 +796,10 @@ static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG return 0;
}
-void StreamInTestEvents(HWND hEditWnd, struct GlobalMessageData *gdat)
+void StreamInTestEvents(HWND hEditWnd, GlobalMessageData *gdat)
{
SrmmWindowData dat = { 0 };
- struct LogStreamData streamData = { 0 };
+ LogStreamData streamData = { 0 };
streamData.isFirst = TRUE;
streamData.events = GetTestEvents();
streamData.dlgDat = &dat;
@@ -816,7 +816,7 @@ void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) {
FINDTEXTEXA fi;
EDITSTREAM stream = { 0 };
- struct LogStreamData streamData = { 0 };
+ LogStreamData streamData = { 0 };
SrmmWindowData *dat = (SrmmWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
CHARRANGE oldSel, sel;
@@ -915,6 +915,7 @@ void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) }
#define RTFPICTHEADERMAXSIZE 78
+
void LoadMsgLogIcons(void)
{
HICON hIcon = NULL;
@@ -958,9 +959,10 @@ void LoadMsgLogIcons(void) hBrush = hBkgBrush;
break;
}
- pLogIconBmpBits[i] = (PBYTE)mir_alloc(RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2);
- //I can't seem to get binary mode working. No matter.
- int rtfHeaderSize = sprintf((char*)pLogIconBmpBits[i], "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, (UINT)bih.biWidth, (UINT)bih.biHeight); //!!!!!!!!!!!
+
+ pLogIconBmpBits[i] = (char*)mir_alloc(RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2);
+ size_t rtfHeaderSize = sprintf(pLogIconBmpBits[i], "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, (UINT)bih.biWidth, (UINT)bih.biHeight); //!!!!!!!!!!!
+
HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp);
FillRect(hdcMem, &rc, hBrush);
DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
@@ -968,14 +970,12 @@ void LoadMsgLogIcons(void) GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *)& bih, DIB_RGB_COLORS);
DestroyIcon(hIcon);
- int n;
- for (n = 0; n < sizeof(BITMAPINFOHEADER); n++)
- sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + n * 2, "%02X", ((PBYTE)& bih)[n]); //!!!!!!!!!!!!!!
- for (n = 0; n < widthBytes * bih.biHeight; n += 4)
- sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + (bih.biSize + n) * 2, "%02X%02X%02X%02X", pBmpBits[n], pBmpBits[n + 1], pBmpBits[n + 2], pBmpBits[n + 3]); //!!!!!!!!!!!!!!!!
+ char *szDest = pLogIconBmpBits[i] + rtfHeaderSize;
+ bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
+ bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
+ strcpy(szDest, "}");
- logIconBmpSize[i] = rtfHeaderSize + (bih.biSize + widthBytes * bih.biHeight) * 2 + 1;
- pLogIconBmpBits[i][logIconBmpSize[i] - 1] = '}';
+ logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
}
mir_free(pBmpBits);
DeleteDC(hdcMem);
diff --git a/plugins/TabSRMM/src/chat/log.cpp b/plugins/TabSRMM/src/chat/log.cpp index 233cdedbb7..b179170d7c 100644 --- a/plugins/TabSRMM/src/chat/log.cpp +++ b/plugins/TabSRMM/src/chat/log.cpp @@ -264,7 +264,7 @@ static void LogEventIEView(LOGSTREAMDATA *streamData, TCHAR *ptszNick) event.count = 1;
memset(&ied, 0, sizeof(ied));
- AddEventToBufferIEView(&buffer, &bufferEnd, &bufferAlloced, streamData, ptszNick);
+ AddEventToBufferIEView(buffer, bufferEnd, bufferAlloced, streamData, ptszNick);
ied.ptszNick = ptszNick;
ied.ptszText = buffer;
ied.time = streamData->lin->time;
@@ -474,30 +474,29 @@ static TCHAR * _tcsnrplc(TCHAR *src, size_t n, const TCHAR *ptrn, const TCHAR *r return src;
}
-static void Log_Append(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...)
+static void Log_Append(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...)
{
va_list va;
int charsDone = 0;
va_start(va, fmt);
for (;;) {
- charsDone = mir_vsnprintf(*buffer + *cbBufferEnd, *cbBufferAlloced - *cbBufferEnd, fmt, va);
+ charsDone = mir_vsnprintf(buffer + cbBufferEnd, cbBufferAlloced - cbBufferEnd, fmt, va);
if (charsDone >= 0)
break;
- *cbBufferAlloced += 4096;
- *buffer = (char *) mir_realloc(*buffer, *cbBufferAlloced);
+ cbBufferAlloced += 4096;
+ buffer = (char*)mir_realloc(buffer, cbBufferAlloced);
}
va_end(va);
- *cbBufferEnd += charsDone;
+ cbBufferEnd += charsDone;
}
-static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const TCHAR *fmt, ...)
+static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const TCHAR *fmt, ...)
{
- va_list va;
int textCharsCount = 0;
- char *d;
TCHAR *line = (TCHAR*)_alloca(8001 * sizeof(TCHAR));
+ va_list va;
va_start(va, fmt);
int lineLen = mir_vsntprintf(line, 8000, fmt, va);
if (lineLen < 0)
@@ -506,14 +505,13 @@ static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buff va_end(va);
lineLen = lineLen * 20 + 8;
- if (*cbBufferEnd + lineLen > *cbBufferAlloced) {
- cbBufferAlloced[0] += (lineLen + 1024 - lineLen % 1024);
- if ((d = (char *) mir_realloc(*buffer, *cbBufferAlloced)) == 0)
+ if (cbBufferEnd + lineLen > cbBufferAlloced) {
+ cbBufferAlloced += (lineLen + 1024 - lineLen % 1024);
+ if ((buffer = (char*)mir_realloc(buffer, cbBufferAlloced)) == 0)
return 0;
- *buffer = d;
}
- d = *buffer + *cbBufferEnd;
+ char *d = buffer + cbBufferEnd;
for (; *line; line++, textCharsCount++) {
if (*line == '\r' && line[1] == '\n') {
@@ -599,11 +597,11 @@ static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buff else d += sprintf(d, "\\u%u ?", (WORD) * line); //!!!!!!!!!
}
- *cbBufferEnd = (int)(d - *buffer);
+ cbBufferEnd = (int)(d - buffer);
return textCharsCount;
}
-static void AddEventToBuffer(char **buffer, int *bufferEnd, int *bufferAlloced, LOGSTREAMDATA *streamData)
+static void AddEventToBuffer(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, LOGSTREAMDATA *streamData)
{
TCHAR szTemp[512], szTemp2[512];
TCHAR* pszNick = NULL;
@@ -718,15 +716,13 @@ static void AddEventToBuffer(char **buffer, int *bufferEnd, int *bufferAlloced, char* Log_CreateRtfHeader(MODULEINFO *mi)
{
- int bufferAlloced, bufferEnd, i = 0;
+ int i = 0;
// guesstimate amount of memory for the RTF header
- bufferEnd = 0;
- bufferAlloced = 4096;
+ size_t bufferEnd = 0, bufferAlloced = 4096;
char *buffer = (char *)mir_realloc(mi->pszHeader, bufferAlloced);
buffer[0] = '\0';
-
// get the number of pixels per logical inch
if (pci->logPixelSY == 0) {
HDC hdc = GetDC(NULL);
@@ -738,24 +734,24 @@ char* Log_CreateRtfHeader(MODULEINFO *mi) // ### RTF HEADER
// font table
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl");
for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, pci->aFonts[i].lf.lfCharSet, pci->aFonts[i].lf.lfFaceName);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, pci->aFonts[i].lf.lfCharSet, pci->aFonts[i].lf.lfFaceName);
// colour table
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}{\\colortbl ;");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ;");
for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(pci->aFonts[i].color), GetGValue(pci->aFonts[i].color), GetBValue(pci->aFonts[i].color));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(pci->aFonts[i].color), GetGValue(pci->aFonts[i].color), GetBValue(pci->aFonts[i].color));
for (i = 0; i < mi->nColorCount; i++)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i]));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i]));
for (i = 0; i < STATUSICONCOUNT; i++)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(g_Settings.nickColors[i]), GetGValue(g_Settings.nickColors[i]), GetBValue(g_Settings.nickColors[i]));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(g_Settings.nickColors[i]), GetGValue(g_Settings.nickColors[i]), GetBValue(g_Settings.nickColors[i]));
// new paragraph
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}\\pard\\sl%d", 1000);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "}\\pard\\sl%d", 1000);
// set tabs and indents
int iIndent = 0;
@@ -771,34 +767,33 @@ char* Log_CreateRtfHeader(MODULEINFO *mi) int iText = GetTextPixelSize(szString, hFont, true) + 3;
DeleteObject(hFont);
iIndent += (iText * 1440) / pci->logPixelSX;
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent);
}
else if (g_Settings.dwIconFlags) {
iIndent += ((g_Settings.bScaleIcons ? 14 : 20) * 1440) / pci->logPixelSX;
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent);
}
if (g_Settings.bShowTime) {
int iSize = (g_Settings.LogTextIndent * 1440) / pci->logPixelSX;
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent + iSize);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent + iSize);
if (g_Settings.bLogIndentEnabled)
iIndent += iSize;
}
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent);
return buffer;
}
static char* Log_CreateRTF(LOGSTREAMDATA *streamData)
{
- char *buffer, *header;
- int bufferAlloced, bufferEnd, me = 0;
- LOGINFO * lin = streamData->lin;
+ int me = 0;
+ LOGINFO *lin = streamData->lin;
MODULEINFO *mi = pci->MM_FindModule(streamData->si->pszModule);
// guesstimate amount of memory for the RTF
- bufferEnd = 0;
- bufferAlloced = streamData->bRedraw ? 2048 * (streamData->si->iEventCount + 2) : 2048;
- buffer = (char *) mir_alloc(bufferAlloced);
+ size_t bufferEnd = 0;
+ size_t bufferAlloced = streamData->bRedraw ? 2048 * (streamData->si->iEventCount + 2) : 2048;
+ char *buffer = (char*)mir_alloc(bufferAlloced);
buffer[0] = '\0';
// ### RTF HEADER
@@ -806,19 +801,18 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) if (0 == mi->pszHeader)
mi->pszHeader = Log_CreateRtfHeader(mi);
- header = mi->pszHeader;
+ char *header = mi->pszHeader;
streamData->crCount = mi->nColorCount;
if (header)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, header);
-
+ Log_Append(buffer, bufferEnd, bufferAlloced, header);
// ### RTF BODY (one iteration per event that should be streamed in)
while (lin) {
// filter
if ((streamData->si->iType != GCW_CHATROOM && streamData->si->iType != GCW_PRIVMESS) || !streamData->si->bFilterEnabled || (streamData->si->iLogFilterFlags & lin->iType) != 0) {
if (lin->next != NULL)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\par ");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\par ");
if (streamData->dat->dwFlags & MWF_DIVIDERWANTED || lin->dwFlags & MWF_DIVIDERWANTED) {
static char szStyle_div[128] = "\0";
@@ -827,19 +821,19 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) lin->dwFlags |= MWF_DIVIDERWANTED;
if (lin->prev || !streamData->bRedraw)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\qc\\sl-1\\highlight%d %s ---------------------------------------------------------------------------------------\\par ", 18, szStyle_div);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\qc\\sl-1\\highlight%d %s ---------------------------------------------------------------------------------------\\par ", 18, szStyle_div);
streamData->dat->dwFlags &= ~MWF_DIVIDERWANTED;
}
// create new line, and set font and color
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\ql\\sl0%s ", pci->Log_SetStyle(0));
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\v~-+%d+-~\\v0 ", lin);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\ql\\sl0%s ", pci->Log_SetStyle(0));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\v~-+%d+-~\\v0 ", lin);
// Insert icon
if (g_Settings.bLogSymbols) // use symbols
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s %c", pci->Log_SetStyle(17), EventToSymbol(lin));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s %c", pci->Log_SetStyle(17), EventToSymbol(lin));
else if (g_Settings.dwIconFlags) {
int iIndex = lin->bIsHighlighted ? ICON_HIGHLIGHT : EventToIcon(lin);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\f0\\fs14");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\f0\\fs14");
while (bufferAlloced - bufferEnd < (pci->logIconBmpSize[0] + 20))
bufferAlloced += 4096;
buffer = (char *) mir_realloc(buffer, bufferAlloced);
@@ -856,20 +850,20 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) iii = lin->bIsHighlighted ? 16 : (lin->bIsMe ? 2 : 1);
mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u",
iii + 1, F.lfWeight >= FW_BOLD ? 1 : 0,F.lfItalic,F.lfUnderline, 2 * abs(F.lfHeight) * 74 / pci->logPixelSY);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", szStyle);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
}
else {
iii = lin->bIsHighlighted ? 16 : EventToIndex(lin);
mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u",
iii + 1, F.lfWeight >= FW_BOLD ? 1 : 0, F.lfItalic,F.lfUnderline ,2 * abs(F.lfHeight) * 74 / pci->logPixelSY);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", szStyle);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
}
}
- else Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", pci->Log_SetStyle(0));
+ else Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", pci->Log_SetStyle(0));
// insert a TAB if necessary to put the timestamp in the right position
if (g_Settings.dwIconFlags)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tab ");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
//insert timestamp
if (g_Settings.bShowTime) {
@@ -879,9 +873,9 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) _tcsncpy_s(szOldTimeStamp, pci->MakeTimeStamp(g_Settings.pszTimeStamp, streamData->si->LastTime), _TRUNCATE);
if (!g_Settings.bShowTimeIfChanged || streamData->si->LastTime == 0 || mir_tstrcmp(szTimeStamp, szOldTimeStamp)) {
streamData->si->LastTime = lin->time;
- Log_AppendRTF(streamData, TRUE, &buffer, &bufferEnd, &bufferAlloced, _T("%s"), szTimeStamp);
+ Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, _T("%s"), szTimeStamp);
}
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tab ");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
}
// Insert the nick
@@ -893,10 +887,10 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) if (g_Settings.bLogClassicIndicators || g_Settings.bColorizeNicksInLog)
pszIndicator[0] = GetIndicator(streamData->si, lin->ptszNick, &crNickIndex);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsMe ? 2 : 1));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsMe ? 2 : 1));
if (g_Settings.bLogClassicIndicators)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s", pszIndicator);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s", pszIndicator);
mir_tstrncpy(pszTemp, lin->bIsMe ? g_Settings.pszOutgoingNick : g_Settings.pszIncomingNick, SIZEOF(pszTemp));
p1 = _tcsstr(pszTemp, _T("%n"));
@@ -910,26 +904,26 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) }
if (g_Settings.bColorizeNicksInLog && pszIndicator[0])
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\cf%u ", OPTIONS_FONTCOUNT + streamData->crCount + crNickIndex);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\cf%u ", OPTIONS_FONTCOUNT + streamData->crCount + crNickIndex);
}
- Log_AppendRTF(streamData, TRUE, &buffer, &bufferEnd, &bufferAlloced, pszTemp, lin->ptszNick);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, " ");
+ Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, pszTemp, lin->ptszNick);
+ Log_Append(buffer, bufferEnd, bufferAlloced, " ");
}
// Insert the message
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
streamData->lin = lin;
- AddEventToBuffer(&buffer, &bufferEnd, &bufferAlloced, streamData);
+ AddEventToBuffer(buffer, bufferEnd, bufferAlloced, streamData);
}
lin = lin->prev;
}
// ### RTF END
if (streamData->bRedraw)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\par}");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\par}");
else
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "}");
return buffer;
}
@@ -1088,9 +1082,9 @@ void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, bool bRedr // this uses hidden marks in the rich text to find the events which should be deleted
if (si->bTrimmed) {
TCHAR szPattern[50];
- FINDTEXTEX fi;
-
mir_sntprintf(szPattern, SIZEOF(szPattern), _T("~-+%d+-~"), si->pLogEnd);
+
+ FINDTEXTEX fi;
fi.lpstrText = szPattern;
fi.chrg.cpMin = 0;
fi.chrg.cpMax = -1;
diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index 35541fa20a..ad276f5bdf 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -137,16 +137,13 @@ void TSAPI CacheLogFonts() _tcsncpy(szYesterday, TranslateT("Yesterday"), 20);
szToday[19] = szYesterday[19] = 0;
- /*
- * cache/create the info panel fonts
- */
-
- COLORREF clr;
- LOGFONTA lf;
-
+ // cache/create the info panel fonts
for (int i = 0; i < IPFONTCOUNT; i++) {
if (CInfoPanel::m_ipConfig.hFonts[i])
DeleteObject(CInfoPanel::m_ipConfig.hFonts[i]);
+
+ COLORREF clr;
+ LOGFONTA lf;
LoadLogfont(i + 100, &lf, &clr, FONTMODULE);
lf.lfUnderline = 0;
CInfoPanel::m_ipConfig.hFonts[i] = CreateFontIndirectA(&lf);
@@ -310,9 +307,8 @@ static int AppendUnicodeToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbB return textCharsCount;
}
-/*
- * same as above but does "\r\n"->"\\par " and "\t"->"\\tab " too
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// same as above but does "\r\n"->"\\par " and "\t"->"\\tab " too
static int AppendToBufferWithRTF(int mode, char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...)
{
@@ -422,7 +418,6 @@ static int AppendToBufferWithRTF(int mode, char **buffer, int *cbBufferEnd, int static void Build_RTF_Header(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, TWindowData *dat)
{
int i;
- char szTemp[30];
LOGFONTA *logFonts = dat->pContainer->theme.logFonts;
COLORREF *fontColors = dat->pContainer->theme.fontColors;
TLogTheme *theme = &dat->pContainer->theme;
@@ -462,6 +457,7 @@ static void Build_RTF_Header(char *&buffer, size_t &bufferEnd, size_t &bufferAll // custom template colors...
for (i = 1; i <= 5; i++) {
+ char szTemp[30];
mir_snprintf(szTemp, 10, "cc%d", i);
colour = theme->custom_colors[i - 1];
if (colour == 0)
@@ -560,7 +556,6 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, struct tm event_time;
BOOL isBold = FALSE, isItalic = FALSE, isUnderline = FALSE;
DWORD dwFormattingParams = MAKELONG(PluginConfig.m_FormatWholeWordsOnly, 0);
- char *rtfMessage = NULL;
size_t bufferEnd = 0, bufferAlloced = 1024;
char *buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0';
@@ -588,17 +583,15 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, dat->cache->updateStats(TSessionStats::SET_LAST_RCV, mir_strlen((char *)dbei.pBlob));
TCHAR *formatted = NULL;
- if (rtfMessage == NULL) {
- TCHAR *msg = DbGetEventTextT(&dbei, dat->codePage);
- if (!msg) {
- mir_free(dbei.pBlob);
- mir_free(buffer);
- return NULL;
- }
- TrimMessage(msg);
- formatted = const_cast<TCHAR *>(Utils::FormatRaw(dat, msg, dwFormattingParams, FALSE));
- mir_free(msg);
+ TCHAR *msg = DbGetEventTextT(&dbei, dat->codePage);
+ if (!msg) {
+ mir_free(dbei.pBlob);
+ mir_free(buffer);
+ return NULL;
}
+ TrimMessage(msg);
+ formatted = const_cast<TCHAR *>(Utils::FormatRaw(dat, msg, dwFormattingParams, FALSE));
+ mir_free(msg);
BOOL bIsStatusChangeEvent = IsStatusEvent(dbei.eventType);
@@ -704,9 +697,8 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, TCHAR cc = szTemplate[i + 1];
skipToNext = FALSE;
skipFont = FALSE;
- /*
- * handle modifiers
- */
+
+ // handle modifiers
while (cc == '#' || cc == '$' || cc == '&' || cc == '?' || cc == '\\') {
switch (cc) {
case '#':
@@ -975,11 +967,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, else if (!skipFont)
AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset));
- if (rtfMessage != NULL)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s", rtfMessage);
- else
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, formatted, MAKELONG(isSent, dat->bIsHistory));
-
+ AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, formatted, MAKELONG(isSent, dat->bIsHistory));
AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s", "\\b0\\ul0\\i0 ");
break;
@@ -988,18 +976,17 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMISC + iFontIDOffset : MSGFONTID_YOURMISC + iFontIDOffset));
{
char *szFileName = (char *)dbei.pBlob + sizeof(DWORD);
+ ptrT tszFileName(DbGetEventStringT(&dbei, szFileName));
+
char *szDescr = szFileName + mir_strlen(szFileName) + 1;
- TCHAR *tszFileName = DbGetEventStringT(&dbei, szFileName);
if (*szDescr != 0) {
- TCHAR *tszDescr = DbGetEventStringT(&dbei, szDescr);
+ ptrT tszDescr(DbGetEventStringT(&dbei, szDescr));
+
TCHAR buf[1000];
mir_sntprintf(buf, SIZEOF(buf), _T("%s (%s)"), tszFileName, tszDescr);
AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, buf, 0);
- mir_free(tszDescr);
}
else AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, tszFileName, 0);
-
- mir_free(tszFileName);
}
break;
@@ -1139,7 +1126,7 @@ skip: static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb)
{
- LogStreamData *dat = (LogStreamData *)dwCookie;
+ LogStreamData *dat = (LogStreamData*)dwCookie;
if (dat->buffer == NULL) {
dat->bufferOffset = 0;
@@ -1389,7 +1376,7 @@ void TSAPI StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAp event.hDbEventFirst = hDbEventFirst;
event.count = count;
CallService(MS_HPP_EG_EVENT, 0, (LPARAM)&event);
- //SendMessage(hwndDlg, DM_FORCESCROLL, (WPARAM)&pt, (LPARAM)&si);
+
DM_ScrollToBottom(dat, 0, 0);
if (fAppend)
dat->hDbEventLast = hDbEventFirst;
diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 0be97597b6..647a067ba1 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -23,17 +23,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern IconItem iconList[];
-static int logPixelSY;
#define LOGICON_MSG_IN 0
#define LOGICON_MSG_OUT 1
#define LOGICON_MSG_NOTICE 2
-static PBYTE pLogIconBmpBits[3];
-static int logIconBmpSize[ SIZEOF(pLogIconBmpBits) ];
+
+static char *pLogIconBmpBits[3];
+static size_t logIconBmpSize[ SIZEOF(pLogIconBmpBits) ];
#define STREAMSTAGE_HEADER 0
#define STREAMSTAGE_EVENTS 1
#define STREAMSTAGE_TAIL 2
#define STREAMSTAGE_STOP 3
+
struct LogStreamData
{
int stage;
@@ -46,6 +47,7 @@ struct LogStreamData SrmmWindowData *dlgDat;
};
+static int logPixelSY;
static char szSep2[40], szSep2_RTL[50];
static void AppendToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...)
@@ -190,7 +192,6 @@ static char *CreateRTFHeader(SrmmWindowData *dat) colour = GetSysColor(COLOR_HOTLIGHT);
AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}");
- //AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}\\pard");
return buffer;
}
@@ -355,33 +356,32 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE }
break;
- case EVENTTYPE_FILE: {
- char* filename = (char*)dbei.pBlob + sizeof(DWORD);
- char* descr = filename + strlen(filename) + 1;
- TCHAR* ptszFileName = DbGetEventStringT(&dbei, filename);
-
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE));
- AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received"));
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, ": ");
- AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, ptszFileName);
- mir_free(ptszFileName);
-
- if (*descr != 0) {
- TCHAR* ptszDescr = DbGetEventStringT(&dbei, descr);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, " (");
- AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, ptszDescr);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, ")");
- mir_free(ptszDescr);
+ case EVENTTYPE_FILE:
+ {
+ char* filename = (char*)dbei.pBlob + sizeof(DWORD);
+ char* descr = filename + strlen(filename) + 1;
+
+ ptrT ptszFileName(DbGetEventStringT(&dbei, filename));
+ AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE));
+ AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received"));
+ AppendToBuffer(buffer, bufferEnd, bufferAlloced, ": ");
+ AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, ptszFileName);
+
+ if (*descr != 0) {
+ ptrT ptszDescr(DbGetEventStringT(&dbei, descr));
+ AppendToBuffer(buffer, bufferEnd, bufferAlloced, " (");
+ AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, ptszDescr);
+ AppendToBuffer(buffer, bufferEnd, bufferAlloced, ")");
+ }
}
break;
- }
+
case EVENTTYPE_MESSAGE:
default:
msg = DbGetEventTextT(&dbei, CP_ACP);
AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle((dbei.eventType == EVENTTYPE_MESSAGE) ? ((dbei.flags & DBEF_SENT) ? MSGFONTID_MYMSG : MSGFONTID_YOURMSG) : MSGFONTID_NOTICE));
AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, msg);
mir_free(msg);
-
}
if (dat->bIsAutoRTL)
@@ -529,24 +529,22 @@ void LoadMsgLogIcons(void) for (int i = 0; i < SIZEOF(pLogIconBmpBits); i++) {
HICON hIcon = Skin_GetIconByHandle(iconList[i].hIcolib);
size_t size = RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2;
- pLogIconBmpBits[i] = (PBYTE)mir_alloc(size);
- //I can't seem to get binary mode working. No matter.
- int rtfHeaderSize = mir_snprintf((char*)pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight);
+ pLogIconBmpBits[i] = (char*)mir_alloc(size);
+ size_t rtfHeaderSize = mir_snprintf(pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight);
HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp);
FillRect(hdcMem, &rc, hBkgBrush);
DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
Skin_ReleaseIcon(hIcon);
SelectObject(hdcMem, hoBmp);
- GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *)& bih, DIB_RGB_COLORS);
+ GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
- for (int n = 0; n < sizeof(BITMAPINFOHEADER); n++)
- sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + n * 2, "%02X", ((PBYTE)& bih)[n]); //!!!!!!!!!!!!!
- for (int n = 0; n < widthBytes * bih.biHeight; n += 4)
- sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + (bih.biSize + n) * 2, "%02X%02X%02X%02X", pBmpBits[n], pBmpBits[n + 1], pBmpBits[n + 2], pBmpBits[n + 3]); //!!!!!!!!!!!!!
+ char *szDest = pLogIconBmpBits[i] + rtfHeaderSize;
+ bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
+ bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
+ strcpy(szDest, "}");
- logIconBmpSize[i] = rtfHeaderSize + (bih.biSize + widthBytes * bih.biHeight) * 2 + 1;
- pLogIconBmpBits[i][logIconBmpSize[i] - 1] = '}';
+ logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
}
mir_free(pBmpBits);
DeleteDC(hdcMem);
diff --git a/src/modules/chat/chat.h b/src/modules/chat/chat.h index 1ba8c46f69..09bdb7c3f4 100644 --- a/src/modules/chat/chat.h +++ b/src/modules/chat/chat.h @@ -41,8 +41,8 @@ extern int g_cbSession, g_cbModuleInfo, g_iFontMode, g_iChatLang; extern TCHAR *g_szFontGroup;
extern mir_cs cs;
-extern PBYTE pLogIconBmpBits[14];
-extern int logIconBmpSize[14];
+extern char* pLogIconBmpBits[14];
+extern size_t logIconBmpSize[14];
// log.c
void LoadMsgLogBitmaps(void);
diff --git a/src/modules/chat/log.cpp b/src/modules/chat/log.cpp index aea1dbaa0e..967de076de 100644 --- a/src/modules/chat/log.cpp +++ b/src/modules/chat/log.cpp @@ -25,8 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // The code for streaming the text is to a large extent copied from
// the srmm module and then modified to fit the chat module.
-PBYTE pLogIconBmpBits[14];
-int logIconBmpSize[ SIZEOF(pLogIconBmpBits) ];
+char* pLogIconBmpBits[14];
+size_t logIconBmpSize[ SIZEOF(pLogIconBmpBits) ];
#define RTFCACHELINESIZE 128
static char CHAT_rtfFontsGlobal[OPTIONS_FONTCOUNT][RTFCACHELINESIZE];
@@ -87,29 +87,28 @@ char* Log_SetStyle(int style) return "";
}
-static void Log_Append(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...)
+static void Log_Append(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...)
{
va_list va;
int charsDone = 0;
va_start(va, fmt);
for (;;) {
- charsDone = mir_vsnprintf(*buffer + *cbBufferEnd, *cbBufferAlloced - *cbBufferEnd, fmt, va);
+ charsDone = mir_vsnprintf(buffer + cbBufferEnd, cbBufferAlloced - cbBufferEnd, fmt, va);
if (charsDone >= 0)
break;
- *cbBufferAlloced += 4096;
- *buffer = (char *)mir_realloc(*buffer, *cbBufferAlloced);
+ cbBufferAlloced += 4096;
+ buffer = (char*)mir_realloc(buffer, cbBufferAlloced);
}
va_end(va);
- *cbBufferEnd += charsDone;
+ cbBufferEnd += charsDone;
}
-static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const TCHAR *fmt, ...)
+static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const TCHAR *fmt, ...)
{
va_list va;
int lineLen, textCharsCount = 0;
TCHAR* line = (TCHAR*)alloca(8001 * sizeof(TCHAR));
- char* d;
va_start(va, fmt);
lineLen = mir_vsntprintf(line, 8000, fmt, va);
@@ -118,12 +117,12 @@ static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buff va_end(va);
lineLen = lineLen * 20 + 8;
- if (*cbBufferEnd + lineLen > *cbBufferAlloced) {
- cbBufferAlloced[0] += (lineLen + 1024 - lineLen % 1024);
- *buffer = (char *)mir_realloc(*buffer, *cbBufferAlloced);
+ if (cbBufferEnd + lineLen > cbBufferAlloced) {
+ cbBufferAlloced += (lineLen + 1024 - lineLen % 1024);
+ buffer = (char *)mir_realloc(buffer, cbBufferAlloced);
}
- d = *buffer + *cbBufferEnd;
+ char *d = buffer + cbBufferEnd;
for (; *line; line++, textCharsCount++) {
if (*line == '\r' && line[1] == '\n') {
@@ -217,11 +216,11 @@ static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buff else d += sprintf(d, "\\u%u ?", (WORD)*line); //!!!!!!!!!!!
}
- *cbBufferEnd = (int)(d - *buffer);
+ cbBufferEnd = (int)(d - buffer);
return textCharsCount;
}
-static void AddEventToBuffer(char **buffer, int *bufferEnd, int *bufferAlloced, LOGSTREAMDATA *streamData)
+static void AddEventToBuffer(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, LOGSTREAMDATA *streamData)
{
TCHAR szTemp[512], szTemp2[512];
TCHAR* pszNick = NULL;
@@ -326,15 +325,14 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData) MODULEINFO *mi = ci.MM_FindModule(streamData->si->pszModule);
// guesstimate amount of memory for the RTF
- int bufferEnd = 0;
- int bufferAlloced = streamData->bRedraw ? 1024 * (streamData->si->iEventCount + 2) : 2048;
+ size_t bufferEnd = 0, bufferAlloced = streamData->bRedraw ? 1024 * (streamData->si->iEventCount + 2) : 2048;
char *buffer = (char *)mir_alloc(bufferAlloced);
buffer[0] = '\0';
// ### RTF HEADER
char *header = mi->pszHeader;
if (header)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, header);
+ Log_Append(buffer, bufferEnd, bufferAlloced, header);
// ### RTF BODY (one iteration per event that should be streamed in)
for (LOGINFO *lin = streamData->lin; lin; lin = lin->prev) {
@@ -345,13 +343,13 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData) // create new line, and set font and color
if (lin->next != NULL)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\par ");
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", Log_SetStyle(0));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\par ");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));
// Insert icon
if ((lin->iType & g_Settings->dwIconFlags) || lin->bIsHighlighted && (g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT)) {
int iIndex = (lin->bIsHighlighted && g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT) ? ICON_HIGHLIGHT : EventToIcon(lin);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\f0\\fs14");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\f0\\fs14");
while (bufferAlloced - bufferEnd < logIconBmpSize[0])
bufferAlloced += 4096;
buffer = (char *)mir_realloc(buffer, bufferAlloced);
@@ -367,18 +365,18 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData) if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
int iii = lin->bIsHighlighted ? 16 : (lin->bIsMe ? 2 : 1);
mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / ci.logPixelSY);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", szStyle);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
}
else {
int iii = lin->bIsHighlighted ? 16 : EventToIndex(lin);
mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / ci.logPixelSY);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", szStyle);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
}
}
- else Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", Log_SetStyle(0));
+ else Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));
if (g_Settings->dwIconFlags)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tab ");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
//insert timestamp
if (g_Settings->bShowTime) {
@@ -388,46 +386,45 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData) mir_tstrncpy(szOldTimeStamp, MakeTimeStamp(g_Settings->pszTimeStamp, streamData->si->LastTime), 30);
if (!g_Settings->bShowTimeIfChanged || streamData->si->LastTime == 0 || mir_tstrcmp(szTimeStamp, szOldTimeStamp)) {
streamData->si->LastTime = lin->time;
- Log_AppendRTF(streamData, TRUE, &buffer, &bufferEnd, &bufferAlloced, _T("%s"), szTimeStamp);
+ Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, _T("%s"), szTimeStamp);
}
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tab ");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
}
// Insert the nick
if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
TCHAR pszTemp[300], *p1;
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", Log_SetStyle(lin->bIsMe ? 2 : 1));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsMe ? 2 : 1));
mir_tstrncpy(pszTemp, lin->bIsMe ? g_Settings->pszOutgoingNick : g_Settings->pszIncomingNick, 299);
p1 = _tcsstr(pszTemp, _T("%n"));
if (p1)
p1[1] = 's';
- Log_AppendRTF(streamData, TRUE, &buffer, &bufferEnd, &bufferAlloced, pszTemp, lin->ptszNick);
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, " ");
+ Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, pszTemp, lin->ptszNick);
+ Log_Append(buffer, bufferEnd, bufferAlloced, " ");
}
// Insert the message
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
streamData->lin = lin;
- AddEventToBuffer(&buffer, &bufferEnd, &bufferAlloced, streamData);
+ AddEventToBuffer(buffer, bufferEnd, bufferAlloced, streamData);
}
// ### RTF END
if (streamData->bRedraw)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\par}");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\par}");
else
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "}");
return buffer;
}
char* Log_CreateRtfHeader(MODULEINFO *mi)
{
- int bufferAlloced, bufferEnd, i;
+ int i;
// guesstimate amount of memory for the RTF header
- bufferEnd = 0;
- bufferAlloced = 4096;
+ size_t bufferEnd = 0, bufferAlloced = 4096;
char *buffer = (char *)mir_realloc(mi->pszHeader, bufferAlloced);
buffer[0] = '\0';
@@ -440,37 +437,37 @@ char* Log_CreateRtfHeader(MODULEINFO *mi) // ### RTF HEADER
// font table
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl");
for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, ci.aFonts[i].lf.lfCharSet, ci.aFonts[i].lf.lfFaceName);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, ci.aFonts[i].lf.lfCharSet, ci.aFonts[i].lf.lfFaceName);
// colour table
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}{\\colortbl ;");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ;");
for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(ci.aFonts[i].color), GetGValue(ci.aFonts[i].color), GetBValue(ci.aFonts[i].color));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(ci.aFonts[i].color), GetGValue(ci.aFonts[i].color), GetBValue(ci.aFonts[i].color));
for (i = 0; i < mi->nColorCount; i++)
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i]));
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i]));
// new paragraph
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}\\pard");
+ Log_Append(buffer, bufferEnd, bufferAlloced, "}\\pard");
// set tabs and indents
int iIndent = 0;
if (g_Settings->dwIconFlags) {
iIndent += (14 * 1440) / ci.logPixelSX;
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent);
}
if (g_Settings->bShowTime) {
int iSize = (g_Settings->LogTextIndent * 1440) / ci.logPixelSX;
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent + iSize);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent + iSize);
if (g_Settings->bLogIndentEnabled)
iIndent += iSize;
}
- Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent);
+ Log_Append(buffer, bufferEnd, bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent);
return buffer;
}
@@ -498,24 +495,23 @@ void LoadMsgLogBitmaps(void) HDC hdcMem = CreateCompatibleDC(hdc);
PBYTE pBmpBits = (PBYTE)mir_alloc(widthBytes * bih.biHeight);
for (int i = 0; i < SIZEOF(pLogIconBmpBits); i++) {
- HICON hIcon = ci.hIcons[i];
size_t size = RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2;
- pLogIconBmpBits[i] = (PBYTE)mir_alloc(size);
- int rtfHeaderSize = mir_snprintf((char *)pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight);
+ pLogIconBmpBits[i] = (char*)mir_alloc(size);
+ size_t rtfHeaderSize = mir_snprintf((char *)pLogIconBmpBits[i], size, "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, bih.biWidth, bih.biHeight);
+
+ HICON hIcon = ci.hIcons[i];
HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp);
FillRect(hdcMem, &rc, hBkgBrush);
DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL);
SelectObject(hdcMem, hoBmp);
GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *)& bih, DIB_RGB_COLORS);
- int n;
- for (n = 0; n < sizeof(BITMAPINFOHEADER); n++)
- sprintf((char *)pLogIconBmpBits[i] + rtfHeaderSize + n * 2, "%02X", ((PBYTE)& bih)[n]); //!!!!!!!!!!!!!
- for (n = 0; n < widthBytes * bih.biHeight; n += 4)
- sprintf((char *)pLogIconBmpBits[i] + rtfHeaderSize + (bih.biSize + n) * 2, "%02X%02X%02X%02X", pBmpBits[n], pBmpBits[n + 1], pBmpBits[n + 2], pBmpBits[n + 3]); //!!!!!!!!!!!!!
+ char *szDest = pLogIconBmpBits[i] + rtfHeaderSize;
+ bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
+ bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
+ strcpy(szDest, "}");
- logIconBmpSize[i] = rtfHeaderSize + (bih.biSize + widthBytes * bih.biHeight) * 2 + 1;
- pLogIconBmpBits[i][logIconBmpSize[i] - 1] = '}';
+ logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
}
mir_free(pBmpBits);
DeleteDC(hdcMem);
|