summaryrefslogtreecommitdiff
path: root/plugins/AutoShutdown/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-08-13 22:13:41 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-08-13 22:13:41 +0000
commit3ec93b6744328421a82b9fd39d711eeea0d9749a (patch)
treea9c454c592bcbe60090c39320811892d14ce9b87 /plugins/AutoShutdown/src/utils.cpp
parentfb24858c747011487663c030ed45635bf057bd88 (diff)
- 64-bit compatibility;
- code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14950 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AutoShutdown/src/utils.cpp')
-rw-r--r--plugins/AutoShutdown/src/utils.cpp144
1 files changed, 73 insertions, 71 deletions
diff --git a/plugins/AutoShutdown/src/utils.cpp b/plugins/AutoShutdown/src/utils.cpp
index d866eadd83..2d8de89575 100644
--- a/plugins/AutoShutdown/src/utils.cpp
+++ b/plugins/AutoShutdown/src/utils.cpp
@@ -26,19 +26,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// mir_free() the return value
char* u2a(const WCHAR *pszUnicode)
{
- int codepage,cch;
- char *psz;
- DWORD flags;
+ if (pszUnicode == NULL)
+ return NULL;
+
+ int codepage = Langpack_GetDefaultCodePage();
- if (pszUnicode==NULL) return NULL;
- codepage = Langpack_GetDefaultCodePage();
/* without WC_COMPOSITECHECK some characters might get out strange (see MS blog) */
- cch=WideCharToMultiByte(codepage,flags=WC_COMPOSITECHECK,pszUnicode,-1,NULL,0,NULL,NULL);
- if (!cch) cch=WideCharToMultiByte(codepage,flags=0,pszUnicode,-1,NULL,0,NULL,NULL);
- if (!cch) return NULL;
+ DWORD flags;
+ int cch = WideCharToMultiByte(codepage, flags = WC_COMPOSITECHECK, pszUnicode, -1, NULL, 0, NULL, NULL);
+ if (!cch)
+ cch = WideCharToMultiByte(codepage, flags = 0, pszUnicode, -1, NULL, 0, NULL, NULL);
+ if (!cch)
+ return NULL;
- psz=(char*)mir_alloc(cch);
- if (psz != NULL && !WideCharToMultiByte(codepage,flags,pszUnicode,-1,psz,cch,NULL,NULL)){
+ char *psz = (char*)mir_alloc(cch);
+ if (psz != NULL && !WideCharToMultiByte(codepage, flags, pszUnicode, -1, psz, cch, NULL, NULL)) {
mir_free(psz);
return NULL;
}
@@ -47,18 +49,18 @@ char* u2a(const WCHAR *pszUnicode)
void TrimString(TCHAR *pszStr)
{
- int i;
- TCHAR *psz,szChars[]=_T(" \r\n\t");
- for(i=0;i<_countof(szChars);++i) {
+ TCHAR *psz, szChars[] = _T(" \r\n\t");
+ for (int i = 0; i < _countof(szChars); ++i) {
/* trim end */
- psz=&pszStr[mir_tstrlen(pszStr)-1];
- while(pszStr[0] && *psz==szChars[i]) {
- *psz=0;
- psz=CharPrev(pszStr,psz);
+ psz = &pszStr[mir_tstrlen(pszStr) - 1];
+ while (pszStr[0] && *psz == szChars[i]) {
+ *psz = 0;
+ psz = CharPrev(pszStr, psz);
}
/* trim beginning */
- for(psz=pszStr;(*psz && *psz==szChars[i]);psz=CharNext(psz));
- memmove(pszStr,psz,(mir_tstrlen(psz)+1)*sizeof(TCHAR));
+ for (psz = pszStr; (*psz && *psz == szChars[i]); psz = CharNext(psz))
+ ;
+ memmove(pszStr, psz, (mir_tstrlen(psz) + 1)*sizeof(TCHAR));
}
}
@@ -73,39 +75,38 @@ static void MessageBoxIndirectFree(void *param)
mir_free(mbp);
}
-void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...)
+void ShowInfoMessage(BYTE flags, const char *pszTitle, const char *pszTextFmt, ...)
{
char szText[256]; /* max for systray */
- MSGBOXPARAMSA *mbp;
va_list va;
- va_start(va,pszTextFmt);
- mir_vsnprintf(szText,_countof(szText),pszTextFmt,va);
+ va_start(va, pszTextFmt);
+ mir_vsnprintf(szText, _countof(szText), pszTextFmt, va);
va_end(va);
if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) {
MIRANDASYSTRAYNOTIFY msn;
- msn.cbSize=sizeof(msn);
- msn.szProto=NULL;
- msn.szInfoTitle=(char*)pszTitle;
- msn.szInfo=(char*)szText;
- msn.uTimeout=30000; /* max timeout */
- msn.dwInfoFlags=flags;
- if (!CallServiceSync(MS_CLIST_SYSTRAY_NOTIFY,0,(LPARAM)&msn))
+ msn.cbSize = sizeof(msn);
+ msn.szProto = NULL;
+ msn.szInfoTitle = (char*)pszTitle;
+ msn.szInfo = (char*)szText;
+ msn.uTimeout = 30000; /* max timeout */
+ msn.dwInfoFlags = flags;
+ if (!CallServiceSync(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&msn))
return; /* success */
}
- mbp=(MSGBOXPARAMSA*)mir_calloc(sizeof(*mbp));
- if (mbp==NULL) return;
+ MSGBOXPARAMSA *mbp = (MSGBOXPARAMSA*)mir_calloc(sizeof(*mbp));
+ if (mbp == NULL) return;
mbp->cbSize = sizeof(*mbp);
mbp->lpszCaption = mir_strdup(pszTitle);
mbp->lpszText = mir_strdup(szText);
- mbp->dwStyle = MB_OK|MB_SETFOREGROUND|MB_TASKMODAL;
+ mbp->dwStyle = MB_OK | MB_SETFOREGROUND | MB_TASKMODAL;
mbp->dwLanguageId = LANGIDFROMLCID(Langpack_GetDefaultLocale());
- switch(flags&NIIF_ICON_MASK) {
- case NIIF_INFO: mbp->dwStyle|=MB_ICONINFORMATION; break;
- case NIIF_WARNING: mbp->dwStyle|=MB_ICONWARNING; break;
- case NIIF_ERROR: mbp->dwStyle|=MB_ICONERROR;
+ switch (flags&NIIF_ICON_MASK) {
+ case NIIF_INFO: mbp->dwStyle |= MB_ICONINFORMATION; break;
+ case NIIF_WARNING: mbp->dwStyle |= MB_ICONWARNING; break;
+ case NIIF_ERROR: mbp->dwStyle |= MB_ICONERROR;
}
mir_forkthread(MessageBoxIndirectFree, mbp);
}
@@ -113,17 +114,17 @@ void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...)
// LocalFree() the return value
char* GetWinErrorDescription(DWORD dwLastError)
{
- char *buf=NULL;
- DWORD flags=FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM;
- if (!FormatMessageA(flags,NULL,dwLastError,LANGIDFROMLCID(Langpack_GetDefaultLocale()),(char*)&buf,0,NULL))
- if (GetLastError()==ERROR_RESOURCE_LANG_NOT_FOUND)
- FormatMessageA(flags,NULL,dwLastError,0,(char*)&buf,0,NULL);
+ char *buf = NULL;
+ DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM;
+ if (!FormatMessageA(flags, NULL, dwLastError, LANGIDFROMLCID(Langpack_GetDefaultLocale()), (char*)&buf, 0, NULL))
+ if (GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND)
+ FormatMessageA(flags, NULL, dwLastError, 0, (char*)&buf, 0, NULL);
return buf;
}
/************************* Time ***********************************/
-BOOL SystemTimeToTimeStamp(SYSTEMTIME *st,time_t *timestamp)
+BOOL SystemTimeToTimeStamp(SYSTEMTIME *st, time_t *timestamp)
{
struct tm ts;
ts.tm_isdst = -1; /* daylight saving time (-1=compute) */
@@ -132,16 +133,16 @@ BOOL SystemTimeToTimeStamp(SYSTEMTIME *st,time_t *timestamp)
ts.tm_hour = st->wHour; /* 0-23 */
ts.tm_mday = st->wDay; /* 1-31 */
ts.tm_wday = st->wDayOfWeek; /* 0-6 (Sun-Sat) */
- ts.tm_mon = st->wMonth-1; /* 0-11 (Jan-Dec) */
- ts.tm_year = st->wYear-1900; /* current year minus 1900 */
- ts.tm_yday=0; /* 0-365 (Jan1=0) */
+ ts.tm_mon = st->wMonth - 1; /* 0-11 (Jan-Dec) */
+ ts.tm_year = st->wYear - 1900; /* current year minus 1900 */
+ ts.tm_yday = 0; /* 0-365 (Jan1=0) */
*timestamp = mktime(&ts);
return (*timestamp != -1);
}
-BOOL TimeStampToSystemTime(time_t timestamp,SYSTEMTIME *st)
+BOOL TimeStampToSystemTime(time_t timestamp, SYSTEMTIME *st)
{
- struct tm ts = {0};
+ struct tm ts = { 0 };
errno_t err = localtime_s(&ts, &timestamp); /* statically alloced, local time correction */
if (err != 0)
return FALSE;
@@ -152,52 +153,53 @@ BOOL TimeStampToSystemTime(time_t timestamp,SYSTEMTIME *st)
st->wHour = (WORD)ts.tm_hour; /* 0-23 */
st->wDay = (WORD)ts.tm_mday; /* 1-31 */
st->wDayOfWeek = (WORD)ts.tm_wday; /* 0-6 (Sun-Sat) */
- st->wMonth = (WORD)(ts.tm_mon+1); /* 1-12 (Jan-Dec) */
- st->wYear = (WORD)(ts.tm_year+1900); /* 1601-30827 */
+ st->wMonth = (WORD)(ts.tm_mon + 1); /* 1-12 (Jan-Dec) */
+ st->wYear = (WORD)(ts.tm_year + 1900); /* 1601-30827 */
return TRUE;
}
-BOOL GetFormatedCountdown(TCHAR *pszOut,int nSize,time_t countdown)
+BOOL GetFormatedCountdown(TCHAR *pszOut, int nSize, time_t countdown)
{
- static BOOL fInited=FALSE;
- static int (WINAPI *pfnGetDurationFormat)(LCID,DWORD,const SYSTEMTIME*,double,WCHAR*,WCHAR*,int);
+ static BOOL fInited = FALSE;
+ static int (WINAPI *pfnGetDurationFormat)(LCID, DWORD, const SYSTEMTIME*, double, WCHAR*, WCHAR*, int);
/* Init */
if (!fInited && IsWinVerVistaPlus()) {
- *(PROC*)&pfnGetDurationFormat=GetProcAddress(GetModuleHandleA("KERNEL32"),"GetDurationFormat");
- fInited=TRUE;
+ *(PROC*)&pfnGetDurationFormat = GetProcAddress(GetModuleHandleA("KERNEL32"), "GetDurationFormat");
+ fInited = TRUE;
}
+
/* WinVista */
if (pfnGetDurationFormat != NULL) {
SYSTEMTIME st;
LCID locale;
- locale=Langpack_GetDefaultLocale();
- if (TimeStampToSystemTime(countdown,&st))
- if (pfnGetDurationFormat(locale,0,&st,0,NULL,pszOut,nSize))
+ locale = Langpack_GetDefaultLocale();
+ if (TimeStampToSystemTime(countdown, &st))
+ if (pfnGetDurationFormat(locale, 0, &st, 0, NULL, pszOut, nSize))
return TRUE;
return FALSE;
}
/* Win9x/NT/XP */
- return StrFromTimeInterval(pszOut,nSize,(countdown>(MAXDWORD/1000))?MAXDWORD:(countdown*1000),10) != 0;
+ return StrFromTimeInterval(pszOut, nSize, (countdown > (MAXDWORD / 1000)) ? MAXDWORD : (countdown * 1000), 10) != 0;
}
-BOOL GetFormatedDateTime(TCHAR *pszOut,int nSize,time_t timestamp,BOOL fShowDateEvenToday)
+BOOL GetFormatedDateTime(TCHAR *pszOut, int nSize, time_t timestamp, BOOL fShowDateEvenToday)
{
- SYSTEMTIME st,stNow;
- LCID locale;
- locale=Langpack_GetDefaultLocale();
+ SYSTEMTIME st, stNow;
+ LCID locale = Langpack_GetDefaultLocale();
GetLocalTime(&stNow);
- TimeStampToSystemTime(timestamp,&st);
+ TimeStampToSystemTime(timestamp, &st);
/* today: no need to show the date */
- if (!fShowDateEvenToday && st.wDay==stNow.wDay && st.wMonth==stNow.wMonth && st.wYear==stNow.wYear)
- return GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,pszOut,nSize) != 0;
+ if (!fShowDateEvenToday && st.wDay == stNow.wDay && st.wMonth == stNow.wMonth && st.wYear == stNow.wYear)
+ return GetTimeFormat(locale, ((st.wSecond == 0) ? TIME_NOSECONDS : 0) | TIME_FORCE24HOURFORMAT, &st, NULL, pszOut, nSize) != 0;
/* show both date and time */
- { TCHAR szDate[128],szTime[128];
- if (!GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,szTime,_countof(szTime)))
+ {
+ TCHAR szDate[128], szTime[128];
+ if (!GetTimeFormat(locale, ((st.wSecond == 0) ? TIME_NOSECONDS : 0) | TIME_FORCE24HOURFORMAT, &st, NULL, szTime, _countof(szTime)))
return FALSE;
- if (!GetDateFormat(locale,DATE_SHORTDATE,&st,NULL,szDate,_countof(szDate)))
+ if (!GetDateFormat(locale, DATE_SHORTDATE, &st, NULL, szDate, _countof(szDate)))
return FALSE;
- mir_sntprintf(pszOut,nSize,_T("%s %s"),szTime,szDate);
+ mir_sntprintf(pszOut, nSize, _T("%s %s"), szTime, szDate);
return TRUE;
}
}
@@ -206,7 +208,7 @@ BOOL GetFormatedDateTime(TCHAR *pszOut,int nSize,time_t timestamp,BOOL fShowDate
void AddHotkey()
{
- HOTKEYDESC hkd = {0};
+ HOTKEYDESC hkd = { 0 };
hkd.cbSize = sizeof(hkd);
hkd.dwFlags = HKD_TCHAR;
hkd.pszName = "AutoShutdown_Toggle";