| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
#include "rholo.h" |
| 12 |
+ |
#include <sys/types.h> |
| 13 |
|
|
| 14 |
|
#ifndef NFRAG2CHUNK |
| 15 |
|
#define NFRAG2CHUNK 4096 /* number of fragments to start chunking */ |
| 24 |
|
|
| 25 |
|
#define rchunk(n) (((n)+(RPACKSIZ/2))/RPACKSIZ) |
| 26 |
|
|
| 27 |
+ |
extern time_t time(); |
| 28 |
+ |
|
| 29 |
|
static PACKHEAD *complist=NULL; /* list of beams to compute */ |
| 30 |
|
static int complen=0; /* length of complist */ |
| 31 |
|
static int listpos=0; /* current list position for next_packet */ |
| 41 |
|
register long c; |
| 42 |
|
/* first check desired quantities */ |
| 43 |
|
if (chunky) |
| 44 |
< |
c = rchunk(b1->nr)*(rchunk(b0->nc)+1) - |
| 45 |
< |
rchunk(b0->nr)*(rchunk(b1->nc)+1); |
| 44 |
> |
c = rchunk(b1->nr)*(rchunk(b0->nc)+1L) - |
| 45 |
> |
rchunk(b0->nr)*(rchunk(b1->nc)+1L); |
| 46 |
|
else |
| 47 |
< |
c = b1->nr*(b0->nc+1) - b0->nr*(b1->nc+1); |
| 48 |
< |
if (c) return(c); |
| 47 |
> |
c = b1->nr*(b0->nc+1L) - b0->nr*(b1->nc+1L); |
| 48 |
> |
if (c > 0) return(1); |
| 49 |
> |
if (c < 0) return(-1); |
| 50 |
|
/* only one file, so skip the following: */ |
| 51 |
|
#if 0 |
| 52 |
|
/* next, check file descriptors */ |
| 262 |
|
free((char *)complist); |
| 263 |
|
done_packets(flush_queue()); |
| 264 |
|
} |
| 265 |
+ |
/* reseed random number generator */ |
| 266 |
+ |
srandom(time(NULL)); |
| 267 |
|
/* allocate beam list */ |
| 268 |
|
complen = 0; |
| 269 |
|
for (j = 0; hdlist[j] != NULL; j++) |
| 342 |
|
chunky++; /* use "chunky" comparison */ |
| 343 |
|
lastin = -1; /* need to re-sort list */ |
| 344 |
|
} |
| 345 |
+ |
#ifdef DEBUG |
| 346 |
+ |
else |
| 347 |
+ |
fprintf(stderr, "sortcomplist: %d fragments\n", |
| 348 |
+ |
listlen); |
| 349 |
+ |
#endif |
| 350 |
|
if (lastin < 0 || listpos*4 >= complen*3) |
| 351 |
|
qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); |
| 352 |
|
else if (listpos) { /* else sort and merge sublist */ |
| 402 |
|
p->nr = complist[listpos].nr - p->nc; |
| 403 |
|
if (p->nr <= 0) |
| 404 |
|
return(0); |
| 405 |
< |
#ifdef DEBUG |
| 406 |
< |
if (n < 1 | n > RPACKSIZ) |
| 396 |
< |
error(CONSISTENCY, "next_packet called with bad n value"); |
| 397 |
< |
#endif |
| 405 |
> |
DCHECK(n < 1 | n > RPACKSIZ, |
| 406 |
> |
CONSISTENCY, "next_packet called with bad n value"); |
| 407 |
|
if (p->nr > n) |
| 408 |
|
p->nr = n; |
| 409 |
|
complist[listpos].nc += p->nr; /* find where this one would go */ |