From 62ab18a9fda2f19c08ae63a14c7a262ca62f0cce Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 8 Jul 2014 15:49:18 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@9732 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SecureIM/src/mmi.cpp | 142 ++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 75 deletions(-) (limited to 'plugins/SecureIM/src/mmi.cpp') diff --git a/plugins/SecureIM/src/mmi.cpp b/plugins/SecureIM/src/mmi.cpp index 4a6b06bbe4..6f9875f604 100644 --- a/plugins/SecureIM/src/mmi.cpp +++ b/plugins/SecureIM/src/mmi.cpp @@ -1,150 +1,142 @@ #include "commonheaders.h" - -void *operator new(size_t sz) { - return mir_alloc(sz); +void *operator new(size_t sz) +{ + return mir_calloc(sz); } - -void *operator new[](size_t size) { +void *operator new[](size_t size) +{ return operator new(size); } - -void operator delete(void *p) { +void operator delete(void *p) +{ mir_free(p); } - -void operator delete[](void * p) { +void operator delete[](void *p) +{ operator delete(p); } - // ANSIzUCS2z + ANSIzUCS2z = ANSIzUCS2z -char *m_wwstrcat(LPCSTR strA, LPCSTR strB) { +char* m_wwstrcat(LPCSTR strA, LPCSTR strB) +{ int lenA = (int)strlen(strA); int lenB = (int)strlen(strB); - LPSTR str = (LPSTR)mir_alloc((lenA+lenB+1)*(sizeof(WCHAR)+1)); - memcpy(str, strA, lenA); - memcpy(str+lenA, strB, lenB+1); - memcpy(str+lenA+lenB+1, strA+lenA+1, lenA*sizeof(WCHAR)); - memcpy(str+lenA+lenB+1+lenA*sizeof(WCHAR), strB+lenB+1, (lenB+1)*sizeof(WCHAR)); + LPSTR str = (LPSTR)mir_alloc((lenA + lenB + 1)*(sizeof(WCHAR) + 1)); + memcpy(str, strA, lenA); + memcpy(str + lenA, strB, lenB + 1); + memcpy(str + lenA + lenB + 1, strA + lenA + 1, lenA*sizeof(WCHAR)); + memcpy(str + lenA + lenB + 1 + lenA*sizeof(WCHAR), strB + lenB + 1, (lenB + 1)*sizeof(WCHAR)); return str; } - // ANSIz + ANSIzUCS2z = ANSIzUCS2z -char *m_awstrcat(LPCSTR strA, LPCSTR strB) { +char* m_awstrcat(LPCSTR strA, LPCSTR strB) +{ int lenA = (int)strlen(strA); - LPSTR tmpA = (LPSTR)mir_alloc((lenA+1)*(sizeof(WCHAR)+1)); + LPSTR tmpA = (LPSTR)mir_alloc((lenA + 1)*(sizeof(WCHAR) + 1)); strcpy(tmpA, strA); - MultiByteToWideChar(CP_ACP, 0, strA, -1, (LPWSTR)(tmpA+lenA+1), (lenA+1)*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, strA, -1, (LPWSTR)(tmpA + lenA + 1), (lenA + 1)*sizeof(WCHAR)); LPSTR str = m_wwstrcat(tmpA, strB); mir_free(tmpA); return str; } - // ANSIz + ANSIz = ANSIzUCS2z -char *m_aastrcat(LPCSTR strA, LPCSTR strB) { +char* m_aastrcat(LPCSTR strA, LPCSTR strB) +{ int lenA = (int)strlen(strA); int lenB = (int)strlen(strB); - LPSTR str = (LPSTR)mir_alloc((lenA+lenB+1)*(sizeof(WCHAR)+1)); - strcpy(str,strA); - strcat(str,strB); - MultiByteToWideChar(CP_ACP, 0, str, -1, (LPWSTR)(str+lenA+lenB+1), (lenA+lenB+1)*sizeof(WCHAR)); + LPSTR str = (LPSTR)mir_alloc((lenA + lenB + 1)*(sizeof(WCHAR) + 1)); + strcpy(str, strA); + strcat(str, strB); + MultiByteToWideChar(CP_ACP, 0, str, -1, (LPWSTR)(str + lenA + lenB + 1), (lenA + lenB + 1)*sizeof(WCHAR)); return str; } - LPSTR m_string = NULL; // ANSIz + ANSIz = ANSIz -char *m_ustrcat(LPCSTR strA, LPCSTR strB) { +char* m_ustrcat(LPCSTR strA, LPCSTR strB) +{ SAFE_FREE(m_string); - m_string = (LPSTR) mir_alloc(strlen(strA)+strlen(strB)+1); - strcpy(m_string,strA); strcat(m_string,strB); + m_string = (LPSTR)mir_alloc(strlen(strA) + strlen(strB) + 1); + strcpy(m_string, strA); strcat(m_string, strB); return m_string; } - LPSTR m_hex = NULL; -LPSTR to_hex(PBYTE bin, int len) { +LPSTR to_hex(PBYTE bin, int len) +{ SAFE_FREE(m_hex); - m_hex = (LPSTR) mir_alloc(len*3+1); + m_hex = (LPSTR)mir_alloc(len * 3 + 1); LPSTR m_ptr = m_hex; - for ( int i=0; iutf8decode(szUtfMsg); LPSTR szMsg = mir_u2a(wszMsg); - flags |= PREF_UNICODE; - int olen = (int)wcslen((LPWSTR)wszMsg)+1; - int nlen = olen*(sizeof(WCHAR)+1); - szNewMsg = (LPSTR) mir_alloc(nlen); - memcpy(szNewMsg,szMsg,olen); - memcpy(szNewMsg+olen,wszMsg,olen*sizeof(WCHAR)); - mir_free(szMsg); + flags |= PREF_UNICODE; + int olen = (int)wcslen((LPWSTR)wszMsg) + 1; + int nlen = olen*(sizeof(WCHAR) + 1); + szNewMsg = (LPSTR)mir_alloc(nlen); + memcpy(szNewMsg, szMsg, olen); + memcpy(szNewMsg + olen, wszMsg, olen*sizeof(WCHAR)); + mir_free(szMsg); } else { flags &= ~PREF_UNICODE; flags |= PREF_UTF; - szNewMsg = (LPSTR) mir_strdup(szUtfMsg); + szNewMsg = (LPSTR)mir_strdup(szUtfMsg); } return szNewMsg; } - -// ¯à¥®¡à §ã¥¬ ⥪áâ ¨§ ä®à¬ â  ¬¨à ­¤ë ¢ ç¨áâë© UTF8 -LPSTR miranda_to_utf8(LPCSTR szMirMsg, DWORD flags) { +// ïðåîáðàçóåì òåêñò èç ôîðìàòà ìèðàíäû â ÷èñòûé UTF8 +LPSTR miranda_to_utf8(LPCSTR szMirMsg, DWORD flags) +{ LPSTR szNewMsg; - if (flags & PREF_UTF) { - szNewMsg = (LPSTR) szMirMsg; - } - else - if (flags & PREF_UNICODE) { - szNewMsg = exp->utf8encode((LPCWSTR)(szMirMsg+strlen(szMirMsg)+1)); - } + if (flags & PREF_UTF) + szNewMsg = (LPSTR)szMirMsg; + else if (flags & PREF_UNICODE) + szNewMsg = exp->utf8encode((LPCWSTR)(szMirMsg + strlen(szMirMsg) + 1)); else { LPWSTR wszMirMsg = mir_a2u(szMirMsg); - szNewMsg = exp->utf8encode((LPCWSTR)wszMirMsg); + szNewMsg = exp->utf8encode(wszMirMsg); mir_free(wszMirMsg); } return mir_strdup(szNewMsg); } - - -// EOF -- cgit v1.2.3