From c8ef8c2f28d28fdcaf3c22fc6df7a26f1cafa982 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Fri, 12 Apr 1991 03:20:58 +0000 Subject: [PATCH] Add new primitives `directory-open-noread' and `directory-read-matching', to facilitate filename completion. --- v7/src/microcode/osfs.h | 9 +++++---- v7/src/microcode/prosfs.c | 26 ++++++++++++++++++++++---- v7/src/microcode/uxfs.c | 37 ++++++++++++++++++++++++++++++++----- v7/src/microcode/version.h | 4 ++-- v8/src/microcode/version.h | 4 ++-- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/v7/src/microcode/osfs.h b/v7/src/microcode/osfs.h index 86dab6705..0e2c37996 100644 --- a/v7/src/microcode/osfs.h +++ b/v7/src/microcode/osfs.h @@ -1,8 +1,8 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/osfs.h,v 1.1 1990/06/20 19:36:23 cph Rel $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/osfs.h,v 1.2 1991/04/12 03:20:38 cph Exp $ -Copyright (c) 1990 Massachusetts Institute of Technology +Copyright (c) 1990-91 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -52,8 +52,9 @@ extern void EXFUN extern void EXFUN (OS_file_link_soft, (CONST char * from_name, CONST char * to_name)); extern void EXFUN (OS_directory_make, (CONST char * name)); -extern CONST char * EXFUN (OS_directory_open, (CONST char * name)); -extern CONST char * EXFUN (OS_directory_read, (void)); +extern void EXFUN (OS_directory_open, (CONST char * name)); extern void EXFUN (OS_directory_close, (void)); +extern CONST char * EXFUN (OS_directory_read, (void)); +extern CONST char * EXFUN (OS_directory_read_matching, (CONST char * prefix)); #endif /* SCM_OSFS_H */ diff --git a/v7/src/microcode/prosfs.c b/v7/src/microcode/prosfs.c index 36e5529fd..c2c0cb0ea 100644 --- a/v7/src/microcode/prosfs.c +++ b/v7/src/microcode/prosfs.c @@ -1,8 +1,8 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/prosfs.c,v 1.2 1990/11/21 07:04:38 jinx Rel $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/prosfs.c,v 1.3 1991/04/12 03:20:45 cph Exp $ -Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology +Copyright (c) 1987-91 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -233,10 +233,19 @@ DEFINE_PRIMITIVE ("DIRECTORY-MAKE", Prim_directory_make, 1, 1, DEFINE_PRIMITIVE ("DIRECTORY-OPEN", Prim_directory_open, 1, 1, "Open the directory NAME for reading.\n\ If successful, return the first filename in the directory as a string.\n\ -If there is no such file, or the directory cannot be opened, #F is returned.") +If there is no such file, #F is returned.") { PRIMITIVE_HEADER (1); - STRING_RESULT (OS_directory_open (STRING_ARG (1))); + OS_directory_open (STRING_ARG (1)); + STRING_RESULT (OS_directory_read ()); +} + +DEFINE_PRIMITIVE ("DIRECTORY-OPEN-NOREAD", Prim_directory_open_noread, 1, 1, + "Open the directory NAME for reading.") +{ + PRIMITIVE_HEADER (1); + OS_directory_open (STRING_ARG (1)); + PRIMITIVE_RETURN (UNSPECIFIC); } DEFINE_PRIMITIVE ("DIRECTORY-READ", Prim_directory_read, 0, 0, @@ -247,6 +256,15 @@ Return #F if there are no more files in the directory.") STRING_RESULT (OS_directory_read ()); } +DEFINE_PRIMITIVE ("DIRECTORY-READ-MATCHING", Prim_directory_read_matching, 1, 1, + "Read and return a filename from the directory opened by `directory-open'.\n\ +The filename must begin with the argument string.\n\ +Return #F if there are no more matching files in the directory.") +{ + PRIMITIVE_HEADER (1); + STRING_RESULT (OS_directory_read_matching (STRING_ARG (1))); +} + DEFINE_PRIMITIVE ("DIRECTORY-CLOSE", Prim_directory_close, 0, 0, "Close the directory opened by `directory-open'.") { diff --git a/v7/src/microcode/uxfs.c b/v7/src/microcode/uxfs.c index 965512f5f..bff41317e 100644 --- a/v7/src/microcode/uxfs.c +++ b/v7/src/microcode/uxfs.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxfs.c,v 1.3 1991/01/24 11:25:50 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxfs.c,v 1.4 1991/04/12 03:20:51 cph Exp $ Copyright (c) 1990-1 Massachusetts Institute of Technology @@ -168,7 +168,7 @@ static struct direct * directory_entry; return (directory_entry -> d_name); \ } -CONST char * +void DEFUN (OS_directory_open, (name), CONST char * name) { if (directory_pointer != 0) @@ -181,7 +181,6 @@ DEFUN (OS_directory_open, (name), CONST char * name) #else error_external_return (); #endif - READ_DIRECTORY_ENTRY (); } CONST char * @@ -192,6 +191,28 @@ DEFUN_VOID (OS_directory_read) READ_DIRECTORY_ENTRY (); } +CONST char * +DEFUN (OS_directory_read_matching, (prefix), CONST char * prefix) +{ + if (directory_pointer == 0) + error_external_return (); + { + unsigned int n = (strlen (prefix)); + while (1) + { + directory_entry = (readdir (directory_pointer)); + if (directory_entry == 0) + { + closedir (directory_pointer); + directory_pointer = 0; + return (0); + } + if ((strncmp (prefix, (directory_entry -> d_name), n)) == 0) + return (directory_entry -> d_name); + } + } +} + void DEFUN_VOID (OS_directory_close) { @@ -210,11 +231,10 @@ DEFUN_VOID (UX_initialize_directory_reader) #else /* not HAVE_DIRENT nor HAVE_DIR */ -CONST char * +void DEFUN (OS_directory_open, (name), CONST char * name) { error_unimplemented_primitive (); - return (0); } CONST char * @@ -224,6 +244,13 @@ DEFUN_VOID (OS_directory_read) return (0); } +CONST char * +DEFUN (OS_directory_read_matching, (prefix), CONST char * prefix) +{ + error_unimplemented_primitive (); + return (0); +} + void DEFUN_VOID (OS_directory_close) { diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index 297ba5af4..238a005a9 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.73 1991/04/02 19:45:32 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.74 1991/04/12 03:20:58 cph Exp $ Copyright (c) 1988-91 Massachusetts Institute of Technology @@ -46,5 +46,5 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 73 +#define SUBVERSION 74 #endif diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h index ed95b9b5c..fdc400a80 100644 --- a/v8/src/microcode/version.h +++ b/v8/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.73 1991/04/02 19:45:32 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.74 1991/04/12 03:20:58 cph Exp $ Copyright (c) 1988-91 Massachusetts Institute of Technology @@ -46,5 +46,5 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 73 +#define SUBVERSION 74 #endif -- 2.25.1