--- a/ExternalStream.st Mon Dec 16 16:00:23 2019 +0100
+++ b/ExternalStream.st Mon Dec 16 16:23:24 2019 +0100
@@ -2269,29 +2269,29 @@
OBJ _handle = __INST(handle);
if (_handle != nil) {
- if ((__INST(handleType) == @symbol(fileHandle))
- || (__INST(handleType) == @symbol(socketHandle))) {
- RETURN (_handle);
- }
- if (__INST(handleType) == @symbol(pipeFilePointer)) {
- RETURN (__MKINT(fileno(__FILEVal(_handle))));
- }
- if ((__INST(handleType) == nil)
- || (__INST(handleType) == @symbol(filePointer))
- || (__INST(handleType) == @symbol(socketFilePointer))
- || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ if ((__INST(handleType) == @symbol(fileHandle))
+ || (__INST(handleType) == @symbol(socketHandle))) {
+ RETURN (_handle);
+ }
+ if (__INST(handleType) == @symbol(pipeFilePointer)) {
+ RETURN (__MKINT(fileno(__FILEVal(_handle))));
+ }
+ if ((__INST(handleType) == nil)
+ || (__INST(handleType) == @symbol(filePointer))
+ || (__INST(handleType) == @symbol(socketFilePointer))
+ || (__INST(handleType) == @symbol(pipeFilePointer))) {
+ FILE *file = __FILEVal(_handle);
+ if (file != NULL) {
+ int fileNo = fileno(file);
+ if (fileNo >= 0) {
#ifdef __win32__
- RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileno(__FILEVal(_handle)))));
+ RETURN(__MKEXTERNALADDRESS(_get_osfhandle(fileNo)));
#else
- FILE *file = __FILEVal(_handle);
- if (file != NULL) {
- int fileNo = fileno(file);
- if (fileNo >= 0) {
- RETURN (__MKINT(fileNo));
- }
- }
+ RETURN (__MKINT(fileNo));
#endif
- }
+ }
+ }
+ }
}
%}.
^ handle
@@ -2444,7 +2444,7 @@
!ExternalStream methodsFor:'defaults'!
bufferSizeForBulkCopy
- "return the size of buffer used when copying big files/bulk data
+ "return the size of buffer used when copying big files/bulk data
from one stream to another.
Due to a bug on older Windows systems, the default used
is chosen very conservatively, as the copy used to fail with big buffers.
@@ -2458,8 +2458,8 @@
DefaultCopyBufferSize notNil ifTrue:[^ DefaultCopyBufferSize].
(OperatingSystem isMSWINDOWSlike and:[OperatingSystem isWin7Like not]) ifTrue:[
- "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
- ^ 1 * 1024.
+ "/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
+ ^ 1 * 1024.
].
^ 64 * 1024.
@@ -2515,9 +2515,9 @@
"report an error, that the stream is in binary mode"
^ InvalidModeError
- raiseRequestWith:self
- errorString:(self className , ' is in binary mode')
- "/ in:thisContext sender
+ raiseRequestWith:self
+ errorString:(self className , ' is in binary mode')
+ "/ in:thisContext sender
"Modified: / 08-05-1999 / 20:12:43 / cg"
"Modified: / 28-06-2019 / 08:43:06 / Claus Gittinger"
@@ -2529,9 +2529,9 @@
"report an error, that the stream is not in binary mode"
^ InvalidModeError
- raiseRequestWith:self
- errorString:(self className , ' is not in binary mode')
- "/ in:thisContext sender
+ raiseRequestWith:self
+ errorString:(self className , ' is not in binary mode')
+ "/ in:thisContext sender
"Modified: / 08-05-1999 / 20:12:40 / cg"
"Modified: / 28-06-2019 / 08:43:11 / Claus Gittinger"
@@ -2543,9 +2543,9 @@
"report an error, that the stream is not in buffered mode"
^ StreamError
- raiseRequestWith:self
- errorString:(self className , ' is unbuffered - operation not allowed')
- "/ in:thisContext sender
+ raiseRequestWith:self
+ errorString:(self className , ' is unbuffered - operation not allowed')
+ "/ in:thisContext sender
"Modified: / 08-05-1999 / 20:12:36 / cg"
"Modified: / 28-06-2019 / 08:43:14 / Claus Gittinger"
@@ -2783,7 +2783,7 @@
|line error|
-%{ /* STACK:100000 */
+%{ /* STACK:50000 */
FILEPOINTER f;
int len, ret;
@@ -3685,11 +3685,11 @@
buffer := ByteArray uninitializedNew:count.
n := self nextAvailableBytes:count into:buffer startingAt:1.
n == 0 ifTrue:[
- ^ #[]
+ ^ #[]
].
n ~~ count ifTrue:[
- ^ buffer copyTo:n
+ ^ buffer copyTo:n
].
^ buffer.
@@ -3741,102 +3741,102 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- && __bothSmallInteger(count, start)
- ) {
- f = __FILEVal(fp);
-
- cnt = __intVal(count);
- offs = __intVal(start) - 1;
-
- if (__isExternalBytesLike(anObject)) {
- OBJ sz;
-
- nInstBytes = 0;
- extPtr = (char *)(__externalBytesAddress(anObject));
- if (extPtr == NULL) goto bad;
- sz = __externalBytesSize(anObject);
- if (__isSmallInteger(sz)) {
- objSize = __intVal(sz);
- } else {
- objSize = 0; /* unknown */
- }
- } else {
- OBJ oClass = __Class(anObject);
- int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-
- nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
-
- switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- case WORDARRAY:
- case LONGARRAY:
- case SWORDARRAY:
- case SLONGARRAY:
- case FLOATARRAY:
- break;
- case DOUBLEARRAY:
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ && __bothSmallInteger(count, start)
+ ) {
+ f = __FILEVal(fp);
+
+ cnt = __intVal(count);
+ offs = __intVal(start) - 1;
+
+ if (__isExternalBytesLike(anObject)) {
+ OBJ sz;
+
+ nInstBytes = 0;
+ extPtr = (char *)(__externalBytesAddress(anObject));
+ if (extPtr == NULL) goto bad;
+ sz = __externalBytesSize(anObject);
+ if (__isSmallInteger(sz)) {
+ objSize = __intVal(sz);
+ } else {
+ objSize = 0; /* unknown */
+ }
+ } else {
+ OBJ oClass = __Class(anObject);
+ int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+
+ nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+
+ switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ break;
+ case DOUBLEARRAY:
#ifdef __NEED_DOUBLE_ALIGN
- nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
#endif
- break;
- case LONGLONGARRAY:
- case SLONGLONGARRAY:
+ break;
+ case LONGLONGARRAY:
+ case SLONGLONGARRAY:
#ifdef __NEED_LONGLONG_ALIGN
- nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+ nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
#endif
- break;
- default:
- goto bad;
- }
- extPtr = (char *)0;
- objSize = __Size(anObject) - nInstBytes;
- }
-
- if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f);
- }
-
- if (extPtr) {
- __READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType));
- } else {
- /*
- * on interrupt, anObject may be moved to another location.
- * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
- * to get a new address.
- */
- offs += nInstBytes;
- __READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType));
- }
- /* 0 is NOT an EOF condition here ... */
- if (ret >= 0) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + ret;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN (__mkSmallInteger(ret));
- }
- __INST(position) = nil;
+ break;
+ default:
+ goto bad;
+ }
+ extPtr = (char *)0;
+ objSize = __Size(anObject) - nInstBytes;
+ }
+
+ if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f);
+ }
+
+ if (extPtr) {
+ __READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered, __INST(handleType));
+ } else {
+ /*
+ * on interrupt, anObject may be moved to another location.
+ * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
+ * to get a new address.
+ */
+ offs += nInstBytes;
+ __READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered, __INST(handleType));
+ }
+ /* 0 is NOT an EOF condition here ... */
+ if (ret >= 0) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + ret;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (__mkSmallInteger(ret));
+ }
+ __INST(position) = nil;
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
}
bad: ;
%}.
hitEOF ifTrue:[^ 0].
error notNil ifTrue:[
- lastErrorNumber := error.
- ^ self readError:error
+ lastErrorNumber := error.
+ ^ self readError:error
].
handle isNil ifTrue:[^ self errorNotOpen].
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
@@ -4620,8 +4620,8 @@
%{
int num;
union {
- char bytes[2];
- short shortVal;
+ char bytes[2];
+ short shortVal;
} u;
OBJ fp;
@@ -4631,44 +4631,44 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
- int cnt;
-
- if (__isSmallInteger(anIntegerOrCharacter)) {
- num = __intVal(anIntegerOrCharacter);
- } else if (__isCharacter(anIntegerOrCharacter)) {
- num = __smallIntegerVal(__characterVal(anIntegerOrCharacter));
- } else
- goto out;
-
- u.shortVal = num;
-
- if (_buffered) {
- __WRITING__(f)
- }
- __WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType));
-
- if (cnt == 2) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 2;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
- __INST(position) = nil; /* i.e. do not know */
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+ int cnt;
+
+ if (__isSmallInteger(anIntegerOrCharacter)) {
+ num = __intVal(anIntegerOrCharacter);
+ } else if (__isCharacter(anIntegerOrCharacter)) {
+ num = __smallIntegerVal(__characterVal(anIntegerOrCharacter));
+ } else
+ goto out;
+
+ u.shortVal = num;
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
+ __WRITEBYTES__(cnt, f, u.bytes, 2, _buffered, __INST(handleType));
+
+ if (cnt == 2) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 2;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
out:;
%}.
@@ -4813,37 +4813,37 @@
(i.e. both signed and unsigned int32 values can be written.
Works in both binary and text modes.
Notice: this message should not be sent explicitly by ANY program.
- the following implementation replaces the code of either nextPutInt32MSB or LSB
- dynamically (see #initialize on the class side)"
+ the following implementation replaces the code of either nextPutInt32MSB or LSB
+ dynamically (see #initialize on the class side)"
|error|
%{
int num;
union {
- char bytes[4];
- int intVal;
+ char bytes[4];
+ int intVal;
} u;
OBJ fp;
__INST(lastErrorNumber) = nil;
if (__isSmallInteger(anInteger)) {
- num = __intVal(anInteger);
+ num = __intVal(anInteger);
} else {
#if __POINTER_SIZE__ == 8
- // always more than 4-bytes
- goto badArg;
+ // always more than 4-bytes
+ goto badArg;
#else
- num = __longIntVal(anInteger);
- if (num == 0) {
- num = __signedLongIntVal(anInteger);
- if (num == 0) {
- /* bad arg or out-of-range integer
- * (handled by the fallBack code)
- */
- goto badArg;
- }
- }
+ num = __longIntVal(anInteger);
+ if (num == 0) {
+ num = __signedLongIntVal(anInteger);
+ if (num == 0) {
+ /* bad arg or out-of-range integer
+ * (handled by the fallBack code)
+ */
+ goto badArg;
+ }
+ }
#endif
}
@@ -4852,36 +4852,36 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- int _buffered = (__INST(buffered) == true);
- FILEPOINTER f = __FILEVal(fp);
- int cnt;
-
- u.intVal = num;
- if (_buffered) {
- __WRITING__(f)
- }
- __WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType));
-
- if (cnt == 4) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 4;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( self );
- }
- __INST(position) = nil; /* i.e. do not know */
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ int _buffered = (__INST(buffered) == true);
+ FILEPOINTER f = __FILEVal(fp);
+ int cnt;
+
+ u.intVal = num;
+ if (_buffered) {
+ __WRITING__(f)
+ }
+ __WRITEBYTES__(cnt, f, u.bytes, 4, _buffered, __INST(handleType));
+
+ if (cnt == 4) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 4;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( self );
+ }
+ __INST(position) = nil; /* i.e. do not know */
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
}
badArg: ;
%}.
@@ -6169,6 +6169,16 @@
mode == #readonly ifTrue:[
^ self errorReadOnly
].
+%{
+#ifdef __win32__
+ {
+ FILEPOINTER f = __FILEVal(__INST(handle));
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ RETURN(false);
+ }
+ }
+#endif
+%}.
fd := self fileHandle.
(OperatingSystem writeCheck:fd) ifTrue:[^ false].
@@ -6298,32 +6308,32 @@
|| (__INST(handleType) == @symbol(filePointer))
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
- int _buffered = (__INST(buffered) == true);
-
- if ((fp = __INST(handle)) != nil) {
- if (__INST(mode) != @symbol(readonly)) {
- if (1 /* _buffered */) {
- FILEPOINTER f = __FILEVal(fp);
+ OBJ fp;
+ int _buffered = (__INST(buffered) == true);
+
+ if ((fp = __INST(handle)) != nil) {
+ if (__INST(mode) != @symbol(readonly)) {
+ if (1 /* _buffered */) {
+ FILEPOINTER f = __FILEVal(fp);
#ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- __win32_fflush(f);
- } else {
- int rslt;
-
- do {
- __threadErrno = 0;
- rslt = __STX_C_CALL1("fflush", fflush, f);
- } while((rslt < 0) && (__threadErrno == EINTR));
- }
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ __win32_fflush(f);
+ } else {
+ int rslt;
+
+ do {
+ __threadErrno = 0;
+ rslt = __STX_C_CALL1("fflush", fflush, f);
+ } while((rslt < 0) && (__threadErrno == EINTR));
+ }
#else /* ! __win32__ */
- __BEGIN_INTERRUPTABLE__
- FFLUSH(f);
- __END_INTERRUPTABLE__
+ __BEGIN_INTERRUPTABLE__
+ FFLUSH(f);
+ __END_INTERRUPTABLE__
#endif /* ! __win32__ */
- }
- }
- }
+ }
+ }
+ }
}
%}
@@ -6342,9 +6352,9 @@
if ((handle != STObject.Nil)
&& (aCharacter.isSTCharacter())) {
- handle.writeChar( aCharacter );
- self.instVarAt_put(I_position, STObject.Nil);
- return __c__._RETURN(aCharacter);
+ handle.writeChar( aCharacter );
+ self.instVarAt_put(I_position, STObject.Nil);
+ return __c__._RETURN(aCharacter);
}
#else
__INST(lastErrorNumber) = nil;
@@ -6353,112 +6363,112 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
-
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
- int cnt;
- char buff[2];
- int nBytes = 1;
-
- if (__INST(binary) != true) {
- if (__isCharacter(aCharacter)) {
- unsigned int codePoint = __intVal(__characterVal(aCharacter));
- if (codePoint <= 0xFF) {
- unsigned char c = codePoint;
- buff[0] = c; nBytes = 1;
-
- if (c == '\n') {
- OBJ mode = __INST(eolMode);
- if (mode == @symbol(nl)) {
- // no EOL translation
- } else if (mode == nil) {
- // no EOL translation
- } else if (mode == @symbol(cr)) {
- buff[0] = '\r';
- } else if (mode == @symbol(eot)) {
- buff[0] = '\004';
- } else if (mode == @symbol(etx)) {
- buff[0] = '\003';
- } else if (mode == @symbol(crlf)) {
- buff[0] = '\r';
- buff[1] = '\n';
- nBytes = 2;
- }
- }
+ OBJ fp;
+
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+ int cnt;
+ char buff[2];
+ int nBytes = 1;
+
+ if (__INST(binary) != true) {
+ if (__isCharacter(aCharacter)) {
+ unsigned int codePoint = __intVal(__characterVal(aCharacter));
+ if (codePoint <= 0xFF) {
+ unsigned char c = codePoint;
+ buff[0] = c; nBytes = 1;
+
+ if (c == '\n') {
+ OBJ mode = __INST(eolMode);
+ if (mode == @symbol(nl)) {
+ // no EOL translation
+ } else if (mode == nil) {
+ // no EOL translation
+ } else if (mode == @symbol(cr)) {
+ buff[0] = '\r';
+ } else if (mode == @symbol(eot)) {
+ buff[0] = '\004';
+ } else if (mode == @symbol(etx)) {
+ buff[0] = '\003';
+ } else if (mode == @symbol(crlf)) {
+ buff[0] = '\r';
+ buff[1] = '\n';
+ nBytes = 2;
+ }
+ }
doWrite:
- if (! f) {
- fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n");
- __INST(handle) = nil;
- goto out;
- }
-
- if (_buffered) {
- __WRITING__(f)
- }
+ if (! f) {
+ fprintf(stderr, "oops - fileHandle is NULL in nextPut:\n");
+ __INST(handle) = nil;
+ goto out;
+ }
+
+ if (_buffered) {
+ __WRITING__(f)
+ }
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(buff, 1, nBytes, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(buff, 1, nBytes, f);
+ } else
# endif
- {
- __WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType));
- }
- if (cnt == nBytes) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + nBytes;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN ( aCharacter );
- }
+ {
+ __WRITEBYTES__(cnt, f, buff, nBytes, _buffered, __INST(handleType));
+ }
+ if (cnt == nBytes) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + nBytes;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN ( aCharacter );
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- }
- }
- } else {
- if (__isSmallInteger(aCharacter)) {
- unsigned char c = __intVal(aCharacter);
- buff[0] = c; nBytes = 1;
- goto doWrite;
- }
- }
- }
+ error = __mkSmallInteger(__threadErrno);
+ }
+ }
+ } else {
+ if (__isSmallInteger(aCharacter)) {
+ unsigned char c = __intVal(aCharacter);
+ buff[0] = c; nBytes = 1;
+ goto doWrite;
+ }
+ }
+ }
}
out: ;
#endif /* not SCHTEAM */
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ aCharacter
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ aCharacter
].
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
binary == true ifTrue:[
- aCharacter isInteger ifFalse:[
- self argumentMustBeInteger.
- ^ aCharacter.
- ].
+ aCharacter isInteger ifFalse:[
+ self argumentMustBeInteger.
+ ^ aCharacter.
+ ].
] ifFalse:[
- (aCharacter isCharacter not
- or:[aCharacter codePoint > 16rFF]) ifTrue:[
- self argumentMustBeCharacter.
- ^ aCharacter.
- ].
+ (aCharacter isCharacter not
+ or:[aCharacter codePoint > 16rFF]) ifTrue:[
+ self argumentMustBeCharacter.
+ ^ aCharacter.
+ ].
].
"/ migration support
self
- nextPutByte:aCharacter asInteger
- toFile:handle.
+ nextPutByte:aCharacter asInteger
+ toFile:handle.
^ aCharacter
"Modified: / 22-11-2018 / 14:47:13 / Stefan Vogel"
@@ -6477,9 +6487,9 @@
if ((handle != STObject.Nil)
&& (aCollection.isSTString())) {
- handle.writeCharacters( aCollection.asSTString().characters );
- self.instVarAt_put(I_position, STObject.Nil);
- return __c__._RETURN_self();
+ handle.writeCharacters( aCollection.asSTString().characters );
+ self.instVarAt_put(I_position, STObject.Nil);
+ return __c__._RETURN_self();
}
#else
@@ -6490,167 +6500,167 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- OBJ fp;
-
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(readonly))
- ) {
- INT len, cnt;
- INT o_offs;
- FILEPOINTER f = __FILEVal(fp);
- int _buffered = (__INST(buffered) == true);
-
- if (! f) {
- fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n");
- __INST(handle) = nil;
- goto out;
- }
- if (_buffered) {
- __WRITING__(f)
- }
-
- if (__isStringLike(aCollection)) {
- OBJ mode = __INST(eolMode);
- char *stringP = __stringVal(aCollection);
- len = __stringSize(aCollection);
-
- if (__INST(binary) != true
- && ((mode == @symbol(cr))
- || (mode == @symbol(etx))
- || (mode == @symbol(eot))
- || (mode == @symbol(crlf)))
- && memchr(stringP, '\n', len) != NULL)
- {
- // there is a '\n' to be translated, replace it into a buffer
-
- char *end;
- char sep[2];
- int sepLen = 1;
- int bufLen;
- char *buf, *endBuf, *sp, *dp;
-
- sep[0] = '\n';
- if (mode == @symbol(crlf)) {
- sep[0] = '\r'; sep[1] = '\n'; sepLen = 2;
- } else if (mode == @symbol(cr)) {
- sep[0] = '\r';
- } else if (mode == @symbol(eot)) {
- sep[0] = '\004';
- } else if (mode == @symbol(etx)) {
- sep[0] = '\003';
- }
-
- // estimate size of buffer - assume every 4th char is a separator
- bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen);
- buf = (char *)malloc(bufLen);
- if (buf == NULL) {
- error = __mkSmallInteger(ENOMEM);
- goto out;
- }
-
- endBuf = buf + bufLen;
- end = stringP + len;
- for (sp = stringP, dp = buf; sp < end; sp++) {
- char c;
-
- if ((dp+sepLen) >= endBuf) {
- char *newBuf;
-
- bufLen = bufLen * 2;
- newBuf = (char *)realloc(buf, bufLen);
- if (newBuf == NULL) {
- free(buf);
- error = __mkSmallInteger(ENOMEM);
- goto out;
- }
- endBuf = newBuf + bufLen;
- dp = newBuf + (dp-buf);
- buf = newBuf;
- }
-
- if ((c = *sp) != '\n') {
- *dp++ = c;
- } else {
- *dp++ = sep[0];
- if (sepLen == 2) {
- *dp++ = sep[1];
- };
- }
- }
-
- len = dp - buf;
+ OBJ fp;
+
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(readonly))
+ ) {
+ INT len, cnt;
+ INT o_offs;
+ FILEPOINTER f = __FILEVal(fp);
+ int _buffered = (__INST(buffered) == true);
+
+ if (! f) {
+ fprintf(stderr, "oops - fileHandle is NULL in nextPutAll:\n");
+ __INST(handle) = nil;
+ goto out;
+ }
+ if (_buffered) {
+ __WRITING__(f)
+ }
+
+ if (__isStringLike(aCollection)) {
+ OBJ mode = __INST(eolMode);
+ char *stringP = __stringVal(aCollection);
+ len = __stringSize(aCollection);
+
+ if (__INST(binary) != true
+ && ((mode == @symbol(cr))
+ || (mode == @symbol(etx))
+ || (mode == @symbol(eot))
+ || (mode == @symbol(crlf)))
+ && memchr(stringP, '\n', len) != NULL)
+ {
+ // there is a '\n' to be translated, replace it into a buffer
+
+ char *end;
+ char sep[2];
+ int sepLen = 1;
+ int bufLen;
+ char *buf, *endBuf, *sp, *dp;
+
+ sep[0] = '\n';
+ if (mode == @symbol(crlf)) {
+ sep[0] = '\r'; sep[1] = '\n'; sepLen = 2;
+ } else if (mode == @symbol(cr)) {
+ sep[0] = '\r';
+ } else if (mode == @symbol(eot)) {
+ sep[0] = '\004';
+ } else if (mode == @symbol(etx)) {
+ sep[0] = '\003';
+ }
+
+ // estimate size of buffer - assume every 4th char is a separator
+ bufLen = (sepLen == 1) ? len : (len + ((len/4) + 1) * sepLen);
+ buf = (char *)malloc(bufLen);
+ if (buf == NULL) {
+ error = __mkSmallInteger(ENOMEM);
+ goto out;
+ }
+
+ endBuf = buf + bufLen;
+ end = stringP + len;
+ for (sp = stringP, dp = buf; sp < end; sp++) {
+ char c;
+
+ if ((dp+sepLen) >= endBuf) {
+ char *newBuf;
+
+ bufLen = bufLen * 2;
+ newBuf = (char *)realloc(buf, bufLen);
+ if (newBuf == NULL) {
+ free(buf);
+ error = __mkSmallInteger(ENOMEM);
+ goto out;
+ }
+ endBuf = newBuf + bufLen;
+ dp = newBuf + (dp-buf);
+ buf = newBuf;
+ }
+
+ if ((c = *sp) != '\n') {
+ *dp++ = c;
+ } else {
+ *dp++ = sep[0];
+ if (sepLen == 2) {
+ *dp++ = sep[1];
+ };
+ }
+ }
+
+ len = dp - buf;
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(buf, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(buf, 1, len, f);
+ } else
# endif
- {
- __WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType));
- }
- free(buf);
- } else { // No EOL conversion needed
+ {
+ __WRITEBYTES__(cnt, f, buf, len, _buffered, __INST(handleType));
+ }
+ free(buf);
+ } else { // No EOL conversion needed
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(stringP, 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(stringP, 1, len, f);
+ } else
# endif
- {
- o_offs = stringP - (char *)__InstPtr(aCollection);
- __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
- }
- }
- } else { // Not a String
- if (__INST(binary) == true) {
- INT offs;
-
- if (__isByteArrayLike(aCollection)) {
- offs = 0;
- len = __byteArraySize(aCollection);
- } else if (__isBytes(aCollection)) {
- offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
- len = __byteArraySize(aCollection) - offs;
- } else
- goto out;
+ {
+ o_offs = stringP - (char *)__InstPtr(aCollection);
+ __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
+ }
+ }
+ } else { // Not a String
+ if (__INST(binary) == true) {
+ INT offs;
+
+ if (__isByteArrayLike(aCollection)) {
+ offs = 0;
+ len = __byteArraySize(aCollection);
+ } else if (__isBytes(aCollection)) {
+ offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
+ len = __byteArraySize(aCollection) - offs;
+ } else
+ goto out;
# ifdef __win32__
- if ((f == __win32_stdout()) || (f == __win32_stderr())) {
- cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f);
- } else
+ if ((f == __win32_stdout()) || (f == __win32_stderr())) {
+ cnt = __win32_fwrite(__stringVal(aCollection), 1, len, f);
+ } else
# endif
- {
- o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection);
- o_offs += offs;
- __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
- }
- } else // Not binary mode
- goto out;
- }
-
- // Now check for errors
- if (cnt == len) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + len;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- RETURN (self);
- }
+ {
+ o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection);
+ o_offs += offs;
+ __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered, __INST(handleType));
+ }
+ } else // Not binary mode
+ goto out;
+ }
+
+ // Now check for errors
+ if (cnt == len) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + len;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ RETURN (self);
+ }
# ifdef __win32__
- __threadErrno = __WIN32_ERR(GetLastError());
+ __threadErrno = __WIN32_ERR(GetLastError());
# endif
- error = __mkSmallInteger(__threadErrno);
- fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len);
- }
+ error = __mkSmallInteger(__threadErrno);
+ fprintf(stderr, "cnt=%"_ld_" len=%"_ld_"\n", (INT)cnt, (INT)len);
+ }
}
out: ;
#endif /* not SCHTEAM */
%}.
error notNil ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].