Fix CD bug for

CD "program files"
cd did only working with CD program files 
now it support ""

svn path=/trunk/; revision=15410
This commit is contained in:
Magnus Olsen 2005-05-19 15:32:22 +00:00
parent 2df4b9dc13
commit 765b83b774

View file

@ -156,8 +156,7 @@ 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 lpOldPath; LPTSTR lpOldPath;
LPTSTR endofstring; /* pointer to the null character in the directory to change to */ size_t size, str_len;
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, /*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*/ but on the other hand paths are generally not very long*/
@ -172,16 +171,28 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
/* Is it safe to change the characters param is pointing to? I presume it is, as there doesn't seem to be any /* 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?) */ post-processing of it after the function call (what would that accomplish?) */
dir=param; size = _tcscspn(param, _T("\"") );
endofstring=dir+_tcslen(dir); str_len = _tcslen(param)-1;
while ((lastquote = _tcsrchr(dir, _T('\"')))) if ((param[size] == _T('"')) && (str_len >1))
{ {
endofstring--;
memmove(lastquote,lastquote+1,endofstring-lastquote); if (size==0)
*endofstring=_T('\0'); {
_tcsncpy(param,&param[size+1],str_len);
param[str_len] = _T('\0');
}
size = _tcscspn(param, _T("\"") );
if (param[size] == _T('"'))
{
param[size] = _T('\0');
}
} }
dir=param;
/* if doing a CD and no parameters given, print out current directory */ /* if doing a CD and no parameters given, print out current directory */
if (!dir || !dir[0]) if (!dir || !dir[0])
{ {