Commit 57f76bd3 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd.exe: Fix dir filename /s and resolve many output differences.

parent 5704b4be
......@@ -57,6 +57,12 @@ typedef enum _DISPLAYORDER
Date
} DISPLAYORDER;
struct directory_stack
{
struct directory_stack *next;
char *name;
};
static int file_total, dir_total, recurse, wide, bare, max_width, lower;
static int shortname, usernames;
static ULONGLONG byte_total;
......@@ -286,7 +292,7 @@ void WCMD_directory (void) {
if (errorlevel==0 && !bare) {
if (recurse) {
WCMD_output ("\n\n Total files listed:\n%8d files%25s bytes\n",
WCMD_output ("\n Total files listed:\n%8d files%25s bytes\n",
file_total, WCMD_filesize64 (byte_total));
WCMD_output ("%8d directories %18s bytes free\n\n",
dir_total, WCMD_filesize64 (free.QuadPart));
......@@ -333,10 +339,12 @@ void WCMD_list_directory (char *search_path, int level) {
/*
* If the path supplied does not include a wildcard, and the endpoint of the
* path references a directory, we need to list the *contents* of that
* directory not the directory file itself.
* directory not the directory file itself. However, only do this on first
* entry and not subsequent recursion
*/
if ((strchr(search_path, '*') == NULL) && (strchr(search_path, '%') == NULL)) {
if ((level == 0) &&
(strchr(search_path, '*') == NULL) && (strchr(search_path, '%') == NULL)) {
status = GetFileAttributes (search_path);
if ((status != INVALID_FILE_ATTRIBUTES) && (status & FILE_ATTRIBUTE_DIRECTORY)) {
if (search_path[strlen(search_path)-1] == '\\') {
......@@ -355,14 +363,11 @@ void WCMD_list_directory (char *search_path, int level) {
/* Load all files into an in memory structure */
fd = HeapAlloc(GetProcessHeap(),0,sizeof(WIN32_FIND_DATA));
WINE_TRACE("Looking for matches to '%s'\n", search_path);
hff = FindFirstFile (search_path, fd);
if (hff == INVALID_HANDLE_VALUE) {
SetLastError (ERROR_FILE_NOT_FOUND);
WCMD_print_error ();
HeapFree(GetProcessHeap(),0,fd);
errorlevel = 1;
return;
}
entry_count = 0;
} else {
do {
/* Skip any which are filtered out by attribute */
if (((fd+entry_count)->dwFileAttributes & attrsbits) != showattrs) continue;
......@@ -385,25 +390,20 @@ void WCMD_list_directory (char *search_path, int level) {
}
} while (FindNextFile(hff, (fd+entry_count)) != 0);
FindClose (hff);
/* Handle case where everything is filtered out */
if (entry_count == 0) {
SetLastError (ERROR_FILE_NOT_FOUND);
WCMD_print_error ();
HeapFree(GetProcessHeap(),0,fd);
errorlevel = 1;
return;
}
/* Sort the list of files */
qsort (fd, entry_count, sizeof(WIN32_FIND_DATA), WCMD_dir_sort);
/* Output the results */
if (!bare) {
if (level != 0) WCMD_output ("\n\n");
WCMD_output ("Directory of %s\n\n", real_path);
if (level != 0 && (entry_count > 0)) WCMD_output ("\n");
if ((entry_count > 0) || (!recurse && level == 0)) WCMD_output ("Directory of %s\n\n", real_path);
}
/* Handle case where everything is filtered out */
if (entry_count > 0) {
/* Sort the list of files */
qsort (fd, entry_count, sizeof(WIN32_FIND_DATA), WCMD_dir_sort);
/* Work out the number of columns */
WINE_TRACE("%d entries, maxwidth=%d, widest=%d\n", entry_count, max_width, widest);
if (wide || orderByCol) {
......@@ -417,6 +417,7 @@ void WCMD_list_directory (char *search_path, int level) {
WINE_TRACE("cols=%d, rows=%d\n", numCols, numRows);
for (rows=0; rows<numRows; rows++) {
BOOL addNewLine = TRUE;
for (cols=0; cols<numCols; cols++) {
char username[24];
......@@ -491,6 +492,8 @@ void WCMD_list_directory (char *search_path, int level) {
if (!((strcmp((fd+i)->cFileName, ".") == 0) ||
(strcmp((fd+i)->cFileName, "..") == 0))) {
WCMD_output ("%s%s", recurse?real_path:"", (fd+i)->cFileName);
} else {
addNewLine = FALSE;
}
}
}
......@@ -510,7 +513,7 @@ void WCMD_list_directory (char *search_path, int level) {
}
}
}
WCMD_output ("\n");
if (addNewLine) WCMD_output ("\n");
cur_width = 0;
}
......@@ -526,25 +529,72 @@ void WCMD_list_directory (char *search_path, int level) {
file_total = file_total + file_count;
dir_total = dir_total + dir_count;
if (!bare) {
if (dir_count == 1) WCMD_output ("1 directory ");
if (!bare && !recurse) {
if (dir_count == 1) WCMD_output ("%8d directory ", 1);
else WCMD_output ("%8d directories", dir_count);
}
for (i=0; i<entry_count; i++) {
if ((recurse) &&
((fd+i)->cFileName[0] != '.') &&
((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
#if 0
GetFullPathName ((fd+i)->cFileName, sizeof(string), string, NULL);
#endif
}
HeapFree(GetProcessHeap(),0,fd);
/* When recursing, look in all subdirectories for matches */
if (recurse) {
struct directory_stack *dirStack = NULL;
struct directory_stack *lastEntry = NULL;
WIN32_FIND_DATA finddata;
/* Build path to search */
strcpy(string, search_path);
p = strrchr (string, '\\');
strcpy(p+1, "*");
WINE_TRACE("Recursive, looking for '%s'\n", string);
hff = FindFirstFile (string, &finddata);
if (hff != INVALID_HANDLE_VALUE) {
do {
if ((finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
(strcmp(finddata.cFileName, "..") != 0) &&
(strcmp(finddata.cFileName, ".") != 0)) {
struct directory_stack *thisDir;
/* Work out search parameter in sub dir */
p = strrchr (search_path, '\\');
lstrcpyn (string, search_path, (p-search_path+2));
lstrcat (string, (fd+i)->cFileName);
string[(p-search_path+2)] = 0x00;
lstrcat (string, finddata.cFileName);
lstrcat (string, p);
WCMD_list_directory (string, 1);
WINE_TRACE("Recursive, Adding to search list '%s'\n", string);
/* Allocate memory, add to list */
thisDir = (struct directory_stack *) HeapAlloc(GetProcessHeap(),0,sizeof(struct directory_stack));
if (dirStack == NULL) dirStack = thisDir;
if (lastEntry != NULL) lastEntry->next = thisDir;
lastEntry = thisDir;
thisDir->next = NULL;
thisDir->name = HeapAlloc(GetProcessHeap(),0,(strlen(string)+1));
strcpy(thisDir->name, string);
}
} while (FindNextFile(hff, &finddata) != 0);
FindClose (hff);
while (dirStack != NULL) {
struct directory_stack *thisDir = dirStack;
dirStack = thisDir->next;
WCMD_list_directory (thisDir->name, 1);
HeapFree(GetProcessHeap(),0,thisDir->name);
HeapFree(GetProcessHeap(),0,thisDir);
}
}
HeapFree(GetProcessHeap(),0,fd);
}
/* Handle case where everything is filtered out */
if ((file_total + dir_total == 0) && (level == 0)) {
SetLastError (ERROR_FILE_NOT_FOUND);
WCMD_print_error ();
errorlevel = 1;
}
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment