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

1.1       ohara       1: /* -*- mode: C -*- */
1.24    ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.23 2003/06/05 21:12:07 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;
1.24    ! ohara     137:
        !           138: /* The following is a derived class from cmo_list.
        !           139:    that is, list_append can be used. */
        !           140: typedef struct {
        !           141:     int tag;
        !           142:     int length;   /* number of monomials */
        !           143:     cell head[1]; /* list of monomials */
        !           144:     int var;      /* name of the main variable */
        !           145: } cmo_polynomial_in_one_variable;
        !           146:
        !           147: typedef struct {
        !           148:     int tag;
        !           149:     cmo_list *ringdef; /* list of variables */
        !           150:     cmo *coef;  /* ZZ, QQ, int32, Poly_in_1var, Tree, Zero, DPoly */
        !           151: } cmo_recursive_polynomial;
1.1       ohara     152:
                    153: typedef cmo ox;
                    154:
                    155: typedef ox ox_sync_ball;
                    156:
                    157: typedef struct {
                    158:     int tag;
                    159:     int command;
                    160: } ox_command;
                    161:
                    162: typedef struct {
                    163:     int tag;
1.18      ohara     164:     struct cmo *cmo;
1.1       ohara     165: } ox_data;
                    166:
                    167: cmo_null*          new_cmo_null();
                    168: cmo_int32*         new_cmo_int32(int i);
                    169: cmo_string*        new_cmo_string(char* s);
                    170: cmo_mathcap*       new_cmo_mathcap(cmo* ob);
                    171: cmo_list*          new_cmo_list();
                    172: cmo_monomial32*    new_cmo_monomial32();
                    173: cmo_monomial32*    new_cmo_monomial32_size(int size);
                    174: cmo_zz*            new_cmo_zz();
                    175: cmo_zz*            new_cmo_zz_size(int size);
                    176: cmo_zz*            new_cmo_zz_set_si(int integer);
                    177: cmo_zz*            new_cmo_zz_set_mpz(mpz_ptr z);
                    178: cmo_zz*            new_cmo_zz_noinit();
                    179: cmo_zz*            new_cmo_zz_set_string(char* s);
                    180: cmo_zero*          new_cmo_zero();
1.12      ohara     181: cmo_double*        new_cmo_double(double d);
1.1       ohara     182: cmo_distributed_polynomial* new_cmo_distributed_polynomial();
                    183: cmo_dms_generic*   new_cmo_dms_generic();
                    184: cmo_ring_by_name*  new_cmo_ring_by_name(cmo* ob);
                    185: cmo_indeterminate* new_cmo_indeterminate(cmo* ob);
                    186: cmo_error2*        new_cmo_error2(cmo* ob);
                    187:
                    188: ox_data*           new_ox_data(cmo* c);
                    189: ox_command*        new_ox_command(int sm_code);
                    190: ox_sync_ball*      new_ox_sync_ball();
                    191:
                    192: char*              new_string_set_cmo(cmo* m);
                    193:
                    194: cmo_error2*        make_error_object(int err_code, cmo* ob);
                    195:
                    196: /* Low level API */
1.2       ohara     197: cmo*               receive_cmo(OXFILE *fp);
1.17      ohara     198: cmo*               receive_cmo_tag(OXFILE *fp, int tag);
1.2       ohara     199: int                receive_int32(OXFILE *fp);
                    200: int                receive_ox_tag(OXFILE *fp);
                    201:
                    202: void               send_cmo(OXFILE *fp, cmo* m);
                    203: int                send_int32(OXFILE *fp, int integer);
                    204: void               send_ox(OXFILE *fp, ox* m);
                    205: void               send_ox_cmo(OXFILE *fp, cmo* m);
                    206: void               send_ox_command(OXFILE *fp, int sm_command);
                    207: int                send_ox_tag(OXFILE *fp, int tag);
1.1       ohara     208:
                    209: int                next_serial();
                    210: void               setCmotypeDisable(int type);
                    211:
                    212: /* High level API */
