ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fgetword.c
(Generate patch)

Comparing ray/src/common/fgetword.c (file contents):
Revision 1.1 by greg, Mon Jul 22 13:55:12 1991 UTC vs.
Revision 2.7 by greg, Sun Apr 9 21:33:24 2017 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Read white space separated words from stream
6 + *
7 + *  External symbols declared in rtio.h
8   */
9  
10 < #include  <stdio.h>
10 > #include "copyright.h"
11  
12 + #include  "rtio.h"
13 +
14   #include  <ctype.h>
15  
16  
17   char *
18 < fgetword(s, n, fp)              /* get a word, maximum n-1 characters */
19 < char  *s;
20 < int  n;
21 < register FILE  *fp;
18 > fgetword(                       /* get (quoted) word up to n-1 characters */
19 >        char  *s,
20 >        int  n,
21 >        FILE  *fp
22 > )
23   {
24 <        register char  *cp;
25 <        register int  c;
24 >        int  quote = '\0';
25 >        char  *cp;
26 >        int  c;
27 >                                        /* sanity checks */
28 >        if ((s == NULL) | (n < 2))
29 >                return(NULL);
30                                          /* skip initial white space */
31          do
32                  c = getc(fp);
33          while (isspace(c));
34 <                                        /* check for end of file */
35 <        if (c == EOF)
36 <                return(NULL);
34 >                                        /* check for quote */
35 >        if ((c == '"') | (c == '\'')) {
36 >                quote = c;
37 >                c = getc(fp);
38 >        }
39                                          /* get actual word */
40          cp = s;
41 <        do {
42 <                if (--n <= 0)                   /* check length limit */
41 >        while (c != EOF && !(quote ? c==quote : isspace(c))) {
42 >                if (--n <= 0)           /* check length limit */
43                          break;
44                  *cp++ = c;
45                  c = getc(fp);
46 <        } while (c != EOF && !isspace(c));
46 >        }
47          *cp = '\0';
48 <        if (c != EOF)                   /* replace delimiter */
48 >        if ((c != EOF) & !quote)        /* replace space */
49                  ungetc(c, fp);
50          return(s);
43 }
44
45
46 isint(s)                        /* check integer format */
47 char  *s;
48 {
49        register char  *cp = s;
50
51        while (isspace(*cp))
52                cp++;
53        if (*cp == '-' || *cp == '+')
54                cp++;
55        do
56                if (!isdigit(*cp))
57                        return(0);
58        while (*++cp);
59        return(1);
60 }
61
62
63 isflt(s)                        /* check float format */
64 char  *s;
65 {
66        register char  *cp = s;
67
68        while (isspace(*cp))
69                cp++;
70        if (*cp == '-' || *cp == '+')
71                cp++;
72        s = cp;
73        while (isdigit(*cp))
74                cp++;
75        if (*cp == '.') {
76                cp++; s++;
77                while (isdigit(*cp))
78                        cp++;
79        }
80        if (cp == s)
81                return(0);
82        if (*cp == 'e' || *cp == 'E')
83                return(isint(cp+1));
84        return(1);
51   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines