7 |
|
* 9/30/97 GWLarson |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "copyright.h" |
11 |
+ |
|
12 |
+ |
#include <string.h> |
13 |
+ |
|
14 |
|
#include "holo.h" |
15 |
|
|
16 |
|
#ifndef CACHESIZE |
70 |
|
register HOLO *hp; |
71 |
|
int n; |
72 |
|
/* copy grid to temporary header */ |
73 |
< |
bcopy((void *)hproto, (void *)&hdhead, sizeof(HDGRID)); |
73 |
> |
memcpy((void *)&hdhead, (void *)hproto, sizeof(HDGRID)); |
74 |
|
/* compute grid vectors and sizes */ |
75 |
|
hdcompgrid(&hdhead); |
76 |
|
/* allocate header with directory */ |
78 |
|
if ((hp = (HOLO *)malloc(n)) == NULL) |
79 |
|
return(NULL); |
80 |
|
/* copy header information */ |
81 |
< |
copystruct(hp, &hdhead); |
81 |
> |
*hp = hdhead; |
82 |
|
/* allocate and clear beam list */ |
83 |
|
hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
84 |
|
if (hp->bl == NULL) { |
85 |
|
free((void *)hp); |
86 |
|
return(NULL); |
87 |
|
} |
88 |
< |
bzero((void *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
88 |
> |
memset((void *)hp->bl, '\0', (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
89 |
|
hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1); /* set blglob(hp) */ |
90 |
|
hp->fd = -1; |
91 |
|
hp->dirty = 0; |
92 |
|
hp->priv = NULL; |
93 |
|
/* clear beam directory */ |
94 |
< |
bzero((void *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); |
94 |
> |
memset((void *)hp->bi, '\0', (nbeams(hp)+1)*sizeof(BEAMI)); |
95 |
|
return(hp); /* all is well */ |
96 |
|
} |
97 |
|
|
127 |
|
if (fd >= nhdfragls) { |
128 |
|
hdfragl = (struct fraglist *)hdrealloc((char *)hdfragl, |
129 |
|
(fd+1)*sizeof(struct fraglist), "hdattach"); |
130 |
< |
bzero((void *)(hdfragl+nhdfragls), |
131 |
< |
(fd+1-nhdfragls)*sizeof(struct fraglist)); |
130 |
> |
memset((void *)(hdfragl+nhdfragls), |
131 |
> |
'\0', (fd+1-nhdfragls)*sizeof(struct fraglist)); |
132 |
|
nhdfragls = fd+1; |
133 |
|
} |
134 |
|
hdfragl[fd].nlinks++; |
143 |
|
hdrelease(fd) /* stop tracking file fragments for some section */ |
144 |
|
register int fd; |
145 |
|
{ |
146 |
< |
if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) |
146 |
> |
if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks) |
147 |
|
return; |
148 |
|
if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { |
149 |
|
free((void *)hdfragl[fd].fi); |
213 |
|
fpos = hdfilen(fd); |
214 |
|
biglob(hp)->nrd = rtrunc = 0; |
215 |
|
for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) |
216 |
< |
if (hp->bi[n].nrd) |
216 |
> |
if (hp->bi[n].nrd) { |
217 |
|
if (hp->bi[n].fo+hp->bi[n].nrd*sizeof(RAYVAL) > fpos) { |
218 |
|
rtrunc += hp->bi[n].nrd; |
219 |
|
hp->bi[n].nrd = 0; |
220 |
|
} else |
221 |
|
biglob(hp)->nrd += hp->bi[n].nrd; |
222 |
+ |
} |
223 |
|
if (rtrunc) { |
224 |
|
sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", |
225 |
|
rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); |
262 |
|
hp->dirseg[j].n = 1; |
263 |
|
break; |
264 |
|
} |
265 |
< |
copystruct(hp->dirseg+j, hp->dirseg+(j-1)); |
265 |
> |
*(hp->dirseg+j) = *(hp->dirseg+(j-1)); |
266 |
|
} |
267 |
|
do { /* check neighbors */ |
268 |
|
mindist = nbeams(hp); /* find closest */ |
284 |
|
hp->dirseg[minpos].n - hp->dirseg[j].s; |
285 |
|
hp->dirty--; |
286 |
|
while (++j < hp->dirty) /* close the gap */ |
287 |
< |
copystruct(hp->dirseg+j, hp->dirseg+(j+1)); |
287 |
> |
*(hp->dirseg+j) = *(hp->dirseg+(j+1)); |
288 |
|
} while (mindist <= MINDIRSEL); |
289 |
|
} |
290 |
|
|
406 |
|
int n; |
407 |
|
|
408 |
|
if (nr <= 0) return(NULL); |
409 |
< |
CHECK(i < 1 | i > nbeams(hp), |
409 |
> |
CHECK((i < 1) | (i > nbeams(hp)), |
410 |
|
CONSISTENCY, "bad beam index given to hdnewrays"); |
411 |
|
if (hp->bl[i] != NULL) |
412 |
|
hp->bl[i]->tick = hdclock; /* preempt swap */ |
434 |
|
hdfreefrag(hp, i); /* relinquish old fragment */ |
435 |
|
p = hdbray(hp->bl[i]) + hp->bl[i]->nrm; |
436 |
|
hp->bl[i]->nrm += nr; /* update in-core structure */ |
437 |
< |
bzero((void *)p, nr*sizeof(RAYVAL)); |
437 |
> |
memset((void *)p, '\0', nr*sizeof(RAYVAL)); |
438 |
|
blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */ |
439 |
|
return(p); /* point to new rays */ |
440 |
|
} |
447 |
|
{ |
448 |
|
register int n; |
449 |
|
|
450 |
< |
CHECK(i < 1 | i > nbeams(hp), |
450 |
> |
CHECK((i < 1) | (i > nbeams(hp)), |
451 |
|
CONSISTENCY, "bad beam index given to hdgetbeam"); |
452 |
|
if (hp->bl[i] == NULL) { /* load from disk */ |
453 |
|
if (!(n = hp->bi[i].nrd)) |
492 |
|
hdloadbeams(hb, n, bf) /* load a list of beams in optimal order */ |
493 |
|
register HDBEAMI *hb; /* list gets sorted by hdfilord() */ |
494 |
|
int n; /* list length */ |
495 |
< |
int (*bf)(); /* callback function (optional) */ |
495 |
> |
void (*bf)(); /* callback function (optional) */ |
496 |
|
{ |
497 |
|
unsigned origcachesize, memuse; |
498 |
|
int bytesloaded, needbytes, bytes2free; |
501 |
|
/* precheck consistency */ |
502 |
|
if (n <= 0) return; |
503 |
|
for (i = n; i--; ) |
504 |
< |
if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h)) |
504 |
> |
if (hb[i].h==NULL || (hb[i].b<1) | (hb[i].b>nbeams(hb[i].h))) |
505 |
|
error(CONSISTENCY, "bad beam in hdloadbeams"); |
506 |
|
/* sort list for optimal access */ |
507 |
|
qsort((void *)hb, n, sizeof(HDBEAMI), hdfilord); |
556 |
|
if (++k >= f->nfrags) |
557 |
|
goto endloop; |
558 |
|
if (k > j) |
559 |
< |
copystruct(f->fi+j, f->fi+k); |
559 |
> |
*(f->fi+j) = *(f->fi+k); |
560 |
|
} |
561 |
|
endloop: |
562 |
|
f->nfrags = j; |
588 |
|
f->fi[j].nrd = bi->nrd; |
589 |
|
break; |
590 |
|
} |
591 |
< |
copystruct(f->fi+j, f->fi+(j-1)); |
591 |
> |
*(f->fi+j) = *(f->fi+(j-1)); |
592 |
|
} |
593 |
|
/* coalesce adjacent fragments */ |
594 |
|
/* successors never empty */ |
622 |
|
register struct fraglist *f; |
623 |
|
register int i; |
624 |
|
|
625 |
< |
if (fd < 0 | fd >= nhdfragls || !(f = &hdfragl[fd])->nlinks) |
625 |
> |
if ((fd < 0) | (fd >= nhdfragls) || !(f = &hdfragl[fd])->nlinks) |
626 |
|
return(0); /* listless */ |
627 |
|
if (listlen != NULL) |
628 |
|
*listlen = f->nfrags; |
762 |
|
return(nchanged); |
763 |
|
} |
764 |
|
if (i == 0) { /* clobber entire holodeck */ |
765 |
< |
if (biglob(hp)->nrd == 0 & blglob(hp)->nrm == 0) |
765 |
> |
if ((biglob(hp)->nrd == 0) & (blglob(hp)->nrm == 0)) |
766 |
|
return(0); /* already empty */ |
767 |
|
nchanged = 0; |
768 |
|
nchanged = 0; |
818 |
|
hb[j].b = i; |
819 |
|
break; |
820 |
|
} |
821 |
< |
copystruct(hb+j, hb+(j-1)); |
821 |
> |
*(hb+j) = *(hb+(j-1)); |
822 |
|
} |
823 |
|
} |
824 |
|
return(nents); /* return new list length */ |