[BUG_FIXED] Fix status bar display bug that xml/html utf8 indicator makes status bar display ANSI instead of ANSI as UTF-8.

[UPDATE] Convert process thread module from ANSI to Unicode.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@593 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2009-12-23 19:23:20 +00:00
parent 00e79d39c8
commit dbe22f6cac
5 changed files with 77 additions and 59 deletions

View File

@ -17,6 +17,7 @@
#include "precompiledHeaders.h" #include "precompiledHeaders.h"
#include "EncodingMapper.h" #include "EncodingMapper.h"
#include "Scintilla.h"
// Don't change the order // Don't change the order
EncodingUnit encodings[] = { EncodingUnit encodings[] = {
@ -129,7 +130,7 @@ int EncodingMapper::getIndexFromEncoding(int encoding) const
int EncodingMapper::getEncodingFromString(const char *encodingAlias) const int EncodingMapper::getEncodingFromString(const char *encodingAlias) const
{ {
if (isInListA(encodingAlias, "utf-8 utf8")) if (isInListA(encodingAlias, "utf-8 utf8"))
return 65001; return SC_CP_UTF8;
size_t nbItem = sizeof(encodings)/sizeof(EncodingUnit); size_t nbItem = sizeof(encodings)/sizeof(EncodingUnit);
int enc = -1; int enc = -1;

View File

@ -15,8 +15,9 @@
//along with this program; if not, write to the Free Software //along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "precompiledHeaders.h"
#include "process.h" #include "process.h"
#include "SysMsg.h" //#include "SysMsg.h"
BOOL Process::run() BOOL Process::run()
{ {
@ -38,11 +39,11 @@ BOOL Process::run()
try { try {
// Create stdout pipe // Create stdout pipe
if (!::CreatePipe(&_hPipeOutR, &hPipeOutW, &sa, 0)) if (!::CreatePipe(&_hPipeOutR, &hPipeOutW, &sa, 0))
error("CreatePipe", result, 1000); error(TEXT("CreatePipe"), result, 1000);
// Create stderr pipe // Create stderr pipe
if (!::CreatePipe(&_hPipeErrR, &hPipeErrW, &sa, 0)) if (!::CreatePipe(&_hPipeErrR, &hPipeErrW, &sa, 0))
error("CreatePipe", result, 1001); error(TEXT("CreatePipe"), result, 1001);
STARTUPINFO startup; STARTUPINFO startup;
PROCESS_INFORMATION procinfo; PROCESS_INFORMATION procinfo;
@ -69,27 +70,27 @@ BOOL Process::run()
_hProcessThread = procinfo.hThread; _hProcessThread = procinfo.hThread;
if(!started) if(!started)
error("CreateProcess", result, 1002); error(TEXT("CreateProcess"), result, 1002);
hListenerEvent[0] = ::CreateEvent(NULL, FALSE, FALSE, "listenerEvent"); hListenerEvent[0] = ::CreateEvent(NULL, FALSE, FALSE, TEXT("listenerEvent"));
if(!hListenerEvent[0]) if(!hListenerEvent[0])
error("CreateEvent", result, 1003); error(TEXT("CreateEvent"), result, 1003);
hListenerEvent[1] = ::CreateEvent(NULL, FALSE, FALSE, "listenerStdErrEvent"); hListenerEvent[1] = ::CreateEvent(NULL, FALSE, FALSE, TEXT("listenerStdErrEvent"));
if(!hListenerEvent[1]) if(!hListenerEvent[1])
error("CreateEvent", result, 1004); error(TEXT("CreateEvent"), result, 1004);
hListenerStdOutThread = ::CreateThread(NULL, 0, staticListenerStdOut, this, 0, NULL); hListenerStdOutThread = ::CreateThread(NULL, 0, staticListenerStdOut, this, 0, NULL);
if (!hListenerStdOutThread) if (!hListenerStdOutThread)
error("CreateThread", result, 1005); error(TEXT("CreateThread"), result, 1005);
hListenerStdErrThread = ::CreateThread(NULL, 0, staticListenerStdErr, this, 0, NULL); hListenerStdErrThread = ::CreateThread(NULL, 0, staticListenerStdErr, this, 0, NULL);
if (!hListenerStdErrThread) if (!hListenerStdErrThread)
error("CreateThread", result, 1006); error(TEXT("CreateThread"), result, 1006);
::WaitForSingleObject(_hProcess, INFINITE); ::WaitForSingleObject(_hProcess, INFINITE);
::WaitForMultipleObjects(2, hListenerEvent, TRUE, INFINITE); ::WaitForMultipleObjects(2, hListenerEvent, TRUE, INFINITE);
} catch (int coderr){} } catch (int /*coderr*/){}
// on va fermer toutes les handles // on va fermer toutes les handles
if (hPipeOutW) if (hPipeOutW)
@ -117,11 +118,11 @@ BOOL Process::run()
void Process::listenerStdOut() void Process::listenerStdOut()
{ {
BOOL Result = 0; //BOOL Result = 0;
DWORD size = 0; //DWORD size = 0;
DWORD bytesAvail = 0; DWORD bytesAvail = 0;
BOOL result = 0; BOOL result = 0;
HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, "listenerEvent"); HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerEvent"));
//FILE *fp = NULL; //FILE *fp = NULL;
int taille = 0; int taille = 0;
@ -134,7 +135,8 @@ void Process::listenerStdOut()
::ResumeThread(_hProcessThread); ::ResumeThread(_hProcessThread);
while (true) bool goOn = true;
while (goOn)
{ // got data { // got data
memset(bufferOut,0x00,MAX_LINE_LENGTH + 1); memset(bufferOut,0x00,MAX_LINE_LENGTH + 1);
//memset(bufferErr,0x00,MAX_LINE_LENGTH + 1); //memset(bufferErr,0x00,MAX_LINE_LENGTH + 1);
@ -145,6 +147,7 @@ void Process::listenerStdOut()
if (!::PeekNamedPipe(_hPipeOutR, bufferOut, taille, &outbytesRead, &bytesAvail, NULL)) if (!::PeekNamedPipe(_hPipeOutR, bufferOut, taille, &outbytesRead, &bytesAvail, NULL))
{ {
bytesAvail = 0; bytesAvail = 0;
goOn = false;
break; break;
} }
@ -152,18 +155,24 @@ void Process::listenerStdOut()
{ {
result = :: ReadFile(_hPipeOutR, bufferOut, taille, &outbytesRead, NULL); result = :: ReadFile(_hPipeOutR, bufferOut, taille, &outbytesRead, NULL);
if ((!result) && (outbytesRead == 0)) if ((!result) && (outbytesRead == 0))
{
goOn = false;
break; break;
}
} }
//outbytesRead = strlen(bufferOut); //outbytesRead = strlen(bufferOut);
bufferOut[outbytesRead] = '\0'; bufferOut[outbytesRead] = '\0';
string s; generic_string s;
s.assign(bufferOut); s.assign(bufferOut);
_stdoutStr += s; _stdoutStr += s;
if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode)) if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode))
{ {
if (nExitCode != STILL_ACTIVE) if (nExitCode != STILL_ACTIVE)
{
goOn = false;
break; // EOF condition break; // EOF condition
}
} }
//else //else
//break; //break;
@ -172,17 +181,17 @@ void Process::listenerStdOut()
if(!::SetEvent(hListenerEvent)) if(!::SetEvent(hListenerEvent))
{ {
systemMessage("Thread listenerStdOut"); systemMessage(TEXT("Thread listenerStdOut"));
} }
} }
void Process::listenerStdErr() void Process::listenerStdErr()
{ {
BOOL Result = 0; //BOOL Result = 0;
DWORD size = 0; //DWORD size = 0;
DWORD bytesAvail = 0; DWORD bytesAvail = 0;
BOOL result = 0; BOOL result = 0;
HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, "listenerStdErrEvent"); HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerStdErrEvent"));
int taille = 0; int taille = 0;
//TCHAR bufferOut[MAX_LINE_LENGTH + 1]; //TCHAR bufferOut[MAX_LINE_LENGTH + 1];
@ -194,7 +203,8 @@ void Process::listenerStdErr()
::ResumeThread(_hProcessThread); ::ResumeThread(_hProcessThread);
while (true) bool goOn = true;
while (goOn)
{ // got data { // got data
memset(bufferErr, 0x00, MAX_LINE_LENGTH + 1); memset(bufferErr, 0x00, MAX_LINE_LENGTH + 1);
taille = sizeof(bufferErr) - sizeof(TCHAR); taille = sizeof(bufferErr) - sizeof(TCHAR);
@ -204,6 +214,7 @@ void Process::listenerStdErr()
if (!::PeekNamedPipe(_hPipeErrR, bufferErr, taille, &errbytesRead, &bytesAvail, NULL)) if (!::PeekNamedPipe(_hPipeErrR, bufferErr, taille, &errbytesRead, &bytesAvail, NULL))
{ {
bytesAvail = 0; bytesAvail = 0;
goOn = false;
break; break;
} }
@ -211,18 +222,24 @@ void Process::listenerStdErr()
{ {
result = :: ReadFile(_hPipeErrR, bufferErr, taille, &errbytesRead, NULL); result = :: ReadFile(_hPipeErrR, bufferErr, taille, &errbytesRead, NULL);
if ((!result) && (errbytesRead == 0)) if ((!result) && (errbytesRead == 0))
{
goOn = false;
break; break;
}
} }
//outbytesRead = strlen(bufferOut); //outbytesRead = strlen(bufferOut);
bufferErr[errbytesRead] = '\0'; bufferErr[errbytesRead] = '\0';
string s; generic_string s;
s.assign(bufferErr); s.assign(bufferErr);
_stderrStr += s; _stderrStr += s;
if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode)) if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode))
{ {
if (nExitCode != STILL_ACTIVE) if (nExitCode != STILL_ACTIVE)
{
goOn = false;
break; // EOF condition break; // EOF condition
}
} }
//else //else
//break; //break;
@ -231,11 +248,11 @@ void Process::listenerStdErr()
if(!::SetEvent(hListenerEvent)) if(!::SetEvent(hListenerEvent))
{ {
systemMessage("Thread stdout listener"); systemMessage(TEXT("Thread stdout listener"));
} }
} }
void Process::error(const char *txt2display, BOOL & returnCode, int errCode) void Process::error(const TCHAR *txt2display, BOOL & returnCode, int errCode)
{ {
systemMessage(txt2display); systemMessage(txt2display);
returnCode = FALSE; returnCode = FALSE;

View File

@ -19,29 +19,28 @@
#define PROCESSUS_H #define PROCESSUS_H
#include <windows.h> #include <windows.h>
#include <string> //#include <string>
using namespace std; using namespace std;
class Process class Process
{ {
public: public:
Process() {}; Process() {};
Process(const char *cmd, const char *cDir/*, unsigned int id = 0*/) Process(const TCHAR *cmd, const TCHAR *cDir)
: _stdoutStr(""), _stderrStr(""), _hPipeOutR(NULL), : _stdoutStr(TEXT("")), _stderrStr(TEXT("")), _hPipeOutR(NULL),
_hPipeErrR(NULL), _hProcess(NULL), _hProcessThread(NULL) { _hPipeErrR(NULL), _hProcess(NULL), _hProcessThread(NULL) {
strcpy(_command, cmd); lstrcpy(_command, cmd);
strcpy(_curDir, cDir); lstrcpy(_curDir, cDir);
//_pid = id;
}; };
BOOL run(); BOOL run();
const char * getStdout() const { const TCHAR * getStdout() const {
return _stdoutStr.c_str(); return _stdoutStr.c_str();
}; };
const char * getStderr() const { const TCHAR * getStderr() const {
return _stderrStr.c_str(); return _stderrStr.c_str();
}; };
@ -50,21 +49,21 @@ public:
}; };
bool hasStdout() { bool hasStdout() {
return _stdoutStr.compare(""); return (_stdoutStr.compare(TEXT("")) != 0);
}; };
bool hasStderr() { bool hasStderr() {
return _stderrStr.compare(""); return (_stderrStr.compare(TEXT("")) != 0);
}; };
protected: protected:
// LES ENTREES // LES ENTREES
char _command[256]; TCHAR _command[256];
char _curDir[256]; TCHAR _curDir[256];
// LES SORTIES // LES SORTIES
string _stdoutStr; generic_string _stdoutStr;
string _stderrStr; generic_string _stderrStr;
int _exitCode; int _exitCode;
// LES HANDLES // LES HANDLES
@ -85,7 +84,7 @@ protected:
}; };
void listenerStdOut(); void listenerStdOut();
void listenerStdErr(); void listenerStdErr();
void error(const char *txt2display, BOOL & returnCode, int errCode); void error(const TCHAR *txt2display, BOOL & returnCode, int errCode);
}; };
#endif //PROCESSUS_H #endif //PROCESSUS_H

