--- ray/src/common/fputword.c 2003/07/17 09:21:29 3.7 +++ ray/src/common/fputword.c 2024/08/03 15:32:59 3.11 @@ -1,8 +1,8 @@ #ifndef lint -static const char RCSid[] = "$Id: fputword.c,v 3.7 2003/07/17 09:21:29 schorsch Exp $"; +static const char RCSid[] = "$Id: fputword.c,v 3.11 2024/08/03 15:32:59 greg Exp $"; #endif /* - * Read white space separated words from stream + * Write word to stream, quoting as necessary * * External symbols declared in rtio.h */ @@ -10,7 +10,6 @@ static const char RCSid[] = "$Id: fputword.c,v 3.7 200 #include "copyright.h" #include -#include #include "rtio.h" @@ -26,12 +25,12 @@ FILE *fp; for (cp = s; *cp; cp++) if (isspace(*cp)) hasspace++; - else if (*cp == '"') + else if ((cp > s) & (*cp == '"') && cp[1]) quote = '\''; - else if (*cp == '\'') + else if ((cp > s) & (*cp == '\'') && cp[1]) quote = '"'; - if (hasspace || quote) { /* output with quotes */ + if (!*s | hasspace | quote) { /* output with quotes */ if (!quote) quote = '"'; fputc(quote, fp); fputs(s, fp);