ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/readobj2.c
Revision: 2.3
Committed: Fri Jun 4 17:02:19 1993 UTC (30 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +1 -1 lines
Log Message:
removed declaration of fgets()

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 greg 2.3 char *fgetline();
32 greg 1.1 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     /* call function */
101     (*f)(&thisobj);
102     /* free memory */
103     if (thisobj.os != NULL)
104     switch (thisobj.otype) {
105     case OBJ_CONE:
106     case OBJ_CUP:
107     case OBJ_CYLINDER:
108     case OBJ_TUBE:
109     case OBJ_RING:
110     freecone(&thisobj);
111     break;
112     case OBJ_FACE:
113     freeface(&thisobj);
114     break;
115     case OBJ_INSTANCE:
116     freeinstance(&thisobj);
117     break;
118     }
119     freefargs(&thisobj.oargs);
120     }