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 1.1 by greg, Thu Feb 2 10:34:39 1989 UTC vs.
Revision 1.6 by greg, Fri Jul 19 09:25:43 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19   #include  <ctype.h>
20  
21   OBJREC  *objblock[MAXOBJBLK];           /* our objects */
22 < int  nobjects = 0;                      /* # of objects */
22 > OBJECT  nobjects = 0;                   /* # of objects */
23  
24  
25   readobj(input)                  /* read in an object file or stream */
26   char  *input;
27   {
28          FILE  *popen();
29 <        char  *fgets();
29 >        char  *fgets(), *fgetline();
30          FILE  *infp;
31          char  buf[512];
32          register int  c;
# Line 48 | Line 48 | char  *input;
48                          continue;
49                  if (c == '#') {                         /* comment */
50                          fgets(buf, sizeof(buf), infp);
51 <                } else if (c == '!') {                  /* pipe */
51 >                } else if (c == '!') {                  /* command */
52                          ungetc(c, infp);
53 <                        fgets(buf, sizeof(buf), infp);
54 <                        c = strlen(buf);
55 <                        if (buf[c-1] == '\n')
56 <                                buf[c-1] = '\0';
53 >                        fgetline(buf, sizeof(buf), infp);
54                          readobj(buf);
55                  } else {                                /* object */
56                          ungetc(c, infp);
# Line 73 | Line 70 | FILE  *fp;
70   {
71          OBJECT  obj;
72          char  sbuf[MAXSTR];
73 +        int  rval;
74          register OBJREC  *objp;
75  
76          if ((obj = newobject()) == OVOID)
# Line 108 | Line 106 | FILE  *fp;
106                          error(USER, errmsg);
107                  }
108                  objp->otype = objptr(alias)->otype;
109 <                bcopy(&objptr(alias)->oargs, &objp->oargs, sizeof(FUNARGS));
110 <        } else if (readfargs(&objp->oargs, fp) < 0) {
109 >                copystruct(&objp->oargs, &objptr(alias)->oargs);
110 >        } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
111                  sprintf(errmsg, "(%s): bad arguments", name);
112                  objerror(objp, USER, errmsg);
113 +        } else if (rval < 0) {
114 +                sprintf(errmsg, "(%s): error reading scene", name);
115 +                error(SYSTEM, errmsg);
116          }
117                                          /* initialize */
118          objp->os = NULL;
# Line 121 | Line 122 | FILE  *fp;
122   }
123  
124  
124 readfargs(fa, fp)               /* read function arguments from stream */
125 register FUNARGS  *fa;
126 FILE  *fp;
127 {
128        char  sbuf[MAXSTR];
129        int  n;
130        register int  i;
131
132        if (fscanf(fp, "%d", &n) != 1 || n < 0)
133                return(-1);
134        if (fa->nsargs = n) {
135                fa->sarg = (char **)bmalloc(n*sizeof(char *));
136                if (fa->sarg == NULL)
137                        goto memerr;
138                for (i = 0; i < fa->nsargs; i++) {
139                        if (fscanf(fp, "%s", sbuf) != 1)
140                                return(-1);
141                        fa->sarg[i] = savestr(sbuf);
142                }
143        } else
144                fa->sarg = NULL;
145        if (fscanf(fp, "%d", &n) != 1 || n < 0)
146                return(-1);
147 #ifdef  IARGS
148        if (fa->niargs = n) {
149                fa->iarg = (long *)bmalloc(n*sizeof(int));
150                if (fa->iarg == NULL)
151                        goto memerr;
152                for (i = 0; i < n; i++)
153                        if (fscanf(fp, "%ld", &fa->iarg[i]) != 1)
154                                return(-1);
155        } else
156                fa->iarg = NULL;
157 #else
158        if (n != 0)
159                return(-1);
160 #endif
161        if (fscanf(fp, "%d", &n) != 1 || n < 0)
162                return(-1);
163        if (fa->nfargs = n) {
164                fa->farg = (double *)bmalloc(n*sizeof(double));
165                if (fa->farg == NULL)
166                        goto memerr;
167                for (i = 0; i < n; i++)
168                        if (fscanf(fp, "%lf", &fa->farg[i]) != 1)
169                                return(-1);
170        } else
171                fa->farg = NULL;
172        return(0);
173 memerr:
174        error(SYSTEM, "out of memory in readfargs");
175 }
176
177
125   int
126   newobject()                             /* get a new object */
127   {
# Line 185 | Line 132 | newobject()                            /* get a new object */
132                  i = nobjects >> 6;
133                  if (i >= MAXOBJBLK)
134                          return(OVOID);
135 <                objblock[i] = (OBJREC *)malloc(0100*sizeof(OBJREC));
135 >                objblock[i] = (OBJREC *)bmalloc(0100*sizeof(OBJREC));
136                  if (objblock[i] == NULL)
137                          return(OVOID);
138          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines