From e4b97eb62e82a4d75a9c7c4c985d9ca83160208b Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Wed, 18 Mar 2015 14:38:24 +0000 Subject: [PATCH] Handle "copy H*.txt file.txt" correctly Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3907 --- src/shell/shell_cmds.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp index 731c3bc1..f4ef6840 100644 --- a/src/shell/shell_cmds.cpp +++ b/src/shell/shell_cmds.cpp @@ -682,13 +682,16 @@ void DOS_Shell::CMD_COPY(char * args) { if(temp) *temp = 0;//strip off *.* from target // add '\\' if target is a directory + bool target_is_file = true; if (pathTarget[strlen(pathTarget)-1]!='\\') { if (DOS_FindFirst(pathTarget,0xffff & ~DOS_ATTR_VOLUME)) { dta.GetResult(name,size,date,time,attr); - if (attr & DOS_ATTR_DIRECTORY) + if (attr & DOS_ATTR_DIRECTORY) { strcat(pathTarget,"\\"); + target_is_file = false; + } } - }; + } else target_is_file = false; //Find first sourcefile bool ret = DOS_FindFirst(const_cast(source.filename.c_str()),0xffff & ~DOS_ATTR_VOLUME); @@ -701,7 +704,8 @@ void DOS_Shell::CMD_COPY(char * args) { Bit16u sourceHandle,targetHandle; char nameTarget[DOS_PATHLENGTH]; char nameSource[DOS_PATHLENGTH]; - + + bool second_file_of_current_source = false; while (ret) { dta.GetResult(name,size,date,time,attr); @@ -714,6 +718,10 @@ void DOS_Shell::CMD_COPY(char * args) { strcpy(nameTarget,pathTarget); if (nameTarget[strlen(nameTarget)-1]=='\\') strcat(nameTarget,name); + //Special variable to ensure that copy * a_file, where a_file is not a directory concats. + bool special = second_file_of_current_source && target_is_file; + second_file_of_current_source = true; + if (special) oldsource.concat = true; //Don't create a new file when in concat mode if (oldsource.concat || DOS_CreateFile(nameTarget,0,&targetHandle)) { Bit32u dummy=0; @@ -731,7 +739,7 @@ void DOS_Shell::CMD_COPY(char * args) { failed |= DOS_CloseFile(sourceHandle); failed |= DOS_CloseFile(targetHandle); WriteOut(" %s\n",name); - if(!source.concat) count++; //Only count concat files once + if(!source.concat && !special) count++; //Only count concat files once } else { DOS_CloseFile(sourceHandle); WriteOut(MSG_Get("SHELL_CMD_COPY_FAILURE"),const_cast(target.filename.c_str()));