| 5 |
|
* Routines for loading and checking variables from file. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
< |
/* ==================================================================== |
| 9 |
< |
* The Radiance Software License, Version 1.0 |
| 10 |
< |
* |
| 11 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
| 12 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
| 13 |
< |
* |
| 14 |
< |
* Redistribution and use in source and binary forms, with or without |
| 15 |
< |
* modification, are permitted provided that the following conditions |
| 16 |
< |
* are met: |
| 17 |
< |
* |
| 18 |
< |
* 1. Redistributions of source code must retain the above copyright |
| 19 |
< |
* notice, this list of conditions and the following disclaimer. |
| 20 |
< |
* |
| 21 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
| 22 |
< |
* notice, this list of conditions and the following disclaimer in |
| 23 |
< |
* the documentation and/or other materials provided with the |
| 24 |
< |
* distribution. |
| 25 |
< |
* |
| 26 |
< |
* 3. The end-user documentation included with the redistribution, |
| 27 |
< |
* if any, must include the following acknowledgment: |
| 28 |
< |
* "This product includes Radiance software |
| 29 |
< |
* (http://radsite.lbl.gov/) |
| 30 |
< |
* developed by the Lawrence Berkeley National Laboratory |
| 31 |
< |
* (http://www.lbl.gov/)." |
| 32 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
| 33 |
< |
* if and wherever such third-party acknowledgments normally appear. |
| 34 |
< |
* |
| 35 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
| 36 |
< |
* and "The Regents of the University of California" must |
| 37 |
< |
* not be used to endorse or promote products derived from this |
| 38 |
< |
* software without prior written permission. For written |
| 39 |
< |
* permission, please contact [email protected]. |
| 40 |
< |
* |
| 41 |
< |
* 5. Products derived from this software may not be called "Radiance", |
| 42 |
< |
* nor may "Radiance" appear in their name, without prior written |
| 43 |
< |
* permission of Lawrence Berkeley National Laboratory. |
| 44 |
< |
* |
| 45 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 46 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 47 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 48 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
| 49 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 50 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 51 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 52 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 53 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 54 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 55 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 56 |
< |
* SUCH DAMAGE. |
| 57 |
< |
* ==================================================================== |
| 58 |
< |
* |
| 59 |
< |
* This software consists of voluntary contributions made by many |
| 60 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
| 61 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
| 62 |
< |
* <http://www.lbl.gov/>. |
| 63 |
< |
*/ |
| 8 |
> |
#include "copyright.h" |
| 9 |
|
|
| 10 |
|
#include <stdio.h> |
| 11 |
|
#include <stdlib.h> |
| 12 |
|
#include <ctype.h> |
| 13 |
+ |
|
| 14 |
+ |
#include "standard.h" |
| 15 |
|
#include "vars.h" |
| 16 |
|
|
| 17 |
|
#define NOCHAR 127 /* constant for character to delete */ |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
void |
| 23 |
< |
loadvars(rfname) /* load variables into vv from file */ |
| 24 |
< |
char *rfname; |
| 23 |
> |
loadvars( /* load variables into vv from file */ |
| 24 |
> |
const char *rfname |
| 25 |
> |
) |
| 26 |
|
{ |
| 27 |
|
FILE *fp; |
| 28 |
|
char buf[512]; |
| 29 |
< |
register char *cp; |
| 29 |
> |
char *cp; |
| 30 |
|
|
| 31 |
|
if (rfname == NULL) |
| 32 |
|
fp = stdin; |
| 54 |
|
quit(1); |
| 55 |
|
} |
| 56 |
|
} |
| 57 |
< |
fclose(fp); |
| 57 |
> |
if (fp != stdin) |
| 58 |
> |
fclose(fp); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
int |
| 63 |
< |
setvariable(ass, mv) /* assign variable according to string */ |
| 64 |
< |
register char *ass; |
| 65 |
< |
VARIABLE *(*mv)(); |
| 63 |
> |
setvariable( /* assign variable according to string */ |
| 64 |
> |
const char *ass, |
| 65 |
> |
VARIABLE *(*mv)(const char*) |
| 66 |
> |
) |
| 67 |
|
{ |
| 68 |
+ |
int quote = '\0'; |
| 69 |
|
char varname[32]; |
| 70 |
|
int n; |
| 71 |
< |
register char *cp; |
| 72 |
< |
register VARIABLE *vp; |
| 73 |
< |
register int i; |
| 71 |
> |
char *cp; |
| 72 |
> |
VARIABLE *vp; |
| 73 |
> |
int i; |
| 74 |
|
|
| 75 |
|
while (isspace(*ass)) /* skip leading space */ |
| 76 |
|
ass++; |
| 94 |
|
if (vp == NULL) |
| 95 |
|
return(-1); |
| 96 |
|
/* assign new value */ |
| 97 |
< |
if (i = vp->nass) { |
| 97 |
> |
if ( (i = vp->nass) ) { |
| 98 |
|
cp = vp->value; |
| 99 |
|
while (i--) |
| 100 |
|
while (*cp++) |
| 101 |
|
; |
| 102 |
|
i = cp - vp->value; |
| 103 |
< |
vp->value = (char *)realloc(vp->value, i+n+1); |
| 103 |
> |
vp->value = (char *)realloc((void *)vp->value, i+n+1); |
| 104 |
|
} else |
| 105 |
|
vp->value = (char *)malloc(n+1); |
| 106 |
|
if (vp->value == NULL) { |
| 107 |
|
perror(progname); |
| 108 |
|
quit(1); |
| 109 |
|
} |
| 110 |
< |
cp = vp->value+i; /* copy value, squeezing spaces */ |
| 110 |
> |
cp = vp->value+i; /* copy value */ |
| 111 |
|
*cp = *ass; |
| 112 |
|
for (i = 1; i <= n; i++) { |
| 113 |
|
if (ass[i] == NOCHAR) |
| 114 |
|
continue; |
| 115 |
< |
if (isspace(*cp)) |
| 116 |
< |
while (isspace(ass[i])) |
| 117 |
< |
i++; |
| 115 |
> |
if (quote) { /* don't change quoted parts */ |
| 116 |
> |
quote *= (ass[i] != quote); |
| 117 |
> |
} else { /* otherwise, squeeze spaces */ |
| 118 |
> |
if (isspace(*cp)) |
| 119 |
> |
while (isspace(ass[i])|(ass[i]==NOCHAR)) |
| 120 |
> |
i++; |
| 121 |
> |
if ((ass[i] == '"') | (ass[i] == '\'')) |
| 122 |
> |
quote = ass[i]; |
| 123 |
> |
} |
| 124 |
|
*++cp = ass[i]; |
| 125 |
|
} |
| 126 |
|
if (isspace(*cp)) /* remove trailing space */ |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
VARIABLE * |
| 133 |
< |
matchvar(nam) /* match a variable by its name */ |
| 134 |
< |
char *nam; |
| 133 |
> |
matchvar( /* match a variable by its name */ |
| 134 |
> |
const char *nam |
| 135 |
> |
) |
| 136 |
|
{ |
| 137 |
|
int n = strlen(nam); |
| 138 |
< |
register int i; |
| 138 |
> |
int i; |
| 139 |
|
|
| 140 |
|
for (i = 0; i < NVARS; i++) |
| 141 |
|
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
char * |
| 148 |
< |
nvalue(vn, n) /* return nth variable value */ |
| 149 |
< |
register int vn; |
| 150 |
< |
register int n; |
| 148 |
> |
nvalue( /* return nth variable value */ |
| 149 |
> |
int vn, |
| 150 |
> |
int n |
| 151 |
> |
) |
| 152 |
|
{ |
| 153 |
< |
register char *cp; |
| 153 |
> |
char *cp; |
| 154 |
|
|
| 155 |
< |
if (vval(vn) == NULL | n < 0 | n >= vdef(vn)) |
| 155 |
> |
if ((vval(vn) == NULL) | (n < 0) | (n >= vdef(vn))) |
| 156 |
|
return(NULL); |
| 157 |
|
cp = vval(vn); |
| 158 |
|
while (n--) |
| 163 |
|
|
| 164 |
|
|
| 165 |
|
void |
| 166 |
< |
checkvalues() /* check assignments */ |
| 166 |
> |
checkvalues(void) /* check assignments */ |
| 167 |
|
{ |
| 168 |
< |
register int i; |
| 168 |
> |
int i; |
| 169 |
|
|
| 170 |
|
for (i = 0; i < NVARS; i++) |
| 171 |
|
if (vv[i].fixval != NULL) |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
void |
| 177 |
< |
onevalue(vp) /* only one assignment for this variable */ |
| 178 |
< |
register VARIABLE *vp; |
| 177 |
> |
onevalue( /* only one assignment for this variable */ |
| 178 |
> |
VARIABLE *vp |
| 179 |
> |
) |
| 180 |
|
{ |
| 181 |
|
if (vp->nass < 2) |
| 182 |
|
return; |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
void |
| 194 |
< |
catvalues(vp) /* concatenate variable values */ |
| 195 |
< |
register VARIABLE *vp; |
| 194 |
> |
catvalues( /* concatenate variable values */ |
| 195 |
> |
VARIABLE *vp |
| 196 |
> |
) |
| 197 |
|
{ |
| 198 |
< |
register char *cp; |
| 198 |
> |
char *cp; |
| 199 |
|
|
| 200 |
|
if (vp->nass < 2) |
| 201 |
|
return; |
| 208 |
|
|
| 209 |
|
|
| 210 |
|
int |
| 211 |
< |
badmatch(tv, cv) /* case insensitive truncated comparison */ |
| 212 |
< |
register char *tv, *cv; |
| 211 |
> |
badmatch( /* case insensitive truncated comparison */ |
| 212 |
> |
char *tv, |
| 213 |
> |
char *cv |
| 214 |
> |
) |
| 215 |
|
{ |
| 216 |
|
if (!*tv) return(1); /* null string cannot match */ |
| 217 |
|
do |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
void |
| 226 |
< |
boolvalue(vp) /* check boolean for legal values */ |
| 227 |
< |
register VARIABLE *vp; |
| 226 |
> |
boolvalue( /* check boolean for legal values */ |
| 227 |
> |
VARIABLE *vp |
| 228 |
> |
) |
| 229 |
|
{ |
| 230 |
|
if (!vp->nass) return; |
| 231 |
|
onevalue(vp); |
| 244 |
|
|
| 245 |
|
|
| 246 |
|
void |
| 247 |
< |
qualvalue(vp) /* check qualitative var. for legal values */ |
| 248 |
< |
register VARIABLE *vp; |
| 247 |
> |
qualvalue( /* check qualitative var. for legal values */ |
| 248 |
> |
VARIABLE *vp |
| 249 |
> |
) |
| 250 |
|
{ |
| 251 |
|
if (!vp->nass) return; |
| 252 |
|
onevalue(vp); |
| 266 |
|
quit(1); |
| 267 |
|
} |
| 268 |
|
|
| 269 |
+ |
void |
| 270 |
+ |
strvalue( /* check for single (quoted) string value */ |
| 271 |
+ |
VARIABLE *vp |
| 272 |
+ |
) |
| 273 |
+ |
{ |
| 274 |
+ |
if (!vp->nass) return; |
| 275 |
+ |
onevalue(vp); |
| 276 |
+ |
if ((vp->value[0] == '"') | (vp->value[0] == '\'')) { |
| 277 |
+ |
char *cp = vp->value + strlen(vp->value+1); |
| 278 |
+ |
if ((cp != vp->value) & (*cp == vp->value[0])) { |
| 279 |
+ |
vp->value++; /* elide quotation marks */ |
| 280 |
+ |
*cp = '\0'; |
| 281 |
+ |
} |
| 282 |
+ |
} |
| 283 |
+ |
} |
| 284 |
|
|
| 285 |
+ |
|
| 286 |
|
void |
| 287 |
< |
intvalue(vp) /* check integer variable for legal values */ |
| 288 |
< |
register VARIABLE *vp; |
| 287 |
> |
intvalue( /* check integer variable for legal values */ |
| 288 |
> |
VARIABLE *vp |
| 289 |
> |
) |
| 290 |
|
{ |
| 291 |
|
if (!vp->nass) return; |
| 292 |
|
onevalue(vp); |
| 298 |
|
|
| 299 |
|
|
| 300 |
|
void |
| 301 |
< |
fltvalue(vp) /* check float variable for legal values */ |
| 302 |
< |
register VARIABLE *vp; |
| 301 |
> |
fltvalue( /* check float variable for legal values */ |
| 302 |
> |
VARIABLE *vp |
| 303 |
> |
) |
| 304 |
|
{ |
| 305 |
|
if (!vp->nass) return; |
| 306 |
|
onevalue(vp); |
| 312 |
|
|
| 313 |
|
|
| 314 |
|
void |
| 315 |
< |
printvars(fp) /* print variable values */ |
| 316 |
< |
register FILE *fp; |
| 315 |
> |
printvars( /* print variable values */ |
| 316 |
> |
FILE *fp |
| 317 |
> |
) |
| 318 |
|
{ |
| 319 |
|
int i, j, k, clipline; |
| 320 |
< |
register char *cp; |
| 320 |
> |
char *cp; |
| 321 |
|
|
| 322 |
|
for (i = 0; i < NVARS; i++) /* print each variable */ |
| 323 |
|
for (j = 0; j < vdef(i); j++) { /* print each assignment */ |