migration support
authorClaus Gittinger <cg@exept.de>
Wed, 28 Jun 2000 10:29:29 +0200
changeset 5431 24ce291c71f2
parent 5430 7d0aa5fc6c22
child 5432 c71559a881e2
migration support
ExternalStream.st
--- a/ExternalStream.st	Wed Jun 28 10:15:22 2000 +0200
+++ b/ExternalStream.st	Wed Jun 28 10:29:29 2000 +0200
@@ -2370,126 +2370,127 @@
 
     __INST(lastErrorNumber) = nil;
     if (((fp = __INST(filePointer)) != nil)
-	&& (__INST(mode) != @symbol(writeonly))
-	&& (__INST(binary) != true)
+        && (__INST(mode) != @symbol(writeonly))
+        && (__INST(binary) != true)
     ) {
-	f = __FILEVal(fp);
-	buffer[0] = '\0';
-
-	_buffered = (__INST(buffered) == true);
-	if (_buffered) {
-	    __READING__(f);
-	} 
-
-	rslt = nextPtr = buffer;
-	limit = buffer + sizeof(buffer) - 2;
-
-	for (;;) {
-	    __READBYTE__(ret, f, nextPtr, _buffered);
-	    if (ret <= 0) {
-		if (nextPtr == buffer)
-		    rslt = NULL;
-		if (ret == 0) {
-		    __INST(hitEOF) = true;
-		    break;
-		} else {
-		    __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
-		    goto err;
-		}
-	    }
-
-	    if (*nextPtr == '\n') {
-		cutOff = 1;
-		*nextPtr = '\0';
-		break;
-	    }
-	    if (*nextPtr == '\r') {
-		char peekChar;
-
-		/*
-		 * peek ahead for a newLine ...
-		 */
-		__READBYTE__(ret, f, &peekChar, _buffered);
-		if (ret <= 0) {
-		    cutOff = 1;
-		    *nextPtr = '\0';
-		    if (ret == 0) {
-			__INST(hitEOF) = true;
-			break;
-		    }
-		    __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
-		    goto err;
-		}
-
-		if (peekChar == '\n') {
-		    cutOff = 2;
-		    *nextPtr = '\0';
-		    break;
-		}
-
-		__UNGETC__(peekChar, f, _buffered);
-
-		cutOff = 1;
-		*nextPtr = '\0';
-		break;
-	    }
-
-	    nextPtr++;
-	    if (nextPtr >= limit) {
-		*nextPtr = '\0';
-		lineTooLong = 1;
-		if (@global(InfoPrinting) == true) {
-		    fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
-		}
-		break;
-	    }
-	}
-
-	if (rslt != NULL) {
-	    len = nextPtr-buffer;
-
-	    if (__INST(position) != nil) {
-		int __p;
-
-		__p = __intVal(__INST(position)) + len + cutOff;
-		__INST(position) = __MKSMALLINT(__p);
-	    }
-	    /* remove any EOL character */
-	    if (len != 0) {
-		if (buffer[len-1] == '\n') {
-		    buffer[--len] = '\0';
-		}
-		if ((len != 0) && (buffer[len-1] == '\r')) {
-		    buffer[--len] = '\0';
-		}
-	    }
-	    line = __MKSTRING_L(buffer, len);
-	    if (! lineTooLong) {
-		RETURN ( line );
-	    }
-	}
+        f = __FILEVal(fp);
+        buffer[0] = '\0';
+
+        _buffered = (__INST(buffered) == true);
+        if (_buffered) {
+            __READING__(f);
+        } 
+
+        rslt = nextPtr = buffer;
+        limit = buffer + sizeof(buffer) - 2;
+
+        for (;;) {
+            __READBYTE__(ret, f, nextPtr, _buffered);
+            if (ret <= 0) {
+                if (nextPtr == buffer)
+                    rslt = NULL;
+                if (ret == 0) {
+                    __INST(hitEOF) = true;
+                    break;
+                } else {
+                    __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
+                    goto err;
+                }
+            }
+
+            if (*nextPtr == '\n') {
+                cutOff = 1;
+                *nextPtr = '\0';
+                break;
+            }
+            if (*nextPtr == '\r') {
+                char peekChar;
+
+                /*
+                 * peek ahead for a newLine ...
+                 */
+                __READBYTE__(ret, f, &peekChar, _buffered);
+                if (ret <= 0) {
+                    cutOff = 1;
+                    *nextPtr = '\0';
+                    if (ret == 0) {
+                        __INST(hitEOF) = true;
+                        break;
+                    }
+                    __INST(lastErrorNumber) = __MKSMALLINT(__threadErrno);
+                    goto err;
+                }
+
+                if (peekChar == '\n') {
+                    cutOff = 2;
+                    *nextPtr = '\0';
+                    break;
+                }
+
+                __UNGETC__(peekChar, f, _buffered);
+
+                cutOff = 1;
+                *nextPtr = '\0';
+                break;
+            }
+
+            nextPtr++;
+            if (nextPtr >= limit) {
+                *nextPtr = '\0';
+                lineTooLong = 1;
+                if (@global(InfoPrinting) == true) {
+                    fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
+                }
+                break;
+            }
+        }
+
+        if (rslt != NULL) {
+            len = nextPtr-buffer;
+
+            if (__INST(position) != nil) {
+                int __p;
+
+                __p = __intVal(__INST(position)) + len + cutOff;
+                __INST(position) = __MKSMALLINT(__p);
+            }
+            /* remove any EOL character */
+            if (len != 0) {
+                if (buffer[len-1] == '\n') {
+                    buffer[--len] = '\0';
+                }
+                if ((len != 0) && (buffer[len-1] == '\r')) {
+                    buffer[--len] = '\0';
+                }
+            }
+            line = __MKSTRING_L(buffer, len);
+            if (! lineTooLong) {
+                RETURN ( line );
+            }
+        }
     }
 err: ;
 %}.
     line notNil ifTrue:[
-	"/ the line as read is longer than 32k characters (boy - what a line)
-	"/ The exception could be handled by reading more and returning the
-	"/ concatenation in your exception handler (the receiver and the partial
-	"/ line are passed as parameter)
-
-	LineTooLongErrorSignal isHandled ifTrue:[
-	    ^ LineTooLongErrorSignal
-		raiseRequestWith:(Array with:self with:line)
-		     errorString:('line too long read error')
-	].
-	^ line , self nextLine
+        "/ the line as read is longer than 32k characters (boy - what a line)
+        "/ The exception could be handled by reading more and returning the
+        "/ concatenation in your exception handler (the receiver and the partial
+        "/ line are passed as parameter)
+
+        LineTooLongErrorSignal isHandled ifTrue:[
+            ^ LineTooLongErrorSignal
+                raiseRequestWith:(Array with:self with:line)
+                     errorString:('line too long read error')
+        ].
+        ^ line , self nextLine
     ].
 
-    hitEOF ifTrue:[^ self pastEnd].
+    (hitEOF == true) ifTrue:[^ self pastEnd].
     lastErrorNumber notNil ifTrue:[^ self readError].
     filePointer isNil ifTrue:[^ self errorNotOpen].
     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
-    ^ self errorBinary
+    (binary == true) ifTrue:[^ self errorBinary].
+    ^ super nextLine
 !
 
 nextPutLine:aString
@@ -5619,6 +5620,6 @@
 !ExternalStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.215 2000-06-28 08:15:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.216 2000-06-28 08:29:29 cg Exp $'
 ! !
 ExternalStream initialize!