home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / tex / texsrc1 / Src / lib / c / eofeoln < prev    next >
Text File  |  1993-05-02  |  765b  |  48 lines

  1. /* eofeoln.c: implement Pascal's ideas for end-of-file and end-of-line
  2.    testing.  */
  3.  
  4. #include "config.h"
  5.  
  6.  
  7. /* Return true if we're at the end of FILE, else false.  This implements
  8.    Pascal's `eof' builtin.  */
  9.  
  10. boolean
  11. eof (file)
  12.   FILE *file;
  13. {
  14.   register int c;
  15.  
  16.   /* Maybe we're already at the end?  */
  17.   if (feof (file))
  18.     return true;
  19.  
  20.   if ((c = getc (file)) == EOF)
  21.     return true;
  22.  
  23.   /* We weren't at the end.  Back up.  */
  24.   (void) ungetc (c, file);
  25.  
  26.   return false;
  27. }
  28.  
  29.  
  30. /* Return true on end-of-line in FILE or at the end of FILE, else false.  */
  31.  
  32. boolean
  33. eoln (file)
  34.   FILE *file;
  35. {
  36.   register int c;
  37.  
  38.   if (feof (file))
  39.     return true;
  40.   
  41.   c = getc (file);
  42.   
  43.   if (c != EOF)
  44.     (void) ungetc (c, file);
  45.     
  46.   return c == '\n' || c == EOF;
  47. }
  48.