home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / netpbm_src.lzh / NETPBM / PBM / libpbm4.c < prev    next >
Text File  |  1996-11-24  |  2KB  |  85 lines

  1. /* libpbm4.c - pbm utility library part 4
  2. **
  3. ** Copyright (C) 1988 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include "pbm.h"
  14. #include "libpbm.h"
  15.  
  16. char
  17. pbm_getc( file )
  18.     FILE* file;
  19.     {
  20.     register int ich;
  21.     register char ch;
  22.  
  23.     ich = getc( file );
  24.     if ( ich == EOF )
  25.     pm_error( "EOF / read error" );
  26.     ch = (char) ich;
  27.     
  28.     if ( ch == '#' )
  29.     {
  30.     do
  31.         {
  32.         ich = getc( file );
  33.         if ( ich == EOF )
  34.         pm_error( "EOF / read error" );
  35.         ch = (char) ich;
  36.         }
  37. #ifndef _OSK
  38.     while ( ch != '\n' && ch != '\r' );
  39. #else
  40.     while ( ch != '\n' && ch != '\l' );
  41. #endif
  42.     }
  43.  
  44.     return ch;
  45.     }
  46.  
  47. unsigned char
  48. pbm_getrawbyte( file )
  49.     FILE* file;
  50.     {
  51.     register int iby;
  52.  
  53.     iby = getc( file );
  54.     if ( iby == EOF )
  55.     pm_error( "EOF / read error" );
  56.     return (unsigned char) iby;
  57.     }
  58.  
  59. int
  60. pbm_getint( file )
  61.     FILE* file;
  62.     {
  63.     register char ch;
  64.     register int i;
  65.  
  66.     do
  67.     {
  68.     ch = pbm_getc( file );
  69.     }
  70.     while ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
  71.  
  72.     if ( ch < '0' || ch > '9' )
  73.     pm_error( "junk in file where an integer should be" );
  74.  
  75.     i = 0;
  76.     do
  77.     {
  78.     i = i * 10 + ch - '0';
  79.     ch = pbm_getc( file );
  80.         }
  81.     while ( ch >= '0' && ch <= '9' );
  82.  
  83.     return i;
  84.     }
  85.