[BACK]Return to ox_toolkit.h CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.20

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>