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.2 by greg, Mon Jul 22 14:33:06 1991 UTC vs.
Revision 2.4 by greg, Fri Jun 27 06:53:21 2003 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 */
18 > fgetword(s, n, fp)              /* get (quoted) word up to n-1 characters */
19   char  *s;
20   int  n;
21   register FILE  *fp;
22   {
23 +        int  quote = '\0';
24          register char  *cp;
25          register int  c;
26                                          /* skip initial white space */
27          do
28                  c = getc(fp);
29          while (isspace(c));
30 +                                        /* check for quote */
31 +        if ((c == '"' | c == '\'')) {
32 +                quote = c;
33 +                c = getc(fp);
34 +        }
35                                          /* check for end of file */
36          if (c == EOF)
37                  return(NULL);
38                                          /* get actual word */
39          cp = s;
40          do {
41 <                if (--n <= 0)                   /* check length limit */
41 >                if (--n <= 0)           /* check length limit */
42                          break;
43                  *cp++ = c;
44                  c = getc(fp);
45 <        } while (c != EOF && !isspace(c));
45 >        } while (c != EOF && !(quote ? c==quote : isspace(c)));
46          *cp = '\0';
47 <        if (c != EOF)                   /* replace delimiter */
47 >        if ((c != EOF & !quote))        /* replace space */
48                  ungetc(c, fp);
49          return(s);
50   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines