Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
vars.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  variable_s

Defines

#define UPPER(c)   ((c)&~0x20) /* ASCII trick */
#define vnam(vc)   (vv[vc].name)
#define vdef(vc)   (vv[vc].nass)
#define vval(vc)   (vv[vc].value)
#define vint(vc)   atoi(vval(vc))
#define vflt(vc)   atof(vval(vc))
#define vlet(vc)   UPPER(vval(vc)[0])
#define vscale   vlet
#define vbool(vc)   (vlet(vc)=='T')
#define HIGH   'H'
#define MEDIUM   'M'
#define LOW   'L'

Typedefs

typedef struct variable_s VARIABLE

Functions

VARIABLEmatchvar ()
char * nvalue ()
void loadvars (char *rfname)
int setvariable (char *ass, VARIABLE *(*mv)(char *))
VARIABLEmatchvar (char *nam)
char * nvalue (int vn, int n)
void checkvalues (void)
void onevalue (VARIABLE *vp)
void catvalues (VARIABLE *vp)
int badmatch (char *tv, char *cv)
void boolvalue (VARIABLE *vp)
void qualvalue (VARIABLE *vp)
void intvalue (VARIABLE *vp)
void fltvalue (VARIABLE *vp)
void printvars (FILE *fp)

Variables

int NVARS
VARIABLE vv []
char * progname
int nowarn

Define Documentation

#define HIGH   'H'

Definition at line 45 of file vars.h.

#define LOW   'L'

Definition at line 47 of file vars.h.

#define MEDIUM   'M'

Definition at line 46 of file vars.h.

#define UPPER (   c)    ((c)&~0x20) /* ASCII trick */

Definition at line 34 of file vars.h.

#define vbool (   vc)    (vlet(vc)=='T')

Definition at line 43 of file vars.h.

#define vdef (   vc)    (vv[vc].nass)

Definition at line 37 of file vars.h.

#define vflt (   vc)    atof(vval(vc))

Definition at line 40 of file vars.h.

#define vint (   vc)    atoi(vval(vc))

Definition at line 39 of file vars.h.

#define vlet (   vc)    UPPER(vval(vc)[0])

Definition at line 41 of file vars.h.

#define vnam (   vc)    (vv[vc].name)

Definition at line 36 of file vars.h.

#define vscale   vlet

Definition at line 42 of file vars.h.

#define vval (   vc)    (vv[vc].value)

Definition at line 38 of file vars.h.


Typedef Documentation

typedef struct variable_s VARIABLE

Function Documentation

int badmatch ( char *  tv,
char *  cv 
)

Definition at line 197 of file loadvars.c.

{
       if (!*tv) return(1);        /* null string cannot match */
       do
              if (UPPER(*tv) != *cv++)
                     return(1);
       while (*++tv);
       return(0);           /* OK */
}

Here is the caller graph for this function:

void boolvalue ( VARIABLE vp)

Definition at line 210 of file loadvars.c.

{
       if (!vp->nass) return;
       onevalue(vp);
       switch (UPPER(vp->value[0])) {
       case 'T':
              if (badmatch(vp->value, "TRUE")) break;
              return;
       case 'F':
              if (badmatch(vp->value, "FALSE")) break;
              return;
       }
       fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
                     progname, vp->name);
       quit(1);
}

Here is the call graph for this function:

void catvalues ( VARIABLE vp)

Definition at line 181 of file loadvars.c.

{
       register char *cp;

       if (vp->nass < 2)
              return;
       for (cp = vp->value; vp->nass > 1; vp->nass--) {
              while (*cp)
                     cp++;
              *cp++ = ' ';
       }
}

Here is the caller graph for this function:

void checkvalues ( void  )

Definition at line 154 of file loadvars.c.

{
       register int  i;

       for (i = 0; i < NVARS; i++)
              if (vv[i].fixval != NULL)
                     (*vv[i].fixval)(vv+i);
}

Here is the caller graph for this function:

void fltvalue ( VARIABLE vp)

Definition at line 266 of file loadvars.c.

{
       if (!vp->nass) return;
       onevalue(vp);
       if (isflt(vp->value)) return;
       fprintf(stderr, "%s: illegal value for real variable '%s'\n",
                     progname, vp->name);
       quit(1);
}

Here is the call graph for this function:

void intvalue ( VARIABLE vp)

Definition at line 253 of file loadvars.c.

{
       if (!vp->nass) return;
       onevalue(vp);
       if (isint(vp->value)) return;
       fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
                     progname, vp->name);
       quit(1);
}

Here is the call graph for this function:

void loadvars ( char *  rfname)

Definition at line 23 of file loadvars.c.

