--- ray/src/hd/rhoptimize.c 1999/02/01 09:56:18 3.7 +++ ray/src/hd/rhoptimize.c 2003/07/27 22:12:02 3.15 @@ -1,19 +1,18 @@ -/* Copyright (c) 1999 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhoptimize.c,v 3.15 2003/07/27 22:12:02 schorsch Exp $"; #endif - /* * Optimize holodeck for quick access. * * 11/4/98 Greg Ward Larson */ -#include "holo.h" - #include +#include +#include "rtprocess.h" /* getpid() */ +#include "holo.h" + #ifndef BKBSIZE #define BKBSIZE 256 /* beam clump size (kilobytes) */ #endif @@ -22,8 +21,6 @@ char *progname; char tempfile[128]; int dupchecking = 0; -extern char *rindex(); -extern int quit(); extern long rhinitcopy(); @@ -41,7 +38,7 @@ char *argv[]; dupchecking++; argv++; argc--; } - if (argc < 1 | argc > 2) { + if ((argc < 1) | (argc > 2)) { fprintf(stderr, "Usage: %s [-u] input.hdk [output.hdk]\n", progname); exit(1); @@ -56,7 +53,7 @@ char *argv[]; error(SYSTEM, errmsg); } strcpy(tempfile, inpname); - if ((outname = rindex(tempfile, '/')) != NULL) + if ((outname = strrchr(tempfile, '/')) != NULL) outname++; else outname = tempfile; @@ -68,14 +65,14 @@ char *argv[]; lastopos = 0L; /* copy sections one by one */ while (nextipos != 0L) { /* set input position; get next */ - lseek(hdfd[0], nextipos, 0); + lseek(hdfd[0], (off_t)nextipos, 0); read(hdfd[0], (char *)&nextipos, sizeof(nextipos)); /* get output position; set last */ - thisopos = lseek(hdfd[1], 0L, 2); + thisopos = lseek(hdfd[1], (off_t)0, 2); if (lastopos > 0L) { - lseek(hdfd[1], lastopos, 0); + lseek(hdfd[1], (off_t)lastopos, 0); write(hdfd[1], (char *)&thisopos, sizeof(thisopos)); - lseek(hdfd[1], 0L, 2); + lseek(hdfd[1], (off_t)0, 2); } lastopos = thisopos; thisopos = 0L; /* write place holder */ @@ -107,6 +104,10 @@ char *infn, *outfn; sprintf(errmsg, "cannot open \"%s\" for reading", infn); error(SYSTEM, errmsg); } + if (access(outfn, F_OK) == 0) { + sprintf(errmsg, "output file \"%s\" already exists!", outfn); + error(USER, errmsg); + } if ((outfp = fopen(outfn, "w+")) == NULL) { sprintf(errmsg, "cannot open \"%s\" for writing", outfn); error(SYSTEM, errmsg); @@ -157,9 +158,9 @@ int n; rva[i].r[1][0]==rva[j].r[1][0] && rva[i].r[1][1]==rva[j].r[1][1] ) { n--; /* swap duplicate with end */ - copystruct(&rtmp, rva+n); - copystruct(rva+n, rva+i); - copystruct(rva+i, &rtmp); + rtmp = *(rva+n); + *(rva+n) = *(rva+i); + *(rva+i) = rtmp; i--; /* recheck one we swapped */ } return(n); @@ -172,7 +173,7 @@ static int bpcmp(b1p, b2p) /* compare beam positions on disk */ int *b1p, *b2p; { - register long pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; + register off_t pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; if (pdif < 0L) return(-1); return(pdif > 0L); @@ -190,13 +191,13 @@ int *bq, nb; int n; beamdir = hp->bi; /* sort based on file position */ - qsort((char *)bq, nb, sizeof(*bq), bpcmp); + qsort((void *)bq, nb, sizeof(*bq), bpcmp); /* transfer and free each beam */ for (i = 0; i < nb; i++) { bp = hdgetbeam(hp, bq[i]); DCHECK(bp==NULL, CONSISTENCY, "empty beam in xferclump"); n = dupchecking ? nuniq(hdbray(bp),bp->nrm) : bp->nrm; - bcopy((char *)hdbray(bp), (char *)hdnewrays(hout,bq[i],n), + memcpy((void *)hdnewrays(hout,bq[i],n),(void *)hdbray(bp), n*sizeof(RAYVAL)); hdfreebeam(hp, bq[i]); } @@ -220,6 +221,7 @@ int ifd, ofd; } +void eputs(s) /* put error message to stderr */ register char *s; { @@ -239,6 +241,7 @@ register char *s; } +void quit(code) /* exit the program gracefully */ int code; {