From ece4aa3f3fc709ce4cb852b60608027d069f652c Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 14 Apr 2012 21:35:58 +0000 Subject: [PATCH] [CMD] Handle the + character only optionally as a token seperator, so that other commands like rename are not affected. svn path=/trunk/; revision=56349 --- reactos/base/shell/cmd/attrib.c | 2 +- reactos/base/shell/cmd/chcp.c | 2 +- reactos/base/shell/cmd/choice.c | 2 +- reactos/base/shell/cmd/cmd.h | 2 +- reactos/base/shell/cmd/copy.c | 2 +- reactos/base/shell/cmd/date.c | 2 +- reactos/base/shell/cmd/del.c | 4 +- reactos/base/shell/cmd/free.c | 2 +- reactos/base/shell/cmd/internal.c | 4 +- reactos/base/shell/cmd/misc.c | 4 +- reactos/base/shell/cmd/mklink.c | 2 +- reactos/base/shell/cmd/ren.c | 138 +++++++++++++++--------------- reactos/base/shell/cmd/replace.c | 2 +- reactos/base/shell/cmd/time.c | 2 +- reactos/base/shell/cmd/timer.c | 2 +- reactos/base/shell/cmd/type.c | 2 +- 16 files changed, 87 insertions(+), 87 deletions(-) diff --git a/reactos/base/shell/cmd/attrib.c b/reactos/base/shell/cmd/attrib.c index 2778ba5cc0d..8b619d06a8f 100644 --- a/reactos/base/shell/cmd/attrib.c +++ b/reactos/base/shell/cmd/attrib.c @@ -213,7 +213,7 @@ INT CommandAttrib (LPTSTR param) nErrorLevel = 0; /* build parameter array */ - arg = split (param, &argc, FALSE); + arg = split (param, &argc, FALSE, FALSE); /* check for options */ for (i = 0; i < argc; i++) diff --git a/reactos/base/shell/cmd/chcp.c b/reactos/base/shell/cmd/chcp.c index b834f231b41..92ddb8ee6aa 100644 --- a/reactos/base/shell/cmd/chcp.c +++ b/reactos/base/shell/cmd/chcp.c @@ -33,7 +33,7 @@ INT CommandChcp (LPTSTR param) nErrorLevel = 0; /* get parameters */ - arg = split (param, &args, FALSE); + arg = split (param, &args, FALSE, FALSE); if (args == 0) { diff --git a/reactos/base/shell/cmd/choice.c b/reactos/base/shell/cmd/choice.c index 6b2c490ea27..3503e7db8f2 100644 --- a/reactos/base/shell/cmd/choice.c +++ b/reactos/base/shell/cmd/choice.c @@ -150,7 +150,7 @@ CommandChoice (LPTSTR param) } /* build parameter array */ - arg = split (param, &argc, FALSE); + arg = split (param, &argc, FALSE, FALSE); /* evaluate arguments */ if (argc > 0) diff --git a/reactos/base/shell/cmd/cmd.h b/reactos/base/shell/cmd/cmd.h index 9344ac9372f..25df5889d7a 100644 --- a/reactos/base/shell/cmd/cmd.h +++ b/reactos/base/shell/cmd/cmd.h @@ -332,7 +332,7 @@ BOOL SetRootPath(TCHAR *oldpath,TCHAR *InPath); TCHAR cgetchar (VOID); BOOL CheckCtrlBreak (INT); BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry); -LPTSTR *split (LPTSTR, LPINT, BOOL); +LPTSTR *split (LPTSTR, LPINT, BOOL, BOOL); LPTSTR *splitspace (LPTSTR, LPINT); VOID freep (LPTSTR *); LPTSTR _stpcpy (LPTSTR, LPCTSTR); diff --git a/reactos/base/shell/cmd/copy.c b/reactos/base/shell/cmd/copy.c index 6f975f1c3e7..9037f64f693 100644 --- a/reactos/base/shell/cmd/copy.c +++ b/reactos/base/shell/cmd/copy.c @@ -438,7 +438,7 @@ INT cmd_copy(LPTSTR param) /* Split the user input into array */ - arg = split(param, &argc, FALSE); + arg = split(param, &argc, FALSE, TRUE); nFiles = argc; /* Read switches and count files */ diff --git a/reactos/base/shell/cmd/date.c b/reactos/base/shell/cmd/date.c index 8c093877bcd..05548c4001f 100644 --- a/reactos/base/shell/cmd/date.c +++ b/reactos/base/shell/cmd/date.c @@ -193,7 +193,7 @@ INT cmd_date (LPTSTR param) nErrorLevel = 0; /* build parameter array */ - arg = split (param, &argc, FALSE); + arg = split (param, &argc, FALSE, FALSE); /* check for options */ for (i = 0; i < argc; i++) diff --git a/reactos/base/shell/cmd/del.c b/reactos/base/shell/cmd/del.c index bd262005be1..e19cf77b4ab 100644 --- a/reactos/base/shell/cmd/del.c +++ b/reactos/base/shell/cmd/del.c @@ -275,7 +275,7 @@ DeleteFiles(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags) } while (FindNextFile (hFile, &f)); FindClose (hFile); - } + } else error_sfile_not_found(szFullPath); return dwFiles; } @@ -385,7 +385,7 @@ INT CommandDelete (LPTSTR param) nErrorLevel = 0; - arg = split (param, &args, FALSE); + arg = split (param, &args, FALSE, FALSE); if (args == 0) { diff --git a/reactos/base/shell/cmd/free.c b/reactos/base/shell/cmd/free.c index b266ee479f5..9bf8a430ae9 100644 --- a/reactos/base/shell/cmd/free.c +++ b/reactos/base/shell/cmd/free.c @@ -106,7 +106,7 @@ INT CommandFree (LPTSTR param) else szParam = param; - arg = split (szParam, &argc, FALSE); + arg = split (szParam, &argc, FALSE, FALSE); for (i = 0; i < argc; i++) PrintDiskInfo (arg[i]); diff --git a/reactos/base/shell/cmd/internal.c b/reactos/base/shell/cmd/internal.c index fcfcde156e2..73e91d484d8 100644 --- a/reactos/base/shell/cmd/internal.c +++ b/reactos/base/shell/cmd/internal.c @@ -321,7 +321,7 @@ INT cmd_mkdir (LPTSTR param) return 0; } - p = split (param, &argc, FALSE); + p = split (param, &argc, FALSE, FALSE); if (argc == 0) { ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING); @@ -411,7 +411,7 @@ INT cmd_rmdir (LPTSTR param) return 0; } - arg = split (param, &args, FALSE); + arg = split (param, &args, FALSE, FALSE); dirCount = 0; /* check for options anywhere in command line */ diff --git a/reactos/base/shell/cmd/misc.c b/reactos/base/shell/cmd/misc.c index 4b28d7a155c..abff7482df5 100644 --- a/reactos/base/shell/cmd/misc.c +++ b/reactos/base/shell/cmd/misc.c @@ -275,7 +275,7 @@ static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern) * are spaces and slashes ('/'). */ -LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards) +LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards, BOOL handle_plus) { LPTSTR *arg; LPTSTR start; @@ -315,7 +315,7 @@ LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards) /* check for separators */ if (_istspace(*s) || (*s == _T('/')) || - (*s == _T('+'))) + (handle_plus && (*s == _T('+')))) { /* Make length at least one character */ if (s == start) s++; diff --git a/reactos/base/shell/cmd/mklink.c b/reactos/base/shell/cmd/mklink.c index 6cffe784261..f2752adb6bc 100644 --- a/reactos/base/shell/cmd/mklink.c +++ b/reactos/base/shell/cmd/mklink.c @@ -132,7 +132,7 @@ cmd_mklink(LPTSTR param) return 0; } - arg = split(param, &argc, FALSE); + arg = split(param, &argc, FALSE, FALSE); for (i = 0; i < argc; i++) { if (arg[i][0] == _T('/')) diff --git a/reactos/base/shell/cmd/ren.c b/reactos/base/shell/cmd/ren.c index 7281760dcde..004242307ef 100644 --- a/reactos/base/shell/cmd/ren.c +++ b/reactos/base/shell/cmd/ren.c @@ -3,7 +3,7 @@ * * * History: - * + * * * 27-Jul-1998 (John P Price ) * added config.h include @@ -20,13 +20,13 @@ * 30-Apr-2005 (Magnus Olsen) ) * Remove all hardcode string to En.rc * 25-Nov-2008 (Victor Martinez) Patch dedicated to Myrjala because her comprenhension and love :D - * Fixing following Bugs: + * Fixing following Bugs: * -Wrong behavior with wildcards when Source and Destiny are Paths(FIXED). * -Wrong general behavior (MSDN:"Rename cant move files between subdirectories")(FIXED) * -Wrong behavior when renaming without path in destiny:(i.e) "ren C:\text\as.txt list.txt" it moves as.txt and then rename it(FIXED) * (MSDN: If there is a Path in Source and no Path in Destiny, then Destiny Path is Source Path,because never Ren has to be used to move.) * -Implemented checkings if SourcePath and DestinyPath are differents. - * + * */ #include @@ -59,13 +59,13 @@ INT cmd_rename (LPTSTR param) DWORD dwFiles = 0; /* number of renamedd files */ INT i; - + LPTSTR srcPattern = NULL; /* Source Argument*/ TCHAR srcPath[MAX_PATH]; /*Source Path Directories*/ LPTSTR srcFILE = NULL; /*Contains the files name(s)*/ - TCHAR srcFinal[MAX_PATH]; - - + TCHAR srcFinal[MAX_PATH]; + + LPTSTR dstPattern = NULL; /*Destiny Argument*/ TCHAR dstPath[MAX_PATH]; /*Source Path Directories*/ LPTSTR dstFILE = NULL; /*Contains the files name(s)*/ @@ -75,12 +75,12 @@ INT cmd_rename (LPTSTR param) BOOL bDstWildcard = FALSE; BOOL bPath = FALSE; - - - - - - + + + + + + LPTSTR p,q,r; HANDLE hFile; @@ -88,8 +88,8 @@ INT cmd_rename (LPTSTR param) /*If the PARAM=/? then show the help*/ if (!_tcsncmp(param, _T("/?"), 2)) { - - + + ConOutResPaging(TRUE,STRING_REN_HELP1); return 0; } @@ -97,8 +97,8 @@ INT cmd_rename (LPTSTR param) nErrorLevel = 0; /* Split the argument list.Args will be saved in arg vector*/ - arg = split(param, &args, FALSE); - + arg = split(param, &args, FALSE, FALSE); + if (args < 2) { if (!(dwFlags & REN_ERROR)) @@ -124,7 +124,7 @@ INT cmd_rename (LPTSTR param) case _T('N'): dwFlags |= REN_NOTHING; break; - + case _T('P'): dwFlags |= REN_PROMPT; break; @@ -158,8 +158,8 @@ INT cmd_rename (LPTSTR param) freep(arg); return 1; } - - + + /* Get destination pattern and source pattern*/ for (i = 0; i < args; i++) { @@ -167,16 +167,16 @@ INT cmd_rename (LPTSTR param) continue; dstPattern = arg[i]; //we save the Last argument as dstPattern srcPattern = arg[i-1]; - + } - - - - + + + + if (_tcschr(srcPattern, _T('\\'))) //Checking if the Source (srcPattern) is a Path to the file - { - + { + bPath= TRUE; //Splitting srcPath and srcFile. @@ -190,11 +190,11 @@ INT cmd_rename (LPTSTR param) if(!_tcschr(srcFILE, _T('\\'))) break; } _tcsncpy(srcPath,srcPattern,_tcslen(srcPattern)-_tcslen(srcFILE)); - - - + + + if(_tcschr(dstPattern, _T('\\'))) //Checking if the Destiny (dstPattern)is also a Path.And splitting dstPattern in dstPath and srcPath. - { + { dstFILE = _tcschr(dstPattern, _T('\\')); nSlash=0; while(_tcschr(dstFILE, _T('\\'))) @@ -204,53 +204,53 @@ INT cmd_rename (LPTSTR param) if(!_tcschr(dstFILE, _T('\\'))) break; } _tcsncpy(dstPath,dstPattern,_tcslen(dstPattern)-_tcslen(dstFILE)); - + if((_tcslen(dstPath)!=_tcslen(srcPath))||(_tcsncmp(srcPath,dstPath,_tcslen(srcPath))!=0)) //If it has a Path,then MUST be equal than srcPath { error_syntax(dstPath); freep(arg); return 1; } - }else { //If Destiny hasnt a Path,then (MSDN says) srcPath is its Path. - + }else { //If Destiny hasnt a Path,then (MSDN says) srcPath is its Path. + _tcscpy(dstPath,srcPath); - + dstFILE=dstPattern; - + } - - + + } - + if (!_tcschr(srcPattern, _T('\\'))) //If srcPattern isnt a Path but a name: - { + { srcFILE=srcPattern; if(_tcschr(dstPattern, _T('\\'))) - { + { error_syntax(dstPattern); - + freep(arg); return 1; }else dstFILE=dstPattern; } - + //Checking Wildcards. if (_tcschr(dstFILE, _T('*')) || _tcschr(dstFILE, _T('?'))) bDstWildcard = TRUE; - - - + + + TRACE("\n\nSourcePattern: %s SourcePath: %s SourceFile: %s", debugstr_aw(srcPattern),debugstr_aw(srcPath),debugstr_aw(srcFILE)); TRACE("\n\nDestinationPattern: %s Destination Path:%s Destination File: %s\n", debugstr_aw(dstPattern),debugstr_aw(dstPath),debugstr_aw(dstFILE)); - + hFile = FindFirstFile(srcPattern, &f); - + if (hFile == INVALID_HANDLE_VALUE) { if (!(dwFlags & REN_ERROR)) error_file_not_found(); - + } do { @@ -271,7 +271,7 @@ INT cmd_rename (LPTSTR param) continue; TRACE("Found source name: %s\n", debugstr_aw(f.cFileName)); - /* So here we have splitted the dstFILE and we have find a f.cFileName(thanks to srcPattern) + /* So here we have splitted the dstFILE and we have find a f.cFileName(thanks to srcPattern) * Now we have to use the mask (dstFILE) (which can have Wildcards) with f.cFileName to find destination file name(dstLast) */ p = f.cFileName; q = dstFILE; @@ -310,37 +310,37 @@ INT cmd_rename (LPTSTR param) *r = 0; //Well we have splitted the Paths,so now we have to paste them again(if needed),thanks bPath. if( bPath == TRUE) - { - + { + _tcscpy(srcFinal,srcPath); - + _tcscat(srcFinal,f.cFileName); - + _tcscpy(dstFinal,dstPath); _tcscat(dstFinal,dstLast); - - + + }else{ _tcscpy(srcFinal,f.cFileName); _tcscpy(dstFinal,dstLast); } - + TRACE("DestinationPath: %s\n", debugstr_aw(dstFinal)); - - + + if (!(dwFlags & REN_QUIET) && !(dwFlags & REN_TOTAL)) - + ConOutPrintf(_T("%s -> %s\n"),srcFinal , dstFinal); /* Rename the file */ if (!(dwFlags & REN_NOTHING)) - { - - - + { + + + if (MoveFile(srcFinal, dstFinal)) { dwFiles++; @@ -354,12 +354,12 @@ INT cmd_rename (LPTSTR param) } } } - + while (FindNextFile(hFile, &f)); //Closing and Printing errors. - + FindClose(hFile); - + if (!(dwFlags & REN_QUIET)) { @@ -368,9 +368,9 @@ INT cmd_rename (LPTSTR param) else ConOutResPrintf(STRING_REN_HELP3, dwFiles); } - + freep(arg); - + return 0; } diff --git a/reactos/base/shell/cmd/replace.c b/reactos/base/shell/cmd/replace.c index 29495cce202..01bc2ac3bdf 100644 --- a/reactos/base/shell/cmd/replace.c +++ b/reactos/base/shell/cmd/replace.c @@ -376,7 +376,7 @@ INT cmd_replace (LPTSTR param) } /* Divide the argument in to an array of c-strings */ - arg = split (param, &argc, FALSE); + arg = split (param, &argc, FALSE, FALSE); nFiles = argc; /* Read options */ diff --git a/reactos/base/shell/cmd/time.c b/reactos/base/shell/cmd/time.c index 0e608d5f68a..78ff91dfc2a 100644 --- a/reactos/base/shell/cmd/time.c +++ b/reactos/base/shell/cmd/time.c @@ -145,7 +145,7 @@ INT cmd_time (LPTSTR param) nErrorLevel = 0; /* build parameter array */ - arg = split (param, &argc, FALSE); + arg = split (param, &argc, FALSE, FALSE); /* check for options */ for (i = 0; i < argc; i++) diff --git a/reactos/base/shell/cmd/timer.c b/reactos/base/shell/cmd/timer.c index f0537771174..588e4292169 100644 --- a/reactos/base/shell/cmd/timer.c +++ b/reactos/base/shell/cmd/timer.c @@ -100,7 +100,7 @@ INT CommandTimer (LPTSTR param) nErrorLevel = 0; - p = split (param, &argc, FALSE); + p = split (param, &argc, FALSE, FALSE); //read options for (i = 0; i < argc; i++) diff --git a/reactos/base/shell/cmd/type.c b/reactos/base/shell/cmd/type.c index 86f1f41d0aa..60a17208c44 100644 --- a/reactos/base/shell/cmd/type.c +++ b/reactos/base/shell/cmd/type.c @@ -56,7 +56,7 @@ INT cmd_type (LPTSTR param) return 1; } - argv = split (param, &argc, TRUE); + argv = split (param, &argc, TRUE, FALSE); for(i = 0; i < argc; i++) {