OSDN Git Service

Use WINDOW_TEXT_LENGTH instead of 0x100 as the buffer size for
authorKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Wed, 18 May 2011 14:14:19 +0000 (23:14 +0900)
committerKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Thu, 26 May 2011 23:44:18 +0000 (08:44 +0900)
GetWindowText. Remove size arguments from SetCorrectApplicationName,
FairConsoleApplicationName, IsConsole and IsJavaW in CUtils.

xkeymacs/profile.cpp
xkeymacsdll/Commands.cpp
xkeymacsdll/Utils.cpp
xkeymacsdll/Utils.h
xkeymacsdll/xkeymacsdll.cpp

index 2bebf78..ffce7ac 100644 (file)
@@ -454,7 +454,7 @@ BOOL CALLBACK CProfile::EnumWindowsProc(const HWND hWnd, const LPARAM lParam)
                        } else if (!_tcsnicmp(pTask[i].ProcessName, _T("vim.exe"), sizeof(pTask[i].ProcessName))) {\r
                                szAppName.Format(_T("VIM"));\r
                        } else {\r
-                               CUtils::SetCorrectApplicationName(pTask[i].ProcessName, sizeof(pTask[i].ProcessName), szWindowName, sizeof(szWindowName));\r
+                               CUtils::SetCorrectApplicationName(pTask[i].ProcessName, szWindowName);\r
                                GetAppName(&szAppName, szWindowName);\r
                        }\r
                        break;\r
index ea954cf..22081c1 100644 (file)
@@ -666,7 +666,7 @@ int CCommands::EndOfLine()
 // C-f: Right\r
 int CCommands::ForwardChar()\r
 {\r
-//     TCHAR szWindowText[0x100] = {'\0'};\r
+//     TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
 //     GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
 //     CUtils::Log("C-f: %s", szWindowText);\r
 \r
index 542dece..965262a 100644 (file)
@@ -29,7 +29,7 @@ CUtils::~CUtils()
 BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)\r
 {\r
        {\r
-               TCHAR buf[0x100] = {'\0'};\r
+               TCHAR buf[WINDOW_TEXT_LENGTH] = {'\0'};\r
                GetWindowText(GetForegroundWindow(), buf, sizeof(buf));\r
 //             CUtils::Log(_T("Window Text --%s--"), buf);\r
                szDialogTitle->Format(_T("%s"), buf);\r
@@ -198,7 +198,7 @@ LPCTSTR const CUtils::GetApplicationName()
        return m_szApplicationName;\r
 }\r
 \r
-void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength)\r
+void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
 {\r
        if (IsFindDialog()) {\r
                return;\r
@@ -207,13 +207,13 @@ void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicati
        if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) {         // "foo bar" -> foo bar\r
                int nApplicationName = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1;     // length of "foo bar"\r
                _tcsncpy(szWindowText, szWindowText + 1, nApplicationName);\r
-               memset(szWindowText + nApplicationName, 0, nWindowTextLength - nApplicationName);\r
+               memset(szWindowText + nApplicationName, 0, WINDOW_TEXT_LENGTH - nApplicationName);\r
        } else if (_tcschr(szWindowText, _T(' '))) {    // foo bar -> foo\r
                LPTSTR pFirstSpace = _tcschr(szWindowText, _T(' '));\r
-               memset(pFirstSpace, 0, nWindowTextLength - (pFirstSpace - szWindowText));\r
+               memset(pFirstSpace, 0, WINDOW_TEXT_LENGTH - (pFirstSpace - szWindowText));\r
        }\r
 \r
-       memset(szApplicationName, 0, nApplicationNameLength);\r
+       memset(szApplicationName, 0, MAX_PATH);\r
        _stprintf(szApplicationName, _T("%s"), szWindowText);\r
 \r
        static LPCTSTR const szExe = _T(".exe");\r
@@ -223,9 +223,9 @@ void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicati
 }\r
 \r
 // Set real application name in the szApplicationName.\r
