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 |
|
|
19 |
– |
#include "otypes.h" |
16 |
|
|
17 |
+ |
static void oputstr(char *s); |
18 |
+ |
static void putfullnode(OCTREE fn); |
19 |
+ |
static void oputint(long i, int siz); |
20 |
+ |
static void oputflt(double f); |
21 |
+ |
static void puttree(OCTREE ot); |
22 |
|
|
23 |
< |
writeoct(store, scene, ofn) /* write octree structures to stdout */ |
24 |
< |
int store; |
25 |
< |
CUBE *scene; |
26 |
< |
char *ofn[]; |
23 |
> |
|
24 |
> |
void |
25 |
> |
writeoct( /* write octree structures to stdout */ |
26 |
> |
int store, |
27 |
> |
CUBE *scene, |
28 |
> |
char *ofn[] |
29 |
> |
) |
30 |
|
{ |
31 |
|
char sbuf[64]; |
32 |
< |
register int i; |
32 |
> |
int i; |
33 |
|
/* write format number */ |
34 |
< |
putint((long)OCTMAGIC, 2); |
34 |
> |
oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2); |
35 |
|
|
36 |
|
if (!(store & IO_BOUNDS)) |
37 |
|
return; |
38 |
|
/* write boundaries */ |
39 |
|
for (i = 0; i < 3; i++) { |
40 |
|
sprintf(sbuf, "%.12g", scene->cuorg[i]); |
41 |
< |
putstr(sbuf); |
41 |
> |
oputstr(sbuf); |
42 |
|
} |
43 |
|
sprintf(sbuf, "%.12g", scene->cusize); |
44 |
< |
putstr(sbuf); |
44 |
> |
oputstr(sbuf); |
45 |
|
/* write object file names */ |
46 |
|
if (store & IO_FILES) |
47 |
|
for (i = 0; ofn[i] != NULL; i++) |
48 |
< |
putstr(ofn[i]); |
49 |
< |
putstr(""); |
48 |
> |
oputstr(ofn[i]); |
49 |
> |
oputstr(""); |
50 |
|
/* write number of objects */ |
51 |
< |
putint((long)nobjects, sizeof(OBJECT)); |
51 |
> |
oputint((long)nobjects, sizeof(OBJECT)); |
52 |
|
|
53 |
|
if (!(store & IO_TREE)) |
54 |
|
return; |
58 |
|
if (store & IO_FILES || !(store & IO_SCENE)) |
59 |
|
return; |
60 |
|
/* write the scene */ |
61 |
< |
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); |
61 |
> |
writescene(0, nobjects, stdout); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
< |
static |
66 |
< |
putstr(s) /* write null-terminated string to stdout */ |
67 |
< |
register char *s; |
65 |
> |
static void |
66 |
> |
oputstr( /* write null-terminated string to stdout */ |
67 |
> |
register char *s |
68 |
> |
) |
69 |
|
{ |
70 |
< |
do |
71 |
< |
putc(*s, stdout); |
72 |
< |
while (*s++); |
70 |
> |
putstr(s, stdout); |
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; |
76 |
> |
static void |
77 |
> |
putfullnode( /* write out a full node */ |
78 |
> |
OCTREE fn |
79 |
> |
) |
80 |
|
{ |
81 |
|
OBJECT oset[MAXSET+1]; |
82 |
|
register int i; |
83 |
|
|
84 |
|
objset(oset, fn); |
85 |
|
for (i = 0; i <= oset[0]; i++) |
86 |
< |
putint((long)oset[i], sizeof(OBJECT)); |
86 |
> |
oputint((long)oset[i], sizeof(OBJECT)); |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
< |
static |
91 |
< |
putint(i, siz) /* write a siz-byte integer to stdout */ |
92 |
< |
register long i; |
93 |
< |
register int siz; |
90 |
> |
static void |
91 |
> |
oputint( /* write a siz-byte integer to stdout */ |
92 |
> |
register long i, |
93 |
> |
register int siz |
94 |
> |
) |
95 |
|
{ |
96 |
< |
while (siz--) |
97 |
< |
putc(i>>(siz<<3) & 0xff, stdout); |
96 |
> |
putint(i, siz, stdout); |
97 |
|
if (ferror(stdout)) |
98 |
|
error(SYSTEM, "write error in putint"); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
< |
static |
103 |
< |
putflt(f) /* put out floating point number */ |
104 |
< |
double f; |
102 |
> |
static void |
103 |
> |
oputflt( /* put out floating point number */ |
104 |
> |
double f |
105 |
> |
) |
106 |
|
{ |
107 |
< |
extern double frexp(); |
108 |
< |
int e; |
109 |
< |
|
110 |
< |
putint((long)(frexp(f,&e)*0x7fffffff), 4); |
111 |
< |
putint((long)e, 1); |
107 |
> |
putflt(f, stdout); |
108 |
> |
if (ferror(stdout)) |
109 |
> |
error(SYSTEM, "write error in putflt"); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
< |
static |
114 |
< |
puttree(ot) /* write octree to stdout in pre-order form */ |
115 |
< |
register OCTREE ot; |
113 |
> |
static void |
114 |
> |
puttree( /* write octree to stdout in pre-order form */ |
115 |
> |
register OCTREE ot |
116 |
> |
) |
117 |
|
{ |
118 |
|
register int i; |
119 |
|
|
126 |
|
putfullnode(ot); /* write fullnode */ |
127 |
|
} else |
128 |
|
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((long)o->oargs.niargs, 2); |
151 |
– |
for (i = 0; i < o->oargs.niargs; i++) |
152 |
– |
putint((long)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]); |
129 |
|
} |