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

1.1       ohara       1: /* -*- mode: C -*- */
1.25    ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.24 2003/08/21 12:44:06 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);
1.25    ! ohara     186: cmo_polynomial_in_one_variable* new_cmo_polynomial_in_one_variable(int var);
        !           187: cmo_recursive_polynomial* new_cmo_recursive_polynomial(cmo_list* ringdef, cmo* coef);
1.1       ohara     188: cmo_error2*        new_cmo_error2(cmo* ob);
                    189:
                    190: ox_data*           new_ox_data(cmo* c);
                    191: ox_command*        new_ox_command(int sm_code);
                    192: ox_sync_ball*      new_ox_sync_ball();
                    193:
                    194: char*              new_string_set_cmo(cmo* m);
                    195:
                    196: cmo_error2*        make_error_object(int err_code, cmo* ob);
                    197:
                    198: /* Low level API */
1.2       ohara     199: cmo*               receive_cmo(OXFILE *fp);
1.17      ohara     200: cmo*               receive_cmo_tag(OXFILE *fp, int tag);
1.2       ohara     201: int                receive_int32(OXFILE *fp);
                    202: int                receive_ox_tag(OXFILE *fp);
                    203:
                    204: void               send_cmo(OXFILE *fp, cmo* m);
                    205: int                send_int32(OXFILE *fp, int integer);
                    206: void               send_ox(OXFILE *fp, ox* m);
                    207: void               send_ox_cmo(OXFILE *fp, cmo* m);
                    208: void               send_ox_command(OXFILE *fp, int sm_command);
                    209: int                send_ox_tag(OXFILE *fp, int tag);
1.1       ohara     210:
                    211: int                next_serial();
                    212: void               setCmotypeDisable(int type);
                    213:
                    214: /* High level API */
1.2       ohara     215: void               ox_close(OXFILE *sv);
                    216: void               ox_shutdown(OXFILE *sv);
                    217: void               ox_reset(OXFILE *sv);
                    218: void               ox_execute_string(OXFILE *sv, char* str);
                    219: cmo_mathcap*       ox_mathcap(OXFILE *sv);
                    220: char*              ox_popString(OXFILE *sv);
                    221: void               ox_pops(OXFILE *sv, int num);
                    222: cmo*               ox_pop_cmo(OXFILE *sv);
                    223: void               ox_push_cmo(OXFILE *sv, cmo *c);
                    224: void               ox_push_cmd(OXFILE *sv, int sm_code);
                    225: void               ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
                    226: int                ox_flush(OXFILE *sv);
                    227:
1.16      ohara     228: cell*              list_first(cmo_list *);
                    229: int                list_endof(cmo_list *, cell *el);
1.2       ohara     230: cell*              list_next(cell *el);
1.16      ohara     231: cmo_list*          list_append(cmo_list*, cmo *ob);
1.22      ohara     232: cmo_list*          list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16      ohara     233: cmo_list*          list_appendl(cmo_list*, ...);
                    234: int                list_length(cmo_list* );
                    235: cmo*               list_nth(cmo_list* , int n);
1.2       ohara     236:
1.1       ohara     237: int                cmolen_cmo(cmo* m);
1.2       ohara     238: void               dump_buffer_init(char *s);
                    239: void               dump_cmo(cmo* m);
                    240: void               dump_ox_command(ox_command* m);
                    241: void               dump_ox_data(ox_data* m);
1.1       ohara     242:
1.2       ohara     243: void               print_cmo(cmo* c);
                    244: void               resize_mpz(mpz_ptr mpz, int size);
1.1       ohara     245:
1.2       ohara     246: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1       ohara     247:
                    248: int add_hook_before_send_cmo(hook_t func);
                    249: int add_hook_after_send_cmo(hook_t func);
                    250:
                    251: /* functions related to parse.c */
                    252:
                    253: #define PFLAG_ADDREV   1
                    254:
                    255: typedef struct symbol *symbol_t;
                    256:
1.2       ohara     257: void setflag_parse(int flag);
1.1       ohara     258: cmo *parse();
1.2       ohara     259: void init_parser(char *s);
1.1       ohara     260:
                    261: symbol_t lookup_by_symbol(char *key);
                    262: symbol_t lookup_by_token(int tok);
                    263: symbol_t lookup_by_tag(int tag);
                    264: symbol_t lookup(int i);
1.13      ohara     265: char*    get_symbol_by_tag(int tag);
1.2       ohara     266:
                    267: /* for mathcap database */
1.6       ohara     268: mathcap *new_mathcap();
                    269: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.16      ohara     270: cmo_mathcap* mathcap_get(mathcap *);
                    271: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
                    272: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2       ohara     273:
                    274: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    275: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    276:
                    277: /* for OXFILE */
1.25    ! ohara     278: int oxf_listen(int *portp);
1.2       ohara     279: OXFILE *oxf_connect_active(char *hostname, short port);
                    280: OXFILE *oxf_connect_passive(int listened);
                    281: OXFILE *oxf_open(int fd);
                    282: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
                    283: OXFILE *oxf_control(OXFILE *oxfp);
                    284: int  oxf_confirm_client(OXFILE *oxfp, char *passwd);
                    285: int  oxf_confirm_server(OXFILE *oxfp, char *passwd);
                    286: void oxf_flush(OXFILE *oxfp);
                    287: void oxf_close(OXFILE *oxfp);
                    288: void oxf_setopt(OXFILE *oxfp, int mode);
                    289: void oxf_determine_byteorder_client(OXFILE *oxfp);
                    290: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4       ohara     291: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8       ohara     292: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6       ohara     293: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.2       ohara     294:
                    295: /* example: which("xterm", getenv("PATH")); */
                    296: char *which(char *exe, const char *env);
                    297: char *generate_otp();
1.1       ohara     298:
1.10      ohara     299: int ox_stderr_init(FILE *fp);
1.11      ohara     300: int ox_printf(char *format, ...);
1.16      ohara     301:
                    302: #ifdef __cplusplus
                    303: }
                    304: #endif
                    305:
1.1       ohara     306: #endif /* _OX_TOOLKIT_H_ */

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