From aeae01dc50a5adea8fe003c8195540b1f2b2169f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 2 Dec 2014 20:19:18 +0000 Subject: more transparent implementation of AppendToBuffer git-svn-id: http://svn.miranda-ng.org/main/trunk@11222 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Scriver/src/globals.h | 2 +- plugins/Scriver/src/msglog.cpp | 143 +++++++++++++------------- plugins/Scriver/src/msgwindow.cpp | 15 ++- plugins/Scriver/src/utils.cpp | 10 +- plugins/Scriver/src/utils.h | 2 +- plugins/TabSRMM/src/msglog.cpp | 207 +++++++++++++++++++------------------- src/core/stdmsg/src/msglog.cpp | 102 +++++++++---------- 7 files changed, 235 insertions(+), 246 deletions(-) diff --git a/plugins/Scriver/src/globals.h b/plugins/Scriver/src/globals.h index 58c94545c7..8fa58f6d4f 100644 --- a/plugins/Scriver/src/globals.h +++ b/plugins/Scriver/src/globals.h @@ -87,7 +87,7 @@ struct GlobalMessageData HANDLE hParentWindowList; ParentWindowData *lastParent; ParentWindowData *lastChatParent; - int limitNamesLength; + DWORD limitNamesLength; int activeAlpha; int inactiveAlpha; HMENU hMenuANSIEncoding; diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index 0ca661d1f2..f29db42b95 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -251,19 +251,19 @@ static void freeEvent(EventData *evt) mir_free(evt); } -static int AppendUnicodeOrAnsiiToBufferL(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const WCHAR *line, size_t maxLen, BOOL isAnsii) +static int AppendUnicodeOrAnsiiToBufferL(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const WCHAR *line, size_t maxLen, BOOL isAnsii) { if (maxLen == -1) maxLen = wcslen(line); const WCHAR *maxLine = line + maxLen; size_t lineLen = maxLen*9 + 8; - if (*cbBufferEnd + lineLen > *cbBufferAlloced) { - cbBufferAlloced[0] += int(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); } - char *d = *buffer + *cbBufferEnd; + char *d = buffer + cbBufferEnd; if (isAnsii) { strcpy(d, "{"); d++; @@ -312,16 +312,16 @@ static int AppendUnicodeOrAnsiiToBufferL(char **buffer, int *cbBufferEnd, int *c strcpy(d, "}"); d++; - *cbBufferEnd = (int)(d - *buffer); + cbBufferEnd = (int)(d - buffer); return textCharsCount; } -static int AppendAnsiToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *line) +static int AppendAnsiToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *line) { return AppendUnicodeOrAnsiiToBufferL(buffer, cbBufferEnd, cbBufferAlloced, _A2T(line), -1, TRUE); } -static int AppendUnicodeToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const WCHAR *line) +static int AppendUnicodeToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const WCHAR *line) { return AppendUnicodeOrAnsiiToBufferL(buffer, cbBufferEnd, cbBufferAlloced, line, -1, FALSE); } @@ -333,47 +333,46 @@ static char *CreateRTFHeader(SrmmWindowData *dat, struct GlobalMessageData *gdat logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); - int bufferEnd = 0; - int bufferAlloced = 1024; + size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0'; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced,"{\\rtf1\\ansi\\deff0{\\fonttbl"); + + AppendToBuffer(buffer, bufferEnd, bufferAlloced,"{\\rtf1\\ansi\\deff0{\\fonttbl"); for (int i = 0; i < fontOptionsListSize; i++) { LOGFONT lf; LoadMsgDlgFont(i, &lf, NULL); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "{\\f%u\\fnil\\fcharset%u %S;}", i, lf.lfCharSet, lf.lfFaceName); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u %S;}", i, lf.lfCharSet, lf.lfFaceName); } - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "}{\\colortbl "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}{\\colortbl "); COLORREF colour; for (int i = 0; i < fontOptionsListSize; i++) { LoadMsgDlgFont(i, NULL, &colour); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); } if (GetSysColorBrush(COLOR_HOTLIGHT) == NULL) colour = RGB(0, 0, 255); else colour = GetSysColor(COLOR_HOTLIGHT); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_BKGCOLOUR, SRMSGDEFSET_BKGCOLOUR); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_INCOMINGBKGCOLOUR, SRMSGDEFSET_INCOMINGBKGCOLOUR); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_OUTGOINGBKGCOLOUR, SRMSGDEFSET_OUTGOINGBKGCOLOUR); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_LINECOLOUR, SRMSGDEFSET_LINECOLOUR); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "}"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}"); return buffer; } // mir_free() the return value static char* CreateRTFTail() { - int bufferAlloced = 1024, bufferEnd = 0; - char *buffer = (char*)mir_alloc(bufferAlloced); - buffer[0] = '\0'; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "}"); + size_t bufferAlloced = 1024, bufferEnd = 0; + char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0'; + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}"); return buffer; } @@ -489,7 +488,7 @@ static int DetectURL(wchar_t *text, BOOL firstChar) { return 0; } -static void AppendWithCustomLinks(EventData *evt, int style, char **buffer, int *bufferEnd, int *bufferAlloced) +static void AppendWithCustomLinks(EventData *evt, int style, char *&buffer, size_t &bufferEnd, size_t &bufferAlloced) { if (evt->pszText == NULL) return; @@ -544,8 +543,8 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct Glob int style, showColon = 0; int isGroupBreak = TRUE; int highlight = 0; - int bufferEnd = 0; - int bufferAlloced = 1024; + + size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0'; if ((gdat->flags & SMF_GROUPMESSAGES) && evt->dwFlags == LOWORD(dat->lastEventType) && @@ -557,47 +556,47 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct Glob if (!streamData->isFirst && !dat->isMixed) { if (isGroupBreak || gdat->flags & SMF_MARKFOLLOWUPS) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\line"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line"); } if (evt->dwFlags & IEEDF_RTL) dat->isMixed = 1; if (!streamData->isFirst && isGroupBreak && (gdat->flags & SMF_DRAWLINES)) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\sl-1\\slmult0\\highlight%d\\cf%d\\fs1 \\par\\sl0", fontOptionsListSize + 4, fontOptionsListSize + 4); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1\\slmult0\\highlight%d\\cf%d\\fs1 \\par\\sl0", fontOptionsListSize + 4, fontOptionsListSize + 4); if (streamData->isFirst) { if (evt->dwFlags & IEEDF_RTL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlpar"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrpar"); } else { if (evt->dwFlags & IEEDF_RTL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlpar"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrpar"); } if (evt->eventType == EVENTTYPE_MESSAGE) highlight = fontOptionsListSize + 2 + ((evt->dwFlags & IEEDF_SENT) ? 1 : 0); else highlight = fontOptionsListSize + 1; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\highlight%d\\cf%d", highlight, highlight); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\highlight%d\\cf%d", highlight, highlight); if (!streamData->isFirst && dat->isMixed) { if (isGroupBreak) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\sl-1 \\par\\sl0"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1 \\par\\sl0"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\sl-1 \\line\\sl0"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1 \\line\\sl0"); } streamData->isFirst = FALSE; if (dat->isMixed) { if (evt->dwFlags & IEEDF_RTL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrch\\rtlch"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrch\\rtlch"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlch\\ltrch"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlch\\ltrch"); } if ((gdat->flags & SMF_SHOWICONS) && isGroupBreak) { int i = LOGICON_MSG_NOTICE; @@ -615,13 +614,13 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct Glob break; } - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\fs1 "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\fs1 "); while (bufferAlloced - bufferEnd < logIconBmpSize[i]) bufferAlloced += 1024; buffer = (char*)mir_realloc(buffer, bufferAlloced); CopyMemory(buffer + bufferEnd, pLogIconBmpBits[i], logIconBmpSize[i]); bufferEnd += logIconBmpSize[i]; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " "); } if (gdat->flags & SMF_SHOWTIME && (evt->eventType != EVENTTYPE_MESSAGE || @@ -640,47 +639,47 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct Glob else timestampString = TimestampToString(gdat->flags, evt->time, 0); if (timestampString != NULL) { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, timestampString); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, timestampString); } if (evt->eventType != EVENTTYPE_MESSAGE) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); showColon = 1; } if ((!(gdat->flags & SMF_HIDENAMES) && evt->eventType == EVENTTYPE_MESSAGE && isGroupBreak) || evt->eventType == EVENTTYPE_JABBER_CHATSTATES || evt->eventType == EVENTTYPE_JABBER_PRESENCE) { if (evt->eventType == EVENTTYPE_MESSAGE) { if (showColon) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME)); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME)); } - else AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", SetToStyle(MSGFONTID_NOTICE)); + else AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(MSGFONTID_NOTICE)); if (evt->dwFlags & IEEDF_UNICODE_NICK) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, evt->pszNickW); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszNickW); else - AppendAnsiToBuffer(&buffer, &bufferEnd, &bufferAlloced, evt->pszNick); + AppendAnsiToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszNick); showColon = 1; if (evt->eventType == EVENTTYPE_MESSAGE && gdat->flags & SMF_GROUPMESSAGES) { if (gdat->flags & SMF_MARKFOLLOWUPS) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\line"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line"); showColon = 0; } } if ((gdat->flags & SMF_AFTERMASK) == SMF_AFTERMASK && evt->eventType == EVENTTYPE_MESSAGE && isGroupBreak) { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TimestampToString(gdat->flags, evt->time, 2)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TimestampToString(gdat->flags, evt->time, 2)); showColon = 1; } if (showColon && evt->eventType == EVENTTYPE_MESSAGE) { if (evt->dwFlags & IEEDF_RTL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\~%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\~%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); } switch (evt->eventType) { case EVENTTYPE_JABBER_CHATSTATES: @@ -688,49 +687,49 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct Glob case EVENTTYPE_URL: case EVENTTYPE_FILE: style = MSGFONTID_NOTICE; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", SetToStyle(style)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(style)); if (evt->eventType == EVENTTYPE_FILE) { if (evt->dwFlags & IEEDF_SENT) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateT("File sent")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("File sent")); else - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateT("File received")); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, _T(":")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("File received")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, _T(":")); } else if (evt->eventType == EVENTTYPE_URL) { if (evt->dwFlags & IEEDF_SENT) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateT("URL sent")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("URL sent")); else - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateT("URL received")); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, _T(":")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("URL received")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, _T(":")); } - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, _T(" ")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, _T(" ")); if (evt->pszTextW != NULL) { if (evt->dwFlags & IEEDF_UNICODE_TEXT) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, evt->pszTextW); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszTextW); else - AppendAnsiToBuffer(&buffer, &bufferEnd, &bufferAlloced, evt->pszText); + AppendAnsiToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszText); } if (evt->pszText2W != NULL) { - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, _T(" (")); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, _T(" (")); if (evt->dwFlags & IEEDF_UNICODE_TEXT2) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, evt->pszText2W); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszText2W); else - AppendAnsiToBuffer(&buffer, &bufferEnd, &bufferAlloced, evt->pszText2); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, _T(")")); + AppendAnsiToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszText2); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, _T(")")); } break; default: if (gdat->flags & SMF_MSGONNEWLINE && showColon) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\line"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line"); style = evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYMSG : MSGFONTID_YOURMSG; - AppendWithCustomLinks(evt, style, &buffer, &bufferEnd, &bufferAlloced); + AppendWithCustomLinks(evt, style, buffer, bufferEnd, bufferAlloced); break; } if (dat->isMixed) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par"); dat->lastEventTime = evt->time; dat->lastEventType = MAKELONG(evt->dwFlags, evt->eventType); diff --git a/plugins/Scriver/src/msgwindow.cpp b/plugins/Scriver/src/msgwindow.cpp index 1504e4a8e5..bec26597d2 100644 --- a/plugins/Scriver/src/msgwindow.cpp +++ b/plugins/Scriver/src/msgwindow.cpp @@ -39,14 +39,11 @@ static const TCHAR *titleTokenNames[] = {_T("%name%"), _T("%status%"), _T("%stat TCHAR* GetWindowTitle(MCONTACT hContact, const char *szProto) { - int isTemplate; - int i, j; TCHAR* tokens[4] = { 0 }; size_t tokenLen[4] = { 0 }; TCHAR *p, *tmplt, *title; - char *accModule; TCHAR *pszNewTitleEnd = mir_tstrdup(TranslateT("Message Session")); - isTemplate = 0; + int isTemplate = 0; if (hContact && szProto) { tokens[0] = GetNickname(hContact, szProto); tokenLen[0] = mir_tstrlen(tokens[0]); @@ -55,7 +52,8 @@ TCHAR* GetWindowTitle(MCONTACT hContact, const char *szProto) tokens[2] = db_get_tsa(hContact, "CList", "StatusMsg"); if (tokens[2] != NULL) { tokenLen[2] = mir_tstrlen(tokens[2]); - for (i = j = 0; i < tokenLen[2]; i++) { + size_t j = 0; + for (size_t i = 0; i < tokenLen[2]; i++) { if (tokens[2][i] == '\r') continue; if (tokens[2][i] == '\n') @@ -67,7 +65,7 @@ TCHAR* GetWindowTitle(MCONTACT hContact, const char *szProto) tokenLen[2] = j; } - accModule = (char*)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, hContact, 0); + char *accModule = (char*)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, hContact, 0); if (accModule != NULL) { PROTOACCOUNT* proto = (PROTOACCOUNT*)CallService(MS_PROTO_GETACCOUNT, 0, (LPARAM)accModule); if (proto != NULL) { @@ -87,7 +85,7 @@ TCHAR* GetWindowTitle(MCONTACT hContact, const char *szProto) } else tmplt = _T(""); - size_t len; + size_t i, len; for (len = 0, p = tmplt; *p; p++, len++) { if (*p == '%') { for (i = 0; i < SIZEOF(titleTokenNames); i++) { @@ -117,7 +115,8 @@ TCHAR* GetWindowTitle(MCONTACT hContact, const char *szProto) break; } } - if (i < SIZEOF(titleTokenNames)) continue; + if (i < SIZEOF(titleTokenNames)) + continue; } title[len++] = *p; } diff --git a/plugins/Scriver/src/utils.cpp b/plugins/Scriver/src/utils.cpp index c3b663bd3f..1f6b99e682 100644 --- a/plugins/Scriver/src/utils.cpp +++ b/plugins/Scriver/src/utils.cpp @@ -269,21 +269,21 @@ TCHAR *GetRichEditSelection(HWND hwnd) return NULL; } -void AppendToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...) +void AppendToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...) { va_list va; int charsDone; 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 += 1024; - *buffer = (char*)mir_realloc(*buffer, *cbBufferAlloced); + cbBufferAlloced += 1024; + buffer = (char*)mir_realloc(buffer, cbBufferAlloced); } va_end(va); - *cbBufferEnd += charsDone; + cbBufferEnd += charsDone; } diff --git a/plugins/Scriver/src/utils.h b/plugins/Scriver/src/utils.h index 5f9f4afee8..bcb81d4a49 100644 --- a/plugins/Scriver/src/utils.h +++ b/plugins/Scriver/src/utils.h @@ -48,7 +48,7 @@ int SetRichTextEncoded(HWND hwnd, const char *text, int codepage); void SearchWord(TCHAR * word, int engine); HDWP ResizeToolbar(HWND hwnd, HDWP hdwp, int width, int vPos, int height, int cControls, const ToolbarButton * buttons, int controlVisibility); void ShowToolbarControls(HWND hwndDlg, int cControls, const ToolbarButton * buttons, int controlVisibility, int state); -void AppendToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...); +void AppendToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...); int MeasureMenuItem(WPARAM wParam, LPARAM lParam); int DrawMenuItem(WPARAM wParam, LPARAM lParam); void SetSearchEngineIcons(HMENU hMenu, HIMAGELIST hImageList); diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index e0aa1f7e61..35541fa20a 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -202,32 +202,32 @@ static int TSAPI GetColorIndex(char *rtffont) return 0; } -static void AppendToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...) +static void AppendToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...) { va_list va; int charsDone; 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 += 1024; - *buffer = (char *)mir_realloc(*buffer, *cbBufferAlloced); + cbBufferAlloced += 1024; + buffer = (char*)mir_realloc(buffer, cbBufferAlloced); } va_end(va); - *cbBufferEnd += charsDone; + cbBufferEnd += charsDone; } -static int AppendUnicodeToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const TCHAR * line, int mode) +static int AppendUnicodeToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const TCHAR *line, int mode) { - int lineLen = (int)(wcslen(line)) * 9 + 8; - if (*cbBufferEnd + lineLen > *cbBufferAlloced) { - cbBufferAlloced[0] += (lineLen + 1024UL - lineLen % 1024UL); - *buffer = (char*)mir_realloc(*buffer, *cbBufferAlloced); + int lineLen = (int)(wcslen(line)) * 9 + 8; + if (cbBufferEnd + lineLen > cbBufferAlloced) { + cbBufferAlloced += (lineLen + 1024UL - lineLen % 1024UL); + buffer = (char*)mir_realloc(buffer, cbBufferAlloced); } - char *d = *buffer + *cbBufferEnd; + char *d = buffer + cbBufferEnd; strcpy(d, "{\\uc1 "); d += 6; @@ -306,7 +306,7 @@ static int AppendUnicodeToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferA strcpy(d, "}"); d++; - *cbBufferEnd = (int)(d - *buffer); + cbBufferEnd = (int)(d - buffer); return textCharsCount; } @@ -419,7 +419,7 @@ static int AppendToBufferWithRTF(int mode, char **buffer, int *cbBufferEnd, int return (int)(_mbslen((unsigned char *)*buffer + *cbBufferEnd)); } -static void Build_RTF_Header(char **buffer, int *bufferEnd, int *bufferAlloced, TWindowData *dat) +static void Build_RTF_Header(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, TWindowData *dat) { int i; char szTemp[30]; @@ -486,16 +486,15 @@ static void Build_RTF_Header(char **buffer, int *bufferEnd, int *bufferAlloced, // mir_free() the return value static char* CreateRTFHeader(TWindowData *dat) { - int bufferEnd = 0; - int bufferAlloced = 1024; + size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0'; - Build_RTF_Header(&buffer, &bufferEnd, &bufferAlloced, dat); + Build_RTF_Header(buffer, bufferEnd, bufferAlloced, dat); return buffer; } -static void AppendTimeStamp(TCHAR *szFinalTimestamp, int isSent, char **buffer, int *bufferEnd, int *bufferAlloced, int skipFont, +static void AppendTimeStamp(TCHAR *szFinalTimestamp, int isSent, char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, int skipFont, TWindowData *dat, int iFontIDOffset) { if (skipFont) @@ -533,14 +532,10 @@ static TCHAR* Template_MakeRelativeDate(TWindowData *dat, HANDLE hTimeZone, time // mir_free() the return value static char *CreateRTFTail(TWindowData *dat) { - char *buffer; - int bufferAlloced, bufferEnd; - - bufferEnd = 0; - bufferAlloced = 1024; - buffer = (char *)mir_alloc(bufferAlloced); + size_t bufferEnd = 0, bufferAlloced = 1024; + char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0'; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "}"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}"); return buffer; } @@ -567,7 +562,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, DWORD dwFormattingParams = MAKELONG(PluginConfig.m_FormatWholeWordsOnly, 0); char *rtfMessage = NULL; - int bufferEnd = 0, bufferAlloced = 1024; + size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; DBEVENTINFO dbei = { 0 }; @@ -608,7 +603,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, BOOL bIsStatusChangeEvent = IsStatusEvent(dbei.eventType); if (dat->isAutoRTL & 2) { // means: last \\par was deleted to avoid new line at end of log - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par"); dat->isAutoRTL &= ~2; } @@ -636,7 +631,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, if (szStyle_div[0] == 0) mir_snprintf(szStyle_div, 128, "\\f%u\\cf%u\\ul0\\b%d\\i%d\\fs%u", H_MSGFONTID_DIVIDERS, H_MSGFONTID_DIVIDERS, 0, 0, 5); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", H_MSGFONTID_DIVIDERS, H_MSGFONTID_DIVIDERS); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", H_MSGFONTID_DIVIDERS, H_MSGFONTID_DIVIDERS); dat->dwFlags &= ~MWF_DIVIDERWANTED; } if (dwEffectiveFlags & MWF_LOG_GROUPMODE && ((dbei.flags & (DBEF_SENT | DBEF_READ | DBEF_RTL)) == LOWORD(dat->iLastEventType)) && dbei.eventType == EVENTTYPE_MESSAGE && HIWORD(dat->iLastEventType) == EVENTTYPE_MESSAGE && (dbei.timestamp - dat->lastEventTime) < 86400) { @@ -645,26 +640,26 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, g_groupBreak = TRUE; } if (!streamData->isEmpty && g_groupBreak && (dwEffectiveFlags & MWF_LOG_GRID)) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", MSGDLGFONTCOUNT + 4, MSGDLGFONTCOUNT + 4); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", MSGDLGFONTCOUNT + 4, MSGDLGFONTCOUNT + 4); if (dbei.flags & DBEF_RTL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlpar"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrpar"); /* OnO: highlight start */ if (bIsStatusChangeEvent) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\highlight%d\\cf%d", MSGDLGFONTCOUNT + 7, MSGDLGFONTCOUNT + 7); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\highlight%d\\cf%d", MSGDLGFONTCOUNT + 7, MSGDLGFONTCOUNT + 7); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\highlight%d\\cf%d", MSGDLGFONTCOUNT + (dat->bIsHistory ? 5 : 1) + ((isSent) ? 1 : 0), MSGDLGFONTCOUNT + (dat->bIsHistory ? 5 : 1) + ((isSent) ? 1 : 0)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\highlight%d\\cf%d", MSGDLGFONTCOUNT + (dat->bIsHistory ? 5 : 1) + ((isSent) ? 1 : 0), MSGDLGFONTCOUNT + (dat->bIsHistory ? 5 : 1) + ((isSent) ? 1 : 0)); streamData->isEmpty = FALSE; if (dat->isAutoRTL & 1) { if (dbei.flags & DBEF_RTL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrch\\rtlch"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrch\\rtlch"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlch\\ltrch"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlch\\ltrch"); } // templated code starts here @@ -701,7 +696,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, dat->hHistoryEvents[dat->curHistory++] = hDbEvent; } - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ul0\\b0\\i0 "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ul0\\b0\\i0 "); for (size_t i = 0; i < iTemplateLen;) { TCHAR ci = szTemplate[i]; @@ -763,7 +758,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, TCHAR color, code; switch (cc) { case 'V': - //AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\fs0\\\expnd-40 ~-%d-~", hDbEvent); + //AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\fs0\\\expnd-40 ~-%d-~", hDbEvent); break; case 'I': if (dwEffectiveFlags & MWF_LOG_SHOWICONS) { @@ -785,21 +780,21 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, if (bIsStatusChangeEvent) icon = LOGICON_STATUS; } - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s\\fs1 #~#%01d%c%s ", GetRTFFont(MSGFONTID_SYMBOLS_IN), icon, isSent ? '>' : '<', GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s\\fs1 #~#%01d%c%s ", GetRTFFont(MSGFONTID_SYMBOLS_IN), icon, isSent ? '>' : '<', GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); } else skipToNext = TRUE; break; case 'D': // long date if (showTime && showDate) { TCHAR *szFinalTimestamp = Template_MakeRelativeDate(dat, hTimeZone, dbei.timestamp, g_groupBreak, (TCHAR)'D'); - AppendTimeStamp(szFinalTimestamp, isSent, &buffer, &bufferEnd, &bufferAlloced, skipFont, dat, iFontIDOffset); + AppendTimeStamp(szFinalTimestamp, isSent, buffer, bufferEnd, bufferAlloced, skipFont, dat, iFontIDOffset); } else skipToNext = TRUE; break; case 'E': // short date... if (showTime && showDate) { TCHAR *szFinalTimestamp = Template_MakeRelativeDate(dat, hTimeZone, dbei.timestamp, g_groupBreak, (TCHAR)'E'); - AppendTimeStamp(szFinalTimestamp, isSent, &buffer, &bufferEnd, &bufferAlloced, skipFont, dat, iFontIDOffset); + AppendTimeStamp(szFinalTimestamp, isSent, buffer, bufferEnd, bufferAlloced, skipFont, dat, iFontIDOffset); } else skipToNext = TRUE; break; @@ -807,55 +802,55 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, case 'h': // 24 hour if (showTime) { if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, cc == 'h' ? "%02d" : "%2d", cc == 'h' ? event_time.tm_hour : (event_time.tm_hour > 12 ? event_time.tm_hour - 12 : event_time.tm_hour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, cc == 'h' ? "%02d" : "%2d", cc == 'h' ? event_time.tm_hour : (event_time.tm_hour > 12 ? event_time.tm_hour - 12 : event_time.tm_hour)); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, cc == 'h' ? "%s %02d" : "%s %2d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), cc == 'h' ? event_time.tm_hour : (event_time.tm_hour > 12 ? event_time.tm_hour - 12 : event_time.tm_hour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, cc == 'h' ? "%s %02d" : "%s %2d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), cc == 'h' ? event_time.tm_hour : (event_time.tm_hour > 12 ? event_time.tm_hour - 12 : event_time.tm_hour)); } else skipToNext = TRUE; break; case 'm': // minute if (showTime) { if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%02d", event_time.tm_min); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%02d", event_time.tm_min); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_min); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_min); } else skipToNext = TRUE; break; case 's': //second if (showTime && dwEffectiveFlags & MWF_LOG_SHOWSECONDS) { if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%02d", event_time.tm_sec); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%02d", event_time.tm_sec); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_sec); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_sec); } else skipToNext = TRUE; break; case 'p': // am/pm symbol if (showTime) { if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s", event_time.tm_hour > 11 ? "PM" : "AM"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s", event_time.tm_hour > 11 ? "PM" : "AM"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s %s", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_hour > 11 ? "PM" : "AM"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s %s", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_hour > 11 ? "PM" : "AM"); } else skipToNext = TRUE; break; case 'o': // month if (showTime && showDate) { if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%02d", event_time.tm_mon + 1); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%02d", event_time.tm_mon + 1); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_mon + 1); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_mon + 1); } else skipToNext = TRUE; break; case 'O': // month (name) if (showTime && showDate) { if (skipFont) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateTS(months[event_time.tm_mon]), MAKELONG(isSent, dat->bIsHistory)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateTS(months[event_time.tm_mon]), MAKELONG(isSent, dat->bIsHistory)); else { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset)); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateTS(months[event_time.tm_mon]), MAKELONG(isSent, dat->bIsHistory)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateTS(months[event_time.tm_mon]), MAKELONG(isSent, dat->bIsHistory)); } } else skipToNext = TRUE; @@ -863,19 +858,19 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, case 'd': // day of month if (showTime && showDate) { if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%02d", event_time.tm_mday); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%02d", event_time.tm_mday); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_mday); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s %02d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_mday); } else skipToNext = TRUE; break; case 'w': // day of week if (showTime && showDate) { if (skipFont) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateTS(weekDays[event_time.tm_wday]), MAKELONG(isSent, dat->bIsHistory)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateTS(weekDays[event_time.tm_wday]), MAKELONG(isSent, dat->bIsHistory)); else { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset)); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, TranslateTS(weekDays[event_time.tm_wday]), MAKELONG(isSent, dat->bIsHistory)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateTS(weekDays[event_time.tm_wday]), MAKELONG(isSent, dat->bIsHistory)); } } else skipToNext = TRUE; @@ -883,9 +878,9 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, case 'y': // year if (showTime && showDate) { if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%04d", event_time.tm_year + 1900); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%04d", event_time.tm_year + 1900); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s %04d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_year + 1900); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s %04d", GetRTFFont(isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset), event_time.tm_year + 1900); } else skipToNext = TRUE; break; @@ -893,7 +888,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, case 'r': // long date if (showTime && showDate) { TCHAR *szFinalTimestamp = Template_MakeRelativeDate(dat, hTimeZone, dbei.timestamp, g_groupBreak, cc); - AppendTimeStamp(szFinalTimestamp, isSent, &buffer, &bufferEnd, &bufferAlloced, skipFont, dat, iFontIDOffset); + AppendTimeStamp(szFinalTimestamp, isSent, buffer, bufferEnd, bufferAlloced, skipFont, dat, iFontIDOffset); } else skipToNext = TRUE; break; @@ -901,7 +896,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, case 'T': if (showTime) { TCHAR *szFinalTimestamp = Template_MakeRelativeDate(dat, hTimeZone, dbei.timestamp, g_groupBreak, (TCHAR)((dwEffectiveFlags & MWF_LOG_SHOWSECONDS) ? cc : (TCHAR)'t')); - AppendTimeStamp(szFinalTimestamp, isSent, &buffer, &bufferEnd, &bufferAlloced, skipFont, dat, iFontIDOffset); + AppendTimeStamp(szFinalTimestamp, isSent, buffer, bufferEnd, bufferAlloced, skipFont, dat, iFontIDOffset); } else skipToNext = TRUE; break; @@ -929,37 +924,37 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, c = 0x4e; } if (skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%c%s ", c, GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%c%s ", c, GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s %c%s ", isSent ? GetRTFFont(MSGFONTID_SYMBOLS_OUT) : GetRTFFont(MSGFONTID_SYMBOLS_IN), c, GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s %c%s ", isSent ? GetRTFFont(MSGFONTID_SYMBOLS_OUT) : GetRTFFont(MSGFONTID_SYMBOLS_IN), c, GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); } else skipToNext = TRUE; break; case 'n': // hard line break - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, dbei.flags & DBEF_RTL ? "\\rtlpar\\par\\rtlpar" : "\\par\\ltrpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, dbei.flags & DBEF_RTL ? "\\rtlpar\\par\\rtlpar" : "\\par\\ltrpar"); break; case 'l': // soft line break - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\line"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line"); break; case 'N': // nickname if (!skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYNAME + iFontIDOffset : MSGFONTID_YOURNAME + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYNAME + iFontIDOffset : MSGFONTID_YOURNAME + iFontIDOffset)); if (isSent) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, szMyName, MAKELONG(isSent, dat->bIsHistory)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, szMyName, MAKELONG(isSent, dat->bIsHistory)); else - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, szYourName, MAKELONG(isSent, dat->bIsHistory)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, szYourName, MAKELONG(isSent, dat->bIsHistory)); break; case 'U': // UIN if (!skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYNAME + iFontIDOffset : MSGFONTID_YOURNAME + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYNAME + iFontIDOffset : MSGFONTID_YOURNAME + iFontIDOffset)); if (!isSent) - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, dat->cache->getUIN(), MAKELONG(isSent, dat->bIsHistory)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, dat->cache->getUIN(), MAKELONG(isSent, dat->bIsHistory)); else - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, dat->myUin, MAKELONG(isSent, dat->bIsHistory)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, dat->myUin, MAKELONG(isSent, dat->bIsHistory)); break; case 'e': // error message - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(MSGFONTID_ERROR)); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, (wchar_t *)dbei.szModule, MAKELONG(isSent, dat->bIsHistory)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(MSGFONTID_ERROR)); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, (wchar_t *)dbei.szModule, MAKELONG(isSent, dat->bIsHistory)); break; case 'M': // message switch (dbei.eventType) { @@ -970,27 +965,27 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, break; if (dbei.eventType == EVENTTYPE_ERRMSG) { if (!skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\line%s ", GetRTFFont(bIsStatusChangeEvent ? H_MSGFONTID_STATUSCHANGES : MSGFONTID_MYMSG)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line%s ", GetRTFFont(bIsStatusChangeEvent ? H_MSGFONTID_STATUSCHANGES : MSGFONTID_MYMSG)); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\line "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line "); } else if (!skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(bIsStatusChangeEvent ? H_MSGFONTID_STATUSCHANGES : MSGFONTID_MYMSG)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(bIsStatusChangeEvent ? H_MSGFONTID_STATUSCHANGES : MSGFONTID_MYMSG)); } else if (!skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); if (rtfMessage != NULL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s", rtfMessage); + 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 "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s", "\\b0\\ul0\\i0 "); break; case EVENTTYPE_FILE: if (!skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMISC + iFontIDOffset : MSGFONTID_YOURMISC + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMISC + iFontIDOffset : MSGFONTID_YOURMISC + iFontIDOffset)); { char *szFileName = (char *)dbei.pBlob + sizeof(DWORD); char *szDescr = szFileName + mir_strlen(szFileName) + 1; @@ -999,10 +994,10 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, TCHAR *tszDescr = DbGetEventStringT(&dbei, szDescr); TCHAR buf[1000]; mir_sntprintf(buf, SIZEOF(buf), _T("%s (%s)"), tszFileName, tszDescr); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, buf, 0); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, buf, 0); mir_free(tszDescr); } - else AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, tszFileName, 0); + else AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, tszFileName, 0); mir_free(tszFileName); } @@ -1010,48 +1005,48 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, default: if (!skipFont) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); ptrT tszText(DbGetEventTextT(&dbei, CP_ACP)); - AppendUnicodeToBuffer(&buffer, &bufferEnd, &bufferAlloced, tszText, 0); + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, tszText, 0); } break; case '*': // bold - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, isBold ? "\\b0 " : "\\b "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, isBold ? "\\b0 " : "\\b "); isBold = !isBold; break; case '/': // italic - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, isItalic ? "\\i0 " : "\\i "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, isItalic ? "\\i0 " : "\\i "); isItalic = !isItalic; break; case '_': // italic - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, isUnderline ? "\\ul0 " : "\\ul "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, isUnderline ? "\\ul0 " : "\\ul "); isUnderline = !isUnderline; break; case '-': // grid line color = szTemplate[i + 2]; if (color >= '0' && color <= '4') { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", MSGDLGFONTCOUNT + 8 + (color - '0'), MSGDLGFONTCOUNT + 7 + (color - '0')); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", MSGDLGFONTCOUNT + 8 + (color - '0'), MSGDLGFONTCOUNT + 7 + (color - '0')); i++; } - else AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", MSGDLGFONTCOUNT + 4, MSGDLGFONTCOUNT + 4); + else AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par\\sl-1\\slmult0\\highlight%d\\cf%d\\-\\par\\sl0", MSGDLGFONTCOUNT + 4, MSGDLGFONTCOUNT + 4); break; case '~': // font break (switch to default font...) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); break; case 'H': // highlight color = szTemplate[i + 2]; if (color >= '0' && color <= '4') { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\highlight%d", MSGDLGFONTCOUNT + 8 + (color - '0')); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\highlight%d", MSGDLGFONTCOUNT + 8 + (color - '0')); i++; } - else AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\highlight%d", (MSGDLGFONTCOUNT + (dat->bIsHistory ? 5 : 1) + ((isSent) ? 1 : 0))); + else AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\highlight%d", (MSGDLGFONTCOUNT + (dat->bIsHistory ? 5 : 1) + ((isSent) ? 1 : 0))); break; case '|': // tab if (dwEffectiveFlags & MWF_LOG_INDENT) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\tab"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\tab"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " "); break; case 'f': // font tag... code = szTemplate[i + 2]; @@ -1076,7 +1071,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, } if (fontindex != -1) { i++; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s ", GetRTFFont(fontindex)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(fontindex)); } else skipToNext = TRUE; } @@ -1085,33 +1080,33 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, case 'c': // font color (using one of the predefined 5 colors) or one of the standard font colors (m = message, d = date/time, n = nick) color = szTemplate[i + 2]; if (color >= '0' && color <= '4') { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\cf%d ", MSGDLGFONTCOUNT + 8 + (color - '0')); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\cf%d ", MSGDLGFONTCOUNT + 8 + (color - '0')); i++; } else if (color == (TCHAR)'d') { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_MYTIME + iFontIDOffset : MSGFONTID_YOURTIME + iFontIDOffset); i++; } else if (color == (TCHAR)'m') { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset); i++; } else if (color == (TCHAR)'n') { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_MYNAME + iFontIDOffset : MSGFONTID_YOURNAME + iFontIDOffset); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_MYNAME + iFontIDOffset : MSGFONTID_YOURNAME + iFontIDOffset); i++; } else if (color == (TCHAR)'s') { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_SYMBOLS_OUT : MSGFONTID_SYMBOLS_IN); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\cf%d ", isSent ? MSGFONTID_SYMBOLS_OUT : MSGFONTID_SYMBOLS_IN); i++; } else skipToNext = TRUE; break; case '<': // bidi tag - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlmark\\rtlch "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlmark\\rtlch "); break; case '>': // bidi tag - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrmark\\ltrch "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrmark\\ltrch "); break; } skip: @@ -1124,15 +1119,15 @@ skip: else { char temp[24]; mir_snprintf(temp, 24, "{\\uc1\\u%d?}", (int)ci); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, temp); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, temp); i++; } } if (dat->hHistoryEvents) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, dat->szMicroLf, MSGDLGFONTCOUNT + 1 + ((isSent) ? 1 : 0), hDbEvent); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, dat->szMicroLf, MSGDLGFONTCOUNT + 1 + ((isSent) ? 1 : 0), hDbEvent); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par"); if (streamData->dbei == 0) mir_free(dbei.pBlob); diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index a10f615d95..0be97597b6 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -48,42 +48,41 @@ struct LogStreamData static char szSep2[40], szSep2_RTL[50]; -static void AppendToBuffer(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...) +static void AppendToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...) { va_list va; int charsDone; 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 += 1024; - *buffer = (char *) mir_realloc(*buffer, *cbBufferAlloced); + cbBufferAlloced += 1024; + buffer = (char*)mir_realloc(buffer, cbBufferAlloced); } va_end(va); - *cbBufferEnd += charsDone; + cbBufferEnd += charsDone; } static const TCHAR *bbcodes[] = { _T("[b]"), _T("[i]"), _T("[u]"), _T("[s]"), _T("[/b]"), _T("[/i]"), _T("[/u]"), _T("[/s]") }; static const char *bbcodefmt[] = { "\\b ", "\\i ", "\\ul ", "\\strike ", "\\b0 ", "\\i0 ", "\\ul0 ", "\\strike0 " }; -static int AppendToBufferWithRTF(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, TCHAR* line) +static int AppendToBufferWithRTF(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, TCHAR* line) { DWORD textCharsCount = 0; char *d; - int lineLen; if (line == NULL) return 0; - lineLen = (int)_tcslen(line) * 9 + 8; - if (*cbBufferEnd + lineLen > *cbBufferAlloced) { - cbBufferAlloced[0] += (lineLen + 1024 - lineLen % 1024); - *buffer = (char *)mir_realloc(*buffer, *cbBufferAlloced); + size_t lineLen = _tcslen(line) * 9 + 8; + if (cbBufferEnd + lineLen > cbBufferAlloced) { + cbBufferAlloced += lineLen + 1024 - lineLen % 1024; + buffer = (char*)mir_realloc(buffer, cbBufferAlloced); } - d = *buffer + *cbBufferEnd; + d = buffer + cbBufferEnd; strcpy(d, "{\\uc1 "); d += 6; @@ -160,7 +159,7 @@ static int AppendToBufferWithRTF(char **buffer, int *cbBufferEnd, int *cbBufferA *(d++) = '}'; *d = 0; - *cbBufferEnd = (int)(d - *buffer); + cbBufferEnd = (int)(d - buffer); return textCharsCount; } @@ -171,39 +170,37 @@ static char *CreateRTFHeader(SrmmWindowData *dat) HDC hdc = GetDC(NULL); logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); - int bufferEnd = 0; - int bufferAlloced = 1024; + size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl"); LOGFONT lf; for (int i = 0; LoadMsgDlgFont(i, &lf, NULL); i++) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, FONT_FORMAT, i, lf.lfCharSet, lf.lfFaceName); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, FONT_FORMAT, i, lf.lfCharSet, lf.lfFaceName); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "}{\\colortbl "); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}{\\colortbl "); COLORREF colour; for (int i = 0; LoadMsgDlgFont(i, NULL, &colour); i++) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); if (GetSysColorBrush(COLOR_HOTLIGHT) == NULL) colour = RGB(0, 0, 255); else 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"); + 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; } //mir_free() the return value static char *CreateRTFTail(SrmmWindowData *dat) { - int bufferEnd = 0; - int bufferAlloced = 1024; + size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "}"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}"); return buffer; } @@ -232,7 +229,6 @@ int DbEventIsShown(DBEVENTINFO *dbei) //mir_free() the return value static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE hDbEvent, struct LogStreamData *streamData) { - int bufferAlloced, bufferEnd; int showColon = 0; DBEVENTINFO dbei = { sizeof(dbei) }; @@ -253,33 +249,33 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE else if (dbei.eventType == EVENTTYPE_JABBER_CHATSTATES || dbei.eventType == EVENTTYPE_JABBER_PRESENCE) { db_event_markRead(hContact, hDbEvent); } - bufferEnd = 0; - bufferAlloced = 1024; + + size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; if (!dat->bIsAutoRTL && !streamData->isEmpty) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par"); if (dbei.flags & DBEF_RTL) { - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlpar"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlpar"); dat->bIsAutoRTL = TRUE; } - else AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrpar"); + else AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrpar"); streamData->isEmpty = 0; if (dat->bIsAutoRTL) { if (dbei.flags & DBEF_RTL) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\ltrch\\rtlch"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrch\\rtlch"); else - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\rtlch\\ltrch"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlch\\ltrch"); } if (g_dat.flags & SMF_SHOWICONS) { int i = ((dbei.eventType == EVENTTYPE_MESSAGE) ? ((dbei.flags & DBEF_SENT) ? LOGICON_MSG_OUT : LOGICON_MSG_IN): LOGICON_MSG_NOTICE); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\f0\\fs14"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\f0\\fs14"); while (bufferAlloced - bufferEnd < logIconBmpSize[i]) bufferAlloced += 1024; buffer = (char *)mir_realloc(buffer, bufferAlloced); @@ -298,8 +294,8 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE tmi.printTimeStamp(NULL, dbei.timestamp, szFormat, str, SIZEOF(str), 0); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, str); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); + AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, str); showColon = 1; } @@ -318,15 +314,15 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE } else szName = pcli->pfnGetContactDisplayName(hContact, 0); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME)); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, szName); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME)); + AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, szName); showColon = 1; if (ci.pszVal) mir_free(ci.pszVal); } if (showColon) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "%s :", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s :", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); TCHAR *msg, *szName; switch (dbei.eventType) { @@ -348,13 +344,13 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE } else szName = pcli->pfnGetContactDisplayName(hContact, 0); - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE)); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, szName); - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, _T(" ")); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(MSGFONTID_NOTICE)); + AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, szName); + AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, _T(" ")); msg = DbGetEventTextT(&dbei, CP_ACP); if (msg) { - AppendToBufferWithRTF(&buffer, &bufferEnd, &bufferAlloced, msg); + AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, msg); mir_free(msg); } break; @@ -364,17 +360,17 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE 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); + 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, ")"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, " ("); + AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, ptszDescr); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, ")"); mir_free(ptszDescr); } break; @@ -382,14 +378,14 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, HANDLE 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); + 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) - AppendToBuffer(&buffer, &bufferEnd, &bufferAlloced, "\\par"); + AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par"); mir_free(dbei.pBlob); return buffer; -- cgit v1.2.3