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