diff options
author | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-02-25 19:22:25 +0000 |
commit | ad547a6b5986815fda458221149728d9d9ab1d87 (patch) | |
tree | 16296910eb3eca724371474ea9aea3994dc69614 /Build/source/texk/web2c/lib/eofeoln.c | |
parent | 947b43de3dd21d58ccc2ffadefc4441ea1c2a813 (diff) |
restore Build,TODO from r57911
git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/lib/eofeoln.c')
-rw-r--r-- | Build/source/texk/web2c/lib/eofeoln.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/lib/eofeoln.c b/Build/source/texk/web2c/lib/eofeoln.c new file mode 100644 index 00000000000..1930df9051a --- /dev/null +++ b/Build/source/texk/web2c/lib/eofeoln.c @@ -0,0 +1,65 @@ +/* eofeoln.c: implement Pascal's ideas for end-of-file and end-of-line + testing. Public domain. */ + +#include <w2c/config.h> +#include "lib.h" + +/* Return true if we're at the end of FILE, else false. This implements + Pascal's `eof' builtin. */ + +boolean +eof (FILE *file) +{ + register int c; + + /* If FILE doesn't exist, return true. This happens, for example, + when a user does `mft foo.mf' -- there's no change file, + so we never open it, so we end up calling this with a null pointer. */ + if (!file) + return true; + + /* Maybe we're already at the end? */ + if (feof (file)) + return true; + + if ((c = getc (file)) == EOF) + return true; + + /* We weren't at the end. Back up. */ + (void) ungetc (c, file); + + return false; +} + + +/* Return true on end-of-line in FILE or at the end of FILE, else false. */ +/* Accept both CR and LF as end-of-line. */ + +boolean +eoln (FILE *file) +{ + register int c; + + if (feof (file)) + return true; + + c = getc (file); + + if (c != EOF) + (void) ungetc (c, file); + + return c == '\n' || c == '\r' || c == EOF; +} + +/* Consume input up and including the first eol encountered. */ +/* Handle CRLF as a single end-of-line. */ + +void +readln (FILE *f) +{ + int c; + while ((c = getc (f)) != '\n' && c != '\r' && c != EOF) + ; + if (c == '\r' && (c = getc (f)) != '\n' && c != EOF) + ungetc (c, f); +} |