--- ray/src/common/readoct.c 2019/05/04 00:32:47 2.31 +++ ray/src/common/readoct.c 2025/04/23 01:57:04 2.36 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: readoct.c,v 2.31 2019/05/04 00:32:47 greg Exp $"; +static const char RCSid[] = "$Id: readoct.c,v 2.36 2025/04/23 01:57:04 greg Exp $"; #endif /* * readoct.c - routines to read octree information. @@ -41,6 +41,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; @@ -62,7 +64,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) @@ -87,6 +93,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) @@ -111,15 +122,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 (infp != stdin) + 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); } @@ -127,8 +145,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); @@ -139,8 +155,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"); @@ -156,8 +172,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)) @@ -169,7 +184,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); @@ -182,8 +196,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: @@ -209,7 +223,7 @@ static int nonsurfintree(OCTREE ot) /* check tree for modifiers */ { OBJECT set[MAXSET+1]; - register int i; + int i; if (isempty(ot)) return(0); @@ -230,7 +244,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: