--- ray/src/ot/writeoct.c 1989/03/21 15:55:07 1.2 +++ ray/src/ot/writeoct.c 2004/11/09 16:09:20 2.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: writeoct.c,v 2.7 2004/11/09 16:09:20 greg Exp $"; #endif - /* * writeoct.c - routines for writing octree information to stdout. * @@ -13,36 +10,49 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" #include "octree.h" - #include "object.h" +#include "oconv.h" -#include "otypes.h" +#ifdef putc_unlocked /* avoid horrendous overhead of flockfile */ +#undef putc +#define putc putc_unlocked +#endif +static void oputstr(char *s); +static void putfullnode(OCTREE fn); +static void oputint(long i, int siz); +static void oputflt(double f); +static void puttree(OCTREE ot); -writeoct(store, scene, ofn) /* write octree structures to stdout */ -int store; -CUBE *scene; -char *ofn[]; + +void +writeoct( /* write octree structures to stdout */ + int store, + CUBE *scene, + char *ofn[] +) { char sbuf[64]; - register int i; + int i; /* write format number */ - putint((long)OCTMAGIC, 2); + oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2); if (!(store & IO_BOUNDS)) return; /* write boundaries */ for (i = 0; i < 3; i++) { sprintf(sbuf, "%.12g", scene->cuorg[i]); - putstr(sbuf); + oputstr(sbuf); } sprintf(sbuf, "%.12g", scene->cusize); - putstr(sbuf); + oputstr(sbuf); /* write object file names */ if (store & IO_FILES) for (i = 0; ofn[i] != NULL; i++) - putstr(ofn[i]); - putstr(""); + oputstr(ofn[i]); + oputstr(""); + /* write number of objects */ + oputint((long)nobjects, sizeof(OBJECT)); if (!(store & IO_TREE)) return; @@ -52,67 +62,62 @@ char *ofn[]; if (store & IO_FILES || !(store & IO_SCENE)) return; /* write the scene */ - for (i = 0; i < NUMOTYPE; i++) - putstr(ofun[i].funame); - putstr(""); - for (i = 0; i < nobjects; i++) - putobj(objptr(i)); - putobj(NULL); + writescene(0, nobjects, stdout); } -static -putstr(s) /* write null-terminated string to stdout */ -register char *s; +static void +oputstr( /* write null-terminated string to stdout */ + register char *s +) { - do - putc(*s, stdout); - while (*s++); + putstr(s, stdout); if (ferror(stdout)) error(SYSTEM, "write error in putstr"); } -static -putfullnode(fn) /* write out a full node */ -OCTREE fn; +static void +putfullnode( /* write out a full node */ + OCTREE fn +) { OBJECT oset[MAXSET+1]; register int i; objset(oset, fn); for (i = 0; i <= oset[0]; i++) - putint((long)oset[i], sizeof(OBJECT)); + oputint((long)oset[i], sizeof(OBJECT)); } -static -putint(i, siz) /* write a siz-byte integer to stdout */ -register long i; -register int siz; +static void +oputint( /* write a siz-byte integer to stdout */ + register long i, + register int siz +) { - while (siz--) - putc(i>>(siz<<3) & 0xff, stdout); + putint(i, siz, stdout); if (ferror(stdout)) error(SYSTEM, "write error in putint"); } -static -putflt(f) /* put out floating point number */ -double f; +static void +oputflt( /* put out floating point number */ + double f +) { - extern double frexp(); - int e; - - putint((long)(frexp(f,&e)*0x7fffffff), 4); - putint(e, 1); + putflt(f, stdout); + if (ferror(stdout)) + error(SYSTEM, "write error in putflt"); } -static -puttree(ot) /* write octree to stdout in pre-order form */ -register OCTREE ot; +static void +puttree( /* write octree to stdout in pre-order form */ + register OCTREE ot +) { register int i; @@ -125,31 +130,4 @@ register OCTREE ot; putfullnode(ot); /* write fullnode */ } else putc(OT_EMPTY, stdout); /* indicate empty */ -} - - -static -putobj(o) /* write out object */ -register OBJREC *o; -{ - register int i; - - if (o == NULL) { /* terminator */ - putint(-1L, 1); - return; - } - putint((long)o->otype, 1); - putint((long)o->omod, sizeof(OBJECT)); - putstr(o->oname); - putint((long)o->oargs.nsargs, 2); - for (i = 0; i < o->oargs.nsargs; i++) - putstr(o->oargs.sarg[i]); -#ifdef IARGS - putint(o->oargs.niargs, 2); - for (i = 0; i < o->oargs.niargs; i++) - putint(o->oargs.iarg[i], 4); -#endif - putint((long)o->oargs.nfargs, 2); - for (i = 0; i < o->oargs.nfargs; i++) - putflt(o->oargs.farg[i]); }