Removed support for current directories on several drives at once from cmd.exe. Now in NTDLL.

svn path=/trunk/; revision=1892
This commit is contained in:
Carl Nettelblad 2001-05-06 17:12:44 +00:00
parent 8efef1784a
commit 96a0d04b3b
2 changed files with 39 additions and 74 deletions

View file

@ -1,4 +1,4 @@
/* $Id: cmd.c,v 1.25 2001/04/26 11:31:33 ekohl Exp $
/* $Id: cmd.c,v 1.26 2001/05/06 17:12:44 cnettel Exp $
*
* CMD.C - command-line interface.
*
@ -185,41 +185,19 @@ Execute (LPTSTR first, LPTSTR rest)
/* check for a drive change */
if ((_istalpha (first[0])) && (!_tcscmp (first + 1, _T(":"))))
{
TCHAR szPath[MAX_PATH];
TCHAR szVar[5];
#ifdef _DEBUG
DebugPrintf ("Drive change to drive %s\n", first);
#endif
/* save curent directory in environment variable */
GetCurrentDirectory (MAX_PATH, szPath);
_tcscpy (szVar, _T("=A:"));
szVar[1] = _totupper (szPath[0]);
SetEnvironmentVariable (szVar, szPath);
/* check for current directory of new drive */
_tcscpy (szVar, _T("=A:"));
szVar[1] = _totupper (*first);
if (GetEnvironmentVariable (szVar, szPath, MAX_PATH) == 0)
BOOL working = TRUE;
if (!SetCurrentDirectory(first))
/* Guess they changed disc or something, handle that gracefully and get to root */
{
/* no environment variable found */
_tcscpy (szPath, _T("A:\\"));
szPath[0] = _totupper (*first);
TCHAR str[4];
str[0]=first[0];
str[1]=':';
str[2]='\\';
str[3]=0;
working = SetCurrentDirectory(str);
}
#ifdef _DEBUG
DebugPrintf ("Drive change to drive %s\n", szPath);
#endif
/* set new current directory */
SetCurrentDirectory (szPath);
GetCurrentDirectory (MAX_PATH, szPath);
if (szPath[0] != (TCHAR)_totupper (*first))
ConErrPuts (INVALIDDRIVE);
if (!working) ConErrPuts (INVALIDDRIVE);
return;
}

View file

@ -152,7 +152,6 @@ VOID FreeLastPath (VOID)
free (lpLastPath);
}
/*
* CD / CHDIR
*
@ -160,10 +159,12 @@ VOID FreeLastPath (VOID)
INT cmd_chdir (LPTSTR cmd, LPTSTR param)
{
LPTSTR dir; /* pointer to the directory to change to */
LPTSTR place; /* used to search for the \ when no space is used */
LPTSTR lpOldPath;
LPTSTR *arg = NULL;
INT argc;
LPTSTR endofstring; /* pointer to the null character in the directory to change to */
LPTSTR lastquote; /* pointer to the last quotation mark in the directory to change to */
/*Should we better declare a variable containing _tsclen(dir) ? It's used a few times,
but on the other hand paths are generally not very long*/
if (!_tcsncmp (param, _T("/?"), 2))
{
@ -179,33 +180,18 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
return 0;
}
/* check if there is no space between the command and the path */
if (param[0] == _T('\0'))
{
/* search for the '\', '.' or '-' so that both short & long names will work */
for (place = cmd; *place; place++)
if (*place == _T('.') || *place == _T('\\') || *place == _T('-'))
break;
/* The whole param string is our parameter these days. The only thing we do is eliminating every quotation mark */
/* Is it safe to change the characters param is pointing to? I presume it is, as there doesn't seem to be any
post-processing of it after the function call (what would that accomplish?) */
if (*place)
dir = place;
else
/* signal that there are no parameters */
dir = NULL;
}
else
{
arg = split (param, &argc);
dir=param;
endofstring=dir+_tcslen(dir);
if (argc > 1)
{
/*JPP 20-Jul-1998 use standard error message */
error_too_many_parameters (param);
freep (arg);
return 1;
}
else
dir = arg[0];
while (lastquote = _tcsrchr(dir,'\"'))
{
endofstring--;
memmove(lastquote,lastquote+1,endofstring-lastquote);
*endofstring=_T('\0');
}
/* if doing a CD and no parameters given, print out current directory */
@ -217,7 +203,6 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
ConOutPuts (szPath);
freep (arg);
return 0;
}
@ -227,12 +212,9 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
if (lpLastPath)
dir = lpLastPath;
else
{
freep (arg);
return 0;
}
}
else if (dir && _tcslen (dir) > 1 && dir[1] == _T(':'))
else if (dir && _tcslen (dir)==2 && dir[1] == _T(':'))
{
TCHAR szRoot[3] = _T("A:");
TCHAR szPath[MAX_PATH];
@ -249,7 +231,6 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
ConOutPuts (szPath);
freep (arg);
return 0;
}
@ -271,17 +252,23 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
free (lpOldPath);
lpOldPath = NULL;
freep (arg);
return 1;
}
else
{
if (lpLastPath)
free (lpLastPath);
lpLastPath = lpOldPath;
if (towupper(dir[0])!=lpOldPath[0])
{
SetCurrentDirectory(lpOldPath);
free(lpOldPath);
}
else
{
if (lpLastPath)
free (lpLastPath);
lpLastPath = lpOldPath;
}
}
freep (arg);
return 0;
}