Improved command line completion. Patch by Marc Schuetz.

svn path=/trunk/; revision=4591
This commit is contained in:
Eric Kohl 2003-04-26 16:38:05 +00:00
parent 01a868d4b8
commit 8b4929f41e
3 changed files with 105 additions and 25 deletions

View file

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.1 2003/03/20 19:19:22 rcampbell Exp $
/* $Id: cmd.c,v 1.2 2003/04/26 16:38:05 ekohl Exp $
*
* CMD.C - command-line interface.
*
@ -245,8 +245,8 @@ Execute (LPTSTR first, LPTSTR rest)
stui.wShowWindow = SW_SHOWDEFAULT;
// return console to standard mode
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
SetConsoleMode (GetStdHandle(STD_INPUT_HANDLE),
ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
if (CreateProcess (szFullName,
szFullCmdLine,
@ -321,9 +321,21 @@ DoCommand (LPTSTR line)
/* Anything to do ? */
if (*rest)
{
/* Copy over 1st word as lower case */
while (!IsDelimiter (*rest))
*cp++ = _totlower (*rest++);
if (*rest == _T('"'))
{
/* treat quoted words specially */
rest++;
while(*rest != _T('\0') && *rest != _T('"'))
*cp++ = _totlower (*rest++);
}
else
{
while (!IsDelimiter (*rest))
*cp++ = _totlower (*rest++);
}
/* Terminate first word */
*cp = _T('\0');

View file

@ -288,7 +288,9 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
case VK_TAB:
#ifdef FEATURE_UNIX_FILENAME_COMPLETION
/* expand current file name */
if (current == charcount) /* only works at end of line*/
if ((current == charcount) ||
(current == charcount - 1 &&
str[current] == _T('"'))) /* only works at end of line*/
{
if (wLastKey != VK_TAB)
{
@ -297,10 +299,18 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
charcount = _tcslen (str);
current = charcount;
if (current > 0 &&
str[current-1] == _T('"'))
current--;
SetCursorXY (orgx, orgy);
ConOutPrintf (_T("%s"), str);
if ((_tcslen (str) > (USHORT)(maxx - orgx)) && (orgy == maxy + 1))
if ((charcount > (USHORT)(maxx - orgx)) && (orgy == maxy + 1))
orgy--;
/* set cursor position */
SetCursorXY ((orgx + current) % maxx,
orgy + (orgx + current) / maxx);
}
else
{
@ -310,6 +320,10 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
PrintPrompt ();
GetCursorXY (&orgx, &orgy);
ConOutPrintf (_T("%s"), str);
/* set cursor position */
SetCursorXY ((orgx + current) % maxx,
orgy + (orgx + current) / maxx);
}
}

View file

@ -48,8 +48,17 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
count = 0;
/* find front of word */
while (count > 0 && str[count] != _T(' '))
if (str[count] == _T('"'))
{
count--;
while (count > 0 && str[count] != _T('"'))
count--;
}
else
{
while (count > 0 && str[count] != _T(' '))
count--;
}
/* if not at beginning, go forward 1 */
if (str[count] == _T(' '))
@ -57,9 +66,18 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
start = count;
if (str[count] == _T('"'))
count++; /* don't increment start */
/* extract directory from word */
_tcscpy (directory, &str[start]);
_tcscpy (directory, &str[count]);
curplace = _tcslen (directory) - 1;
if (curplace >= 0 && directory[curplace] == _T('"'))
directory[curplace--] = _T('\0');
_tcscpy (path, directory);
while (curplace >= 0 && directory[curplace] != _T('\\') &&
directory[curplace] != _T(':'))
{
@ -67,8 +85,6 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
curplace--;
}
_tcscpy (path, &str[start]);
/* look for a '.' in the filename */
for (count = _tcslen (directory); path[count] != _T('\0'); count++)
{
@ -102,8 +118,6 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
_tcscat (fname, _T("\\"));
else
_tcscat (fname, _T(" "));
if (!maxmatch[0] && perfectmatch)
{
@ -120,25 +134,49 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
break;
}
}
if (maxmatch[count] == _T('\0') &&
fname[count] != _T('\0'))
perfectmatch = FALSE;
}
}
while (FindNextFile (hFile, &file));
FindClose (hFile);
if( perfectmatch )
{
str[start] = '\"';
_tcscpy (&str[start+1], directory);
_tcscat (&str[start], maxmatch);
_tcscat (&str[start], "\"" );
}
/* only quote if the filename contains spaces */
if (_tcschr(directory, _T(' ')) ||
_tcschr(maxmatch, _T(' ')))
{
str[start] = _T('\"');
_tcscpy (&str[start+1], directory);
_tcscat (&str[start], maxmatch);
_tcscat (&str[start], _T("\"") );
}
else
{
_tcscpy (&str[start], directory);
_tcscat (&str[start], maxmatch);
}
/* append a space if last word is not a directory */
if(perfectmatch)
{
curplace = _tcslen(&str[start]);
if(str[start+curplace-1] == _T('"'))
curplace--;
if(str[start+curplace-1] != _T('\\'))
_tcscat(&str[start], _T(" "));
}
else
{
#ifdef __REACTOS__
Beep (440, 50);
#else
MessageBeep (-1);
#endif
}
}
else
{
@ -186,8 +224,17 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
count = 0;
/* find front of word */
while (count > 0 && str[count] != _T(' '))
if (str[count] == _T('"'))
{
count--;
while (count > 0 && str[count] != _T('"'))
count--;
}
else
{
while (count > 0 && str[count] != _T(' '))
count--;
}
/* if not at beginning, go forward 1 */
if (str[count] == _T(' '))
@ -195,9 +242,18 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
start = count;
if (str[count] == _T('"'))
count++; /* don't increment start */
/* extract directory from word */
_tcscpy (directory, &str[start]);
_tcscpy (directory, &str[count]);
curplace = _tcslen (directory) - 1;
if (curplace >= 0 && directory[curplace] == _T('"'))
directory[curplace--] = _T('\0');
_tcscpy (path, directory);
while (curplace >= 0 &&
directory[curplace] != _T('\\') &&
directory[curplace] != _T(':'))
@ -206,8 +262,6 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
curplace--;
}
_tcscpy (path, &str[start]);
/* look for a . in the filename */
for (count = _tcslen (directory); path[count] != _T('\0'); count++)
{