@@ -341,14 +341,12 @@ INT cmd_copy(LPTSTR param)
341
341
WIN32_FIND_DATA findBuffer ;
342
342
HANDLE hFile = NULL ;
343
343
BOOL bTouch = FALSE;
344
- /* Used when something like "copy c*.exe d*.exe" during the process of
345
- figuring out the new name */
346
344
/* Pointer to keep track of how far through the append input(file1+file2+file3) we are */
347
345
TCHAR * appendPointer = _T ("\0" );
348
346
/* The full path to src and dest. This has drive letter, folders, and filename */
349
347
TCHAR tmpDestPath [MAX_PATH ];
350
348
TCHAR tmpSrcPath [MAX_PATH ];
351
- /* A bool on weather or not the destination name will be taking from the input */
349
+ /* A bool to know whether or not the destination name will be taken from the input */
352
350
BOOL bSrcName = FALSE;
353
351
/* Seems like a waste but it is a pointer used to copy from input to PreserveName */
354
352
TCHAR * UseThisName ;
@@ -357,6 +355,7 @@ INT cmd_copy(LPTSTR param)
357
355
int size ;
358
356
TCHAR * szTouch ;
359
357
BOOL bHasWildcard , bDone = FALSE, bMoreFiles = FALSE;
358
+ /* Used for something like "copy c*.exe d*.exe" */
360
359
BOOL bMultipleSource = FALSE, bMultipleDest = FALSE;
361
360
362
361
@@ -369,7 +368,7 @@ INT cmd_copy(LPTSTR param)
369
368
370
369
nErrorLevel = 0 ;
371
370
372
- /* Get the envor value if it exists */
371
+ /* Get the env variable value if it exists */
373
372
evar = cmd_alloc (512 * sizeof (TCHAR ));
374
373
if (evar == NULL )
375
374
size = 0 ;
@@ -578,27 +577,27 @@ INT cmd_copy(LPTSTR param)
578
577
bMultipleSource = TRUE;
579
578
}
580
579
581
- /* Reusing the number of files variable */
580
+ /* Reuse the number of files variable */
582
581
nFiles = 0 ;
583
582
584
583
/* Check if no destination argument is passed */
585
584
if (nDes == -1 )
586
585
{
587
586
/* If no destination was entered then just use
588
587
the current directory as the destination */
589
- GetCurrentDirectory (MAX_PATH , szDestPath );
588
+ GetCurrentDirectory (ARRAYSIZE ( szDestPath ) , szDestPath );
590
589
}
591
590
else
592
591
{
593
592
/* Check if the destination is 'x:' */
594
593
if ((arg [nDes ][1 ] == _T (':' )) && (arg [nDes ][2 ] == _T ('\0' )))
595
594
{
596
- GetRootPath (arg [nDes ], szDestPath , MAX_PATH );
595
+ GetRootPath (arg [nDes ], szDestPath , ARRAYSIZE ( szDestPath ) );
597
596
}
598
597
else
599
598
{
600
599
/* If the user entered two file names then form the full string path */
601
- GetFullPathName (arg [nDes ], MAX_PATH , szDestPath , NULL );
600
+ GetFullPathName (arg [nDes ], ARRAYSIZE ( szDestPath ) , szDestPath , NULL );
602
601
}
603
602
604
603
/* Make sure there is an ending slash to the path if the dest is a folder */
@@ -618,12 +617,12 @@ INT cmd_copy(LPTSTR param)
618
617
}
619
618
}
620
619
621
- if (nDes != -1 ) /* you can only append files when there is a destination */
620
+ if (nDes != -1 ) /* Append files only when there is a destination */
622
621
{
623
622
if (bMultipleSource && !bMultipleDest )
624
623
{
625
624
/* We have multiple source files, but not multiple destination
626
- files. This means we are appending the soruce files. */
625
+ files. This means we are appending the source files. */
627
626
bAppend = TRUE;
628
627
if (_tcschr (arg [nSrc ], _T ('|' )) != NULL )
629
628
appendPointer = arg [nSrc ];
@@ -662,7 +661,7 @@ INT cmd_copy(LPTSTR param)
662
661
szSrcPath [0 ] = _T ('\0' );
663
662
664
663
/* Loop through the source file name and copy all
665
- the chars one at a time until it gets too + */
664
+ the chars one at a time until we reach the separator */
666
665
while (TRUE)
667
666
{
668
667
if (appendPointer [0 ] == _T ('|' ))
@@ -685,7 +684,7 @@ INT cmd_copy(LPTSTR param)
685
684
{
686
685
/* Only time there is a , in the source is when they are using touch
687
686
Cant have a destination and can only have on ,, at the end of the string
688
- Cant have more then one file name */
687
+ Cant have more than one file name */
689
688
szTouch = _tcsstr (arg [nSrc ], _T ("|" ));
690
689
if (_tcsncmp (szTouch ,_T ("|,,\0" ), 4 ) || (nDes != -1 ))
691
690
{
@@ -714,8 +713,8 @@ INT cmd_copy(LPTSTR param)
714
713
}
715
714
716
715
717
- /* From this point on, we can assume that the shortest path is 3 letters long
718
- and that would be [DriveLetter]:\ */
716
+ /* From this point on, we can assume that the shortest path is
717
+ 3 letters long and that would be [DriveLetter]:\ */
719
718
720
719
/* Check if the path has a wildcard */
721
720
bHasWildcard = (_tcschr (szSrcPath , _T ('*' )) != NULL );
@@ -742,10 +741,10 @@ INT cmd_copy(LPTSTR param)
742
741
/* Get a list of all the files */
743
742
hFile = FindFirstFile (szSrcPath , & findBuffer );
744
743
745
- /* If it couldnt open the file handle, print out the error */
744
+ /* If we could not open the file handle, print out the error */
746
745
if (hFile == INVALID_HANDLE_VALUE )
747
746
{
748
- /* only print source name when more then one file */
747
+ /* only print source name when more than one file */
749
748
if (bMultipleSource )
750
749
ConOutPrintf (_T ("%s\n" ), szSrcPath );
751
750
@@ -757,10 +756,12 @@ INT cmd_copy(LPTSTR param)
757
756
758
757
/* Strip the paths back to the folder they are in */
759
758
for (i = (_tcslen (szSrcPath ) - 1 ); i > -1 ; i -- )
759
+ {
760
760
if (szSrcPath [i ] != _T ('\\' ))
761
761
szSrcPath [i ] = _T ('\0' );
762
762
else
763
763
break ;
764
+ }
764
765
765
766
do
766
767
{
@@ -803,7 +804,7 @@ INT cmd_copy(LPTSTR param)
803
804
_tcscat (tmpDestPath , findBuffer .cFileName );
804
805
else
805
806
{
806
- /* If there is no wildcard you can use the name the user entered */
807
+ /* If there is no wildcard, use the name the user entered */
807
808
if ((_tcschr (UseThisName , _T ('*' )) == NULL ) &&
808
809
(_tcschr (UseThisName , _T ('?' )) == NULL ))
809
810
{
@@ -836,7 +837,7 @@ INT cmd_copy(LPTSTR param)
836
837
break ;
837
838
}
838
839
839
- /* only print source name when more then one file */
840
+ /* only print source name when more than one file */
840
841
if (bMultipleSource )
841
842
ConOutPrintf (_T ("%s\n" ), tmpSrcPath );
842
843
@@ -848,11 +849,10 @@ INT cmd_copy(LPTSTR param)
848
849
if (nOverwrite == PROMPT_ALL || (nOverwrite == PROMPT_YES && bAppend ))
849
850
dwFlags |= COPY_NO_PROMPT ;
850
851
851
- /* Tell weather the copy was successful or not */
852
+ /* Tell whether the copy was successful or not */
852
853
if (copy (tmpSrcPath ,tmpDestPath , bAppend , dwFlags , bTouch ))
853
854
{
854
855
nFiles ++ ;
855
- //LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR1, szMsg, ARRAYSIZE(szMsg));
856
856
}
857
857
else
858
858
{
@@ -865,14 +865,14 @@ INT cmd_copy(LPTSTR param)
865
865
/* Loop through all wildcard files */
866
866
} while (FindNextFile (hFile , & findBuffer ));
867
867
868
+ FindClose (hFile );
869
+
868
870
/* Loop through all files in src string with a + */
869
- } while (!bDone );
871
+ } while (!bDone );
870
872
871
873
/* print out the number of files copied */
872
874
ConOutResPrintf (STRING_COPY_FILE , bAppend ? 1 : nFiles );
873
875
874
- if (hFile ) FindClose (hFile );
875
-
876
876
if (arg != NULL )
877
877
freep (arg );
878
878
0 commit comments