ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fputword.c
Revision: 3.10
Committed: Fri Nov 13 01:06:14 2020 UTC (3 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, HEAD
Changes since 3.9: +3 -3 lines
Log Message:
fix: avoid quoting words that are already in quotes

File Contents

# User Rev Content
1 greg 3.1 #ifndef lint
2 greg 3.10 static const char RCSid[] = "$Id: fputword.c,v 3.9 2011/06/22 16:55:35 greg Exp $";
3 greg 3.1 #endif
4     /*
5 greg 3.9 * Write word to stream, quoting as necessary
6 greg 3.1 *
7 greg 3.4 * External symbols declared in rtio.h
8 greg 3.1 */
9    
10 greg 3.2 #include "copyright.h"
11 greg 3.1
12     #include <ctype.h>
13    
14 schorsch 3.7 #include "rtio.h"
15 greg 3.1
16     void
17     fputword(s, fp) /* put (quoted) word to file stream */
18     char *s;
19     FILE *fp;
20     {
21 greg 3.3 int hasspace = 0;
22     int quote = 0;
23 greg 3.1 register char *cp;
24     /* check if quoting needed */
25     for (cp = s; *cp; cp++)
26 greg 3.3 if (isspace(*cp))
27     hasspace++;
28 greg 3.10 else if ((cp > s) & (*cp == '"') && cp[1])
29 greg 3.3 quote = '\'';
30 greg 3.10 else if ((cp > s) & (*cp == '\'') && cp[1])
31 greg 3.3 quote = '"';
32    
33     if (hasspace || quote) { /* output with quotes */
34     if (!quote) quote = '"';
35     fputc(quote, fp);
36     fputs(s, fp);
37     fputc(quote, fp);
38     } else /* output sans quotes */
39     fputs(s, fp);
40 greg 3.1 }