--- ray/src/common/fputword.c 2003/02/25 02:47:21 3.2 +++ ray/src/common/fputword.c 2003/03/27 04:16:33 3.3 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: fputword.c,v 3.2 2003/02/25 02:47:21 greg Exp $"; +static const char RCSid[] = "$Id: fputword.c,v 3.3 2003/03/27 04:16:33 greg Exp $"; #endif /* * Read white space separated words from stream @@ -19,20 +19,23 @@ fputword(s, fp) /* put (quoted) word to file stream char *s; FILE *fp; { + int hasspace = 0; + int quote = 0; register char *cp; /* check if quoting needed */ for (cp = s; *cp; cp++) - if (isspace(*cp)) { - int quote; - if (index(s, '"')) - quote = '\''; - else - quote = '"'; - fputc(quote, fp); - fputs(s, fp); - fputc(quote, fp); - return; - } - /* output sans quotes */ - fputs(s, fp); + if (isspace(*cp)) + hasspace++; + else if (*cp == '"') + quote = '\''; + else if (*cp == '\'') + quote = '"'; + + if (hasspace || quote) { /* output with quotes */ + if (!quote) quote = '"'; + fputc(quote, fp); + fputs(s, fp); + fputc(quote, fp); + } else /* output sans quotes */ + fputs(s, fp); }