1 /* eofeoln.c: implement Pascal's ideas for end-of-file and end-of-line
2 testing. Public domain. */
4 #include <w2c/config.h>
7 /* Return true if we're at the end of FILE, else false. This implements
8 Pascal's `eof' builtin. */
15 /* If FILE doesn't exist, return true. This happens, for example,
16 when a user does `mft foo.mf' -- there's no change file,
17 so we never open it, so we end up calling this with a null pointer. */
21 /* Maybe we're already at the end? */
25 if ((c
= getc (file
)) == EOF
)
28 /* We weren't at the end. Back up. */
29 (void) ungetc (c
, file
);
35 /* Return true on end-of-line in FILE or at the end of FILE, else false. */
36 /* Accept both CR and LF as end-of-line. */
49 (void) ungetc (c
, file
);
51 return c
== '\n' || c
== '\r' || c
== EOF
;
54 /* Consume input up and including the first eol encountered. */
55 /* Handle CRLF as a single end-of-line. */
61 while ((c
= getc (f
)) != '\n' && c
!= '\r' && c
!= EOF
)
63 if (c
== '\r' && (c
= getc (f
)) != '\n' && c
!= EOF
)