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