⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filecomp.c

📁 PocketCMD是与pocketconsole配合实用的命令行解释器(Shell)
💻 C
字号:
/* *  FILECOMP.C - handles filename completion. * * *  Comments: * *    30-Jul-1998 (John P Price <linux-guru@gcfl.net>) *       moved from command.c file *       made second TAB display list of filename matches *       made filename be lower case if last character typed is lower case * *    25-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>) *       Cleanup. Unicode safe! */#include "config.h"#include "cmd.h" #ifdef FEATURE_UNIX_FILENAME_COMPLETIONVOID CompleteFilename (LPTSTR str, INT charcount){	WIN32_FIND_DATA file;	HANDLE hFile;	INT   curplace = 0;	INT   start;	INT   count;	BOOL  found_dot = FALSE;	BOOL  perfectmatch = TRUE;	TCHAR path[MAX_PATH];	TCHAR fname[MAX_PATH];	TCHAR maxmatch[MAX_PATH] = _T("");	TCHAR directory[MAX_PATH];	LPCOMMAND cmds_ptr;	/* expand current file name */	count = charcount - 1;	if (count < 0)		count = 0;	/* find front of word */	while (count > 0 && str[count] != _T(' '))		count--;	/* if not at beginning, go forward 1 */	if (str[count] == _T(' '))		count++;	start = count;	/* extract directory from word */	_tcscpy (directory, &str[start]);	curplace = _tcslen (directory) - 1;	while (curplace >= 0 && directory[curplace] != _T('\\') &&		   directory[curplace] != _T(':'))	{		directory[curplace] = 0;		curplace--;	}	_tcscpy (path, &str[start]);	/* look for a '.' in the filename */	for (count = _tcslen (directory); path[count] != _T('\0'); count++)	{		if (path[count] == _T('.'))		{			found_dot = TRUE;			break;		}	}	if (found_dot)		_tcscat (path, _T("*"));	else		_tcscat (path, _T("*.*"));	/* current fname */	curplace = 0;	hFile = FindFirstFile (path, &file);	if (hFile != INVALID_HANDLE_VALUE)	{		/* find anything */		do		{			/* ignore "." and ".." */			if (!_tcscmp (file.cFileName, _T(".")) ||				!_tcscmp (file.cFileName, _T("..")))				continue;			_tcscpy (fname, file.cFileName);			if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)				_tcscat (fname, _T("\\"));			else				_tcscat (fname, _T(" "));			if (!maxmatch[0] && perfectmatch)			{				_tcscpy(maxmatch, fname);			}			else			{				for (count = 0; maxmatch[count] && fname[count]; count++)				{					if (tolower(maxmatch[count]) != tolower(fname[count]))					{						perfectmatch = FALSE;						maxmatch[count] = 0;						break;					}				}			}		}		while (FindNextFile (hFile, &file));		FindClose (hFile);                if( perfectmatch )                {		    str[start] = _T('\"');		    _tcscpy (&str[start+1], directory);		    _tcscat (&str[start], maxmatch);                    _tcscat (&str[start], _T("\"") );                }		else			MessageBeep (-1);	}	else	{		/* no match found - search for internal command */		for (cmds_ptr = cmds; cmds_ptr->name; cmds_ptr++)		{			if (!_tcsnicmp (&str[start], cmds_ptr->name,				_tcslen (&str[start])))			{				/* return the mach only if it is unique */				if (_tcsnicmp (&str[start], (cmds_ptr+1)->name, _tcslen (&str[start])))					_tcscpy (&str[start], cmds_ptr->name);				break;			}		}		MessageBeep (-1);	}}/* * returns 1 if at least one match, else returns 0 */BOOL ShowCompletionMatches (LPTSTR str, INT charcount){	WIN32_FIND_DATA file;	HANDLE hFile;	BOOL  found_dot = FALSE;	INT   curplace = 0;	INT   start;	INT   count;	TCHAR path[MAX_PATH];	TCHAR fname[MAX_PATH];	TCHAR directory[MAX_PATH];	/* expand current file name */	count = charcount - 1;	if (count < 0)		count = 0;	/* find front of word */	while (count > 0 && str[count] != _T(' '))		count--;	/* if not at beginning, go forward 1 */	if (str[count] == _T(' '))		count++;	start = count;	/* extract directory from word */	_tcscpy (directory, &str[start]);	curplace = _tcslen (directory) - 1;	while (curplace >= 0 &&		   directory[curplace] != _T('\\') &&		   directory[curplace] != _T(':'))	{		directory[curplace] = 0;		curplace--;	}	_tcscpy (path, &str[start]);	/* look for a . in the filename */	for (count = _tcslen (directory); path[count] != _T('\0'); count++)	{		if (path[count] == _T('.'))		{			found_dot = TRUE;			break;		}	}	if (found_dot)		_tcscat (path, _T("*"));	else		_tcscat (path, _T("*.*"));	/* current fname */	curplace = 0;	hFile = FindFirstFile (path, &file);	if (hFile != INVALID_HANDLE_VALUE)	{		/* find anything */		ConOutChar (_T('\n'));		count = 0;		do		{			/* ignore . and .. */			if (!_tcscmp (file.cFileName, _T(".")) || 				!_tcscmp (file.cFileName, _T("..")))				continue;			if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)				_stprintf (fname, _T("[%s]"), file.cFileName);			else				_tcscpy (fname, file.cFileName);			ConOutPrintf (_T("%-14s"), fname);			if (++count == 5)			{				ConOutChar (_T('\n'));				count = 0;			}		}		while (FindNextFile (hFile, &file));		FindClose (hFile);		if (count)			ConOutChar (_T('\n'));	}	else	{		/* no match found */		MessageBeep (-1);		return FALSE;	}	return TRUE;}#endif#ifdef FEATURE_4NT_FILENAME_COMPLETION//static VOID BuildFilenameMatchList (...)// VOID CompleteFilenameNext (LPTSTR, INT)// VOID CompleteFilenamePrev (LPTSTR, INT)// VOID RemoveFilenameMatchList (VOID)#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -