diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/luatex.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/luatex.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luatex.c b/Build/source/texk/web2c/luatexdir/luatex.c index 2c893cd2bbe..c6ddb639192 100644 --- a/Build/source/texk/web2c/luatexdir/luatex.c +++ b/Build/source/texk/web2c/luatexdir/luatex.c @@ -615,10 +615,15 @@ void topenin(void) /* Find the end of the buffer. */ for (last = first; buffer[last]; ++last); - /* Make `last' be one past the last non-blank character in `buffer'. */ - /* ??? The test for '\r' should not be necessary. */ - for (--last; last >= first - && ISBLANK(buffer[last]) && buffer[last] != '\r'; --last); + /* Make `last' be one past the last non-space character in `buffer', + ignoring line terminators (but not, e.g., tabs). This is because + we are supposed to treat this like a line of TeX input. Although + there are pathological cases (SPC CR SPC CR) where this differs + from input_line below, and from previous behavior of removing all + whitespace, the simplicity of removing all trailing line terminators + seems more in keeping with actual command line processing. */ +#define IS_SPC_OR_EOL(c) ((c) == ' ' || (c) == '\r' || (c) == '\n') + for (--last; last >= first && IS_SPC_OR_EOL (buffer[last]); --last) last++; /* One more time, this time converting to TeX's internal character @@ -1060,9 +1065,10 @@ boolean input_line(FILE * f) ; else { int k3 = getc (f); - - if (k1 == 0xef && k2 == 0xbb && k3 == 0xbf) /* UTF-8 */ - ; + int k4 = getc (f); + if (k1 == 0xef && k2 == 0xbb && k3 == 0xbf && + k4 >= 0 && k4 <= 0x7e) /* UTF-8 */ + ungetc (k4, f); else rewind (f); } @@ -1097,8 +1103,13 @@ boolean input_line(FILE * f) ungetc(i, f); } - /* Trim trailing whitespace. */ - while (last > first && ISBLANK(buffer[last - 1])) + /* Trim trailing space character (but not, e.g., tabs). We can't have + line terminators because we stopped reading at the first \r or \n. + TeX's rule is to strip only trailing spaces (and eols). David + Fuchs mentions that this stripping was done to ensure portability + of TeX documents given the padding with spaces on fixed-record + "lines" on some systems of the time, e.g., IBM VM/CMS and OS/360. */ + while (last > first && buffer[last - 1] == ' ') --last; /* Don't bother using xord if we don't need to. */ |