Back to index

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

Go to the source code of this file.

Classes

struct  LIBR
struct  epnode
union  epnode.v
struct  vardef.v.ln

Defines

#define VAR   1
#define NUM   2
#define UMINUS   3
#define CHAN   4
#define FUNC   5
#define ARG   6
#define CLKT   7
#define SYM   8
#define RMAXWORD   127 /* maximum word/id length */
#define CNTXMARK   '`' /* context mark */
#define isid(c)
#define evalue(ep)   (*eoper[(ep)->type])(ep)
#define E_VARIABLE   001
#define E_FUNCTION   002
#define E_INCHAN   004
#define E_OUTCHAN   010
#define E_RCONST   020
#define E_REDEFW   040

Typedefs

typedef struct epnode EPNODE
typedef struct vardef

Functions

void biggerlib (void)
void fcompile (char *fname)
void scompile (char *str, char *fname, int ln)
double varvalue (char *vname)
double evariable (EPNODE *ep)
void varset (char *vname, int assign, double val)
void dclear (char *name)
void dremove (char *name)
int vardefined (char *name)
char * setcontext (char *ctx)
char * pushcontext (char *ctx)
char * popcontext (void)
char * qualname (char *nam, int lvl)
int incontext (char *qn)
void chanout (void(*cs)(int n, double v))
void dcleanup (int lvl)
EPNODEdlookup (char *name)
VARDEF * varlookup (char *name)
VARDEF * varinsert (char *name)
void varfree (VARDEF *ln)
EPNODEdfirst (void)
EPNODEdnext (void)
EPNODEdpop (char *name)
void dpush (char *nm, EPNODE *ep)
void addchan (EPNODE *sp)
void getstatement (void)
EPNODEgetdefn (void)
EPNODEgetchan (void)
EPNODEeparse (char *expr)
double eval (char *expr)
int epcmp (EPNODE *ep1, EPNODE *ep2)
void epfree (EPNODE *epar)
EPNODEekid (EPNODE *ep, int n)
int nekids (EPNODE *ep)
void initfile (FILE *fp, char *fn, int ln)
void initstr (char *s, char *fn, int ln)
void getscanpos (char **fnp, int *lnp, char **spp, FILE **fpp)
int scan (void)
char * long2ascii (long l)
void syntax (char *err)
void addekid (EPNODE *ep, EPNODE *ekid)
char * getname (void)
int getinum (void)
double getnum (void)
EPNODEgetE1 (void)
EPNODEgetE2 (void)
EPNODEgetE3 (void)
EPNODEgetE4 (void)
EPNODEgetE5 (void)
EPNODErconst (EPNODE *epar)
int isconstvar (EPNODE *ep)
int isconstfun (EPNODE *ep)
int fundefined (char *fname)
double funvalue (char *fname, int n, double *a)
void funset (char *fname, int nargs, int assign, double(*fptr)(char *))
int nargum (void)
double argument (int n)
VARDEF * argf (int n)
char * argfun (int n)
double efunc (EPNODE *ep)
LIBRliblookup (char *fname)
void libupdate (char *fn)
void eprint (EPNODE *ep, FILE *fp)
void dprint (char *name, FILE *fp)
double chanvalue (int n)

Variables

double(* eoper [])(EPNODE *)
unsigned long eclock
unsigned int esupport
EPNODEcurfunc
int nextc
int eofc

Class Documentation

struct epnode

Definition at line 31 of file calcomp.h.

Collaboration diagram for epnode:
Class Members
struct epnode * sibling
int type
union epnode v
union epnode.v

Definition at line 32 of file calcomp.h.

Class Members
int chan
struct epnode * kid
v ln
char * name
double num
unsigned long tick
struct epnode::vardef.v.ln

Definition at line 38 of file calcomp.h.

Class Members
struct epnode * def
LIBR * lib
char * name
struct vardef * next
int nlinks

Define Documentation

#define ARG   6

Definition at line 19 of file calcomp.h.

#define CHAN   4

Definition at line 17 of file calcomp.h.

#define CLKT   7

Definition at line 20 of file calcomp.h.

#define CNTXMARK   '`' /* context mark */

Definition at line 53 of file calcomp.h.

#define E_FUNCTION   002

Definition at line 62 of file calcomp.h.

#define E_INCHAN   004

Definition at line 63 of file calcomp.h.

#define E_OUTCHAN   010

Definition at line 64 of file calcomp.h.

#define E_RCONST   020

Definition at line 65 of file calcomp.h.

#define E_REDEFW   040

Definition at line 66 of file calcomp.h.

#define E_VARIABLE   001

Definition at line 61 of file calcomp.h.

