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. * CMD.C - command-line interface.
* *
@ -184,42 +184,20 @@ Execute (LPTSTR first, LPTSTR rest)
/* check for a drive change */ /* check for a drive change */
if ((_istalpha (first[0])) && (!_tcscmp (first + 1, _T(":")))) if ((_istalpha (first[0])) && (!_tcscmp (first + 1, _T(":"))))
{ {
TCHAR szPath[MAX_PATH]; BOOL working = TRUE;
TCHAR szVar[5]; if (!SetCurrentDirectory(first))
/* Guess they changed disc or something, handle that gracefully and get to root */
#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)
{ {
/* no environment variable found */ TCHAR str[4];
_tcscpy (szPath, _T("A:\\")); str[0]=first[0];
szPath[0] = _totupper (*first); str[1]=':';
str[2]='\\';
str[3]=0;
working = SetCurrentDirectory(str);
} }
#ifdef _DEBUG if (!working) ConErrPuts (INVALIDDRIVE);
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);
return; return;
} }

View file

@ -152,7 +152,6 @@ VOID FreeLastPath (VOID)
free (lpLastPath); free (lpLastPath);
} }
/* /*
* CD / CHDIR * CD / CHDIR
* *
@ -160,10 +159,12 @@ VOID FreeLastPath (VOID)
INT cmd_chdir (LPTSTR cmd, LPTSTR param) INT cmd_chdir (LPTSTR cmd, LPTSTR param)
{ {
LPTSTR dir; /* pointer to the directory to change to */ LPTSTR dir; /* pointer to the directory to change to */
LPTSTR place; /* used to search for the \ when no space is used */
LPTSTR lpOldPath; LPTSTR lpOldPath;
LPTSTR *arg = NULL; LPTSTR endofstring; /* pointer to the null character in the directory to change to */
INT argc; 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)) if (!_tcsncmp (param, _T("/?"), 2))
{ {
@ -179,33 +180,18 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
return 0; return 0;
} }
/* check if there is no space between the command and the path */ /* The whole param string is our parameter these days. The only thing we do is eliminating every quotation mark */
if (param[0] == _T('\0')) /* 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?) */
/* 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;
if (*place) dir=param;
dir = place; endofstring=dir+_tcslen(dir);
else
/* signal that there are no parameters */
dir = NULL;
}
else
{
arg = split (param, &argc);
if (argc > 1) while (lastquote = _tcsrchr(dir,'\"'))
{ {
/*JPP 20-Jul-1998 use standard error message */ endofstring--;
error_too_many_parameters (param); memmove(lastquote,lastquote+1,endofstring-lastquote);
freep (arg); *endofstring=_T('\0');
return 1;
}
else
dir = arg[0];
} }
/* if doing a CD and no parameters given, print out current directory */ /* 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); ConOutPuts (szPath);
freep (arg);
return 0; return 0;
} }
@ -227,12 +212,9 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
if (lpLastPath) if (lpLastPath)
dir = lpLastPath; dir = lpLastPath;
else else
{
freep (arg);
return 0; 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 szRoot[3] = _T("A:");
TCHAR szPath[MAX_PATH]; TCHAR szPath[MAX_PATH];
@ -249,7 +231,6 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
ConOutPuts (szPath); ConOutPuts (szPath);
freep (arg);
return 0; return 0;
} }
@ -271,17 +252,23 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
free (lpOldPath); free (lpOldPath);
lpOldPath = NULL; lpOldPath = NULL;
freep (arg);
return 1; return 1;
} }
else else
{ {
if (lpLastPath) if (towupper(dir[0])!=lpOldPath[0])
free (lpLastPath); {
lpLastPath = lpOldPath; SetCurrentDirectory(lpOldPath);
free(lpOldPath);
}
else
{
if (lpLastPath)
free (lpLastPath);
lpLastPath = lpOldPath;
}
} }
freep (arg);
return 0; return 0;
} }