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 >
Wrap
C/C++ Source or Header
|
1988-01-28
|
1KB
|
98 lines
#include <ctype.h>
#define flush_space(file,ch)\
while (isspace(ch = getc(file)));
#define flush_blanks(file,ch)\
while (ch = getc(file), (ch == ' ') || (ch == '\t'));
/*
* read from 4 - 6 blank or tab seperated integers from file
* The line must be terminated by a ';'
* Returns the number of integers read, or -1 in case of error.
*/
get_box(file, a,b,c,d,e,f)
FILE *file;
int *a, *b, *c, *d;
{
register int ch;
if (get_int(file,a) != 0) {
return(-1);
}
if (get_int(file,b) != 0) {
return(-1);
}
if (get_int(file,c) != 0) {
return(-1);
}
if (get_int(file,d) != 0) {
return(-1);
}
if (get_int(file,e) != 0) {
flush_blanks(file,ch);
if (ch != ';') {
ungetc(c, file);
return(-1);
}
return(4);
}
if (get_int(file,f) != 0) {
flush_blanks(file,ch);
if (ch != ';') {
ungetc(c, file);
return(-1);
}
return(5);
}
flush_blanks(file,ch);
if (ch != ';') {
ungetc(c, file);
return(-1);
}
return(6);
}
get_int(file,ret)
FILE *file;
int *ret;
{
register int c, val;
int negative;
flush_blanks(file,c);
if (c == '-') {
c = getc(file);
negative = 1;
} else {
negative = 0;
}
if (!isdigit(c)) {
ungetc(c, file);
return(-1);
}
val = 0;
while(isdigit(c)) {
val = 10*val + (c - '0');
c = getc(file);
}
ungetc(c, file);
*ret = (negative ? -val : val);
return(0);
}