2 |
|
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
< |
* Read white space separated words from stream |
5 |
> |
* Write word to stream, quoting as necessary |
6 |
|
* |
7 |
< |
* External symbols declared in standard.h |
7 |
> |
* External symbols declared in rtio.h |
8 |
|
*/ |
9 |
|
|
10 |
|
#include "copyright.h" |
11 |
|
|
12 |
– |
#include <stdio.h> |
13 |
– |
|
12 |
|
#include <ctype.h> |
13 |
|
|
14 |
+ |
#include "rtio.h" |
15 |
|
|
16 |
|
void |
17 |
|
fputword(s, fp) /* put (quoted) word to file stream */ |
18 |
|
char *s; |
19 |
|
FILE *fp; |
20 |
|
{ |
21 |
+ |
int hasspace = 0; |
22 |
+ |
int quote = 0; |
23 |
|
register char *cp; |
24 |
|
/* check if quoting needed */ |
25 |
|
for (cp = s; *cp; cp++) |
26 |
< |
if (isspace(*cp)) { |
27 |
< |
int quote; |
28 |
< |
if (index(s, '"')) |
29 |
< |
quote = '\''; |
30 |
< |
else |
31 |
< |
quote = '"'; |
32 |
< |
fputc(quote, fp); |
33 |
< |
fputs(s, fp); |
34 |
< |
fputc(quote, fp); |
35 |
< |
return; |
36 |
< |
} |
37 |
< |
/* output sans quotes */ |
38 |
< |
fputs(s, fp); |
26 |
> |
if (isspace(*cp)) |
27 |
> |
hasspace++; |
28 |
> |
else if ((cp > s) & (*cp == '"') && cp[1]) |
29 |
> |
quote = '\''; |
30 |
> |
else if ((cp > s) & (*cp == '\'') && cp[1]) |
31 |
> |
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 |
|
} |