summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2018-03-31 20:38:17 +0200
committerDidier Raboud <odyx@debian.org>2018-03-31 20:38:17 +0200
commit13406335997bbe6a887c9b30dcd58df39b83b44e (patch)
tree479febfebc136d9a9284f9e91f2f00a65faa7121 /Source
parentb7b6fd51060345030a52744d34c570b30533b02e (diff)
Import Upstream version 2.30
Diffstat (limited to 'Source')
-rwxr-xr-xSource/Platform.h1
-rwxr-xr-xSource/ResourceEditor.cpp36
-rwxr-xr-xSource/ResourceEditor.h4
-rwxr-xr-xSource/SConscript1
-rwxr-xr-xSource/Tests/winchar.cpp21
-rwxr-xr-xSource/build.cpp51
-rwxr-xr-xSource/build.h4
-rwxr-xr-xSource/exehead/exec.c2
-rwxr-xr-xSource/exehead/util.c33
-rwxr-xr-xSource/lang.cpp8
-rwxr-xr-xSource/makenssi.cpp16
-rwxr-xr-xSource/script.cpp9
-rwxr-xr-xSource/strlist.cpp2
-rwxr-xr-xSource/strlist.h2
-rwxr-xr-xSource/util.cpp63
-rwxr-xr-xSource/util.h2
16 files changed, 142 insertions, 113 deletions
diff --git a/Source/Platform.h b/Source/Platform.h
index 5cb146b..28d7209 100755
--- a/Source/Platform.h
+++ b/Source/Platform.h
@@ -55,6 +55,7 @@ typedef const unsigned short *LPCWCH, *PCWCH, *LPCWSTR, *PCWSTR, *LPCOLESTR;
typedef unsigned int UINT_PTR;
// basic stuff
typedef void * HANDLE;
+typedef HANDLE HWND;
typedef unsigned long HKEY;
// some gdi
typedef unsigned long COLORREF;
diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp
index c43008d..0c42202 100755
--- a/Source/ResourceEditor.cpp
+++ b/Source/ResourceEditor.cpp
@@ -547,16 +547,16 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P
for (int i = 0; i < entries; i++) {
MY_IMAGE_RESOURCE_DIRECTORY_ENTRY rd = rdToScan->Entries[i];
- rd.OffsetToData = ConvertEndianness(rd.OffsetToData);
- rd.Name = ConvertEndianness(rd.Name);
+ rd.UOffset.OffsetToData = ConvertEndianness(rd.UOffset.OffsetToData);
+ rd.UName.Name = ConvertEndianness(rd.UName.Name);
// If this entry points to data entry get a pointer to it
- if (!rd.DirectoryOffset.DataIsDirectory)
- rde = PIMAGE_RESOURCE_DATA_ENTRY(rd.OffsetToData + (BYTE*)rdRoot);
+ if (!rd.UOffset.DirectoryOffset.DataIsDirectory)
+ rde = PIMAGE_RESOURCE_DATA_ENTRY(rd.UOffset.OffsetToData + (BYTE*)rdRoot);
// If this entry has a name, translate it from Unicode
- if (rd.NameString.NameIsString) {
- PIMAGE_RESOURCE_DIR_STRING_U rds = PIMAGE_RESOURCE_DIR_STRING_U(rd.NameString.NameOffset + (char*)rdRoot);
+ if (rd.UName.NameString.NameIsString) {
+ PIMAGE_RESOURCE_DIR_STRING_U rds = PIMAGE_RESOURCE_DIR_STRING_U(rd.UName.NameString.NameOffset + (char*)rdRoot);
size_t nameSize = ConvertEndianness(rds->Length);
szName = new WCHAR[nameSize+1];
@@ -565,15 +565,15 @@ CResourceDirectory* CResourceEditor::ScanDirectory(PRESOURCE_DIRECTORY rdRoot, P
}
// Else, set the name to this entry's id
else
- szName = MAKEINTRESOURCEW(ConvertEndianness(rdToScan->Entries[i].Id));
+ szName = MAKEINTRESOURCEW(ConvertEndianness(rdToScan->Entries[i].UName.Id));
- if (rd.DirectoryOffset.DataIsDirectory)
+ if (rd.UOffset.DirectoryOffset.DataIsDirectory)
rdc->AddEntry(
new CResourceDirectoryEntry(
szName,
ScanDirectory(
rdRoot,
- PRESOURCE_DIRECTORY(rd.DirectoryOffset.OffsetToDirectory + (BYTE*)rdRoot)
+ PRESOURCE_DIRECTORY(rd.UOffset.DirectoryOffset.OffsetToDirectory + (BYTE*)rdRoot)
)
)
);
@@ -632,10 +632,10 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
MY_IMAGE_RESOURCE_DIRECTORY_ENTRY rDirE;
ZeroMemory(&rDirE, sizeof(rDirE));
- rDirE.DirectoryOffset.DataIsDirectory = crd->GetEntry(i)->IsDataDirectory();
- rDirE.Id = crd->GetEntry(i)->HasName() ? 0 : crd->GetEntry(i)->GetId();
- rDirE.Id = ConvertEndianness(rDirE.Id);
- rDirE.NameString.NameIsString = (crd->GetEntry(i)->HasName()) ? 1 : 0;
+ rDirE.UOffset.DirectoryOffset.DataIsDirectory = crd->GetEntry(i)->IsDataDirectory();
+ rDirE.UName.Id = crd->GetEntry(i)->HasName() ? 0 : crd->GetEntry(i)->GetId();
+ rDirE.UName.Id = ConvertEndianness(rDirE.UName.Id);
+ rDirE.UName.NameString.NameIsString = (crd->GetEntry(i)->HasName()) ? 1 : 0;
CopyMemory(seeker, &rDirE, sizeof(MY_IMAGE_RESOURCE_DIRECTORY_ENTRY));
crd->GetEntry(i)->m_dwWrittenAt = DWORD(seeker);
@@ -666,7 +666,7 @@ void CResourceEditor::WriteRsrcSec(BYTE* pbRsrcSec) {
while (!qStrings.empty()) {
CResourceDirectoryEntry* cRDirE = qStrings.front();
- PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_dwWrittenAt)->NameString.NameOffset = ConvertEndianness(DWORD(seeker) - DWORD(pbRsrcSec));
+ PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(cRDirE->m_dwWrittenAt)->UName.NameString.NameOffset = ConvertEndianness(DWORD(seeker) - DWORD(pbRsrcSec));
WCHAR* szName = cRDirE->GetName();
WORD iLen = winchar_strlen(szName) + 1;
@@ -705,13 +705,13 @@ void CResourceEditor::SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt)
for (int i = 0; i < resDir->CountEntries(); i++) {
PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY rde = PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY(resDir->GetEntry(i)->m_dwWrittenAt);
if (resDir->GetEntry(i)->IsDataDirectory()) {
- rde->DirectoryOffset.DataIsDirectory = 1;
- rde->DirectoryOffset.OffsetToDirectory = resDir->GetEntry(i)->GetSubDirectory()->m_dwWrittenAt - newResDirAt;
- rde->OffsetToData = ConvertEndianness(rde->OffsetToData);
+ rde->UOffset.DirectoryOffset.DataIsDirectory = 1;
+ rde->UOffset.DirectoryOffset.OffsetToDirectory = resDir->GetEntry(i)->GetSubDirectory()->m_dwWrittenAt - newResDirAt;
+ rde->UOffset.OffsetToData = ConvertEndianness(rde->UOffset.OffsetToData);
SetOffsets(resDir->GetEntry(i)->GetSubDirectory(), newResDirAt);
}
else {
- rde->OffsetToData = ConvertEndianness(resDir->GetEntry(i)->GetDataEntry()->m_dwWrittenAt - newResDirAt);
+ rde->UOffset.OffsetToData = ConvertEndianness(resDir->GetEntry(i)->GetDataEntry()->m_dwWrittenAt - newResDirAt);
}
}
}
diff --git a/Source/ResourceEditor.h b/Source/ResourceEditor.h
index d03ba07..eb542c8 100755
--- a/Source/ResourceEditor.h
+++ b/Source/ResourceEditor.h
@@ -72,7 +72,7 @@ typedef struct _MY_IMAGE_RESOURCE_DIRECTORY_ENTRY {
} NameString;
DWORD Name;
WORD Id;
- };
+ } UName;
union {
DWORD OffsetToData;
struct {
@@ -84,7 +84,7 @@ typedef struct _MY_IMAGE_RESOURCE_DIRECTORY_ENTRY {
DWORD OffsetToDirectory:31;
#endif
} DirectoryOffset;
- };
+ } UOffset;
} MY_IMAGE_RESOURCE_DIRECTORY_ENTRY,*PMY_IMAGE_RESOURCE_DIRECTORY_ENTRY;
#pragma pack()
diff --git a/Source/SConscript b/Source/SConscript
index 3759f4d..5215c89 100755
--- a/Source/SConscript
+++ b/Source/SConscript
@@ -54,7 +54,6 @@ libs = Split("""
gdi32
user32
pthread
- stdc++
iconv
""")
diff --git a/Source/Tests/winchar.cpp b/Source/Tests/winchar.cpp
index d25ebb2..99934a9 100755
--- a/Source/Tests/winchar.cpp
+++ b/Source/Tests/winchar.cpp
@@ -4,6 +4,9 @@
#include <time.h>
#include <stdlib.h>
+// macro for fixing endianity
+#define _x(x) FIX_ENDIAN_INT16(WCHAR(x))
+
class WinCharTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( WinCharTest );
@@ -19,7 +22,7 @@ class WinCharTest : public CppUnit::TestFixture {
public:
void testFromAnsi() {
- WCHAR test[] = { 't', 'e', 's', 't', 0 };
+ WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR *dyn = winchar_fromansi("test");
CPPUNIT_ASSERT_EQUAL( 0, memcmp(test, dyn, 5) );
@@ -28,7 +31,7 @@ public:
}
void testToAnsi() {
- WCHAR test[] = { 't', 'e', 's', 't', 0 };
+ WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
char *dyn = winchar_toansi(test);
CPPUNIT_ASSERT_EQUAL( 0, strcmp("test", dyn) );
@@ -37,7 +40,7 @@ public:
}
void testStrCpy() {
- WCHAR a[] = { 't', 'e', 's', 't', 0 };
+ WCHAR a[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR b[5];
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strcpy(b, a) );
@@ -45,13 +48,13 @@ public:
}
void testStrNCpy() {
- WCHAR a1[] = { 't', 'e', 's', 't', 0 };
+ WCHAR a1[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
WCHAR b[5];
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a1, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a1, b, 5 * sizeof(WCHAR)) );
- WCHAR a2[] = { 't', 'e', 0, 0, 0 };
+ WCHAR a2[] = { _x('t'), _x('e'), 0, 0, 0 };
CPPUNIT_ASSERT_EQUAL( (WCHAR*) b, (WCHAR*) winchar_strncpy(b, a2, 5) );
CPPUNIT_ASSERT_EQUAL( 0, memcmp(a2, b, 5 * sizeof(WCHAR)) );
@@ -61,7 +64,7 @@ public:
}
void testStrLen() {
- WCHAR test[] = { 't', 'e', 's', 't', 0 };
+ WCHAR test[] = { _x('t'), _x('e'), _x('s'), _x('t'), 0 };
CPPUNIT_ASSERT_EQUAL( (size_t) 4, winchar_strlen(test) );
}
@@ -76,9 +79,9 @@ public:
void testStrCmp() {
char a[] = "a";
- WCHAR wa[] = { 'a', 0 };
+ WCHAR wa[] = { _x('a'), 0 };
char b[] = "b";
- WCHAR wb[] = { 'b', 0 };
+ WCHAR wb[] = { _x('b'), 0 };
char empty[] = "";
WCHAR wempty[] = { 0 };
@@ -98,7 +101,7 @@ public:
}
void testStrDup() {
- WCHAR a[] = { 'a', 'b', 'c', 0 };
+ WCHAR a[] = { _x('a'), _x('b'), _x('c'), 0 };
WCHAR *b = winchar_strdup(a);
diff --git a/Source/build.cpp b/Source/build.cpp
index 7994b96..a335c08 100755
--- a/Source/build.cpp
+++ b/Source/build.cpp
@@ -253,9 +253,7 @@ CEXEBuild::CEXEBuild() :
disable_window_icon=0;
-#ifdef _WIN32
notify_hwnd=0;
-#endif
#ifdef NSIS_SUPPORT_BGBG
bg_default_font.lfHeight=40;
@@ -451,12 +449,8 @@ int CEXEBuild::add_string(const char *string, int process/*=1*/, WORD codepage/*
int CEXEBuild::add_intstring(const int i) // returns offset in stringblock
{
- char i_str[128];
-#ifdef _WIN32
+ char i_str[1024];
wsprintf(i_str, "%d", i);
-#else
- snprintf(i_str, 128, "%d", i);
-#endif
return add_string(i_str);
}
@@ -466,22 +460,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
const char *p=in;
while (*p)
{
- const char *np;
-#ifdef _WIN32
- np = CharNextExA(codepage, p, 0);
-#else
- {
- char buf[1024];
- snprintf(buf, 1024, "CP%d", codepage);
- setlocale(LC_CTYPE, buf);
- int len = mblen(p, strlen(p));
- if (len > 0)
- np = p + len;
- else
- np = p + 1;
- setlocale(LC_CTYPE, "");
- }
-#endif
+ const char *np = CharNextExA(codepage, p, 0);
if (np - p > 1) // multibyte char
{
int l = np - p;
@@ -531,7 +510,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
// which is also memory wasting
// So the line below must be commented !??
//m_UserVarNames.inc_reference(idxUserVar);
- *out++ = (unsigned int) NS_VAR_CODE; // Named user variable;
+ *out++ = (char) NS_VAR_CODE; // Named user variable;
WORD w = FIX_ENDIAN_INT16(CODE_SHORT(idxUserVar));
memcpy(out, &w, sizeof(WORD));
out += sizeof(WORD);
@@ -555,7 +534,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
{
int CSIDL_Value_current = m_ShellConstants.get_value1(idxConst);
int CSIDL_Value_all = m_ShellConstants.get_value2(idxConst);
- *out++=(unsigned int)NS_SHELL_CODE; // Constant code identifier
+ *out++=(char)NS_SHELL_CODE; // Constant code identifier
*out++=(char)CSIDL_Value_current;
*out++=(char)CSIDL_Value_all;
p = pShellConstName;
@@ -576,7 +555,7 @@ int CEXEBuild::preprocess_string(char *out, const char *in, WORD codepage/*=CP_A
idx = DefineLangString(cp);
if (idx < 0)
{
- *out++ = (unsigned int)NS_LANG_CODE; // Next word is lang-string Identifier
+ *out++ = (char)NS_LANG_CODE; // Next word is lang-string Identifier
WORD w = FIX_ENDIAN_INT16(CODE_SHORT(-idx-1));
memcpy(out, &w, sizeof(WORD));
out += sizeof(WORD);
@@ -1166,12 +1145,8 @@ int CEXEBuild::add_section(const char *secname, const char *defname, int expand/
if (defname[0])
{
- char buf[128];
-#ifdef _WIN32
+ char buf[1024];
wsprintf(buf, "%d", cur_header->blocks[NB_SECTIONS].num);
-#else
- snprintf(buf, 128, "%d", cur_header->blocks[NB_SECTIONS].num);
-#endif
if (definedlist.add(defname, buf))
{
ERROR_MSG("Error: \"%s\" already defined, can't assign section index!\n", defname);
@@ -2603,11 +2578,7 @@ int CEXEBuild::write_output(void)
{
int total_out_size_estimate=
m_exehead_size+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(crc32_t):0);
-#ifdef _WIN32
- int pc=MulDiv(db_opt_save,1000,db_opt_save+total_out_size_estimate);
-#else
- int pc=(int)(((long long)db_opt_save*1000)/(db_opt_save+total_out_size_estimate));
-#endif
+ int pc=(int)(((INT64)db_opt_save*1000)/(db_opt_save+total_out_size_estimate));
INFO_MSG("Datablock optimizer saved %d bytes (~%d.%d%%).\n",db_opt_save,
pc/10,pc%10);
}
@@ -3133,11 +3104,7 @@ void CEXEBuild::warning_fl(const char *s, ...)
void CEXEBuild::ERROR_MSG(const char *s, ...) const
{
-#ifdef _WIN32
if (display_errors || notify_hwnd)
-#else
- if (display_errors)
-#endif
{
char buf[NSIS_MAX_STRLEN*10];
va_list val;
@@ -3196,16 +3163,16 @@ void CEXEBuild::print_warnings()
fflush(g_output);
}
-#ifdef _WIN32
void CEXEBuild::notify(notify_e code, const char *data) const
{
+#ifdef _WIN32
if (notify_hwnd)
{
COPYDATASTRUCT cds = {(DWORD)code, strlen(data)+1, (void *) data};
SendMessage(notify_hwnd, WM_COPYDATA, 0, (LPARAM)&cds);
}
-}
#endif
+}
// Added by Ximon Eighteen 5th August 2002
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
diff --git a/Source/build.h b/Source/build.h
index 6164439..6c41a45 100755
--- a/Source/build.h
+++ b/Source/build.h
@@ -123,12 +123,8 @@ class CEXEBuild {
char *curfilename;
FILE *fp;
-#ifdef _WIN32
HWND notify_hwnd;
void notify(notify_e code, const char *data) const;
-#else
- void notify(notify_e code, const char *data) const { }
-#endif
private:
int check_write_output_errors() const;
diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c
index aa0186e..d4adab4 100755
--- a/Source/exehead/exec.c
+++ b/Source/exehead/exec.c
@@ -335,10 +335,12 @@ static int NSISCALL ExecuteEntry(entry *entry_)
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
{
+ log_printf3("CreateDirectory: can't create \"%s\" (err=%d)",buf1,GetLastError());
exec_error++;
}
else if ((GetFileAttributes(buf1) & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
+ log_printf2("CreateDirectory: can't create \"%s\" - a file already exists",buf1);
exec_error++;
}
}
diff --git a/Source/exehead/util.c b/Source/exehead/util.c
index 12b0722..fe1481f 100755
--- a/Source/exehead/util.c
+++ b/Source/exehead/util.c
@@ -628,6 +628,37 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab)
LPITEMIDLIST idl;
int x = 2;
+ DWORD ver = GetVersion();
+
+ /*
+
+ SHGetFolderPath as provided by shfolder.dll is used to get special folders
+ unless the installer is running on Windows 95/98. For 95/98 shfolder.dll is
+ only used for the Application Data and Documents folder (if the DLL exists).
+ Oherwise, the old SHGetSpecialFolderLocation API is called.
+
+ There reason for not using shfolder.dll for all folders on 95/98 is that
+ some unsupported folders (such as the Start Menu folder for all users) are
+ simulated instead of returning an error so whe can fall back on the folder
+ for the current user.
+
+ SHGetFolderPath in shell32.dll could be called directly for Windows versions
+ later than 95/98 but there is no need to do so, because shfolder.dll is still
+ provided and calls shell32.dll.
+
+ */
+
+ BOOL use_shfolder =
+ // Use shfolder if not on 95/98
+ !((ver & 0x80000000) && (LOWORD(ver) != 0x5A04)) ||
+
+ // Unless the Application Data or Documents folder is requested
+ (
+ (fldrs[2] == CSIDL_COMMON_APPDATA) ||
+ (fldrs[2] == CSIDL_COMMON_DOCUMENTS)
+ );
+
+ /* Carry on... shfolder stuff is over. */
if (g_exec_flags.all_user_var)
{
@@ -654,7 +685,7 @@ char * NSISCALL GetNSISString(char *outbuf, int strtab)
while (x--)
{
- if (g_SHGetFolderPath)
+ if (g_SHGetFolderPath && use_shfolder)
{
PFNSHGETFOLDERPATHA SHGetFolderPathFunc = (PFNSHGETFOLDERPATHA) g_SHGetFolderPath;
if (!SHGetFolderPathFunc(g_hwnd, fldrs[x], NULL, SHGFP_TYPE_CURRENT, out))
diff --git a/Source/lang.cpp b/Source/lang.cpp
index 9ea2a96..586c81a 100755
--- a/Source/lang.cpp
+++ b/Source/lang.cpp
@@ -876,14 +876,6 @@ char SkipComments(FILE *f) {
return (char) c;
}
-#ifndef _WIN32
-BOOL IsValidCodePage(UINT CodePage)
-{
- // FIXME make a real check
- return TRUE;
-}
-#endif
-
// NSIS Language File parser
LanguageTable * CEXEBuild::LoadLangFile(char *filename) {
FILE *f = FOPEN(filename, "r");
diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp
index 9ea962d..46551d5 100755
--- a/Source/makenssi.cpp
+++ b/Source/makenssi.cpp
@@ -152,11 +152,11 @@ static void print_stub_info(CEXEBuild& build)
{
if (build.display_info)
{
- fprintf(g_output,"Size of first header is %d bytes.\n",sizeof(firstheader));
- fprintf(g_output,"Size of main header is %d bytes.\n",sizeof(header));
- fprintf(g_output,"Size of each section is %d bytes.\n",sizeof(section));
- fprintf(g_output,"Size of each page is %d bytes.\n",sizeof(page));
- fprintf(g_output,"Size of each instruction is %d bytes.\n",sizeof(entry));
+ fprintf(g_output,"Size of first header is %lu bytes.\n",(unsigned long)sizeof(firstheader));
+ fprintf(g_output,"Size of main header is %lu bytes.\n",(unsigned long)sizeof(header));
+ fprintf(g_output,"Size of each section is %lu bytes.\n",(unsigned long)sizeof(section));
+ fprintf(g_output,"Size of each page is %lu bytes.\n",(unsigned long)sizeof(page));
+ fprintf(g_output,"Size of each instruction is %lu bytes.\n",(unsigned long)sizeof(entry));
int x=build.definedlist.getnum();
fprintf(g_output,"\nDefined symbols: ");
for (int i=0; i<x; i++)
@@ -243,11 +243,13 @@ static int change_to_script_dir(CEXEBuild& build, string& script)
return 0;
}
+#ifdef NSIS_HPUX_ALLOW_UNALIGNED_DATA_ACCESS
+extern "C" void allow_unaligned_data_access();
+#endif
+
int main(int argc, char **argv)
{
-
#ifdef NSIS_HPUX_ALLOW_UNALIGNED_DATA_ACCESS
- extern "C" void allow_unaligned_data_access();
allow_unaligned_data_access();
#endif
diff --git a/Source/script.cpp b/Source/script.cpp
index 62581ed..25ebcdc 100755
--- a/Source/script.cpp
+++ b/Source/script.cpp
@@ -298,7 +298,11 @@ int CEXEBuild::doParse(const char *str)
}
// parse before checking if the line should be ignored, so block comments won't be missed
- res=line.parse((char*)m_linebuild.get(),!strnicmp((char*)m_linebuild.get(),"!define",7));
+
+ // escaped quotes should be ignored for compile time commands that set defines
+ // because defines can be inserted in commands at a later stage
+ bool ignore_escaping = (!strnicmp((char*)m_linebuild.get(),"!define",7) || !strnicmp((char*)m_linebuild.get(),"!insertmacro",12));
+ res=line.parse((char*)m_linebuild.get(), ignore_escaping);
inside_comment = line.inCommentBlock();
@@ -2772,7 +2776,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
datebuf[0]=0;
size_t s=strftime(datebuf,sizeof(datebuf),value,localtime(&rawtime));
- if (s < 0)
+ if (s == 0)
datebuf[0]=0;
else
datebuf[max(s,sizeof(datebuf)-1)]=0;
@@ -5757,7 +5761,6 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
return PS_OK;
}
- return PS_ERROR;
case TOK_INITPLUGINSDIR:
{
int ret;
diff --git a/Source/strlist.cpp b/Source/strlist.cpp
index e655c6a..f61fa0b 100755
--- a/Source/strlist.cpp
+++ b/Source/strlist.cpp
@@ -125,7 +125,7 @@ int DefineList::add(const char *name, const char *value/*=""*/)
extern void quit();
if (g_display_errors)
{
- fprintf(g_output,"\nInternal compiler error #12345: GrowBuf realloc/malloc(%d) failed.\n",strlen(value)+1);
+ fprintf(g_output,"\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n",(unsigned long)strlen(value)+1);
fflush(g_output);
}
quit();
diff --git a/Source/strlist.h b/Source/strlist.h
index 8c151dc..0c2a633 100755
--- a/Source/strlist.h
+++ b/Source/strlist.h
@@ -72,7 +72,7 @@ class SortedStringList
extern void quit();
if (g_display_errors)
{
- fprintf(g_output,"\nInternal compiler error #12345: GrowBuf realloc/malloc(%d) failed.\n",strlen(name)+1);
+ fprintf(g_output,"\nInternal compiler error #12345: GrowBuf realloc/malloc(%lu) failed.\n",(unsigned long)strlen(name)+1);
fflush(g_output);
}
quit();
diff --git a/Source/util.cpp b/Source/util.cpp
index 893e4bc..cd0b757 100755
--- a/Source/util.cpp
+++ b/Source/util.cpp
@@ -307,7 +307,7 @@ int find_in_dir(PRESOURCE_DIRECTORY rd, WORD id) {
WORD l = i + FIX_ENDIAN_INT16(rd->Header.NumberOfIdEntries);
for (; i < l; i++) {
- if (FIX_ENDIAN_INT16(rd->Entries[i].Id) == id) {
+ if (FIX_ENDIAN_INT16(rd->Entries[i].UName.Id) == id) {
return i;
}
}
@@ -326,10 +326,10 @@ int generate_unicons_offsets(unsigned char* exeHeader, size_t exeHeaderSize, uns
int idx = find_in_dir(rdRoot, (WORD) (long) RT_ICON);
MY_ASSERT(idx < 0, "no icons found");
MY_IMAGE_RESOURCE_DIRECTORY_ENTRY rdEntry = rdRoot->Entries[idx];
- FIX_ENDIAN_INT32_INPLACE(rdEntry.OffsetToData);
- MY_ASSERT(!rdEntry.DirectoryOffset.DataIsDirectory, "bad resource directory");
+ FIX_ENDIAN_INT32_INPLACE(rdEntry.UOffset.OffsetToData);
+ MY_ASSERT(!rdEntry.UOffset.DirectoryOffset.DataIsDirectory, "bad resource directory");
- PRESOURCE_DIRECTORY rdIcons = PRESOURCE_DIRECTORY(rdEntry.DirectoryOffset.OffsetToDirectory + DWORD(rdRoot));
+ PRESOURCE_DIRECTORY rdIcons = PRESOURCE_DIRECTORY(rdEntry.UOffset.DirectoryOffset.OffsetToDirectory + DWORD(rdRoot));
MY_ASSERT((size_t)rdIcons - (size_t)exeHeader > exeHeaderSize, "corrupted EXE - invalid pointer");
@@ -339,19 +339,19 @@ int generate_unicons_offsets(unsigned char* exeHeader, size_t exeHeaderSize, uns
for (WORD i = 0; i < wNumberOfEntries; i++) { // Icons dir can't have named entries
MY_IMAGE_RESOURCE_DIRECTORY_ENTRY icoEntry = rdIcons->Entries[i];
- FIX_ENDIAN_INT32_INPLACE(icoEntry.OffsetToData);
+ FIX_ENDIAN_INT32_INPLACE(icoEntry.UOffset.OffsetToData);
- MY_ASSERT(!icoEntry.DirectoryOffset.DataIsDirectory, "bad resource directory");
- PRESOURCE_DIRECTORY rd = PRESOURCE_DIRECTORY(icoEntry.DirectoryOffset.OffsetToDirectory + DWORD(rdRoot));
+ MY_ASSERT(!icoEntry.UOffset.DirectoryOffset.DataIsDirectory, "bad resource directory");
+ PRESOURCE_DIRECTORY rd = PRESOURCE_DIRECTORY(icoEntry.UOffset.DirectoryOffset.OffsetToDirectory + DWORD(rdRoot));
MY_ASSERT((size_t)rd - (size_t)exeHeader > exeHeaderSize, "corrupted EXE - invalid pointer");
MY_IMAGE_RESOURCE_DIRECTORY_ENTRY datEntry = rd->Entries[0];
- FIX_ENDIAN_INT32_INPLACE(datEntry.OffsetToData);
+ FIX_ENDIAN_INT32_INPLACE(datEntry.UOffset.OffsetToData);
- MY_ASSERT(datEntry.DirectoryOffset.DataIsDirectory, "bad resource directory");
+ MY_ASSERT(datEntry.UOffset.DirectoryOffset.DataIsDirectory, "bad resource directory");
- PIMAGE_RESOURCE_DATA_ENTRY rde = PIMAGE_RESOURCE_DATA_ENTRY(datEntry.OffsetToData + DWORD(rdRoot));
+ PIMAGE_RESOURCE_DATA_ENTRY rde = PIMAGE_RESOURCE_DATA_ENTRY(datEntry.UOffset.OffsetToData + DWORD(rdRoot));
MY_ASSERT((size_t)rde - (size_t)exeHeader > exeHeaderSize, "corrupted EXE - invalid pointer");
@@ -413,6 +413,23 @@ char *CharNext(const char *s) {
return (char *) s + l;
}
+char *CharNextExA(WORD codepage, const char *s, int flags) {
+ char buf[1024];
+ snprintf(buf, 1024, "CP%d", codepage);
+ setlocale(LC_CTYPE, buf);
+
+ const char* np;
+ int len = mblen(s, strlen(s));
+ if (len > 0)
+ np = s + len;
+ else
+ np = s + 1;
+
+ setlocale(LC_CTYPE, "");
+
+ return (char *) np;
+}
+
int wsprintf(char *s, const char *format, ...) {
va_list val;
va_start(val, format);
@@ -511,6 +528,20 @@ int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
return cchWideChar - (outbytes / sizeof (WCHAR));
}
+BOOL IsValidCodePage(UINT CodePage)
+{
+ char cp[128];
+ create_code_page_string(cp, sizeof(cp), CodePage);
+
+ iconv_t cd = iconv_open("UCS-2LE", cp);
+ if (cd == (iconv_t) -1)
+ return FALSE;
+
+ iconv_close(cd);
+
+ return TRUE;
+}
+
#define MY_ERROR_MSG(x) {if (g_display_errors) {fprintf(g_output,"%s", x);}}
char *my_convert(const char *path)
@@ -574,18 +605,18 @@ FILE *my_fopen(const char *path, const char *mode)
}
#endif//!_WIN32
-void *operator new(size_t size) {
+void *operator new(size_t size) throw(bad_alloc) {
void *p = malloc(size);
if (!p)
throw bad_alloc();
return p;
}
-void operator delete(void *p) {
+void operator delete(void *p) throw() {
if (p) free(p);
}
-void operator delete [](void *p) {
+void operator delete [](void *p) throw() {
if (p) free(p);
}
@@ -664,7 +695,7 @@ string get_executable_path(const char* argv0) {
char* pathtmp;
char* path = NULL;
size_t len = 100;
- size_t nchars;
+ int nchars;
while(1){
pathtmp = (char*)realloc(path,len+1);
if( pathtmp == NULL ){
@@ -673,11 +704,11 @@ string get_executable_path(const char* argv0) {
}
path = pathtmp;
nchars = readlink("/proc/self/exe", path, len);
- if( nchars < 0 ){
+ if( nchars == -1 ){
free(path);
return get_full_path(argv0);
}
- if( nchars < len ){
+ if( nchars < (int) len ){
path[nchars] = '\0';
string result(path);
free(path);
diff --git a/Source/util.h b/Source/util.h
index 08aeee7..b29c4a8 100755
--- a/Source/util.h
+++ b/Source/util.h
@@ -65,12 +65,14 @@ int sane_system(const char *command);
#ifndef _WIN32
char *CharPrev(const char *s, const char *p);
char *CharNext(const char *s);
+char *CharNextExA(WORD codepage, const char *s, int flags);
int wsprintf(char *s, const char *format, ...);
int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar,
LPBOOL lpUsedDefaultChar);
int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
+BOOL IsValidCodePage(UINT CodePage);
char *my_convert(const char *path);
void my_convert_free(char *converted_path);