--- ray/src/common/fgetword.c 1991/07/22 13:55:12 1.1 +++ ray/src/common/fgetword.c 2003/06/27 06:53:21 2.4 @@ -1,85 +1,50 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: fgetword.c,v 2.4 2003/06/27 06:53:21 greg Exp $"; #endif - /* * Read white space separated words from stream + * + * External symbols declared in rtio.h */ -#include +#include "copyright.h" +#include "rtio.h" + #include char * -fgetword(s, n, fp) /* get a word, maximum n-1 characters */ +fgetword(s, n, fp) /* get (quoted) word up to n-1 characters */ char *s; int n; register FILE *fp; { + int quote = '\0'; register char *cp; register int c; /* skip initial white space */ do c = getc(fp); while (isspace(c)); + /* check for quote */ + if ((c == '"' | c == '\'')) { + quote = c; + c = getc(fp); + } /* check for end of file */ if (c == EOF) return(NULL); /* get actual word */ cp = s; do { - if (--n <= 0) /* check length limit */ + if (--n <= 0) /* check length limit */ break; *cp++ = c; c = getc(fp); - } while (c != EOF && !isspace(c)); + } while (c != EOF && !(quote ? c==quote : isspace(c))); *cp = '\0'; - if (c != EOF) /* replace delimiter */ + if ((c != EOF & !quote)) /* replace space */ ungetc(c, fp); return(s); -} - - -isint(s) /* check integer format */ -char *s; -{ - register char *cp = s; - - while (isspace(*cp)) - cp++; - if (*cp == '-' || *cp == '+') - cp++; - do - if (!isdigit(*cp)) - return(0); - while (*++cp); - return(1); -} - - -isflt(s) /* check float format */ -char *s; -{ - register char *cp = s; - - while (isspace(*cp)) - cp++; - if (*cp == '-' || *cp == '+') - cp++; - s = cp; - while (isdigit(*cp)) - cp++; - if (*cp == '.') { - cp++; s++; - while (isdigit(*cp)) - cp++; - } - if (cp == s) - return(0); - if (*cp == 'e' || *cp == 'E') - return(isint(cp+1)); - return(1); }