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