Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.26
1.1 ohara 1: /* -*- mode: C -*- */
1.26 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.25 2003/09/15 09:31:41 ohara Exp $ */
1.1 ohara 3:
4: #ifndef _OX_TOOLKIT_H_
5:
6: #define _OX_TOOLKIT_H_
7:
1.16 ohara 8: #ifdef __cplusplus
9: extern "C" {
10: #endif
11:
1.2 ohara 12: #include <stdio.h>
1.14 ohara 13: #if defined(WITH_GMP)
1.5 ohara 14: #include <gmp.h>
1.15 ohara 15: #else
16: #include "gmp_fake.h"
1.14 ohara 17: #endif /* WITH_GMP */
1.5 ohara 18: #include <ox/cmotag.h>
19: #include <ox/oxMessageTag.h>
20: #include <ox/smCommand.h>
1.21 ohara 21: #include <gc/gc.h>
1.20 ohara 22:
1.21 ohara 23: #define MALLOC(x) GC_MALLOC((x))
1.23 ohara 24: #define MALLOC_ATOMIC(x) GC_MALLOC_ATOMIC((x))
1.20 ohara 25: #define ALLOCA(x) alloca((x))
1.21 ohara 26: /* #define FREE(x) free((x)) */
27: #define FREE(x)
1.1 ohara 28:
1.2 ohara 29: #if !defined(__GNUC__) && !defined(__inline__)
30: #define __inline__
31: #endif
32:
1.7 ohara 33: /* Mathcap Local Database */
34: typedef struct {
35: int tag;
36: int flag;
37: } table;
38:
39: typedef struct mathcap {
40: table *cmotbl;
41: table *smtbl;
42: } mathcap;
43:
44: /* OpenXM File Descripter */
1.2 ohara 45: typedef struct OXFILE{
1.6 ohara 46: int fd;
47: int (*send_int32)(struct OXFILE *oxfp, int int32);
48: int (*receive_int32)(struct OXFILE *oxfp);
49: int serial_number;
1.9 ohara 50: int received_serial_number;
1.6 ohara 51: struct OXFILE *control; /* pointer to his control server. */
52: struct mathcap *mathcap;
53: int error;
1.19 ohara 54: char *wbuf;
55: int wbuf_size;
56: int wbuf_count;
1.2 ohara 57: } OXFILE;
1.1 ohara 58:
1.18 ohara 59: typedef struct cmo {
1.1 ohara 60: int tag;
61: } cmo;
62:
63: typedef cmo cmo_null;
64: typedef cmo cmo_zero;
65: typedef cmo cmo_dms_generic;
66:
67: typedef struct {
68: int tag;
69: int i;
70: } cmo_int32;
71:
72: typedef struct {
73: int tag;
74: int size;
75: char *body;
76: } cmo_datum;
77:
78: typedef struct {
79: int tag;
80: char *s;
81: } cmo_string;
82:
83: typedef struct {
84: int tag;
85: cmo *ob;
86: } cmo_mathcap;
87:
88: typedef cmo_mathcap cmo_error2;
89: typedef cmo_mathcap cmo_ring_by_name;
90: typedef cmo_mathcap cmo_indeterminate;
91:
1.2 ohara 92: /* a double linked list */
1.1 ohara 93: typedef struct cell {
1.18 ohara 94: struct cmo *cmo;
1.1 ohara 95: struct cell *next;
1.2 ohara 96: struct cell *prev;
1.22 ohara 97: int exp;
1.1 ohara 98: } cell;
99:
100: typedef struct {
101: int tag;
102: int length; /* length of this list (unnecessary) */
103: cell head[1];
104: } cmo_list;
105:
106: typedef struct {
107: int tag;
108: int length;
109: int *exps;
110: cmo *coef;
111: } cmo_monomial32;
112:
113: typedef struct {
114: int tag;
115: mpz_t mpz;
116: } cmo_zz;
117:
118: typedef struct {
119: int tag;
120: cmo *num; /* Bunshi (cmo_zz) */
121: cmo *den; /* Bunbo (cmo_zz) */
122: } cmo_qq;
123:
1.12 ohara 124: typedef struct {
125: int tag;
126: double d; /* machine dependent */
127: } cmo_double;
128:
1.1 ohara 129: /* The following is a derived class from cmo_list.
1.2 ohara 130: that is, list_append can be used. */
1.1 ohara 131: typedef struct {
132: int tag;
133: int length; /* number of monomials */
134: cell head[1]; /* a list of monomials */
135: cmo *ringdef;
136: } cmo_distributed_polynomial;
1.24 ohara 137:
138: /* The following is a derived class from cmo_list.
139: that is, list_append can be used. */
140: typedef struct {
141: int tag;
142: int length; /* number of monomials */
143: cell head[1]; /* list of monomials */
144: int var; /* name of the main variable */
145: } cmo_polynomial_in_one_variable;
146:
147: typedef struct {
148: int tag;
149: cmo_list *ringdef; /* list of variables */
150: cmo *coef; /* ZZ, QQ, int32, Poly_in_1var, Tree, Zero, DPoly */
151: } cmo_recursive_polynomial;
1.1 ohara 152:
1.26 ! ohara 153: typedef struct {
! 154: int tag;
! 155: cmo_string *name;
! 156: cmo_list *attributes;
! 157: cmo_list *leaves;
! 158: } cmo_tree;
! 159:
! 160: typedef struct {
! 161: int tag;
! 162: cmo_list *args;
! 163: cmo_tree *body;
! 164: } cmo_lambda;
! 165:
1.1 ohara 166: typedef cmo ox;
167:
168: typedef ox ox_sync_ball;
169:
170: typedef struct {
171: int tag;
172: int command;
173: } ox_command;
174:
175: typedef struct {
176: int tag;
1.18 ohara 177: struct cmo *cmo;
1.1 ohara 178: } ox_data;
179:
180: cmo_null* new_cmo_null();
181: cmo_int32* new_cmo_int32(int i);
182: cmo_string* new_cmo_string(char* s);
183: cmo_mathcap* new_cmo_mathcap(cmo* ob);
184: cmo_list* new_cmo_list();
185: cmo_monomial32* new_cmo_monomial32();
186: cmo_monomial32* new_cmo_monomial32_size(int size);
187: cmo_zz* new_cmo_zz();
188: cmo_zz* new_cmo_zz_size(int size);
189: cmo_zz* new_cmo_zz_set_si(int integer);
190: cmo_zz* new_cmo_zz_set_mpz(mpz_ptr z);
191: cmo_zz* new_cmo_zz_noinit();
192: cmo_zz* new_cmo_zz_set_string(char* s);
193: cmo_zero* new_cmo_zero();
1.12 ohara 194: cmo_double* new_cmo_double(double d);
1.1 ohara 195: cmo_distributed_polynomial* new_cmo_distributed_polynomial();
196: cmo_dms_generic* new_cmo_dms_generic();
197: cmo_ring_by_name* new_cmo_ring_by_name(cmo* ob);
198: cmo_indeterminate* new_cmo_indeterminate(cmo* ob);
1.25 ohara 199: cmo_polynomial_in_one_variable* new_cmo_polynomial_in_one_variable(int var);
200: cmo_recursive_polynomial* new_cmo_recursive_polynomial(cmo_list* ringdef, cmo* coef);
1.26 ! ohara 201: cmo_tree* new_cmo_tree(cmo_string* name, cmo_list *attributes, cmo_list *leaves);
! 202: cmo_lambda* new_cmo_lambda(cmo_list* args, cmo_tree* body);
1.1 ohara 203: cmo_error2* new_cmo_error2(cmo* ob);
204:
205: ox_data* new_ox_data(cmo* c);
206: ox_command* new_ox_command(int sm_code);
207: ox_sync_ball* new_ox_sync_ball();
208:
209: char* new_string_set_cmo(cmo* m);
210:
211: cmo_error2* make_error_object(int err_code, cmo* ob);
212:
213: /* Low level API */
1.2 ohara 214: cmo* receive_cmo(OXFILE *fp);
1.17 ohara 215: cmo* receive_cmo_tag(OXFILE *fp, int tag);
1.2 ohara 216: int receive_int32(OXFILE *fp);
217: int receive_ox_tag(OXFILE *fp);
218:
219: void send_cmo(OXFILE *fp, cmo* m);
220: int send_int32(OXFILE *fp, int integer);
221: void send_ox(OXFILE *fp, ox* m);
222: void send_ox_cmo(OXFILE *fp, cmo* m);
223: void send_ox_command(OXFILE *fp, int sm_command);
224: int send_ox_tag(OXFILE *fp, int tag);
1.1 ohara 225:
226: int next_serial();
227: void setCmotypeDisable(int type);
228:
229: /* High level API */
1.2 ohara 230: void ox_close(OXFILE *sv);
231: void ox_shutdown(OXFILE *sv);
232: void ox_reset(OXFILE *sv);
233: void ox_execute_string(OXFILE *sv, char* str);
234: cmo_mathcap* ox_mathcap(OXFILE *sv);
235: char* ox_popString(OXFILE *sv);
236: void ox_pops(OXFILE *sv, int num);
237: cmo* ox_pop_cmo(OXFILE *sv);
238: void ox_push_cmo(OXFILE *sv, cmo *c);
239: void ox_push_cmd(OXFILE *sv, int sm_code);
240: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
241: int ox_flush(OXFILE *sv);
242:
1.16 ohara 243: cell* list_first(cmo_list *);
244: int list_endof(cmo_list *, cell *el);
1.2 ohara 245: cell* list_next(cell *el);
1.16 ohara 246: cmo_list* list_append(cmo_list*, cmo *ob);
1.22 ohara 247: cmo_list* list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16 ohara 248: cmo_list* list_appendl(cmo_list*, ...);
249: int list_length(cmo_list* );
250: cmo* list_nth(cmo_list* , int n);
1.2 ohara 251:
1.1 ohara 252: int cmolen_cmo(cmo* m);
1.2 ohara 253: void dump_buffer_init(char *s);
254: void dump_cmo(cmo* m);
255: void dump_ox_command(ox_command* m);
256: void dump_ox_data(ox_data* m);
1.1 ohara 257:
1.2 ohara 258: void print_cmo(cmo* c);
259: void resize_mpz(mpz_ptr mpz, int size);
1.1 ohara 260:
1.2 ohara 261: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1 ohara 262:
263: int add_hook_before_send_cmo(hook_t func);
264: int add_hook_after_send_cmo(hook_t func);
265:
266: /* functions related to parse.c */
267:
268: #define PFLAG_ADDREV 1
269:
270: typedef struct symbol *symbol_t;
271:
1.2 ohara 272: void setflag_parse(int flag);
1.1 ohara 273: cmo *parse();
1.2 ohara 274: void init_parser(char *s);
1.1 ohara 275:
276: symbol_t lookup_by_symbol(char *key);
277: symbol_t lookup_by_token(int tok);
278: symbol_t lookup_by_tag(int tag);
279: symbol_t lookup(int i);
1.13 ohara 280: char* get_symbol_by_tag(int tag);
1.2 ohara 281:
282: /* for mathcap database */
1.6 ohara 283: mathcap *new_mathcap();
284: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.16 ohara 285: cmo_mathcap* mathcap_get(mathcap *);
286: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
287: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2 ohara 288:
289: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
290: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
291:
292: /* for OXFILE */
1.25 ohara 293: int oxf_listen(int *portp);
1.2 ohara 294: OXFILE *oxf_connect_active(char *hostname, short port);
295: OXFILE *oxf_connect_passive(int listened);
296: OXFILE *oxf_open(int fd);
297: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
298: OXFILE *oxf_control(OXFILE *oxfp);
299: int oxf_confirm_client(OXFILE *oxfp, char *passwd);
300: int oxf_confirm_server(OXFILE *oxfp, char *passwd);
301: void oxf_flush(OXFILE *oxfp);
302: void oxf_close(OXFILE *oxfp);
303: void oxf_setopt(OXFILE *oxfp, int mode);
304: void oxf_determine_byteorder_client(OXFILE *oxfp);
305: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4 ohara 306: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8 ohara 307: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6 ohara 308: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2 ohara 309:
310: /* example: which("xterm", getenv("PATH")); */
311: char *which(char *exe, const char *env);
312: char *generate_otp();
1.1 ohara 313:
1.10 ohara 314: int ox_stderr_init(FILE *fp);
1.11 ohara 315: int ox_printf(char *format, ...);
1.16 ohara 316:
317: #ifdef __cplusplus
318: }
319: #endif
320:
1.1 ohara 321: #endif /* _OX_TOOLKIT_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>