ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readobj.c
Revision: 2.6
Committed: Mon Aug 24 16:42:46 1998 UTC (25 years, 8 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 2.5: +1 -1 lines
Log Message:
changed object block size and increased object limit to 32 million

File Contents

# Content
1 /* Copyright (c) 1994 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * readobj.c - routines for reading in object descriptions.
9 *
10 * 7/28/85
11 */
12
13 #include "standard.h"
14
15 #include "object.h"
16
17 #include "otypes.h"
18
19 #include <ctype.h>
20
21 extern char *fgetword(), *strcpy();
22
23 OBJREC *objblock[MAXOBJBLK]; /* our objects */
24 OBJECT nobjects = 0; /* # of objects */
25
26
27 readobj(inpspec) /* read in an object file or stream */
28 char *inpspec;
29 {
30 FILE *popen();
31 char *fgetline();
32 OBJECT lastobj;
33 FILE *infp;
34 char buf[1024];
35 register int c;
36
37 lastobj = nobjects;
38 if (inpspec == NULL) {
39 infp = stdin;
40 inpspec = "standard input";
41 } else if (inpspec[0] == '!') {
42 if ((infp = popen(inpspec+1, "r")) == NULL) {
43 sprintf(errmsg, "cannot execute \"%s\"", inpspec);
44 error(SYSTEM, errmsg);
45 }
46 } else if ((infp = fopen(inpspec, "r")) == NULL) {
47 sprintf(errmsg, "cannot open scene file \"%s\"", inpspec);
48 error(SYSTEM, errmsg);
49 }
50 while ((c = getc(infp)) != EOF) {
51 if (isspace(c))
52 continue;
53 if (c == '#') { /* comment */
54 fgets(buf, sizeof(buf), infp);
55 } else if (c == '!') { /* command */
56 ungetc(c, infp);
57 fgetline(buf, sizeof(buf), infp);
58 readobj(buf);
59 } else { /* object */
60 ungetc(c, infp);
61 getobject(inpspec, infp);
62 }
63 }
64 if (inpspec[0] == '!')
65 pclose(infp);
66 else
67 fclose(infp);
68 if (nobjects == lastobj) {
69 sprintf(errmsg, "(%s): empty file", inpspec);
70 error(WARNING, errmsg);
71 }
72 }
73
74
75 getobject(name, fp) /* read the next object */
76 char *name;
77 FILE *fp;
78 {
79 OBJECT obj;
80 char sbuf[MAXSTR];
81 int rval;
82 register OBJREC *objp;
83
84 if ((obj = newobject()) == OVOID)
85 error(SYSTEM, "out of object space");
86 objp = objptr(obj);
87 /* get modifier */
88 strcpy(sbuf, "EOF");
89 fgetword(sbuf, MAXSTR, fp);
90 if (!strcmp(sbuf, VOIDID))
91 objp->omod = OVOID;
92 else if ((objp->omod = modifier(sbuf)) == OVOID) {
93 sprintf(errmsg, "(%s): undefined modifier \"%s\"", name, sbuf);
94 error(USER, errmsg);
95 }
96 /* get type */
97 strcpy(sbuf, "EOF");
98 fgetword(sbuf, MAXSTR, fp);
99 if (!strcmp(sbuf, ALIASID))
100 objp->otype = -1;
101 else if ((objp->otype = otype(sbuf)) < 0) {
102 sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
103 error(USER, errmsg);
104 }
105 /* get identifier */
106 sbuf[0] = '\0';
107 fgetword(sbuf, MAXSTR, fp);
108 objp->oname = savqstr(sbuf);
109 /* get arguments */
110 if (objp->otype == -1) {
111 register OBJECT alias;
112 strcpy(sbuf, "EOF");
113 fgetword(sbuf, MAXSTR, fp);
114 if ((alias = modifier(sbuf)) == OVOID) {
115 sprintf(errmsg,
116 "(%s): bad reference \"%s\" for %s \"%s\"",
117 name, sbuf, ALIASID, objp->oname);
118 error(USER, errmsg);
119 }
120 objp->otype = objptr(alias)->otype;
121 copystruct(&objp->oargs, &objptr(alias)->oargs);
122 } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
123 sprintf(errmsg, "(%s): bad arguments", name);
124 objerror(objp, USER, errmsg);
125 } else if (rval < 0) {
126 sprintf(errmsg, "(%s): error reading scene", name);
127 error(SYSTEM, errmsg);
128 }
129 /* initialize */
130 objp->os = NULL;
131
132 insertobject(obj); /* add to global structure */
133 }
134
135
136 int
137 newobject() /* get a new object */
138 {
139 register int i;
140
141 if ((nobjects & 077) == 0) { /* new block */
142 errno = 0;
143 i = nobjects >> 6;
144 if (i >= MAXOBJBLK)
145 return(OVOID);
146 objblock[i] = (OBJREC *)bmalloc(OBJBLKSIZ*sizeof(OBJREC));
147 if (objblock[i] == NULL)
148 return(OVOID);
149 }
150 return(nobjects++);
151 }