FileStream.st
changeset 2936 5cce0f2166d9
parent 2921 f42da059311e
child 2963 17bd9be72f9b
--- a/FileStream.st	Tue Sep 16 06:10:09 1997 +0200
+++ b/FileStream.st	Tue Sep 16 16:55:06 1997 +0200
@@ -12,7 +12,7 @@
 
 ExternalStream subclass:#FileStream
 	instanceVariableNames:'pathName canPosition'
-	classVariableNames:'OpenErrorSignal'
+	classVariableNames:''
 	poolDictionaries:''
 	category:'Streams-External'
 !
@@ -172,14 +172,6 @@
     ]
 ! !
 
-!FileStream class methodsFor:'Signal constants'!
-
-openErrorSignal
-    "return the signal raised if an open fails"
-
-    ^ OpenErrorSignal
-! !
-
 !FileStream class methodsFor:'instance creation'!
 
 appendingOldFileNamed:filename
@@ -429,6 +421,153 @@
     ^ nil
 ! !
 
+!FileStream methodsFor:'positioning'!
+
+position
+    "return the read/write position in the file -
+     notice, in smalltalk indices start at 1 so begin of file is 1"
+
+%{  /* NOCONTEXT */
+
+    FILE *f;
+    long currentPosition;
+    extern long ftell(), lseek();
+
+    if (__INST(filePointer) != nil) {
+	f = __FILEVal(__INST(filePointer));
+	do {
+	    if (__INST(buffered) == true) {
+		currentPosition = ftell(f);
+	    } else {
+		currentPosition = lseek(fileno(f), 0L, SEEK_CUR);
+	    }
+	} while ((currentPosition < 0) && (errno == EINTR));
+	if (currentPosition >= 0) {
+	    /*
+	     * notice: Smalltalk index starts at 1
+	     */
+	    RETURN ( __MKSMALLINT(currentPosition + 1) );
+	}
+	__INST(lastErrorNumber) = __MKSMALLINT(errno);
+    }
+%}.
+    lastErrorNumber notNil ifTrue:[^ self ioError].
+    filePointer isNil ifTrue:[^ self errorNotOpen].
+    ^ self primitiveFailed
+!
+
+position:newPos
+    "set the read/write position in the file"
+
+%{  /* NOCONTEXT */
+
+    FILE *f;
+    long ret;
+    OBJ fp;
+    long nP;
+    extern long lseek();
+
+    if ((__INST(canPosition) != false) 
+     || (newPos == __MKSMALLINT(1))) {
+        if ((fp = __INST(filePointer)) != nil) {
+	    if (__isSmallInteger(newPos)) {
+	        f = __FILEVal(fp);
+	        nP = (long)__intVal(newPos);
+
+	        /*
+	         * notice: Smalltalk index starts at 1
+	         */
+	        nP--;
+
+	        do {
+		    if (__INST(buffered) == true) {
+		        ret = fseek(f, nP, SEEK_SET);
+		    } else {
+		        ret = lseek(fileno(f), nP, SEEK_SET);
+		    }
+	        } while ((ret < 0) && (errno == EINTR));
+	        if (ret >= 0) {
+		    __INST(position) = newPos;
+		    /*
+		     * just to make certain ...
+		     */
+		    __INST(hitEOF) = false;
+		    RETURN ( self );
+	        }
+	        __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	    }
+	}
+    }
+%}.
+    canPosition == false ifTrue:[
+	"/ position by rewinding & re-reading everything up-to
+	"/ that point.
+	^ self slowPosition:newPos
+    ].
+    lastErrorNumber notNil ifTrue:[^ self ioError].
+    filePointer isNil ifTrue:[^ self errorNotOpen].
+    ^ self primitiveFailed
+!
+
+setToEnd
+    "set the read/write position in the file to be at the end of the file"
+
+%{
+    FILE *f;
+    long ret;
+    extern long lseek();
+
+    if (__INST(filePointer) != nil) {
+	f = __FILEVal(__INST(filePointer));
+	__INST(position) = nil;
+	do {
+	    if (__INST(buffered) == true) {
+		ret = fseek(f, 0L, SEEK_END);
+	    } else {
+		ret = lseek(fileno(f), 0L, SEEK_END);
+	    }
+	} while ((ret < 0) && (errno == EINTR));
+	if (ret >= 0) {
+	    RETURN ( self );
+	}
+	__INST(lastErrorNumber) = __MKSMALLINT(errno);
+    }
+%}.
+    lastErrorNumber notNil ifTrue:[^ self ioError].
+    filePointer isNil ifTrue:[^ self errorNotOpen].
+    ^ self primitiveFailed
+!
+
+slowPosition:newPos
+    "position the file by re-reading everything up-to newPos.
+     The effect is the same as that of #position:, but its much slower.
+     This is required to reposition nonPositionable streams, such
+     as tape-streams or variable-record-RMS files under VMS.
+     Caveat:
+         This should really be done transparently by the stdio library."
+
+    |buffer amount|
+
+    self isReadable ifFalse:[
+	"/ sorry
+	^ self positionError
+    ].
+
+    buffer := ByteArray new:8*1024.
+
+    (position isNil "/ i.e. unknown
+    or:[newPos < position]) ifTrue:[
+        self reset.
+    ].
+    [position < newPos] whileTrue:[
+	amount := (buffer size) min:(newPos-position).
+	(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[
+	    ^ self positionError
+	].
+    ].
+    "/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR.
+! !
+
 !FileStream methodsFor:'printing & storing'!
 
 printOn:aStream
@@ -797,160 +936,8 @@
     mode := aModeSymbol
 ! !
 
-!FileStream methodsFor:'positioning'!
-
-position
-    "return the read/write position in the file -
-     notice, in smalltalk indices start at 1 so begin of file is 1"
-
-%{  /* NOCONTEXT */
-
-    FILE *f;
-    long currentPosition;
-    extern long ftell(), lseek();
-
-    if (__INST(filePointer) != nil) {
-	f = __FILEVal(__INST(filePointer));
-	do {
-	    if (__INST(buffered) == true) {
-		currentPosition = ftell(f);
-	    } else {
-		currentPosition = lseek(fileno(f), 0L, SEEK_CUR);
-	    }
-	} while ((currentPosition < 0) && (errno == EINTR));
-	if (currentPosition >= 0) {
-	    /*
-	     * notice: Smalltalk index starts at 1
-	     */
-	    RETURN ( __MKSMALLINT(currentPosition + 1) );
-	}
-	__INST(lastErrorNumber) = __MKSMALLINT(errno);
-    }
-%}.
-    lastErrorNumber notNil ifTrue:[^ self ioError].
-    filePointer isNil ifTrue:[^ self errorNotOpen].
-    ^ self primitiveFailed
-!
-
-position:newPos
-    "set the read/write position in the file"
-
-%{  /* NOCONTEXT */
-
-    FILE *f;
-    long ret;
-    OBJ fp;
-    long nP;
-    extern long lseek();
-
-    if ((__INST(canPosition) != false) 
-     || (newPos == __MKSMALLINT(1))) {
-        if ((fp = __INST(filePointer)) != nil) {
-	    if (__isSmallInteger(newPos)) {
-	        f = __FILEVal(fp);
-	        nP = (long)__intVal(newPos);
-
-	        /*
-	         * notice: Smalltalk index starts at 1
-	         */
-	        nP--;
-
-	        do {
-		    if (__INST(buffered) == true) {
-		        ret = fseek(f, nP, SEEK_SET);
-		    } else {
-		        ret = lseek(fileno(f), nP, SEEK_SET);
-		    }
-	        } while ((ret < 0) && (errno == EINTR));
-	        if (ret >= 0) {
-		    __INST(position) = newPos;
-		    /*
-		     * just to make certain ...
-		     */
-		    __INST(hitEOF) = false;
-		    RETURN ( self );
-	        }
-	        __INST(lastErrorNumber) = __MKSMALLINT(errno);
-	    }
-	}
-    }
-%}.
-    canPosition == false ifTrue:[
-	"/ position by rewinding & re-reading everything up-to
-	"/ that point.
-	^ self slowPosition:newPos
-    ].
-    lastErrorNumber notNil ifTrue:[^ self ioError].
-    filePointer isNil ifTrue:[^ self errorNotOpen].
-    ^ self primitiveFailed
-!
-
-slowPosition:newPos
-    "position the file by re-reading everything up-to newPos.
-     The effect is the same as that of #position:, but its much slower.
-     This is required to reposition nonPositionable streams, such
-     as tape-streams or variable-record-RMS files under VMS.
-     Caveat:
-         This should really be done transparently by the stdio library."
-
-    |buffer amount|
-
-    self isReadable ifFalse:[
-	"/ sorry
-	^ self positionError
-    ].
-
-    buffer := ByteArray new:8*1024.
-
-    (position isNil "/ i.e. unknown
-    or:[newPos < position]) ifTrue:[
-        self reset.
-    ].
-    [position < newPos] whileTrue:[
-	amount := (buffer size) min:(newPos-position).
-	(self nextBytes:amount into:buffer startingAt:1) ~~ amount ifTrue:[
-	    ^ self positionError
-	].
-    ].
-    "/ ('FileStream [info]: slow position - please convert ''' , pathName printString , ''' to streamLF format') infoPrintCR.
-!
-
-setToEnd
-    "set the read/write position in the file to be at the end of the file"
-
-%{
-    FILE *f;
-    long ret;
-    extern long lseek();
-
-    if (__INST(filePointer) != nil) {
-	f = __FILEVal(__INST(filePointer));
-	__INST(position) = nil;
-	do {
-	    if (__INST(buffered) == true) {
-		ret = fseek(f, 0L, SEEK_END);
-	    } else {
-		ret = lseek(fileno(f), 0L, SEEK_END);
-	    }
-	} while ((ret < 0) && (errno == EINTR));
-	if (ret >= 0) {
-	    RETURN ( self );
-	}
-	__INST(lastErrorNumber) = __MKSMALLINT(errno);
-    }
-%}.
-    lastErrorNumber notNil ifTrue:[^ self ioError].
-    filePointer isNil ifTrue:[^ self errorNotOpen].
-    ^ self primitiveFailed
-! !
-
 !FileStream methodsFor:'queries'!
 
-size
-    self obsoleteMethodWarning:'use #fileSize'.
-    ^ self fileSize.
-!
-
 fileSize
     "return the size in bytes of the file"
 
@@ -997,6 +984,11 @@
     lastErrorNumber notNil ifTrue:[^ self ioError].
     filePointer isNil ifTrue:[^ self errorNotOpen].
     ^ self primitiveFailed
+!
+
+size
+    self obsoleteMethodWarning:'use #fileSize'.
+    ^ self fileSize.
 ! !
 
 !FileStream methodsFor:'testing'!
@@ -1011,5 +1003,6 @@
 !FileStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.45 1997-09-15 20:34:41 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/FileStream.st,v 1.46 1997-09-16 14:55:06 stefan Exp $'
 ! !
+FileStream initialize!