ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fgetline.c
Revision: 1.2
Committed: Wed Oct 4 16:36:55 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +11 -13 lines
Log Message:
Left escape characters in line.

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1989 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8 greg 1.2 * fgetline.c - read line with escaped newlines.
9 greg 1.1 *
10     * 10/4/89
11     */
12    
13     #include <stdio.h>
14    
15    
16     char *
17     fgetline(s, n, fp) /* read in line with escapes, elide final newline */
18     char *s;
19 greg 1.2 int n;
20     register FILE *fp;
21 greg 1.1 {
22 greg 1.2 int escape = 0;
23     register char *cp = s;
24     register int c = EOF;
25 greg 1.1
26 greg 1.2 while (--n > 0 && (c = getc(fp)) != EOF) {
27     if (c == '\n' && (cp == s || cp[-1] != '\\'))
28     break;
29 greg 1.1 *cp++ = c;
30     }
31 greg 1.2 if (cp == s && c == EOF)
32 greg 1.1 return(NULL);
33 greg 1.2 *cp = '\0';
34 greg 1.1 return(s);
35     }