mirror of
https://github.com/reactos/reactos.git
synced 2024-08-08 04:08:29 +00:00
Improved command line completion. Patch by Marc Schuetz.
svn path=/trunk/; revision=4591
This commit is contained in:
parent
01a868d4b8
commit
8b4929f41e
|
@ -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.
|
* CMD.C - command-line interface.
|
||||||
*
|
*
|
||||||
|
@ -245,8 +245,8 @@ Execute (LPTSTR first, LPTSTR rest)
|
||||||
stui.wShowWindow = SW_SHOWDEFAULT;
|
stui.wShowWindow = SW_SHOWDEFAULT;
|
||||||
|
|
||||||
// return console to standard mode
|
// return console to standard mode
|
||||||
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
|
SetConsoleMode (GetStdHandle(STD_INPUT_HANDLE),
|
||||||
ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
|
ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
|
||||||
|
|
||||||
if (CreateProcess (szFullName,
|
if (CreateProcess (szFullName,
|
||||||
szFullCmdLine,
|
szFullCmdLine,
|
||||||
|
@ -321,9 +321,21 @@ DoCommand (LPTSTR line)
|
||||||
/* Anything to do ? */
|
/* Anything to do ? */
|
||||||
if (*rest)
|
if (*rest)
|
||||||
{
|
{
|
||||||
/* Copy over 1st word as lower case */
|
if (*rest == _T('"'))
|
||||||
while (!IsDelimiter (*rest))
|
{
|
||||||
*cp++ = _totlower (*rest++);
|
/* treat quoted words specially */
|
||||||
|
|
||||||
|
rest++;
|
||||||
|
|
||||||
|
while(*rest != _T('\0') && *rest != _T('"'))
|
||||||
|
*cp++ = _totlower (*rest++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (!IsDelimiter (*rest))
|
||||||
|
*cp++ = _totlower (*rest++);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Terminate first word */
|
/* Terminate first word */
|
||||||
*cp = _T('\0');
|
*cp = _T('\0');
|
||||||
|
|
|
@ -288,7 +288,9 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
||||||
case VK_TAB:
|
case VK_TAB:
|
||||||
#ifdef FEATURE_UNIX_FILENAME_COMPLETION
|
#ifdef FEATURE_UNIX_FILENAME_COMPLETION
|
||||||
/* expand current file name */
|
/* 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)
|
if (wLastKey != VK_TAB)
|
||||||
{
|
{
|
||||||
|
@ -297,10 +299,18 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
||||||
charcount = _tcslen (str);
|
charcount = _tcslen (str);
|
||||||
current = charcount;
|
current = charcount;
|
||||||
|
|
||||||
|
if (current > 0 &&
|
||||||
|
str[current-1] == _T('"'))
|
||||||
|
current--;
|
||||||
|
|
||||||
SetCursorXY (orgx, orgy);
|
SetCursorXY (orgx, orgy);
|
||||||
ConOutPrintf (_T("%s"), str);
|
ConOutPrintf (_T("%s"), str);
|
||||||
if ((_tcslen (str) > (USHORT)(maxx - orgx)) && (orgy == maxy + 1))
|
if ((charcount > (USHORT)(maxx - orgx)) && (orgy == maxy + 1))
|
||||||
orgy--;
|
orgy--;
|
||||||
|
|
||||||
|
/* set cursor position */
|
||||||
|
SetCursorXY ((orgx + current) % maxx,
|
||||||
|
orgy + (orgx + current) / maxx);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -310,6 +320,10 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
||||||
PrintPrompt ();
|
PrintPrompt ();
|
||||||
GetCursorXY (&orgx, &orgy);
|
GetCursorXY (&orgx, &orgy);
|
||||||
ConOutPrintf (_T("%s"), str);
|
ConOutPrintf (_T("%s"), str);
|
||||||
|
|
||||||
|
/* set cursor position */
|
||||||
|
SetCursorXY ((orgx + current) % maxx,
|
||||||
|
orgy + (orgx + current) / maxx);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,17 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
/* find front of word */
|
/* find front of word */
|
||||||
while (count > 0 && str[count] != _T(' '))
|
if (str[count] == _T('"'))
|
||||||
|
{
|
||||||
count--;
|
count--;
|
||||||
|
while (count > 0 && str[count] != _T('"'))
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (count > 0 && str[count] != _T(' '))
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
|
||||||
/* if not at beginning, go forward 1 */
|
/* if not at beginning, go forward 1 */
|
||||||
if (str[count] == _T(' '))
|
if (str[count] == _T(' '))
|
||||||
|
@ -57,9 +66,18 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
|
||||||
|
|
||||||
start = count;
|
start = count;
|
||||||
|
|
||||||
|
if (str[count] == _T('"'))
|
||||||
|
count++; /* don't increment start */
|
||||||
|
|
||||||
/* extract directory from word */
|
/* extract directory from word */
|
||||||
_tcscpy (directory, &str[start]);
|
_tcscpy (directory, &str[count]);
|
||||||
curplace = _tcslen (directory) - 1;
|
curplace = _tcslen (directory) - 1;
|
||||||
|
|
||||||
|
if (curplace >= 0 && directory[curplace] == _T('"'))
|
||||||
|
directory[curplace--] = _T('\0');
|
||||||
|
|
||||||
|
_tcscpy (path, directory);
|
||||||
|
|
||||||
while (curplace >= 0 && directory[curplace] != _T('\\') &&
|
while (curplace >= 0 && directory[curplace] != _T('\\') &&
|
||||||
directory[curplace] != _T(':'))
|
directory[curplace] != _T(':'))
|
||||||
{
|
{
|
||||||
|
@ -67,8 +85,6 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
|
||||||
curplace--;
|
curplace--;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tcscpy (path, &str[start]);
|
|
||||||
|
|
||||||
/* look for a '.' in the filename */
|
/* look for a '.' in the filename */
|
||||||
for (count = _tcslen (directory); path[count] != _T('\0'); count++)
|
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)
|
if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
_tcscat (fname, _T("\\"));
|
_tcscat (fname, _T("\\"));
|
||||||
else
|
|
||||||
_tcscat (fname, _T(" "));
|
|
||||||
|
|
||||||
if (!maxmatch[0] && perfectmatch)
|
if (!maxmatch[0] && perfectmatch)
|
||||||
{
|
{
|
||||||
|
@ -120,25 +134,49 @@ VOID CompleteFilename (LPTSTR str, INT charcount)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maxmatch[count] == _T('\0') &&
|
||||||
|
fname[count] != _T('\0'))
|
||||||
|
perfectmatch = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (FindNextFile (hFile, &file));
|
while (FindNextFile (hFile, &file));
|
||||||
|
|
||||||
FindClose (hFile);
|
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
|
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__
|
#ifdef __REACTOS__
|
||||||
Beep (440, 50);
|
Beep (440, 50);
|
||||||
#else
|
#else
|
||||||
MessageBeep (-1);
|
MessageBeep (-1);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -186,8 +224,17 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
/* find front of word */
|
/* find front of word */
|
||||||
while (count > 0 && str[count] != _T(' '))
|
if (str[count] == _T('"'))
|
||||||
|
{
|
||||||
count--;
|
count--;
|
||||||
|
while (count > 0 && str[count] != _T('"'))
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (count > 0 && str[count] != _T(' '))
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
|
||||||
/* if not at beginning, go forward 1 */
|
/* if not at beginning, go forward 1 */
|
||||||
if (str[count] == _T(' '))
|
if (str[count] == _T(' '))
|
||||||
|
@ -195,9 +242,18 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
|
||||||
|
|
||||||
start = count;
|
start = count;
|
||||||
|
|
||||||
|
if (str[count] == _T('"'))
|
||||||
|
count++; /* don't increment start */
|
||||||
|
|
||||||
/* extract directory from word */
|
/* extract directory from word */
|
||||||
_tcscpy (directory, &str[start]);
|
_tcscpy (directory, &str[count]);
|
||||||
curplace = _tcslen (directory) - 1;
|
curplace = _tcslen (directory) - 1;
|
||||||
|
|
||||||
|
if (curplace >= 0 && directory[curplace] == _T('"'))
|
||||||
|
directory[curplace--] = _T('\0');
|
||||||
|
|
||||||
|
_tcscpy (path, directory);
|
||||||
|
|
||||||
while (curplace >= 0 &&
|
while (curplace >= 0 &&
|
||||||
directory[curplace] != _T('\\') &&
|
directory[curplace] != _T('\\') &&
|
||||||
directory[curplace] != _T(':'))
|
directory[curplace] != _T(':'))
|
||||||
|
@ -206,8 +262,6 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
|
||||||
curplace--;
|
curplace--;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tcscpy (path, &str[start]);
|
|
||||||
|
|
||||||
/* look for a . in the filename */
|
/* look for a . in the filename */
|
||||||
for (count = _tcslen (directory); path[count] != _T('\0'); count++)
|
for (count = _tcslen (directory); path[count] != _T('\0'); count++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue