ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/readobj2.c
Revision: 2.8
Committed: Mon Oct 27 10:29:29 2003 UTC (20 years, 5 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.7: +13 -8 lines
Log Message:
Various compatibility fixes.

File Contents

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