home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / sun / lib2 / libpbm4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-01  |  1.4 KB  |  66 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. % Modified by    Jin, Guojun - LBL    10/01/91
  13. */
  14.  
  15. #include "pbm.h"
  16. #include "libpbm.h"
  17.  
  18. char
  19. pbm_getc(file)
  20. FILE*    file;
  21. {
  22. register int    ich = getc( file );
  23.     if (ich == EOF)
  24.         return    prgmerr(DEBUGANY, "EOF - pbm_getc");
  25.  
  26.     if (ich == '#')    {
  27.         do {
  28.         ich = getc( file );
  29.         if (ich == EOF)
  30.             return    prgmerr(DEBUGANY, "EOF - pbm_getc#");
  31.         }    while (ich != '\n');
  32.     }
  33.  
  34. return    (char)ich;
  35. }
  36.  
  37. unsigned char
  38. pbm_getrawbyte( file )
  39. FILE* file;
  40. {
  41. register int    iby = getc( file );
  42.     if (iby == EOF)
  43.         return    prgmerr(DEBUGANY, "EOF - pbm_getrawbyte");
  44. return    (unsigned char) iby;
  45. }
  46.  
  47. pbm_getint(file)
  48. FILE* file;
  49. {
  50. register char    ch;
  51. register int    i=0;
  52.  
  53.     do    ch = pbm_getc(file);    while (ch == ' ' || ch == '\t' || ch == '\n');
  54.  
  55.     if (ch < '0' || ch > '9')
  56.     return    prgmerr(DEBUGANY, "junk in file where an integer should be");
  57.  
  58.     do    {
  59.     i = i * 10 + ch - '0';
  60.     ch = pbm_getc(file);
  61.         }
  62.     while (ch >= '0' && ch <= '9');
  63.  
  64. return    i;
  65. }
  66.