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.9 by greg, Tue Feb 25 02:47:21 2003 UTC vs.
Revision 2.20 by greg, Tue Mar 30 12:42:33 2010 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 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
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  "rtprocess.h"
18 + #include  "standard.h"
19   #include  "object.h"
15
20   #include  "otypes.h"
21  
18 #include  <ctype.h>
22  
23   OBJREC  *objblock[MAXOBJBLK];           /* our objects */
24   OBJECT  nobjects = 0;                   /* # of objects */
# Line 27 | Line 30 | char  *inpspec;
30   {
31          OBJECT  lastobj;
32          FILE  *infp;
33 <        char  buf[1024];
33 >        char  buf[2048];
34          register int  c;
35  
36          lastobj = nobjects;
# Line 73 | Line 76 | getobject(name, fp)                    /* read the next object */
76   char  *name;
77   FILE  *fp;
78   {
79 + #define OALIAS  -2
80          OBJECT  obj;
81          char  sbuf[MAXSTR];
82          int  rval;
# Line 84 | Line 88 | FILE  *fp;
88                                          /* get modifier */
89          strcpy(sbuf, "EOF");
90          fgetword(sbuf, MAXSTR, fp);
91 +        if (strchr(sbuf, '\t')) {
92 +                sprintf(errmsg, "(%s): illegal tab in modifier \"%s\"",
93 +                                        name, sbuf);
94 +                error(USER, errmsg);
95 +        }
96          if (!strcmp(sbuf, VOIDID))
97                  objp->omod = OVOID;
98 +        else if (!strcmp(sbuf, ALIASMOD))
99 +                objp->omod = OALIAS;
100          else if ((objp->omod = modifier(sbuf)) == OVOID) {
101                  sprintf(errmsg, "(%s): undefined modifier \"%s\"", name, sbuf);
102                  error(USER, errmsg);
# Line 93 | Line 104 | FILE  *fp;
104                                          /* get type */
105          strcpy(sbuf, "EOF");
106          fgetword(sbuf, MAXSTR, fp);
107 <        if (!strcmp(sbuf, ALIASID))
97 <                objp->otype = -1;
98 <        else if ((objp->otype = otype(sbuf)) < 0) {
107 >        if ((objp->otype = otype(sbuf)) < 0) {
108                  sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
109                  error(USER, errmsg);
110          }
111                                          /* get identifier */
112          sbuf[0] = '\0';
113          fgetword(sbuf, MAXSTR, fp);
114 +        if (strchr(sbuf, '\t')) {
115 +                sprintf(errmsg, "(%s): illegal tab in identifier \"%s\"",
116 +                                        name, sbuf);
117 +                error(USER, errmsg);
118 +        }
119          objp->oname = savqstr(sbuf);
120                                          /* get arguments */
121 <        if (objp->otype == -1) {
121 >        if (objp->otype == MOD_ALIAS) {
122                  register OBJECT  alias;
123                  strcpy(sbuf, "EOF");
124                  fgetword(sbuf, MAXSTR, fp);
125                  if ((alias = modifier(sbuf)) == OVOID) {
126 <                        sprintf(errmsg,
127 <                        "(%s): bad reference \"%s\" for %s \"%s\"",
128 <                                        name, sbuf, ALIASID, objp->oname);
115 <                        error(USER, errmsg);
126 >                        sprintf(errmsg, "(%s): bad reference \"%s\"",
127 >                                        name, sbuf);
128 >                        objerror(objp, USER, errmsg);
129                  }
130 <                objp->otype = objptr(alias)->otype;
131 <                copystruct(&objp->oargs, &objptr(alias)->oargs);
130 >                if (objp->omod == OALIAS ||
131 >                                objp->omod == objptr(alias)->omod) {
132 >                        objp->omod = alias;
133 >                } else {
134 >                        objp->oargs.sarg = (char **)malloc(sizeof(char *));
135 >                        if (objp->oargs.sarg == NULL)
136 >                                error(SYSTEM, "out of memory in getobject");
137 >                        objp->oargs.nsargs = 1;
138 >                        objp->oargs.sarg[0] = savestr(sbuf);
139 >                }
140          } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
141                  sprintf(errmsg, "(%s): bad arguments", name);
142                  objerror(objp, USER, errmsg);
# Line 123 | Line 144 | FILE  *fp;
144                  sprintf(errmsg, "(%s): error reading scene", name);
145                  error(SYSTEM, errmsg);
146          }
147 +        if (objp->omod == OALIAS) {
148 +                sprintf(errmsg, "(%s): inappropriate use of '%s' modifier",
149 +                                name, ALIASMOD);
150 +                objerror(objp, USER, errmsg);
151 +        }
152                                          /* initialize */
153          objp->os = NULL;
154  
155          insertobject(obj);              /* add to global structure */
156 + #undef OALIAS
157   }
158  
159  
160 < int
160 > OBJECT
161   newobject()                             /* get a new object */
162   {
163          register int  i;
# Line 149 | Line 176 | newobject()                            /* get a new object */
176  
177   void
178   freeobjects(firstobj, nobjs)            /* free a range of objects */
179 < OBJECT  firstobj, nobjs;
179 > int  firstobj, nobjs;
180   {
181          register int  obj;
182                                          /* check bounds */
# Line 165 | Line 192 | OBJECT  firstobj, nobjs;
192                  free_os(o);             /* free client memory */
193                  freeqstr(o->oname);
194                  freefargs(&o->oargs);
195 <                bzero(o, sizeof(OBJREC));
195 >                memset((void *)o, '\0', sizeof(OBJREC));
196          }
197          clearobjndx();
198                                          /* free objects off end */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines