_countof and swprintf fixes for VC6
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6045 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
34395604e8
commit
82d42b1159
13 changed files with 68 additions and 74 deletions
|
@ -2,6 +2,12 @@
|
|||
|
||||
#include "pluginapi.h"
|
||||
|
||||
#ifdef _countof
|
||||
#define COUNTOF _countof
|
||||
#else
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
unsigned int g_stringsize;
|
||||
stack_t **g_stacktop;
|
||||
TCHAR *g_variables;
|
||||
|
@ -267,7 +273,7 @@ int NSISCALL myatoi_or(const TCHAR *s)
|
|||
int NSISCALL popint()
|
||||
{
|
||||
TCHAR buf[128];
|
||||
if (popstringn(buf,_countof(buf)))
|
||||
if (popstringn(buf,COUNTOF(buf)))
|
||||
return 0;
|
||||
|
||||
return myatoi(buf);
|
||||
|
@ -276,7 +282,7 @@ int NSISCALL popint()
|
|||
int NSISCALL popint_or()
|
||||
{
|
||||
TCHAR buf[128];
|
||||
if (popstringn(buf,_countof(buf)))
|
||||
if (popstringn(buf,COUNTOF(buf)))
|
||||
return 0;
|
||||
|
||||
return myatoi_or(buf);
|
||||
|
|
|
@ -18,15 +18,10 @@
|
|||
|
||||
#include <nsis/pluginapi.h> // nsis plugin
|
||||
|
||||
#ifndef _countof
|
||||
#ifndef __cplusplus
|
||||
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
|
||||
#ifdef _countof
|
||||
#define COUNTOF _countof
|
||||
#else
|
||||
extern "C++" {
|
||||
template <typename _CountofType,size_t _SizeOfArray> char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
|
||||
#define _countof(_Array) sizeof(*__countof_helper(_Array))
|
||||
}
|
||||
#endif
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
// Use for functions only called from one place to possibly reduce some code
|
||||
|
@ -251,7 +246,7 @@ bool INLINE ValidateFields() {
|
|||
((pField->nMinLength > 0) && (nLength < pField->nMinLength))) {
|
||||
if (pField->pszValidateText) {
|
||||
TCHAR szTitle[1024];
|
||||
GetWindowText(hMainWindow, szTitle, _countof(szTitle));
|
||||
GetWindowText(hMainWindow, szTitle, COUNTOF(szTitle));
|
||||
MessageBox(hConfigWindow, pField->pszValidateText, szTitle, MB_OK|MB_ICONWARNING);
|
||||
}
|
||||
mySetFocus(pField->hwnd);
|
||||
|
@ -543,7 +538,7 @@ int WINAPI ReadSettings(void) {
|
|||
ConvertNewLines(pField->pszValidateText);
|
||||
|
||||
{
|
||||
int nResult = GetPrivateProfileString(szField, _T("Filter"), _T("All Files|*.*"), szResult, _countof(szResult), pszFilename);
|
||||
int nResult = GetPrivateProfileString(szField, _T("Filter"), _T("All Files|*.*"), szResult, COUNTOF(szResult), pszFilename);
|
||||
if (nResult) {
|
||||
// Convert the filter to the format required by Windows: NULL after each
|
||||
// item followed by a terminating NULL
|
||||
|
@ -631,10 +626,10 @@ LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify)
|
|||
ofn.hwndOwner = hConfigWindow;
|
||||
ofn.lpstrFilter = pField->pszFilter;
|
||||
ofn.lpstrFile = szBrowsePath;
|
||||
ofn.nMaxFile = _countof(szBrowsePath);
|
||||
ofn.nMaxFile = COUNTOF(szBrowsePath);
|
||||
ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);
|
||||
|
||||
GetWindowText(pField->hwnd, szBrowsePath, _countof(szBrowsePath));
|
||||
GetWindowText(pField->hwnd, szBrowsePath, COUNTOF(szBrowsePath));
|
||||
|
||||
tryagain:
|
||||
GetCurrentDirectory(BUFFER_SIZE, szResult); // save working dir
|
||||
|
@ -1121,7 +1116,7 @@ int WINAPI createCfgDlg()
|
|||
|
||||
#undef DEFAULT_STYLES
|
||||
|
||||
if (pField->nType < 1 || pField->nType > (int)(_countof(ClassTable)))
|
||||
if (pField->nType < 1 || pField->nType > (int)(COUNTOF(ClassTable)))
|
||||
continue;
|
||||
|
||||
DWORD dwStyle, dwExStyle;
|
||||
|
|
|
@ -27,22 +27,17 @@ int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low)
|
|||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef _countof
|
||||
#ifndef __cplusplus
|
||||
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
|
||||
#ifdef _countof
|
||||
#define COUNTOF _countof
|
||||
#else
|
||||
extern "C++" {
|
||||
template <typename _CountofType,size_t _SizeOfArray> char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
|
||||
#define _countof(_Array) sizeof(*__countof_helper(_Array))
|
||||
}
|
||||
#endif
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
int found = 0;
|
||||
|
||||
TCHAR fullpath[1024];
|
||||
TCHAR *p;
|
||||
if (!GetFullPathName(filepath.c_str(), _countof(fullpath), fullpath, &p))
|
||||
if (!GetFullPathName(filepath.c_str(), COUNTOF(fullpath), fullpath, &p))
|
||||
return 0;
|
||||
|
||||
ITypeLib* typeLib;
|
||||
|
|
|
@ -139,14 +139,14 @@ void UpdateToolBarCompressorButton()
|
|||
LoadString(g_sdata.hInstance,
|
||||
IDS_COMPRESSOR,
|
||||
temp,
|
||||
_countof(temp));
|
||||
COUNTOF(temp));
|
||||
my_memset(szBuffer, 0, sizeof(szBuffer));
|
||||
lstrcat(szBuffer,temp);
|
||||
lstrcat(szBuffer,_T(" ["));
|
||||
LoadString(g_sdata.hInstance,
|
||||
iString,
|
||||
temp,
|
||||
_countof(temp));
|
||||
COUNTOF(temp));
|
||||
lstrcat(szBuffer,temp);
|
||||
lstrcat(szBuffer,_T("]"));
|
||||
|
||||
|
@ -181,7 +181,7 @@ void AddToolBarButtonTooltip(int id, int iString)
|
|||
LoadString(g_sdata.hInstance,
|
||||
iString,
|
||||
szBuffer,
|
||||
_countof(szBuffer));
|
||||
COUNTOF(szBuffer));
|
||||
ti.lpszText = (LPTSTR) szBuffer;
|
||||
ti.rect.left =rect.left;
|
||||
ti.rect.top = rect.top;
|
||||
|
|
|
@ -27,15 +27,10 @@
|
|||
#include "toolbar.h"
|
||||
#include "noclib.h"
|
||||
|
||||
#ifndef _countof
|
||||
#ifndef __cplusplus
|
||||
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
|
||||
#ifdef _countof
|
||||
#define COUNTOF _countof
|
||||
#else
|
||||
extern "C++" {
|
||||
template <typename _CountofType,size_t _SizeOfArray> char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
|
||||
#define _countof(_Array) sizeof(*__countof_helper(_Array))
|
||||
}
|
||||
#endif
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
NTOOLTIP g_tip;
|
||||
|
@ -305,7 +300,7 @@ void CompileNSISScript() {
|
|||
/* script cmd args */ lstrlen(args) + /* space */ 1 +
|
||||
/* defines /Dblah=... */ lstrlen(symbols) + /* space */ 1 +
|
||||
/* /XSetCompressor... */ lstrlen(compressor) + /* space */ 1 +
|
||||
/* /NOTTIFYHWND + HWND */ _countof(_T("/NOTIFYHWND -4294967295")) + /* space */ 1
|
||||
/* /NOTTIFYHWND + HWND */ COUNTOF(_T("/NOTIFYHWND -4294967295")) + /* space */ 1
|
||||
+6); /* for -- \"\" and NULL */
|
||||
|
||||
g_sdata.compile_command = (TCHAR *) GlobalAlloc(GPTR, byteSize);
|
||||
|
@ -755,7 +750,7 @@ void PushMRUFile(TCHAR* fname)
|
|||
}
|
||||
|
||||
my_memset(full_file_name,0,sizeof(full_file_name));
|
||||
rv = GetFullPathName(fname,_countof(full_file_name),full_file_name,NULL);
|
||||
rv = GetFullPathName(fname,COUNTOF(full_file_name),full_file_name,NULL);
|
||||
if (rv == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ TCHAR *GetResultStr(SystemProc *proc)
|
|||
#ifdef SYSTEM_LOG_DEBUG
|
||||
|
||||
// System log debugging turned on
|
||||
#define SYSTEM_LOG_ADD(a) { register int _len = lstrlen(syslogbuf); lstrcpyn(syslogbuf + _len, a, _countof(syslogbuf) - _len); }
|
||||
#define SYSTEM_LOG_ADD(a) { register int _len = lstrlen(syslogbuf); lstrcpyn(syslogbuf + _len, a, COUNTOF(syslogbuf) - _len); }
|
||||
#define SYSTEM_LOG_POST { SYSTEM_LOG_ADD(_T("\n")); WriteToLog(syslogbuf); *syslogbuf = 0; }
|
||||
|
||||
HANDLE logfile = NULL;
|
||||
|
|
|
@ -8,15 +8,10 @@
|
|||
|
||||
#include "defs.h"
|
||||
|
||||
#ifndef _countof
|
||||
#ifndef __cplusplus
|
||||
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
|
||||
#ifdef _countof
|
||||
#define COUNTOF _countof
|
||||
#else
|
||||
extern "C++" {
|
||||
template <typename _CountofType,size_t _SizeOfArray> char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
|
||||
#define _countof(_Array) sizeof(*__countof_helper(_Array))
|
||||
}
|
||||
#endif
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) {
|
||||
|
@ -37,13 +32,13 @@ void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size,
|
|||
|
||||
EXDLL_INIT();
|
||||
|
||||
if (popstringn(title, _countof(initial)))
|
||||
if (popstringn(title, COUNTOF(initial)))
|
||||
{
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (popstringn(initial, _countof(title)))
|
||||
if (popstringn(initial, COUNTOF(title)))
|
||||
{
|
||||
pushstring(_T("error"));
|
||||
return;
|
||||
|
|
|
@ -4,15 +4,10 @@
|
|||
#include <ctype.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
#ifndef _countof
|
||||
#ifndef __cplusplus
|
||||
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
|
||||
#ifdef _countof
|
||||
#define COUNTOF _countof
|
||||
#else
|
||||
extern "C++" {
|
||||
template <typename _CountofType,size_t _SizeOfArray> char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
|
||||
#define _countof(_Array) sizeof(*__countof_helper(_Array))
|
||||
}
|
||||
#endif
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -751,7 +746,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_HIDE);
|
||||
{
|
||||
for (size_t x = 0; x < _countof(ids); x ++)
|
||||
for (size_t x = 0; x < COUNTOF(ids); x ++)
|
||||
ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_SHOWNA);
|
||||
SetDlgItemText(hwndDlg,IDOK,_T("&Generate"));
|
||||
EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
|
||||
|
@ -761,7 +756,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
case IDC_TEST:
|
||||
if (!g_hThread) {
|
||||
TCHAR buf[1024];
|
||||
GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,_countof(buf));
|
||||
GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,COUNTOF(buf));
|
||||
ShellExecute(hwndDlg,_T("open"),buf,_T(""),_T(""),SW_SHOW);
|
||||
}
|
||||
break;
|
||||
|
@ -782,7 +777,7 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
g_compressor_solid = 0;
|
||||
g_mui=!IsDlgButtonChecked(hwndDlg,IDC_CLASSICUI);
|
||||
SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, _T(""));
|
||||
for (size_t x = 0; x < _countof(ids); x ++)
|
||||
for (size_t x = 0; x < COUNTOF(ids); x ++)
|
||||
ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_SHOWNA);
|
||||
SetDlgItemText(hwndDlg,IDOK,_T("&Close"));
|
||||
|
|
|
@ -107,6 +107,14 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG;
|
|||
#define _vsnprintf vsnprintf
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef _countof
|
||||
#define COUNTOF _countof
|
||||
#else
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
#endif
|
||||
|
||||
#ifndef __BIG_ENDIAN__
|
||||
# define FIX_ENDIAN_INT32_INPLACE(x) ((void)(x))
|
||||
# define FIX_ENDIAN_INT32(x) (x)
|
||||
|
@ -203,6 +211,11 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG;
|
|||
|
||||
// functions
|
||||
|
||||
// Anders: MSVC's swprintf is non standard, use _snwprintf when you really mean swprintf
|
||||
#if !defined(_MSC_VER) && !defined(_snwprintf)
|
||||
#define _snwprintf swprintf
|
||||
#endif
|
||||
|
||||
// Jim Park: These str functions will probably never be encountered with all my
|
||||
// Unicode changes. And if they were used, these would probably be wrong.
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -210,7 +210,7 @@ void CResourceVersionInfo::ExportToStream(GrowBuf &strm, int Index)
|
|||
int codepage = m_ChildStringLists.get_codepage(Index);
|
||||
LANGID langid = m_ChildStringLists.get_lang(Index);
|
||||
WCHAR Buff[16];
|
||||
swprintf(Buff, _countof(Buff), L"%04x%04x", langid, codepage);
|
||||
_snwprintf(Buff, COUNTOF(Buff), L"%04x%04x", langid, codepage);
|
||||
SaveVersionHeader (stringInfoStream, 0, 0, 0, Buff, &ZEROS);
|
||||
|
||||
for ( int i = 0; i < pChildStrings->getnum(); i++ )
|
||||
|
|
|
@ -199,7 +199,7 @@ int CLZMA::Init(int level, unsigned int dicSize)
|
|||
NCoderPropID::kDictionarySize,
|
||||
NCoderPropID::kNumFastBytes
|
||||
};
|
||||
const int kNumProps = _countof(propdIDs);
|
||||
const int kNumProps = COUNTOF(propdIDs);
|
||||
PROPVARIANT props[kNumProps];
|
||||
// NCoderPropID::kAlgorithm
|
||||
props[0].vt = VT_UI4;
|
||||
|
|
|
@ -651,7 +651,7 @@ TCHAR * NSISCALL GetNSISString(TCHAR *outbuf, int strtab)
|
|||
// Still working within ps_tmpbuf, so set out to the
|
||||
// current position that is passed in.
|
||||
if (outbuf >= ps_tmpbuf &&
|
||||
(size_t) (outbuf - ps_tmpbuf) < _countof(ps_tmpbuf))
|
||||
(size_t) (outbuf - ps_tmpbuf) < COUNTOF(ps_tmpbuf))
|
||||
{
|
||||
out = outbuf;
|
||||
outbuf = 0;
|
||||
|
|
|
@ -105,8 +105,8 @@ TCHAR *CEXEBuild::set_timestamp_predefine(const TCHAR *filename)
|
|||
FileTimeToLocalFileTime(&fd.ftLastWriteTime, &floctime);
|
||||
FileTimeToSystemTime(&floctime, &stime);
|
||||
|
||||
GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stime, NULL, datebuf, _countof(datebuf));
|
||||
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, _countof(timebuf));
|
||||
GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &stime, NULL, datebuf, COUNTOF(datebuf));
|
||||
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, COUNTOF(timebuf));
|
||||
wsprintf(timestampbuf,_T("%s %s"),datebuf,timebuf);
|
||||
|
||||
definedlist.add(_T("__TIMESTAMP__"),timestampbuf);
|
||||
|
@ -2651,7 +2651,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
}
|
||||
else
|
||||
{
|
||||
_tcsnccpy(build_font, line.gettoken_str(1), _countof(build_font));
|
||||
_tcsnccpy(build_font, line.gettoken_str(1), COUNTOF(build_font));
|
||||
build_font_size = line.gettoken_int(2);
|
||||
|
||||
SCRIPT_MSG(_T("SetFont: \"%s\" %s\n"), line.gettoken_str(1), line.gettoken_str(2));
|
||||
|
@ -2820,12 +2820,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
rawtime = mktime(gmtime(&rawtime));
|
||||
|
||||
datebuf[0]=0;
|
||||
size_t s=_tcsftime(datebuf,_countof(datebuf),value,localtime(&rawtime));
|
||||
size_t s=_tcsftime(datebuf,COUNTOF(datebuf),value,localtime(&rawtime));
|
||||
|
||||
if (s == 0)
|
||||
datebuf[0]=0;
|
||||
else
|
||||
datebuf[max(s,_countof(datebuf)-1)]=0;
|
||||
datebuf[max(s,COUNTOF(datebuf)-1)]=0;
|
||||
|
||||
value=datebuf;
|
||||
} else if (!_tcsicmp(define,_T("/file")) || !_tcsicmp(define,_T("/file_noerr"))) {
|
||||
|
@ -2925,8 +2925,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
SCRIPT_MSG(_T("!undef: \"%s\"\n"),line.gettoken_str(1));
|
||||
return PS_OK;
|
||||
case TOK_P_PACKEXEHEADER:
|
||||
_tcsnccpy(build_packname,line.gettoken_str(1),_countof(build_packname)-1);
|
||||
_tcsnccpy(build_packcmd,line.gettoken_str(2),_countof(build_packcmd)-1);
|
||||
_tcsnccpy(build_packname,line.gettoken_str(1),COUNTOF(build_packname)-1);
|
||||
_tcsnccpy(build_packcmd,line.gettoken_str(2),COUNTOF(build_packcmd)-1);
|
||||
SCRIPT_MSG(_T("!packhdr: filename=\"%s\", command=\"%s\"\n"),
|
||||
build_packname, build_packcmd);
|
||||
return PS_OK;
|
||||
|
@ -3139,7 +3139,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
for (;;)
|
||||
{
|
||||
str[0]=0;
|
||||
_fgetts(str,_countof(str),fp);
|
||||
_fgetts(str,COUNTOF(str),fp);
|
||||
if (!str[0]) break; // eof
|
||||
|
||||
TCHAR *p=str;
|
||||
|
@ -4059,8 +4059,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
TCHAR *np=p;
|
||||
while (*np && *np != _T('|')) np++;
|
||||
if (*np) *np++=0;
|
||||
for (x = 0 ; (unsigned) x < _countof(list) && _tcsicmp(list[x].str, p); x++);
|
||||
if ((unsigned) x < _countof(list))
|
||||
for (x = 0 ; (unsigned) x < COUNTOF(list) && _tcsicmp(list[x].str, p); x++);
|
||||
if ((unsigned) x < COUNTOF(list))
|
||||
{
|
||||
r|=list[x].id;
|
||||
}
|
||||
|
@ -4729,9 +4729,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
|
|||
TCHAR *np=p;
|
||||
while (*np && *np != _T('|')) np++;
|
||||
if (*np) *np++=0;
|
||||
for (x = 0 ; (unsigned) x < _countof(list) && _tcsicmp(list[x].str,p); x ++);
|
||||
for (x = 0 ; (unsigned) x < COUNTOF(list) && _tcsicmp(list[x].str,p); x ++);
|
||||
|
||||
if ((unsigned) x < _countof(list))
|
||||
if ((unsigned) x < COUNTOF(list))
|
||||
{
|
||||
r|=list[x].id;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue