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

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.4 static const char RCSid[] = "$Id$";
3 greg 1.1 #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 greg 1.5 extern char *fgetword();
17    
18 greg 2.4 readobj2(input, callback) /* read in an object file or stream */
19 greg 1.1 char *input;
20     int (*callback)();
21     {
22     FILE *popen();
23 greg 2.3 char *fgetline();
24 greg 1.1 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 greg 2.4 readobj2(buf, callback);
49 greg 1.1 } else { /* object */
50     ungetc(c, infp);
51 greg 2.4 getobject2(input, infp, callback);
52 greg 1.1 }
53     }
54     if (input[0] == '!')
55     pclose(infp);
56     else
57     fclose(infp);
58     }
59    
60    
61 greg 2.4 getobject2(name, fp, f) /* read the next object */
62 greg 1.1 char *name;
63     FILE *fp;
64     int (*f)();
65     {
66     char sbuf[MAXSTR];
67     OBJREC thisobj;
68     /* get modifier */
69 greg 1.5 fgetword(sbuf, MAXSTR, fp);
70 greg 1.2 thisobj.omod = OVOID;
71 greg 1.1 /* get type */
72 greg 1.5 fgetword(sbuf, MAXSTR, fp);
73 greg 2.5 if ((thisobj.otype = otype(sbuf)) < 0) {
74 greg 1.1 sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
75     error(USER, errmsg);
76     }
77     /* get identifier */
78 greg 1.5 fgetword(sbuf, MAXSTR, fp);
79 greg 1.1 thisobj.oname = sbuf;
80     /* get arguments */
81 greg 2.5 if (thisobj.otype == MOD_ALIAS) {
82 greg 1.1 fscanf(fp, "%*s");
83     return;
84     }
85 greg 1.4 if (readfargs(&thisobj.oargs, fp) <= 0) {
86 greg 1.1 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 greg 2.4 free_os(&thisobj);
95 greg 1.1 }