{
       FILE   *fp;
       char   buf[512];
       register char *cp;

       if (rfname == NULL)
              fp = stdin;
       else if ((fp = fopen(rfname, "r")) == NULL) {
              perror(rfname);
              quit(1);
       }
       while (fgetline(buf, sizeof(buf), fp) != NULL) {
              for (cp = buf; *cp; cp++) {
                     switch (*cp) {
                     case '\\':
                            *cp++ = NOCHAR;
                            continue;
                     case '#':
                            *cp = '\0';
                            break;
                     default:
                            continue;
                     }
                     break;
              }
              if (setvariable(buf, matchvar) < 0) {
                     fprintf(stderr, "%s: unknown variable: %s\n",
                                   rfname, buf);
                     quit(1);
              }
       }
       fclose(fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

VARIABLE* matchvar ( char *  nam)

Definition at line 123 of file loadvars.c.

{
       int    n = strlen(nam);
       register int  i;

       for (i = 0; i < NVARS; i++)
              if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
                     return(vv+i);
       return(NULL);
}

Here is the caller graph for this function:

char* nvalue ( )
char* nvalue ( int  vn,
int  n 
)

Definition at line 137 of file loadvars.c.

{
       register char *cp;

       if ((vval(vn) == NULL) | (n < 0) | (n >= vdef(vn)))
              return(NULL);
       cp = vval(vn);
       while (n--)
              while (*cp++)
                     ;
       return(cp);
}

Here is the caller graph for this function:

void onevalue ( VARIABLE vp)

Definition at line 165 of file loadvars.c.

{
       if (vp->nass < 2)
              return;
       if (!nowarn)
              fprintf(stderr,
              "%s: warning - multiple assignment of variable '%s'\n",
                     progname, vp->name);
       do
              vp->value += strlen(vp->value)+1;
       while (--vp->nass > 1);
}

Here is the caller graph for this function:

void printvars ( FILE *  fp)

Definition at line 279 of file loadvars.c.

{
       int    i, j, k, clipline;
       register 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);
              k = clipline = ( vv[i].fixval == catvalues ? 64 : 236 )
                            - strlen(vnam(i)) ;
              cp = nvalue(i, j);
              while (*cp) {
                  putc(*cp++, fp);
                  if (--k <= 0) {         /* line too long */
                     while (*cp && !isspace(*cp))
                         fputc(*cp++, fp);       /* finish this word */
                     if (*cp) {           /* start new line */
                         if (vv[i].fixval == catvalues) {
                            fputc('\n', fp);
                            fputs(vnam(i), fp);
                            fputc('=', fp);
                         } else
                            fputs(" \\\n", fp);
                         k = clipline;
                     }
                  }
              }
               fputc('\n', fp);
           }
       fflush(fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qualvalue ( VARIABLE vp)

Definition at line 230 of file loadvars.c.

{
       if (!vp->nass) return;
       onevalue(vp);
       switch (UPPER(vp->value[0])) {
       case 'L':
              if (badmatch(vp->value, "LOW")) break;
              return;
       case 'M':
              if (badmatch(vp->value, "MEDIUM")) break;
              return;
       case 'H':
              if (badmatch(vp->value, "HIGH")) break;
              return;
       }
       fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
                     progname, vp->name);
       quit(1);
}

Here is the call graph for this function:

int setvariable ( char *  ass,
VARIABLE *(*)(char *)  mv 
)

Definition at line 61 of file loadvars.c.

{
       char   varname[32];
       int    n;
       register char *cp;
       register VARIABLE    *vp;
       register int  i;

       while (isspace(*ass))              /* skip leading space */
              ass++;
       cp = varname;               /* extract name */
       while (cp < varname+sizeof(varname)-1
                     && *ass && !isspace(*ass) && *ass != '=')
              *cp++ = *ass++;
       *cp = '\0';
       if (!varname[0])
              return(0);    /* no variable name! */
                                   /* trim value */
       while (isspace(*ass) || *ass == '=')
              ass++;
       for (n = strlen(ass); n > 0; n--)
              if (!isspace(ass[n-1]))
                     break;
       if (!n)
              return(0);    /* no assignment */
                                   /* match variable from list */
       vp = (*mv)(varname);
       if (vp == NULL)
              return(-1);
                                   /* assign new value */
       if ( (i = vp->nass) ) {
              cp = vp->value;
              while (i--)
                     while (*cp++)
                            ;
              i = cp - vp->value;
              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 = *ass;
       for (i = 1; i <= n; i++) {
              if (ass[i] == NOCHAR)
                     continue;
              if (isspace(*cp))
                     while (isspace(ass[i]))
                            i++;
              *++cp = ass[i];
       }
       if (isspace(*cp))           /* remove trailing space */
              *cp = '\0';
       return(++vp->nass);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int nowarn

Definition at line 92 of file rcalc.c.

int NVARS

Definition at line 35 of file rholo.c.

char* progname

Definition at line 21 of file histo.c.

Definition at line 37 of file rholo.c.