--- a/ExternalStream.st Sat Feb 07 13:28:17 2015 +0100
+++ b/ExternalStream.st Sat Feb 07 13:32:22 2015 +0100
@@ -2036,10 +2036,12 @@
eolMode
"return how end-of-line (EOL) is to be marked.
Returns one one of:
- #crlf -> add a CR-NL, as in MSDOS
- #cr -> add a CR, as in VMS
- #nl -> add a NL, as in Unix
- nil -> transparent
+ #crlf -> use CR-NL, as in MSDOS
+ #cr -> use CR, as in VMS or pre OSX mac
+ #nl -> use NL, as in Unix
+ #eot -> use EOT (as in some old modem protocols or mainframe files)
+ #etx -> use ETX (as in some old modem protocols or mainframe files)
+ anyOther -> like #nl
"
^ eolMode
@@ -2048,10 +2050,12 @@
eolMode:aSymbolOrNil
"specify how end-of-line (EOL) is to be marked.
The argument may be one of:
- #crlf -> add a CR-NL, as in MSDOS
- #cr -> add a CR, as in VMS
- #nl -> add a NL, as in Unix
- anyOther -> like #nl
+ #crlf -> use CR-NL, as in MSDOS
+ #cr -> use CR, as in VMS or pre OSX mac
+ #nl -> use NL, as in Unix
+ #eot -> use EOT (as in some old modem protocols or mainframe files)
+ #etx -> use ETX (as in some old modem protocols or mainframe files)
+ anyOther -> like #nl
"
eolMode := aSymbolOrNil
@@ -2724,6 +2728,10 @@
cp = "\r"; len = 1;
} else if (mode == @symbol(crlf)) {
cp = "\r\n"; len = 2;
+ } else if (mode == @symbol(eot)) {
+ cp = "\004"; len = 1;
+ } else if (mode == @symbol(etx)) {
+ cp = "\003"; len = 1;
} else {
cp = "\n"; len = 1;
}
@@ -5709,6 +5717,10 @@
cp = "\r"; len = 1;
} else if (mode == @symbol(crlf)) {
cp = "\r\n"; len = 2;
+ } else if (mode == @symbol(eot)) {
+ cp = "\004"; len = 1;
+ } else if (mode == @symbol(etx)) {
+ cp = "\003"; len = 1;
} else {
cp = "\n"; len = 1;
}
@@ -5822,10 +5834,18 @@
buff[0] = c; nBytes = 1;
if (c == '\n') {
- if (__INST(eolMode) == @symbol(nl)) {
- } else if (__INST(eolMode) == @symbol(cr)) {
+ 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 (__INST(eolMode) == @symbol(crlf)) {
+ } 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;
@@ -5934,26 +5954,40 @@
}
if (__isStringLike(aCollection)) {
+ OBJ mode = __INST(eolMode);
char *stringP = __stringVal(aCollection);
len = __stringSize(aCollection);
if (__INST(binary) != true
- && ((__INST(eolMode) == @symbol(cr))
- || (__INST(eolMode) == @symbol(crnl)))
+ && ((mode == @symbol(cr))
+ || (mode == @symbol(etx))
+ || (mode == @symbol(eot))
+ || (mode == @symbol(crnl)))
&& memchr(stringP, '\n', len) != NULL)
{
- // see if there is a \n which needs to be translated, replace it
+ // there is a '\n' to be translated, replace it into a buffer
char *end = stringP + len;
- char *sep = __INST(eolMode) == @symbol(crlf) ? "\r\n" : "\r";
- int sepLen = strlen(sep);
+ 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 == 0) {
+ if (buf == NULL) {
error = __mkSmallInteger(ENOMEM);
goto out;
}
@@ -5964,9 +5998,9 @@
if (dp >= endBuf) {
char *newBuf;
- bufLen = bufLen + ((bufLen/4) + 1) * sepLen;
+ bufLen = bufLen * 2;
newBuf = (char *)realloc(buf, bufLen);
- if (newBuf == 0) {
+ if (newBuf == NULL) {
free(buf);
error = __mkSmallInteger(ENOMEM);
goto out;
@@ -6094,6 +6128,7 @@
}
if (__isStringLike(aCollection)) {
char *stringP;
+ OBJ mode = __INST(eolMode);
len = __stringSize(aCollection);
if (iStop > len) {
@@ -6105,22 +6140,35 @@
stringP = __stringVal(aCollection) + iStart - 1;
if (__INST(binary) != true
- && ((__INST(eolMode) == @symbol(cr))
- || (__INST(eolMode) != @symbol(crnl)))
+ && ((mode == @symbol(cr))
+ || (mode == @symbol(etx))
+ || (mode == @symbol(eot))
+ || (mode == @symbol(crnl)))
&& memchr(stringP, '\n', len) != NULL)
{
// see if there is a \n which needs to be translated, replace it
char *end = stringP + len;
- char *sep = __INST(eolMode) == @symbol(crlf) ? "\r\n" : "\r";
- int sepLen = strlen(sep);
+ 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 == 0) {
+ if (buf == NULL) {
error = __mkSmallInteger(ENOMEM);
goto out;
}
@@ -6131,9 +6179,9 @@
if (dp >= endBuf) {
char *newBuf;
- bufLen = bufLen + ((bufLen/4) + 1) * sepLen;
+ bufLen = bufLen * 2;
newBuf = (char *)realloc(buf, bufLen);
- if (newBuf == 0) {
+ if (newBuf == NULL) {
free(buf);
error = __mkSmallInteger(ENOMEM);
goto out;
@@ -6375,11 +6423,11 @@
!ExternalStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.403 2015-02-06 23:09:13 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.404 2015-02-07 12:32:22 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.403 2015-02-06 23:09:13 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.404 2015-02-07 12:32:22 cg Exp $'
! !