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