home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / pbm / libpbm4.c < prev    next >
C/C++ Source or Header  |  1993-10-04  |  2KB  |  81 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.     while ( ch != '\n' && ch != '\r' );
  38.     }
  39.  
  40.     return ch;
  41.     }
  42.  
  43. unsigned char
  44. pbm_getrawbyte( file )
  45.     FILE* file;
  46.     {
  47.     register int iby;
  48.  
  49.     iby = getc( file );
  50.     if ( iby == EOF )
  51.     pm_error( "EOF / read error" );
  52.     return (unsigned char) iby;
  53.     }
  54.  
  55. int
  56. pbm_getint( file )
  57.     FILE* file;
  58.     {
  59.     register char ch;
  60.     register int i;
  61.  
  62.     do
  63.     {
  64.     ch = pbm_getc( file );
  65.     }
  66.     while ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
  67.  
  68.     if ( ch < '0' || ch > '9' )
  69.     pm_error( "junk in file where an integer should be" );
  70.  
  71.     i = 0;
  72.     do
  73.     {
  74.     i = i * 10 + ch - '0';
  75.     ch = pbm_getc( file );
  76.         }
  77.     while ( ch >= '0' && ch <= '9' );
  78.  
  79.     return i;
  80.     }
  81.