ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/readobj2.c
Revision: 2.4
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +6 -29 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

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 1.1 if (!strcmp(sbuf, ALIASID))
74     thisobj.otype = -1;
75     else if ((thisobj.otype = otype(sbuf)) < 0) {
76     sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
77     error(USER, errmsg);
78     }
79     /* get identifier */
80 greg 1.5 fgetword(sbuf, MAXSTR, fp);
81 greg 1.1 thisobj.oname = sbuf;
82     /* get arguments */
83     if (thisobj.otype == -1) {
84     fscanf(fp, "%*s");
85     return;
86     }
87 greg 1.4 if (readfargs(&thisobj.oargs, fp) <= 0) {
88 greg 1.1 sprintf(errmsg, "(%s): bad arguments", name);
89     objerror(&thisobj, USER, errmsg);
90     }
91     thisobj.os = NULL;
92     /* call function */
93     (*f)(&thisobj);
94     /* free memory */
95     freefargs(&thisobj.oargs);
96 greg 2.4 free_os(&thisobj);
97 greg 1.1 }