ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 1.2
Committed: Tue Mar 21 15:55:07 1989 UTC (35 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +3 -3 lines
Log Message:
fixed putint() portability

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1986 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * writeoct.c - routines for writing octree information to stdout.
9     *
10     * 7/30/85
11     */
12    
13     #include "standard.h"
14    
15     #include "octree.h"
16    
17     #include "object.h"
18    
19     #include "otypes.h"
20    
21    
22     writeoct(store, scene, ofn) /* write octree structures to stdout */
23     int store;
24     CUBE *scene;
25     char *ofn[];
26     {
27     char sbuf[64];
28     register int i;
29     /* write format number */
30     putint((long)OCTMAGIC, 2);
31    
32     if (!(store & IO_BOUNDS))
33     return;
34     /* write boundaries */
35     for (i = 0; i < 3; i++) {
36     sprintf(sbuf, "%.12g", scene->cuorg[i]);
37     putstr(sbuf);
38     }
39     sprintf(sbuf, "%.12g", scene->cusize);
40     putstr(sbuf);
41     /* write object file names */
42     if (store & IO_FILES)
43     for (i = 0; ofn[i] != NULL; i++)
44     putstr(ofn[i]);
45     putstr("");
46    
47     if (!(store & IO_TREE))
48     return;
49     /* write the octree */
50     puttree(scene->cutree);
51    
52     if (store & IO_FILES || !(store & IO_SCENE))
53     return;
54     /* write the scene */
55     for (i = 0; i < NUMOTYPE; i++)
56     putstr(ofun[i].funame);
57     putstr("");
58     for (i = 0; i < nobjects; i++)
59     putobj(objptr(i));
60     putobj(NULL);
61     }
62    
63    
64     static
65     putstr(s) /* write null-terminated string to stdout */
66     register char *s;
67     {
68     do
69     putc(*s, stdout);
70     while (*s++);
71     if (ferror(stdout))
72     error(SYSTEM, "write error in putstr");
73     }
74    
75    
76     static
77     putfullnode(fn) /* write out a full node */
78     OCTREE fn;
79     {
80     OBJECT oset[MAXSET+1];
81     register int i;
82    
83     objset(oset, fn);
84     for (i = 0; i <= oset[0]; i++)
85     putint((long)oset[i], sizeof(OBJECT));
86     }
87    
88    
89     static
90     putint(i, siz) /* write a siz-byte integer to stdout */
91     register long i;
92     register int siz;
93     {
94     while (siz--)
95 greg 1.2 putc(i>>(siz<<3) & 0xff, stdout);
96 greg 1.1 if (ferror(stdout))
97     error(SYSTEM, "write error in putint");
98     }
99    
100    
101     static
102     putflt(f) /* put out floating point number */
103     double f;
104     {
105     extern double frexp();
106     int e;
107    
108 greg 1.2 putint((long)(frexp(f,&e)*0x7fffffff), 4);
109 greg 1.1 putint(e, 1);
110     }
111    
112    
113     static
114     puttree(ot) /* write octree to stdout in pre-order form */
115     register OCTREE ot;
116     {
117     register int i;
118    
119     if (istree(ot)) {
120     putc(OT_TREE, stdout); /* indicate tree */
121     for (i = 0; i < 8; i++) /* write tree */
122     puttree(octkid(ot, i));
123     } else if (isfull(ot)) {
124     putc(OT_FULL, stdout); /* indicate fullnode */
125     putfullnode(ot); /* write fullnode */
126     } else
127     putc(OT_EMPTY, stdout); /* indicate empty */
128     }
129    
130    
131     static
132     putobj(o) /* write out object */
133     register OBJREC *o;
134     {
135     register int i;
136    
137     if (o == NULL) { /* terminator */
138     putint(-1L, 1);
139     return;
140     }
141     putint((long)o->otype, 1);
142     putint((long)o->omod, sizeof(OBJECT));
143     putstr(o->oname);
144     putint((long)o->oargs.nsargs, 2);
145     for (i = 0; i < o->oargs.nsargs; i++)
146     putstr(o->oargs.sarg[i]);
147     #ifdef IARGS
148     putint(o->oargs.niargs, 2);
149     for (i = 0; i < o->oargs.niargs; i++)
150 greg 1.2 putint(o->oargs.iarg[i], 4);
151 greg 1.1 #endif
152     putint((long)o->oargs.nfargs, 2);
153     for (i = 0; i < o->oargs.nfargs; i++)
154     putflt(o->oargs.farg[i]);
155     }