cmd update:
[reactos.git] / reactos / subsys / system / cmd / internal.c
index 318b6b3..926f74b 100644 (file)
  *
  *    23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
  *        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.
  */
 
-#include "config.h"
-
 #include "precomp.h"
-#include <tchar.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-
+#include "resource.h"
 
 #ifdef INCLUDE_CMD_CHDIR
 
@@ -158,50 +156,64 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
 {
        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 */
+       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))
        {
-               ConOutPuts (_T("Changes the current directory or displays it's name\n\n"
-                                          "CHDIR [drive:][path]\n"
-                                          "CHDIR[..|-]\n"
-                                          "CD [drive:][path]\n"
-                                          "CD[..|-]\n\n"
-                                          "  ..   parent directory\n"
-                                          "  -    previous directory\n\n"
-                                          "Type CD drive: to display the current directory on the specified drive.\n"
-                                          "Type CD without a parameter to display the current drive and directory."));
+               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,&param[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;
        }
 
@@ -244,9 +256,52 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param)
 
        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;
@@ -288,11 +343,9 @@ INT cmd_mkdir (LPTSTR cmd, LPTSTR param)
        LPTSTR *p = NULL;
        INT argc;
 
-
        if (!_tcsncmp (param, _T("/?"), 2))
        {
-               ConOutPuts (_T("Creates a directory.\n\n"
-                                          "MKDIR [drive:]path\nMD [drive:]path"));
+               ConOutResPuts(STRING_MKDIR_HELP);
                return 0;
        }
 
@@ -327,7 +380,7 @@ INT cmd_mkdir (LPTSTR cmd, LPTSTR param)
 
        if (!dir)
        {
-               ConErrPrintf (_T("Required parameter missing\n"));
+               ConErrResPuts (STRING_ERROR_REQ_PARAM_MISSING);
                return 1;
        }
 
@@ -365,8 +418,7 @@ INT cmd_rmdir (LPTSTR cmd, LPTSTR param)
 
        if (!_tcsncmp (param, _T("/?"), 2))
        {
-               ConOutPuts (_T("Removes a directory.\n\n"
-                                          "RMDIR [drive:]path\nRD [drive:]path"));
+               ConOutResPuts(STRING_RMDIR_HELP);
                return 0;
        }
 
@@ -400,7 +452,7 @@ INT cmd_rmdir (LPTSTR cmd, LPTSTR param)
 
        if (!dir)
        {
-               ConErrPrintf (_T("Required parameter missing\n"));
+               ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
                return 1;
        }
 
@@ -431,7 +483,7 @@ INT CommandExit (LPTSTR cmd, LPTSTR param)
 {
        if (!_tcsncmp (param, _T("/?"), 2))
        {
-               ConOutPuts (_T("Exits the command line interpreter.\n\nEXIT"));
+               ConOutResPuts(STRING_EXIT_HELP);
                return 0;
        }
 
@@ -449,8 +501,7 @@ INT CommandRem (LPTSTR cmd, LPTSTR param)
 {
        if (!_tcsncmp (param, _T("/?"), 2))
        {
-               ConOutPuts (_T("Starts a comment line in a batch file.\n\n"
-                              "REM [Comment]"));
+               ConOutResPuts(STRING_REM_HELP);
        }
 
        return 0;
@@ -464,4 +515,10 @@ INT CommandShowCommands (LPTSTR cmd, LPTSTR param)
        return 0;
 }
 
+INT CommandShowCommandsDetail (LPTSTR cmd, LPTSTR param)
+{
+       PrintCommandListDetail ();
+       return 0;
+}
+
 /* EOF */