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 2.2 by greg, Mon Jan 25 12:41:24 1993 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  <ctype.h>
20  
21 + extern char  *fgetword(), *strcpy();
22 +
23   OBJREC  *objblock[MAXOBJBLK];           /* our objects */
24 < int  nobjects = 0;                      /* # of objects */
24 > OBJECT  nobjects = 0;                   /* # of objects */
25  
26  
27   readobj(input)                  /* read in an object file or stream */
28   char  *input;
29   {
30          FILE  *popen();
31 <        char  *fgets();
31 >        char  *fgets(), *fgetline();
32          FILE  *infp;
33          char  buf[512];
34          register int  c;
# Line 48 | Line 50 | char  *input;
50                          continue;
51                  if (c == '#') {                         /* comment */
52                          fgets(buf, sizeof(buf), infp);
53 <                } else if (c == '!') {                  /* pipe */
53 >                } else if (c == '!') {                  /* command */
54                          ungetc(c, infp);
55 <                        fgets(buf, sizeof(buf), infp);
54 <                        c = strlen(buf);
55 <                        if (buf[c-1] == '\n')
56 <                                buf[c-1] = '\0';
55 >                        fgetline(buf, sizeof(buf), infp);
56                          readobj(buf);
57                  } else {                                /* object */
58                          ungetc(c, infp);
# Line 73 | Line 72 | FILE  *fp;
72   {
73          OBJECT  obj;
74          char  sbuf[MAXSTR];
75 +        int  rval;
76          register OBJREC  *objp;
77  
78          if ((obj = newobject()) == OVOID)
79                  error(SYSTEM, "out of object space");
80          objp = objptr(obj);
81                                          /* get modifier */
82 <        fscanf(fp, "%s", sbuf);
82 >        strcpy(sbuf, "EOF");
83 >        fgetword(sbuf, MAXSTR, fp);
84          if (!strcmp(sbuf, VOIDID))
85                  objp->omod = OVOID;
86          else if ((objp->omod = modifier(sbuf)) == OVOID) {
# Line 87 | Line 88 | FILE  *fp;
88                  error(USER, errmsg);
89          }
90                                          /* get type */
91 <        fscanf(fp, "%s", sbuf);
91 >        strcpy(sbuf, "EOF");
92 >        fgetword(sbuf, MAXSTR, fp);
93          if (!strcmp(sbuf, ALIASID))
94                  objp->otype = -1;
95          else if ((objp->otype = otype(sbuf)) < 0) {
# Line 95 | Line 97 | FILE  *fp;
97                  error(USER, errmsg);
98          }
99                                          /* get identifier */
100 <        fscanf(fp, "%s", sbuf);
100 >        sbuf[0] = '\0';
101 >        fgetword(sbuf, MAXSTR, fp);
102          objp->oname = savqstr(sbuf);
103                                          /* get arguments */
104          if (objp->otype == -1) {
105                  register OBJECT  alias;
106 <                fscanf(fp, "%s", sbuf);
106 >                strcpy(sbuf, "EOF");
107 >                fgetword(sbuf, MAXSTR, fp);
108                  if ((alias = modifier(sbuf)) == OVOID) {
109                          sprintf(errmsg,
110                          "(%s): bad reference \"%s\" for %s \"%s\"",
# Line 108 | Line 112 | FILE  *fp;
112                          error(USER, errmsg);
113                  }
114                  objp->otype = objptr(alias)->otype;
115 <                bcopy(&objptr(alias)->oargs, &objp->oargs, sizeof(FUNARGS));
116 <        } else if (readfargs(&objp->oargs, fp) < 0) {
115 >                copystruct(&objp->oargs, &objptr(alias)->oargs);
116 >        } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
117                  sprintf(errmsg, "(%s): bad arguments", name);
118                  objerror(objp, USER, errmsg);
119 +        } else if (rval < 0) {
120 +                sprintf(errmsg, "(%s): error reading scene", name);
121 +                error(SYSTEM, errmsg);
122          }
123                                          /* initialize */
124          objp->os = NULL;
118        objp->lastrno = -1;
125  
126          insertobject(obj);              /* add to global structure */
127   }
128  
129  
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
130   int
131   newobject()                             /* get a new object */
132   {
# Line 185 | Line 137 | newobject()                            /* get a new object */
137                  i = nobjects >> 6;
138                  if (i >= MAXOBJBLK)
139                          return(OVOID);
140 <                objblock[i] = (OBJREC *)malloc(0100*sizeof(OBJREC));
140 >                objblock[i] = (OBJREC *)bmalloc(0100*sizeof(OBJREC));
141                  if (objblock[i] == NULL)
142                          return(OVOID);
143          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines