ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/holofile.c
(Generate patch)

Comparing ray/src/hd/holofile.c (file contents):
Revision 3.51 by schorsch, Mon Jul 21 22:30:18 2003 UTC vs.
Revision 3.54 by greg, Wed Oct 22 02:06:34 2003 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11  
12   #include <string.h>
13  
14 + #include "platform.h"
15 +
16   #include "holo.h"
17  
18   #ifndef CACHESIZE
# Line 133 | Line 135 | int    wr;
135          }
136          hdfragl[fd].nlinks++;
137          hdfragl[fd].writable = wr;              /* set writable flag */
138 <        hdfragl[fd].flen = lseek(fd, (off_t)0, 2);      /* get file length */
138 >                                                /* get file length */
139 >        hdfragl[fd].flen = lseek(fd, (off_t)0, SEEK_END);
140   }
141  
142  
# Line 143 | Line 146 | int    wr;
146   hdrelease(fd)           /* stop tracking file fragments for some section */
147   register int    fd;
148   {
149 <        if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks)
149 >        if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks)
150                  return;
151          if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) {
152                  free((void *)hdfragl[fd].fi);
# Line 165 | Line 168 | HDGRID *hproto;                /* holodeck section grid */
168          register int    n;
169                                          /* prepare for system errors */
170          errno = 0;
171 <        if ((fpos = lseek(fd, (off_t)0, 1)) < 0)
171 >        if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0)
172                  error(SYSTEM, "cannot determine holodeck file position");
173          if (hproto == NULL) {           /* assume we're loading it */
174                  HDGRID  hpr;
# Line 190 | Line 193 | HDGRID *hproto;                /* holodeck section grid */
193                  if (fd < nhdfragls && hdfragl[fd].nlinks)
194                          writable = hdfragl[fd].writable;
195                  else
196 <                        writable = lseek(fd, fpos, 0) == fpos &&
196 >                        writable = lseek(fd, fpos, SEEK_SET) == fpos &&
197                                  write(fd, (char *)hp, sizeof(HDGRID)) ==
198                                                          sizeof(HDGRID);
199          } else {                        /* else assume we're creating it */
# Line 213 | Line 216 | HDGRID *hproto;                /* holodeck section grid */
216          fpos = hdfilen(fd);
217          biglob(hp)->nrd = rtrunc = 0;
218          for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--)
219 <                if (hp->bi[n].nrd)
219 >                if (hp->bi[n].nrd) {
220                          if (hp->bi[n].fo+hp->bi[n].nrd*sizeof(RAYVAL) > fpos) {
221                                  rtrunc += hp->bi[n].nrd;
222                                  hp->bi[n].nrd = 0;
223                          } else
224                                  biglob(hp)->nrd += hp->bi[n].nrd;
225 +                }
226          if (rtrunc) {
227                  sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)",
228                                  rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd));
# Line 246 | Line 250 | int    i;
250          register int    j;
251  
252          if (!hp->dirty++) {                     /* write smudge first time */
253 <                if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0
254 <                                || write(hp->fd, (char *)&smudge,
253 >                if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI),
254 >                                        SEEK_SET) < 0 ||
255 >                                write(hp->fd, (char *)&smudge,
256                                          sizeof(BEAMI)) != sizeof(BEAMI))
257                          error(SYSTEM, "seek/write error in hdmarkdirty");
258                  hp->dirseg[0].s = i;
# Line 310 | Line 315 | int    all;
315          errno = 0;                      /* write dirty segments */
316          for (j = 0; j < hp->dirty; j++) {
317                  if (lseek(hp->fd, biglob(hp)->fo +
318 <                                (hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0)
318 >                            (hp->dirseg[j].s-1)*sizeof(BEAMI), SEEK_SET) < 0)
319                          error(SYSTEM, "cannot seek on holodeck file");
320                  n = hp->dirseg[j].n * sizeof(BEAMI);
321                  if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n)
# Line 359 | Line 364 | int    fd;
364          if (fd < 0)
365                  return(-1);
366          if (fd >= nhdfragls || !hdfragl[fd].nlinks) {
367 <                if ((fpos = lseek(fd, (off_t)0, 1)) < 0)
367 >                if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0)
368                          return(-1);
369 <                flen = lseek(fd, (off_t)0, 2);
370 <                lseek(fd, fpos, 0);
369 >                flen = lseek(fd, (off_t)0, SEEK_END);
370 >                lseek(fd, fpos, SEEK_SET);
371                  return(flen);
372          }
373          return(hdfragl[fd].flen);
# Line 405 | Line 410 | int    nr;                     /* number of new rays desired */
410          int     n;
411  
412          if (nr <= 0) return(NULL);
413 <        CHECK(i < 1 | i > nbeams(hp),
413 >        CHECK((i < 1) | (i > nbeams(hp)),
414                          CONSISTENCY, "bad beam index given to hdnewrays");
415          if (hp->bl[i] != NULL)
416                  hp->bl[i]->tick = hdclock;      /* preempt swap */
# Line 417 | Line 422 | int    nr;                     /* number of new rays desired */
422                  blglob(hp)->nrm += n;
423                  if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) {
424                          errno = 0;
425 <                        if (lseek(hp->fd, hp->bi[i].fo, 0) < 0)
425 >                        if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0)
426                                  error(SYSTEM, "seek error on holodeck file");
427                          n *= sizeof(RAYVAL);
428                          if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n)
# Line 446 | Line 451 | register int   i;
451   {
452          register int    n;
453  
454 <        CHECK(i < 1 | i > nbeams(hp),
454 >        CHECK((i < 1) | (i > nbeams(hp)),
455                          CONSISTENCY, "bad beam index given to hdgetbeam");
456          if (hp->bl[i] == NULL) {                /* load from disk */
457                  if (!(n = hp->bi[i].nrd))
# Line 456 | Line 461 | register int   i;
461                  hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam");
462                  blglob(hp)->nrm += hp->bl[i]->nrm = n;
463                  errno = 0;
464 <                if (lseek(hp->fd, hp->bi[i].fo, 0) < 0)
464 >                if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0)
465                          error(SYSTEM, "seek error on holodeck file");
466                  n *= sizeof(RAYVAL);
467                  if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n)
# Line 500 | Line 505 | void   (*bf)();                /* callback function (optional) */
505                                          /* precheck consistency */
506          if (n <= 0) return;
507          for (i = n; i--; )
508 <                if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h))
508 >                if (hb[i].h==NULL || (hb[i].b<1) | (hb[i].b>nbeams(hb[i].h)))
509                          error(CONSISTENCY, "bad beam in hdloadbeams");
510                                          /* sort list for optimal access */
511          qsort((void *)hb, n, sizeof(HDBEAMI), hdfilord);
# Line 621 | Line 626 | register int32 *listsiz;
626          register struct fraglist        *f;
627          register int    i;
628  
629 <        if (fd < 0 | fd >= nhdfragls || !(f = &hdfragl[fd])->nlinks)
629 >        if ((fd < 0) | (fd >= nhdfragls) || !(f = &hdfragl[fd])->nlinks)
630                  return(0);              /* listless */
631          if (listlen != NULL)
632                  *listlen = f->nfrags;
# Line 687 | Line 692 | register int   i;
692          if (nrays) {                    /* get and write new fragment */
693                  nfo = hdallocfrag(hp->fd, nrays);
694                  errno = 0;
695 <                if (lseek(hp->fd, nfo, 0) < 0)
695 >                if (lseek(hp->fd, nfo, SEEK_SET) < 0)
696                          error(SYSTEM, "cannot seek on holodeck file");
697                  n = hp->bl[i]->nrm * sizeof(RAYVAL);
698                  if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) {
# Line 761 | Line 766 | register int   i;
766                  return(nchanged);
767          }
768          if (i == 0) {                   /* clobber entire holodeck */
769 <                if (biglob(hp)->nrd == 0 & blglob(hp)->nrm == 0)
769 >                if ((biglob(hp)->nrd == 0) & (blglob(hp)->nrm == 0))
770                          return(0);              /* already empty */
771                  nchanged = 0;
772                  nchanged = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines