ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/common/fputword.c
Revision: 3.12
Committed: Wed Dec 17 20:06:05 2025 UTC (2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 3.11: +6 -7 lines
Log Message:
refactor: ANSIfication

File Contents

# User Rev Content
1 greg 3.1 #ifndef lint
2 greg 3.12 static const char RCSid[] = "$Id: fputword.c,v 3.11 2024/08/03 15:32:59 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 greg 3.12 /* put (quoted) word to file stream */
17 greg 3.1 void
18 greg 3.12 fputword(char *s, FILE *fp)
19 greg 3.1 {
20 greg 3.12 int hasspace = 0;
21     int quote = 0;
22     char *cp;
23 greg 3.1 /* check if quoting needed */
24     for (cp = s; *cp; cp++)
25 greg 3.3 if (isspace(*cp))
26     hasspace++;
27 greg 3.10 else if ((cp > s) & (*cp == '"') && cp[1])
28 greg 3.3 quote = '\'';
29 greg 3.10 else if ((cp > s) & (*cp == '\'') && cp[1])
30 greg 3.3 quote = '"';
31    
32 greg 3.11 if (!*s | hasspace | quote) { /* output with quotes */
33 greg 3.3 if (!quote) quote = '"';
34     fputc(quote, fp);
35     fputs(s, fp);
36     fputc(quote, fp);
37     } else /* output sans quotes */
38     fputs(s, fp);
39 greg 3.1 }