[PATCH] CMD.exe: Remove code duplication for _splitpath
Jason Edmeades
us at edmeades.me.uk
Thu Apr 26 15:38:03 CDT 2007
Note: This makes cmd.exe pull in msvcrt, but so does native
---
programs/cmd/Makefile.in | 4 ++-
programs/cmd/batch.c | 56 +---------------------------------------------
programs/cmd/builtins.c | 10 ++++----
programs/cmd/directory.c | 8 +++---
programs/cmd/wcmd.h | 2 -
5 files changed, 13 insertions(+), 67 deletions(-)
diff --git a/programs/cmd/Makefile.in b/programs/cmd/Makefile.in
index 3a81838..fcaa0e5 100644
--- a/programs/cmd/Makefile.in
+++ b/programs/cmd/Makefile.in
@@ -4,7 +4,9 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = cmd.exe
APPMODE = -mconsole
-IMPORTS = shell32 user32 advapi32 kernel32
+IMPORTS = shell32 user32 advapi32 msvcrt kernel32
+EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt
+MODCFLAGS = @BUILTINFLAG@
C_SRCS = \
batch.c \
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 0824c27..eea05e6 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -231,60 +231,6 @@ char *WCMD_fgets (char *s, int n, HANDLE h) {
return p;
}
-/* WCMD_splitpath - copied from winefile as no obvious way to use it otherwise */
-void WCMD_splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ext)
-{
- const CHAR* end; /* end of processed string */
- const CHAR* p; /* search pointer */
- const CHAR* s; /* copy pointer */
-
- /* extract drive name */
- if (path[0] && path[1]==':') {
- if (drv) {
- *drv++ = *path++;
- *drv++ = *path++;
- *drv = '\0';
- }
- } else if (drv)
- *drv = '\0';
-
- /* search for end of string or stream separator */
- for(end=path; *end && *end!=':'; )
- end++;
-
- /* search for begin of file extension */
- for(p=end; p>path && *--p!='\\' && *p!='/'; )
- if (*p == '.') {
- end = p;
- break;
- }
-
- if (ext)
- for(s=end; (*ext=*s++); )
- ext++;
-
- /* search for end of directory name */
- for(p=end; p>path; )
- if (*--p=='\\' || *p=='/') {
- p++;
- break;
- }
-
- if (name) {
- for(s=p; s<end; )
- *name++ = *s++;
-
- *name = '\0';
- }
-
- if (dir) {
- for(s=path; s<p; )
- *dir++ = *s++;
-
- *dir = '\0';
- }
-}
-
/****************************************************************************
* WCMD_HandleTildaModifiers
*
@@ -529,7 +475,7 @@ void WCMD_HandleTildaModifiers(char **start, char *forVariable) {
if (finaloutput[0] != 0x00) strcat(finaloutput, " ");
/* Split into components */
- WCMD_splitpath(fullfilename, drive, dir, fname, ext);
+ _splitpath(fullfilename, drive, dir, fname, ext);
/* 5. Handle 'd' : Drive Letter */
if (memchr(firstModifier, 'd', modifierLen) != NULL) {
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 4d0fd5e..985dfd9 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -278,7 +278,7 @@ BOOL WCMD_delete (char *command, BOOL expectDir) {
/* Convert path into actual directory spec */
GetFullPathName (argCopy, sizeof(fpath), fpath, NULL);
- WCMD_splitpath(fpath, drive, dir, fname, ext);
+ _splitpath(fpath, drive, dir, fname, ext);
/* Only prompt for * and *.*, not *a, a*, *.a* etc */
if ((strcmp(fname, "*") == 0) &&
@@ -427,7 +427,7 @@ BOOL WCMD_delete (char *command, BOOL expectDir) {
/* Convert path into actual directory spec */
GetFullPathName (argCopy, sizeof(thisDir), thisDir, NULL);
- WCMD_splitpath(thisDir, drive, dir, fname, ext);
+ _splitpath(thisDir, drive, dir, fname, ext);
strcpy(thisDir, drive);
strcat(thisDir, dir);
@@ -846,7 +846,7 @@ void WCMD_move (void) {
WINE_TRACE("Move from '%s'('%s') to '%s'\n", input, param1, output);
/* Split into components */
- WCMD_splitpath(input, drive, dir, fname, ext);
+ _splitpath(input, drive, dir, fname, ext);
hff = FindFirstFile (input, &fd);
while (hff != INVALID_HANDLE_VALUE) {
@@ -1062,7 +1062,7 @@ void WCMD_rename (void) {
dotDst = strchr(param2, '.');
/* Split into components */
- WCMD_splitpath(input, drive, dir, fname, ext);
+ _splitpath(input, drive, dir, fname, ext);
hff = FindFirstFile (input, &fd);
while (hff != INVALID_HANDLE_VALUE) {
@@ -1394,7 +1394,7 @@ void WCMD_setshow_default (char *command) {
/* Convert path into actual directory spec */
GetFullPathName (string, sizeof(fpath), fpath, NULL);
- WCMD_splitpath(fpath, drive, dir, fname, ext);
+ _splitpath(fpath, drive, dir, fname, ext);
/* Rebuild path */
sprintf(string, "%s%s%s", drive, dir, fd.cFileName);
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c
index 24c7c6c..1676189 100644
--- a/programs/cmd/directory.c
+++ b/programs/cmd/directory.c
@@ -339,7 +339,7 @@ void WCMD_directory (char *cmd) {
thisEntry->next = NULL;
/* Split into components */
- WCMD_splitpath(path, drive, dir, fname, ext);
+ _splitpath(path, drive, dir, fname, ext);
WINE_TRACE("Path Parts: drive: '%s' dir: '%s' name: '%s' ext:'%s'\n",
drive, dir, fname, ext);
@@ -844,8 +844,8 @@ int WCMD_dir_sort (const void *a, const void *b)
char extB[MAX_PATH];
/* Split into components */
- WCMD_splitpath(filea->cFileName, drive, dir, fname, extA);
- WCMD_splitpath(fileb->cFileName, drive, dir, fname, extB);
+ _splitpath(filea->cFileName, drive, dir, fname, extA);
+ _splitpath(fileb->cFileName, drive, dir, fname, extB);
result = lstrcmpi(extA, extB);
}
@@ -899,7 +899,7 @@ void WCMD_getfileowner(char *filename, char *owner, int ownerlen) {
/* Convert to a username */
if (LookupAccountSid(NULL, pSID, name, &nameLen, domain, &domainLen, &nameuse)) {
- snprintf(owner, ownerlen, "%s%c%s", domain, '\\', name);
+ _snprintf(owner, ownerlen, "%s%c%s", domain, '\\', name);
}
HeapFree(GetProcessHeap(),0,secBuffer);
}
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 76cd22b..423c16b 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -85,8 +85,6 @@ void WCMD_opt_s_strip_quotes(char *cmd);
void WCMD_HandleTildaModifiers(char **start, char *forVariable);
BOOL WCMD_ask_confirm (char *message, BOOL showSureText);
-void WCMD_splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ext);
-
/* Data structure to hold context when executing batch files */
typedef struct {
--
1.5.0
More information about the wine-patches
mailing list