--- ray/src/common/readoct.c 2016/02/02 18:02:32 2.29 +++ ray/src/common/readoct.c 2025/06/07 05:09:45 2.37 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: readoct.c,v 2.29 2016/02/02 18:02:32 greg Exp $"; +static const char RCSid[] = "$Id: readoct.c,v 2.37 2025/06/07 05:09:45 greg Exp $"; #endif /* * readoct.c - routines to read octree information. @@ -11,18 +11,12 @@ static const char RCSid[] = "$Id: readoct.c,v 2.29 201 #include #include "platform.h" -#include "paths.h" #include "standard.h" #include "octree.h" #include "object.h" #include "otypes.h" #include "resolu.h" -#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ -#undef getc -#define getc getc_unlocked -#endif - static double ogetflt(void); static long ogetint(int); static char *ogetstr(char *); @@ -46,6 +40,8 @@ readoct( /* read in octree file or stream */ char *ofn[] ) { + time_t oct_t = 0; + time_t last_it = 0; char sbuf[512]; int nf; int i; @@ -67,7 +63,11 @@ readoct( /* read in octree file or stream */ inpspec); error(SYSTEM, errmsg); } + oct_t = fddate(fileno(infp)); } +#ifdef getc_unlocked /* avoid stupid semaphores */ + flockfile(infp); +#endif SET_FILE_BINARY(infp); /* get header */ if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : (FILE *)NULL) < 0) @@ -92,6 +92,11 @@ readoct( /* read in octree file or stream */ readobj(sbuf); if (load & IO_FILES) ofn[nf] = savqstr(sbuf); + if (oct_t > last_it) { + time_t t = fdate(sbuf); + if (t > last_it) + last_it = t; + } nf++; } if (load & IO_FILES) @@ -116,15 +121,22 @@ readoct( /* read in octree file or stream */ if (nobjects != objorig+fnobjects) octerror(USER, "bad object count; octree stale?"); /* check for non-surfaces */ - if (nonsurfintree(scene->cutree)) + if (oct_t <= last_it && nonsurfintree(scene->cutree)) octerror(USER, "modifier in tree; octree stale?"); } } /* close the input */ - if (infn[0] == '!') - pclose(infp); - else + if (inpspec[0] == '!') { + if (pclose(infp) != 0) { + sprintf(errmsg, "bad status from \"%s\"", inpspec); + error(WARNING, errmsg); + } + } else if (infp != stdin) fclose(infp); +#ifdef getc_unlocked + else + funlockfile(infp); +#endif return(nf); } @@ -132,8 +144,6 @@ readoct( /* read in octree file or stream */ static char * ogetstr(char *s) /* get null-terminated string */ { - extern char *getstr(); - if (getstr(s, infp) == NULL) octerror(USER, "truncated octree"); return(s); @@ -144,8 +154,8 @@ static OCTREE getfullnode() /* get a set, return fullnode */ { OBJECT set[MAXSET+1]; - register int i; - register long m; + int i; + long m; if ((set[0] = ogetint(objsize)) > MAXSET) octerror(USER, "bad set in getfullnode"); @@ -161,8 +171,7 @@ getfullnode() /* get a set, return fullnode */ static long ogetint(int siz) /* get a siz-byte integer */ { - extern long getint(); - register long r; + long r; r = getint(siz, infp); if (feof(infp)) @@ -174,7 +183,6 @@ ogetint(int siz) /* get a siz-byte integer */ static double ogetflt() /* get a floating point number */ { - extern double getflt(); double r; r = getflt(infp); @@ -187,8 +195,8 @@ ogetflt() /* get a floating point number */ static OCTREE gettree() /* get a pre-ordered octree */ { - register OCTREE ot; - register int i; + OCTREE ot; + int i; switch (getc(infp)) { case OT_EMPTY: @@ -214,7 +222,7 @@ static int nonsurfintree(OCTREE ot) /* check tree for modifiers */ { OBJECT set[MAXSET+1]; - register int i; + int i; if (isempty(ot)) return(0); @@ -235,7 +243,7 @@ nonsurfintree(OCTREE ot) /* check tree for modifiers static void skiptree(void) /* skip octree on input */ { - register int i; + int i; switch (getc(infp)) { case OT_EMPTY: