#include <string.h>
#include <stdlib.h>
#include <ctype.h>
+#include <tchar.h>
#include "cmd.h"
#include "batch.h"
static BOOL DoSwitches (LPTSTR, LPDWORD);
-static BOOL AddFile (LPFILES, char *, int *, int *, LPDWORD);
-static BOOL AddFiles (LPFILES, char *, int *, int *, int *, LPDWORD);
+static BOOL AddFile (LPFILES, TCHAR *, int *, int *, LPDWORD);
+static BOOL AddFiles (LPFILES, TCHAR *, int *, int *, int *, LPDWORD);
static BOOL GetDestination (LPFILES, LPFILES);
-static INT ParseCommand (LPFILES, int, char **, LPDWORD);
+static INT ParseCommand (LPFILES, int, TCHAR **, LPDWORD);
static VOID DeleteFileList (LPFILES);
static INT Overwrite (LPTSTR);
}
else if (_tcslen (arg) > 2)
{
- error_too_many_parameters ("");
+ error_too_many_parameters (_T(""));
return FALSE;
}
static BOOL
-AddFile (LPFILES f, char *arg, int *source, int *dest, LPDWORD flags)
+AddFile (LPFILES f, TCHAR *arg, int *source, int *dest, LPDWORD flags)
{
if (*dest)
{
- error_too_many_parameters ("");
+ error_too_many_parameters (_T(""));
return FALSE;
}
if (*source)
static BOOL
-AddFiles (LPFILES f, char *arg, int *source, int *dest,
+AddFiles (LPFILES f, TCHAR *arg, int *source, int *dest,
int *count, LPDWORD flags)
{
- char t[128];
+ TCHAR t[128];
int j;
int k;
if (*dest)
{
- error_too_many_parameters ("");
+ error_too_many_parameters (_T(""));
return FALSE;
}
static INT
-ParseCommand (LPFILES f, int argc, char **arg, LPDWORD lpdwFlags)
+ParseCommand (LPFILES f, int argc, TCHAR **arg, LPDWORD lpdwFlags)
{
INT i;
INT dest;
INT source;
INT count;
-
+ TCHAR temp[128];
dest = 0;
source = 0;
count = 0;
source = 0;
else if (!_tcschr(arg[i], _T('+')) && source)
{
- if (!AddFile(f, arg[i], &source, &dest, lpdwFlags))
+
+// Make sure we have a clean workable path
+
+ GetFullPathName( arg[i], 128, (LPTSTR) &temp, NULL);
+// printf("A Input %s, Output %s\n", arg[i], temp);
+
+ if (!AddFile(f, (TCHAR *) &temp, &source, &dest, lpdwFlags))
return -1;
f = f->next;
count++;
}
else
{
- if (!AddFiles(f, arg[i], &source, &dest, &count, lpdwFlags))
+
+ GetFullPathName( arg[i], 128, (LPTSTR) &temp, NULL);
+// printf("B Input %s, Output %s\n", arg[i], temp);
+
+ if (!AddFiles(f, (TCHAR *) &temp, &source, &dest, &count, lpdwFlags))
return -1;
while (f->next != NULL)
f = f->next;
}
#ifdef _DEBUG
- DebugPrintf ("ParseCommand: flags has %s\n",
- *lpdwFlags & ASCII ? "ASCII" : "BINARY");
+ DebugPrintf (_T("ParseCommand: flags has %s\n"),
+ *lpdwFlags & ASCII ? _T("ASCII") : _T("BINARY"));
#endif
return count;
}
BOOL bEof = FALSE;
#ifdef _DEBUG
- DebugPrintf ("checking mode\n");
+ DebugPrintf (_T("checking mode\n"));
#endif
dwAttrib = GetFileAttributes (source);
static INT
-SetupCopy (LPFILES sources, char **p, BOOL bMultiple,
- char *drive_d, char *dir_d, char *file_d,
- char *ext_d, int *append, LPDWORD lpdwFlags)
+SetupCopy (LPFILES sources, TCHAR **p, BOOL bMultiple,
+ TCHAR *drive_d, TCHAR *dir_d, TCHAR *file_d,
+ TCHAR *ext_d, int *append, LPDWORD lpdwFlags)
{
WIN32_FIND_DATA find;
-
- char drive_s[_MAX_DRIVE];
- CHAR dir_s[_MAX_DIR];
- char file_s[_MAX_FNAME];
- char ext_s[_MAX_EXT];
- char from_merge[_MAX_PATH];
+ TCHAR drive_s[_MAX_DRIVE];
+ TCHAR dir_s[_MAX_DIR];
+ TCHAR file_s[_MAX_FNAME];
+ TCHAR ext_s[_MAX_EXT];
+ TCHAR from_merge[_MAX_PATH];
LPTSTR real_source;
LPTSTR real_dest;
BOOL bAll = FALSE;
BOOL bDone;
HANDLE hFind;
+ TCHAR temp[128];
#ifdef _DEBUG
DebugPrintf (_T("SetupCopy\n"));
#endif
- real_source = (LPTSTR)malloc (MAX_PATH);
- real_dest = (LPTSTR)malloc (MAX_PATH);
+ real_source = (LPTSTR)malloc (MAX_PATH * sizeof(TCHAR));
+ real_dest = (LPTSTR)malloc (MAX_PATH * sizeof(TCHAR));
if (!real_source || !real_dest)
{
while (sources->next != NULL)
{
- _splitpath (sources->szFile, drive_s, dir_s, file_s, ext_s);
- hFind = FindFirstFile (sources->szFile, &find);
+
+/* Force a clean full path
+*/
+ GetFullPathName( sources->szFile, 128, (LPTSTR) &temp, NULL);
+
+ _tsplitpath (sources->szFile, drive_s, dir_s, file_s, ext_s);
+
+ hFind = FindFirstFile ((TCHAR*)&temp, &find);
if (hFind == INVALID_HANDLE_VALUE)
{
error_file_not_found();
if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
goto next;
- _makepath(from_merge, drive_d, dir_d, file_d, ext_d);
+ _tmakepath(from_merge, drive_d, dir_d, file_d, ext_d);
+
if (from_merge[_tcslen(from_merge) - 1] == _T('\\'))
from_merge[_tcslen(from_merge) - 1] = 0;
+// printf("Merge %s, filename %s\n", from_merge, find.cFileName);
+
if (IsDirectory (from_merge))
{
+
+// printf("Merge DIR\n");
+
bMultiple = FALSE;
_tcscat (from_merge, _T("\\"));
_tcscat (from_merge, find.cFileName);
bMultiple = TRUE;
_tcscpy (real_dest, from_merge);
- _makepath (real_source, drive_s, dir_s, find.cFileName, NULL);
+ _tmakepath (real_source, drive_s, dir_s, find.cFileName, NULL);
#ifdef _DEBUG
- DebugPrintf (_T("copying %s -> %s (%sappending%s)\n"),
+ DebugPrintf(_T("copying %S -> %S (%Sappending%S)\n"),
real_source, real_dest,
- *append ? "" : "not ",
- sources->dwFlag & ASCII ? ", ASCII" : ", BINARY");
+ *append ? _T("") : _T("not "),
+ sources->dwFlag & ASCII ? _T(", ASCII") : _T(", BINARY"));
#endif
if (IsValidFileName (real_dest) && !bAll)
INT cmd_copy (LPTSTR first, LPTSTR rest)
{
- char **p;
- char drive_d[_MAX_DRIVE];
- char dir_d[_MAX_DIR];
- char file_d[_MAX_FNAME];
- char ext_d[_MAX_EXT];
+ TCHAR **p;
+ TCHAR drive_d[_MAX_DRIVE];
+ TCHAR dir_d[_MAX_DIR];
+ TCHAR file_d[_MAX_FNAME];
+ TCHAR ext_d[_MAX_EXT];
int argc;
int append;
bDestFound = GetDestination (sources, &dest);
if (bDestFound)
{
- _splitpath (dest.szFile, drive_d, dir_d, file_d, ext_d);
+ _tsplitpath (dest.szFile, drive_d, dir_d, file_d, ext_d);
if (IsDirectory (dest.szFile))
{
+// printf("A szFile= %s, Dir = %s, File = %s, Ext = %s\n", dest.szFile, dir_d, file_d, ext_d);
_tcscat (dir_d, file_d);
_tcscat (dir_d, ext_d);
file_d[0] = _T('\0');
else
bWildcards = FALSE;
- if (strchr(rest, '+'))
+ if (_tcschr(rest, _T('+')))
bMultiple = TRUE;
else
bMultiple = FALSE;
if (bDestFound && !bWildcards)
{
+
+// _tcscpy(sources->szFile, dest.szFile);
+
copied = SetupCopy (sources, p, bMultiple, drive_d, dir_d, file_d, ext_d, &append, &dwFlags);
}
else if (bDestFound && bWildcards)
}
else if (!bDestFound && !bMultiple)
{
- _splitpath (sources->szFile, drive_d, dir_d, file_d, ext_d);
+ _tsplitpath (sources->szFile, drive_d, dir_d, file_d, ext_d);
if (IsDirectory (sources->szFile))
{
+// printf("B File = %s, Ext = %s\n", file_d, ext_d);
+
_tcscat (dir_d, file_d);
_tcscat (dir_d, ext_d);
file_d[0] = _T('\0');
ext_d[0] = _T('\0');
}
- copied = SetupCopy (sources, p, FALSE, "", "", file_d, ext_d, &append, &dwFlags);
+ copied = SetupCopy (sources, p, FALSE, _T(""), _T(""), file_d, ext_d, &append, &dwFlags);
}
else
{
- _splitpath(sources->szFile, drive_d, dir_d, file_d, ext_d);
+ _tsplitpath(sources->szFile, drive_d, dir_d, file_d, ext_d);
if (IsDirectory (sources->szFile))
{
+// printf("C File = %s, Ext = %s\n", file_d, ext_d);
+
_tcscat (dir_d, file_d);
_tcscat (dir_d, ext_d);
file_d[0] = _T('\0');
}
DeleteFileList (sources);
- freep (p);
+ freep ((VOID*)p);
ConOutPrintf (_T(" %d file(s) copied\n"), copied);
return 1;