• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

XKeymacs for 64bit Windows


Commit MetaInfo

Révisionf03357a27dc665bd9afa5890152eba0582c9eb36 (tree)
l'heure2011-05-27 08:44:18
AuteurKazuhiro Fujieda <fujieda@user...>
CommiterKazuhiro Fujieda

Message de Log

Use WINDOW_TEXT_LENGTH instead of 0x100 as the buffer size for
GetWindowText. Remove size arguments from SetCorrectApplicationName,
FairConsoleApplicationName, IsConsole and IsJavaW in CUtils.

Change Summary

Modification

--- a/xkeymacs/profile.cpp
+++ b/xkeymacs/profile.cpp
@@ -454,7 +454,7 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
454454 } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vim.exe"), sizeof(pTask[i].ProcessName))) {
455455 szAppName.Format(_T("VIM"));
456456 } else {
457- CUtils::SetCorrectApplicationName(pTask[i].ProcessName, sizeof(pTask[i].ProcessName), szWindowName, sizeof(szWindowName));
457+ CUtils::SetCorrectApplicationName(pTask[i].ProcessName, szWindowName);
458458 GetAppName(&szAppName, szWindowName);
459459 }
460460 break;
--- a/xkeymacsdll/Commands.cpp
+++ b/xkeymacsdll/Commands.cpp
@@ -666,7 +666,7 @@ int CCommands::EndOfLine()
666666 // C-f: Right
667667 int CCommands::ForwardChar()
668668 {
669-// TCHAR szWindowText[0x100] = {'\0'};
669+// TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
670670 // GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
671671 // CUtils::Log("C-f: %s", szWindowText);
672672
--- a/xkeymacsdll/Utils.cpp
+++ b/xkeymacsdll/Utils.cpp
@@ -29,7 +29,7 @@ CUtils::~CUtils()
2929 BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)
3030 {
3131 {
32- TCHAR buf[0x100] = {'\0'};
32+ TCHAR buf[WINDOW_TEXT_LENGTH] = {'\0'};
3333 GetWindowText(GetForegroundWindow(), buf, sizeof(buf));
3434 // CUtils::Log(_T("Window Text --%s--"), buf);
3535 szDialogTitle->Format(_T("%s"), buf);
@@ -198,7 +198,7 @@ LPCTSTR const CUtils::GetApplicationName()
198198 return m_szApplicationName;
199199 }
200200
201-void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength)
201+void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)
202202 {
203203 if (IsFindDialog()) {
204204 return;
@@ -207,13 +207,13 @@ void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicati
207207 if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar
208208 int nApplicationName = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"
209209 _tcsncpy(szWindowText, szWindowText + 1, nApplicationName);
210- memset(szWindowText + nApplicationName, 0, nWindowTextLength - nApplicationName);
210+ memset(szWindowText + nApplicationName, 0, WINDOW_TEXT_LENGTH - nApplicationName);
211211 } else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo
212212 LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' '));
213- memset(pFirstSpace, 0, nWindowTextLength - (pFirstSpace - szWindowText));
213+ memset(pFirstSpace, 0, WINDOW_TEXT_LENGTH - (pFirstSpace - szWindowText));
214214 }
215215
216- memset(szApplicationName, 0, nApplicationNameLength);
216+ memset(szApplicationName, 0, MAX_PATH);
217217 _stprintf(szApplicationName, _T("%s"), szWindowText);
218218
219219 static LPCTSTR const szExe = _T(".exe");
@@ -223,9 +223,9 @@ void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicati
223223 }
224224
225225 // Set real application name in the szApplicationName.
226-void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nApplicationNameLength, LPTSTR szWindowText, const int nWindowTextLength)
226+void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)
227227 {
228- if (IsConsole(szApplicationName, nApplicationNameLength)) {
228+ if (IsConsole(szApplicationName)) {
229229 int i = 0;
230230 static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"),
231231 _T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"),
@@ -239,28 +239,28 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nAppl
239239 return;
240240 }
241241
242- TCHAR sz[0x100] = {'\0'};
242+ TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
243243 _stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator);
244244
245245 if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo"
246246 _tcscpy(szWindowText, szWindowText + _tcslen(sz));
247- FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);
247+ FairConsoleApplicationName(szApplicationName, szWindowText);
248248 return;
249249 }
250250 }
251251
252252 for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {
253- TCHAR szWindowTextLower[0x100] = {'\0'};
253+ TCHAR szWindowTextLower[WINDOW_TEXT_LENGTH] = {'\0'};
254254 _tcscpy(szWindowTextLower, szWindowText);
255255 _tcslwr(szWindowTextLower);
256256
257257 if (_tcsstr(szWindowTextLower, szPromptPath[i])) {
258- TCHAR sz[0x100] = {'\0'};
258+ TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};
259259 _stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator);
260260
261261 if (_tcsstr(szWindowTextLower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"
262262 _tcscpy(szWindowText, _tcsstr(szWindowTextLower, sz) + _tcslen(sz));
263- FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);
263+ FairConsoleApplicationName(szApplicationName, szWindowText);
264264 return;
265265 } else { // "X:\WINNT\system32\cmd.exe"
266266 return;
@@ -268,65 +268,58 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nAppl
268268 }
269269 }
270270
271- if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))
271+ LPTSTR newName = NULL, newText = NULL;
272+ if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))
272273 || (*szWindowText == _T('~'))
273274 || (*szWindowText == _T('/'))) { // Bash
274- memset(szApplicationName, 0, nApplicationNameLength);
275- _stprintf(szApplicationName, _T("bash.exe"));
276- memset(szWindowText, 0, nWindowTextLength);
277- _stprintf(szWindowText, _T("bash"));
275+ newName = _T("bash.exe");
276+ newText = _T("bash");
278277 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {
279- memset(szApplicationName, 0, nApplicationNameLength);
280- _stprintf(szApplicationName, _T("pdksh.exe"));
281- memset(szWindowText, 0, nWindowTextLength);
282- _stprintf(szWindowText, _T("pdksh"));
278+ newName = _T("pdksh.exe");
279+ newText = _T("pdksh");
283280 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {
284- memset(szApplicationName, 0, nApplicationNameLength);
285- _stprintf(szApplicationName, _T("tcsh.exe"));
286- memset(szWindowText, 0, nWindowTextLength);
287- _stprintf(szWindowText, _T("tcsh"));
281+ newName = _T("tcsh.exe");
282+ newText = _T("tcsh");
288283 } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {
289- memset(szApplicationName, 0, nApplicationNameLength);
290- _stprintf(szApplicationName, _T("zsh.exe"));
291- memset(szWindowText, 0, nWindowTextLength);
292- _stprintf(szWindowText, _T("zsh"));
284+ newName = _T("zsh.exe");
285+ newText = _T("zsh");
293286 } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)
294287 || !_tcsnicmp(szWindowText, _T("cat"), 3)) {
295- memset(szApplicationName, 0, nApplicationNameLength);
296- _stprintf(szApplicationName, _T("sh.exe"));
297- memset(szWindowText, 0, nWindowTextLength);
298- _stprintf(szWindowText, _T("MKS Korn Shell"));
288+ newName = _T("sh.exe");
289+ newText = _T("MKS Korn Shell");
299290 } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)
300291 || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {
301- memset(szApplicationName, 0, nApplicationNameLength);
302- _stprintf(szApplicationName, _T("csh.exe"));
303- memset(szWindowText, 0, nWindowTextLength);
304- _stprintf(szWindowText, _T("C Shell"));
292+ newName = _T("csh.exe");
293+ newText = _T("C Shell");
305294 } else if (_tcsstr(szWindowText, _T(" - VIM"))) {
306- memset(szApplicationName, 0, nApplicationNameLength);
307- _stprintf(szApplicationName, _T("vim.exe"));
308- memset(szWindowText, 0, nWindowTextLength);
309- _stprintf(szWindowText, _T("VIM"));
295+ newName = _T("vim.exe");
296+ newText = _T("VIM");
310297 } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {
311- memset(szApplicationName, 0, nApplicationNameLength);
312- _stprintf(szApplicationName, _T("Poderosa.exe"));
313- memset(szWindowText, 0, nWindowTextLength);
314- _stprintf(szWindowText, _T("Poderosa"));
298+ newName = _T("Poderosa.exe");
299+ newText = _T("Poderosa");
315300 } else { // unknown console application
316- FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);
301+ FairConsoleApplicationName(szApplicationName, szWindowText);
317302 }
318- } else if (IsJavaW(szApplicationName, nApplicationNameLength)) {
303+ if (newName) {
304+ memset(szApplicationName, 0, MAX_PATH);
305+ _stprintf(szApplicationName, newName);
306+ memset(szWindowText, 0, WINDOW_TEXT_LENGTH);
307+ _stprintf(szWindowText, newText);
308+ }
309+ } else if (IsJavaW(szApplicationName)) {
310+ LPTSTR newName = NULL;
319311 if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {
320- memset(szApplicationName, 0, nApplicationNameLength);
321- _stprintf(szApplicationName, _T("eclipse.exe"));
312+ newName = _T("eclipse.exe");
322313 } else if (!_tcsicmp(szWindowText, _T("BlueJ"))
323314 || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {
324- memset(szApplicationName, 0, nApplicationNameLength);
325- _stprintf(szApplicationName, _T("bluej.exe"));
315+ newName = _T("bluej.exe");
326316 } else if (!_tcsicmp(szWindowText, _T("JUDE"))
327317 || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {
328- memset(szApplicationName, 0, nApplicationNameLength);
329- _stprintf(szApplicationName, _T("jude.exe"));
318+ newName = _T("jude.exe");
319+ }
320+ if (newName) {
321+ memset(szApplicationName, 0, MAX_PATH);
322+ _stprintf(szApplicationName, newName);
330323 }
331324 }
332325 return;
@@ -378,13 +371,13 @@ void CUtils::SetApplicationName(BOOL bImeComposition)
378371
379372 memset(m_szApplicationName, 0, sizeof(m_szApplicationName));
380373 _tcscpy(m_szApplicationName, _T("CMD.exe"));
381- TCHAR szWindowText[0x100] = {'\0'};
374+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
382375 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
383- SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));
376+ SetCorrectApplicationName(m_szApplicationName, szWindowText);
384377 } else if (IsJavaW()) {
385- TCHAR szWindowText[0x100] = {'\0'};
378+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
386379 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
387- SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));
380+ SetCorrectApplicationName(m_szApplicationName, szWindowText);
388381 }
389382 if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {
390383 // CUtils::Log(_T("SetApplicationName: cygwin"));
@@ -646,15 +639,15 @@ BOOL CUtils::IsConsole()
646639 || !_tcsicmp(m_szApplicationName, _T("telnet.exe"));
647640 }
648641
649-BOOL CUtils::IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength)
642+BOOL CUtils::IsConsole(LPCTSTR szApplicationName)
650643 {
651- return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), nApplicationNameLength)
652- || !_tcsnicmp(szApplicationName, _T("CMD.exe"), nApplicationNameLength);
644+ return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), MAX_PATH)
645+ || !_tcsnicmp(szApplicationName, _T("CMD.exe"), MAX_PATH);
653646 }
654647
655-BOOL CUtils::IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength)
648+BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)
656649 {
657- return !_tcsnicmp(szApplicationName, _T("javaw.exe"), nApplicationNameLength);
650+ return !_tcsnicmp(szApplicationName, _T("javaw.exe"), MAX_PATH);
658651 }
659652
660653 BOOL CUtils::IsSleipnir()
@@ -789,7 +782,7 @@ BOOL CUtils::IsVisualBasicEditor()
789782 || IsMicrosoftWord()
790783 || IsOutlook()
791784 || IsProject()) {
792- TCHAR szWindowText[0x100] = {'\0'};
785+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
793786 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
794787 static LPCTSTR const szVBE = _T("Microsoft Visual Basic - ");
795788 if (!_tcsnicmp(szWindowText, szVBE, _tcslen(szVBE))) {
@@ -801,7 +794,7 @@ BOOL CUtils::IsVisualBasicEditor()
801794
802795 BOOL CUtils::IsEclipse()
803796 {
804- TCHAR szWindowText[0x100] = {'\0'};
797+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
805798 GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));
806799
807800 LPCTSTR szEclipse = _T(" - Eclipse Platform");
@@ -833,7 +826,7 @@ int CUtils::GetClipboardTextLength()
833826 BOOL CUtils::IsDialog()
834827 {
835828 HWND hwnd = GetForegroundWindow();
836- TCHAR szWindowText[0x100] = {'\0'};
829+ TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
837830 if (!GetWindowText(hwnd, szWindowText, sizeof(szWindowText)))
838831 return FALSE; // inside sound box
839832 return GetParent(GetForegroundWindow()) != NULL;
--- a/xkeymacsdll/Utils.h
+++ b/xkeymacsdll/Utils.h
@@ -9,6 +9,8 @@
99 #pragma once
1010 #endif // _MSC_VER > 1000
1111
12+#include "xkeymacsdll.h"
13+
1214 class AFX_EXT_CLASS CUtils
1315 {
1416 public:
@@ -65,7 +67,7 @@ public:
6567 static BOOL IsCsh();
6668 static BOOL IsSh();
6769 static BOOL IsBash();
68- static void SetCorrectApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength);
70+ static void SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText);
6971 static void Log(LPTSTR fmt, ...);
7072 static BOOL IsSleipnir();
7173 static BOOL IsConsole();
@@ -120,9 +122,9 @@ public:
120122 private:
121123 static BOOL IsTOForEOF();
122124 static int GetFormatTag(LPTSTR szFormatTag);
123- static void FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength);
124- static BOOL IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength);
125- static BOOL IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength);
125+ static void FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText);
126+ static BOOL IsConsole(LPCTSTR szApplicationName);
127+ static BOOL IsJavaW(LPCTSTR szApplicationName);
126128 static void SetIMEName();
127129 static OSVERSIONINFO m_OsVersionInfo;
128130 static TCHAR m_szIMEName[MAX_PATH];
--- a/xkeymacsdll/xkeymacsdll.cpp
+++ b/xkeymacsdll/xkeymacsdll.cpp
@@ -2041,7 +2041,7 @@ BOOL CXkeymacsDll::IsMatchWindowText(CString szWindowText)
20412041 {
20422042 BOOL bIsMatchWindowText = TRUE;
20432043
2044- TCHAR szCurrentWindowText[0x100] = {'\0'};
2044+ TCHAR szCurrentWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
20452045 GetWindowText(GetForegroundWindow(), szCurrentWindowText, sizeof(szCurrentWindowText));
20462046
20472047 switch (CUtils::GetWindowTextType(szWindowText)) {