1.2       ohara     213: void               ox_close(OXFILE *sv);
                    214: void               ox_shutdown(OXFILE *sv);
                    215: void               ox_reset(OXFILE *sv);
                    216: void               ox_execute_string(OXFILE *sv, char* str);
                    217: cmo_mathcap*       ox_mathcap(OXFILE *sv);
                    218: char*              ox_popString(OXFILE *sv);
                    219: void               ox_pops(OXFILE *sv, int num);
                    220: cmo*               ox_pop_cmo(OXFILE *sv);
                    221: void               ox_push_cmo(OXFILE *sv, cmo *c);
                    222: void               ox_push_cmd(OXFILE *sv, int sm_code);
                    223: void               ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
                    224: int                ox_flush(OXFILE *sv);
                    225:
1.16      ohara     226: cell*              list_first(cmo_list *);
                    227: int                list_endof(cmo_list *, cell *el);
1.2       ohara     228: cell*              list_next(cell *el);
1.16      ohara     229: cmo_list*          list_append(cmo_list*, cmo *ob);
1.22      ohara     230: cmo_list*          list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16      ohara     231: cmo_list*          list_appendl(cmo_list*, ...);
                    232: int                list_length(cmo_list* );
                    233: cmo*               list_nth(cmo_list* , int n);
1.2       ohara     234:
1.1       ohara     235: int                cmolen_cmo(cmo* m);
1.2       ohara     236: void               dump_buffer_init(char *s);
                    237: void               dump_cmo(cmo* m);
                    238: void               dump_ox_command(ox_command* m);
                    239: void               dump_ox_data(ox_data* m);
1.1       ohara     240:
1.2       ohara     241: void               print_cmo(cmo* c);
                    242: void               resize_mpz(mpz_ptr mpz, int size);
1.1       ohara     243:
1.2       ohara     244: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1       ohara     245:
                    246: int add_hook_before_send_cmo(hook_t func);
                    247: int add_hook_after_send_cmo(hook_t func);
                    248:
                    249: /* functions related to parse.c */
                    250:
                    251: #define PFLAG_ADDREV   1
                    252:
                    253: typedef struct symbol *symbol_t;
                    254:
1.2       ohara     255: void setflag_parse(int flag);
1.1       ohara     256: cmo *parse();
1.2       ohara     257: void init_parser(char *s);
1.1       ohara     258:
                    259: symbol_t lookup_by_symbol(char *key);
                    260: symbol_t lookup_by_token(int tok);
                    261: symbol_t lookup_by_tag(int tag);
                    262: symbol_t lookup(int i);
1.13      ohara     263: char*    get_symbol_by_tag(int tag);
1.2       ohara     264:
                    265: /* for mathcap database */
1.6       ohara     266: mathcap *new_mathcap();
                    267: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.16      ohara     268: cmo_mathcap* mathcap_get(mathcap *);
                    269: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
                    270: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2       ohara     271:
                    272: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    273: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    274:
                    275: /* for OXFILE */
1.4       ohara     276: int oxf_listen(short *portp);
1.2       ohara     277: OXFILE *oxf_connect_active(char *hostname, short port);
                    278: OXFILE *oxf_connect_passive(int listened);
                    279: OXFILE *oxf_open(int fd);
                    280: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
                    281: OXFILE *oxf_control(OXFILE *oxfp);
                    282: int  oxf_confirm_client(OXFILE *oxfp, char *passwd);
                    283: int  oxf_confirm_server(OXFILE *oxfp, char *passwd);
                    284: void oxf_flush(OXFILE *oxfp);
                    285: void oxf_close(OXFILE *oxfp);
                    286: void oxf_setopt(OXFILE *oxfp, int mode);
                    287: void oxf_determine_byteorder_client(OXFILE *oxfp);
                    288: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4       ohara     289: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8       ohara     290: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6       ohara     291: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2       ohara     292:
                    293: /* example: which("xterm", getenv("PATH")); */
                    294: char *which(char *exe, const char *env);
                    295: char *generate_otp();
1.1       ohara     296:
1.10      ohara     297: int ox_stderr_init(FILE *fp);
1.11      ohara     298: int ox_printf(char *format, ...);
1.16      ohara     299:
                    300: #ifdef __cplusplus
                    301: }
                    302: #endif
                    303:
1.1       ohara     304: #endif /* _OX_TOOLKIT_H_ */

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