| 1 | greg | 2.16 | /* RCSid $Id: calcomp.h,v 2.15 2003/08/04 19:20:26 greg Exp $ */ | 
| 2 | greg | 1.1 | /* | 
| 3 |  |  | *  calcomp.h - header file for expression parser. | 
| 4 | greg | 2.6 | */ | 
| 5 | schorsch | 2.9 | #ifndef _RAD_CALCOMP_H_ | 
| 6 |  |  | #define _RAD_CALCOMP_H_ | 
| 7 | schorsch | 2.14 |  | 
| 8 |  |  | #include <stdio.h> | 
| 9 |  |  |  | 
| 10 | schorsch | 2.9 | #ifdef __cplusplus | 
| 11 |  |  | extern "C" { | 
| 12 |  |  | #endif | 
| 13 | greg | 2.7 |  | 
| 14 | greg | 2.2 | #define  VAR            1 | 
| 15 |  |  | #define  NUM            2 | 
| 16 |  |  | #define  UMINUS         3 | 
| 17 |  |  | #define  CHAN           4 | 
| 18 |  |  | #define  FUNC           5 | 
| 19 |  |  | #define  ARG            6 | 
| 20 |  |  | #define  TICK           7 | 
| 21 |  |  | #define  SYM            8 | 
| 22 | greg | 1.4 | /* also: '+', '-', '*', '/', '^', '=', ':' */ | 
| 23 | greg | 1.1 |  | 
| 24 |  |  | typedef struct { | 
| 25 |  |  | char  *fname;               /* function name */ | 
| 26 | greg | 1.5 | short  nargs;               /* # of required arguments */ | 
| 27 |  |  | short  atyp;                /* assignment type (':' or '=') */ | 
| 28 | greg | 2.16 | double  (*f)(char *);       /* pointer to function */ | 
| 29 | greg | 1.1 | }  LIBR;                /* a library function */ | 
| 30 |  |  |  | 
| 31 |  |  | typedef struct epnode { | 
| 32 | greg | 2.2 | int  type;                  /* node type */ | 
| 33 | greg | 1.1 | struct epnode  *sibling;    /* next child this level */ | 
| 34 |  |  | union { | 
| 35 |  |  | struct epnode  *kid;    /* first child */ | 
| 36 | greg | 2.2 | double  num;            /* number */ | 
| 37 | greg | 1.1 | char  *name;            /* symbol name */ | 
| 38 |  |  | int  chan;              /* channel number */ | 
| 39 | greg | 2.4 | unsigned long  tick;    /* timestamp */ | 
| 40 | greg | 1.1 | struct vardef { | 
| 41 |  |  | char  *name;                /* variable name */ | 
| 42 | greg | 2.2 | int  nlinks;                /* number of references */ | 
| 43 | greg | 1.1 | struct epnode  *def;        /* definition */ | 
| 44 |  |  | LIBR  *lib;                 /* library definition */ | 
| 45 |  |  | struct vardef  *next;       /* next in hash list */ | 
| 46 |  |  | }  *ln;                 /* link */ | 
| 47 |  |  | } v;                /* value */ | 
| 48 |  |  | }  EPNODE;      /* an expression node */ | 
| 49 |  |  |  | 
| 50 |  |  | typedef struct vardef  VARDEF;  /* a variable definition */ | 
| 51 |  |  |  | 
| 52 | schorsch | 2.13 | #define  RMAXWORD       127             /* maximum word/id length */ | 
| 53 | greg | 2.2 | #define  CNTXMARK       '`'             /* context mark */ | 
| 54 | greg | 1.6 |  | 
| 55 | greg | 2.2 | #define  isid(c)        (isalnum(c) || (c) == '_' || \ | 
| 56 | greg | 1.6 | (c) == '.' || (c) == CNTXMARK) | 
| 57 |  |  |  | 
| 58 | greg | 2.6 | #define  evalue(ep)     (*eoper[(ep)->type])(ep) | 
| 59 |  |  |  | 
| 60 |  |  | /* flags to set in esupport */ | 
| 61 |  |  | #define  E_VARIABLE     001 | 
| 62 |  |  | #define  E_FUNCTION     002 | 
| 63 |  |  | #define  E_INCHAN       004 | 
| 64 |  |  | #define  E_OUTCHAN      010 | 
| 65 |  |  | #define  E_RCONST       020 | 
| 66 |  |  | #define  E_REDEFW       040 | 
| 67 |  |  |  | 
| 68 | greg | 2.15 | extern double  (*eoper[])(EPNODE *); | 
| 69 | greg | 2.4 | extern unsigned long  eclock; | 
| 70 | greg | 2.6 | extern unsigned int  esupport; | 
| 71 |  |  | extern EPNODE   *curfunc; | 
| 72 | greg | 1.1 | extern int  nextc; | 
| 73 |  |  |  | 
| 74 | schorsch | 2.14 | /* defined in biggerlib.c */ | 
| 75 |  |  | extern void biggerlib(void); | 
| 76 |  |  |  | 
| 77 | greg | 2.6 | /* defined in caldefn.c */ | 
| 78 |  |  | extern void     fcompile(char *fname); | 
| 79 |  |  | extern void     scompile(char *str, char *fname, int ln); | 
| 80 |  |  | extern double   varvalue(char *vname); | 
| 81 |  |  | extern double   evariable(EPNODE *ep); | 
| 82 |  |  | extern void     varset(char *fname, int assign, double val); | 
| 83 |  |  | extern void     dclear(char *name); | 
| 84 |  |  | extern void     dremove(char *name); | 
| 85 |  |  | extern int      vardefined(char *name); | 
| 86 |  |  | extern char     *setcontext(char *ctx); | 
| 87 |  |  | extern char     *pushcontext(char *ctx); | 
| 88 |  |  | extern char     *popcontext(void); | 
| 89 |  |  | extern char     *qualname(char *nam, int lvl); | 
| 90 |  |  | extern int      incontext(char *qn); | 
| 91 | greg | 2.8 | extern void     chanout(void (*cs)(int n, double v)); | 
| 92 | greg | 2.6 | extern void     dcleanup(int lvl); | 
| 93 |  |  | extern EPNODE   *dlookup(char *name); | 
| 94 |  |  | extern VARDEF   *varlookup(char *name); | 
| 95 |  |  | extern VARDEF   *varinsert(char *name); | 
| 96 |  |  | extern void     varfree(VARDEF *ln); | 
| 97 |  |  | extern EPNODE   *dfirst(void); | 
| 98 |  |  | extern EPNODE   *dnext(void); | 
| 99 |  |  | extern EPNODE   *dpop(char *name); | 
| 100 |  |  | extern void     dpush(char *nm, EPNODE *ep); | 
| 101 |  |  | extern void     addchan(EPNODE *sp); | 
| 102 | schorsch | 2.14 | extern void     getstatement(void); | 
| 103 |  |  | extern EPNODE   *getdefn(void); | 
| 104 |  |  | extern EPNODE   *getchan(void); | 
| 105 | greg | 2.6 | /* defined in calexpr.c */ | 
| 106 |  |  | extern EPNODE   *eparse(char *expr); | 
| 107 |  |  | extern double   eval(char *expr); | 
| 108 |  |  | extern int      epcmp(EPNODE *ep1, EPNODE *ep2); | 
| 109 |  |  | extern void     epfree(EPNODE *epar); | 
| 110 |  |  | extern EPNODE   *ekid(EPNODE *ep, int n); | 
| 111 |  |  | extern int      nekids(EPNODE *ep); | 
| 112 |  |  | extern void     initfile(FILE *fp, char *fn, int ln); | 
| 113 |  |  | extern void     initstr(char *s, char *fn, int ln); | 
| 114 |  |  | extern void     getscanpos(char **fnp, int *lnp, char **spp, FILE **fpp); | 
| 115 |  |  | extern int      scan(void); | 
| 116 |  |  | extern char     *long2ascii(long l); | 
| 117 |  |  | extern void     syntax(char *err); | 
| 118 |  |  | extern void     addekid(EPNODE *ep, EPNODE *ekid); | 
| 119 |  |  | extern char     *getname(void); | 
| 120 |  |  | extern int      getinum(void); | 
| 121 |  |  | extern double   getnum(void); | 
| 122 |  |  | extern EPNODE   *getE1(void); | 
| 123 |  |  | extern EPNODE   *getE2(void); | 
| 124 |  |  | extern EPNODE   *getE3(void); | 
| 125 |  |  | extern EPNODE   *getE4(void); | 
| 126 |  |  | extern EPNODE   *getE5(void); | 
| 127 |  |  | extern EPNODE   *rconst(EPNODE *epar); | 
| 128 |  |  | extern int      isconstvar(EPNODE *ep); | 
| 129 |  |  | extern int      isconstfun(EPNODE *ep); | 
| 130 |  |  | /* defined in calfunc.c */ | 
| 131 |  |  | extern int      fundefined(char *fname); | 
| 132 |  |  | extern double   funvalue(char *fname, int n, double *a); | 
| 133 | greg | 2.16 | extern void     funset(char *fname, int nargs, int assign, | 
| 134 |  |  | double (*fptr)(char *)); | 
| 135 | greg | 2.6 | extern int      nargum(void); | 
| 136 |  |  | extern double   argument(int n); | 
| 137 |  |  | extern VARDEF   *argf(int n); | 
| 138 |  |  | extern char     *argfun(int n); | 
| 139 |  |  | extern double   efunc(EPNODE *ep); | 
| 140 |  |  | extern LIBR     *liblookup(char *fname); | 
| 141 |  |  | extern void     libupdate(char *fn); | 
| 142 |  |  | /* defined in calprnt.c */ | 
| 143 |  |  | extern void     eprint(EPNODE *ep, FILE *fp); | 
| 144 |  |  | extern void     dprint(char *name, FILE *fp); | 
| 145 |  |  | /* defined in savestr.c */ | 
| 146 |  |  | extern char     *savestr(char *str); | 
| 147 |  |  | extern void     freestr(char *s); | 
| 148 |  |  | extern int      shash(char *s); | 
| 149 |  |  | /* defined in ealloc.c */ | 
| 150 |  |  | extern char     *emalloc(unsigned int n); | 
| 151 |  |  | extern char     *ecalloc(unsigned int ne, unsigned int es); | 
| 152 |  |  | extern char     *erealloc(char *cp, unsigned int n); | 
| 153 |  |  | extern void     efree(char *cp); | 
| 154 |  |  | /* defined by client */ | 
| 155 |  |  | extern double   chanvalue(int n); | 
| 156 |  |  |  | 
| 157 | schorsch | 2.9 |  | 
| 158 |  |  | #ifdef __cplusplus | 
| 159 |  |  | } | 
| 160 | greg | 2.6 | #endif | 
| 161 | schorsch | 2.9 | #endif /* _RAD_CALCOMP_H_ */ | 
| 162 |  |  |  |