fix lines that terminate on EOF

This commit is contained in:
Vítor Santos Costa 2016-03-05 23:43:11 +00:00
parent 79d99a7768
commit bc914e9e91

View File

@ -62,12 +62,16 @@ static Int rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS) {
unsigned char *pt = buf; unsigned char *pt = buf;
do { do {
ch = st->stream_wgetc_for_read(sno); ch = st->stream_wgetc_for_read(sno);
if (ch < 127) if (ch < 127) {
*pt++ = ch; *pt++ = ch;
else if (ch < 0) {
pt += get_utf8(pt, 4, &ch); ch = '\n';
if (pt + 4 == buf + buf_sz) pt[-1] = '\n';
break; } else
pt += get_utf8(pt, 4, &ch);
if (pt + 4 == buf + buf_sz)
break;
}
} while (ch != '\n'); } while (ch != '\n');
sz = pt - buf; sz = pt - buf;
} }
@ -150,10 +154,15 @@ static Int read_line_to_string(USES_REGS1) {
unsigned char *pt = buf; unsigned char *pt = buf;
do { do {
ch = st->stream_wgetc_for_read(sno); ch = st->stream_wgetc_for_read(sno);
if (ch < 127) if (ch < 127) {
*pt++ = ch; if (ch < 0) {
else ch = '\n';
pt[-1] = '\n';
} else
*pt++ = ch;
} else {
pt += put_utf8(pt, ch); pt += put_utf8(pt, ch);
}
if (pt + 4 == buf + buf_sz) if (pt + 4 == buf + buf_sz)
break; break;
} while (ch != '\n'); } while (ch != '\n');