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