From 3423db1f72f85c7f2d7b067b6774fe7ec64ae8e2 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Wed, 9 Oct 1996 15:40:15 +0000 Subject: [PATCH] Fix directory reader so that wildcarding is done by the Win32 API rather than Scheme code. This improves performance and makes the wildcarding work as in other Win32 programs. Also implement OS_directory_read_matching which improves performance of completion in Edwin. --- v7/src/microcode/ntfs.c | 69 ++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/v7/src/microcode/ntfs.c b/v7/src/microcode/ntfs.c index 5ad687786..036bf21b1 100644 --- a/v7/src/microcode/ntfs.c +++ b/v7/src/microcode/ntfs.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntfs.c,v 1.11 1996/10/07 17:55:38 cph Exp $ +$Id: ntfs.c,v 1.12 1996/10/09 15:40:15 cph Exp $ Copyright (c) 1992-96 Massachusetts Institute of Technology @@ -270,37 +270,36 @@ DEFUN (OS_directory_valid_p, (index), long index) } unsigned int -DEFUN (OS_directory_open, (name), CONST char * name) +DEFUN (OS_directory_open, (name), CONST char * search_pattern) { - char filename[128], searchname[128]; - nt_dir * dir = NT_malloc(sizeof(nt_dir)); - + char pattern [MAX_PATH]; + nt_dir * dir = (malloc (sizeof (nt_dir))); if (dir == 0) error_system_call (ENOMEM, syscall_malloc); - - if (nt_pathname_as_filename (name, filename)) - sprintf (searchname, "%s*.*", filename); - else - sprintf (searchname, "%s\\*.*", filename); - - dir->handle = FindFirstFile(searchname, &(dir->entry)); - if (dir->handle == INVALID_HANDLE_VALUE) - error_system_call (errno, syscall_opendir); - - dir->more = TRUE; + strcpy (pattern, search_pattern); + { + unsigned int len = (strlen (pattern)); + if ((len > 0) && ((pattern [len - 1]) == '\\')) + strcat (pattern, "*.*"); + } + (dir -> handle) = (FindFirstFile (pattern, (& (dir -> entry)))); + if ((dir -> handle) == INVALID_HANDLE_VALUE) + { + free (dir); + error_system_call (errno, syscall_opendir); + } + (dir -> more) = TRUE; return (allocate_directory_pointer (dir)); } CONST char * DEFUN (OS_directory_read, (index), unsigned int index) { - nt_dir * dir = REFERENCE_DIRECTORY (index); - - if (dir == 0 || !dir->more) - return 0; - - GET_DIRECTORY_ENTRY_NAME(dir->entry, dir->pathname); - dir->more = FindNextFile(dir->handle, &(dir->entry)); + nt_dir * dir = (REFERENCE_DIRECTORY (index)); + if ((dir == 0) || (! (dir -> more))) + return (0); + GET_DIRECTORY_ENTRY_NAME ((dir -> entry), (dir -> pathname)); + (dir -> more) = (FindNextFile ((dir -> handle), (& (dir -> entry)))); return (dir -> pathname); } @@ -309,19 +308,25 @@ DEFUN (OS_directory_read_matching, (index, prefix), unsigned int index AND CONST char * prefix) { - error_unimplemented_primitive (); - return (0); + unsigned int n = (strlen (prefix)); + while (1) + { + CONST char * pathname = (OS_directory_read (index)); + if (pathname == 0) + return (0); + if ((strnicmp (pathname, prefix, n)) == 0) + return (pathname); + } } void DEFUN (OS_directory_close, (index), unsigned int index) -{ - nt_dir * dir = REFERENCE_DIRECTORY (index); - +{ + nt_dir * dir = (REFERENCE_DIRECTORY (index)); if (dir) - { - FindClose(dir->handle); - NT_free(dir); - } + { + FindClose (dir -> handle); + free (dir); + } DEALLOCATE_DIRECTORY (index); } -- 2.25.1