Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.16
1.1 ohara 1: /* -*- mode: C -*- */
1.16 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.15 2003/03/30 08:05:22 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);
172: int receive_int32(OXFILE *fp);
173: int receive_ox_tag(OXFILE *fp);
174:
175: void send_cmo(OXFILE *fp, cmo* m);
176: int send_int32(OXFILE *fp, int integer);
177: void send_ox(OXFILE *fp, ox* m);
178: void send_ox_cmo(OXFILE *fp, cmo* m);
179: void send_ox_command(OXFILE *fp, int sm_command);
180: int send_ox_tag(OXFILE *fp, int tag);
1.1 ohara 181:
182: int next_serial();
183: void setCmotypeDisable(int type);
184:
185: /* High level API */
1.2 ohara 186: void ox_close(OXFILE *sv);
187: void ox_shutdown(OXFILE *sv);
188: void ox_reset(OXFILE *sv);
189: void ox_execute_string(OXFILE *sv, char* str);
190: cmo_mathcap* ox_mathcap(OXFILE *sv);
191: char* ox_popString(OXFILE *sv);
192: void ox_pops(OXFILE *sv, int num);
193: cmo* ox_pop_cmo(OXFILE *sv);
194: void ox_push_cmo(OXFILE *sv, cmo *c);
195: void ox_push_cmd(OXFILE *sv, int sm_code);
196: void ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
197: int ox_flush(OXFILE *sv);
198:
1.16 ! ohara 199: cell* list_first(cmo_list *);
! 200: int list_endof(cmo_list *, cell *el);
1.2 ohara 201: cell* list_next(cell *el);
1.16 ! ohara 202: cmo_list* list_append(cmo_list*, cmo *ob);
! 203: cmo_list* list_appendl(cmo_list*, ...);
! 204: int list_length(cmo_list* );
! 205: cmo* list_nth(cmo_list* , int n);
1.2 ohara 206:
1.1 ohara 207: int cmolen_cmo(cmo* m);
1.2 ohara 208: void dump_buffer_init(char *s);
209: void dump_cmo(cmo* m);
210: void dump_ox_command(ox_command* m);
211: void dump_ox_data(ox_data* m);
1.1 ohara 212:
1.2 ohara 213: void print_cmo(cmo* c);
214: void resize_mpz(mpz_ptr mpz, int size);
1.1 ohara 215:
1.2 ohara 216: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1 ohara 217:
218: int add_hook_before_send_cmo(hook_t func);
219: int add_hook_after_send_cmo(hook_t func);
220:
221: /* functions related to parse.c */
222:
223: #define PFLAG_ADDREV 1
224:
225: typedef struct symbol *symbol_t;
226:
1.2 ohara 227: void setflag_parse(int flag);
1.1 ohara 228: cmo *parse();
1.2 ohara 229: void init_parser(char *s);
1.1 ohara 230:
231: symbol_t lookup_by_symbol(char *key);
232: symbol_t lookup_by_token(int tok);
233: symbol_t lookup_by_tag(int tag);
234: symbol_t lookup(int i);
1.13 ohara 235: char* get_symbol_by_tag(int tag);
1.2 ohara 236:
237: /* for mathcap database */
1.6 ohara 238: mathcap *new_mathcap();
239: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.16 ! ohara 240: cmo_mathcap* mathcap_get(mathcap *);
! 241: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
! 242: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2 ohara 243:
244: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
245: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
246:
247: /* for OXFILE */
1.4 ohara 248: int oxf_listen(short *portp);
1.2 ohara 249: OXFILE *oxf_connect_active(char *hostname, short port);
250: OXFILE *oxf_connect_passive(int listened);
251: OXFILE *oxf_open(int fd);
252: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
253: OXFILE *oxf_control(OXFILE *oxfp);
254: int oxf_confirm_client(OXFILE *oxfp, char *passwd);
255: int oxf_confirm_server(OXFILE *oxfp, char *passwd);
256: void oxf_flush(OXFILE *oxfp);
257: void oxf_close(OXFILE *oxfp);
258: void oxf_setopt(OXFILE *oxfp, int mode);
259: void oxf_determine_byteorder_client(OXFILE *oxfp);
260: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4 ohara 261: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8 ohara 262: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6 ohara 263: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2 ohara 264:
265: /* example: which("xterm", getenv("PATH")); */
266: char *which(char *exe, const char *env);
267: char *generate_otp();
1.1 ohara 268:
1.10 ohara 269: int ox_stderr_init(FILE *fp);
1.11 ohara 270: int ox_printf(char *format, ...);
1.16 ! ohara 271:
! 272: #ifdef __cplusplus
! 273: }
! 274: #endif
! 275:
1.1 ohara 276: #endif /* _OX_TOOLKIT_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>