* Improved chdir/cd command.
*
* 02-Apr-2004 (Magnus Olsen <magnus@greatlord.com>)
- Remove all hard code string so they can be
- translate to other langues.
+ * Remove all hard code string so they can be
+ * translate to other langues.
*/
#include "precomp.h"
{
LPTSTR dir; /* pointer to the directory to change to */
LPTSTR lpOldPath;
- 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 */
- WCHAR szMsg[RC_STRING_MAX_SIZE];
+ size_t size, str_len;
+ WIN32_FIND_DATA FileData;
+ HANDLE hSearch;
+ DWORD dwAttrs;
+ BOOL fFinished = FALSE;
+
/*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))
- {
- LoadString( GetModuleHandle(NULL), STRING_CD_HELP, (LPTSTR) szMsg,sizeof(szMsg));
- ConOutPuts (_T((LPTSTR)szMsg));
+ {
+ ConOutResPuts(STRING_CD_HELP);
return 0;
}
/* 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?) */
+
+ size = _tcscspn(param, _T("\"") );
+ str_len = _tcslen(param)-1;
- dir=param;
- endofstring=dir+_tcslen(dir);
-
- while ((lastquote = _tcsrchr(dir, _T('\"'))))
+ if ((param[size] == _T('"')) && (str_len >1))
{
- endofstring--;
- memmove(lastquote,lastquote+1,endofstring-lastquote);
- *endofstring=_T('\0');
+
+ if (size==0)
+ {
+ _tcsncpy(param,¶m[size+1],str_len);
+ param[str_len] = _T('\0');
+ }
+
+ size = _tcscspn(param, _T("\"") );
+ if (param[size] == _T('"'))
+ {
+ param[size] = _T('\0');
+ }
+
}
+ str_len = _tcslen(param);
+ if (str_len==1)
+ {
+ if (param[0] == _T('*'))
+ {
+ param[0] = _T('.');
+ }
+ }
+
+ dir=param;
+
/* if doing a CD and no parameters given, print out current directory */
if (!dir || !dir[0])
{
TCHAR szPath[MAX_PATH];
GetCurrentDirectory (MAX_PATH, szPath);
-
ConOutPuts (szPath);
-
-
return 0;
}
if (!SetCurrentDirectory (dir))
{
+
+ hSearch = FindFirstFile(dir, &FileData);
+ if (hSearch == INVALID_HANDLE_VALUE)
+ {
+ ConOutFormatMessage(GetLastError());
+ free (lpOldPath);
+ lpOldPath = NULL;
+ return 1;
+ }
+
+
+ while (!fFinished)
+ {
+ dwAttrs = GetFileAttributes(FileData.cFileName);
+#ifdef _DEBUG
+ DebugPrintf(_T("Search found folder :%s\n"),FileData.cFileName);
+#endif
+ if ((dwAttrs & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ FindClose(hSearch);
+ // change folder
+ if (!SetCurrentDirectory (FileData.cFileName))
+ {
+ ConOutFormatMessage(GetLastError());
+ free (lpOldPath);
+ lpOldPath = NULL;
+ return 1;
+ }
+
+
+ return 0;
+ }
+
+ else if (!FindNextFile(hSearch, &FileData))
+ {
+ FindClose(hSearch);
+ ConOutFormatMessage(GetLastError());
+ free (lpOldPath);
+ lpOldPath = NULL;
+ return 1;
+ }
+ }
+
//ErrorMessage (GetLastError(), _T("CD"));
ConOutFormatMessage(GetLastError());
-
+
/* throw away current directory */
free (lpOldPath);
lpOldPath = NULL;
LPTSTR place; /* used to search for the \ when no space is used */
LPTSTR *p = NULL;
INT argc;
- WCHAR szMsg[RC_STRING_MAX_SIZE];
if (!_tcsncmp (param, _T("/?"), 2))
{
- LoadString( GetModuleHandle(NULL), STRING_MKDIR_HELP, (LPTSTR) szMsg,sizeof(szMsg));
- ConOutPuts (_T((LPTSTR)szMsg));
-
+ ConOutResPuts(STRING_MKDIR_HELP);
return 0;
}
if (!dir)
{
- LoadString( GetModuleHandle(NULL), STRING_PARAM_ERROR, (LPTSTR) szMsg,sizeof(szMsg));
- ConErrPrintf (_T((LPTSTR)szMsg));
+ ConErrResPuts (STRING_ERROR_REQ_PARAM_MISSING);
return 1;
}
LPTSTR *p = NULL;
INT argc;
-
- WCHAR szMsg[RC_STRING_MAX_SIZE];
-
if (!_tcsncmp (param, _T("/?"), 2))
{
- LoadString( GetModuleHandle(NULL), STRING_RMDIR_HELP, (LPTSTR) szMsg,sizeof(szMsg));
-
- ConOutPuts (_T((LPTSTR)szMsg));
-
+ ConOutResPuts(STRING_RMDIR_HELP);
return 0;
}
if (!dir)
{
- LoadString( GetModuleHandle(NULL), STRING_PARAM_ERROR, (LPTSTR) szMsg,sizeof(szMsg));
- ConErrPrintf (_T((LPTSTR)szMsg));
-
+ ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
return 1;
}
*/
INT CommandExit (LPTSTR cmd, LPTSTR param)
{
- WCHAR szMsg[RC_STRING_MAX_SIZE];
-
if (!_tcsncmp (param, _T("/?"), 2))
{
- LoadString( GetModuleHandle(NULL), STRING_EXIT_HELP, (LPTSTR) szMsg,sizeof(szMsg));
- ConOutPuts (_T((LPTSTR)szMsg));
+ ConOutResPuts(STRING_EXIT_HELP);
return 0;
}
*/
INT CommandRem (LPTSTR cmd, LPTSTR param)
{
- WCHAR szMsg[RC_STRING_MAX_SIZE];
-
if (!_tcsncmp (param, _T("/?"), 2))
{
- LoadString( GetModuleHandle(NULL), STRING_REM_HELP, (LPTSTR) szMsg,sizeof(szMsg));
- ConOutPuts (_T((LPTSTR)szMsg));
+ ConOutResPuts(STRING_REM_HELP);
}
return 0;
return 0;
}
+INT CommandShowCommandsDetail (LPTSTR cmd, LPTSTR param)
+{
+ PrintCommandListDetail ();
+ return 0;
+}
+
/* EOF */