File: eofeoln.c

package info (click to toggle)
texlive-bin 2007.dfsg.2-4%2Blenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 245,472 kB
  • ctags: 135,653
  • sloc: ansic: 971,350; cpp: 307,149; sh: 53,218; perl: 39,201; makefile: 12,611; python: 6,078; xml: 5,342; asm: 4,245; yacc: 3,108; pascal: 2,483; ruby: 2,089; ada: 1,681; lex: 1,654; objc: 1,357; awk: 1,214; tcl: 973; cs: 879; lisp: 708; sed: 536; java: 172; csh: 47
file content (65 lines) | stat: -rw-r--r-- 1,377 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eofeoln.c: implement Pascal's ideas for end-of-file and end-of-line
   testing.  Public domain. */

#include "config.h"


/* Return true if we're at the end of FILE, else false.  This implements
   Pascal's `eof' builtin.  */

boolean
eof P1C(FILE *, file)
{
  register int c;

  /* If FILE doesn't exist, return false. This happens when, 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 P1C(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 P1C(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);
}