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

Comparing ray/src/common/header.c (file contents):
Revision 1.3 by greg, Fri Apr 19 10:33:25 1991 UTC vs.
Revision 2.4 by greg, Sun Feb 27 10:16:45 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1988 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   *
10   *      8/19/88
11   *
12 < *  printargs(ac,av,fp) print an argument list to fp, followed by '\n'
12 > *  newheader(t,fp)     start new information header identified by string t
13 > *  isheadid(s)         returns true if s is a header id line
14 > *  headidval(r,s)      copy header identifier value in s to r
15 > *  printargs(ac,av,fp) print an argument list to fp, followed by '\n'
16   *  isformat(s)         returns true if s is of the form "FORMAT=*"
17   *  formatval(r,s)      copy the format value in s to r
18   *  fputformat(s,fp)    write "FORMAT=%s" to fp
# Line 22 | Line 25 | static char SCCSid[] = "$SunId$ LBL";
25   #include  <stdio.h>
26   #include  <ctype.h>
27  
28 < #define  MAXLINE        512
28 > #define  MAXLINE        512
29  
30 < char  FMTSTR[] = "FORMAT=";
31 < int  FMTSTRL = 7;
30 > #ifndef BSD
31 > #define  index  strchr
32 > #endif
33  
34 + extern char  *index();
35  
36 + char  HDRSTR[] = "#?";          /* information header magic number */
37 +
38 + char  FMTSTR[] = "FORMAT=";     /* format identifier */
39 +
40 +
41 + newheader(s, fp)                /* identifying line of information header */
42 + char  *s;
43 + register FILE  *fp;
44 + {
45 +        fputs(HDRSTR, fp);
46 +        fputs(s, fp);
47 +        putc('\n', fp);
48 + }
49 +
50 +
51 + headidval(r,s)                  /* get header id (return true if is id) */
52 + register char  *r, *s;
53 + {
54 +        register char  *cp = HDRSTR;
55 +
56 +        while (*cp) if (*cp++ != *s++) return(0);
57 +        if (r == NULL) return(1);
58 +        while (*s) *r++ = *s++;
59 +        *r = '\0';
60 +        return(1);
61 + }
62 +
63 +
64 + isheadid(s)                     /* check to see if line is header id */
65 + char  *s;
66 + {
67 +        return(headidval(NULL, s));
68 + }
69 +
70 +
71   printargs(ac, av, fp)           /* print arguments to a file */
72   int  ac;
73   char  **av;
74 < FILE  *fp;
74 > register FILE  *fp;
75   {
76 +        int  quote;
77 +
78          while (ac-- > 0) {
79 <                fputs(*av++, fp);
79 >                if (index(*av, ' ') != NULL) {          /* quote it */
80 >                        if (index(*av, '\'') != NULL)
81 >                                quote = '"';
82 >                        else
83 >                                quote = '\'';
84 >                        putc(quote, fp);
85 >                        fputs(*av++, fp);
86 >                        putc(quote, fp);
87 >                } else
88 >                        fputs(*av++, fp);
89                  putc(' ', fp);
90          }
91          putc('\n', fp);
92   }
93  
94  
95 < isformat(s)                     /* is line a format line? */
45 < char  *s;
46 < {
47 <        return(!strncmp(s,FMTSTR,FMTSTRL));
48 < }
49 <
50 <
51 < formatval(r, s)                 /* return format value */
95 > formatval(r, s)                 /* get format value (return true if format) */
96   register char  *r;
97   register char  *s;
98   {
99 <        s += FMTSTRL;
99 >        register char  *cp = FMTSTR;
100 >
101 >        while (*cp) if (*cp++ != *s++) return(0);
102          while (isspace(*s)) s++;
103 <        if (!*s) { *r = '\0'; return; }
103 >        if (!*s) return(0);
104 >        if (r == NULL) return(1);
105          while(*s) *r++ = *s++;
106          while (isspace(r[-1])) r--;
107          *r = '\0';
108 +        return(1);
109   }
110  
111  
112 + isformat(s)                     /* is line a format line? */
113 + char  *s;
114 + {
115 +        return(formatval(NULL, s));
116 + }
117 +
118 +
119   fputformat(s, fp)               /* put out a format value */
120   char  *s;
121   FILE  *fp;
# Line 80 | Line 135 | char  *p;
135  
136          for ( ; ; ) {
137                  buf[MAXLINE-2] = '\n';
138 <                if (fgets(buf, sizeof(buf), fp) == NULL)
138 >                if (fgets(buf, MAXLINE, fp) == NULL)
139                          return(-1);
140                  if (buf[0] == '\n')
141                          return(0);
142 + #ifdef MSDOS
143 +                if (buf[0] == '\r' && buf[1] == '\n')
144 +                        return(0);
145 + #endif
146                  if (buf[MAXLINE-2] != '\n') {
147                          ungetc(buf[MAXLINE-2], fp);     /* prevent false end */
148                          buf[MAXLINE-2] = '\0';
# Line 105 | Line 164 | mycheck(s, cp)                 /* check a header line for format inf
164   char  *s;
165   register struct check  *cp;
166   {
167 <        if (!strncmp(s,FMTSTR,FMTSTRL))
109 <                formatval(cp->fs, s);
110 <        else if (cp->fp != NULL)        /* don't copy format info. */
167 >        if (!formatval(cp->fs, s) && cp->fp != NULL)
168                  fputs(s, cp->fp);
169   }
170  
# Line 134 | Line 191 | char   *pat, *str;
191                  case '*':                       /* match any string */
192                          while (p[1] == '*') p++;
193                          do
194 <                                if ( (p[1] == '?' || p[1] == *s)
194 >                                if ( (p[1]=='?' || p[1]==*s)
195                                                  && copymatch(p+1,s) ) {
196                                          strcpy(pat, str);
197                                          return(1);
# Line 164 | Line 221 | char   *pat, *str;
221   * Checkheader(fin,fmt,fout) returns a value of 1 if the input format
222   * matches the specification in fmt, 0 if no input format was found,
223   * and -1 if the input format does not match or there is an
224 < * error reading the header.  If fmt is NULL, then -1 is returned
224 > * error reading the header.  If fmt is empty, then -1 is returned
225   * if any input format is found (or there is an error), and 0 otherwise.
226   * If fmt contains any '*' or '?' characters, then checkheader
227   * does wildcard expansion and copies a matching result into fmt.
# Line 183 | Line 240 | FILE  *fout;
240          cdat.fp = fout;
241          cdat.fs[0] = '\0';
242          if (getheader(fin, mycheck, &cdat) < 0)
186                return(-1);
187        if (fmt == NULL && cdat.fs[0] != '\0')
243                  return(-1);
244          if (cdat.fs[0] != '\0')
245                  return(copymatch(fmt, cdat.fs) ? 1 : -1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines