# HG changeset patch # User Claus Gittinger # Date 840112117 -7200 # Node ID 0d50b800b011d870ab14268ce66053ea5a966fb5 # Parent 09e6117a14570bfee0f05822d736f13fb37cac31 directory readOps for NT diff -r 09e6117a1457 -r 0d50b800b011 DirStr.st --- a/DirStr.st Thu Aug 15 14:18:53 1996 +0200 +++ b/DirStr.st Thu Aug 15 14:28:37 1996 +0200 @@ -20,34 +20,83 @@ !DirectoryStream primitiveDefinitions! %{ -#include -#define _STDIO_H_INCLUDED_ +#define UNIX_LIKE +#if defined(WIN32) +# undef UNIX_LIKE +#endif -#include -#define _ERRNO_H_INCLUDED_ +#ifdef UNIX_LIKE + +# include +# define _STDIO_H_INCLUDED_ + +# include +# define _ERRNO_H_INCLUDED_ -#ifndef transputer -# include -# include - -# ifdef HAS_OPENDIR +# ifndef transputer # include -# ifdef NEXT -# include -# else -# ifndef VMS -# include -# endif /* not VMS */ +# include + +# ifdef HAS_OPENDIR +# include +# ifdef NEXT +# include +# else +# ifndef VMS +# include +# endif /* not VMS */ +# endif # endif # endif -#endif /* * on some systems errno is a macro ... check for it here */ -#ifndef errno - extern errno; -#endif +# ifndef errno + extern errno; +# endif +#endif /* UNIX_LIKE */ + +#ifdef WIN32 + +# ifdef i386 +# define _X86_ +# endif + +# undef INT +# undef Array +# undef Number +# undef Method +# undef Point +# undef Context +# undef Rectangle + +# include /* */ +# include /* */ +# include /* */ +# include /* */ +# include /* */ +# include /* */ + +# ifdef __DEF_Array +# define Array __DEF_Array +# endif +# ifdef __DEF_Number +# define Number __DEF_Number +# endif +# ifdef __DEF_Method +# define Method __DEF_Method +# endif +# ifdef __DEF_Point +# define Point __DEF_Point +# endif +# ifdef __DEF_Context +# define Context __DEF_Context +# endif + +# define __HANDLEVal(o) (HANDLE)__MKCP(o) + +#endif /* WIN32 */ %} ! ! @@ -353,7 +402,7 @@ Basically, its an interface to opendir, readdir and closedir. [author:] - Claus Gittinger + Claus Gittinger " ! ! @@ -378,36 +427,52 @@ %{ #ifdef HAS_OPENDIR DIR *d; -#ifdef NEXT +# ifdef NEXT struct direct *dp; -#else +# else struct dirent *dp; -#endif +# endif OBJ dirP; - if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { - __INST(lastErrorNumber) = nil; - d = (DIR *)__FILEVal(dirP); + __INST(lastErrorNumber) = nil; + d = (DIR *)__FILEVal(dirP); - __BEGIN_INTERRUPTABLE__ - do { - errno = 0; - dp = readdir(d); - } while ((dp == NULL) && (errno == EINTR)); - __END_INTERRUPTABLE__ + __BEGIN_INTERRUPTABLE__ + do { + errno = 0; + dp = readdir(d); + } while ((dp == NULL) && (errno == EINTR)); + __END_INTERRUPTABLE__ - if (dp != NULL) { - nextEntry = __MKSTRING((char *)(dp->d_name) COMMA_CON); - } else { - if (errno) { - __INST(lastErrorNumber) = __MKSMALLINT(errno); - } else { - __INST(hitEOF) = true; - } + if (dp != NULL) { + nextEntry = __MKSTRING((char *)(dp->d_name) COMMA_CON); + } else { + if (errno) { + __INST(lastErrorNumber) = __MKSMALLINT(errno); + } else { + __INST(hitEOF) = true; + } } } -#endif +#else /* no HAS_OPENDIR */ +# ifdef WIN32 + HANDLE d; + WIN32_FIND_DATA data; + OBJ dirP; + + if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { + __INST(lastErrorNumber) = nil; + d = __HANDLEVal(dirP); + + if (FindNextFile(d, &data)) { + nextEntry = __MKSTRING( data.cFileName ); + } else { + __INST(hitEOF) = true; + } + } +# endif /* WIN32 */ +#endif /* HAS_OPENDIR */ %}. lastErrorNumber notNil ifTrue:[^ self ioError]. prevEntry := readAhead. @@ -440,6 +505,15 @@ __INST(dirPointer) = nil; closedir( (DIR *)(__FILEVal(dp)) ); } +#else +# ifdef WIN32 + OBJ dp; + + if ((dp = __INST(dirPointer)) != nil) { + __INST(dirPointer) = nil; + FindClose( __HANDLEVal(dp) ); + } +# endif #endif %} ! ! @@ -449,7 +523,7 @@ openForReading "open the file for readonly" - |ok| + |ok entry| mode := #readonly. %{ @@ -476,6 +550,30 @@ } } } +#else +# ifdef WIN32 + HANDLE d; + OBJ path, dp; + char pattern[512]; + WIN32_FIND_DATA data; + + ok = false; + if (__INST(dirPointer) == nil) { + path = __INST(pathName); + if (__isString(path)) { + strcpy(pattern, __stringVal(path)); + strcat(pattern, "\\*"); + d = FindFirstFile(pattern, &data); + if (d == INVALID_HANDLE_VALUE) { + __INST(lastErrorNumber) = __MKSMALLINT(GetLastError()); + } else { + __INST(dirPointer) = dp = __MKOBJ(d); __STORE(self, dp); + entry = __MKSTRING( data.cFileName ); + ok = true; + } + } + } +# endif #endif %}. ok isNil ifTrue:[ @@ -487,7 +585,11 @@ (ok == true) ifTrue:[ Lobby register:self. - self nextLine. "read 1st entry into readAhead buffer" + entry isNil ifTrue:[ + self nextLine. "read 1st entry into readAhead buffer" + ] ifFalse:[ + readAhead := entry. + ]. ^ self ]. dirPointer notNil ifTrue:[^ self errorOpen]. @@ -513,5 +615,5 @@ !DirectoryStream class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/Attic/DirStr.st,v 1.30 1996-04-25 17:01:37 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/Attic/DirStr.st,v 1.31 1996-08-15 12:28:37 cg Exp $' ! ! diff -r 09e6117a1457 -r 0d50b800b011 DirectoryStream.st --- a/DirectoryStream.st Thu Aug 15 14:18:53 1996 +0200 +++ b/DirectoryStream.st Thu Aug 15 14:28:37 1996 +0200 @@ -20,34 +20,83 @@ !DirectoryStream primitiveDefinitions! %{ -#include -#define _STDIO_H_INCLUDED_ +#define UNIX_LIKE +#if defined(WIN32) +# undef UNIX_LIKE +#endif -#include -#define _ERRNO_H_INCLUDED_ +#ifdef UNIX_LIKE + +# include +# define _STDIO_H_INCLUDED_ + +# include +# define _ERRNO_H_INCLUDED_ -#ifndef transputer -# include -# include - -# ifdef HAS_OPENDIR +# ifndef transputer # include -# ifdef NEXT -# include -# else -# ifndef VMS -# include -# endif /* not VMS */ +# include + +# ifdef HAS_OPENDIR +# include +# ifdef NEXT +# include +# else +# ifndef VMS +# include +# endif /* not VMS */ +# endif # endif # endif -#endif /* * on some systems errno is a macro ... check for it here */ -#ifndef errno - extern errno; -#endif +# ifndef errno + extern errno; +# endif +#endif /* UNIX_LIKE */ + +#ifdef WIN32 + +# ifdef i386 +# define _X86_ +# endif + +# undef INT +# undef Array +# undef Number +# undef Method +# undef Point +# undef Context +# undef Rectangle + +# include /* */ +# include /* */ +# include /* */ +# include /* */ +# include /* */ +# include /* */ + +# ifdef __DEF_Array +# define Array __DEF_Array +# endif +# ifdef __DEF_Number +# define Number __DEF_Number +# endif +# ifdef __DEF_Method +# define Method __DEF_Method +# endif +# ifdef __DEF_Point +# define Point __DEF_Point +# endif +# ifdef __DEF_Context +# define Context __DEF_Context +# endif + +# define __HANDLEVal(o) (HANDLE)__MKCP(o) + +#endif /* WIN32 */ %} ! ! @@ -353,7 +402,7 @@ Basically, its an interface to opendir, readdir and closedir. [author:] - Claus Gittinger + Claus Gittinger " ! ! @@ -378,36 +427,52 @@ %{ #ifdef HAS_OPENDIR DIR *d; -#ifdef NEXT +# ifdef NEXT struct direct *dp; -#else +# else struct dirent *dp; -#endif +# endif OBJ dirP; - if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { - __INST(lastErrorNumber) = nil; - d = (DIR *)__FILEVal(dirP); + __INST(lastErrorNumber) = nil; + d = (DIR *)__FILEVal(dirP); - __BEGIN_INTERRUPTABLE__ - do { - errno = 0; - dp = readdir(d); - } while ((dp == NULL) && (errno == EINTR)); - __END_INTERRUPTABLE__ + __BEGIN_INTERRUPTABLE__ + do { + errno = 0; + dp = readdir(d); + } while ((dp == NULL) && (errno == EINTR)); + __END_INTERRUPTABLE__ - if (dp != NULL) { - nextEntry = __MKSTRING((char *)(dp->d_name) COMMA_CON); - } else { - if (errno) { - __INST(lastErrorNumber) = __MKSMALLINT(errno); - } else { - __INST(hitEOF) = true; - } + if (dp != NULL) { + nextEntry = __MKSTRING((char *)(dp->d_name) COMMA_CON); + } else { + if (errno) { + __INST(lastErrorNumber) = __MKSMALLINT(errno); + } else { + __INST(hitEOF) = true; + } } } -#endif +#else /* no HAS_OPENDIR */ +# ifdef WIN32 + HANDLE d; + WIN32_FIND_DATA data; + OBJ dirP; + + if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { + __INST(lastErrorNumber) = nil; + d = __HANDLEVal(dirP); + + if (FindNextFile(d, &data)) { + nextEntry = __MKSTRING( data.cFileName ); + } else { + __INST(hitEOF) = true; + } + } +# endif /* WIN32 */ +#endif /* HAS_OPENDIR */ %}. lastErrorNumber notNil ifTrue:[^ self ioError]. prevEntry := readAhead. @@ -440,6 +505,15 @@ __INST(dirPointer) = nil; closedir( (DIR *)(__FILEVal(dp)) ); } +#else +# ifdef WIN32 + OBJ dp; + + if ((dp = __INST(dirPointer)) != nil) { + __INST(dirPointer) = nil; + FindClose( __HANDLEVal(dp) ); + } +# endif #endif %} ! ! @@ -449,7 +523,7 @@ openForReading "open the file for readonly" - |ok| + |ok entry| mode := #readonly. %{ @@ -476,6 +550,30 @@ } } } +#else +# ifdef WIN32 + HANDLE d; + OBJ path, dp; + char pattern[512]; + WIN32_FIND_DATA data; + + ok = false; + if (__INST(dirPointer) == nil) { + path = __INST(pathName); + if (__isString(path)) { + strcpy(pattern, __stringVal(path)); + strcat(pattern, "\\*"); + d = FindFirstFile(pattern, &data); + if (d == INVALID_HANDLE_VALUE) { + __INST(lastErrorNumber) = __MKSMALLINT(GetLastError()); + } else { + __INST(dirPointer) = dp = __MKOBJ(d); __STORE(self, dp); + entry = __MKSTRING( data.cFileName ); + ok = true; + } + } + } +# endif #endif %}. ok isNil ifTrue:[ @@ -487,7 +585,11 @@ (ok == true) ifTrue:[ Lobby register:self. - self nextLine. "read 1st entry into readAhead buffer" + entry isNil ifTrue:[ + self nextLine. "read 1st entry into readAhead buffer" + ] ifFalse:[ + readAhead := entry. + ]. ^ self ]. dirPointer notNil ifTrue:[^ self errorOpen]. @@ -513,5 +615,5 @@ !DirectoryStream class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.30 1996-04-25 17:01:37 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.31 1996-08-15 12:28:37 cg Exp $' ! !