cmd: Extend wine's builtin glob matches ?.* to CD and CHDIR.

Henry Kroll admin at comptune.com
Thu Dec 14 21:53:03 CST 2006


Greetings, Gentlemen:

cmd: Extend wine's builtin glob matches ?.* to CD and CHDIR.

Enjoy your holiday season!

---
 programs/cmd/builtins.c  |   52 ++++++++++++++++++++++++++++++++++++++++++++--
 programs/cmd/directory.c |    7 ------
 2 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 8a79b98..35b166d 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -35,7 +35,7 @@
 #define WIN32_LEAN_AND_MEAN
 
 #include "wcmd.h"
-
+int WCMD_dir_sort (const void *a, const void *b);
 void WCMD_execute (char *orig_command, char *parameter, char *substitution);
 
 struct env_stack
@@ -785,13 +785,54 @@ void WCMD_setshow_default (void) {
 
 BOOL status;
 char string[1024];
-
+HANDLE hff;
+WIN32_FIND_DATA *fd;
+int entry_count = 0;
+  
   if (strlen(param1) == 0) {
     GetCurrentDirectory (sizeof(string), string);
     strcat (string, "\n");
     WCMD_output (string);
   }
   else {
+    /* Change dir, with glob wildcard search */
+    if ((strchr(param1, '*') != NULL) || (strchr(param1, '?') != NULL)) {
+      /* Load all files into an in memory structure */
+      fd = malloc (sizeof(WIN32_FIND_DATA));
+      hff = FindFirstFile (param1, fd);
+      if (hff == INVALID_HANDLE_VALUE) {
+        SetLastError (ERROR_FILE_NOT_FOUND);
+        WCMD_print_error ();
+        FindClose (hff);
+        free (fd);
+        return;
+      }
+      /* Get list of possible directory matches */
+      do {
+        if (((fd+entry_count)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+          entry_count++;
+          fd = realloc (fd, (entry_count+1)*sizeof(WIN32_FIND_DATA));
+          if (fd == NULL) {
+            WCMD_output ("Memory Allocation Error");
+            FindClose (hff);
+            return;
+          }
+        }
+      } while (FindNextFile(hff, (fd+entry_count)) != 0);
+      FindClose (hff);
+      
+      /* Sort the list of directories */
+      qsort (fd, entry_count, sizeof(WIN32_FIND_DATA), WCMD_dir_sort);
+      
+      /* Change directory to the first one */
+      status = SetCurrentDirectory (fd->cFileName);
+      free(fd);
+      if (!status) {
+        WCMD_print_error ();
+      }
+      return;
+    }
+    /* Change dir, without wildcards */
     status = SetCurrentDirectory (param1);
     if (!status) {
       WCMD_print_error ();
@@ -1150,3 +1191,10 @@ BOOL status;
   }
   return 1;
 }
+
+
+int WCMD_dir_sort (const void *a, const void *b)
+{
+  return (lstrcmpi(((const WIN32_FIND_DATA *)a)->cFileName,
+                   ((const WIN32_FIND_DATA *)b)->cFileName));
+}
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c
index 9a6b811..351afdb 100644
--- a/programs/cmd/directory.c
+++ b/programs/cmd/directory.c
@@ -361,10 +361,3 @@ char b;
   }
   return (buff);
 }
-
-
-int WCMD_dir_sort (const void *a, const void *b)
-{
-  return (lstrcmpi(((const WIN32_FIND_DATA *)a)->cFileName,
-                   ((const WIN32_FIND_DATA *)b)->cFileName));
-}
-- 
1.4.2.4



More information about the wine-patches mailing list