Back to index

radiance  4R0+20100331
fputword.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: fputword.c,v 3.8 2004/04/02 21:41:23 greg Exp $";
00003 #endif
00004 /*
00005  * Read white space separated words from stream
00006  *
00007  *  External symbols declared in rtio.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include <ctype.h>
00013 
00014 #include "rtio.h"
00015 
00016 void
00017 fputword(s, fp)                    /* put (quoted) word to file stream */
00018 char  *s;
00019 FILE  *fp;
00020 {
00021        int           hasspace = 0;
00022        int           quote = 0;
00023        register char *cp;
00024                                    /* check if quoting needed */
00025        for (cp = s; *cp; cp++)
00026               if (isspace(*cp))
00027                      hasspace++;
00028               else if (*cp == '"')
00029                      quote = '\'';
00030               else if (*cp == '\'')
00031                      quote = '"';
00032 
00033        if (hasspace || quote) {    /* output with quotes */
00034               if (!quote) quote = '"';
00035               fputc(quote, fp);
00036               fputs(s, fp);
00037               fputc(quote, fp);
00038        } else                      /* output sans quotes */
00039               fputs(s, fp);
00040 }