--- ray/src/common/loadvars.c 2003/02/22 02:07:22 2.9
+++ ray/src/common/loadvars.c 2025/06/07 05:09:45 2.24
@@ -1,70 +1,16 @@
#ifndef lint
-static const char RCSid[] = "$Id: loadvars.c,v 2.9 2003/02/22 02:07:22 greg Exp $";
+static const char RCSid[] = "$Id: loadvars.c,v 2.24 2025/06/07 05:09:45 greg Exp $";
#endif
/*
* Routines for loading and checking variables from file.
*/
-/* ====================================================================
- * The Radiance Software License, Version 1.0
- *
- * Copyright (c) 1990 - 2002 The Regents of the University of California,
- * through Lawrence Berkeley National Laboratory. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes Radiance software
- * (http://radsite.lbl.gov/)
- * developed by the Lawrence Berkeley National Laboratory
- * (http://www.lbl.gov/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
- * and "The Regents of the University of California" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact radiance@radsite.lbl.gov.
- *
- * 5. Products derived from this software may not be called "Radiance",
- * nor may "Radiance" appear in their name, without prior written
- * permission of Lawrence Berkeley National Laboratory.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of Lawrence Berkeley National Laboratory. For more
- * information on Lawrence Berkeley National Laboratory, please see
- * .
- */
+#include "copyright.h"
-#include
-#include
#include
+
+#include "standard.h"
+#include "paths.h"
#include "vars.h"
#define NOCHAR 127 /* constant for character to delete */
@@ -73,12 +19,13 @@ extern char *fgetline();
void
-loadvars(rfname) /* load variables into vv from file */
-char *rfname;
+loadvars( /* load variables into vv from file */
+ const char *rfname
+)
{
FILE *fp;
char buf[512];
- register char *cp;
+ char *cp;
if (rfname == NULL)
fp = stdin;
@@ -106,20 +53,23 @@ char *rfname;
quit(1);
}
}
- fclose(fp);
+ if (fp != stdin)
+ fclose(fp);
}
int
-setvariable(ass, mv) /* assign variable according to string */
-register char *ass;
-VARIABLE *(*mv)();
+setvariable( /* assign variable according to string */
+ const char *ass,
+ VARIABLE *(*mv)(const char*)
+)
{
+ int quote = '\0';
char varname[32];
int n;
- register char *cp;
- register VARIABLE *vp;
- register int i;
+ char *cp;
+ VARIABLE *vp;
+ int i;
while (isspace(*ass)) /* skip leading space */
ass++;
@@ -143,27 +93,33 @@ VARIABLE *(*mv)();
if (vp == NULL)
return(-1);
/* assign new value */
- if (i = vp->nass) {
+ if ( (i = vp->nass) ) {
cp = vp->value;
while (i--)
while (*cp++)
;
i = cp - vp->value;
- vp->value = (char *)realloc(vp->value, i+n+1);
+ vp->value = (char *)realloc((void *)vp->value, i+n+1);
} else
vp->value = (char *)malloc(n+1);
if (vp->value == NULL) {
perror(progname);
quit(1);
}
- cp = vp->value+i; /* copy value, squeezing spaces */
+ cp = vp->value+i; /* copy value */
*cp = *ass;
for (i = 1; i <= n; i++) {
if (ass[i] == NOCHAR)
continue;
- if (isspace(*cp))
- while (isspace(ass[i]))
- i++;
+ if (quote) { /* don't change quoted parts */
+ quote *= (ass[i] != quote);
+ } else { /* otherwise, squeeze spaces */
+ if (isspace(*cp))
+ while (isspace(ass[i])|(ass[i]==NOCHAR))
+ i++;
+ if ((ass[i] == '"') | (ass[i] == '\''))
+ quote = ass[i];
+ }
*++cp = ass[i];
}
if (isspace(*cp)) /* remove trailing space */
@@ -173,11 +129,12 @@ VARIABLE *(*mv)();
VARIABLE *
-matchvar(nam) /* match a variable by its name */
-char *nam;
+matchvar( /* match a variable by its name */
+ const char *nam
+)
{
int n = strlen(nam);
- register int i;
+ int i;
for (i = 0; i < NVARS; i++)
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
@@ -187,13 +144,14 @@ char *nam;
char *
-nvalue(vn, n) /* return nth variable value */
-register int vn;
-register int n;
+nvalue( /* return nth variable value */
+ int vn,
+ int n
+)
{
- register char *cp;
+ char *cp;
- if (vval(vn) == NULL | n < 0 | n >= vdef(vn))
+ if ((vval(vn) == NULL) | (n < 0) | (n >= vdef(vn)))
return(NULL);
cp = vval(vn);
while (n--)
@@ -204,9 +162,9 @@ register int n;
void
-checkvalues() /* check assignments */
+checkvalues(void) /* check assignments */
{
- register int i;
+ int i;
for (i = 0; i < NVARS; i++)
if (vv[i].fixval != NULL)
@@ -215,8 +173,9 @@ checkvalues() /* check assignments */
void
-onevalue(vp) /* only one assignment for this variable */
-register VARIABLE *vp;
+onevalue( /* only one assignment for this variable */
+ VARIABLE *vp
+)
{
if (vp->nass < 2)
return;
@@ -231,10 +190,11 @@ register VARIABLE *vp;
void
-catvalues(vp) /* concatenate variable values */
-register VARIABLE *vp;
+catvalues( /* concatenate variable values */
+ VARIABLE *vp
+)
{
- register char *cp;
+ char *cp;
if (vp->nass < 2)
return;
@@ -247,8 +207,10 @@ register VARIABLE *vp;
int
-badmatch(tv, cv) /* case insensitive truncated comparison */
-register char *tv, *cv;
+badmatch( /* case insensitive truncated comparison */
+ char *tv,
+ char *cv
+)
{
if (!*tv) return(1); /* null string cannot match */
do
@@ -260,8 +222,9 @@ register char *tv, *cv;
void
-boolvalue(vp) /* check boolean for legal values */
-register VARIABLE *vp;
+boolvalue( /* check boolean for legal values */
+ VARIABLE *vp
+)
{
if (!vp->nass) return;
onevalue(vp);
@@ -280,8 +243,9 @@ register VARIABLE *vp;
void
-qualvalue(vp) /* check qualitative var. for legal values */
-register VARIABLE *vp;
+qualvalue( /* check qualitative var. for legal values */
+ VARIABLE *vp
+)
{
if (!vp->nass) return;
onevalue(vp);
@@ -301,10 +265,27 @@ register VARIABLE *vp;
quit(1);
}
+void
+strvalue( /* check for single (quoted) string value */
+ VARIABLE *vp
+)
+{
+ if (!vp->nass) return;
+ onevalue(vp);
+ if ((vp->value[0] == '"') | (vp->value[0] == '\'')) {
+ char *cp = vp->value + strlen(vp->value+1);
+ if ((cp != vp->value) & (*cp == vp->value[0])) {
+ vp->value++; /* elide quotation marks */
+ *cp = '\0';
+ }
+ }
+}
+
void
-intvalue(vp) /* check integer variable for legal values */
-register VARIABLE *vp;
+intvalue( /* check integer variable for legal values */
+ VARIABLE *vp
+)
{
if (!vp->nass) return;
onevalue(vp);
@@ -316,8 +297,9 @@ register VARIABLE *vp;
void
-fltvalue(vp) /* check float variable for legal values */
-register VARIABLE *vp;
+fltvalue( /* check float variable for legal values */
+ VARIABLE *vp
+)
{
if (!vp->nass) return;
onevalue(vp);
@@ -328,17 +310,35 @@ register VARIABLE *vp;
}
+int
+singlevar( /* assigned single value? */
+ VARIABLE *vp
+)
+{
+ if (vp->fixval == catvalues)
+ return(0);
+
+ return((vp->fixval == strvalue) |
+ (vp->fixval == fltvalue) |
+ (vp->fixval == intvalue) |
+ (vp->fixval == qualvalue) |
+ (vp->fixval == boolvalue));
+}
+
void
-printvars(fp) /* print variable values */
-register FILE *fp;
+printvars( /* print variable values */
+ FILE *fp
+)
{
int i, j, k, clipline;
- register char *cp;
+ char *cp;
for (i = 0; i < NVARS; i++) /* print each variable */
for (j = 0; j < vdef(i); j++) { /* print each assignment */
fputs(vnam(i), fp);
- fputs("= ", fp);
+ fputc('=', fp);
+ if (!singlevar(&vv[i]))
+ fputc(' ', fp);
k = clipline = ( vv[i].fixval == catvalues ? 64 : 236 )
- strlen(vnam(i)) ;
cp = nvalue(i, j);