--- ray/src/hd/holofile.c 2003/06/30 14:59:11 3.49 +++ ray/src/hd/holofile.c 2003/10/22 02:06:34 3.54 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: holofile.c,v 3.49 2003/06/30 14:59:11 schorsch Exp $"; +static const char RCSid[] = "$Id: holofile.c,v 3.54 2003/10/22 02:06:34 greg Exp $"; #endif /* * Routines for managing holodeck files @@ -11,6 +11,8 @@ static const char RCSid[] = "$Id: holofile.c,v 3.49 20 #include +#include "platform.h" + #include "holo.h" #ifndef CACHESIZE @@ -78,7 +80,7 @@ HDGRID *hproto; if ((hp = (HOLO *)malloc(n)) == NULL) return(NULL); /* copy header information */ - copystruct(hp, &hdhead); + *hp = hdhead; /* allocate and clear beam list */ hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); if (hp->bl == NULL) { @@ -133,7 +135,8 @@ int wr; } hdfragl[fd].nlinks++; hdfragl[fd].writable = wr; /* set writable flag */ - hdfragl[fd].flen = lseek(fd, (off_t)0, 2); /* get file length */ + /* get file length */ + hdfragl[fd].flen = lseek(fd, (off_t)0, SEEK_END); } @@ -143,7 +146,7 @@ int wr; hdrelease(fd) /* stop tracking file fragments for some section */ register int fd; { - if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) + if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks) return; if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { free((void *)hdfragl[fd].fi); @@ -165,7 +168,7 @@ HDGRID *hproto; /* holodeck section grid */ register int n; /* prepare for system errors */ errno = 0; - if ((fpos = lseek(fd, (off_t)0, 1)) < 0) + if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) error(SYSTEM, "cannot determine holodeck file position"); if (hproto == NULL) { /* assume we're loading it */ HDGRID hpr; @@ -190,7 +193,7 @@ HDGRID *hproto; /* holodeck section grid */ if (fd < nhdfragls && hdfragl[fd].nlinks) writable = hdfragl[fd].writable; else - writable = lseek(fd, fpos, 0) == fpos && + writable = lseek(fd, fpos, SEEK_SET) == fpos && write(fd, (char *)hp, sizeof(HDGRID)) == sizeof(HDGRID); } else { /* else assume we're creating it */ @@ -213,12 +216,13 @@ HDGRID *hproto; /* holodeck section grid */ fpos = hdfilen(fd); biglob(hp)->nrd = rtrunc = 0; for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) - if (hp->bi[n].nrd) + if (hp->bi[n].nrd) { if (hp->bi[n].fo+hp->bi[n].nrd*sizeof(RAYVAL) > fpos) { rtrunc += hp->bi[n].nrd; hp->bi[n].nrd = 0; } else biglob(hp)->nrd += hp->bi[n].nrd; + } if (rtrunc) { sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); @@ -246,8 +250,9 @@ int i; register int j; if (!hp->dirty++) { /* write smudge first time */ - if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0 - || write(hp->fd, (char *)&smudge, + if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), + SEEK_SET) < 0 || + write(hp->fd, (char *)&smudge, sizeof(BEAMI)) != sizeof(BEAMI)) error(SYSTEM, "seek/write error in hdmarkdirty"); hp->dirseg[0].s = i; @@ -261,7 +266,7 @@ int i; hp->dirseg[j].n = 1; break; } - copystruct(hp->dirseg+j, hp->dirseg+(j-1)); + *(hp->dirseg+j) = *(hp->dirseg+(j-1)); } do { /* check neighbors */ mindist = nbeams(hp); /* find closest */ @@ -283,7 +288,7 @@ int i; hp->dirseg[minpos].n - hp->dirseg[j].s; hp->dirty--; while (++j < hp->dirty) /* close the gap */ - copystruct(hp->dirseg+j, hp->dirseg+(j+1)); + *(hp->dirseg+j) = *(hp->dirseg+(j+1)); } while (mindist <= MINDIRSEL); } @@ -310,7 +315,7 @@ int all; errno = 0; /* write dirty segments */ for (j = 0; j < hp->dirty; j++) { if (lseek(hp->fd, biglob(hp)->fo + - (hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0) + (hp->dirseg[j].s-1)*sizeof(BEAMI), SEEK_SET) < 0) error(SYSTEM, "cannot seek on holodeck file"); n = hp->dirseg[j].n * sizeof(BEAMI); if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n) @@ -359,10 +364,10 @@ int fd; if (fd < 0) return(-1); if (fd >= nhdfragls || !hdfragl[fd].nlinks) { - if ((fpos = lseek(fd, (off_t)0, 1)) < 0) + if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) return(-1); - flen = lseek(fd, (off_t)0, 2); - lseek(fd, fpos, 0); + flen = lseek(fd, (off_t)0, SEEK_END); + lseek(fd, fpos, SEEK_SET); return(flen); } return(hdfragl[fd].flen); @@ -405,7 +410,7 @@ int nr; /* number of new rays desired */ int n; if (nr <= 0) return(NULL); - CHECK(i < 1 | i > nbeams(hp), + CHECK((i < 1) | (i > nbeams(hp)), CONSISTENCY, "bad beam index given to hdnewrays"); if (hp->bl[i] != NULL) hp->bl[i]->tick = hdclock; /* preempt swap */ @@ -417,7 +422,7 @@ int nr; /* number of new rays desired */ blglob(hp)->nrm += n; if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) { errno = 0; - if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) + if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) error(SYSTEM, "seek error on holodeck file"); n *= sizeof(RAYVAL); if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) @@ -446,7 +451,7 @@ register int i; { register int n; - CHECK(i < 1 | i > nbeams(hp), + CHECK((i < 1) | (i > nbeams(hp)), CONSISTENCY, "bad beam index given to hdgetbeam"); if (hp->bl[i] == NULL) { /* load from disk */ if (!(n = hp->bi[i].nrd)) @@ -456,7 +461,7 @@ register int i; hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam"); blglob(hp)->nrm += hp->bl[i]->nrm = n; errno = 0; - if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) + if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) error(SYSTEM, "seek error on holodeck file"); n *= sizeof(RAYVAL); if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) @@ -491,7 +496,7 @@ register HDBEAMI *hb1, *hb2; hdloadbeams(hb, n, bf) /* load a list of beams in optimal order */ register HDBEAMI *hb; /* list gets sorted by hdfilord() */ int n; /* list length */ -int (*bf)(); /* callback function (optional) */ +void (*bf)(); /* callback function (optional) */ { unsigned origcachesize, memuse; int bytesloaded, needbytes, bytes2free; @@ -500,7 +505,7 @@ int (*bf)(); /* callback function (optional) */ /* precheck consistency */ if (n <= 0) return; for (i = n; i--; ) - if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h)) + if (hb[i].h==NULL || (hb[i].b<1) | (hb[i].b>nbeams(hb[i].h))) error(CONSISTENCY, "bad beam in hdloadbeams"); /* sort list for optimal access */ qsort((void *)hb, n, sizeof(HDBEAMI), hdfilord); @@ -555,7 +560,7 @@ int i; if (++k >= f->nfrags) goto endloop; if (k > j) - copystruct(f->fi+j, f->fi+k); + *(f->fi+j) = *(f->fi+k); } endloop: f->nfrags = j; @@ -587,7 +592,7 @@ int i; f->fi[j].nrd = bi->nrd; break; } - copystruct(f->fi+j, f->fi+(j-1)); + *(f->fi+j) = *(f->fi+(j-1)); } /* coalesce adjacent fragments */ /* successors never empty */ @@ -621,7 +626,7 @@ register int32 *listsiz; register struct fraglist *f; register int i; - if (fd < 0 | fd >= nhdfragls || !(f = &hdfragl[fd])->nlinks) + if ((fd < 0) | (fd >= nhdfragls) || !(f = &hdfragl[fd])->nlinks) return(0); /* listless */ if (listlen != NULL) *listlen = f->nfrags; @@ -687,7 +692,7 @@ register int i; if (nrays) { /* get and write new fragment */ nfo = hdallocfrag(hp->fd, nrays); errno = 0; - if (lseek(hp->fd, nfo, 0) < 0) + if (lseek(hp->fd, nfo, SEEK_SET) < 0) error(SYSTEM, "cannot seek on holodeck file"); n = hp->bl[i]->nrm * sizeof(RAYVAL); if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { @@ -761,7 +766,7 @@ register int i; return(nchanged); } if (i == 0) { /* clobber entire holodeck */ - if (biglob(hp)->nrd == 0 & blglob(hp)->nrm == 0) + if ((biglob(hp)->nrd == 0) & (blglob(hp)->nrm == 0)) return(0); /* already empty */ nchanged = 0; nchanged = 0; @@ -817,7 +822,7 @@ register HOLO *hp; /* section we're adding from */ hb[j].b = i; break; } - copystruct(hb+j, hb+(j-1)); + *(hb+j) = *(hb+(j-1)); } } return(nents); /* return new list length */