Skip to content

Commit

Permalink
FIX: remove CRLF on Windows and LF on Posix platforms from tail of IN…
Browse files Browse the repository at this point in the history
…PUT line

INPUT function was using TRIM/with newline, but that was not enough on Windows as it was not removing the CR byte. Also it was quite overkill as there should not be any other newlines in the system/ports/input line.

Also with this change, the output on all platforms should be same in this situation:
```
>> read system/ports/input
foo
== #{666F6F}
```

Before this modification it would return `#{666F6F0D0A}` on Windows and `#{666F6F0A}` on Linux.
  • Loading branch information
Oldes committed Jan 9, 2019
1 parent 9d3d85b commit 5eb7fb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
34 changes: 5 additions & 29 deletions src/core/p-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,15 @@
req->data = BIN_HEAD(ser);
req->length = SERIES_AVAIL(ser);

#ifdef nono
// Is the buffer large enough?
req->length = SERIES_AVAIL(ser); // space available
if (req->length < OUT_BUF_SIZE/2) Extend_Series(ser, OUT_BUF_SIZE);
req->length = SERIES_AVAIL(ser);

// Don't make buffer too large: Bug #174 ?????
if (req->length > 1024) req->length = 1024; //???
req->data = STR_TAIL(ser); // write at tail //???
if (SERIES_TAIL(ser) == 0) req->actual = 0; //???
#endif

result = OS_DO_DEVICE(req, RDC_READ);
if (result < 0) Trap_Port(RE_READ_ERROR, port, req->error);

#ifdef nono
// Does not belong here!!
// Remove or replace CRs:
result = 0;
for (n = 0; n < req->actual; n++) {
chr = GET_ANY_CHAR(ser, n);
if (chr == CR) {
chr = LF;
// Skip LF if it follows:
if ((n+1) < req->actual &&
LF == GET_ANY_CHAR(ser, n+1)) n++;
}
SET_ANY_CHAR(ser, result, chr);
result++;
}
#ifdef TO_WINDOWS
if (req->actual > 1) req->actual -= 2; // remove CRLF from tail
#else
if (req->actual > 0) req->actual -= 1; // remove LF from tail
#endif
// Another copy???
//Set_String(ds, Copy_OS_Str((void *)(ser->data), result));

Set_Binary(ds, Copy_Bytes(req->data, req->actual));
break;

Expand Down
6 changes: 2 additions & 4 deletions src/mezz/mezz-files.r
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ clean-path: func [
]

input: function [
{Inputs a string from the console. New-line character is removed.}
{Inputs a string from the console.}
; /hide "Mask input with a * character"
][
if any [
Expand All @@ -72,9 +72,7 @@ input: function [
][
system/ports/input: open [scheme: 'console]
]
line: to-string read system/ports/input
trim/with line newline
line
to string! read system/ports/input
]

ask: func [
Expand Down

0 comments on commit 5eb7fb2

Please sign in to comment.