From f4f18f94698172f27ad7585184f0d0854fbe94e2 Mon Sep 17 00:00:00 2001
From: wizou
Date: Mon, 29 Mar 2010 15:32:24 +0000
Subject: [PATCH] a little bit more TCHARs and minor fixes
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6042 212acab6-be3b-0410-9dea-997c60f758d6
---
Contrib/Modern UI 2/Readme.html | 2 +-
SConstruct | 1 +
Source/build.cpp | 2 +-
Source/lang.cpp | 9 +++++----
Source/script.cpp | 4 ++--
Source/strlist.h | 25 +++++++++++++++++++------
Source/tstring.h | 2 --
7 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/Contrib/Modern UI 2/Readme.html b/Contrib/Modern UI 2/Readme.html
index 8c34dddf..e4e75276 100644
--- a/Contrib/Modern UI 2/Readme.html
+++ b/Contrib/Modern UI 2/Readme.html
@@ -1092,7 +1092,7 @@ FunctionEnd
The pre function is called first and allows you to initalize variables or decide
whether the page should be skipped. Then, the show function is called, which can
be used to customize the interface. Finally, the user input can be validated in the
- leave function. The NSIS Users Manual provides more information about these functions.
+ leave function. The NSIS Users Manual provides more information about these functions.
In the show function, the window handles of all controls on the page can be retrieved
from a Modern UI variable. A list of the variables names is not yet available. For
diff --git a/SConstruct b/SConstruct
index d63d1579..f8dc3428 100644
--- a/SConstruct
+++ b/SConstruct
@@ -223,6 +223,7 @@ defines_h.close()
# write version into version.h
f = open(defenv.File('#$BUILD_CONFIG/nsis-version.h').abspath, 'w')
f.write('// This file is automatically generated by SCons\n// DO NOT EDIT THIS FILE\n')
+f.write('#include "tchar.h"\n')
if defenv.has_key('VER_MAJOR'):
defenv['VERSION'] = defenv['VER_MAJOR']
diff --git a/Source/build.cpp b/Source/build.cpp
index 06cb2b1e..98e275db 100644
--- a/Source/build.cpp
+++ b/Source/build.cpp
@@ -490,7 +490,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP
{
const TCHAR *np;
#ifdef _UNICODE
- np = CharNext(p);
+ np = CharNext(p);
#else
np = CharNextExA(codepage, p, 0);
#endif
diff --git a/Source/lang.cpp b/Source/lang.cpp
index d5fae88d..224608cd 100644
--- a/Source/lang.cpp
+++ b/Source/lang.cpp
@@ -19,6 +19,7 @@
#include "Platform.h"
#include
#include
+#include "tchar.h"
#include "build.h"
#include "util.h"
#include "DialogTemplate.h"
@@ -727,7 +728,7 @@ int CEXEBuild::GenerateLangTables() {
#undef ADD_FONT
}
catch (exception& err) {
- ERROR_MSG(_T("\nError while applying font: %s\n"), err.what());
+ ERROR_MSG(_T("\nError while applying font: %s\n"), CtoTString(err.what()));
return PS_ERROR;
}
}
@@ -790,7 +791,7 @@ int CEXEBuild::GenerateLangTables() {
#undef ADD_FONT
}
catch (exception& err) {
- ERROR_MSG(_T("\nError while applying NLF font/RTL: %s\n"), err.what());
+ ERROR_MSG(_T("\nError while applying NLF font/RTL: %s\n"), CtoTString(err.what()));
return PS_ERROR;
}
@@ -906,7 +907,7 @@ TCHAR SkipComments(FILE *f) {
// NSIS Language File parser
LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) {
- FILE *f = FOPEN(filename, _T("r"));
+ FILE *f = FOPENTEXT(filename, _T("r"));
if (!f) {
ERROR_MSG(_T("Error: Can't open language file - \"%s\"!\n"),filename);
return 0;
@@ -971,7 +972,7 @@ LanguageTable * CEXEBuild::LoadLangFile(TCHAR *filename) {
}
// set ^Language
- nlf->m_szStrings[NLF_LANGUAGE] = strdup(nlf->m_szName);
+ nlf->m_szStrings[NLF_LANGUAGE] = _tcsdup(nlf->m_szName);
int temp;
diff --git a/Source/script.cpp b/Source/script.cpp
index 5d912ea8..2296b9fb 100644
--- a/Source/script.cpp
+++ b/Source/script.cpp
@@ -2825,7 +2825,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (s == 0)
datebuf[0]=0;
else
- datebuf[max(s,sizeof(datebuf)-1)]=0;
+ datebuf[max(s,_countof(datebuf)-1)]=0;
value=datebuf;
} else if (!_tcsicmp(define,_T("/file")) || !_tcsicmp(define,_T("/file_noerr"))) {
@@ -3139,7 +3139,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
for (;;)
{
str[0]=0;
- fgets(str,sizeof(str),fp);
+ _fgetts(str,_countof(str),fp);
if (!str[0]) break; // eof
TCHAR *p=str;
diff --git a/Source/strlist.h b/Source/strlist.h
index 2e9f53d5..b49f61fe 100644
--- a/Source/strlist.h
+++ b/Source/strlist.h
@@ -300,7 +300,8 @@ class SortedStringListND // no delete - can be placed in GrowBuf
int pos=find(name,-1,case_sensitive,1,&where);
if (pos==-1) return alwaysreturnpos ? where : -1;
- newstruct.name=strings.add(name,strlen(name)+1);
+
+ // Note that .name is set with the TCHAR* offset into m_strings.
newstruct.name=strings.add(name,strlen(name)+1);
gr.add(&newstruct,sizeof(T));
T *s=(T*)gr.get();
@@ -357,6 +358,7 @@ class SortedStringListND // no delete - can be placed in GrowBuf
int ll=0;
int nextpos=(ul+ll)/2;
+ // Do binary search on m_gr which is sorted. m_strings is NOT sorted.
while (ul > ll)
{
int res;
@@ -366,21 +368,32 @@ class SortedStringListND // no delete - can be placed in GrowBuf
if (case_sensitive)
res = _tcscmp(str, pCurr);
else
- res = stricmp(str, pCurr);
+ res = _tcsicmp(str, pCurr);
}
else
{
+ unsigned int pCurr_len = _tcslen(pCurr);
if (case_sensitive)
- res=strncmp(str, pCurr, mymin((unsigned int) n_chars, strlen(pCurr)));
+ res = _tcsncmp(str, pCurr, mymin((unsigned int) n_chars, pCurr_len));
else
- res=strnicmp(str, pCurr, mymin((unsigned int) n_chars, strlen(pCurr)));
- if (res == 0 && n_chars != -1 && (unsigned int) n_chars != strlen(pCurr))
- res = n_chars - strlen(pCurr);
+ res = _tcsncicmp(str, pCurr, mymin((unsigned int) n_chars, pCurr_len));
+
+ // If there is a match and we are looking for a partial match and
+ // n_chars is NOT the length of the current string, then the
+ // comparison result is determined by the length comparison.
+ if (res == 0 && n_chars != -1 && (unsigned int) n_chars != pCurr_len)
+ res = n_chars - pCurr_len;
}
+ // Found!
if (res==0)
{
+ // Return where we found it in *where.
if (where) *where = nextpos;
+
+ // If returnbestpos, then we should return -1, otherwise where
+ // we found it. But if (returnbestpos && case_sensitive == -1)
+ // returns nextpos.
return returnbestpos ? (case_sensitive!=-1 ? -1 : nextpos) : nextpos;
}
if (res<0) ul=nextpos;
diff --git a/Source/tstring.h b/Source/tstring.h
index 9159397d..95351671 100644
--- a/Source/tstring.h
+++ b/Source/tstring.h
@@ -21,8 +21,6 @@
#include "tchar.h"
#include
-//#include
-//#include
/* Abstract string type as well. */
#ifdef _UNICODE