ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/common/fputword.c
(Generate patch)

Comparing ray/src/common/fputword.c (file contents):
Revision 3.2 by greg, Tue Feb 25 02:47:21 2003 UTC vs.
Revision 3.12 by greg, Wed Dec 17 20:06:05 2025 UTC

# Line 2 | Line 2
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 + /* put (quoted) word to file stream */
17   void
18 < fputword(s, fp)                 /* put (quoted) word to file stream */
19 < char  *s;
20 < FILE  *fp;
18 > fputword(char *s, FILE *fp)
19   {
20 <        register char   *cp;
20 >        int     hasspace = 0;
21 >        int     quote = 0;
22 >        char    *cp;
23                                          /* check if quoting needed */
24          for (cp = s; *cp; cp++)
25 <                if (isspace(*cp)) {
26 <                        int     quote;
27 <                        if (index(s, '"'))
28 <                                quote = '\'';
29 <                        else
30 <                                quote = '"';
31 <                        fputc(quote, fp);
32 <                        fputs(s, fp);
33 <                        fputc(quote, fp);
34 <                        return;
35 <                }
36 <                                        /* output sans quotes */
37 <        fputs(s, fp);
25 >                if (isspace(*cp))
26 >                        hasspace++;
27 >                else if ((cp > s) & (*cp == '"') && cp[1])
28 >                        quote = '\'';
29 >                else if ((cp > s) & (*cp == '\'') && cp[1])
30 >                        quote = '"';
31 >
32 >        if (!*s | hasspace | quote) {   /* output with quotes */
33 >                if (!quote) quote = '"';
34 >                fputc(quote, fp);
35 >                fputs(s, fp);
36 >                fputc(quote, fp);
37 >        } else                          /* output sans quotes */
38 >                fputs(s, fp);
39   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)