ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/readobj2.c
Revision: 2.14
Committed: Tue Apr 22 14:51:29 2025 UTC (2 weeks, 2 days ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.13: +2 -2 lines
Log Message:
fix: Changed some errors to warnings for pclose()

File Contents

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