ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/readobj2.c
Revision: 2.5
Committed: Tue Mar 11 19:29:05 2003 UTC (21 years ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.4: +2 -4 lines
Log Message:
Changed alias handling to allow tracking, fixed freeobjects() and do_irrad bugs

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * readobj2.c - routines for reading in object descriptions.
6 */
7
8 #include "standard.h"
9
10 #include "object.h"
11
12 #include "otypes.h"
13
14 #include <ctype.h>
15
16 extern char *fgetword();
17
18 readobj2(input, callback) /* read in an object file or stream */
19 char *input;
20 int (*callback)();
21 {
22 FILE *popen();
23 char *fgetline();
24 FILE *infp;
25 char buf[512];
26 register int c;
27
28 if (input == NULL) {
29 infp = stdin;
30 input = "standard input";
31 } else if (input[0] == '!') {
32 if ((infp = popen(input+1, "r")) == NULL) {
33 sprintf(errmsg, "cannot execute \"%s\"", input);
34 error(SYSTEM, errmsg);
35 }
36 } else if ((infp = fopen(input, "r")) == NULL) {
37 sprintf(errmsg, "cannot open scene file \"%s\"", input);
38 error(SYSTEM, errmsg);
39 }
40 while ((c = getc(infp)) != EOF) {
41 if (isspace(c))
42 continue;
43 if (c == '#') { /* comment */
44 fgets(buf, sizeof(buf), infp);
45 } else if (c == '!') { /* command */
46 ungetc(c, infp);
47 fgetline(buf, sizeof(buf), infp);
48 readobj2(buf, callback);
49 } else { /* object */
50 ungetc(c, infp);
51 getobject2(input, infp, callback);
52 }
53 }
54 if (input[0] == '!')
55 pclose(infp);
56 else
57 fclose(infp);
58 }
59
60
61 getobject2(name, fp, f) /* read the next object */
62 char *name;
63 FILE *fp;
64 int (*f)();
65 {
66 char sbuf[MAXSTR];
67 OBJREC thisobj;
68 /* get modifier */
69 fgetword(sbuf, MAXSTR, fp);
70 thisobj.omod = OVOID;
71 /* get type */
72 fgetword(sbuf, MAXSTR, fp);
73 if ((thisobj.otype = otype(sbuf)) < 0) {
74 sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
75 error(USER, errmsg);
76 }
77 /* get identifier */
78 fgetword(sbuf, MAXSTR, fp);
79 thisobj.oname = sbuf;
80 /* get arguments */
81 if (thisobj.otype == MOD_ALIAS) {
82 fscanf(fp, "%*s");
83 return;
84 }
85 if (readfargs(&thisobj.oargs, fp) <= 0) {
86 sprintf(errmsg, "(%s): bad arguments", name);
87 objerror(&thisobj, USER, errmsg);
88 }
89 thisobj.os = NULL;
90 /* call function */
91 (*f)(&thisobj);
92 /* free memory */
93 freefargs(&thisobj.oargs);
94 free_os(&thisobj);
95 }