ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/readobj2.c
Revision: 2.1
Committed: Tue Nov 12 17:01:03 1991 UTC (32 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.5: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * readobj2.c - routines for reading in object descriptions.
9     */
10    
11     #include "standard.h"
12    
13     #include "object.h"
14    
15     #include "otypes.h"
16    
17     #include <ctype.h>
18    
19 greg 1.5 extern char *fgetword();
20    
21 greg 1.1 OBJREC *objblock[MAXOBJBLK]; /* our objects */
22     OBJECT nobjects = 0; /* # of objects */
23     int newobject() {return(0);}
24    
25    
26     readobj(input, callback) /* read in an object file or stream */
27     char *input;
28     int (*callback)();
29     {
30     FILE *popen();
31     char *fgets(), *fgetline();
32     FILE *infp;
33     char buf[512];
34     register int c;
35    
36     if (input == NULL) {
37     infp = stdin;
38     input = "standard input";
39     } else if (input[0] == '!') {
40     if ((infp = popen(input+1, "r")) == NULL) {
41     sprintf(errmsg, "cannot execute \"%s\"", input);
42     error(SYSTEM, errmsg);
43     }
44     } else if ((infp = fopen(input, "r")) == NULL) {
45     sprintf(errmsg, "cannot open scene file \"%s\"", input);
46     error(SYSTEM, errmsg);
47     }
48     while ((c = getc(infp)) != EOF) {
49     if (isspace(c))
50     continue;
51     if (c == '#') { /* comment */
52     fgets(buf, sizeof(buf), infp);
53     } else if (c == '!') { /* command */
54     ungetc(c, infp);
55     fgetline(buf, sizeof(buf), infp);
56 greg 1.2 readobj(buf, callback);
57 greg 1.1 } else { /* object */
58     ungetc(c, infp);
59     getobject(input, infp, callback);
60     }
61     }
62     if (input[0] == '!')
63     pclose(infp);
64     else
65     fclose(infp);
66     }
67    
68    
69     getobject(name, fp, f) /* read the next object */
70     char *name;
71     FILE *fp;
72     int (*f)();
73     {
74     char sbuf[MAXSTR];
75     OBJREC thisobj;
76     /* get modifier */
77 greg 1.5 fgetword(sbuf, MAXSTR, fp);
78 greg 1.2 thisobj.omod = OVOID;
79 greg 1.1 /* get type */
80 greg 1.5 fgetword(sbuf, MAXSTR, fp);
81 greg 1.1 if (!strcmp(sbuf, ALIASID))
82     thisobj.otype = -1;
83     else if ((thisobj.otype = otype(sbuf)) < 0) {
84     sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
85     error(USER, errmsg);
86     }
87     /* get identifier */
88 greg 1.5 fgetword(sbuf, MAXSTR, fp);
89 greg 1.1 thisobj.oname = sbuf;
90     /* get arguments */
91     if (thisobj.otype == -1) {
92     fscanf(fp, "%*s");
93     return;
94     }
95 greg 1.4 if (readfargs(&thisobj.oargs, fp) <= 0) {
96 greg 1.1 sprintf(errmsg, "(%s): bad arguments", name);
97     objerror(&thisobj, USER, errmsg);
98     }
99     thisobj.os = NULL;
100     thisobj.lastrno = -1;
101     /* call function */
102     (*f)(&thisobj);
103     /* free memory */
104     if (thisobj.os != NULL)
105     switch (thisobj.otype) {
106     case OBJ_CONE:
107     case OBJ_CUP:
108     case OBJ_CYLINDER:
109     case OBJ_TUBE:
110     case OBJ_RING:
111     freecone(&thisobj);
112     break;
113     case OBJ_FACE:
114     freeface(&thisobj);
115     break;
116     case OBJ_INSTANCE:
117     freeinstance(&thisobj);
118     break;
119     }
120     freefargs(&thisobj.oargs);
121     }