-void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nApplicationNameLength, LPTSTR szWindowText, const int nWindowTextLength)\r
+void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
 {\r
-       if (IsConsole(szApplicationName, nApplicationNameLength)) {\r
+       if (IsConsole(szApplicationName)) {\r
                int i = 0;\r
                static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"),\r
                                                                                           _T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"),\r
@@ -239,28 +239,28 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nAppl
                                return;\r
                        }\r
 \r
-                       TCHAR sz[0x100] = {'\0'};\r
+                       TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
                        _stprintf(sz, _T("%s%s"), szPromptName[i], szSeparator);\r
 \r
                        if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) {        // "Command Promp - foo"\r
                                _tcscpy(szWindowText, szWindowText + _tcslen(sz));\r
-                               FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);\r
+                               FairConsoleApplicationName(szApplicationName, szWindowText);\r
                                return;\r
                        }\r
                }\r
 \r
                for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {\r
-                       TCHAR szWindowTextLower[0x100] = {'\0'};\r
+                       TCHAR szWindowTextLower[WINDOW_TEXT_LENGTH] = {'\0'};\r
                        _tcscpy(szWindowTextLower, szWindowText);\r
                        _tcslwr(szWindowTextLower);\r
 \r
                        if (_tcsstr(szWindowTextLower, szPromptPath[i])) {\r
-                               TCHAR sz[0x100] = {'\0'};\r
+                               TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
                                _stprintf(sz, _T("%s%s"), szPromptPath[i], szSeparator);\r
 \r
                                if (_tcsstr(szWindowTextLower, sz)) {                           // "X:\WINNT\system32\cmd.exe - foo"\r
                                        _tcscpy(szWindowText, _tcsstr(szWindowTextLower, sz) + _tcslen(sz));\r
-                                       FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);\r
+                                       FairConsoleApplicationName(szApplicationName, szWindowText);\r
                                        return;\r
                                } else {                                                                        // "X:\WINNT\system32\cmd.exe"\r
                                        return;\r
@@ -268,65 +268,58 @@ void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, const int nAppl
                        }\r
                }\r
 \r
-               if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
+               LPTSTR newName = NULL, newText = NULL;\r
+                               if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
                 || (*szWindowText == _T('~'))\r
                 || (*szWindowText == _T('/'))) {                                               // Bash\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("bash.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("bash"));\r
+                       newName = _T("bash.exe");\r
+                       newText = _T("bash");\r
                } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("pdksh.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("pdksh"));\r
+                       newName = _T("pdksh.exe");\r
+                       newText = _T("pdksh");\r
                } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("tcsh.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("tcsh"));\r
+                       newName = _T("tcsh.exe");\r
+                       newText = _T("tcsh");\r
                } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("zsh.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("zsh"));\r
+                       newName = _T("zsh.exe");\r
+                       newText = _T("zsh");\r
                } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)\r
                                || !_tcsnicmp(szWindowText, _T("cat"), 3)) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("sh.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("MKS Korn Shell"));\r
+                       newName = _T("sh.exe");\r
+                       newText = _T("MKS Korn Shell");\r
                } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)\r
                                || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("csh.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("C Shell"));\r
+                       newName = _T("csh.exe");\r
+                       newText = _T("C Shell");\r
                } else if (_tcsstr(szWindowText, _T(" - VIM"))) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("vim.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("VIM"));\r
+                       newName = _T("vim.exe");\r
+                       newText = _T("VIM");\r
                } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("Poderosa.exe"));\r
-                       memset(szWindowText, 0, nWindowTextLength);\r
-                       _stprintf(szWindowText, _T("Poderosa"));\r
+                       newName = _T("Poderosa.exe");\r
+                       newText = _T("Poderosa");\r
                } else {                                                                                        // unknown console application\r
-                       FairConsoleApplicationName(szApplicationName, nApplicationNameLength, szWindowText, nWindowTextLength);\r
+                       FairConsoleApplicationName(szApplicationName, szWindowText);\r
                }\r
-       } else if (IsJavaW(szApplicationName, nApplicationNameLength)) {\r
+               if (newName) {\r
+                       memset(szApplicationName, 0, MAX_PATH);\r
+                       _stprintf(szApplicationName, newName);\r
+                       memset(szWindowText, 0, WINDOW_TEXT_LENGTH);\r
+                       _stprintf(szWindowText, newText);\r
+               }\r
+       } else if (IsJavaW(szApplicationName)) {\r
+               LPTSTR newName = NULL;\r
                if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("eclipse.exe"));\r
+                       newName = _T("eclipse.exe");\r
                } else if (!_tcsicmp(szWindowText, _T("BlueJ"))\r
                            || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("bluej.exe"));\r
+                       newName = _T("bluej.exe");\r
                } else if (!_tcsicmp(szWindowText, _T("JUDE"))\r
                            || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {\r
-                       memset(szApplicationName, 0, nApplicationNameLength);\r
-                       _stprintf(szApplicationName, _T("jude.exe"));\r
+                       newName = _T("jude.exe");\r
+               }\r
+               if (newName) {\r
+                       memset(szApplicationName, 0, MAX_PATH);\r
+                       _stprintf(szApplicationName, newName);\r
                }\r
        }\r
        return;\r
@@ -378,13 +371,13 @@ void CUtils::SetApplicationName(BOOL bImeComposition)
 \r
                        memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
                        _tcscpy(m_szApplicationName, _T("CMD.exe"));\r
-                       TCHAR szWindowText[0x100] = {'\0'};\r
+                       TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
                        GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
-                       SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));\r
+                       SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
                } else if (IsJavaW()) {\r
-                       TCHAR szWindowText[0x100] = {'\0'};\r
+                       TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
                        GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
-                       SetCorrectApplicationName(m_szApplicationName, sizeof(m_szApplicationName), szWindowText, sizeof(szWindowText));\r
+                       SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
                }\r
                if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {\r
 //                     CUtils::Log(_T("SetApplicationName: cygwin"));\r
@@ -646,15 +639,15 @@ BOOL CUtils::IsConsole()
                || !_tcsicmp(m_szApplicationName, _T("telnet.exe"));\r
 }\r
 \r
-BOOL CUtils::IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength)\r
+BOOL CUtils::IsConsole(LPCTSTR szApplicationName)\r
 {\r
-       return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), nApplicationNameLength)\r
-               || !_tcsnicmp(szApplicationName, _T("CMD.exe"), nApplicationNameLength);\r
+       return !_tcsnicmp(szApplicationName, _T("WINOA386.MOD"), MAX_PATH)\r
+               || !_tcsnicmp(szApplicationName, _T("CMD.exe"), MAX_PATH);\r
 }\r
 \r
-BOOL CUtils::IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength)\r
+BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)\r
 {\r
-       return !_tcsnicmp(szApplicationName, _T("javaw.exe"), nApplicationNameLength);\r
+       return !_tcsnicmp(szApplicationName, _T("javaw.exe"), MAX_PATH);\r
 }\r
 \r
 BOOL CUtils::IsSleipnir()\r
@@ -789,7 +782,7 @@ BOOL CUtils::IsVisualBasicEditor()
         || IsMicrosoftWord()\r
         || IsOutlook()\r
         || IsProject()) {\r
-               TCHAR szWindowText[0x100] = {'\0'};\r
+               TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
                GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
                static LPCTSTR const szVBE = _T("Microsoft Visual Basic - ");\r
                if (!_tcsnicmp(szWindowText, szVBE, _tcslen(szVBE))) {\r
@@ -801,7 +794,7 @@ BOOL CUtils::IsVisualBasicEditor()
 \r
 BOOL CUtils::IsEclipse()\r
 {\r
-       TCHAR szWindowText[0x100] = {'\0'};\r
+       TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
        GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
 \r
        LPCTSTR szEclipse = _T(" - Eclipse Platform");\r
@@ -833,7 +826,7 @@ int CUtils::GetClipboardTextLength()
 BOOL CUtils::IsDialog()\r
 {\r
        HWND hwnd = GetForegroundWindow();\r
-       TCHAR szWindowText[0x100] = {'\0'};\r
+       TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
        if (!GetWindowText(hwnd, szWindowText, sizeof(szWindowText)))\r
                return FALSE; // inside sound box\r
        return GetParent(GetForegroundWindow()) != NULL;\r
index 2cbec7b..6307b74 100644 (file)
@@ -9,6 +9,8 @@
 #pragma once\r
 #endif // _MSC_VER > 1000\r
 \r
+#include "xkeymacsdll.h"\r
+\r
 class AFX_EXT_CLASS CUtils  \r
 {\r
 public:\r
@@ -65,7 +67,7 @@ public:
        static BOOL IsCsh();\r
        static BOOL IsSh();\r
        static BOOL IsBash();\r
-       static void SetCorrectApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength);\r
+       static void SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText);\r
        static void Log(LPTSTR fmt, ...);\r
        static BOOL IsSleipnir();\r
        static BOOL IsConsole();\r
@@ -120,9 +122,9 @@ public:
 private:\r
        static BOOL IsTOForEOF();\r
        static int GetFormatTag(LPTSTR szFormatTag);\r
-       static void FairConsoleApplicationName(LPTSTR szApplicationName, int nApplicationNameLength, LPTSTR szWindowText, int nWindowTextLength);\r
-       static BOOL IsConsole(LPCTSTR szApplicationName, int nApplicationNameLength);\r
-       static BOOL IsJavaW(LPCTSTR szApplicationName, int nApplicationNameLength);\r
+       static void FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText);\r
+       static BOOL IsConsole(LPCTSTR szApplicationName);\r
+       static BOOL IsJavaW(LPCTSTR szApplicationName);\r
        static void SetIMEName();\r
        static OSVERSIONINFO m_OsVersionInfo;\r
        static TCHAR m_szIMEName[MAX_PATH];\r
index 9a11ddc..020a404 100644 (file)
@@ -2041,7 +2041,7 @@ BOOL CXkeymacsDll::IsMatchWindowText(CString szWindowText)
 {\r
        BOOL bIsMatchWindowText = TRUE;\r
 \r
-       TCHAR szCurrentWindowText[0x100] = {'\0'};\r
+       TCHAR szCurrentWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
        GetWindowText(GetForegroundWindow(), szCurrentWindowText, sizeof(szCurrentWindowText));\r
 \r
        switch (CUtils::GetWindowTextType(szWindowText)) {\r