📄 mshell_funcs.c
字号:
/* * mShell * Copyright 2006, Julien Lecomte * * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the * use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software in a * product, an acknowledgment in the product documentation would be appreciated * but is not required. * 2. Altered source versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * * $Id: mshell_funcs.c,v 1.4 2006/04/06 14:52:13 julienlecomte Exp $ */#include "mshell_preconfig.h"#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <shlwapi.h>#include "mshell.h"TCHAR szPathSystem[MAX_PATH]; /* Root ( /[usr] for mSys ) */extern HWND hMDIClient;/* Paths searched to find msys-1.0.dll */static LPTSTR lpSearchPaths[] = { ".", ".\\bin", "..\\bin", "", ""};/* Known shells */static POSSHELLS lpShells[] = { {SHELL_BASH, "bash.exe", "/bin/bash" }, {SHELL_SH, "sh.exe" , "/bin/sh" }, {SHELL_NONE, "" , ""}};static BOOL FindSystemDLLFromPath (LPCTSTR lpPath){ TCHAR szPathSearch[MAX_PATH]; unsigned int i = 0; while (*lpSearchPaths[i]) { ZeroMemory (szPathSearch, sizeof(TCHAR) * MAX_PATH); PathCombine (szPathSearch, lpPath, lpSearchPaths[i]); PathAddBackslash (szPathSearch); PathCombine (szPathSearch, szPathSearch, "msys-1.0.dll"); if (PathFileExists (szPathSearch) && !PathIsDirectory (szPathSearch)) { /* Found msys-1.0.dll ! */ CopyMemory (szPathSystem, szPathSearch, sizeof(TCHAR) * MAX_PATH); PathRemoveFileSpec (szPathSystem); PathCombine (szPathSystem, szPathSystem, ".."); return TRUE; } i++; } return FALSE;}BOOL FindSystemDLL (void){ TCHAR szPath[MAX_PATH]; int nRet; ZeroMemory (szPathSystem, sizeof(TCHAR) * MAX_PATH); /* Can we base our search on our path ? */ nRet = GetModuleFileName (NULL, szPath, MAX_PATH); if (nRet && (nRet < MAX_PATH)) { PathRemoveFileSpec (szPath); PathAddBackslash (szPath); if (FindSystemDLLFromPath (szPath)) return TRUE; } /* Can we base our search on our current folder ? */ nRet = GetCurrentDirectory (MAX_PATH, szPath); if (nRet && (nRet < MAX_PATH)) { PathAddBackslash (szPath); if (FindSystemDLLFromPath (szPath)) return TRUE; }#ifdef DEBUG_FIXED_PATH return FindSystemDLLFromPath (DEBUG_FIXED_PATH);#else return FALSE;#endif}BOOL ValidateShellInfo (LPTERMINAL_INFO lpTI, HWND hCombo, HWND hMsgBox){ TCHAR szBuffer[MAX_PATH]; int nIndex = SendMessage (hCombo, CB_GETCURSEL, 0, 0); IFFAIL_MSGBOX_RETURN (nIndex == CB_ERR, hMsgBox, "No shell was chosen.", FALSE); SendMessage (hCombo, CB_GETLBTEXT, nIndex, (LPARAM) szBuffer); int nShell = -1; unsigned int i = 0; while ((&lpShells[i].type != SHELL_NONE) && (nShell == -1)) if (StrCmp (lpShells[i++].caption, szBuffer) == 0) nShell = i-1; IFFAIL_MSGBOX_RETURN (nShell == -1, hMsgBox, "Chosen shell unknown.", FALSE); /* FIXME: Right now we only support rxvt ...ugh... */ CopyMemory (lpTI->szCmdLine, "rxvt.exe", sizeof(TCHAR) * MAX_PATH); StrCatBuff (lpTI->szCmdLine, TEXT(" -backspacekey \027 -sl 2500"), MAX_PATH); StrCatBuff (lpTI->szCmdLine, TEXT(" -fg LightGrey -bg Black"), MAX_PATH); StrCatBuff (lpTI->szCmdLine, TEXT(" -tn msys"), MAX_PATH); StrCatBuff (lpTI->szCmdLine, TEXT(" -geometry 80x25"), MAX_PATH); StrCatBuff (lpTI->szCmdLine, TEXT(" -fn \"Courier-12\""), MAX_PATH); //StrCatBuff (lpTI->szCmdLine, TEXT(" -fn \"Courier\""), MAX_PATH); StrCatBuff (lpTI->szCmdLine, TEXT(" -e "), MAX_PATH); StrCatBuff (lpTI->szCmdLine, lpShells[nShell].caption, MAX_PATH); StrCatBuff (lpTI->szCmdLine, TEXT(" --login -i"), MAX_PATH); CopyMemory (lpTI->szSysDir, szPathSystem, sizeof(TCHAR) * MAX_PATH); CopyMemory (lpTI->szCurDir, lpTI->szSysDir, sizeof(TCHAR) * MAX_PATH); PathCombine (lpTI->szCurDir, lpTI->szCurDir, "bin\\"); DEBUG_ECHO ("lpTI->szCmdLine = %s\n", lpTI->szCmdLine); DEBUG_ECHO ("lpTI->szSysDir = %s\n", lpTI->szSysDir); DEBUG_ECHO ("lpTI->szCurDir = %s\n", lpTI->szCurDir); /* Create the terminal window */ HWND hNew = CreateMDIWindow (WNDCLASS_TERMINAL, "Terminal", WS_MAXIMIZE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hMDIClient, GetModuleHandle (NULL), (LPARAM) lpTI); IFFAIL_MSGBOX_RETURN (!hNew, hMsgBox, "Cannot create terminal.", FALSE) return TRUE;}BOOL PopulateShells (HWND hChoiceBox){ unsigned int nCount = 0; TCHAR szPath[MAX_PATH]; int i = 0; while (lpShells[i].type != SHELL_NONE) { CopyMemory (szPath, szPathSystem, sizeof(TCHAR) * MAX_PATH); PathCombine (szPath, szPath, "bin\\"); PathCombine (szPath, szPath, lpShells[i].name); if (PathFileExists (szPath) && !PathIsDirectory (szPath)) { /* Found the shell */ SendMessage (hChoiceBox, CB_ADDSTRING, 0, (LPARAM) lpShells[i].caption); nCount++; } i++; } if (!nCount) return FALSE; SendMessage (hChoiceBox, CB_SETCURSEL, 0, 0); return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -