--- ray/src/hd/rhcopy.c 2003/06/26 00:58:10 3.17 +++ ray/src/hd/rhcopy.c 2017/05/03 18:05:15 3.28 @@ -1,10 +1,12 @@ #ifndef lint -static const char RCSid[] = "$Id: rhcopy.c,v 3.17 2003/06/26 00:58:10 schorsch Exp $"; +static const char RCSid[] = "$Id: rhcopy.c,v 3.28 2017/05/03 18:05:15 greg Exp $"; #endif /* * Copy data into a holodeck file */ +#include "platform.h" +#include "rterror.h" #include "holo.h" #include "view.h" @@ -20,10 +22,29 @@ char obstr, unobstr; /* flag pointer values */ char *progname; /* global argv[0] */ +struct phead { + VIEW vw; + double expos; + short gotview; + short badfmt; + short altprims; +}; +static int openholo(char *fname, int append); +static void addray(FVECT ro, FVECT rd, double d, COLR cv); +static gethfunc holheadline; +static int bpcmp(const void *b1p, const void *b2p); +static int addclump(HOLO *hp, int *bq, int nb); +static void addholo(char *hdf); +static gethfunc picheadline; +static void addpicz(char *pcf, char *zbf); -main(argc, argv) -int argc; -char *argv[]; + + +int +main( + int argc, + char *argv[] +) { int i; @@ -64,7 +85,7 @@ char *argv[]; userr: fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n", progname); - fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n", + fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.hdr inp1.zbf ..\n", progname); exit(1); } @@ -74,12 +95,14 @@ userr: #define H_OBST 02 #define H_OBSF 04 -int -holheadline(s, hf) /* check holodeck header line */ -register char *s; -int *hf; +static int +holheadline( /* check holodeck header line */ + register char *s, + void *vhf +) { char fmt[32]; + int *hf = vhf; if (formatval(fmt, s)) { if (strcmp(fmt, HOLOFMT)) @@ -91,9 +114,9 @@ int *hf; if (!strncmp(s, "OBSTRUCTIONS=", 13)) { s += 13; while (*s == ' ') s++; - if (*s == 't' | *s == 'T') + if ((*s == 't') | (*s == 'T')) *hf |= H_OBST; - else if (*s == 'f' | *s == 'F') + else if ((*s == 'f') | (*s == 'F')) *hf |= H_OBSF; else error(WARNING, "bad OBSTRUCTIONS value in holodeck"); @@ -103,14 +126,15 @@ int *hf; } int -openholo(fname, append) /* open existing holodeck file for i/o */ -char *fname; -int append; +openholo( /* open existing holodeck file for i/o */ + char *fname, + int append +) { FILE *fp; int fd; int hflags = 0; - long nextloc; + off_t nextloc; int n; /* open holodeck file */ if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) { @@ -119,7 +143,7 @@ int append; error(SYSTEM, errmsg); } /* check header and magic number */ - if (getheader(fp, holheadline, (char *)&hflags) < 0 || + if (getheader(fp, holheadline, &hflags) < 0 || hflags&H_BADF || getw(fp) != HOLOMAGIC) { sprintf(errmsg, "file \"%s\" not in holodeck format", fname); error(USER, errmsg); @@ -128,7 +152,7 @@ int append; nextloc = ftell(fp); /* get stdio position */ fclose(fp); /* done with stdio */ for (n = 0; nextloc > 0L; n++) { /* initialize each section */ - lseek(fd, (off_t)nextloc, 0); + lseek(fd, nextloc, SEEK_SET); read(fd, (char *)&nextloc, sizeof(nextloc)); hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : hflags&H_OBSF ? &unobstr : (char *)NULL; @@ -141,15 +165,18 @@ int append; #undef H_OBSF -addray(ro, rd, d, cv) /* add a ray to our output holodeck */ -FVECT ro, rd; -double d; -COLR cv; +void +addray( /* add a ray to our output holodeck */ + FVECT ro, + FVECT rd, + double d, + COLR cv +) { int sn, bi, n; register HOLO *hp; GCOORD gc[2]; - BYTE rr[2][2]; + uby8 rr[2][2]; BEAM *bp; double d0, d1; unsigned dc; @@ -191,10 +218,12 @@ COLR cv; static BEAMI *beamdir; static int -bpcmp(b1p, b2p) /* compare beam positions on disk */ -int *b1p, *b2p; +bpcmp( /* compare beam positions on disk */ + const void *b1p, + const void *b2p +) { - register off_t pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; + register off_t pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo; if (pdif > 0L) return(1); if (pdif < 0L) return(-1); @@ -202,9 +231,11 @@ int *b1p, *b2p; } static int -addclump(hp, bq, nb) /* transfer the given clump and free */ -HOLO *hp; -int *bq, nb; +addclump( /* transfer the given clump and free */ + HOLO *hp, + int *bq, + int nb +) { GCOORD gc[2]; FVECT ro, rd; @@ -234,8 +265,11 @@ int *bq, nb; return(0); } -addholo(hdf) /* add a holodeck file */ -char *hdf; + +void +addholo( /* add a holodeck file */ + char *hdf +) { int fd; /* open the holodeck for reading */ @@ -251,21 +285,15 @@ char *hdf; } -struct phead { - VIEW vw; - double expos; - short gotview; - short badfmt; - short altprims; -}; - -int -picheadline(s, ph) /* process picture header line */ -char *s; -struct phead *ph; +static int +picheadline( /* process picture header line */ + char *s, + void *vph +) { char fmt[32]; + struct phead *ph = vph; if (formatval(fmt, s)) { ph->badfmt = strcmp(fmt, COLRFMT); @@ -287,8 +315,11 @@ struct phead *ph; } -addpicz(pcf, zbf) /* add a picture + depth-buffer */ -char *pcf, *zbf; +void +addpicz( /* add a picture + depth-buffer */ + char *pcf, + char *zbf +) { FILE *pfp; int zfd; @@ -314,10 +345,10 @@ char *pcf, *zbf; error(SYSTEM, pcf); } /* load picture header */ - copystruct(&phd.vw, &stdview); + phd.vw = stdview; phd.expos = 1.0; phd.badfmt = phd.gotview = phd.altprims = 0; - if (getheader(pfp, picheadline, (char *)&phd) < 0 || + if (getheader(pfp, picheadline, &phd) < 0 || phd.badfmt || !fgetsresolu(&prs, pfp)) { sprintf(errmsg, "bad format for picture file \"%s\"", pcf); error(USER, errmsg); @@ -328,16 +359,16 @@ char *pcf, *zbf; error(USER, errmsg); } if (phd.altprims) { - sprintf(errmsg, "ignoring primary values in picture \"%s\"", + sprintf(errmsg, "ignoring color primaries in picture \"%s\"", pcf); error(WARNING, errmsg); } /* figure out what to do about exposure */ - if (phd.expos < 0.99 | phd.expos > 1.01) { + if ((phd.expos < 0.99) | (phd.expos > 1.01)) { emult = -log(phd.expos)/log(2.); eshft = emult >= 0. ? emult+.5 : emult-.5; emult -= (double)eshft; - if (emult <= 0.01 & emult >= -0.01) + if ((emult <= 0.01) & (emult >= -0.01)) emult = -1.; else { emult = 1./phd.expos; @@ -350,7 +381,7 @@ char *pcf, *zbf; /* allocate buffers */ cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR)); zscn = (float *)malloc(scanlen(&prs)*sizeof(float)); - if (cscn == NULL | zscn == NULL) + if ((cscn == NULL) | (zscn == NULL)) error(SYSTEM, "out of memory in addpicz"); /* read and process each scanline */ for (j = 0; j < numscans(&prs); j++) { @@ -393,8 +424,9 @@ char *pcf, *zbf; void -eputs(s) /* put error message to stderr */ -register char *s; +eputs( /* put error message to stderr */ + register char *s +) { static int midline = 0; @@ -413,8 +445,9 @@ register char *s; void -quit(code) /* exit the program gracefully */ -int code; +quit( /* exit the program gracefully */ + int code +) { hdsync(NULL, 1); /* write out any buffered data */ exit(code);