POSIX fixes for native and crossplatform utils
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6427 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
859b5d3d07
commit
52a8b320ef
16 changed files with 66 additions and 46 deletions
|
@ -41,7 +41,8 @@ int GetTLBVersion(tstring& filepath, DWORD& high, DWORD & low)
|
|||
hr = LoadTypeLib(fullpath, &typeLib);
|
||||
#else
|
||||
// If built without UNICODE, we still need to convert this string to a Unicode string.
|
||||
WCHAR *ole_filename = wcsdup_fromTchar(fullpath, CP_ACP);
|
||||
WCHAR *ole_filename = WinWStrDupFromTChar(fullpath);
|
||||
if (!ole_filename) return 0;
|
||||
hr = LoadTypeLib(ole_filename, &typeLib);
|
||||
free(ole_filename);
|
||||
#endif
|
||||
|
|
|
@ -20,5 +20,5 @@ libs = Split("""
|
|||
|
||||
Import('BuildUtil')
|
||||
|
||||
BuildUtil(target, files, libs, res = res, resources = resources, entry = 'NSISWinMainNOCRT')
|
||||
BuildUtil(target, files, libs, res = res, resources = resources, entry = 'NSISWinMainNOCRT', nodeflib = True)
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include "resource.h"
|
||||
#include "toolbar.h"
|
||||
|
||||
#ifdef COUNTOF
|
||||
#undef COUNTOF
|
||||
#endif
|
||||
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
#define MRU_LIST_SIZE 5
|
||||
|
|
|
@ -672,7 +672,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
// Numeric inline
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // temp3 is set to 0 when we start parsing a new parameter
|
||||
#pragma GCC diagnostic ignored "-Wuninitialized" // temp3 is set to 0 when we start parsing a new parameter
|
||||
#endif
|
||||
if (temp3 == 0)
|
||||
#ifdef __GNUC__
|
||||
|
@ -748,7 +748,7 @@ SystemProc *PrepareProc(BOOL NeedForCall)
|
|||
// Next parameter is output or something else
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#pragma GCC diagnostic ignored "-Wuninitialized"
|
||||
#endif
|
||||
temp3++;
|
||||
#ifdef __GNUC__
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
# define terr cerr
|
||||
# define _T(x) x
|
||||
# define _tmain main
|
||||
# ifdef _WIN32
|
||||
# define _tunlink _unlink
|
||||
# else
|
||||
# define _tunlink unlink
|
||||
# endif
|
||||
# define FOPEN fopen
|
||||
|
||||
typedef std::string tstring;
|
||||
|
|
|
@ -135,12 +135,15 @@ plugin_uenv.Append(CPPDEFINES = ['_UNICODE', 'UNICODE'])
|
|||
|
||||
### cross-platform util environment
|
||||
|
||||
cp_util_env = tdefenv.Clone()
|
||||
if defenv['PLATFORM'] == 'win32':
|
||||
cp_util_env = tdefenv.Clone()
|
||||
else:
|
||||
cp_util_env = defenv.Clone()
|
||||
|
||||
cp_util_env.Append(CPPPATH = ['#$BUILD_CONFIG'])
|
||||
|
||||
if cp_util_env['PLATFORM'] == 'win32':
|
||||
cp_util_env.Append(LINKFLAGS = ['$ALIGN_FLAG'])
|
||||
cp_util_env.Append(LINKFLAGS = ['$ALIGN_FLAG']) # 512 bytes align
|
||||
|
||||
if not defenv['DEBUG']:
|
||||
cp_util_env.Append(CCFLAGS = ['-O2']) # optimize
|
||||
|
@ -153,9 +156,16 @@ conf.Finish()
|
|||
|
||||
### util environment
|
||||
|
||||
util_env = cp_util_env.Clone()
|
||||
util_env = tdefenv.Clone()
|
||||
cross_env(util_env)
|
||||
|
||||
util_env.Append(CPPPATH = ['#$BUILD_CONFIG'])
|
||||
|
||||
if not defenv['DEBUG']:
|
||||
util_env.Append(CCFLAGS = ['-O2']) # optimize
|
||||
util_env.Append(CCFLAGS = ['-Wall']) # all warnings
|
||||
util_env.Append(CCFLAGS = ['-fno-strict-aliasing']) # not safe for strict aliasing
|
||||
|
||||
util_env.Append(LINKFLAGS = ['-mwindows']) # build windows executables
|
||||
util_env.Append(LINKFLAGS = ['$ALIGN_FLAG']) # 512 bytes align
|
||||
|
||||
|
|
|
@ -728,10 +728,11 @@ def BuildUtilEnv(defines = None, flags = None, libs = None,
|
|||
libs.remove('z')
|
||||
AddZLib(env, platform)
|
||||
|
||||
if cli:
|
||||
env.Append(LINKFLAGS = env['SUBSYS_CON'])
|
||||
else:
|
||||
env.Append(LINKFLAGS = env['SUBSYS_WIN'])
|
||||
if platform == 'win32':
|
||||
if cli:
|
||||
env.Append(LINKFLAGS = env['SUBSYS_CON'])
|
||||
else:
|
||||
env.Append(LINKFLAGS = env['SUBSYS_WIN'])
|
||||
|
||||
AddEnvStandardFlags(env, defines, flags, libs, entry, nodeflib)
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
// some definitions for non Win32 platforms were taken from MinGW's free Win32 library
|
||||
|
||||
|
||||
#if defined(__cplusplus) && defined(MAKENSIS) && !defined(_MSC_VER)
|
||||
template<class T> class NSISCHARTYPE{ T _c; public: NSISCHARTYPE(){} NSISCHARTYPE(T c):_c(c){} operator T()const{ return _c; } operator int()const{ return (int) _c; } operator bool()const{ return _c != 0; } };
|
||||
#if defined(__cplusplus) && defined(MAKENSIS) && (!defined(_MSC_VER) || _MSC_VER > 1200)
|
||||
template<class T> class NSISCHARTYPE{ T _c; public: NSISCHARTYPE(){} NSISCHARTYPE(T c):_c(c){} operator T()const{ return _c; } };
|
||||
typedef NSISCHARTYPE<unsigned short> WINWCHAR; // WINWCHAR is always UTF16LE and should not be passed to wcs* functions
|
||||
#else
|
||||
typedef unsigned short WINWCHAR;
|
||||
|
|
|
@ -222,11 +222,10 @@ bool CResourceEditor::UpdateResourceW(const WINWCHAR* szType, WINWCHAR* szName,
|
|||
#ifndef _UNICODE
|
||||
static WINWCHAR* ResStringToUnicode(const char *szString) {
|
||||
if (IS_INTRESOURCE(szString)) return MAKEINTRESOURCEWINW((ULONG_PTR)szString);
|
||||
WINWCHAR *s = WinWStrDupFromTChar(szString, CP_ACP);
|
||||
WINWCHAR *s = WinWStrDupFromTChar(szString);
|
||||
if (!s) throw std::bad_alloc();
|
||||
return s;
|
||||
}
|
||||
|
||||
static void FreeUnicodeResString(WINWCHAR* szwString) {
|
||||
if (!IS_INTRESOURCE(szwString)) free(szwString);
|
||||
}
|
||||
|
|
|
@ -1109,7 +1109,7 @@ static INT_PTR CALLBACK DirProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
|
||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // available_set is checked first so available is initialized
|
||||
#pragma GCC diagnostic ignored "-Wuninitialized" // available_set is checked first so available is initialized
|
||||
#endif
|
||||
if (available_set && available < total)
|
||||
error = NSIS_INSTDIR_NOT_ENOUGH_SPACE;
|
||||
|
|
|
@ -183,10 +183,15 @@ typedef unsigned char _TUCHAR;
|
|||
|
||||
// string comparisons
|
||||
#define _tcscmp strcmp
|
||||
#define _tcsicmp _stricmp
|
||||
#define _tcsncmp strncmp
|
||||
#define _tcsncicmp _strnicmp
|
||||
#ifdef _WIN32
|
||||
#define _tcsicmp _stricmp
|
||||
#define _tcsnicmp _strnicmp
|
||||
#else
|
||||
#define _tcsicmp strcasecmp
|
||||
#define _tcsnicmp strncasecmp
|
||||
#endif
|
||||
|
||||
// upper / lower
|
||||
#define _tcslwr _strlwr
|
||||
|
|
|
@ -22,10 +22,7 @@
|
|||
|
||||
UINT StrLenUTF16(const void*str)
|
||||
{
|
||||
unsigned short *p = (unsigned short *) str;
|
||||
UINT cch = 0;
|
||||
for(;p[cch];) ++cch;
|
||||
return cch;
|
||||
return sizeof(wchar_t) == 2 ? wcslen((wchar_t*)str) : InlineStrLenUTF16(str);
|
||||
}
|
||||
|
||||
bool StrSetUTF16LE(tstring&dest, const void*src)
|
||||
|
|
|
@ -73,6 +73,14 @@ inline bool UTF8_GetTrailCount(unsigned char chFirst, unsigned char &cb)
|
|||
return true;
|
||||
}
|
||||
|
||||
inline UINT InlineStrLenUTF16(const void*str)
|
||||
{
|
||||
unsigned short *p = (unsigned short *) str;
|
||||
UINT cch = 0;
|
||||
for(;p[cch];) ++cch;
|
||||
return cch;
|
||||
}
|
||||
|
||||
#ifdef MAKENSIS
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -406,6 +406,7 @@ int _wstat(const wchar_t *Path, struct stat *pS)
|
|||
return retval;
|
||||
}
|
||||
|
||||
#ifdef _UNICODE
|
||||
static int NSISRT_wsystem(const wchar_t *wcmd)
|
||||
{
|
||||
if (!wcmd) return system(NULL);
|
||||
|
@ -416,6 +417,7 @@ static int NSISRT_wsystem(const wchar_t *wcmd)
|
|||
NSISRT_free(cmd);
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char* nsis_iconv_get_host_endian_ucs4_code()
|
||||
{
|
||||
|
@ -945,8 +947,9 @@ int sane_system(const TCHAR *command)
|
|||
#endif // ~_UNICODE
|
||||
#else // !_WIN32
|
||||
#ifndef _UNICODE
|
||||
PATH_CONVERT(command);
|
||||
return _tsystem(command);
|
||||
TCHAR* cmd = const_cast<TCHAR*>(command);
|
||||
PATH_CONVERT(cmd);
|
||||
return _tsystem(cmd);
|
||||
#else
|
||||
return NSISRT_wsystem(command);
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,11 @@ int WinWStrNICmpASCII(const WINWCHAR *a, const char *b, size_t n)
|
|||
#ifndef _WIN32
|
||||
size_t WinWStrLen(const WINWCHAR *s)
|
||||
{
|
||||
#ifdef MAKENSIS // Only makensis implements all the functions in utf.cpp
|
||||
return StrLenUTF16(s);
|
||||
#else
|
||||
return sizeof(wchar_t) == 2 ? wcslen((wchar_t*)str) : InlineStrLenUTF16(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
WINWCHAR* WinWStrCpy(WINWCHAR *d, const WINWCHAR *s)
|
||||
|
@ -84,9 +88,17 @@ WINWCHAR* WinWStrDupFromWinWStr(const WINWCHAR *s)
|
|||
|
||||
WINWCHAR* WinWStrDupFromTChar(const TCHAR *s)
|
||||
{
|
||||
#ifdef MAKENSIS
|
||||
WCToUTF16LEHlpr cnv;
|
||||
if (!cnv.Create(s)) throw runtime_error("Unicode conversion failed");
|
||||
return (WINWCHAR*) cnv.Detach();
|
||||
#else
|
||||
// NOTE: Anything outside the ASCII range will not convert correctly!
|
||||
size_t cch = strlen(s);
|
||||
WINWCHAR* p = (WINWCHAR*) malloc(++cch * 2);
|
||||
if (p) for (size_t i = 0; i < cch; ++i) p[i] = s[i];
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
|
||||
int WinWStrToInt(const WINWCHAR *s)
|
||||
|
@ -102,17 +114,3 @@ int WinWStrToInt(const WINWCHAR *s)
|
|||
return ((int)v) * sign;
|
||||
}
|
||||
#endif // ~!_WIN32
|
||||
|
||||
#if 0
|
||||
WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage/* = CP_ACP*/)
|
||||
{
|
||||
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
|
||||
if (l == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
|
||||
WCHAR *ws = new WCHAR[l + 1];
|
||||
if (MultiByteToWideChar(codepage, 0, s, -1, ws, l + 1) == 0)
|
||||
throw runtime_error("Unicode conversion failed");
|
||||
return ws;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -44,13 +44,4 @@ int WinWStrToInt(const WINWCHAR *s);
|
|||
inline WINWCHAR* WinWStrDupFromTChar(const TCHAR *s, unsigned int codepage) { return WinWStrDupFromTChar(s); }
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
WCHAR *wcsdup_fromansi(const char* s, unsigned int codepage = CP_ACP);
|
||||
#ifdef _UNICODE
|
||||
#define wcsdup_fromTchar(s, codepage) _wcsdup(s) // codepage is not used in this mode
|
||||
#else
|
||||
#define wcsdup_fromTchar(s, codepage) wcsdup_fromansi(s, codepage)
|
||||
#endif
|
||||
#endif
|
||||
#endif // ~INC_NSIS_WINCHAR
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue