1 |
greg |
3.1 |
#ifndef lint |
2 |
greg |
3.4 |
static const char RCSid[] = "$Id: fputword.c,v 3.3 2003/03/27 04:16:33 greg Exp $"; |
3 |
greg |
3.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Read white space separated words from stream |
6 |
|
|
* |
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 |
greg |
3.4 |
#include "rtio.h" |
13 |
greg |
3.1 |
|
14 |
|
|
#include <ctype.h> |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
void |
18 |
|
|
fputword(s, fp) /* put (quoted) word to file stream */ |
19 |
|
|
char *s; |
20 |
|
|
FILE *fp; |
21 |
|
|
{ |
22 |
greg |
3.3 |
int hasspace = 0; |
23 |
|
|
int quote = 0; |
24 |
greg |
3.1 |
register char *cp; |
25 |
|
|
/* check if quoting needed */ |
26 |
|
|
for (cp = s; *cp; cp++) |
27 |
greg |
3.3 |
if (isspace(*cp)) |
28 |
|
|
hasspace++; |
29 |
|
|
else if (*cp == '"') |
30 |
|
|
quote = '\''; |
31 |
|
|
else if (*cp == '\'') |
32 |
|
|
quote = '"'; |
33 |
|
|
|
34 |
|
|
if (hasspace || quote) { /* output with quotes */ |
35 |
|
|
if (!quote) quote = '"'; |
36 |
|
|
fputc(quote, fp); |
37 |
|
|
fputs(s, fp); |
38 |
|
|
fputc(quote, fp); |
39 |
|
|
} else /* output sans quotes */ |
40 |
|
|
fputs(s, fp); |
41 |
greg |
3.1 |
} |