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 |
|
* |
13 |
|
|
14 |
|
#include "object.h" |
15 |
|
|
16 |
< |
#include "otypes.h" |
16 |
> |
static int oputint(), oputstr(), puttree(); |
17 |
|
|
21 |
– |
static int putint(), putstr(), puttree(), putobj(); |
18 |
|
|
23 |
– |
|
19 |
|
writeoct(store, scene, ofn) /* write octree structures to stdout */ |
20 |
|
int store; |
21 |
|
CUBE *scene; |
22 |
|
char *ofn[]; |
23 |
|
{ |
24 |
|
char sbuf[64]; |
25 |
< |
register int i; |
25 |
> |
int i; |
26 |
|
/* write format number */ |
27 |
< |
putint((long)(OCTMAGIC+sizeof(OBJECT)), 2); |
27 |
> |
oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2); |
28 |
|
|
29 |
|
if (!(store & IO_BOUNDS)) |
30 |
|
return; |
31 |
|
/* write boundaries */ |
32 |
|
for (i = 0; i < 3; i++) { |
33 |
|
sprintf(sbuf, "%.12g", scene->cuorg[i]); |
34 |
< |
putstr(sbuf); |
34 |
> |
oputstr(sbuf); |
35 |
|
} |
36 |
|
sprintf(sbuf, "%.12g", scene->cusize); |
37 |
< |
putstr(sbuf); |
37 |
> |
oputstr(sbuf); |
38 |
|
/* write object file names */ |
39 |
|
if (store & IO_FILES) |
40 |
|
for (i = 0; ofn[i] != NULL; i++) |
41 |
< |
putstr(ofn[i]); |
42 |
< |
putstr(""); |
41 |
> |
oputstr(ofn[i]); |
42 |
> |
oputstr(""); |
43 |
|
/* write number of objects */ |
44 |
< |
putint((long)nobjects, sizeof(OBJECT)); |
44 |
> |
oputint((long)nobjects, sizeof(OBJECT)); |
45 |
|
|
46 |
|
if (!(store & IO_TREE)) |
47 |
|
return; |
51 |
|
if (store & IO_FILES || !(store & IO_SCENE)) |
52 |
|
return; |
53 |
|
/* write the scene */ |
54 |
< |
for (i = 0; i < NUMOTYPE; i++) |
60 |
< |
putstr(ofun[i].funame); |
61 |
< |
putstr(""); |
62 |
< |
for (i = 0; i < nobjects; i++) |
63 |
< |
putobj(objptr(i)); |
64 |
< |
putobj(NULL); |
54 |
> |
writescene(0, nobjects, stdout); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
static |
59 |
< |
putstr(s) /* write null-terminated string to stdout */ |
59 |
> |
oputstr(s) /* write null-terminated string to stdout */ |
60 |
|
register char *s; |
61 |
|
{ |
62 |
< |
do |
73 |
< |
putc(*s, stdout); |
74 |
< |
while (*s++); |
62 |
> |
putstr(s, stdout); |
63 |
|
if (ferror(stdout)) |
64 |
|
error(SYSTEM, "write error in putstr"); |
65 |
|
} |
74 |
|
|
75 |
|
objset(oset, fn); |
76 |
|
for (i = 0; i <= oset[0]; i++) |
77 |
< |
putint((long)oset[i], sizeof(OBJECT)); |
77 |
> |
oputint((long)oset[i], sizeof(OBJECT)); |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
static |
82 |
< |
putint(i, siz) /* write a siz-byte integer to stdout */ |
82 |
> |
oputint(i, siz) /* write a siz-byte integer to stdout */ |
83 |
|
register long i; |
84 |
|
register int siz; |
85 |
|
{ |
86 |
< |
while (siz--) |
99 |
< |
putc(i>>(siz<<3) & 0xff, stdout); |
86 |
> |
putint(i, siz, stdout); |
87 |
|
if (ferror(stdout)) |
88 |
|
error(SYSTEM, "write error in putint"); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
static |
93 |
< |
putflt(f) /* put out floating point number */ |
93 |
> |
oputflt(f) /* put out floating point number */ |
94 |
|
double f; |
95 |
|
{ |
96 |
< |
extern double frexp(); |
97 |
< |
int e; |
98 |
< |
|
112 |
< |
putint((long)(frexp(f,&e)*0x7fffffff), 4); |
113 |
< |
putint((long)e, 1); |
96 |
> |
putflt(f, stdout); |
97 |
> |
if (ferror(stdout)) |
98 |
> |
error(SYSTEM, "write error in putflt"); |
99 |
|
} |
100 |
|
|
101 |
|
|
114 |
|
putfullnode(ot); /* write fullnode */ |
115 |
|
} else |
116 |
|
putc(OT_EMPTY, stdout); /* indicate empty */ |
132 |
– |
} |
133 |
– |
|
134 |
– |
|
135 |
– |
static |
136 |
– |
putobj(o) /* write out object */ |
137 |
– |
register OBJREC *o; |
138 |
– |
{ |
139 |
– |
register int i; |
140 |
– |
|
141 |
– |
if (o == NULL) { /* terminator */ |
142 |
– |
putint(-1L, 1); |
143 |
– |
return; |
144 |
– |
} |
145 |
– |
putint((long)o->otype, 1); |
146 |
– |
putint((long)o->omod, sizeof(OBJECT)); |
147 |
– |
putstr(o->oname); |
148 |
– |
putint((long)o->oargs.nsargs, 2); |
149 |
– |
for (i = 0; i < o->oargs.nsargs; i++) |
150 |
– |
putstr(o->oargs.sarg[i]); |
151 |
– |
#ifdef IARGS |
152 |
– |
putint((long)o->oargs.niargs, 2); |
153 |
– |
for (i = 0; i < o->oargs.niargs; i++) |
154 |
– |
putint((long)o->oargs.iarg[i], 4); |
155 |
– |
#endif |
156 |
– |
putint((long)o->oargs.nfargs, 2); |
157 |
– |
for (i = 0; i < o->oargs.nfargs; i++) |
158 |
– |
putflt(o->oargs.farg[i]); |
117 |
|
} |