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 2.8 by greg, Thu Aug 10 19:10:44 2017 UTC vs.
Revision 2.9 by greg, Fri Feb 10 04:32:19 2023 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14   #include  <ctype.h>
15  
16  
17 + #define isquote(c)      (((c) == '"') | ((c) == '\''))
18 +
19 +
20   char *
21   fgetword(                       /* get (quoted) word up to n-1 characters */
22          char  *s,
# Line 32 | Line 35 | fgetword(                      /* get (quoted) word up to n-1 characters
35                  c = getc(fp);
36          while (isspace(c));
37                                          /* check for quote */
38 <        if ((c == '"') | (c == '\'')) {
38 >        if (isquote(c)) {
39                  quote = c;
40                  c = getc(fp);
41          }
42 <                                        /* get actual word */
43 <        cp = s;
44 <        while (c != EOF && !(quote ? c==quote : isspace(c))) {
45 <                if (--n <= 0)           /* check length limit */
46 <                        break;
47 <                *cp++ = c;
48 <                c = getc(fp);
42 >        cp = s;                         /* get actual word */
43 >        while (c != EOF) {
44 >                if (c == quote)         /* end quote? */
45 >                        quote = '\0';
46 >                else if (!quote && isquote(c))
47 >                        quote = c;      /* started new quote */
48 >                else {
49 >                        if (!quote && isspace(c))
50 >                                break;  /* end of word */
51 >                        if (--n <= 0)
52 >                                break;  /* hit length limit */
53 >                        *cp++ = c;
54 >                }
55 >                c = getc(fp);           /* get next character */
56          }
57          *cp = '\0';
58 <        if (c == EOF) {                 /* hit end-of-file? */
59 <                if (cp == s)            /* and got nothing? */
50 <                        return(NULL);
51 <        } else if (!quote)              /* replace white character */
52 <                ungetc(c, fp);
58 >        if ((c == EOF) & (cp == s))     /* hit end-of-file? */
59 >                return(NULL);
60          return(s);
61   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines