DirectoryStream.st
changeset 13778 8e34483d10dd
parent 12909 e844bd18a3aa
child 14437 3a983b537183
--- a/DirectoryStream.st	Fri Oct 07 13:58:26 2011 +0200
+++ b/DirectoryStream.st	Fri Oct 07 15:57:55 2011 +0200
@@ -493,13 +493,13 @@
     |contents|
 
     contents := OrderedCollection new.
-    [self atEnd] whileFalse:[  
-        |l|
-        l := self nextLine.
-        l isNil ifTrue:[
-            ^ contents
-        ].
-        contents add:l
+    [self atEnd] whileFalse:[
+	|l|
+	l := self nextLine.
+	l isNil ifTrue:[
+	    ^ contents
+	].
+	contents add:l
     ].
     ^ contents
 !
@@ -515,31 +515,31 @@
     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 {
-            do {
-                __threadErrno = 0;
-                dp = readdir(d);
-                /*
-                 * for compatibility with ST-80,
-                 * skip entries for '.' and '..'.
-                 * If wanted, these must be added synthetically.
-                 */
-            } while (dp && ((strcmp(dp->d_name, ".")==0) || (strcmp(dp->d_name, "..")==0)));
-        } while ((dp == NULL) && (__threadErrno == EINTR));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    do {
+		__threadErrno = 0;
+		dp = readdir(d);
+		/*
+		 * for compatibility with ST-80,
+		 * skip entries for '.' and '..'.
+		 * If wanted, these must be added synthetically.
+		 */
+	    } while (dp && ((strcmp(dp->d_name, ".")==0) || (strcmp(dp->d_name, "..")==0)));
+	} while ((dp == NULL) && (__threadErrno == EINTR));
+	__END_INTERRUPTABLE__
 
-        if (dp != NULL) {
-            nextEntry = __MKSTRING((char *)(dp->d_name));
-        } else {
-            if (__threadErrno) {
-                __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
-            } else {
-                __INST(hitEOF) = true;
-            }
+	if (dp != NULL) {
+	    nextEntry = __MKSTRING((char *)(dp->d_name));
+	} else {
+	    if (__threadErrno) {
+		__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+	    } else {
+		__INST(hitEOF) = true;
+	    }
        }
     }
 #else /* no HAS_OPENDIR */
@@ -550,23 +550,23 @@
     int rslt;
 
     if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) {
-        __INST(lastErrorNumber) = nil;
-        d = __HANDLEVal(dirP);
+	__INST(lastErrorNumber) = nil;
+	d = __HANDLEVal(dirP);
 
-        do {
-            __threadErrno = 0;
-            rslt = STX_API_NOINT_CALL2( "FindNextFileW", FindNextFileW, d, &data );
-        } while ((rslt < 0) && (__threadErrno == EINTR));
+	do {
+	    __threadErrno = 0;
+	    rslt = STX_API_NOINT_CALL2( "FindNextFileW", FindNextFileW, d, &data );
+	} while ((rslt < 0) && (__threadErrno == EINTR));
 
-        if (rslt > 0) {
-            nextEntry = __MKU16STRING( data.cFileName );
-        } else {
-           __INST(hitEOF) = true;
-        }
+	if (rslt > 0) {
+	    nextEntry = __MKU16STRING( data.cFileName );
+	} else {
+	   __INST(hitEOF) = true;
+	}
     }
 # endif /* WIN32 */
 #endif /* HAS_OPENDIR */
- 
+
 #ifdef unix
     isUnix = true;
 #endif
@@ -574,17 +574,17 @@
 %}.
     lastErrorNumber notNil ifTrue:[^ self ioError].
     nextEntry notNil ifTrue:[
-        isUnix == true ifTrue:[
-            "linux strings are in UTF8 (in contemporary linux versions)"
-            [
-                nextEntry := nextEntry utf8Decoded.
-            ] on:InvalidEncodingError do:[:ex|
-                "maybe there are old filenames in ISO8859-x,
-                 just keep them untranslated"
-            ].
-        ] ifFalse:[
-            nextEntry := nextEntry asSingleByteStringIfPossible.
-        ]
+	isUnix == true ifTrue:[
+	    "linux strings are in UTF8 (in contemporary linux versions)"
+	    [
+		nextEntry := nextEntry utf8Decoded.
+	    ] on:InvalidEncodingError do:[:ex|
+		"maybe there are old filenames in ISO8859-x,
+		 just keep them untranslated"
+	    ].
+	] ifFalse:[
+	    nextEntry := nextEntry asSingleByteStringIfPossible.
+	]
     ].
     prevEntry := readAheadEntry.
     readAheadEntry := nextEntry.
@@ -644,109 +644,106 @@
 
     ok = false;
     if (__INST(dirPointer) == nil) {
-        path = __INST(pathName);
-        if (__isStringLike(path)) {
-            __BEGIN_INTERRUPTABLE__
-            __threadErrno = 0;
-            do {
-                path = __INST(pathName);
-                d = opendir((char *) __stringVal(path));
-            } while ((d == NULL) && (__threadErrno == EINTR));
-            __END_INTERRUPTABLE__
+	path = __INST(pathName);
+	if (__isStringLike(path)) {
+	    __BEGIN_INTERRUPTABLE__
+	    __threadErrno = 0;
+	    do {
+		path = __INST(pathName);
+		d = opendir((char *) __stringVal(path));
+	    } while ((d == NULL) && (__threadErrno == EINTR));
+	    __END_INTERRUPTABLE__
 
-            if (d == NULL) {
-                __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
-            } else {
-                dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
-                ok = true;
-            }
-        }
+	    if (d == NULL) {
+		__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
+	    } else {
+		dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
+		ok = true;
+	    }
+	}
     }
 #else
 # ifdef WIN32
-#  ifndef MAXPATHLEN
-#   define MAXPATHLEN 1024
-#  endif
     HANDLE d;
     OBJ path, dp;
     union {
-        char pattern[MAXPATHLEN];
-        wchar_t wpattern[MAXPATHLEN];
+	char pattern[MAXPATHLEN];
+	wchar_t wpattern[MAXPATHLEN];
     } uP;
     union {
-        WIN32_FIND_DATAA data;
-        WIN32_FIND_DATAW wdata;
+	WIN32_FIND_DATAA data;
+	WIN32_FIND_DATAW wdata;
     } uD;
 
     ok = false;
     if (__INST(dirPointer) == nil) {
-        path = __INST(pathName);
-        if (__isStringLike(path)) {
-            int l = __stringSize(path);
+	path = __INST(pathName);
+	if (__isStringLike(path)) {
+	    int l = __stringSize(path);
 
-            if (l < (MAXPATHLEN-4)) {
-                strncpy(uP.pattern, __stringVal(path), l);
-                strcpy(uP.pattern+l, "\\*");
+	    if (l < (MAXPATHLEN-4)) {
+		strncpy(uP.pattern, __stringVal(path), l);
+		strcpy(uP.pattern+l, "\\*");
 
-                do {
-                    __threadErrno = 0;
-                    d = STX_API_NOINT_CALL2( "FindFirstFileA", FindFirstFileA, uP.pattern, &uD.data );
-                } while ((d < 0) && (__threadErrno == EINTR));
+		do {
+		    __threadErrno = 0;
+		    d = STX_API_NOINT_CALL2( "FindFirstFileA", FindFirstFileA, uP.pattern, &uD.data );
+		} while ((d < 0) && (__threadErrno == EINTR));
 
-                if (d == INVALID_HANDLE_VALUE) {
-                    __INST(lastErrorNumber) = __mkSmallInteger(GetLastError());
-                } else {
-                    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
-                    entry = __MKSTRING( uD.data.cFileName );
-                    ok = true;
-                }
-            }
-        }
-        else if (__isUnicode16String(path)) {
-            int l = __unicode16StringSize(path);
-            int i;
+		if (d == INVALID_HANDLE_VALUE) {
+		    __INST(lastErrorNumber) = __mkSmallInteger(GetLastError());
+		} else {
+		    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
+		    entry = __MKSTRING( uD.data.cFileName );
+		    ok = true;
+		}
+	    }
+	}
+	else if (__isUnicode16String(path)) {
+	    int l = __unicode16StringSize(path);
+	    int i;
 
-            if (l < (MAXPATHLEN-4)) {
-                for (i=0; i<l; i++) {
-                    uP.wpattern[i] = __unicode16StringVal(path)[i];
-                }
-                uP.wpattern[i++] = '\\';
-                uP.wpattern[i++] = '*';
-                uP.wpattern[i] = 0;
+	    if (l < (MAXPATHLEN-4)) {
+		for (i=0; i<l; i++) {
+		    uP.wpattern[i] = __unicode16StringVal(path)[i];
+		}
+		uP.wpattern[i++] = '\\';
+		uP.wpattern[i++] = '*';
+		uP.wpattern[i] = 0;
 
-                do {
-                    __threadErrno = 0;
-                    d = STX_API_NOINT_CALL2( "FindFirstFileW", FindFirstFileW, uP.wpattern, &uD.wdata );
-                } while ((d < 0) && (__threadErrno == EINTR));
+		do {
+		    __threadErrno = 0;
+		    d = STX_API_NOINT_CALL2( "FindFirstFileW", FindFirstFileW, uP.wpattern, &uD.wdata );
+		} while ((d < 0) && (__threadErrno == EINTR));
 
-                if (d == INVALID_HANDLE_VALUE) {
-                    __INST(lastErrorNumber) = __mkSmallInteger(GetLastError());
-                } else {
-                    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
-                    entry = __MKU16STRING( uD.wdata.cFileName );
-                    ok = true;
-                }
-            }
-        }
+		if (d == INVALID_HANDLE_VALUE) {
+		    __INST(lastErrorNumber) = __mkSmallInteger(GetLastError());
+		} else {
+		    dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp);
+		    entry = __MKU16STRING( uD.wdata.cFileName );
+		    ok = true;
+		}
+	    }
+	}
     }
 # endif
 #endif
 %}.
     ok isNil ifTrue:[
-        "
-         opendir not avalable - use slower pipe
-        "
-        ^ PipeStream readingFrom:('cd ' , pathName , '; ls -a')
+	"
+	 opendir not avalable - use slower pipe
+	"
+	^ PipeStream readingFrom:('cd ' , pathName , '; ls -a')
     ].
 
     (ok == true) ifTrue:[
-        Lobby register:self.
-        entry isNil ifTrue:[
-            self nextLine. "read 1st entry into readAheadEntry buffer"
-        ] ifFalse:[
-            readAheadEntry := entry.
-        ].
-        ^ self
+	Lobby register:self.
+	entry isNil ifTrue:[
+	    self nextLine. "read 1st entry into readAheadEntry buffer"
+	] ifFalse:[
+	    readAheadEntry := entry.
+	].
+	^ self
     ].
     dirPointer notNil ifTrue:[^ self errorAlreadyOpen].
     lastErrorNumber notNil ifTrue:[^ self openError].
@@ -795,9 +792,9 @@
 !DirectoryStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.74 2010-04-30 16:48:14 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.75 2011-10-07 13:57:55 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.74 2010-04-30 16:48:14 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.75 2011-10-07 13:57:55 cg Exp $'
 ! !