#ifndef MC_H1#define MC_H23extern "C" {45/*******************************************************************6LIST HANDLING DEFINITIONS7*******************************************************************/89typedef struct list {10struct list *next; /* pointer to next item in list */11char *name; /* name of list item */12} LIST;1314#ifdef MATC_OPENMP15/* Move initialization to matc.c::mtc_init() for thread safety */16extern LIST *listheaders;17#pragma omp threadprivate(listheaders)1819/* Data with thread-local storage cannot be reliably accessed across DLL20borders. Use an accessor function instead. */21LIST * mtc_get_listheaders(void);22#else23extern LIST listheaders[];24#endif /* MATC_OPENMP */2526#define ALLOCATIONS 027#define CONSTANTS 128#define VARIABLES 229#define COMMANDS 330#define FUNCTIONS 43132#define MAX_HEADERS 53334#ifdef MATC_OPENMP35#define LISTHEADERS (mtc_get_listheaders())36#else37#define LISTHEADERS listheaders38#endif /* MATC_OPENMP */39#define ALLOC_HEAD LISTHEADERS[ALLOCATIONS].next40#define CONST_HEAD LISTHEADERS[CONSTANTS].next41#define VAR_HEAD LISTHEADERS[VARIABLES].next42#define COM_HEAD LISTHEADERS[COMMANDS].next43#define FUNC_HEAD LISTHEADERS[FUNCTIONS].next4445#define NEXT(lst) (lst)->next46#define NAME(lst) (lst)->name4748/*******************************************************************49MEMORY HANDLING50********************************************************************/5152/*53memory allocation and deallocation routines54*/55#define ALLOCMEM(size) mem_alloc(size)56#define FREEMEM(ptr) mem_free(ptr)5758/*59we use a lot of string copying.60*/61#define STRCOPY(str) strcpy((char *)ALLOCMEM(strlen(str)+1),(str))6263typedef struct alloc_list {64struct alloc_list *next;65char *mem;66} ALLOC_LIST;6768#define ALLOC_LST(mem) (ALLOC_LIST *)((char *)mem-sizeof(ALLOC_LIST))69#define ALLOC_SIZE(size) (size+sizeof(ALLOC_LIST))70#define ALLOC_PTR(lst) (char *)((char *)lst+sizeof(ALLOC_LIST))7172/*******************************************************************73VARIABLES74*******************************************************************/7576/*77* MATC matrix is internally represented by this structure.78*/79typedef struct MATRIX80{81int type, /* TYPE_DOUBLE or TYPE_STRING */82refcount, /* reference count */83nrow, ncol; /* number of rows and columns */84double *data; /* pointer to double array */85} MATRIX;868788/*89* list of VARIABLES90*/9192typedef struct variable93{94struct variable *next; /* pointer to next item in list */95char *name; /* name of the item */96int changed;97MATRIX *me;98} VARIABLE;99100/*101shortcuts for accessing structure MATRIX102*/103#define MATR(ptr) (ptr)->me->data104#define TYPE(ptr) (ptr)->me->type105#define NROW(ptr) (ptr)->me->nrow106#define NCOL(ptr) (ptr)->me->ncol107#define REFCNT(ptr) (ptr)->me->refcount108#define M(ptr,i,j) (ptr)->me->data[(i) * NCOL(ptr) + (j)]109110#define VARIABLESIZE sizeof(VARIABLE)111#define MATRIXSIZE sizeof(MATRIX)112#define MATSIZE(ptr) NROW(ptr)*NCOL(ptr)*sizeof(double)113114#define TYPE_DOUBLE 0115#define TYPE_COMPLEX 1 /* this is not */116#define TYPE_STRING 2117118/*******************************************************************119INTERNAL COMMANDS AND USER FUNCTIONS120*******************************************************************/121122typedef struct command123{124struct command *next; /* pointer to next item in list */125char *name; /* name of the item */126int flags, /* CMDFLAG_PW & CMDFLAG_CE */127minp, maxp; /* min. and max. no. of parameters */128VARIABLE *(*sub)(); /* function to execute */129char *help; /* help string... */130} COMMAND;131132#define COMSIZE sizeof(COMMAND)133134#define CMDFLAG_PW 1 /* element by element operation */135#define CMDFLAG_CE 2 /* command can be executed when136preprocessing if constant137arguments. */138139/*******************************************************************140USER DEFINED FUNCTIONS141*******************************************************************/142143typedef struct function144{145struct function *next; /* pointer to next function in list */146char *name, /* name of the function */147**parnames, /* function parameter names (if any) */148**exports, /* functions exported variables */149**imports, /* functions imported variables */150*help; /* functions help text */151int parcount; /* defined number of parameters */152struct clause *body; /* function body */153} FUNCTION;154155#define FUNCSIZE sizeof(FUNCTION)156157}158159#endif // MC_H160161162