home *** CD-ROM | disk | FTP | other *** search
/ gdead.berkeley.edu / gdead.berkeley.edu.tar / gdead.berkeley.edu / pub / cad-tools / ciftomann.tar / pggen_dir / getbox.c < prev    next >
C/C++ Source or Header  |  1988-01-28  |  1KB  |  98 lines

  1. #include <ctype.h>
  2.  
  3. #define flush_space(file,ch)\
  4.     while (isspace(ch = getc(file)));
  5.  
  6. #define flush_blanks(file,ch)\
  7.     while (ch = getc(file), (ch == ' ') || (ch == '\t'));
  8.  
  9. /*
  10.  * read from 4 - 6 blank or tab seperated integers from file
  11.  * The line must be terminated by a ';'
  12.  * Returns the number of integers read, or -1 in case of error.
  13.  */
  14.  
  15. get_box(file, a,b,c,d,e,f)
  16. FILE *file;
  17. int *a, *b, *c, *d;
  18. {
  19.     register int ch;
  20.  
  21.     if (get_int(file,a) != 0) {
  22.     return(-1);
  23.     }
  24.  
  25.     if (get_int(file,b) != 0) {
  26.     return(-1);
  27.     }
  28.  
  29.     if (get_int(file,c) != 0) {
  30.     return(-1);
  31.     }
  32.  
  33.     if (get_int(file,d) != 0) {
  34.     return(-1);
  35.     }
  36.  
  37.     if (get_int(file,e) != 0) {
  38.     flush_blanks(file,ch);
  39.     if (ch != ';') {
  40.         ungetc(c, file);
  41.         return(-1);
  42.     }
  43.     return(4);
  44.     }
  45.     
  46.     if (get_int(file,f) != 0) {
  47.     flush_blanks(file,ch);
  48.     if (ch != ';') {
  49.         ungetc(c, file);
  50.         return(-1);
  51.     }
  52.     return(5);
  53.     }
  54.     
  55.     flush_blanks(file,ch);
  56.     if (ch != ';') {
  57.     ungetc(c, file);
  58.     return(-1);
  59.     }
  60.  
  61.     return(6);
  62. }
  63.  
  64. get_int(file,ret)
  65. FILE *file;
  66. int *ret;
  67. {
  68.     register int c, val;
  69.     int negative;
  70.  
  71.     flush_blanks(file,c);
  72.  
  73.     if (c == '-') {
  74.     c = getc(file);
  75.     negative = 1;
  76.     } else {
  77.     negative = 0;
  78.     }
  79.  
  80.     if (!isdigit(c)) {
  81.     ungetc(c, file);
  82.     return(-1);
  83.     }
  84.  
  85.     val = 0;
  86.  
  87.     while(isdigit(c)) {
  88.     val = 10*val + (c - '0');
  89.     c = getc(file);
  90.     }
  91.  
  92.     ungetc(c, file);
  93.  
  94.     *ret = (negative ? -val : val);
  95.  
  96.     return(0);
  97. }
  98.