home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / unixtex-6.1b-src.lha / unixtex-6.1b / web2c / lib / eofeoln.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-12  |  765 b   |  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.