--- ray/src/rt/data.c 1991/12/19 14:54:58 2.2 +++ ray/src/rt/data.c 1992/11/22 10:02:57 2.5 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -23,9 +23,9 @@ extern char *fgetword(); extern char *libpath; /* library search path */ -static DATARRAY *dlist = NULL; /* data array list */ +static DATARRAY *dlist = NULL; /* data array list */ -static DATARRAY *plist = NULL; /* picture list */ +static DATARRAY *plist = NULL; /* picture list */ DATARRAY * @@ -45,7 +45,7 @@ char *dname; /* * If we haven't loaded the data already, we will look - * for it in the directorys specified by the library path. + * for it in the directories specified by the library path. * * The file has the following format: * @@ -139,14 +139,13 @@ scanerr: } -static double inpaspect; /* aspect ratio of input picture */ - static -headaspect(s) /* check string for aspect ratio */ +headaspect(s, iap) /* check string for aspect ratio */ char *s; +double *iap; { if (isaspect(s)) - inpaspect *= aspectval(s); + *iap *= aspectval(s); } @@ -155,11 +154,12 @@ getpict(pname) /* get picture pname */ char *pname; { extern char *libpath; + double inpaspect; char *pfname; FILE *fp; COLOR *scanin; int sl, ns; - RESOLU inpres; + RESOLU inpres; FLOAT loc[2]; int y; register int x, i; @@ -184,9 +184,12 @@ char *pname; sprintf(errmsg, "cannot open picture file \"%s\"", pfname); error(SYSTEM, errmsg); } +#ifdef MSDOS + setmode(fileno(fp), O_BINARY); +#endif /* get dimensions */ inpaspect = 1.0; - getheader(fp, headaspect); + getheader(fp, headaspect, &inpaspect); if (!fgetsresolu(&inpres, fp)) goto readerr; for (i = 0; i < 3; i++) { @@ -245,57 +248,59 @@ readerr: freedata(dname) /* free memory associated with dname */ char *dname; { + DATARRAY head; register DATARRAY *dp, *dpl; register int i; - for (dpl = NULL, dp = dlist; dp != NULL; dpl = dp, dp = dp->next) - if (!strcmp(dname, dp->name)) { - if (dpl == NULL) - dlist = dp->next; - else - dpl->next = dp->next; + head.next = dlist; + dpl = &head; + while ((dp = dpl->next) != NULL) + if (dname == NULL || !strcmp(dname, dp->name)) { + dpl->next = dp->next; free((char *)dp->arr); for (i = 0; i < dp->nd; i++) if (dp->dim[i].p != NULL) free((char *)dp->dim[i].p); freestr(dp->name); free((char *)dp); - return; - } + } else + dpl = dp; + dlist = head.next; } freepict(pname) /* free memory associated with pname */ char *pname; { + DATARRAY head; register DATARRAY *pp, *ppl; - for (ppl = NULL, pp = plist; pp != NULL; ppl = pp, pp = pp->next) - if (!strcmp(pname, pp->name)) { - if (ppl == NULL) - plist = pp->next; - else - ppl->next = pp->next; + head.next = plist; + ppl = &head; + while ((pp = ppl->next) != NULL) + if (pname == NULL || !strcmp(pname, pp->name)) { + ppl->next = pp->next; free((char *)pp[0].arr); free((char *)pp[1].arr); free((char *)pp[2].arr); freestr(pp[0].name); free((char *)pp); - return; - } + } else + ppl = pp; + plist = head.next; } double datavalue(dp, pt) /* interpolate data value at a point */ register DATARRAY *dp; -double *pt; +double *pt; { DATARRAY sd; int asize; int lower, upper; register int i; - double x, y, y0, y1; + double x, y, y0, y1; /* set up dimensions for recursion */ sd.nd = dp->nd - 1; asize = 1;