--- a/ExternalStream.st Mon Aug 26 10:03:48 2019 +0200
+++ b/ExternalStream.st Mon Aug 26 10:06:33 2019 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1988 by Claus Gittinger
All Rights Reserved
@@ -4901,7 +4899,7 @@
"
(FileStream newTemporary
nextPutUtf16:$B;
- nextPutUtf16:$Ä;
+ nextPutUtf16:$Ä;
nextPutUtf16:(Character codePoint:16r10CCCC);
reset;
binary;
@@ -6322,7 +6320,7 @@
!
nextPut:aCharacter
- "write the argument, aCharacter - return nil if failed, self if ok.
+ "write the argument, aCharacter - raise an error if failed.
Only single-byte characters are currently supported"
|error|
@@ -6332,9 +6330,9 @@
if ((handle != STObject.Nil)
&& (aCharacter.isSTCharacter())) {
- handle.writeChar( aCharacter );
- self.instVarAt_put(I_position, STObject.Nil);
- return __c__._RETURN_self();
+ handle.writeChar( aCharacter );
+ self.instVarAt_put(I_position, STObject.Nil);
+ return __c__._RETURN_self();
}
#else
__INST(lastErrorNumber) = nil;
@@ -6343,112 +6341,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 ( self );
- }
+ {
+ __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 ( self );
+ }
# 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.
- ^ self
+ lastErrorNumber := error.
+ self writeError:error.
+ ^ self
].
handle isNil ifTrue:[self errorNotOpen. ^ self].
(mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
binary == true ifTrue:[
- aCharacter isInteger ifFalse:[
- self argumentMustBeInteger.
- ^ self.
- ].
+ aCharacter isInteger ifFalse:[
+ self argumentMustBeInteger.
+ ^ self.
+ ].
] ifFalse:[
- (aCharacter isCharacter not
- or:[aCharacter codePoint > 16rFF]) ifTrue:[
- self argumentMustBeCharacter.
- ^ self.
- ].
+ (aCharacter isCharacter not
+ or:[aCharacter codePoint > 16rFF]) ifTrue:[
+ self argumentMustBeCharacter.
+ ^ self.
+ ].
].
"/ migration support
self
- nextPutByte:aCharacter asInteger
- toFile:handle
+ nextPutByte:aCharacter asInteger
+ toFile:handle
"Modified: / 22-11-2018 / 14:47:13 / Stefan Vogel"
!
@@ -6465,9 +6463,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
@@ -6478,172 +6476,172 @@
|| (__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].
- ^ super nextPutAll:aCollection
+ super nextPutAll:aCollection
"Modified: / 22-11-2018 / 11:16:12 / Stefan Vogel"
!
@@ -6865,7 +6863,7 @@
].
"
- 'Bönnigheim' asUnicode16String errorPrintCR
+ 'Bönnigheim' asUnicode16String errorPrintCR
"
!