[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.23

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

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