#define evalue (   ep)    (*eoper[(ep)->type])(ep)

Definition at line 58 of file calcomp.h.

#define FUNC   5

Definition at line 18 of file calcomp.h.

#define isid (   c)
Value:
(isalnum(c) || (c) == '_' || \
                     (c) == '.' || (c) == CNTXMARK)

Definition at line 55 of file calcomp.h.

#define NUM   2

Definition at line 15 of file calcomp.h.

#define RMAXWORD   127 /* maximum word/id length */

Definition at line 52 of file calcomp.h.

#define SYM   8

Definition at line 21 of file calcomp.h.

#define UMINUS   3

Definition at line 16 of file calcomp.h.

#define VAR   1

Definition at line 14 of file calcomp.h.


Typedef Documentation

typedef struct epnode EPNODE
typedef struct vardef

Definition at line 50 of file calcomp.h.


Function Documentation

void addchan ( EPNODE sp)

Definition at line 529 of file caldefn.c.

{
    int        ch = sp->v.kid->v.chan;
    register EPNODE  *ep, *epl;

    for (epl = NULL, ep = outchan; ep != NULL; epl = ep, ep = ep->sibling)
       if (ep->v.kid->v.chan >= ch) {
           if (epl != NULL)
              epl->sibling = sp;
           else
              outchan = sp;
           if (ep->v.kid->v.chan > ch)
              sp->sibling = ep;
           else {
              sp->sibling = ep->sibling;
              epfree(ep);
           }
           return;
       }
    if (epl != NULL)
       epl->sibling = sp;
    else
       outchan = sp;
    sp->sibling = NULL;

}

Here is the call graph for this function:

Here is the caller graph for this function:

void addekid ( EPNODE ep,
EPNODE ekid 
)

Here is the caller graph for this function:

VARDEF* argf ( int  n)

Definition at line 224 of file calfunc.c.

{
    register ACTIVATION  *actp;
    register EPNODE  *ep;

    for (actp = curact; actp != NULL; actp = actp->prev) {

       if (n <= 0)
           break;

       if (actp->fun == NULL)
           goto badarg;

       if ((ep = ekid(actp->fun, n)) == NULL) {
           eputs(actp->name);
           eputs(": too few arguments\n");
           quit(1);
       }
       if (ep->type == VAR)
           return(ep->v.ln);                     /* found it */

       if (ep->type != ARG)
           goto badarg;

       n = ep->v.chan;                           /* try previous context */
    }
    eputs("Bad call to argf!\n");
    quit(1);

badarg:
    eputs(actp->name);
    eputs(": argument not a function\n");
    quit(1);
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* argfun ( int  n)

Definition at line 263 of file calfunc.c.

{
    return(argf(n)->name);
}

Here is the call graph for this function:

double argument ( int  n)

Definition at line 192 of file calfunc.c.

{
    register ACTIVATION  *actp = curact;
    register EPNODE  *ep = NULL;
    double  aval;

    if (actp == NULL || --n < 0) {
       eputs("Bad call to argument!\n");
       quit(1);
    }
                                          /* already computed? */
    if (n < AFLAGSIZ && 1L<<n & actp->an)
       return(actp->ap[n]);

    if (actp->fun == NULL || (ep = ekid(actp->fun, n+1)) == NULL) {
       eputs(actp->name);
       eputs(": too few arguments\n");
       quit(1);
    }
    curact = actp->prev;                  /* pop environment */
    aval = evalue(ep);                           /* compute argument */
    curact = actp;                        /* push back environment */
    if (n < ALISTSIZ) {                          /* save value */
       actp->ap[n] = aval;
       actp->an |= 1L<<n;
    }
    return(aval);
}

Here is the call graph for this function:

void biggerlib ( void  )

Definition at line 22 of file biggerlib.c.

{
                            /* the Bessel functions */
    funset("j0", 1, ':', l_j0);
    funset("j1", 1, ':', l_j1);
    funset("jn", 2, ':', l_jn);
    funset("y0", 1, ':', l_y0);
    funset("y1", 1, ':', l_y1);
    funset("yn", 2, ':', l_yn);
    funset("erf", 1, ':', l_erf);
    funset("erfc", 1, ':', l_erfc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void chanout ( void(*)(int n, double v cs)

Definition at line 331 of file caldefn.c.

{
    register EPNODE  *ep;

    for (ep = outchan; ep != NULL; ep = ep->sibling)
       (*cs)(ep->v.kid->v.chan, evalue(ep->v.kid->sibling));

}

Here is the caller graph for this function:

double chanvalue ( int  n)

Definition at line 132 of file calc.c.

{
       if (n == 0)
              n = nres;
       else if (n > nres || nres-n >= MAXRES) {
              fprintf(stderr, "$%d: illegal result\n", n);
              return(0.0);
       }
       return(result[(n-1)%MAXRES]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dcleanup ( int  lvl)

Definition at line 344 of file caldefn.c.

{
    register int  i;
    register VARDEF  *vp;
    register EPNODE  *ep;
                            /* if context is global, clear all */
    for (i = 0; i < NHASH; i++)
       for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
           if (incontext(vp->name)) {
              if (lvl >= 2)
                  dremove(vp->name);
              else
                  dclear(vp->name);
           }
    if (lvl >= 1) {
       for (ep = outchan; ep != NULL; ep = ep->sibling)
           epfree(ep);
       outchan = NULL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dclear ( char *  name)

Definition at line 161 of file caldefn.c.

{
    register EPNODE  *ep;

    while ((ep = dpop(name)) != NULL) {
       if (ep->type == ':') {
           dpush(name, ep);        /* don't clear constants */
           return;
       }
       epfree(ep);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* dfirst ( void  )

Definition at line 465 of file caldefn.c.

{
    htndx = 0;
    htpos = NULL;
    ochpos = outchan;
    return(dnext());
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* dlookup ( char *  name)

Definition at line 369 of file caldefn.c.

{
    register VARDEF  *vp;
    
    if ((vp = varlookup(name)) == NULL)
       return(NULL);
    return(vp->def);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* dnext ( void  )

Definition at line 475 of file caldefn.c.

{
    register EPNODE  *ep;
    register char  *nm;

    while (htndx < NHASH) {
       if (htpos == NULL)
              htpos = hashtbl[htndx++];
       while (htpos != NULL) {
           ep = htpos->def;
           nm = htpos->name;
           htpos = htpos->next;
           if (ep != NULL && incontext(nm))
              return(ep);
       }
    }
    if ((ep = ochpos) != NULL)
       ochpos = ep->sibling;
    return(ep);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* dpop ( char *  name)

Definition at line 498 of file caldefn.c.

{
    register VARDEF  *vp;
    register EPNODE  *dp;
    
    if ((vp = varlookup(name)) == NULL || vp->def == NULL)
       return(NULL);
    dp = vp->def;
    vp->def = dp->sibling;
    varfree(vp);
    return(dp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dprint ( char *  name,
FILE *  fp 
)

Definition at line 104 of file calprnt.c.

{
    register EPNODE  *ep;
    
    if (name == NULL)
       for (ep = dfirst(); ep != NULL; ep = dnext()) {
           eprint(ep, fp);
           fputs(";\n", fp);
       }
    else if ((ep = dlookup(name)) != NULL) {
       eprint(ep, fp);
       fputs(";\n", fp);
    } else {
       wputs(name);
       wputs(": undefined\n");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dpush ( char *  nm,
EPNODE ep 
)

Here is the caller graph for this function:

void dremove ( char *  name)

Definition at line 178 of file caldefn.c.

{
    register EPNODE  *ep;

    while ((ep = dpop(name)) != NULL)
       epfree(ep);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double efunc ( EPNODE ep)

Definition at line 271 of file calfunc.c.

{
    ACTIVATION  act;
    double  alist[ALISTSIZ];
    double  rval;
    register VARDEF  *dp;
                                   /* push environment */
    dp = resolve(ep->v.kid);
    act.name = dp->name;
    act.prev = curact;
    act.ap = alist;
    act.an = 0;
    act.fun = ep;
    curact = &act;

    if (dp->def == NULL || dp->def->v.kid->type != FUNC)
       rval = libfunc(act.name, dp);
    else
       rval = evalue(dp->def->v.kid->sibling);
    
    curact = act.prev;                    /* pop environment */
    return(rval);
}

Here is the call graph for this function:

EPNODE* ekid ( EPNODE ep,
int  n 
)

Here is the caller graph for this function:

EPNODE* eparse ( char *  expr)

Definition at line 88 of file calexpr.c.

{
    EPNODE  *ep;

    initstr(expr, NULL, 0);
    curfunc = NULL;
    ep = getE1();
    if (nextc != EOF)
       syntax("unexpected character");
    return(ep);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int epcmp ( EPNODE ep1,
EPNODE ep2 
)

Here is the caller graph for this function:

void epfree ( EPNODE epar)

Here is the caller graph for this function:

void eprint ( EPNODE ep,
FILE *  fp 
)

Definition at line 17 of file calprnt.c.

{
    static EPNODE  *curdef = NULL;
    register EPNODE  *ep1 = NULL;

    switch (ep->type) {

       case VAR:
           fputs(ep->v.ln->name, fp);
           break;

       case SYM:
           fputs(ep->v.name, fp);
           break;

       case FUNC:
           eprint(ep->v.kid, fp);
           fputc('(', fp);
           ep1 = ep->v.kid->sibling;
           while (ep1 != NULL) {
              eprint(ep1, fp);
              if ((ep1 = ep1->sibling) != NULL)
                  fputs(", ", fp);
           }
           fputc(')', fp);
           break;

       case ARG:
           if (curdef == NULL || curdef->v.kid->type != FUNC ||
                     (ep1 = ekid(curdef->v.kid, ep->v.chan)) == NULL) {
              eputs("Bad argument!\n");
              quit(1);
           }
           eprint(ep1, fp);
           break;

       case NUM:
           fprintf(fp, "%.9g", ep->v.num);
           break;

       case UMINUS:
           fputc('-', fp);
           eprint(ep->v.kid, fp);
           break;

       case CHAN:
           fprintf(fp, "$%d", ep->v.chan);
           break;
       
       case '=':
       case ':':
           ep1 = curdef;
           curdef = ep;
           eprint(ep->v.kid, fp);
           fputc(' ', fp);
           fputc(ep->type, fp);
           fputc(' ', fp);
           eprint(ep->v.kid->sibling, fp);
           curdef = ep1;
           break;
           
       case '+':
       case '-':
       case '*':
       case '/':
       case '^':
           fputc('(', fp);
           eprint(ep->v.kid, fp);
           fputc(' ', fp);
           fputc(ep->type, fp);
           fputc(' ', fp);
           eprint(ep->v.kid->sibling, fp);
           fputc(')', fp);
           break;

       default:
           eputs("Bad expression!\n");
           quit(1);

    }

}

Here is the call graph for this function:

Here is the caller graph for this function:

double eval ( char *  expr)

Definition at line 104 of file calexpr.c.

{
    register EPNODE  *ep;
    double  rval;

    ep = eparse(expr);
    rval = evalue(ep);
    epfree(ep);
    return(rval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double evariable ( EPNODE ep)

Definition at line 114 of file caldefn.c.

{
    register VARDEF  *dp = ep->v.ln;

    return(dvalue(dp->name, dp->def));
}

Here is the call graph for this function:

void fcompile ( char *  fname)

Definition at line 70 of file caldefn.c.

{
    FILE  *fp;

    if (fname == NULL)
       fp = stdin;
    else if ((fp = fopen(fname, "r")) == NULL) {
       eputs(fname);
       eputs(": cannot open\n");
       quit(1);
    }
    initfile(fp, fname, 0);
    while (nextc != EOF)
       getstatement();
    if (fname != NULL)
       fclose(fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fundefined ( char *  fname)

Definition at line 76 of file calfunc.c.

{
    register LIBR  *lp;
    register VARDEF  *vp;

    if ((vp = varlookup(fname)) != NULL && vp->def != NULL
              && vp->def->v.kid->type == FUNC)
       return(nekids(vp->def->v.kid) - 1);
    lp = vp != NULL ? vp->lib : liblookup(fname);
    if (lp == NULL)
       return(0);
    return(lp->nargs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void funset ( char *  fname,
int  nargs,
int  assign,
double(*)(char *)  fptr 
)

Definition at line 124 of file calfunc.c.

{
    int  oldlibsize = libsize;
    char *cp;
    register LIBR  *lp;
                                          /* check for context */
    for (cp = fname; *cp; cp++)
       ;
    if (cp == fname)
       return;
    if (cp[-1] == CNTXMARK)
       *--cp = '\0';
    if ((lp = liblookup(fname)) == NULL) {       /* insert */
       if (libsize >= MAXLIB) {
           eputs("Too many library functons!\n");
           quit(1);
       }
       for (lp = &library[libsize]; lp > library; lp--)
           if (strcmp(lp[-1].fname, fname) > 0) {
              lp[0].fname = lp[-1].fname;
              lp[0].nargs = lp[-1].nargs;
              lp[0].atyp = lp[-1].atyp;
              lp[0].f = lp[-1].f;
           } else
              break;
       libsize++;
    }
    if (fptr == NULL) {                          /* delete */
       while (lp < &library[libsize-1]) {
           lp[0].fname = lp[1].fname;
           lp[0].nargs = lp[1].nargs;
           lp[0].atyp = lp[1].atyp;
           lp[0].f = lp[1].f;
           lp++;
       }
       libsize--;
    } else {                              /* or assign */
       lp[0].fname = fname;        /* string must be static! */
       lp[0].nargs = nargs;
       lp[0].atyp = assign;
       lp[0].f = fptr;
    }
    if (libsize != oldlibsize)
       libupdate(fname);                  /* relink library */
}

Here is the call graph for this function:

Here is the caller graph for this function:

double funvalue ( char *  fname,
int  n,
double *  a 
)

Definition at line 93 of file calfunc.c.

{
    ACTIVATION  act;
    register VARDEF  *vp;
    double  rval;
                                   /* push environment */
    act.name = fname;
    act.prev = curact;
    act.ap = a;
    if (n >= AFLAGSIZ)
       act.an = ~0;
    else
       act.an = (1L<<n)-1;
    act.fun = NULL;
    curact = &act;

    if ((vp = varlookup(fname)) == NULL || vp->def == NULL
              || vp->def->v.kid->type != FUNC)
       rval = libfunc(fname, vp);
    else
       rval = evalue(vp->def->v.kid->sibling);

    curact = act.prev;                    /* pop environment */
    return(rval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* getchan ( void  )

Definition at line 664 of file caldefn.c.

{
    register EPNODE  *ep1, *ep2;

    if (nextc != '$')
       syntax("missing '$'");
    scan();

    ep1 = newnode();
    ep1->type = CHAN;
    ep1->v.chan = getinum();

    if (nextc != '=')
       syntax("'=' expected");
    scan();

    ep2 = newnode();
    ep2->type = '=';
    addekid(ep2, ep1);
    addekid(ep2, getE1());

    return(ep2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* getdefn ( void  )

Definition at line 604 of file caldefn.c.

{
    register EPNODE  *ep1, *ep2;

    if (!isalpha(nextc) && nextc != CNTXMARK)
       syntax("illegal variable name");

    ep1 = newnode();
    ep1->type = SYM;
    ep1->v.name = savestr(getname());

    if (esupport&E_FUNCTION && nextc == '(') {
       ep2 = newnode();
       ep2->type = FUNC;
       addekid(ep2, ep1);
       ep1 = ep2;
       do {
           scan();
           if (!isalpha(nextc))
              syntax("illegal parameter name");
           ep2 = newnode();
           ep2->type = SYM;
           ep2->v.name = savestr(getname());
           addekid(ep1, ep2);
       } while (nextc == ',');
       if (nextc != ')')
           syntax("')' expected");
       scan();
       curfunc = ep1;
    }

    if (nextc != '=' && nextc != ':')
       syntax("'=' or ':' expected");

    ep2 = newnode();
    ep2->type = nextc;
    scan();
    addekid(ep2, ep1);
    addekid(ep2, getE1());

    if (ep1->type == SYM && ep1->sibling->type != NUM) {
       ep1 = newnode();
       ep1->type = CLKT;
       ep1->v.tick = 0;
       addekid(ep2, ep1);
       ep1 = newnode();
       ep1->type = NUM;
       addekid(ep2, ep1);
    }
    curfunc = NULL;

    return(ep2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* getE1 ( void  )

Definition at line 584 of file calexpr.c.

{
    register EPNODE  *ep1, *ep2;

    ep1 = getE2();
    while (nextc == '+' || nextc == '-') {
       ep2 = newnode();
       ep2->type = nextc;
       scan();
       addekid(ep2, ep1);
       addekid(ep2, getE2());
       if (esupport&E_RCONST &&
                     ep1->type == NUM && ep1->sibling->type == NUM)
              ep2 = rconst(ep2);
       ep1 = ep2;
    }
    return(ep1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* getE2 ( void  )

Definition at line 606 of file calexpr.c.

{
    register EPNODE  *ep1, *ep2;

    ep1 = getE3();
    while (nextc == '*' || nextc == '/') {
       ep2 = newnode();
       ep2->type = nextc;
       scan();
       addekid(ep2, ep1);
       addekid(ep2, getE3());
       if (esupport&E_RCONST &&
                     ep1->type == NUM && ep1->sibling->type == NUM)
              ep2 = rconst(ep2);
       ep1 = ep2;
    }
    return(ep1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* getE3 ( void  )

Definition at line 628 of file calexpr.c.

{
    register EPNODE  *ep1, *ep2;

    ep1 = getE4();
    if (nextc == '^') {
       ep2 = newnode();
       ep2->type = nextc;
       scan();
       addekid(ep2, ep1);
       addekid(ep2, getE3());
       if (esupport&E_RCONST &&
                     ep1->type == NUM && ep1->sibling->type == NUM)
              ep2 = rconst(ep2);
       return(ep2);
    }
    return(ep1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* getE4 ( void  )

Definition at line 650 of file calexpr.c.

{
    register EPNODE  *ep1, *ep2;

    if (nextc == '-') {
       scan();
       ep2 = getE5();
       if (ep2->type == NUM) {
              ep2->v.num = -ep2->v.num;
              return(ep2);
       }
       if (ep2->type == UMINUS) {  /* don't generate -(-E5) */
           ep1 = ep2->v.kid;
           efree((char *)ep2);
           return(ep1);
       }
       ep1 = newnode();
       ep1->type = UMINUS;
       addekid(ep1, ep2);
       return(ep1);
    }
    if (nextc == '+')
       scan();
    return(getE5());
}

Here is the call graph for this function:

Here is the caller graph for this function:

EPNODE* getE5 ( void  )

Definition at line 679 of file calexpr.c.

{
       int     i;
       char  *nam;
       register EPNODE  *ep1, *ep2;

       if (nextc == '(') {
              scan();
              ep1 = getE1();
              if (nextc != ')')
                     syntax("')' expected");
              scan();
              return(ep1);
       }

       if (esupport&E_INCHAN && nextc == '$') {
              scan();
              ep1 = newnode();
              ep1->type = CHAN;
              ep1->v.chan = getinum();
              return(ep1);
       }

       if (esupport&(E_VARIABLE|E_FUNCTION) &&
                     (isalpha(nextc) || nextc == CNTXMARK)) {
              nam = getname();
              ep1 = NULL;
              if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION)
                            && curfunc != NULL)
                     for (i = 1, ep2 = curfunc->v.kid->sibling;
                                   ep2 != NULL; i++, ep2 = ep2->sibling)
                            if (!strcmp(ep2->v.name, nam)) {
                                   ep1 = newnode();
                                   ep1->type = ARG;
                                   ep1->v.chan = i;
                                   break;
                            }
              if (ep1 == NULL) {
                     ep1 = newnode();
                     ep1->type = VAR;
                     ep1->v.ln = varinsert(nam);
              }
              if (esupport&E_FUNCTION && nextc == '(') {
                     ep2 = newnode();
                     ep2->type = FUNC;
                     addekid(ep2, ep1);
                     ep1 = ep2;
                     do {
                            scan();
                            addekid(ep1, getE1());
                     } while (nextc == ',');
                     if (nextc != ')')
                            syntax("')' expected");
                     scan();
              } else if (!(esupport&E_VARIABLE))
                     syntax("'(' expected");
              if (esupport&E_RCONST && isconstvar(ep1))
                     ep1 = rconst(ep1);
              return(ep1);
       }

       if (isdecimal(nextc)) {
              ep1 = newnode();
              ep1->type = NUM;
              ep1->v.num = getnum();
              return(ep1);
       }
       syntax("unexpected character");
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int getinum ( void  )

Definition at line 527 of file calexpr.c.

{
    register int  n, lnext;

    n = 0;
    lnext = nextc;
    while (isdigit(lnext)) {
       n = n * 10 + lnext - '0';
       lnext = scan();
    }
    return(n);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* getname ( void  )

Definition at line 510 of file calexpr.c.

{
    static char       str[RMAXWORD+1];
    register int  i, lnext;

    lnext = nextc;
    for (i = 0; i < RMAXWORD && isid(lnext); i++, lnext = scan())
       str[i] = lnext;
    str[i] = '\0';
    while (isid(lnext))            /* skip rest of name */
       lnext = scan();

    return(str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double getnum ( void  )

Definition at line 542 of file calexpr.c.

{
    register int  i, lnext;
    char  str[RMAXWORD+1];

    i = 0;
    lnext = nextc;
    while (isdigit(lnext) && i < RMAXWORD) {
       str[i++] = lnext;
       lnext = scan();
    }
    if (lnext == '.' && i < RMAXWORD) {
       str[i++] = lnext;
       lnext = scan();
       if (i == 1 && !isdigit(lnext))
           syntax("badly formed number");
       while (isdigit(lnext) && i < RMAXWORD) {
           str[i++] = lnext;
           lnext = scan();
       }
    }
    if ((lnext == 'e') | (lnext == 'E') && i < RMAXWORD) {
       str[i++] = lnext;
       lnext = scan();
       if ((lnext == '-') | (lnext == '+') && i < RMAXWORD) {
           str[i++] = lnext;
           lnext = scan();
       }
       if (!isdigit(lnext))
           syntax("missing exponent");
       while (isdigit(lnext) && i < RMAXWORD) {
           str[i++] = lnext;
           lnext = scan();
       }
    }
    str[i] = '\0';

    return(atof(str));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void getscanpos ( char **  fnp,
int *  lnp,
char **  spp,
FILE **  fpp 
)

Definition at line 388 of file calexpr.c.

{
    if (fnp != NULL) *fnp = infile;
    if (lnp != NULL) *lnp = lineno;
    if (spp != NULL) *spp = linbuf+linepos;
    if (fpp != NULL) *fpp = infp;
}
void getstatement ( void  )

Definition at line 560 of file caldefn.c.

{
    register EPNODE  *ep;
    char  *qname;
    register VARDEF  *vdef;

    if (nextc == ';') {            /* empty statement */
       scan();
       return;
    }
    if (esupport&E_OUTCHAN &&
              nextc == '$') {             /* channel assignment */
       ep = getchan();
       addchan(ep);
    } else {                       /* ordinary definition */
       ep = getdefn();
       qname = qualname(dname(ep), 0);
       if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL) {
           if (vdef->def != NULL && epcmp(ep, vdef->def)) {
              wputs(qname);
              if (vdef->def->type == ':')
                  wputs(": redefined constant expression\n");
              else
                  wputs(": redefined\n");
           } else if (ep->v.kid->type == FUNC && vdef->lib != NULL) {
              wputs(qname);
              wputs(": definition hides library function\n");
           }
       }
       if (ep->type == ':')
           dremove(qname);
       else
           dclear(qname);
       dpush(qname, ep);
    }
    if (nextc != EOF) {
       if (nextc != ';')
           syntax("';' expected");
       scan();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int incontext ( char *  qn)

Here is the caller graph for this function:

void initfile ( FILE *  fp,
char *  fn,
int  ln 
)

Definition at line 353 of file calexpr.c.

{
    static char       inpbuf[MAXLINE];

    infp = fp;
    linbuf = inpbuf;
    infile = fn;
    lineno = ln;
    linepos = 0;
    inpbuf[0] = '\0';
    scan();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void initstr ( char *  s,
char *  fn,
int  ln 
)

Definition at line 372 of file calexpr.c.

{
    infp = NULL;
    infile = fn;
    lineno = ln;
    linbuf = s;
    linepos = 0;
    scan();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int isconstfun ( EPNODE ep)

Here is the caller graph for this function:

int isconstvar ( EPNODE ep)

Here is the caller graph for this function:

LIBR* liblookup ( char *  fname)

Definition at line 298 of file calfunc.c.

{
    int  upper, lower;
    register int  cm, i;

    lower = 0;
    upper = cm = libsize;

    while ((i = (lower + upper) >> 1) != cm) {
       cm = strcmp(fname, library[i].fname);
       if (cm > 0)
           lower = i;
       else if (cm < 0)
           upper = i;
       else
           return(&library[i]);
       cm = i;
    }
    return(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void libupdate ( char *  fn)

Definition at line 425 of file caldefn.c.

{
    register int  i;
    register VARDEF  *vp;
                                   /* if fn is NULL then relink all */
    for (i = 0; i < NHASH; i++)
       for (vp = hashtbl[i]; vp != NULL; vp = vp->next)
           if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name))
              vp->lib = liblookup(vp->name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* long2ascii ( long  l)

Definition at line 439 of file calexpr.c.

{
    static char       buf[16];
    register char  *cp;
    int        neg = 0;

    if (l == 0)
       return("0");
    if (l < 0) {
       l = -l;
       neg++;
    }
    cp = buf + sizeof(buf);
    *--cp = '\0';
    while (l) {
       *--cp = l % 10 + '0';
       l /= 10;
    }
    if (neg)
       *--cp = '-';
    return(cp);
}

Here is the caller graph for this function:

int nargum ( void  )

Definition at line 176 of file calfunc.c.

{
    register int  n;

    if (curact == NULL)
       return(0);
    if (curact->fun == NULL) {
       for (n = 0; (1L<<n) & curact->an; n++)
           ;
       return(n);
    }
    return(nekids(curact->fun) - 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nekids ( EPNODE ep)

Here is the caller graph for this function:

char* popcontext ( void  )

Definition at line 254 of file caldefn.c.

{
    register char  *cp1, *cp2;

    if (!context[0])               /* nothing left to pop */
       return(context);
    cp2 = context;                 /* find mark */
    while (*++cp2 && *cp2 != CNTXMARK)
       ;
    cp1 = context;                 /* copy tail to front */
    while ( (*cp1++ = *cp2++) )
       ;
    return(context);
}
char* pushcontext ( char *  ctx)

Definition at line 234 of file caldefn.c.

{
    char  oldcontext[MAXCNTX+1];
    register int  n;

    strcpy(oldcontext, context);   /* save old context */
    setcontext(ctx);               /* set new context */
    n = strlen(context);           /* tack on old */
    if (n+strlen(oldcontext) > MAXCNTX) {
       strncpy(context+n, oldcontext, MAXCNTX-n);
       context[MAXCNTX] = '\0';
    } else
       strcpy(context+n, oldcontext);
    return(context);
}

Here is the call graph for this function:

char* qualname ( char *  nam,
int  lvl 
)

Here is the caller graph for this function:

EPNODE* rconst ( EPNODE epar)

Here is the caller graph for this function:

int scan ( void  )

Definition at line 403 of file calexpr.c.

{
    register int  lnext = 0;

    do {
       if (linbuf[linepos] == '\0')
           if (infp == NULL || fgets(linbuf, MAXLINE, infp) == NULL)
              nextc = EOF;
           else {
              nextc = linbuf[0];
              lineno++;
              linepos = 1;
           }
       else
           nextc = linbuf[linepos++];
       if (!lnext)
              lnext = nextc;
       if (nextc == eofc) {
              nextc = EOF;
              break;
       }
       if (nextc == '{') {
           scan();
           while (nextc != '}')
              if (nextc == EOF)
                  syntax("'}' expected");
              else
                  scan();
           scan();
       }
    } while (isspace(nextc));
    return(lnext);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void scompile ( char *  str,
char *  fname,
int  ln 
)

Definition at line 92 of file caldefn.c.

{
    initstr(str, fn, ln);
    while (nextc != EOF)
       getstatement();
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* setcontext ( char *  ctx)

Here is the caller graph for this function:

static void syntax ( char *  err)

Definition at line 789 of file obj2rad.c.

{
       fprintf(stderr, "%s: Wavefront syntax error near line %d: %s\n",
                     inpfile, lineno, er);
       exit(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int vardefined ( char *  name)

Definition at line 190 of file caldefn.c.

{
    register EPNODE  *dp;

    return((dp = dlookup(name)) != NULL && dp->v.kid->type == SYM);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void varfree ( VARDEF *  ln)

Here is the caller graph for this function:

VARDEF* varinsert ( char *  name)

Definition at line 399 of file caldefn.c.

{
    register VARDEF  *vp;
    int        hv;
    
    if ((vp = varlookup(name)) != NULL) {
       vp->nlinks++;
       return(vp);
    }
    vp = (VARDEF *)emalloc(sizeof(VARDEF));
    vp->lib = liblookup(name);
    if (vp->lib == NULL)           /* if name not in library */
       name = qualname(name, 0);   /* use fully qualified version */
    hv = hash(name);
    vp->name = savestr(name);
    vp->nlinks = 1;
    vp->def = NULL;
    vp->next = hashtbl[hv];
    hashtbl[hv] = vp;
    return(vp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

VARDEF* varlookup ( char *  name)

Definition at line 382 of file caldefn.c.

{
    int        lvl = 0;
    register char  *qname;
    register VARDEF  *vp;
                            /* find most qualified match */
    while ((qname = qualname(name, lvl++)) != NULL)
       for (vp = hashtbl[hash(qname)]; vp != NULL; vp = vp->next)
           if (!strcmp(vp->name, qname))
              return(vp);
    return(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void varset ( char *  vname,
int  assign,
double  val 
)

Definition at line 125 of file caldefn.c.

{
    char  *qname;
    register EPNODE  *ep1, *ep2;
                                   /* get qualified name */
    qname = qualname(vname, 0);
                                   /* check for quick set */
    if ((ep1 = dlookup(qname)) != NULL && ep1->v.kid->type == SYM) {
       ep2 = ep1->v.kid->sibling;
       if (ep2->type == NUM) {
           ep2->v.num = val;
           ep1->type = assign;
           return;
       }
    }
                                   /* hand build definition */
    ep1 = newnode();
    ep1->type = assign;
    ep2 = newnode();
    ep2->type = SYM;
    ep2->v.name = savestr(vname);
    addekid(ep1, ep2);
    ep2 = newnode();
    ep2->type = NUM;
    ep2->v.num = val;
    addekid(ep1, ep2);
    dremove(qname);
    dpush(qname, ep1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double varvalue ( char *  vname)

Definition at line 105 of file caldefn.c.

{
    return(dvalue(vname, dlookup(vname)));
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 63 of file caldefn.c.

unsigned long eclock

Definition at line 51 of file caldefn.c.

int eofc

Definition at line 50 of file calexpr.c.

double(* eoper[])(EPNODE *)

Definition at line 53 of file calexpr.c.

unsigned int esupport

Definition at line 47 of file calexpr.c.

int nextc

Definition at line 51 of file calexpr.c.