| 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 |
> |
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 |
> |
char *ass, |
| 65 |
> |
VARIABLE *(*mv)(char*) |
| 66 |
> |
) |
| 67 |
|
{ |
| 68 |
|
char varname[32]; |
| 69 |
|
int n; |
| 70 |
< |
register char *cp; |
| 71 |
< |
register VARIABLE *vp; |
| 72 |
< |
register int i; |
| 70 |
> |
char *cp; |
| 71 |
> |
VARIABLE *vp; |
| 72 |
> |
int i; |
| 73 |
|
|
| 74 |
|
while (isspace(*ass)) /* skip leading space */ |
| 75 |
|
ass++; |
| 93 |
|
if (vp == NULL) |
| 94 |
|
return(-1); |
| 95 |
|
/* assign new value */ |
| 96 |
< |
if (i = vp->nass) { |
| 96 |
> |
if ( (i = vp->nass) ) { |
| 97 |
|
cp = vp->value; |
| 98 |
|
while (i--) |
| 99 |
|
while (*cp++) |
| 100 |
|
; |
| 101 |
|
i = cp - vp->value; |
| 102 |
< |
vp->value = (char *)realloc(vp->value, i+n+1); |
| 102 |
> |
vp->value = (char *)realloc((void *)vp->value, i+n+1); |
| 103 |
|
} else |
| 104 |
|
vp->value = (char *)malloc(n+1); |
| 105 |
|
if (vp->value == NULL) { |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
VARIABLE * |
| 126 |
< |
matchvar(nam) /* match a variable by its name */ |
| 127 |
< |
char *nam; |
| 126 |
> |
matchvar( /* match a variable by its name */ |
| 127 |
> |
char *nam |
| 128 |
> |
) |
| 129 |
|
{ |
| 130 |
|
int n = strlen(nam); |
| 131 |
< |
register int i; |
| 131 |
> |
int i; |
| 132 |
|
|
| 133 |
|
for (i = 0; i < NVARS; i++) |
| 134 |
|
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) |
| 138 |
|
|
| 139 |
|
|
| 140 |
|
char * |
| 141 |
< |
nvalue(vn, n) /* return nth variable value */ |
| 142 |
< |
register int vn; |
| 143 |
< |
register int n; |
| 141 |
> |
nvalue( /* return nth variable value */ |
| 142 |
> |
int vn, |
| 143 |
> |
int n |
| 144 |
> |
) |
| 145 |
|
{ |
| 146 |
< |
register char *cp; |
| 146 |
> |
char *cp; |
| 147 |
|
|
| 148 |
< |
if (vval(vn) == NULL | n < 0 | n >= vdef(vn)) |
| 148 |
> |
if ((vval(vn) == NULL) | (n < 0) | (n >= vdef(vn))) |
| 149 |
|
return(NULL); |
| 150 |
|
cp = vval(vn); |
| 151 |
|
while (n--) |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
void |
| 159 |
< |
checkvalues() /* check assignments */ |
| 159 |
> |
checkvalues(void) /* check assignments */ |
| 160 |
|
{ |
| 161 |
< |
register int i; |
| 161 |
> |
int i; |
| 162 |
|
|
| 163 |
|
for (i = 0; i < NVARS; i++) |
| 164 |
|
if (vv[i].fixval != NULL) |
| 167 |
|
|
| 168 |
|
|
| 169 |
|
void |
| 170 |
< |
onevalue(vp) /* only one assignment for this variable */ |
| 171 |
< |
register VARIABLE *vp; |
| 170 |
> |
onevalue( /* only one assignment for this variable */ |
| 171 |
> |
VARIABLE *vp |
| 172 |
> |
) |
| 173 |
|
{ |
| 174 |
|
if (vp->nass < 2) |
| 175 |
|
return; |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
void |
| 187 |
< |
catvalues(vp) /* concatenate variable values */ |
| 188 |
< |
register VARIABLE *vp; |
| 187 |
> |
catvalues( /* concatenate variable values */ |
| 188 |
> |
VARIABLE *vp |
| 189 |
> |
) |
| 190 |
|
{ |
| 191 |
< |
register char *cp; |
| 191 |
> |
char *cp; |
| 192 |
|
|
| 193 |
|
if (vp->nass < 2) |
| 194 |
|
return; |
| 201 |
|
|
| 202 |
|
|
| 203 |
|
int |
| 204 |
< |
badmatch(tv, cv) /* case insensitive truncated comparison */ |
| 205 |
< |
register char *tv, *cv; |
| 204 |
> |
badmatch( /* case insensitive truncated comparison */ |
| 205 |
> |
char *tv, |
| 206 |
> |
char *cv |
| 207 |
> |
) |
| 208 |
|
{ |
| 209 |
|
if (!*tv) return(1); /* null string cannot match */ |
| 210 |
|
do |
| 216 |
|
|
| 217 |
|
|
| 218 |
|
void |
| 219 |
< |
boolvalue(vp) /* check boolean for legal values */ |
| 220 |
< |
register VARIABLE *vp; |
| 219 |
> |
boolvalue( /* check boolean for legal values */ |
| 220 |
> |
VARIABLE *vp |
| 221 |
> |
) |
| 222 |
|
{ |
| 223 |
|
if (!vp->nass) return; |
| 224 |
|
onevalue(vp); |
| 237 |
|
|
| 238 |
|
|
| 239 |
|
void |
| 240 |
< |
qualvalue(vp) /* check qualitative var. for legal values */ |
| 241 |
< |
register VARIABLE *vp; |
| 240 |
> |
qualvalue( /* check qualitative var. for legal values */ |
| 241 |
> |
VARIABLE *vp |
| 242 |
> |
) |
| 243 |
|
{ |
| 244 |
|
if (!vp->nass) return; |
| 245 |
|
onevalue(vp); |
| 261 |
|
|
| 262 |
|
|
| 263 |
|
void |
| 264 |
< |
intvalue(vp) /* check integer variable for legal values */ |
| 265 |
< |
register VARIABLE *vp; |
| 264 |
> |
intvalue( /* check integer variable for legal values */ |
| 265 |
> |
VARIABLE *vp |
| 266 |
> |
) |
| 267 |
|
{ |
| 268 |
|
if (!vp->nass) return; |
| 269 |
|
onevalue(vp); |
| 275 |
|
|
| 276 |
|
|
| 277 |
|
void |
| 278 |
< |
fltvalue(vp) /* check float variable for legal values */ |
| 279 |
< |
register VARIABLE *vp; |
| 278 |
> |
fltvalue( /* check float variable for legal values */ |
| 279 |
> |
VARIABLE *vp |
| 280 |
> |
) |
| 281 |
|
{ |
| 282 |
|
if (!vp->nass) return; |
| 283 |
|
onevalue(vp); |
| 289 |
|
|
| 290 |
|
|
| 291 |
|
void |
| 292 |
< |
printvars(fp) /* print variable values */ |
| 293 |
< |
register FILE *fp; |
| 292 |
> |
printvars( /* print variable values */ |
| 293 |
> |
FILE *fp |
| 294 |
> |
) |
| 295 |
|
{ |
| 296 |
|
int i, j, k, clipline; |
| 297 |
< |
register char *cp; |
| 297 |
> |
char *cp; |
| 298 |
|
|
| 299 |
|
for (i = 0; i < NVARS; i++) /* print each variable */ |
| 300 |
|
for (j = 0; j < vdef(i); j++) { /* print each assignment */ |