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

Comparing ray/src/common/fgetline.c (file contents):
Revision 1.1 by greg, Wed Oct 4 15:48:15 1989 UTC vs.
Revision 1.2 by greg, Wed Oct 4 16:36:55 1989 UTC

# Line 5 | Line 5 | static char SCCSid[] = "$SunId$ LBL";
5   #endif
6  
7   /*
8 < * fgetline.c - read line with escaped newlines
8 > * fgetline.c - read line with escaped newlines.
9   *
10   *      10/4/89
11   */
# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16   char *
17   fgetline(s, n, fp)      /* read in line with escapes, elide final newline */
18   char  *s;
19 < register int  n;
20 < FILE  *fp;
19 > int  n;
20 > register FILE  *fp;
21   {
22 <        register char  *cp;
23 <        register int  c;
22 >        int  escape = 0;
23 >        register char  *cp = s;
24 >        register int  c = EOF;
25  
26 <        cp = s;
27 <        while (--n > 0 && (c = getc(fp)) != EOF && c != '\n') {
28 <                if (c == '\\') {
28 <                        if ((c = getc(fp)) == EOF)
29 <                                break;
30 <                }
26 >        while (--n > 0 && (c = getc(fp)) != EOF) {
27 >                if (c == '\n' && (cp == s || cp[-1] != '\\'))
28 >                        break;
29                  *cp++ = c;
30          }
31 <        if (cp == s)
31 >        if (cp == s && c == EOF)
32                  return(NULL);
33 <        *cp++ = '\0';
33 >        *cp = '\0';
34          return(s);
35   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines