1 #ifndef MC_H
2 #define MC_H
3 
4 extern "C" {
5 typedef struct list {
6   struct list *next;              /* pointer to next item in list */
7   char *name;                     /* name of list item            */
8 } LIST;
9 
10 extern LIST listheaders[];
11 
12 #define ALLOCATIONS 0
13 #define CONSTANTS   1
14 #define VARIABLES   2
15 #define COMMANDS    3
16 #define FUNCTIONS   4
17 
18 #define MAX_HEADERS 4
19 
20 #define ALLOC_HEAD listheaders[ALLOCATIONS].next
21 #define CONST_HEAD listheaders[CONSTANTS].next
22 #define VAR_HEAD   listheaders[VARIABLES].next
23 #define COM_HEAD   listheaders[COMMANDS].next
24 #define FUNC_HEAD  listheaders[FUNCTIONS].next
25 
26 #define NEXT(lst) (lst)->next
27 #define NAME(lst) (lst)->name
28 
29 /*******************************************************************
30                       MEMORY HANDLING
31 ********************************************************************/
32 
33 /*
34     memory allocation and deallocation routines
35 */
36 #define ALLOCMEM(size) mem_alloc(size)
37 #define FREEMEM(ptr) mem_free(ptr)
38 
39 /*
40     we use a lot of string copying.
41 */
42 #define STRCOPY(str) strcpy((char *)ALLOCMEM(strlen(str)+1),(str))
43 
44 typedef struct alloc_list {
45     struct alloc_list *next;
46     char *mem;
47 } ALLOC_LIST;
48 
49 #define ALLOC_LST(mem) (ALLOC_LIST *)((char *)mem-sizeof(ALLOC_LIST))
50 #define ALLOC_SIZE(size) (size+sizeof(ALLOC_LIST))
51 #define ALLOC_PTR(lst) (char *)((char *)lst+sizeof(ALLOC_LIST))
52 
53 /*******************************************************************
54                            VARIABLES
55 *******************************************************************/
56 
57 /*
58  *    MATC matrix is internally represented by this structure.
59  */
60 typedef struct MATRIX
61 {
62    int type,                    /* TYPE_DOUBLE or TYPE_STRING       */
63        refcount,                /* reference count                  */
64        nrow, ncol;              /* number of rows and columns       */
65    double *data;                /* pointer to double array          */
66 } MATRIX;
67 
68 
69 /*
70  *   list of VARIABLES
71  */
72 
73 typedef struct variable
74 {
75     struct variable *next;       /* pointer to next item in list     */
76     char *name;                  /* name of the item                 */
77     int changed;
78     MATRIX *me;
79 } VARIABLE;
80 
81 /*
82      shortcuts for accsessing structure MATRIX
83 */
84 #define MATR(ptr)    (ptr)->me->data
85 #define TYPE(ptr)    (ptr)->me->type
86 #define NROW(ptr)    (ptr)->me->nrow
87 #define NCOL(ptr)    (ptr)->me->ncol
88 #define REFCNT(ptr)  (ptr)->me->refcount
89 #define M(ptr,i,j)   (ptr)->me->data[(i) * NCOL(ptr) + (j)]
90 
91 #define VARIABLESIZE sizeof(VARIABLE)
92 #define MATRIXSIZE   sizeof(MATRIX)
93 #define MATSIZE(ptr) NROW(ptr)*NCOL(ptr)*sizeof(double)
94 
95 #define TYPE_DOUBLE  0
96 #define TYPE_COMPLEX 1       /* this is not */
97 #define TYPE_STRING  2
98 
99 /*******************************************************************
100                INTERNAL COMMANDS AND USER FUNCTIONS
101 *******************************************************************/
102 
103 typedef struct command
104 {
105   struct command *next;        /* pointer to next item in list    */
106   char *name;                  /* name of the item                */
107   int flags,                   /* CMDFLAG_PW & CMDFLAG_CE         */
108       minp, maxp;              /* min. and max. no. of parameters */
109    VARIABLE *(*sub)();         /* function to execute             */
110   char *help;                  /* help string... */
111 } COMMAND;
112 
113 #define COMSIZE sizeof(COMMAND)
114 
115 #define CMDFLAG_PW 1           /* element by element operation    */
116 #define CMDFLAG_CE 2           /* command can be executed when
117                                   preprosessing if constant
118                                   arguments.                      */
119 
120 /*******************************************************************
121                USER DEFINED FUNCTIONS
122 *******************************************************************/
123 
124 typedef struct function
125 {
126   struct function *next;     /* pointer to next function in list  */
127   char *name,                /* name of the function              */
128        **parnames,           /* function parameter names (if any) */
129        **exports,            /* functions exported variables      */
130        **imports,            /* functions imported variables      */
131        *help;                /* functions help text               */
132   int parcount;              /* defined number of parameters      */
133   struct clause *body;       /* function body                     */
134 } FUNCTION;
135 
136 #define FUNCSIZE sizeof(FUNCTION)
137 
138 }
139 
140 #endif // MC_H
141