View File

@ -23,14 +23,14 @@
class ProcessThread class ProcessThread
{ {
public : public :
ProcessThread(const char *appName, const char *cmd, const char *cDir, HWND hwnd) : _hwnd(hwnd) { ProcessThread(const TCHAR *appName, const TCHAR *cmd, const TCHAR *cDir, HWND hwnd) : _hwnd(hwnd) {
strcpy(_appName, appName); lstrcpy(_appName, appName);
strcpy(_command, cmd); lstrcpy(_command, cmd);
strcpy(_curDir, cDir); lstrcpy(_curDir, cDir);
}; };
BOOL run(){ BOOL run(){
HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, "localVarProcessEvent"); HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, TEXT("localVarProcessEvent"));
_hProcessThread = ::CreateThread(NULL, 0, staticLauncher, this, 0, NULL); _hProcessThread = ::CreateThread(NULL, 0, staticLauncher, this, 0, NULL);
@ -42,9 +42,9 @@ public :
protected : protected :
// ENTREES // ENTREES
char _appName[256]; TCHAR _appName[256];
char _command[256]; TCHAR _command[256];
char _curDir[256]; TCHAR _curDir[256];
HWND _hwnd; HWND _hwnd;
HANDLE _hProcessThread; HANDLE _hProcessThread;
@ -54,28 +54,28 @@ protected :
}; };
bool launch() { bool launch() {
HANDLE hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, "localVarProcessEvent"); HANDLE hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("localVarProcessEvent"));
HWND hwnd = _hwnd; HWND hwnd = _hwnd;
char appName[256]; TCHAR appName[256];
strcpy(appName, _appName); lstrcpy(appName, _appName);
HANDLE hMyself = _hProcessThread; HANDLE hMyself = _hProcessThread;
Process process(_command, _curDir); Process process(_command, _curDir);
if(!::SetEvent(hEvent)) if(!::SetEvent(hEvent))
{ {
systemMessage("Thread launcher"); systemMessage(TEXT("Thread launcher"));
} }
process.run(); process.run();
int code = process.getExitCode(); int code = process.getExitCode();
char codeStr[256]; TCHAR codeStr[256];
sprintf(codeStr, "%s : %0.4X", appName, code); generic_sprintf(codeStr, TEXT("%s : %0.4X"), appName, code);
::MessageBox(hwnd, (char *)process.getStdout(), codeStr, MB_OK); ::MessageBox(hwnd, process.getStdout(), codeStr, MB_OK);
if (process.hasStderr()) if (process.hasStderr())
::MessageBox(hwnd, (char *)process.getStderr(), codeStr, MB_OK); ::MessageBox(hwnd, process.getStderr(), codeStr, MB_OK);
::CloseHandle(hMyself); ::CloseHandle(hMyself);
return true; return true;

View File

@ -429,11 +429,12 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
} }
buf->setUnicodeMode(um); buf->setUnicodeMode(um);
} }
else else // encoding != -1
{ {
buf->setUnicodeMode(uniCookie); // Test if encoding is set to UTF8 w/o BOM (usually for utf8 indicator of xml or html)
buf->setEncoding((encoding == SC_CP_UTF8)?-1:encoding);
buf->setUnicodeMode(uniCookie);
buf->setFormat(format); buf->setFormat(format);
buf->setEncoding(encoding);
} }
//determine buffer properties //determine buffer properties
_nextBufferID++; _nextBufferID++;