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

Comparing ray/src/common/readobj.c (file contents):
Revision 2.8 by greg, Sat Feb 22 02:07:22 2003 UTC vs.
Revision 2.23 by greg, Sat May 4 00:36:58 2019 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  readobj.c - routines for reading in object descriptions.
# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  External symbols declared in object.h
8   */
9  
10 < /* ====================================================================
11 < * The Radiance Software License, Version 1.0
12 < *
13 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
14 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
15 < *
16 < * Redistribution and use in source and binary forms, with or without
17 < * modification, are permitted provided that the following conditions
18 < * are met:
19 < *
20 < * 1. Redistributions of source code must retain the above copyright
21 < *         notice, this list of conditions and the following disclaimer.
22 < *
23 < * 2. Redistributions in binary form must reproduce the above copyright
24 < *       notice, this list of conditions and the following disclaimer in
25 < *       the documentation and/or other materials provided with the
26 < *       distribution.
27 < *
28 < * 3. The end-user documentation included with the redistribution,
29 < *           if any, must include the following acknowledgment:
30 < *             "This product includes Radiance software
31 < *                 (http://radsite.lbl.gov/)
32 < *                 developed by the Lawrence Berkeley National Laboratory
33 < *               (http://www.lbl.gov/)."
34 < *       Alternately, this acknowledgment may appear in the software itself,
35 < *       if and wherever such third-party acknowledgments normally appear.
36 < *
37 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
38 < *       and "The Regents of the University of California" must
39 < *       not be used to endorse or promote products derived from this
40 < *       software without prior written permission. For written
41 < *       permission, please contact [email protected].
42 < *
43 < * 5. Products derived from this software may not be called "Radiance",
44 < *       nor may "Radiance" appear in their name, without prior written
45 < *       permission of Lawrence Berkeley National Laboratory.
46 < *
47 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
48 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
51 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 < * SUCH DAMAGE.
59 < * ====================================================================
60 < *
61 < * This software consists of voluntary contributions made by many
62 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
63 < * information on Lawrence Berkeley National Laboratory, please see
64 < * <http://www.lbl.gov/>.
65 < */
10 > #include "copyright.h"
11  
12 < #include  "standard.h"
12 > #include  <ctype.h>
13 > #include  <string.h>
14 > #include  <stdio.h>
15  
16 + #include  "platform.h"
17 + #include  "paths.h"
18 + #include  "standard.h"
19   #include  "object.h"
70
20   #include  "otypes.h"
21  
73 #include  <ctype.h>
22  
23   OBJREC  *objblock[MAXOBJBLK];           /* our objects */
24   OBJECT  nobjects = 0;                   /* # of objects */
25  
26  
27   void
28 < readobj(inpspec)                /* read in an object file or stream */
29 < char  *inpspec;
28 > readobj(                                /* read in an object file or stream */
29 >        char  *inpspec
30 > )
31   {
32          OBJECT  lastobj;
33          FILE  *infp;
34 <        char  buf[1024];
35 <        register int  c;
34 >        char  buf[2048];
35 >        int  c;
36  
37          lastobj = nobjects;
38          if (inpspec == NULL) {
# Line 114 | Line 63 | char  *inpspec;
63          }
64          if (inpspec[0] == '!')
65                  pclose(infp);
66 <        else
66 >        else if (infp != stdin)
67                  fclose(infp);
68          if (nobjects == lastobj) {
69                  sprintf(errmsg, "(%s): empty file", inpspec);
# Line 124 | Line 73 | char  *inpspec;
73  
74  
75   void
76 < getobject(name, fp)                     /* read the next object */
77 < char  *name;
78 < FILE  *fp;
76 > getobject(                              /* read the next object */
77 >        char  *name,
78 >        FILE  *fp
79 > )
80   {
81 + #define OALIAS  -2
82          OBJECT  obj;
83          char  sbuf[MAXSTR];
84          int  rval;
85 <        register OBJREC  *objp;
85 >        OBJREC  *objp;
86  
87          if ((obj = newobject()) == OVOID)
88                  error(SYSTEM, "out of object space");
# Line 139 | Line 90 | FILE  *fp;
90                                          /* get modifier */
91          strcpy(sbuf, "EOF");
92          fgetword(sbuf, MAXSTR, fp);
93 +        if (strchr(sbuf, '\t')) {
94 +                sprintf(errmsg, "(%s): illegal tab in modifier \"%s\"",
95 +                                        name, sbuf);
96 +                error(USER, errmsg);
97 +        }
98          if (!strcmp(sbuf, VOIDID))
99                  objp->omod = OVOID;
100 +        else if (!strcmp(sbuf, ALIASMOD))
101 +                objp->omod = OALIAS;
102          else if ((objp->omod = modifier(sbuf)) == OVOID) {
103                  sprintf(errmsg, "(%s): undefined modifier \"%s\"", name, sbuf);
104                  error(USER, errmsg);
# Line 148 | Line 106 | FILE  *fp;
106                                          /* get type */
107          strcpy(sbuf, "EOF");
108          fgetword(sbuf, MAXSTR, fp);
109 <        if (!strcmp(sbuf, ALIASID))
152 <                objp->otype = -1;
153 <        else if ((objp->otype = otype(sbuf)) < 0) {
109 >        if ((objp->otype = otype(sbuf)) < 0) {
110                  sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
111                  error(USER, errmsg);
112          }
113                                          /* get identifier */
114          sbuf[0] = '\0';
115          fgetword(sbuf, MAXSTR, fp);
116 +        if (strchr(sbuf, '\t')) {
117 +                sprintf(errmsg, "(%s): illegal tab in identifier \"%s\"",
118 +                                        name, sbuf);
119 +                error(USER, errmsg);
120 +        }
121          objp->oname = savqstr(sbuf);
122                                          /* get arguments */
123 <        if (objp->otype == -1) {
124 <                register OBJECT  alias;
123 >        if (objp->otype == MOD_ALIAS) {
124 >                OBJECT  alias;
125                  strcpy(sbuf, "EOF");
126                  fgetword(sbuf, MAXSTR, fp);
127                  if ((alias = modifier(sbuf)) == OVOID) {
128 <                        sprintf(errmsg,
129 <                        "(%s): bad reference \"%s\" for %s \"%s\"",
130 <                                        name, sbuf, ALIASID, objp->oname);
170 <                        error(USER, errmsg);
128 >                        sprintf(errmsg, "(%s): bad reference \"%s\"",
129 >                                        name, sbuf);
130 >                        objerror(objp, USER, errmsg);
131                  }
132 <                objp->otype = objptr(alias)->otype;
133 <                copystruct(&objp->oargs, &objptr(alias)->oargs);
132 >                if (objp->omod == OALIAS ||
133 >                                objp->omod == objptr(alias)->omod) {
134 >                        objp->omod = alias;
135 >                } else {
136 >                        objp->oargs.sarg = (char **)malloc(sizeof(char *));
137 >                        if (objp->oargs.sarg == NULL)
138 >                                error(SYSTEM, "out of memory in getobject");
139 >                        objp->oargs.nsargs = 1;
140 >                        objp->oargs.sarg[0] = savestr(sbuf);
141 >                }
142          } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
143                  sprintf(errmsg, "(%s): bad arguments", name);
144                  objerror(objp, USER, errmsg);
# Line 178 | Line 146 | FILE  *fp;
146                  sprintf(errmsg, "(%s): error reading scene", name);
147                  error(SYSTEM, errmsg);
148          }
149 +        if (objp->omod == OALIAS) {
150 +                sprintf(errmsg, "(%s): inappropriate use of '%s' modifier",
151 +                                name, ALIASMOD);
152 +                objerror(objp, USER, errmsg);
153 +        }
154                                          /* initialize */
155          objp->os = NULL;
156  
157          insertobject(obj);              /* add to global structure */
158 + #undef OALIAS
159   }
160  
161  
162 < int
163 < newobject()                             /* get a new object */
162 > OBJECT
163 > newobject(void)                         /* get a new object */
164   {
165 <        register int  i;
165 >        int  i;
166  
167          if ((nobjects & (OBJBLKSIZ-1)) == 0) {  /* new block */
168                  errno = 0;
# Line 203 | Line 177 | newobject()                            /* get a new object */
177   }
178  
179   void
180 < freeobjects(firstobj, nobjs)            /* free a range of objects */
181 < OBJECT  firstobj, nobjs;
180 > freeobjects(                            /* free a range of objects */
181 >        int firstobj,
182 >        int nobjs
183 > )
184   {
185 <        register int  obj;
185 >        int  obj;
186                                          /* check bounds */
187          if (firstobj < 0)
188                  return;
# Line 216 | Line 192 | OBJECT  firstobj, nobjs;
192                  return;
193                                          /* clear objects */
194          for (obj = firstobj+nobjs; obj-- > firstobj; ) {
195 <                register OBJREC  *o = objptr(obj);
195 >                OBJREC  *o = objptr(obj);
196                  free_os(o);             /* free client memory */
197                  freeqstr(o->oname);
198                  freefargs(&o->oargs);
199 <                bzero(o, sizeof(OBJREC));
199 >                memset((void *)o, '\0', sizeof(OBJREC));
200          }
201          clearobjndx();
202                                          /* free objects off end */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines